Author: nick Date: 2008-07-18 13:50:35 +0000 (Fri, 18 Jul 2008) New Revision: 27338
Modified: xfce4-settings/trunk/ChangeLog xfce4-settings/trunk/dialogs/mouse-settings/main.c xfce4-settings/trunk/xfce4-settings-helper/Makefile.am xfce4-settings/trunk/xfce4-settings-helper/pointers.c Log: * dialogs/mouse-settings/main.c, xfce4-settings-helper/pointers.c, xfce4-settings-helper/Makefile.am: Show a notification when a mouse device is added. Notifications has a button to open the settings dialog, which will select the new device (if possible). Modified: xfce4-settings/trunk/ChangeLog =================================================================== --- xfce4-settings/trunk/ChangeLog 2008-07-18 11:34:38 UTC (rev 27337) +++ xfce4-settings/trunk/ChangeLog 2008-07-18 13:50:35 UTC (rev 27338) @@ -1,5 +1,12 @@ 2008-07-18 Nick Schermer <[EMAIL PROTECTED]> + * dialogs/mouse-settings/main.c, xfce4-settings-helper/pointers.c, + xfce4-settings-helper/Makefile.am: Show a notification when a + mouse device is added. Notifications has a button to open + the settings dialog, which will select the new device (if possible). + +2008-07-18 Nick Schermer <[EMAIL PROTECTED]> + * dialogs/mouse-settings/main.c: Properly fix previous commit. Also make the code more readable. Modified: xfce4-settings/trunk/dialogs/mouse-settings/main.c =================================================================== --- xfce4-settings/trunk/dialogs/mouse-settings/main.c 2008-07-18 11:34:38 UTC (rev 27337) +++ xfce4-settings/trunk/dialogs/mouse-settings/main.c 2008-07-18 13:50:35 UTC (rev 27338) @@ -79,9 +79,11 @@ /* option entries */ static gboolean opt_version = FALSE; +static gchar *opt_device_name = NULL; static GOptionEntry option_entries[] = { - { "version", 'v', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &opt_version, N_("Version information"), NULL }, + { "version", 'v', 0, G_OPTION_ARG_NONE, &opt_version, N_("Version information"), NULL }, + { "device", 'd', 0, G_OPTION_ARG_STRING, &opt_device_name, N_("Active device in the dialog"), N_("[NAME..]") }, { NULL } }; @@ -788,7 +790,7 @@ GtkTreeIter iter; GtkListStore *store; GtkWidget *treeview; - GtkTreePath *path; + GtkTreePath *path = NULL; GtkTreeViewColumn *column; GtkCellRenderer *renderer; GtkTreeSelection *selection; @@ -868,6 +870,14 @@ COLUMN_DEVICE_XID, device_info->id, COLUMN_DEVICE_NBUTTONS, num_buttons, -1); + /* check if we should select this device */ + if (opt_device_name && strcmp (opt_device_name, device_info->name) == 0) + { + path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter); + g_free (opt_device_name); + opt_device_name = NULL; + } + /* cleanup */ g_free (device_name); g_free (display_name); @@ -884,11 +894,9 @@ { /* set the treeview model */ gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store)); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), COLUMN_DEVICE_XID, GTK_SORT_ASCENDING); #if GTK_CHECK_VERSION (2, 12, 0) gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (treeview), COLUMN_DEVICE_DISPLAY_NAME); #endif - g_object_unref (G_OBJECT (store)); /* icon renderer */ renderer = gtk_cell_renderer_pixbuf_new (); @@ -907,11 +915,19 @@ g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK (mouse_settings_device_selection_changed), gxml); } - /* select the first mouse in the tree */ - path = gtk_tree_path_new_first (); + /* select the mouse in the tree */ + if (G_LIKELY (path == NULL)) + path = gtk_tree_path_new_first (); gtk_tree_selection_select_path (selection, path); gtk_tree_path_free (path); + /* sort after selecting the path */ + if (G_LIKELY (create_store)) + { + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), COLUMN_DEVICE_XID, GTK_SORT_ASCENDING); + g_object_unref (G_OBJECT (store)); + } + /* unlock */ locked--; } @@ -1113,6 +1129,12 @@ if (G_LIKELY (pointers_channel && xsettings_channel)) { +#if HAVE_LIBNOTIFY + /* this is a property we use for notifications, make sure it's there so users van change it */ + if (!xfconf_channel_has_property (pointers_channel, "/ShowNotifications")) + xfconf_channel_set_bool (pointers_channel, "/ShowNotifications", TRUE); +#endif /* !HAVE_LIBNOTIFY */ + /* load the glade xml file */ gxml = glade_xml_new_from_buffer (mouse_dialog_glade, mouse_dialog_glade_length, NULL, NULL); if (G_LIKELY (gxml)) @@ -1258,5 +1280,8 @@ /* shutdown xfconf */ xfconf_shutdown (); + /* cleanup */ + g_free (opt_device_name); + return EXIT_SUCCESS; } Modified: xfce4-settings/trunk/xfce4-settings-helper/Makefile.am =================================================================== --- xfce4-settings/trunk/xfce4-settings-helper/Makefile.am 2008-07-18 11:34:38 UTC (rev 27337) +++ xfce4-settings/trunk/xfce4-settings-helper/Makefile.am 2008-07-18 13:50:35 UTC (rev 27338) @@ -3,6 +3,7 @@ INCLUDES = \ -I${top_srcdir} \ -DDATADIR=\"$(datadir)\" \ + -DBINDIR=\"$(bindir)\" \ -DSRCDIR=\"$(top_srcdir)\" \ -DLOCALEDIR=\"$(localedir)\" \ -DG_LOG_DOMAIN=\"xfce4-settings-helper\" \ Modified: xfce4-settings/trunk/xfce4-settings-helper/pointers.c =================================================================== --- xfce4-settings/trunk/xfce4-settings-helper/pointers.c 2008-07-18 11:34:38 UTC (rev 27337) +++ xfce4-settings/trunk/xfce4-settings-helper/pointers.c 2008-07-18 13:50:35 UTC (rev 27338) @@ -32,11 +32,15 @@ #include <gdk/gdk.h> #include <gdk/gdkx.h> #include <xfconf/xfconf.h> +#include <libxfce4util/libxfce4util.h> #ifdef HAVE_HAL #include <dbus/dbus.h> #include <dbus/dbus-glib-lowlevel.h> #include <hal/libhal.h> +#if HAVE_LIBNOTIFY +#include <libnotify/notify.h> +#endif /* !HAVE_LIBNOTIFY */ #endif /* !HAVE_HAL */ #include "pointers.h" @@ -72,6 +76,13 @@ const gchar *property_name, const GValue *value); #ifdef HAVE_HAL +#if HAVE_LIBNOTIFY +static void xfce_pointers_helper_notification_closed (NotifyNotification *notification, + XfcePointersHelper *helper); +static void xfce_pointers_helper_notification_clicked (NotifyNotification *notification, + gchar *action, + gpointer user_data); +#endif /* !HAVE_LIBNOTIFY */ static gboolean xfce_pointers_helper_device_added_timeout (gpointer user_data); static void xfce_pointers_helper_device_added_timeout_destroyed (gpointer user_data); static void xfce_pointers_helper_device_added (LibHalContext *context, @@ -90,17 +101,24 @@ GObject __parent__; /* xfconf channel */ - XfconfChannel *channel; + XfconfChannel *channel; #ifdef HAVE_HAL /* timeout for adding hal devices */ - guint timeout_id; + guint timeout_id; /* dbus connection */ - DBusConnection *connection; + DBusConnection *connection; /* hal context */ - LibHalContext *context; + LibHalContext *context; + + /* last plugged device name */ + gchar *last_device; + +#ifdef HAVE_LIBNOTIFY + NotifyNotification *notification; +#endif /* !HAVE_LIBNOTIFY */ #endif /* !HAVE_HAL */ }; @@ -133,6 +151,10 @@ helper->timeout_id = 0; helper->context = NULL; helper->connection = NULL; + helper->last_device = NULL; +#ifdef HAVE_LIBNOTIFY + helper->notification = NULL; +#endif /* !HAVE_LIBNOTIFY */ #endif /* !HAVE_HAL */ if (XQueryExtension (GDK_DISPLAY (), "XInputExtension", &dummy, &dummy, &dummy)) @@ -147,6 +169,11 @@ g_signal_connect (G_OBJECT (helper->channel), "property-changed", G_CALLBACK (xfce_pointers_helper_channel_property_changed), NULL); #ifdef HAVE_HAL +#ifdef HAVE_LIBNOTIFY + /* setup a connection with the notification daemon */ + if (!notify_init ("xfce4-settings-helper")) + g_critical ("Failed to connect to the notification daemon."); +#endif /* !HAVE_LIBNOTIFY */ /* initialize the dbus error variable */ dbus_error_init (&derror); @@ -222,6 +249,15 @@ /* release the dbus connection */ if (G_LIKELY (helper->connection)) dbus_connection_unref (helper->connection); + + /* cleanup last device name */ + g_free (helper->last_device); + +#ifdef HAVE_LIBNOTIFY + /* close an opened notification */ + if (G_UNLIKELY (helper->notification)) + notify_notification_close (helper->notification, NULL); +#endif /* !HAVE_LIBNOTIFY */ #endif /* !HAVE_HAL */ /* release the channel */ @@ -591,6 +627,49 @@ #ifdef HAVE_HAL +#if HAVE_LIBNOTIFY +static void +xfce_pointers_helper_notification_closed (NotifyNotification *notification, + XfcePointersHelper *helper) +{ + g_return_if_fail (helper->notification == notification); + + /* set to null */ + helper->notification = NULL; +} + + + +static void +xfce_pointers_helper_notification_clicked (NotifyNotification *notification, + gchar *action, + gpointer user_data) +{ + XfcePointersHelper *helper = XFCE_POINTERS_HELPER (user_data); + GError *error = NULL; + gchar *command; + const gchar *path = BINDIR G_DIR_SEPARATOR_S "xfce4-mouse-settings"; + + /* build a command */ + if (G_LIKELY (helper->last_device)) + command = g_strdup_printf ("%s -d '%s'", path, helper->last_device); + else + command = g_strdup (path); + + /* try to spwn the xfce4-mouse-setting dialog */ + if (!g_spawn_command_line_async (command, &error)) + { + g_critical ("Failed to spawn the mouse settings dialog: %s", error->message); + g_error_free (error); + } + + /* cleanup */ + g_free (command); +} +#endif /* !HAVE_LIBNOTIFY */ + + + static gboolean xfce_pointers_helper_device_added_timeout (gpointer user_data) { @@ -601,6 +680,36 @@ /* restore the devices */ xfce_pointers_helper_restore_devices (helper); +#if HAVE_LIBNOTIFY + /* show a notification */ + if (xfconf_channel_get_bool (helper->channel, "/ShowNotifications", TRUE) + && notify_is_initted ()) + { + if (helper->notification == NULL) + { + /* create a new notification */ + helper->notification = notify_notification_new (_("New Mouse Device"), _("A new mouse device has been plugged. Click the button " + "below to configure the new device."), "input-mouse", NULL); + g_signal_connect (G_OBJECT (helper->notification), "closed", G_CALLBACK (xfce_pointers_helper_notification_closed), helper); + notify_notification_add_action (helper->notification, "configure", _("Open Mouse Settings Dialog"), xfce_pointers_helper_notification_clicked, helper, NULL); + } + + /* show the notification for (another) 4 seconds */ + notify_notification_set_timeout (helper->notification, 4000); + + /* show the notification */ + if (!notify_notification_show (helper->notification, NULL)) + { + /* show warning with the notification information */ + g_warning ("Failed to show notification: %s", _("New Mouse Device")); + + /* failed to show the notification */ + notify_notification_close (helper->notification, NULL); + helper->notification = NULL; + } + } +#endif /* !HAVE_LIBNOTIFY */ + GDK_THREADS_LEAVE (); return FALSE; @@ -611,8 +720,10 @@ static void xfce_pointers_helper_device_added_timeout_destroyed (gpointer user_data) { + XfcePointersHelper *helper = XFCE_POINTERS_HELPER (user_data); + /* reset the timeout id */ - XFCE_POINTERS_HELPER (user_data)->timeout_id = 0; + helper->timeout_id = 0; } @@ -627,9 +738,13 @@ helper = libhal_ctx_get_user_data (context); /* check if an input device has been added and no timeout is running */ - if (libhal_device_query_capability (context, udi, "input", NULL) + if (libhal_device_query_capability (context, udi, "input.mouse", NULL) && helper->timeout_id == 0) { + /* set the device name */ + g_free (helper->last_device); + helper->last_device = libhal_device_get_property_string (context, udi, "info.product", NULL); + /* queue a new timeout */ helper->timeout_id = g_timeout_add_full (G_PRIORITY_LOW, 1000, xfce_pointers_helper_device_added_timeout, helper, xfce_pointers_helper_device_added_timeout_destroyed); _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits