[gnome-control-center] wacom: Call the OSD window for assigning the tablets' buttons



commit d83e0ff5c1b9aa6e9ee6d69932d01086b61c00d2
Author: Joaquim Rocha <jrocha redhat com>
Date:   Fri Jul 26 17:29:20 2013 +0200

    wacom: Call the OSD window for assigning the tablets' buttons
    
    It falls back to the listbox view in case the OSD cannot be shown.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=704798

 panels/wacom/cc-wacom-page.c  |   96 ++++++++++++++++++++++++++++++++++++++--
 panels/wacom/cc-wacom-panel.c |   49 +++++++++++++++++++++
 panels/wacom/cc-wacom-panel.h |    5 ++
 panels/wacom/test-wacom.c     |    8 +++
 4 files changed, 153 insertions(+), 5 deletions(-)
---
diff --git a/panels/wacom/cc-wacom-page.c b/panels/wacom/cc-wacom-page.c
index fae653f..2452bdc 100644
--- a/panels/wacom/cc-wacom-page.c
+++ b/panels/wacom/cc-wacom-page.c
@@ -77,6 +77,8 @@ struct _CcWacomPagePrivate
        /* Display mapping */
        GtkWidget      *mapping;
        GtkWidget      *dialog;
+
+       GCancellable   *cancellable;
 };
 
 /* Button combo box storage columns */
@@ -375,13 +377,12 @@ button_mapping_dialog_closed (GtkDialog   *dialog,
 }
 
 static void
-map_buttons_button_clicked_cb (GtkButton   *button,
-                              CcWacomPage *page)
+show_button_mapping_dialog (CcWacomPage *page)
 {
-       GError *error = NULL;
-       GtkWidget *dialog;
+       GtkWidget          *toplevel;
+       GError             *error = NULL;
+       GtkWidget          *dialog;
        CcWacomPagePrivate *priv;
-       GtkWidget *toplevel;
 
        priv = page->priv;
 
@@ -415,6 +416,84 @@ map_buttons_button_clicked_cb (GtkButton   *button,
 }
 
 static void
+set_osd_visibility_cb (GObject      *source_object,
+                      GAsyncResult *res,
+                      gpointer      data)
+{
+       GError      *error = NULL;
+       GVariant    *result;
+       CcWacomPage *page;
+
+       page = CC_WACOM_PAGE (data);
+
+       result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
+
+       if (result == NULL) {
+               if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+                       g_printerr ("Error setting OSD's visibility: %s\n", error->message);
+                       g_error_free (error);
+                       show_button_mapping_dialog (page);
+               } else {
+                       g_error_free (error);
+                       return;
+               }
+       }
+}
+
+static void
+set_osd_visibility (CcWacomPage *page,
+                   guint32      device_id)
+{
+       CcWacomPagePrivate *priv;
+       GDBusProxy         *proxy;
+
+       priv = page->priv;
+       proxy = cc_wacom_panel_get_gsd_wacom_bus_proxy (priv->panel);
+
+       if (proxy == NULL) {
+               show_button_mapping_dialog (page);
+               return;
+       }
+
+       g_dbus_proxy_call (proxy,
+                          "SetOSDVisibility",
+                          g_variant_new ("(ubb)", device_id, TRUE, TRUE),
+                          G_DBUS_CALL_FLAGS_NONE,
+                          -1,
+                          priv->cancellable,
+                          set_osd_visibility_cb,
+                          page);
+}
+
+static void
+map_buttons_button_clicked_cb (GtkButton   *button,
+                              CcWacomPage *page)
+{
+       CcWacomPagePrivate *priv;
+       GdkDevice *gdk_device = NULL;
+       guint32 device_id;
+        const gchar *layout_path;
+
+       priv = page->priv;
+
+       g_object_get (priv->pad, "gdk-device", &gdk_device, NULL);
+
+       g_return_if_fail (gdk_device != NULL);
+
+       g_object_get (gdk_device, "device-id", &device_id, NULL);
+
+       /* Check if the OSD should be shown instead of the button mapping dialod */
+        layout_path = gsd_wacom_device_get_layout_path (page->priv->pad);
+        if (layout_path && g_file_test (layout_path, G_FILE_TEST_EXISTS)) {
+               set_osd_visibility (page, device_id);
+               return;
+       }
+
+       g_message ("Couldn't find a layout for '%s'. Launching the button mapping dialog.", 
gsd_wacom_device_get_name (priv->pad));
+       show_button_mapping_dialog (page);
+}
+
+static void
 display_mapping_dialog_closed (GtkDialog   *dialog,
                               int          response_id,
                               CcWacomPage *page)
@@ -597,6 +676,11 @@ cc_wacom_page_dispose (GObject *object)
 {
        CcWacomPagePrivate *priv = CC_WACOM_PAGE (object)->priv;
 
+       if (priv->cancellable) {
+               g_cancellable_cancel (priv->cancellable);
+               g_clear_object (&priv->cancellable);
+       }
+
        if (priv->area) {
                calib_area_free (priv->area);
                priv->area = NULL;
@@ -699,6 +783,8 @@ cc_wacom_page_init (CcWacomPage *self)
         gtk_widget_set_halign (priv->nav, GTK_ALIGN_END);
         gtk_widget_set_margin_left (priv->nav, 10);
        gtk_grid_attach (GTK_GRID (box), priv->nav, 1, 0, 1, 1);
+
+       priv->cancellable = g_cancellable_new ();
 }
 
 static void
diff --git a/panels/wacom/cc-wacom-panel.c b/panels/wacom/cc-wacom-panel.c
index 4457fbd..f1cdc68 100644
--- a/panels/wacom/cc-wacom-panel.c
+++ b/panels/wacom/cc-wacom-panel.c
@@ -46,6 +46,10 @@ struct _CcWacomPanelPrivate
        GdkDeviceManager *manager;
        guint             device_added_id;
        guint             device_removed_id;
+
+       /* DBus */
+       GCancellable  *cancellable;
+       GDBusProxy    *proxy;
 };
 
 typedef struct {
@@ -215,6 +219,9 @@ cc_wacom_panel_dispose (GObject *object)
                priv->devices = NULL;
        }
 
+       g_clear_object (&priv->cancellable);
+       g_clear_object (&priv->proxy);
+
        if (priv->pages)
        {
                g_hash_table_destroy (priv->pages);
@@ -415,6 +422,28 @@ cc_wacom_panel_switch_to_panel (CcWacomPanel *self,
 }
 
 static void
+got_wacom_proxy_cb (GObject      *source_object,
+                   GAsyncResult *res,
+                   gpointer      data)
+{
+       GError              *error = NULL;
+       CcWacomPanel        *self;
+       CcWacomPanelPrivate *priv;
+
+       self = CC_WACOM_PANEL (data);
+       priv = self->priv;
+       priv->proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
+
+       g_clear_object (&priv->cancellable);
+
+       if (priv->proxy == NULL) {
+               g_printerr ("Error creating proxy: %s\n", error->message);
+               g_error_free (error);
+               return;
+       }
+}
+
+static void
 enbiggen_label (GtkLabel *label)
 {
        const char *str;
@@ -456,6 +485,18 @@ cc_wacom_panel_init (CcWacomPanel *self)
                return;
        }
 
+       priv->cancellable = g_cancellable_new ();
+
+       g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+                                 G_DBUS_PROXY_FLAGS_NONE,
+                                 NULL,
+                                 "org.gnome.SettingsDaemon",
+                                 "/org/gnome/SettingsDaemon/Wacom",
+                                 "org.gnome.SettingsDaemon.Wacom",
+                                 priv->cancellable,
+                                 got_wacom_proxy_cb,
+                                 self);
+
        /* Notebook */
        notebook = GTK_NOTEBOOK (gtk_notebook_new ());
        priv->notebook = GTK_WIDGET (notebook);
@@ -497,3 +538,11 @@ cc_wacom_panel_init (CcWacomPanel *self)
 
        update_current_page (self);
 }
+
+GDBusProxy *
+cc_wacom_panel_get_gsd_wacom_bus_proxy (CcWacomPanel *self)
+{
+       g_return_val_if_fail (CC_IS_WACOM_PANEL (self), NULL);
+
+       return self->priv->proxy;
+}
diff --git a/panels/wacom/cc-wacom-panel.h b/panels/wacom/cc-wacom-panel.h
index 3ddd20b..55f5755 100644
--- a/panels/wacom/cc-wacom-panel.h
+++ b/panels/wacom/cc-wacom-panel.h
@@ -70,6 +70,11 @@ GType cc_wacom_panel_get_type (void) G_GNUC_CONST;
 void  cc_wacom_panel_switch_to_panel (CcWacomPanel *self,
                                      const char   *panel);
 
+void  cc_wacom_panel_set_osd_visibility (CcWacomPanel *self,
+                                         guint32        device_id);
+
+GDBusProxy * cc_wacom_panel_get_gsd_wacom_bus_proxy (CcWacomPanel *self);
+
 G_END_DECLS
 
 #endif /* _CC_WACOM_PANEL_H */
diff --git a/panels/wacom/test-wacom.c b/panels/wacom/test-wacom.c
index 68dd238..e9c31bc 100644
--- a/panels/wacom/test-wacom.c
+++ b/panels/wacom/test-wacom.c
@@ -16,6 +16,14 @@ cc_wacom_panel_switch_to_panel (CcWacomPanel *self, const char *panel)
        g_message ("Should launch %s preferences here", panel);
 }
 
+GDBusProxy *
+cc_wacom_panel_get_gsd_wacom_bus_proxy (CcWacomPanel *self)
+{
+       g_message ("Should get the g-s-d wacom dbus proxy here");
+
+       return NULL;
+}
+
 static void
 add_page (GList *devices,
          GtkWidget *notebook)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]