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

« back to all changes in this revision

Viewing changes to src/update.c

  • Committer: mvo
  • Date: 2005-09-11 07:15:43 UTC
  • Revision ID: gustavo@niemeyer.net-20050911071543-022d65c46ec8e13b
* src/update.c:
  - make the timeout for the notification stuff 5s
* src/hooks.c:
  - add DontShowAfterReboot key
* src/hook-remove.c:
  - added a possible future hook-remove application that is save
    to be run as root

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
}
92
92
 
93
93
void 
94
 
cb_toggled_show_notifications(GObject *self, void *data)
 
94
cb_toggled_show_notifications(GObject *self, void *user_data)
95
95
{
96
 
      TrayApplet *ta = (TrayApplet*)data;
97
96
      GConfClient *gconf = gconf_client_get_default();
98
97
      gboolean b = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(self));
99
98
      gconf_client_set_bool(gconf, GCONF_KEY_NO_UPDATE_NOTIFICATIONS, !b,NULL);
100
 
      NotifyNotification *n = (NotifyNotification*)g_object_get_data(G_OBJECT(ta->tray_icon),"notification");
101
 
      if(n != NULL) {
102
 
         notify_notification_close(n, NULL);
103
 
         g_object_set_data(G_OBJECT(ta->tray_icon), "notification", NULL);
104
 
      }
105
99
}
106
100
 
107
101
 
176
170
   return FALSE; 
177
171
}
178
172
 
 
173
/*
 
174
 * this function is called when the notification handle is clicked
 
175
 */
 
176
static 
 
177
void notify_callback(NotifyHandle *handle, guint32 uid, void *user_data)
 
178
{
 
179
   GMainLoop *loop = (GMainLoop*)user_data;
 
180
 
 
181
   if(uid == NOTIFICATION_SHOW_UPDATES) {
 
182
      invoke_with_gksu (actions[0][0], _(actions[0][1]));
 
183
   }
 
184
 
 
185
   notify_close(handle);
 
186
   g_main_loop_quit(loop);
 
187
}
 
188
 
179
189
// actually show the notification 
180
 
static gint 
 
190
gint 
181
191
show_notification(gpointer user_data)
182
192
{
183
193
   TrayApplet *ta = (TrayApplet *)user_data;
184
194
 
 
195
   // now show a notification handle 
 
196
   NotifyHandle *n;
 
197
   NotifyHints *hints;
 
198
 
185
199
   int x,y;
186
200
   gdk_window_get_origin(GTK_WIDGET(ta->tray_icon)->window, &x, &y);
187
201
 
189
203
   if(x <= 0 || y <= 0)
190
204
      return TRUE;
191
205
 
192
 
   // check if the update-icon is still visible (in the delay time a 
193
 
   // update may already have been performed)
194
 
   if(!GTK_WIDGET_VISIBLE(ta->tray_icon))
195
 
      return FALSE;
 
206
   //g_print("Placing notification at: %i %i", x, y);
 
207
   GtkRequisition size;
 
208
   gtk_widget_size_request(GTK_WIDGET(ta->tray_icon), &size);
 
209
   x = x + size.width/2;
 
210
   y = y + size.height;
196
211
 
197
 
   // now show a notification handle 
198
 
   NotifyNotification *n = notify_notification_new(_("New updates available"),
199
 
                                                   _("Click on the update icon"
200
 
                                                     " to see the available "
201
 
                                                     "Updates"),
202
 
                                                   GTK_STOCK_INFO, 
203
 
                                                   ta->tray_icon);
204
 
   notify_notification_set_timeout (n, 60*1000);
205
 
   notify_notification_show(n, NULL);
206
 
   // save the notification handle
207
 
   g_object_set_data(G_OBJECT(ta->tray_icon), "notification", n);
 
212
   GMainLoop *loop;
 
213
   loop = g_main_loop_new(NULL, FALSE);
 
214
     
 
215
   hints = notify_hints_new();
 
216
   notify_hints_set_int(hints, "x", x);
 
217
   notify_hints_set_int(hints, "y", y);
 
218
   
 
219
   n = notify_send_notification(NULL,  // replaces nothing
 
220
                                NULL,  // type
 
221
                                NOTIFY_URGENCY_NORMAL,
 
222
                                _("New updates available"), 
 
223
                                _("Click on the update icon the link "
 
224
                                  "to see the available Updates"),
 
225
                                NULL,  // no icon
 
226
                                TRUE,  // expires
 
227
                                60,    // expire timout (big!)
 
228
                                hints, // hints
 
229
                                loop,  // user data
 
230
                                3,    //  actions
 
231
                                NOTIFICATION_DEFAULT, 
 
232
                                "default", 
 
233
                                notify_callback,
 
234
                                NOTIFICATION_SHOW_UPDATES, 
 
235
                                _("Show Updates"), 
 
236
                                notify_callback,
 
237
                                NOTIFICATION_IGNORE, 
 
238
                                _("Tell me about this later"), 
 
239
                                notify_callback
 
240
                                );
 
241
   
208
242
 
209
243
   // remove this from the timeout now
210
244
   return FALSE;
232
266
         gtk_tooltips_set_tip(GTK_TOOLTIPS(ta->tooltip), 
233
267
                              GTK_WIDGET (ta->eventbox), 
234
268
                              _("A error occured, please run Package Manager "
235
 
                                "from the right-click menu or "
 
269
                                "from the righ-click menu or "
236
270
                                "apt-get on a terminal to see what is wrong"),
237
271
                              _("This usually means that your installed "
238
272
                                "packages have unmet dependencies"));
248
282
   
249
283
   if (num_upgrades == 0) {
250
284
      gtk_widget_hide(GTK_WIDGET(ta->tray_icon));
251
 
      NotifyNotification *n = (NotifyNotification*)g_object_get_data(G_OBJECT(ta->tray_icon),"notification");
252
 
      if(n != NULL) {
253
 
         notify_notification_close(n, NULL);
254
 
         g_object_set_data(G_OBJECT(ta->tray_icon), "notification", NULL);
255
 
      }
256
285
      return TRUE;
257
286
   } 
258
287