13
13
/* relative to the home dir */
14
14
#define HOOKS_SEEN ".update-notifier/hooks_seen"
20
static void debug_log_handler (const gchar *log_domain,
21
GLogLevelFlags log_level,
26
g_log_default_handler (log_domain, log_level, message, user_data);
16
31
void hooks_trayicon_update_tooltip (TrayApplet *un, int num_hooks)
18
//g_print("update_tooltip: %x \n", un);
33
g_debug("update_tooltip: %x ", un);
20
35
gchar *explanation;
49
// compare a HookFile with a filename and find the HookFile that matches
35
50
gint compare_hook_func(gconstpointer a, gconstpointer b)
37
//g_print("compare: %s %s\n",(char*)(((HookFileSeen*)a)->filename),(char*)b);
52
//g_debug("compare: %s %s\n",(char*)(((HookFileSeen*)a)->filename),(char*)b);
38
53
return strcmp(((HookFile*)a)->filename, b);
50
65
return buf.st_mtime;
68
/* mark a given hook file as seen
69
(actually implemented to write out all the information we have)
54
71
gboolean hook_file_mark_as_seen(HookDialog *hook_dialog,
57
g_print("mark_hook_file_as_seen: %s\n", hf->filename);
74
g_debug("mark_hook_file_as_seen: %s", hf->filename);
62
79
// write out the list of known files
63
gchar *filename = g_strdup_printf("%s/"HOOKS_SEEN,g_get_home_dir());
80
gchar *filename = g_strdup_printf("%s/%s",g_get_home_dir(),HOOKS_SEEN);
64
81
FILE *f = fopen(filename, "w");
83
g_warning("Something went wrong writing the users hook file");
68
86
GList *elm = g_list_first(hook_dialog->hook_files);
69
87
for(;elm != NULL; elm = g_list_next(elm)) {
70
88
HookFile *e = (HookFile*)elm->data;
72
90
fprintf(f,"%s %i %x\n", e->filename, e->mtime, (int)(e->cmd_run));
91
g_debug("writing: %s %i %x", e->filename, e->mtime, (int)(e->cmd_run));
101
/* mark a given HookFile as run */
81
102
gboolean mark_hook_file_as_run(HookDialog *hook_dialog, HookFile *hf)
84
//g_print("mark_hook_file_as_run: %s\n",filename);
104
// FIXME: TEST THIS CODE
105
//g_debug("mark_hook_file_as_run: %s\n",filename);
85
106
hf->cmd_run = TRUE;
120
141
/* try $field-$languagecode_$countrycode first */
121
142
s = g_strdup_printf("%s-%s", field, get_lang_code(FALSE));
122
143
entry = rfc822_header_lookup(rfc822, s);
123
//g_print("Looking for: %s ; found: %s\n",s,entry);
144
//g_debug("Looking for: %s ; found: %s\n",s,entry);
125
146
if(entry != NULL)
128
149
/* try $field-$languagecode next */
129
150
s = g_strdup_printf("%s-%s", field, get_lang_code(TRUE));
130
//g_print("Looking for: %s ; found: %s\n",s,entry);
151
//g_debug("Looking for: %s ; found: %s\n",s,entry);
131
152
entry = rfc822_header_lookup(rfc822, s);
133
154
if(entry != NULL)
143
164
gboolean show_next_hook(TrayApplet *ta, GList *hooks)
145
g_print("show_next_hook()\n");
166
//g_debug("show_next_hook()\n");
147
168
HookDialog *hook_dialog = (HookDialog *)ta->user_data;
148
169
GladeXML *xml = hook_dialog->glade_xml;
164
185
hf = (HookFile*)elm->data;
165
186
if(hf->seen == FALSE) {
166
187
hook_file = hf->filename;
167
g_print("next_hook is: %s\n",hook_file);
188
//g_debug("next_hook is: %s\n",hook_file);
218
239
void cb_button_run(GtkWidget *self, void *data)
220
//g_print("cb_button_run()\n");
241
//g_debug("cb_button_run()\n");
223
244
TrayApplet *ta = (TrayApplet *)data;
251
272
void cb_button_next(GtkWidget *self, void *data)
253
g_print("cb_button_next()\n");
274
g_debug("cb_button_next()");
254
275
TrayApplet *ta = (TrayApplet *)data;
255
276
HookDialog *hook_dialog = (HookDialog *)ta->user_data;
340
361
compare_hook_func);
341
362
// not seen before, add to the list
342
363
if(elm == NULL) {
343
g_print("never seen before: %s\n",hook_file);
364
g_debug("never seen before: %s",hook_file);
345
366
HookFile *t = g_new0(HookFile, 1);
346
367
t->filename = strdup(hook_file);
354
375
// this is the hook file information we have
355
376
HookFile *hf = (HookFile*)elm->data;
378
// we have not seen it yet
379
if(hf->seen == FALSE) {
356
384
// file has changed since we last seen it
357
385
time_t new_mtime = hook_file_mtime(hook_file);
358
386
if(new_mtime > hf->mtime) {
359
g_print("newer mtime: %s (%i)\n",hook_file,hf->mtime, new_mtime);
387
g_debug("newer mtime: %s (%i > %i))",hook_file, new_mtime, hf->mtime);
361
389
hf->seen = FALSE;
362
390
hf->mtime = new_mtime;
365
394
g_dir_close(dir);
367
g_print("hooks: %i (new: %i)\n", g_list_length(hook_files), new_count);
396
g_debug("hooks: %i (new: %i)", g_list_length(hook_files), new_count);
368
397
hook_dialog->hook_files = hook_files;
370
399
GladeXML *xml = hook_dialog->glade_xml;
371
400
GtkWidget *button_next = glade_xml_get_widget(xml, "button_next");
372
401
assert(button_next);
374
if (new_count == 0) {
375
//g_print("gtk_widget_hide() called on tray_icon\n");
376
405
gtk_widget_hide(GTK_WIDGET(ta->tray_icon));
377
406
gtk_widget_hide(button_next);
379
//g_print("gtk_widget_show() called on tray_icon\n");
380
hooks_trayicon_update_tooltip (ta, new_count);
409
gtk_widget_show(GTK_WIDGET(ta->tray_icon));
410
gtk_widget_hide(button_next);
381
413
gtk_widget_show(GTK_WIDGET(ta->tray_icon));
382
414
gtk_widget_show(button_next);
417
hooks_trayicon_update_tooltip (ta, new_count);
406
440
seen = g_list_append(seen, t);
408
//g_print("got: %s %i %i \n",buf,time,was_run);
442
g_debug("got: %s %i %i ",buf,time,was_run);
410
444
g_free(filename);
433
467
G_CALLBACK(cb_button_run),
470
// setup a custom debug log handler
471
g_log_set_handler (G_LOG_DOMAIN,
436
477
/* show dialog on click */
437
478
g_signal_connect (G_OBJECT(ta->tray_icon),
438
479
"button-release-event",