[Goodies-commits] r3406 - in xfce4-smartpm-plugin/trunk: . src

Anders F Bjorklund afb at xfce.org
Sat Oct 20 10:44:48 CEST 2007


Author: afb
Date: 2007-10-20 08:44:48 +0000 (Sat, 20 Oct 2007)
New Revision: 3406

Modified:
   xfce4-smartpm-plugin/trunk/ChangeLog
   xfce4-smartpm-plugin/trunk/TODO
   xfce4-smartpm-plugin/trunk/configure.in.in
   xfce4-smartpm-plugin/trunk/src/Makefile.am
   xfce4-smartpm-plugin/trunk/src/xfcesmart.c
   xfce4-smartpm-plugin/trunk/src/xfcesmart.h
Log:
notification support

Modified: xfce4-smartpm-plugin/trunk/ChangeLog
===================================================================
--- xfce4-smartpm-plugin/trunk/ChangeLog	2007-10-20 08:39:57 UTC (rev 3405)
+++ xfce4-smartpm-plugin/trunk/ChangeLog	2007-10-20 08:44:48 UTC (rev 3406)
@@ -77,3 +77,7 @@
 	* Move RPM Specfile to a "redhat" subdirectory instead
 	* Add support for slapt-get and gslapt, for Vector Linux
 
+2007-10-10	Anders F Bjorklund <afb at users.sourceforge.net>
+
+	* Add optional libnotify support, for pop-up dialogs
+

Modified: xfce4-smartpm-plugin/trunk/TODO
===================================================================
--- xfce4-smartpm-plugin/trunk/TODO	2007-10-20 08:39:57 UTC (rev 3405)
+++ xfce4-smartpm-plugin/trunk/TODO	2007-10-20 08:44:48 UTC (rev 3406)
@@ -1,6 +1,4 @@
 * Support for multiple channels (for instance only "security" upgrades)
 
-* Show annoying pop-up dialogs when new updates arrive from channels
-
 * Rewrite external Xfce plugin (program) as internal, to save memory
 

Modified: xfce4-smartpm-plugin/trunk/configure.in.in
===================================================================
--- xfce4-smartpm-plugin/trunk/configure.in.in	2007-10-20 08:39:57 UTC (rev 3405)
+++ xfce4-smartpm-plugin/trunk/configure.in.in	2007-10-20 08:44:48 UTC (rev 3406)
@@ -113,6 +113,11 @@
 XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-1.0], [4.3.99.2])
 
 dnl ***********************************
+dnl *** Check for optional packages ***
+dnl ***********************************
+XDT_CHECK_OPTIONAL_PACKAGE([LIBNOTIFY], [libnotify], [0.4.0], [libnotify], [libnotify], "no")
+
+dnl ***********************************
 dnl *** Check for debugging support ***
 dnl ***********************************
 XDT_FEATURE_DEBUG()

Modified: xfce4-smartpm-plugin/trunk/src/Makefile.am
===================================================================
--- xfce4-smartpm-plugin/trunk/src/Makefile.am	2007-10-20 08:39:57 UTC (rev 3405)
+++ xfce4-smartpm-plugin/trunk/src/Makefile.am	2007-10-20 08:44:48 UTC (rev 3406)
@@ -21,12 +21,14 @@
 	$(LIBXFCE4UTIL_CFLAGS)						\
 	$(LIBXFCEGUI4_CFLAGS)						\
 	$(LIBXFCE4PANEL_CFLAGS)						\
+	$(LIBNOTIFY_CFLAGS)						\
 	$(PLATFORM_CFLAGS)
 
 xfce4_smartpm_plugin_LDFLAGS =						\
 	$(LIBXFCE4UTIL_LIBS)						\
 	$(LIBXFCEGUI4_LIBS)						\
 	$(LIBXFCE4PANEL_LIBS)						\
+	$(LIBNOTIFY_LIBS)						\
 	$(PLATFORM_LDFLAGS)
 
 #

Modified: xfce4-smartpm-plugin/trunk/src/xfcesmart.c
===================================================================
--- xfce4-smartpm-plugin/trunk/src/xfcesmart.c	2007-10-20 08:39:57 UTC (rev 3405)
+++ xfce4-smartpm-plugin/trunk/src/xfcesmart.c	2007-10-20 08:44:48 UTC (rev 3406)
@@ -38,6 +38,10 @@
 #include <libxfce4util/libxfce4util.h>
 #include <libxfce4panel/xfce-panel-plugin.h>
 
+#ifdef HAVE_LIBNOTIFY
+#include <libnotify/notify.h>
+#endif
+
 #ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
 #else
@@ -102,6 +106,9 @@
 smart_set_manager(SmartPlugin *smart, gint manager);
 
 static void
+smart_show_notification(SmartPlugin *smart, gchar *summary, gchar *message);
+
+static void
 smart_sudo_smart_gui(SmartPlugin *smart, gchar *args);
 
 static void
@@ -152,6 +159,8 @@
     gchar *s = g_strdup_printf((packages==1)?_("%d upgrade available"):
                                _("%d upgrades available"), packages);
     gtk_tooltips_set_tip(smart->tooltip, smart->button, s, NULL);
+    if (packages != smart->updates_available)
+      smart_show_notification(smart, _("Package Upgrades"), s);
     g_free(s);
     if (smart->show_application)
       smart_set_icon(smart, smart->application_icon, smart->available_icon);
@@ -244,6 +253,8 @@
       s = g_strdup(_("Channels updated"));
 
     gtk_tooltips_set_tip(smart->tooltip, smart->button, s, NULL);
+    if (packages != 0)
+      smart_show_notification(smart, _("Package Updates"), s);
     g_free(s);
   }
   else
@@ -740,7 +751,79 @@
      smart_sudo_smart_gui(smart, NULL);
 }
 
+#ifdef HAVE_LIBNOTIFY
+static void
+smart_notify_callback(NotifyNotification *n, gchar *action, gpointer user_data)
+{
+  SmartPlugin *smart = user_data;
+  GError *error = NULL;
+
+  if (strcmp(action,"upgrade") == 0)
+    smart_launch_program(smart);
+
+  if (n != NULL)
+    notify_notification_close(n, &error);
+}
+#endif
+
 void
+smart_show_notification(SmartPlugin *smart, gchar *summary, gchar *message)
+{
+#ifdef HAVE_LIBNOTIFY
+  NotifyNotification *n;
+  GError *error = NULL;
+  XfceScreenPosition position;
+  GtkRequisition size;
+  int x,y;
+  
+  if (smart->show_notifications)
+  {
+    gdk_window_get_origin (GTK_WIDGET (smart->plugin)->window, &x, &y);
+    gtk_widget_size_request (GTK_WIDGET (smart->plugin), &size);
+ 
+    x = x + size.width/2;
+    y = y + size.height/2;
+
+    position = xfce_panel_plugin_get_screen_position (smart->plugin);
+
+    if (xfce_screen_position_is_horizontal(position))
+    {
+      if (xfce_screen_position_is_top(position)) y += size.height/2;
+      if (xfce_screen_position_is_bottom(position)) y -= size.height/2;
+    }
+    else /* xfce_screen_position_is_vertical */
+    {
+      if (xfce_screen_position_is_left(position)) x += size.width/2;
+      if (xfce_screen_position_is_right(position)) x -= size.width/2;
+    }
+
+    n = notify_notification_new (summary, message, NULL, NULL);
+    
+    notify_notification_add_action (n,
+      "default", "default",
+      smart_notify_callback, smart, NULL);
+    notify_notification_add_action (n,
+      "upgrade", _("Upgrade Now"),
+      smart_notify_callback, smart, NULL);
+
+    notify_notification_set_hint_int32 (n, "x", x);
+    notify_notification_set_hint_int32 (n, "y", y);
+
+    notify_notification_set_icon_from_pixbuf (n, smart->application_icon);
+    notify_notification_set_timeout (n, NOTIFY_EXPIRES_DEFAULT);
+    
+    if (!notify_notification_show (n, &error))
+    {
+      /*xfce_message_dialog(NULL, _("Notify Failed"), GTK_STOCK_DIALOG_ERROR,
+                          _("Failed to show notification"), error->message,
+                          GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);*/
+      g_error_free(error);
+    }
+  }
+#endif
+}
+
+void
 smart_save (XfcePanelPlugin *plugin,
              SmartPlugin    *smart)
 {
@@ -768,6 +851,7 @@
       xfce_rc_write_bool_entry (rc, "dist-upgrade", smart->dist_upgrade);
       xfce_rc_write_int_entry (rc, "manager", smart->package_manager);
       xfce_rc_write_bool_entry (rc, "appicon", smart->show_application);
+      xfce_rc_write_bool_entry (rc, "notify", smart->show_notifications);
 
       /* close the rc file */
       xfce_rc_close (rc);
@@ -801,6 +885,7 @@
           smart->dist_upgrade =  xfce_rc_read_bool_entry (rc, "dist-upgrade", TRUE);
           smart->package_manager = xfce_rc_read_int_entry (rc, "manager", PACKAGE_MANAGER_SMART);
           smart->show_application =  xfce_rc_read_bool_entry (rc, "appicon", TRUE);
+          smart->show_notifications =  xfce_rc_read_bool_entry (rc, "notify", FALSE);
 
           /* cleanup */
           xfce_rc_close (rc);
@@ -818,6 +903,7 @@
   smart->dist_upgrade = TRUE;
   smart->package_manager = PACKAGE_MANAGER_SMART;
   smart->show_application = TRUE;
+  smart->show_notifications = FALSE;
 }
 
 
@@ -946,7 +1032,7 @@
 {
   SmartPlugin *smart = user_data;
 
-  smart->upgrade_directly = gtk_toggle_button_get_active(button);
+  smart->show_notifications = gtk_toggle_button_get_active(button);
 }
 
 static void
@@ -955,6 +1041,15 @@
 {
   SmartPlugin *smart = user_data;
 
+  smart->upgrade_directly = gtk_toggle_button_get_active(button);
+}
+
+static void
+smart_checkbox4_toggle_cb(GtkToggleButton *button,
+        gpointer user_data)
+{
+  SmartPlugin *smart = user_data;
+
   smart->dist_upgrade = gtk_toggle_button_get_active(button);
 }
 
@@ -1021,6 +1116,10 @@
 
   gtk_widget_destroy(dummy);
 
+#ifdef HAVE_LIBNOTIFY
+  notify_init("xfce4-smartpm-plugin");
+#endif
+
   /* set default icon and check */
   smart_size_changed (smart->plugin, smart->current_icon_size, smart);
   smart_set_available(smart, smart->updates_available);
@@ -1042,6 +1141,10 @@
   if (G_UNLIKELY (dialog != NULL))
     gtk_widget_destroy (dialog);
 
+#ifdef HAVE_LIBNOTIFY
+  notify_uninit();
+#endif
+
   /* destroy the panel widgets */
   gtk_widget_destroy (smart->button);
   gtk_widget_destroy (smart->menuitem);
@@ -1370,16 +1473,25 @@
   gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0);
   gtk_box_pack_start(GTK_BOX(vbox),hbox,TRUE,TRUE,0);
 
+  button = gtk_check_button_new_with_label(_("Show notifications for updates and upgrades"));
+  gtk_widget_show (button);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button), smart->show_notifications);
+  g_signal_connect (G_OBJECT(button),"toggled", G_CALLBACK(smart_checkbox2_toggle_cb), smart);
+  gtk_box_pack_start (GTK_BOX(vbox),button,TRUE,TRUE,0);
+#ifndef HAVE_LIBNOTIFY
+  gtk_widget_set_sensitive (button, FALSE);
+#endif
+  
   button = gtk_check_button_new_with_label(_("Upgrade on launch (if upgrades available)"));
   gtk_widget_show (button);
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button), smart->upgrade_directly);
-  g_signal_connect (G_OBJECT(button),"toggled", G_CALLBACK(smart_checkbox2_toggle_cb), smart);
+  g_signal_connect (G_OBJECT(button),"toggled", G_CALLBACK(smart_checkbox3_toggle_cb), smart);
   gtk_box_pack_start (GTK_BOX(vbox),button,TRUE,TRUE,0);
 
   button = gtk_check_button_new_with_label(_("Smart upgrade to newer release (dist-upgrade)"));
   gtk_widget_show (button);
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button), smart->dist_upgrade);
-  g_signal_connect (G_OBJECT(button),"toggled", G_CALLBACK(smart_checkbox3_toggle_cb), smart);
+  g_signal_connect (G_OBJECT(button),"toggled", G_CALLBACK(smart_checkbox4_toggle_cb), smart);
   gtk_box_pack_start (GTK_BOX(vbox),button,TRUE,TRUE,0);
 
   g_object_set_data (G_OBJECT (plugin), "dist-upgrade", button);

Modified: xfce4-smartpm-plugin/trunk/src/xfcesmart.h
===================================================================
--- xfce4-smartpm-plugin/trunk/src/xfcesmart.h	2007-10-20 08:39:57 UTC (rev 3405)
+++ xfce4-smartpm-plugin/trunk/src/xfcesmart.h	2007-10-20 08:44:48 UTC (rev 3406)
@@ -57,6 +57,7 @@
     gboolean dist_upgrade;
     gint package_manager;
     gboolean show_application;
+    gboolean show_notifications;
 }
 SmartPlugin;
 




More information about the Goodies-commits mailing list