[Goodies-commits] r1988 - in notification-daemon-xfce/trunk: . settings src

Nick Schermer nick at xfce.org
Thu Sep 7 11:57:02 CEST 2006


Author: nick
Date: 2006-09-07 09:56:53 +0000 (Thu, 07 Sep 2006)
New Revision: 1988

Modified:
   notification-daemon-xfce/trunk/ChangeLog
   notification-daemon-xfce/trunk/configure.in.in
   notification-daemon-xfce/trunk/settings/Makefile.am
   notification-daemon-xfce/trunk/settings/main.c
   notification-daemon-xfce/trunk/src/daemon.c
   notification-daemon-xfce/trunk/src/daemon.h
   notification-daemon-xfce/trunk/src/engines.c
   notification-daemon-xfce/trunk/src/engines.h
   notification-daemon-xfce/trunk/src/notificationdaemon.xml
Log:
* Added new dbus method to reload the daemon settings.
* Removed hacky code from preview dialog, but trigger the
  ReloadSettings call instead.
* Improved the preview notification: only 1 preview is
  possible, but it moves when the position is changed.


Modified: notification-daemon-xfce/trunk/ChangeLog
===================================================================
--- notification-daemon-xfce/trunk/ChangeLog	2006-09-06 22:30:14 UTC (rev 1987)
+++ notification-daemon-xfce/trunk/ChangeLog	2006-09-07 09:56:53 UTC (rev 1988)
@@ -1,3 +1,11 @@
+2006-09-07 11:40 nick
+
+	* Added new dbus method to reload the daemon settings.
+	* Removed hacky code from preview dialog, but trigger the
+	  ReloadSettings call instead.
+	* Improved the preview notification: only 1 preview is
+	  possible, but it moves when the position is changed.
+
 2006-09-06 23:12 nick
 
 	* Add preview support to the settings dialog.

Modified: notification-daemon-xfce/trunk/configure.in.in
===================================================================
--- notification-daemon-xfce/trunk/configure.in.in	2006-09-06 22:30:14 UTC (rev 1987)
+++ notification-daemon-xfce/trunk/configure.in.in	2006-09-07 09:56:53 UTC (rev 1988)
@@ -59,7 +59,7 @@
                            [mcs-plugin], [xfce-mcs-manager], [yes])
 
 XDT_CHECK_OPTIONAL_PACKAGE([LIBNOTIFY], [libnotify], [0.4.0],
-                           [settings], [libnotify], [yes])
+                           [settings-preview], [libnotify], [yes])
 
 dnl check for debugging support
 XDT_FEATURE_DEBUG()

Modified: notification-daemon-xfce/trunk/settings/Makefile.am
===================================================================
--- notification-daemon-xfce/trunk/settings/Makefile.am	2006-09-06 22:30:14 UTC (rev 1987)
+++ notification-daemon-xfce/trunk/settings/Makefile.am	2006-09-07 09:56:53 UTC (rev 1988)
@@ -21,7 +21,9 @@
 notification_settings_CFLAGS =						\
 	$(GTK_CFLAGS)							\
 	$(LIBXFCE4UTIL_CFLAGS)						\
-	$(LIBXFCEGUI4_CFLAGS)
+	$(LIBXFCEGUI4_CFLAGS)						\
+	$(DBUS_CFLAGS)							\
+	$(DBUS_GLIB_CFLAGS)
 
 notification_settings_LDFLAGS =						\
 	-no-undefined
@@ -29,7 +31,9 @@
 notification_settings_LDADD =						\
 	$(GTK_LIBS)							\
 	$(LIBXFCE4UTIL_LIBS)						\
-	$(LIBXFCEGUI4_LIBS)
+	$(LIBXFCEGUI4_LIBS)						\
+	$(DBUS_LIBS)							\
+	$(DBUS_GLIB_LIBS)
 
 if HAVE_LIBNOTIFY
 notification_settings_CFLAGS +=						\

Modified: notification-daemon-xfce/trunk/settings/main.c
===================================================================
--- notification-daemon-xfce/trunk/settings/main.c	2006-09-06 22:30:14 UTC (rev 1987)
+++ notification-daemon-xfce/trunk/settings/main.c	2006-09-07 09:56:53 UTC (rev 1988)
@@ -36,16 +36,21 @@
 #include <libxfcegui4/libxfcegui4.h>
 #include <libxfce4util/libxfce4util.h>
 
+#define DBUS_API_SUBJECT_TO_CHANGE
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+
 #ifdef HAVE_LIBNOTIFY
 #include <libnotify/notify.h>
 #endif
 
-#define BORDER           6
-#define DEFAULT_POSITION "buttom_right"
-#define NOTIFY_RC_FILE   "xfce4/notify/notify.rc"
+#define BORDER                     6
+#define DEFAULT_POSITION           "buttom_right"
+#define NOTIFY_RC_FILE             "xfce4/notication-daemon-xfce/settingsrc"
+#define NOTIFY_DBUS_NAME           "org.freedesktop.Notifications"
+#define NOTIFY_DBUS_CORE_INTERFACE "org.freedesktop.Notifications"
+#define NOTIFY_DBUS_CORE_OBJECT    "/org/freedesktop/Notifications"
 
-
-
 typedef struct
 {
   const gchar *name;
@@ -61,61 +66,150 @@
   { N_("Top Right"),    "top_right"    },
   { N_("Bottom Left"),  "bottom_left"  },
   { N_("Bottom Right"), "bottom_right" },
-  {    NULL,            NULL           }
+  { NULL,               NULL           }
 };
 
 
 
-static void
-notification_settings_kill_daemon (void)
+static gboolean         notification_settings_init_daemon    (void);
+static void             notification_settings_reload_daemon  (void);
+#ifdef HAVE_LIBNOTIFY
+static void             notification_settings_preview_closed (GObject *object,
+                                                              gpointer user_data);
+static void             notification_settings_preview        (GtkWidget   *button);
+#endif
+static void             notification_settings_save_position  (GtkComboBox *combobox);
+static void             notification_settings_write_setting  (const gchar *key,
+                                                              const gchar *value);
+static gchar           *notification_settings_read_setting   (const gchar *key,
+                                                              const gchar *fallback);
+static GtkWidget       *notifications_settings_dialog_new    (void);
+
+
+
+/* globals */
+static DBusGProxy *proxy = NULL;
+#ifdef HAVE_LIBNOTIFY
+static NotifyNotification *preview = NULL;
+#endif
+
+
+static gboolean
+notification_settings_init_daemon (void)
 {
-  /* this is a real hack, but good enough for most users */
-  GError    *error = NULL;
-  gchar     *argv[] = { "/usr/bin/killall", "-q", "-s", "QUIT", "notification-daemon-xfce", NULL };
+  GError *error = NULL;
+  DBusGConnection *bus = NULL;
 
-  if (!g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, &error))
+  g_type_init ();
+
+  bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+  if (error != NULL)
     {
-      g_error_free (error);
+       g_message ("Unable to get session bus: %s", error->message);
+       g_error_free (error);
+       return FALSE;
     }
+
+  proxy = dbus_g_proxy_new_for_name (bus,
+                                     NOTIFY_DBUS_NAME,
+                                     NOTIFY_DBUS_CORE_OBJECT,
+                                     NOTIFY_DBUS_CORE_INTERFACE);
+  dbus_g_connection_unref (bus);
+
+  return TRUE;
 }
 
 
+
+static void
+notification_settings_reload_daemon (void)
+{
+  GError *error = NULL;
+
+  if (G_UNLIKELY (proxy == NULL))
+    return;
+
+  if (!dbus_g_proxy_call(proxy, "ReloadSettings", &error,
+                         G_TYPE_INVALID, G_TYPE_INVALID))
+  {
+     g_message("Unable to reload the daemon: %s", error->message);
+     g_error_free(error);
+     return;
+  }
+
 #ifdef HAVE_LIBNOTIFY
+  /* reset the preview notification position */
+  if (preview)
+    notify_notification_show (preview, NULL);
+#endif
+}
+
+
+#ifdef HAVE_LIBNOTIFY
 static void
+notification_settings_preview_closed (GObject *object,
+                                      gpointer data)
+{
+  GtkWidget *button;
+
+  g_return_if_fail (object == G_OBJECT (preview));
+
+  button = (GtkWidget *)data;
+
+  /* activate preview button */
+  gtk_widget_set_sensitive (button, TRUE);
+
+  g_object_unref (object);
+  preview = NULL;
+}
+
+
+
+static void
 notification_settings_preview (GtkWidget *button)
 {
-  NotifyNotification *notify;
+  /* return if the notification is already visible */
+  if (preview != NULL)
+    return;
 
-  if (!notify_init("notify-send"))
+  if (!notify_init("notification-settings"))
   {
      g_warning ("Unable to init the notification library");
      return;
   }
 
-  notify = notify_notification_new ("Preview notification",
-                                    _("Lorem Ipsum is simply dummy text of the printing and typesetting industry."),
-                                    "notification-settings",
-                                    NULL);
-  notify_notification_set_urgency (notify, NOTIFY_URGENCY_NORMAL);
-  notify_notification_set_timeout (notify, 5000);
-  notify_notification_show (notify, NULL);
-  g_object_unref (G_OBJECT(notify));
+  /* disable preview button */
+  gtk_widget_set_sensitive (button, FALSE);
+
+  /* create new preview notification */
+  preview = notify_notification_new (_("Preview notification"),
+                                     _("Lorem Ipsum is simply dummy text of the printing "
+                                      "and typesetting industry."),
+                                      "notification-settings",
+                                      NULL);
+  notify_notification_set_urgency (preview, NOTIFY_URGENCY_NORMAL);
+  notify_notification_set_timeout (preview, 5000);
+
+  /* attach close signal */
+  g_signal_connect(G_OBJECT(preview), "closed",
+    G_CALLBACK(notification_settings_preview_closed), button);
+
+  /* show the notification */
+  notify_notification_show (preview, NULL);
   notify_uninit ();
 }
 #endif
 
 
+
 static void
 notification_settings_save_position (GtkComboBox *combobox)
 {
   const PopupLocation *l;
   gint                 i = 0, selected;
   gchar               *identifier;
-  gchar               *file;
-  XfceRc              *rc;
 
-  notification_settings_kill_daemon ();
-
   /* get active selected item */
   selected = gtk_combo_box_get_active (combobox);
 
@@ -136,58 +230,72 @@
     identifier = g_strdup (DEFAULT_POSITION);
 
   /* save identifier */
+  notification_settings_write_setting ("popup_location", identifier);
+
+  /* cleanup */
+  g_free (identifier);
+
+  /* reload daemon */
+  notification_settings_reload_daemon ();
+}
+
+
+
+static void
+notification_settings_write_setting (const gchar *key,
+                                     const gchar *value)
+{
+  gchar  *file;
+  XfceRc *rc;
+
   file = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, NOTIFY_RC_FILE, TRUE);
   if (G_LIKELY (file))
     {
+       /* open rc file, writable */
        rc = xfce_rc_simple_open (file, FALSE);
        g_free (file);
 
        if (G_LIKELY (rc))
          {
-            xfce_rc_write_entry (rc, "popup_location", identifier);
-
+            xfce_rc_write_entry (rc, key, value);
             xfce_rc_close (rc);
          }
     }
-
-    /* cleanup */
-    g_free (identifier);
 }
 
 
 
 static gchar *
-notification_settings_get_position (void)
+notification_settings_read_setting (const gchar *key,
+                                    const gchar *fallback)
 {
-  gchar       *file;
-  XfceRc      *rc;
-  const gchar *value;
-  gchar       *position = NULL;
+  gchar  *file;
+  XfceRc *rc;
+  gchar  *value = NULL;
 
   file = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, NOTIFY_RC_FILE, TRUE);
   if (G_LIKELY (file))
     {
+       /* open rc file, read-only */
        rc = xfce_rc_simple_open (file, TRUE);
        g_free (file);
 
        if (G_LIKELY (rc))
          {
-            value = xfce_rc_read_entry (rc, "popup_location", NULL);
+            value = g_strdup (xfce_rc_read_entry (rc, key, fallback));
 
-            if (G_LIKELY (value))
-              position = g_strdup (value);
-
             xfce_rc_close (rc);
          }
     }
 
-  if (G_UNLIKELY (position == NULL))
-    position = g_strdup (DEFAULT_POSITION);
+  if (G_UNLIKELY (value == NULL))
+    value = g_strdup (fallback);
 
-  return position;
+  return value;
 }
 
 
+
 static GtkWidget *
 notifications_settings_dialog_new (void)
 {
@@ -206,23 +314,7 @@
   gtk_window_set_icon_name (GTK_WINDOW (dialog), "notification-settings");
 
   dialog_vbox = GTK_DIALOG (dialog)->vbox;
-/*
-  hbox = gtk_hbox_new (FALSE, BORDER);
-  gtk_widget_show (hbox);
-  gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, FALSE, FALSE, 0);;
-  gtk_container_set_border_width (GTK_CONTAINER (hbox), BORDER);
 
-  image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_LARGE_TOOLBAR);
-  gtk_misc_set_alignment (GTK_MISC (image), 0, 0.5);
-  gtk_widget_show (image);
-  gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
-
-  label = gtk_label_new (_("To change the notification daemon settings, "
-                           "you need to restart the daemon."));
-  gtk_widget_show (label);
-  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
-  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
-*/
   hbox = gtk_hbox_new (FALSE, BORDER);
   gtk_widget_show (hbox);
   gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, FALSE, FALSE, 0);;
@@ -235,9 +327,10 @@
   combobox = gtk_combo_box_new_text ();
   gtk_widget_show (combobox);
   gtk_box_pack_start (GTK_BOX (hbox), combobox, TRUE, TRUE, 0);
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), combobox);
 
-  active = notification_settings_get_position ();
-
+  /* append all position values */
+  active = notification_settings_read_setting ("popup_location", DEFAULT_POSITION);
   for (l = popup_locations; l->name != NULL; l++)
     {
        gtk_combo_box_append_text (GTK_COMBO_BOX (combobox), l->name);
@@ -247,14 +340,11 @@
 
        i++;
     }
+  g_free (active);
 
   g_signal_connect(G_OBJECT(combobox), "changed",
     G_CALLBACK(notification_settings_save_position), NULL);
 
-  g_free (active);
-
-  gtk_label_set_mnemonic_widget (GTK_LABEL (label), combobox);
-
   /* preview button */
 #ifdef HAVE_LIBNOTIFY
   hbox = GTK_DIALOG (dialog)->action_area;
@@ -294,6 +384,9 @@
 
   gtk_init (&argc, &argv);
 
+  /* init the connection with notification-daemon-xfce */
+  notification_settings_init_daemon ();
+
   /* default icon name */
   gtk_window_set_default_icon_name ("notification-settings");
 
@@ -304,5 +397,18 @@
   /* close dialog */
   gtk_widget_destroy (dialog);
 
+#ifdef HAVE_LIBNOTIFY
+  /* close the preview notification */
+  if (preview)
+    {
+       /* the close signal is not triggered, so also unref */
+       notify_notification_close (preview, NULL);
+       g_object_unref (G_OBJECT (preview));
+    }
+#endif
+
+  /* unref proxy */
+  g_object_unref (G_OBJECT (proxy));
+
   return 0;
 }

Modified: notification-daemon-xfce/trunk/src/daemon.c
===================================================================
--- notification-daemon-xfce/trunk/src/daemon.c	2006-09-06 22:30:14 UTC (rev 1987)
+++ notification-daemon-xfce/trunk/src/daemon.c	2006-09-07 09:56:53 UTC (rev 1988)
@@ -140,6 +140,37 @@
 	g_free(nt);
 }
 
+gchar *
+xfce_load_setting (const gchar *key,
+                   const gchar *fallback)
+{
+	gchar       *file;
+	const gchar *tmp;
+	gchar       *value = NULL;
+	XfceRc      *rc;
+
+	file = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, NOTIFY_RC_FILE, TRUE);
+	if (G_LIKELY (file))
+	{
+		rc = xfce_rc_simple_open (file, FALSE);
+		g_free (file);
+
+		if (G_LIKELY (rc))
+		{
+			tmp = xfce_rc_read_entry (rc, key, NULL);
+
+			if (G_LIKELY (tmp))
+				value = g_strdup (tmp);
+			else
+				xfce_rc_write_entry (rc, key, fallback);
+
+			xfce_rc_close (rc);
+		}
+	}
+
+	return value;
+}
+
 static void
 notify_daemon_init(NotifyDaemon *daemon)
 {
@@ -147,9 +178,6 @@
 	GdkDisplay *display;
 	GdkScreen *screen;
 	gchar *slocation = NULL;
-	gchar *file;
-	XfceRc *rc;
-	const gchar *value;
 	gint i;
 
 	daemon->priv = G_TYPE_INSTANCE_GET_PRIVATE(daemon, NOTIFY_TYPE_DAEMON,
@@ -158,26 +186,8 @@
 	daemon->priv->next_id = 1;
 	daemon->priv->timeout_source = 0;
 
-	/* load popup location from rc file */
-	file = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, NOTIFY_RC_FILE, TRUE);
-	if (file)
-	{
-		rc = xfce_rc_simple_open (file, FALSE);
-		g_free (file);
+	slocation = xfce_load_setting ("popup_location", "bottom_right");
 
-		if (rc)
-		{
-			value = xfce_rc_read_entry (rc, "popup_location", NULL);
-
-			if (value)
-				slocation = g_strdup (value);
-			else
-				xfce_rc_write_entry (rc, "popup_location", "bottom_right");
-
-			xfce_rc_close (rc);
-		}
-	}
-
 	location = get_stack_location_from_string(slocation);
 	g_free(slocation);
 
@@ -674,8 +684,27 @@
 	_close_notification(daemon, NW_GET_NOTIFY_ID(nw), TRUE);
 }
 
+static void
+popup_location_changed_cb(NotifyDaemon *daemon)
+{
+	NotifyStackLocation stack_location;
+	gchar *slocation;
+	gint i;
 
+	if (daemon == NULL)
+		return;
 
+	slocation = xfce_load_setting ("popup_location", "bottom_right");
+
+	g_message ("location: %s", slocation);
+
+	stack_location = get_stack_location_from_string(slocation);
+	g_free (slocation);
+
+	for (i = 0; i < daemon->priv->stacks_size; i++)
+		notify_stack_set_location(daemon->priv->stacks[i], stack_location);
+}
+
 static void
 url_clicked_cb(GtkWindow *nw, const char *url)
 {
@@ -1025,6 +1054,18 @@
 }
 
 gboolean
+notify_daemon_reload_settings (NotifyDaemon *daemon)
+{
+	/* reset the theme engine (not needed with only 1 theme) */
+	/*theme_changed_cb ();*/
+
+	/* new location */
+	popup_location_changed_cb (daemon);
+
+	return TRUE;
+}
+
+gboolean
 notify_daemon_get_server_information(NotifyDaemon *daemon,
 									 char **out_name,
 									 char **out_vendor,

Modified: notification-daemon-xfce/trunk/src/daemon.h
===================================================================
--- notification-daemon-xfce/trunk/src/daemon.h	2006-09-06 22:30:14 UTC (rev 1987)
+++ notification-daemon-xfce/trunk/src/daemon.h	2006-09-07 09:56:53 UTC (rev 1988)
@@ -28,7 +28,7 @@
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
-#define NOTIFY_RC_FILE "xfce4/notify/notify.rc"
+#define NOTIFY_RC_FILE "xfce4/notication-daemon-xfce/settingsrc"
 
 #define NOTIFY_TYPE_DAEMON (notify_daemon_get_type())
 #define NOTIFY_DAEMON(obj) \
@@ -90,12 +90,17 @@
 gboolean notify_daemon_get_capabilities(NotifyDaemon *daemon,
 										char ***out_caps);
 
+gboolean notify_daemon_reload_settings (NotifyDaemon *daemon);
+
 gboolean notify_daemon_get_server_information(NotifyDaemon *daemon,
 											  char **out_name,
 											  char **out_vendor,
 											  char **out_version,
 											  char **out_spec_ver);
 
+gchar *xfce_load_setting (const gchar *key,
+                          const gchar *fallback);
+
 G_END_DECLS
 
 #endif /* NOTIFY_DAEMON_H */

Modified: notification-daemon-xfce/trunk/src/engines.c
===================================================================
--- notification-daemon-xfce/trunk/src/engines.c	2006-09-06 22:30:14 UTC (rev 1987)
+++ notification-daemon-xfce/trunk/src/engines.c	2006-09-07 09:56:53 UTC (rev 1988)
@@ -135,36 +135,30 @@
 	g_free(engine);
 }
 
-static ThemeEngine *
-get_theme_engine(void)
+void
+theme_changed_cb(void)
 {
 	if (active_engine == NULL)
-	{
-		gchar *enginename = NULL;
-		const gchar *value;
-		gchar *file;
-		XfceRc *rc;
+		return;
 
-		/* load the theme from the rc file */
-		file = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, NOTIFY_RC_FILE, TRUE);
-		if (file)
-		{
-			rc = xfce_rc_simple_open (file, FALSE);
-			g_free (file);
+	active_engine->ref_count--;
 
-			if (rc)
-			{
-				value = xfce_rc_read_entry (rc, "engine_name", NULL);
+	if (active_engine->ref_count == 0)
+		destroy_engine(active_engine);
 
-				if (value)
-					enginename = g_strdup (value);
-				else
-					xfce_rc_write_entry (rc, "engine_name", "standard");
+	/* This is no longer the true active engine, so reset this. */
+	active_engine = NULL;
+}
 
-				xfce_rc_close (rc);
-			}
-		}
+static ThemeEngine *
+get_theme_engine(void)
+{
+	if (active_engine == NULL)
+	{
+		gchar *enginename;
 
+		enginename = xfce_load_setting ("engine_name", "standard");
+
 		if (enginename == NULL)
 		{
 			active_engine = load_theme_engine("standard");

Modified: notification-daemon-xfce/trunk/src/engines.h
===================================================================
--- notification-daemon-xfce/trunk/src/engines.h	2006-09-06 22:30:14 UTC (rev 1987)
+++ notification-daemon-xfce/trunk/src/engines.h	2006-09-07 09:56:53 UTC (rev 1988)
@@ -42,5 +42,6 @@
 								   const char *key, GCallback cb);
 void theme_clear_notification_actions(GtkWindow *nw);
 void theme_move_notification(GtkWindow *nw, int x, int y);
+void theme_changed_cb(void);
 
 #endif /* _ENGINES_H_ */

Modified: notification-daemon-xfce/trunk/src/notificationdaemon.xml
===================================================================
--- notification-daemon-xfce/trunk/src/notificationdaemon.xml	2006-09-06 22:30:14 UTC (rev 1987)
+++ notification-daemon-xfce/trunk/src/notificationdaemon.xml	2006-09-07 09:56:53 UTC (rev 1988)
@@ -28,6 +28,10 @@
       <arg type="as" name="return_caps" direction="out"/>
     </method>
 
+    <method name="ReloadSettings">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="notify_daemon_reload_settings"/>
+    </method>
+
     <method name="GetServerInformation">
       <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="notify_daemon_get_server_information"/>
       <arg type="s" name="return_name" direction="out"/>




More information about the Goodies-commits mailing list