~ubuntu-branches/ubuntu/hardy/update-notifier/hardy-proposed

« back to all changes in this revision

Viewing changes to src/hooks.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2007-08-27 13:31:44 UTC
  • Revision ID: james.westby@ubuntu.com-20070827133144-szvj71oh1rhglsma
Tags: 0.59.5
* code cleanups
* fix incorrect tooltip when package manager was
  running (LP: #134959)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include "config.h"
3
3
#endif
4
4
 
 
5
#include <fcntl.h>
5
6
#include <glib.h>
6
7
#include <gtk/gtk.h>
7
8
#include <glib/gstdio.h>
39
40
 
40
41
void hooks_trayicon_update_tooltip (TrayApplet *un, int num_hooks)
41
42
{
42
 
   g_debug("update_tooltip: %x ", un);
 
43
   g_debug("update_tooltip: %p ", un);
43
44
   gchar *updates;
44
 
   gchar *explanation;
45
45
 
46
46
   updates = _("Information available");
47
47
 
140
140
      HookFile *e = (HookFile*)elm->data;
141
141
      g_debug("will write out: %s (%s)",e->filename, e->md5);
142
142
      if(e->seen == TRUE) {
143
 
         g_debug("e->seen: %s %i %x", e->filename,e->mtime, (int)(e->cmd_run));
144
 
         fprintf(f,"%s %i %x\n", e->filename, e->mtime, (int)(e->cmd_run));
 
143
         g_debug("e->seen: %s %li %x", e->filename,e->mtime, (int)(e->cmd_run));
 
144
         fprintf(f,"%s %li %x\n", e->filename, e->mtime, (int)(e->cmd_run));
145
145
      } else if(memcmp(e->md5,md5,16) == 0) {
146
146
         e->seen = TRUE;
147
 
         fprintf(f,"%s %i %x\n", e->filename,hf->mtime, (int)(e->cmd_run));
148
 
         g_debug("same md5: %s %i %x",e->filename,hf->mtime,(int)(e->cmd_run));
 
147
         fprintf(f,"%s %li %x\n", e->filename,hf->mtime, (int)(e->cmd_run));
 
148
         g_debug("same md5: %s %li %x",e->filename,hf->mtime,(int)(e->cmd_run));
149
149
      }
150
150
   }
151
151
 
468
468
      time_t mtime = hook_file_time(hook_file);
469
469
      time_t now = time(NULL);
470
470
 
471
 
      g_debug("now: %i mtime: %i uptime: %f",now,mtime,uptime);
472
 
      g_debug("diff: %i  uptime: %f",now-mtime,uptime);
 
471
      g_debug("now: %li mtime: %li uptime: %f",now,mtime,uptime);
 
472
      g_debug("diff: %li  uptime: %f",now-mtime,uptime);
473
473
      if((int)uptime > 0 && (now - mtime) > (int)uptime) {
474
474
         g_debug("not relevant because of reboot: %s",hook_file);
475
475
         res = FALSE;
499
499
 
500
500
   GtkWidget *d = glade_xml_get_widget(priv->glade_xml,"dialog_hooks");
501
501
   if((d && GTK_WIDGET_VISIBLE(d)) || priv->active_notification != NULL)
502
 
      return;
 
502
      return FALSE;
503
503
 
504
504
   GdkRectangle area;
505
505
   gtk_status_icon_get_geometry(ta->tray_icon, NULL, &area, NULL);
529
529
 
530
530
gboolean check_update_hooks(TrayApplet *ta)
531
531
{
532
 
   g_debug("check_update_hooks()");
533
 
 
534
 
   HookTrayAppletPrivate *priv = (HookTrayAppletPrivate*)ta->user_data;
535
 
 
 
532
   GList *elm;
 
533
   HookFile *hf;
536
534
   GDir* dir;
537
535
   const gchar *hook_file;
538
536
 
 
537
   g_debug("check_update_hooks()");
 
538
   HookTrayAppletPrivate *priv = (HookTrayAppletPrivate*)ta->user_data;
 
539
 
539
540
   dir=g_dir_open(HOOKS_DIR, 0, NULL);
540
541
   if(dir == NULL) {
541
542
      g_warning("can't read %s directory\n",HOOKS_DIR);
553
554
         continue;
554
555
      }
555
556
      // see if we already know about this hook filename
556
 
      GList *elm = g_list_find_custom(priv->hook_files,hook_file,
 
557
      elm = g_list_find_custom(priv->hook_files,hook_file,
557
558
                                      compare_hook_func);
558
559
 
559
560
      // not seen before, add to the list
565
566
         hook_file_md5(hook_file, t->md5);
566
567
         t->cmd_run = FALSE;
567
568
         t->seen = FALSE;
568
 
         priv->hook_files = g_list_append(priv->hook_files, t);
 
569
         priv->hook_files = g_list_append(priv->hook_files, (gpointer)t);
569
570
         // init elm with the just added record (will be needed below)
570
571
         elm = g_list_find_custom(priv->hook_files,hook_file,
571
572
                                  compare_hook_func);
574
575
      
575
576
      // this is the hook file information we have (either because it was
576
577
      // availabe already or because we added it)
577
 
      HookFile *hf = (HookFile*)elm->data;
 
578
      hf = (HookFile*)elm->data;
578
579
 
579
580
      // file has changed since we last saw it
580
581
      time_t new_mtime = hook_file_time(hook_file);
581
582
      if(new_mtime > hf->mtime) {
582
 
         g_debug("newer mtime: %s (%i > %i))",hook_file, new_mtime, hf->mtime);
 
583
         g_debug("newer mtime: %s (%li > %li))",hook_file, new_mtime, hf->mtime);
583
584
         hf->seen = FALSE;
584
585
      }
585
586
 
617
618
         }
618
619
      } else 
619
620
         g_debug("already seen: '%s'",hook_file);
620
 
      
621
 
 
622
 
 
623
621
   }
624
622
   g_dir_close(dir);
625
623
 
654
652
 
655
653
void hook_read_seen_file(HookTrayAppletPrivate *priv, const char* filename)
656
654
{
 
655
   HookFile *t;
657
656
   char buf[512];
658
657
   int time, was_run;
659
658
   FILE *f = fopen(filename, "r");
699
698
         // not in the list yet
700
699
         // add the just read hook file to the list
701
700
         g_debug("got: %s %i %i ",buf,time,was_run);
702
 
         HookFile *t = g_new0(HookFile, 1);
 
701
         t = g_new0(HookFile, 1);
703
702
         t->filename = strdup(buf);
704
703
         t->mtime = time;
705
704
         t->cmd_run = was_run;
706
705
         t->seen = TRUE;
707
706
         hook_file_md5(t->filename,t->md5);
708
707
 
709
 
         priv->hook_files = g_list_append(priv->hook_files, t);
 
708
         priv->hook_files = g_list_append(priv->hook_files, (gpointer)t);
710
709
      }
711
710
   }
712
711
   fclose(f);
742
741
               gint           arg3,
743
742
               gpointer       user_data)
744
743
{
745
 
   GtkTextIter iter, match_start, match_end, match_tmp, iter_real_end;
746
 
   gboolean ret;
 
744
   GtkTextIter iter, match_start, match_end, match_tmp;
747
745
 
748
746
   // get where we start
749
747
   gtk_text_buffer_get_iter_at_offset(buffer, &iter,