1 #ifndef	_WMCLIPHIST_H_
2 #define	_WMCLIPHIST_H_
3 
4 
5 #define _GNU_SOURCE
6 
7 #include <signal.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <ctype.h>
13 #include <errno.h>
14 
15 #include <fcntl.h>
16 #include <regex.h>
17 
18 #include <gtk/gtk.h>
19 #include <gdk/gdk.h>
20 #include <gdk/gdkx.h>
21 
22 #include <foodock.h>
23 
24 #include <debug.h>
25 
26 
27 #define	VERSION			0x0003
28 #define	DEF_LOCKED_COLOR	"red"
29 #define	DEF_MENUKEY		"Control+Alt+V"
30 #define	DEF_PREV_ITEM_KEY	"Control+Alt+C"
31 #define	DEF_EXEC_ITEM_KEY	"Control+Alt+E"
32 #define	MAX_ITEM_LENGTH		40
33 
34 
35 /* ==========================================================================
36  *                                                        CLIPBOARD FUNCTIONS
37  */
38 
39 /* history item */
40 typedef struct {
41 	GtkWidget	*menu_item;
42 	gint		locked;
43 	gchar		*content;
44 	GtkWidget	*menu;
45 }	HISTORY_ITEM;
46 
47 
48 /* number of items to keep (may be overriden from command line) */
49 extern gint		num_items_to_keep;
50 
51 /* when true, clipboard will be automatically taken up by wmcliphist */
52 extern gint		auto_take_up;
53 
54 /* number of items kept */
55 extern gint		num_items;
56 
57 /* list of clipboard history items */
58 extern GList		*history_items;
59 
60 /* selected item */
61 extern HISTORY_ITEM	*selected;
62 
63 /* current number of locked items */
64 extern gint		locked_count;
65 
66 
67 
68 #ifdef DEBUG
69 #define	dump_history_list(header)	dump_history_list_fn(header)
70 #else
71 #define	dump_history_list(header)
72 #endif
73 
74 
75 /*
76  * get clipboard content - partialy inspired by Downloader for X
77  */
78 gboolean
79 my_get_xselection(GtkWidget *window, GdkEvent *event);
80 
81 /*
82  * clipboard conversion - inspired by Downloader for X too :)
83  */
84 gboolean
85 time_conv_select();
86 
87 /*
88  * handles request for selection from other apps
89  */
90 gint
91 selection_handle(GtkWidget *widget,
92 		GtkSelectionData *selection_data,
93 		guint info,
94 		guint time_stamp,
95 		gpointer data);
96 
97 
98 /* ==========================================================================
99  *                                                                  RC CONFIG
100  */
101 
102 /* action record */
103 typedef struct {
104 	regex_t			expression;
105 	enum {
106 		ACT_EXEC,
107 		ACT_SUBMENU,
108 		ACT_IGNORE
109 	}			action;
110 	char			*command;
111 	GtkWidget		*menu_item;
112 	GtkWidget		*submenu;
113 } ACTION;
114 
115 
116 extern GList	*action_list;
117 
118 
119 /*
120  * returns config/data file name in user's home
121  */
122 char *
123 rcconfig_get_name(char *append);
124 
125 /*
126  * read and parse rcconfig
127  */
128 int
129 rcconfig_get(char *fname);
130 
131 /*
132  * free rcconfig data
133  */
134 void
135 rcconfig_free();
136 
137 
138 
139 /* ==========================================================================
140  *                                                                        GUI
141  */
142 
143 /* error codes */
144 #define	E_BASE		10000
145 #define	E_OPEN		(E_BASE | 1)
146 #define	E_INVALID	(E_BASE | 2)
147 #define	E_REMOVE	(E_BASE | 3)
148 #define	E_TOO_MUCH	(E_BASE | 4)
149 #define	E_WRITE		(E_BASE | 5)
150 #define	E_RENAME	(E_BASE | 6)
151 
152 
153 /*
154  * process new history item
155  */
156 void
157 process_item(char *content, gint locked, gboolean exec);
158 
159 
160 
161 /* ==========================================================================
162  *                                                          HISTORY FUNCTIONS
163  */
164 
165 /*
166  * autosave period
167  */
168 extern int	autosave_period;
169 
170 /*
171  * confirm actions?
172  */
173 extern int	confirm_exec;
174 
175 /*
176  *  Exec immediately when item is captured?
177  */
178 extern int	exec_immediately;
179 
180 /*
181  * move supplied item to begin
182  */
183 void
184 move_item_to_begin(HISTORY_ITEM *item);
185 
186 /*
187  * Execute an item.
188  */
189 void
190 exec_item(char *content, ACTION *action);
191 
192 /*
193  * loads history from file
194  */
195 int
196 history_load(gboolean dump_only);
197 
198 /*
199  * store history to file
200  */
201 int
202 history_save();
203 
204 /*
205  * free history data
206  */
207 void
208 history_free();
209 
210 /*
211  * autosave timer function
212  */
213 gboolean
214 history_autosave();
215 
216 
217 /* ==========================================================================
218  *                                                                    HOTKEYS
219  */
220 
221 /* hotkeys */
222 extern gchar		menukey_str[32];
223 extern guint		menukey;
224 extern gchar		prev_item_key_str[32];
225 extern gchar		exec_item_key_str[32];
226 
227 /*
228  *  Exec on hotkey?
229  */
230 extern int	exec_hotkey;
231 
232 /*
233  * initialize hotkeys
234  */
235 void
236 hotkeys_init();
237 
238 /*
239  * disable hotkeys
240  */
241 void
242 hotkeys_done();
243 
244 
245 
246 /* ==========================================================================
247  *                                                                        GUI
248  */
249 
250 /* color of locked item */
251 extern gchar		locked_color_str[32];
252 extern GdkColor		locked_color;
253 extern GtkStyle		*style_locked,
254 			*style_normal;
255 extern gint		submenu_count;
256 
257 /*
258  *  Exec on middle click?
259  */
260 extern int	exec_middleclick;
261 
262 /* main window widget */
263 extern GtkWidget	*main_window;
264 
265 /* dock icon widget */
266 extern GtkWidget	*dock_app;
267 
268 /* clipboard history menu */
269 extern GtkWidget	*menu_hist;
270 extern GtkWidget	*menu_title;
271 
272 /* application menu */
273 extern GtkWidget	*menu_app;
274 extern GtkWidget	*menu_app_clip_ignore;
275 extern GtkWidget	*menu_app_clip_lock;
276 extern GtkWidget	*menu_app_exit;
277 extern GtkWidget	*menu_app_save;
278 
279 /* button */
280 extern GtkWidget	*button;
281 
282 /* pixmap */
283 extern GtkWidget	*pixmap;
284 extern GdkPixmap	*icon;
285 extern GdkBitmap	*icon_mask;
286 extern GdkBitmap	*mask;
287 
288 
289 /*
290  * dock button click response
291  */
292 gboolean
293 button_press(GtkWidget *widget, GdkEvent *event, gpointer data);
294 
295 
296 /*
297  * checks, if there is already such item in menu,
298  * in which case it moves it to the begining
299  */
300 HISTORY_ITEM *
301 menu_item_exists(gchar *content, GtkWidget *submenu);
302 
303 /*
304  * add new item to menu
305  */
306 HISTORY_ITEM *
307 menu_item_add(gchar *content, gint locked, GtkWidget *target_menu);
308 
309 
310 /*
311  * application main menu handler
312  */
313 gboolean
314 menu_app_item_click(GtkWidget *menuitem, gpointer data);
315 
316 
317 /*
318  * open dialog with specified message andbuttons
319  * and return number of button pressed
320  */
321 gint
322 show_message(gchar *message, char *title,
323 		char *b1_text, char *b2_text, char *b3_text);
324 
325 
326 
327 /* ==========================================================================
328  *                                                                  UTILITIES
329  */
330 gchar *
331 from_utf8(gchar *string);
332 
333 #endif
334