52
52
return strcmp(((HookFile*)a)->filename, b);
55
time_t hook_file_mtime(char *filename)
55
time_t hook_file_mtime(const gchar *filename)
58
58
char *file = g_strdup_printf("%s/%s",HOOKS_DIR, filename);
100
100
/* mark a given HookFile as run */
101
101
gboolean mark_hook_file_as_run(HookDialog *hook_dialog, HookFile *hf)
103
// FIXME: TEST THIS CODE
104
//g_debug("mark_hook_file_as_run: %s\n",filename);
106
g_debug("mark_hook_file_as_run: %s\n",hf->filename);
105
107
hf->cmd_run = TRUE;
211
213
char *term = g_strstrip(rfc822_header_lookup(rfc822, "Terminal"));
212
214
g_object_set_data(G_OBJECT(button_run),"cmd", g_strdup(cmd));
213
215
g_object_set_data(G_OBJECT(button_run),"term", g_strdup(term));
214
g_object_set_data(G_OBJECT(button_run),"hook_file", g_strdup(hook_file));
216
g_object_set_data(G_OBJECT(button_run),"hook_file", hf);
215
217
if(cmd != NULL) {
216
218
gtk_widget_show(button_run);
245
247
void cb_button_run(GtkWidget *self, void *data)
247
249
//g_debug("cb_button_run()\n");
250
252
TrayApplet *ta = (TrayApplet *)data;
251
253
HookDialog *hook_dialog = (HookDialog *)ta->user_data;
253
255
/* mark the current hook file as run */
254
gchar *hook_file = g_object_get_data(G_OBJECT(self), "hook_file");
255
mark_hook_file_as_run(hook_dialog, (const char*)hook_file);
256
HookFile *hf = g_object_get_data(G_OBJECT(self), "hook_file");
257
mark_hook_file_as_run(hook_dialog, hf);
257
259
gchar *cmd = g_object_get_data(G_OBJECT(self), "cmd");
258
260
gchar *term = g_object_get_data(G_OBJECT(self), "term");
265
267
if(term != NULL && !g_ascii_strncasecmp(term, "true",-1)) {
266
argv[0] = "gnome-terminal";
274
g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH ,
275
NULL, NULL, NULL, NULL);
268
cmdline = g_strdup_printf("gnome-terminal -e %s",cmd);
270
cmdline = g_strdup(cmd);
272
g_spawn_command_line_async(cmdline, NULL);
278
276
void cb_button_next(GtkWidget *self, void *data)
346
gboolean is_hook_relevant(const gchar *hook_file)
348
g_debug("is_hook_relevant()\n");
351
char *filename = g_strdup_printf("%s%s",HOOKS_DIR,hook_file);
352
FILE *f = fopen(filename, "r");
354
// can't open, can't be relevant
357
struct rfc822_header *rfc822 = rfc822_parse_stanza(f);
359
// check the DontShowAfterReboot flag
360
gchar *b = rfc822_header_lookup(rfc822, "DontShowAfterReboot");
361
if(b != NULL && g_ascii_strncasecmp(b, "true",-1) == 0) {
363
// read the uptime information
364
double uptime=0, idle=0;
366
int fd = open("/proc/uptimex", 0);
367
int local_n = read(fd, buf, sizeof(buf)-1);
369
char *savelocale = setlocale(LC_NUMERIC, NULL);
370
setlocale(LC_NUMERIC,"C");
371
sscanf(buf, "%lf %lf", &uptime,&idle);
373
setlocale(LC_NUMERIC,savelocale);
375
time_t mtime = hook_file_mtime(hook_file);
376
time_t now = time(NULL);
378
g_debug("now: %i mtime: %i uptime: %f\n",now,mtime,uptime);
379
g_debug("diff: %i uptime: %f\n",now-mtime,uptime);
380
if((int)uptime > 0 && (now - mtime) > (int)uptime) {
381
//g_print("not relevant because of reboot: %s\n",hook_file);
388
rfc822_header_free_all(rfc822);
349
392
gboolean check_update_hooks(TrayApplet *ta)
360
403
g_critical("can't read %s directory\n",HOOKS_DIR);
405
int unseen_count = 0;
363
406
GList *hook_files = hook_dialog->hook_files;
364
407
while((hook_file=g_dir_read_name(dir)) != NULL) {
409
// check if the hook still applies (for e.g. DontShowAfterReboot)
410
if(!is_hook_relevant(hook_file))
365
413
// see if we already know about this hook filename
366
414
GList *elm = g_list_find_custom(hook_dialog->hook_files,hook_file,
367
415
compare_hook_func);
368
416
// not seen before, add to the list
369
417
if(elm == NULL) {
370
418
g_debug("never seen before: %s",hook_file);
372
420
HookFile *t = g_new0(HookFile, 1);
373
421
t->filename = strdup(hook_file);
374
422
t->mtime = hook_file_mtime(hook_file);
391
439
time_t new_mtime = hook_file_mtime(hook_file);
392
440
if(new_mtime > hf->mtime) {
393
441
g_debug("newer mtime: %s (%i > %i))",hook_file, new_mtime, hf->mtime);
395
443
hf->seen = FALSE;
396
444
hf->mtime = new_mtime;
400
448
g_dir_close(dir);
402
g_debug("hooks: %i (new: %i)", g_list_length(hook_files), new_count);
450
g_debug("hooks: %i (new: %i)", g_list_length(hook_files), unseen_count);
403
451
hook_dialog->hook_files = hook_files;
405
453
GladeXML *xml = hook_dialog->glade_xml;
406
454
GtkWidget *button_next = glade_xml_get_widget(xml, "button_next");
407
455
assert(button_next);
457
switch(unseen_count) {
411
459
gtk_widget_hide(GTK_WIDGET(ta->tray_icon));
412
460
gtk_widget_hide(button_next);