[gnome-control-center] color: Add the virtual device UI which is used when a physical device connection is impossible



commit e7863d0e0207e0bf2a5bbaee88199610a460dc44
Author: Richard Hughes <richard hughsie com>
Date:   Fri May 20 20:40:10 2011 +0100

    color: Add the virtual device UI which is used when a physical device connection is impossible
    
    This is designed so power users can create virtual devices (just like in
    ColorSync) that represent things like 'Hexachrome Press #2' or 'Cinema'.
    
    This new UI isn't actually wired up yet, and there are no new UI controls as
    the UI still needs love from the designers.
    
    This was added at this point for two reasons:
    
    1. To get the translations early so we can enable this later
    2. To be able to delete the code out of gcm-prefs.c

 panels/color/cc-color-panel.c |  224 ++++++++++++++++++++++++++++++++++++
 panels/color/color.ui         |  255 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 479 insertions(+), 0 deletions(-)
---
diff --git a/panels/color/cc-color-panel.c b/panels/color/cc-color-panel.c
index dea4dc1..6bd72d2 100644
--- a/panels/color/cc-color-panel.c
+++ b/panels/color/cc-color-panel.c
@@ -1661,6 +1661,203 @@ out:
 }
 
 static void
+gcm_prefs_button_virtual_add_cb (GtkWidget *widget, CcColorPanel *prefs)
+{
+  CdDeviceKind device_kind;
+  CdDevice *device;
+  const gchar *model;
+  const gchar *manufacturer;
+  gchar *device_id;
+  GError *error = NULL;
+  GHashTable *device_props;
+  CcColorPanelPrivate *priv = prefs->priv;
+
+  /* get device details */
+  widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                               "combobox_virtual_type"));
+  device_kind = gtk_combo_box_get_active (GTK_COMBO_BOX(widget)) + 2;
+  widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                               "entry_virtual_model"));
+  model = gtk_entry_get_text (GTK_ENTRY (widget));
+  widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                               "entry_virtual_manufacturer"));
+  manufacturer = gtk_entry_get_text (GTK_ENTRY (widget));
+
+  /* create device */
+  device_id = g_strdup_printf ("%s-%s-%s",
+                               cd_device_kind_to_string (device_kind),
+                               manufacturer,
+                               model);
+  device_props = g_hash_table_new_full (g_str_hash, g_str_equal,
+                                        g_free, g_free);
+  g_hash_table_insert (device_props,
+                       g_strdup ("Kind"),
+                       g_strdup (cd_device_kind_to_string (device_kind)));
+  g_hash_table_insert (device_props,
+                       g_strdup ("Mode"),
+                       g_strdup (cd_device_mode_to_string (CD_DEVICE_MODE_VIRTUAL)));
+  g_hash_table_insert (device_props,
+                       g_strdup ("Colorspace"),
+                       g_strdup (cd_colorspace_to_string (CD_COLORSPACE_RGB)));
+  g_hash_table_insert (device_props,
+                       g_strdup ("Model"),
+                       g_strdup (model));
+  g_hash_table_insert (device_props,
+                       g_strdup ("Vendor"),
+                       g_strdup (manufacturer));
+  device = cd_client_create_device_sync (priv->client,
+                                         device_id,
+                                         CD_OBJECT_SCOPE_DISK,
+                                         device_props,
+                                         priv->cancellable,
+                                         &error);
+  if (device == NULL)
+    {
+      g_warning ("Failed to add create virtual device: %s",
+                 error->message);
+      g_error_free (error);
+      goto out;
+    }
+out:
+  g_hash_table_unref (device_props);
+  widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                               "dialog_virtual"));
+  gtk_widget_hide (widget);
+  g_free (device_id);
+}
+
+static void
+gcm_prefs_button_virtual_cancel_cb (GtkWidget *widget, CcColorPanel *prefs)
+{
+  CcColorPanelPrivate *priv = prefs->priv;
+  widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                               "dialog_virtual"));
+  gtk_widget_hide (widget);
+}
+
+static gboolean
+gcm_prefs_virtual_delete_event_cb (GtkWidget *widget,
+                                   GdkEvent *event,
+                                   CcColorPanel *prefs)
+{
+  gcm_prefs_button_virtual_cancel_cb (widget, prefs);
+  return TRUE;
+}
+
+static const gchar *
+cd_device_kind_to_localised_string (CdDeviceKind device_kind)
+{
+  if (device_kind == CD_DEVICE_KIND_DISPLAY)
+    return C_("Device kind", "Display");
+  if (device_kind == CD_DEVICE_KIND_SCANNER)
+    return C_("Device kind", "Scanner");
+  if (device_kind == CD_DEVICE_KIND_PRINTER)
+    return C_("Device kind", "Printer");
+  if (device_kind == CD_DEVICE_KIND_CAMERA)
+    return C_("Device kind", "Camera");
+  if (device_kind == CD_DEVICE_KIND_WEBCAM)
+    return C_("Device kind", "Webcam");
+  return NULL;
+}
+
+static void
+gcm_prefs_setup_virtual_combobox (GtkWidget *widget)
+{
+  guint i;
+  const gchar *text;
+
+  for (i=CD_DEVICE_KIND_SCANNER; i<CD_DEVICE_KIND_LAST; i++)
+    {
+      text = cd_device_kind_to_localised_string (i);
+      if (text == NULL)
+        continue;
+      gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(widget), text);
+    }
+  gtk_combo_box_set_active (GTK_COMBO_BOX (widget), CD_DEVICE_KIND_PRINTER - 2);
+}
+
+static gboolean
+gcm_prefs_virtual_set_from_file (CcColorPanel *prefs, GFile *file)
+{
+  /* TODO: use GCM to get the EXIF data */
+  return FALSE;
+}
+
+static void
+gcm_prefs_virtual_drag_data_received_cb (GtkWidget *widget,
+                                         GdkDragContext *context,
+                                         gint x, gint y,
+                                         GtkSelectionData *data,
+                                         guint info,
+                                         guint _time,
+                                         CcColorPanel *prefs)
+{
+  const guchar *filename;
+  gchar **filenames = NULL;
+  GFile *file = NULL;
+  guint i;
+  gboolean ret;
+
+  /* get filenames */
+  filename = gtk_selection_data_get_data (data);
+  if (filename == NULL)
+    {
+      gtk_drag_finish (context, FALSE, FALSE, _time);
+      goto out;
+    }
+
+  /* import this */
+  g_debug ("dropped: %p (%s)", data, filename);
+
+  /* split, as multiple drag targets are accepted */
+  filenames = g_strsplit_set ((const gchar *)filename, "\r\n", -1);
+  for (i = 0; filenames[i] != NULL; i++)
+    {
+      /* blank entry */
+      if (filenames[i][0] == '\0')
+        continue;
+
+      /* check this is a parsable file */
+      g_debug ("trying to set %s", filenames[i]);
+      file = g_file_new_for_uri (filenames[i]);
+      ret = gcm_prefs_virtual_set_from_file (prefs, file);
+      if (!ret)
+        {
+          g_debug ("%s did not set from file correctly",
+                   filenames[i]);
+          gtk_drag_finish (context, FALSE, FALSE, _time);
+          goto out;
+        }
+      g_object_unref (file);
+      file = NULL;
+    }
+
+  gtk_drag_finish (context, TRUE, FALSE, _time);
+out:
+  if (file != NULL)
+    g_object_unref (file);
+  g_strfreev (filenames);
+}
+
+static void
+gcm_prefs_setup_drag_and_drop (GtkWidget *widget)
+{
+  GtkTargetEntry entry;
+
+  /* setup a dummy entry */
+  entry.target = g_strdup ("text/plain");
+  entry.flags = GTK_TARGET_OTHER_APP;
+  entry.info = 0;
+
+  gtk_drag_dest_set (widget,
+                     GTK_DEST_DEFAULT_ALL,
+                     &entry,
+                     1,
+                     GDK_ACTION_MOVE | GDK_ACTION_COPY);
+  g_free (entry.target);
+}
+
+static void
 cc_color_panel_get_property (GObject    *object,
                               guint       property_id,
                               GValue     *value,
@@ -1862,6 +2059,33 @@ cc_color_panel_init (CcColorPanel *prefs)
   gtk_style_context_add_class (context, GTK_STYLE_CLASS_INLINE_TOOLBAR);
   gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
 
+  /* set up virtual dialog */
+  widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                               "dialog_virtual"));
+  g_signal_connect (widget, "delete-event",
+                    G_CALLBACK (gcm_prefs_virtual_delete_event_cb),
+                    prefs);
+  g_signal_connect (widget, "drag-data-received",
+                    G_CALLBACK (gcm_prefs_virtual_drag_data_received_cb),
+                    prefs);
+  gcm_prefs_setup_drag_and_drop (widget);
+
+  widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                               "button_virtual_add"));
+  g_signal_connect (widget, "clicked",
+                    G_CALLBACK (gcm_prefs_button_virtual_add_cb),
+                    prefs);
+  gtk_widget_set_sensitive (widget, FALSE);
+
+  widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                               "button_virtual_cancel"));
+  g_signal_connect (widget, "clicked",
+                    G_CALLBACK (gcm_prefs_button_virtual_cancel_cb),
+                    prefs);
+  widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                               "combobox_virtual_type"));
+  gcm_prefs_setup_virtual_combobox (widget);
+
   /* set up assign dialog */
   widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
                                                "dialog_assign"));
diff --git a/panels/color/color.ui b/panels/color/color.ui
index e802b51..8f3a62a 100644
--- a/panels/color/color.ui
+++ b/panels/color/color.ui
@@ -227,6 +227,7 @@
                 <property name="icon_size">1</property>
                 <child>
                   <object class="GtkToolButton" id="toolbutton_device_add">
+                    <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="has_tooltip">True</property>
                     <property name="tooltip_markup" translatable="yes">Add a virtual device</property>
@@ -243,6 +244,7 @@
                 </child>
                 <child>
                   <object class="GtkToolButton" id="toolbutton_device_remove">
+                    <property name="visible">True</property>
                     <property name="sensitive">False</property>
                     <property name="can_focus">False</property>
                     <property name="has_tooltip">True</property>
@@ -358,6 +360,259 @@
       </object>
     </child>
   </object>
+  <object class="GtkDialog" id="dialog_virtual">
+    <property name="can_focus">False</property>
+    <property name="border_width">15</property>
+    <property name="title"> </property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <property name="window_position">center-on-parent</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="icon_name">gnome-color-manager</property>
+    <property name="type_hint">dialog</property>
+    <property name="skip_taskbar_hint">True</property>
+    <property name="skip_pager_hint">True</property>
+    <property name="transient_for">dialog_prefs</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox2">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button_virtual_cancel">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+                <property name="secondary">True</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button_virtual_add">
+                <property name="label">gtk-add</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkVBox" id="vbox1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="spacing">9</property>
+            <child>
+              <object class="GtkTable" id="table2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="n_rows">3</property>
+                <property name="n_columns">2</property>
+                <property name="column_spacing">6</property>
+                <property name="row_spacing">9</property>
+                <child>
+                  <object class="GtkHBox" id="hbox27">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkLabel" id="label8">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Device type:</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options">GTK_FILL</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkComboBoxText" id="combobox_virtual_type">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="entry_text_column">0</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkHBox" id="hbox51">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkLabel" id="label10">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Manufacturer:</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options">GTK_FILL</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkHBox" id="hbox50">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkLabel" id="label9">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Model:</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options">GTK_FILL</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkEntry" id="entry_virtual_manufacturer">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="invisible_char">â??</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkEntry" id="entry_virtual_model">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="invisible_char">â??</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkHBox" id="hbox_virtual_info">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="spacing">12</property>
+                <child>
+                  <object class="GtkImage" id="image1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="stock">gtk-dialog-info</property>
+                    <property name="icon-size">6</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkHBox" id="hbox56">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkLabel" id="label_virtual_info">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Image files can be dragged on this window to auto-complete the above fields.</property>
+                        <property name="wrap">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="0">button_virtual_cancel</action-widget>
+      <action-widget response="0">button_virtual_add</action-widget>
+    </action-widgets>
+  </object>
   <object class="GtkSizeGroup" id="sizegroup_buttons"/>
   <object class="GtkSizeGroup" id="sizegroup_combos"/>
   <object class="GtkSizeGroup" id="sizegroup_defaults"/>



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