2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <Elementary.h>
25 # define PACKAGE "CBHM"
29 # define APPNAME "Clipboard History Manager"
32 #define CBHM_MAGIC 0xad960009
34 typedef struct _TargetHandler TargetHandler;
35 typedef struct _AppData AppData;
36 typedef struct _ClipdrawerData ClipdrawerData;
37 typedef struct _CNP_ITEM CNP_ITEM;
38 typedef struct _XHandlerData XHandlerData;
39 typedef struct _StorageData StorageData;
40 typedef char *(*text_converter_func)(AppData *ad, int type_index, const char *str);
42 #define ITEM_CNT_MAX 20
43 #define COPIED_DATA_STORAGE_DIR DATADIR"/.cbhm_files"
45 #include "clipdrawer.h"
46 #include "item_manager.h"
48 #include "xconverter.h"
51 struct _TargetHandler {
55 text_converter_func convert_to_entry;
56 text_converter_func convert_to_target[ATOM_INDEX_MAX];
61 Ecore_X_Display *x_disp;
62 Ecore_X_Window x_root_win;
63 Ecore_X_Window x_event_win;
64 Ecore_X_Window x_active_win;
67 Eina_Bool (*draw_item_add)(AppData *ad, CNP_ITEM *item);
68 Eina_Bool (*draw_item_del)(AppData *ad, CNP_ITEM *item);
69 Eina_Bool (*storage_item_add)(AppData *ad, CNP_ITEM *item);
70 Eina_Bool (*storage_item_del)(AppData *ad, CNP_ITEM *item);
71 Eina_Bool (*storage_item_update)(AppData *ad, CNP_ITEM *item);
72 CNP_ITEM *(*storage_item_load)(StorageData *sd, int index);
74 ClipdrawerData *clipdrawer;
75 XHandlerData *xhandler;
78 CNP_ITEM *clip_selected_item;
79 TargetHandler targetAtoms[ATOM_INDEX_MAX];
82 void *d_malloc(const char *func, int line, size_t size);
83 void *d_calloc(const char *func, int line, size_t n, size_t size);
84 void d_free(const char *func, int line, void *m);
86 extern int _log_domain;
87 #define CRITICAL(...) EINA_LOG_DOM_CRIT(_log_domain, __VA_ARGS__)
88 #define ERR(...) EINA_LOG_DOM_ERR(_log_domain, __VA_ARGS__)
89 #define WRN(...) EINA_LOG_DOM_WARN(_log_domain, __VA_ARGS__)
90 #define INF(...) EINA_LOG_DOM_INFO(_log_domain, __VA_ARGS__)
91 #define DBG(...) EINA_LOG_DOM_DBG(_log_domain, __VA_ARGS__)
92 #define CALLED() DBG("called %s, %s", __FILE__, __func__);
93 #define MALLOC(size) d_malloc(__func__, __LINE__, size)
94 #define CALLOC(n, size) d_calloc(__func__, __LINE__, n, size)
95 #define FREE(p) d_free(__func__, __LINE__, p)
97 // Define memory-safe string functions
98 #define SAFE_STRCMP(s1, s2) ((s1 && s2) ? strcmp(s1, s2) : (s1 ? 1 : -1))
99 #define SAFE_STRNCMP(s1, s2, n) ((s1 && s2) ? strncmp(s1, s2, n) : (s1 ? 1 : -1))
100 #define SAFE_STRDUP(s) (s ? strdup(s) : NULL)
101 #define SAFE_STRNDUP(s, n) (s ? strndup(s, n) : NULL)
102 #define SAFE_STRCPY(dest, src) (src ? strcpy(dest, src) : NULL)
103 #define SAFE_STRNCPY(dest, src, n) (src ? strncpy(dest, src, n) : NULL)
104 #define SAFE_STRCAT(dest, src) ((dest && src) ? strcat(dest, src) : NULL)
105 #define SAFE_STRNCAT(dest, src, n) ((dest && src) ? strncat(dest, src, n) : NULL)
106 #define SAFE_STRCHR(s, c) (s ? strchr(s, c) : NULL)
107 #define SAFE_STRSTR(haystack, needle) (haystack ? strstr(haystack, needle) : NULL)
108 #define SAFE_STRLEN(s) (s ? strlen(s) : 0)