~ubuntu-core-dev/update-notifier/ubuntu

« back to all changes in this revision

Viewing changes to src/update.c

  • Committer: Michael Vogt
  • Date: 2011-09-29 10:01:42 UTC
  • mto: This revision was merged to the branch mainline in revision 640.
  • Revision ID: michael.vogt@ubuntu.com-20110929100142-xucqr26yeeh6jx6q
add trayappletui abstraction, port everything over to it

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
}
56
56
 
57
57
static gboolean
58
 
activate_cb (GtkWidget *widget, 
 
58
gtk_status_icon_click_activate_cb (GtkWidget *widget, 
59
59
             TrayApplet *ta)
60
60
{
61
61
   UpdateTrayAppletPrivate *priv = (UpdateTrayAppletPrivate*)ta->user_data;
70
70
   return TRUE;
71
71
}
72
72
 
73
 
static gboolean
74
 
popup_cb (GtkStatusIcon *status_icon,
75
 
          guint          button,
76
 
          guint          activate_time,
77
 
          TrayApplet     *un)
78
 
{
79
 
   gtk_menu_set_screen (GTK_MENU (un->menu),
80
 
                        gtk_status_icon_get_screen(un->tray_icon));
81
 
   gtk_menu_popup (GTK_MENU (un->menu), NULL, NULL, 
82
 
                   gtk_status_icon_position_menu, un->tray_icon,
83
 
                   button, activate_time);
84
 
   return TRUE;
85
 
}
86
 
 
87
73
void
88
74
update_trayicon_update_tooltip (TrayApplet *ta, int num_upgrades)
89
75
{
94
80
                                      "There are %i updates available",
95
81
                                      num_upgrades),
96
82
                             num_upgrades);
97
 
   gtk_status_icon_set_tooltip_text(ta->tray_icon, updates);
 
83
   tray_applet_ui_set_tooltip_text(ta, updates);
98
84
   g_free(updates);
99
85
}
100
86
 
196
182
      return;
197
183
 
198
184
   if(is_running) {
199
 
 
 
185
#ifdef HAVE_APP_INDICATOR
 
186
      // we can't do fancy stuff like the gray-out with app-indicator,
 
187
      // so we just hide the tray thing here
 
188
      tray_applet_ui_set_visible(ta, FALSE);
 
189
#else
200
190
      // gray out the icon if apt is running, we do this only once,
201
191
      // after the first time, the storage_type changes from ICON_NAME to
202
192
      // IMAGE_PIXBUF
214
204
      }
215
205
 
216
206
      // and update the tooltip
217
 
      gtk_status_icon_set_tooltip_text(ta->tray_icon, _("A package manager is working"));
 
207
      tray_applet_ui_set_tooltip_text(ta->tray_icon, _("A package manager is working"));
218
208
      // and show it
219
 
      gtk_status_icon_set_visible(ta->tray_icon, TRUE);
 
209
      tray_applet_ui_set_visible(ta->tray_icon, TRUE);
 
210
#endif
220
211
 
221
212
      if(priv->active_notification != NULL) {
222
213
         notify_notification_close(priv->active_notification, NULL);
223
214
         priv->active_notification = NULL;
224
215
      }
225
216
   } else {
226
 
      gtk_status_icon_set_from_icon_name(ta->tray_icon, ta->name);
 
217
      tray_applet_ui_set_icon(ta, ta->name);
227
218
   }
228
219
}
229
220
 
240
231
 
241
232
   // check if the update-icon is still visible (in the delay time a 
242
233
   // update may already have been performed)
243
 
   if(!gtk_status_icon_get_visible(ta->tray_icon))
 
234
   if(!tray_applet_ui_get_visible(ta))
244
235
      return FALSE;
245
236
 
246
237
   // now show a notification handle 
277
268
void 
278
269
show_error(TrayApplet *ta, gchar *error_str)
279
270
{
280
 
   gtk_status_icon_set_tooltip_text(ta->tray_icon, error_str);
281
 
   gtk_status_icon_set_from_icon_name(ta->tray_icon, "dialog-error");
282
 
   gtk_status_icon_set_visible(ta->tray_icon, TRUE);
 
271
   tray_applet_ui_set_tooltip_text(ta, error_str);
 
272
   tray_applet_ui_set_icon(ta, "dialog-error");
 
273
   tray_applet_ui_set_visible(ta, TRUE);
283
274
}
284
275
 
285
276
static gboolean
288
279
   struct stat buf;
289
280
   if ((stat("/var/lib/apt/periodic/update-success-stamp", &buf) == 0) &&
290
281
       (time(NULL) - buf.st_mtime > OUTDATED_NAG_AGE) ) {
291
 
      gtk_status_icon_set_visible (ta->tray_icon, TRUE);
 
282
      tray_applet_ui_set_visible (ta, TRUE);
292
283
      ta->name = "gtk-dialog-warning-panel";
293
 
      GdkPixbuf *src = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),
294
 
                                                ta->name, 48, 
295
 
                                                GTK_ICON_LOOKUP_GENERIC_FALLBACK, 
296
 
                                                NULL);
297
 
      gtk_status_icon_set_from_pixbuf(ta->tray_icon, src);
298
 
      g_object_unref(src);
299
 
      gtk_status_icon_set_tooltip_text(ta->tray_icon,
 
284
      tray_applet_ui_set_icon(ta, ta->name);
 
285
      tray_applet_ui_set_tooltip_text(ta,
300
286
                                  _("The update information is outdated. "
301
287
                                    "This may be caused by network "
302
288
                                    "problems or by a repository that "
638
624
          (time(NULL) - buf.st_mtime > OUTDATED_NAG_AGE) ) 
639
625
         g_timeout_add_seconds(OUTDATED_NAG_WAIT, (GSourceFunc)outdated_nag, ta);
640
626
 
641
 
      gtk_status_icon_set_visible (ta->tray_icon, FALSE);
642
 
#ifdef HAVE_APP_INDICATOR         
643
 
      app_indicator_set_status (ta->indicator, 
644
 
                                APP_INDICATOR_STATUS_PASSIVE);
645
 
#endif
 
627
      tray_applet_ui_set_visible (ta, FALSE);
646
628
      if(priv->active_notification != NULL) {
647
629
         notify_notification_close(priv->active_notification, NULL);
648
630
         priv->active_notification = NULL; 
654
636
      ta->name = "software-update-available";
655
637
   else
656
638
      ta->name = "software-update-urgent";
657
 
   gtk_status_icon_set_from_icon_name(ta->tray_icon, ta->name);
658
 
#ifdef HAVE_APP_INDICATOR
659
 
   app_indicator_set_icon (ta->indicator, ta->name);
660
 
#endif
 
639
   tray_applet_ui_set_icon(ta, ta->name);
661
640
 
662
641
   // update the tooltip
663
642
   update_trayicon_update_tooltip(ta, priv->num_upgrades);
666
645
   // the default action
667
646
   if(g_settings_get_boolean(priv->settings, SETTINGS_KEY_AUTO_LAUNCH))
668
647
   {
669
 
      gtk_status_icon_set_visible(ta->tray_icon, FALSE);
 
648
      tray_applet_ui_set_visible(ta, FALSE);
670
649
      if (auto_launch_now(priv)) 
671
650
      {
672
651
         g_spawn_command_line_async("nice ionice -c3 update-manager "
676
655
   }
677
656
 
678
657
   // if we are already visible, skip the rest
679
 
   if(gtk_status_icon_get_visible (ta->tray_icon))
 
658
   if(tray_applet_ui_get_visible (ta))
680
659
      return TRUE;
681
660
 
682
661
   // show the icon
683
 
   gtk_status_icon_set_visible(ta->tray_icon, TRUE);
684
 
#ifdef HAVE_APP_INDICATOR         
685
 
      app_indicator_set_status (ta->indicator, 
686
 
                                APP_INDICATOR_STATUS_ACTIVE);
687
 
#endif
 
662
   tray_applet_ui_set_visible(ta, TRUE);
688
663
   
689
664
   // the user does not no notification messages
690
665
   if(g_settings_get_boolean(priv->settings,
709
684
   priv->active_notification = NULL;
710
685
   ta->user_data = priv;
711
686
 
712
 
   // connect the signals we need
 
687
#ifndef HAVE_APP_INDICATOR
 
688
   // the default action for the gtk_status_icon
713
689
   g_signal_connect (G_OBJECT(ta->tray_icon),
714
690
                     "activate",
715
 
                     G_CALLBACK (activate_cb),
716
 
                     ta);
717
 
   g_signal_connect (G_OBJECT(ta->tray_icon),
718
 
                     "popup-menu",
719
 
                     G_CALLBACK (popup_cb),
720
 
                     ta);
 
691
                     G_CALLBACK (gtk_status_icon_click_activate_cb),
 
692
                     ta);
 
693
#endif
721
694
 
722
695
   /* Menu initialization */
723
696
   update_trayicon_create_menu (ta);
724
 
 
725
 
#ifdef HAVE_APP_INDICATOR
726
 
   app_indicator_set_menu(ta->indicator, GTK_MENU(ta->menu));
727
 
#endif
 
697
   tray_applet_ui_set_menu (ta, ta->menu);
728
698
   
729
699
   /* Check for updates for the first time */
730
700
   update_check (ta);