[gnome-color-manager] Allow virtual devices to be added to the device list
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Allow virtual devices to be added to the device list
- Date: Wed, 24 Feb 2010 10:26:03 +0000 (UTC)
commit 3f6c7b9f1e42a03d453a3922a85ef1f03346c8a2
Author: Richard Hughes <richard hughsie com>
Date: Wed Feb 24 10:24:44 2010 +0000
Allow virtual devices to be added to the device list
data/gcm-prefs.ui | 260 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/gcm-prefs.c | 185 +++++++++++++++++++++++++++++++++++++
2 files changed, 442 insertions(+), 3 deletions(-)
---
diff --git a/data/gcm-prefs.ui b/data/gcm-prefs.ui
index 17f434a..e55e6d7 100644
--- a/data/gcm-prefs.ui
+++ b/data/gcm-prefs.ui
@@ -60,21 +60,23 @@
<property name="visible">True</property>
<property name="spacing">6</property>
<child>
- <object class="GtkButton" id="button_calibrate">
- <property name="label" translatable="yes" comments="This is a button to calibrate the device by creating an ICC profile file using a hardware device or a reference image">Create _Profile for Device</property>
+ <object class="GtkButton" id="button_device_add">
+ <property name="label" translatable="yes" comments="This is a button to add a virtual device">_Add Device</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Adds a virtual device that is not connected.</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_delete">
- <property name="label" translatable="yes" comments="This is a button to delete the saved device">_Delete Device</property>
+ <property name="label" translatable="yes" comments="This is a button to delete the saved or virtual device">_Delete Device</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -87,6 +89,19 @@
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkButton" id="button_calibrate">
+ <property name="label" translatable="yes" comments="This is a button to calibrate the device by creating an ICC profile file using a hardware device or a reference image">Create _Profile for Device</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
@@ -1692,4 +1707,243 @@
<action-widget response="0">button_close</action-widget>
</action-widgets>
</object>
+ <object class="GtkDialog" id="dialog_virtual">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Add Virtual Device</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="type_hint">normal</property>
+ <property name="has_separator">False</property>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="dialog-vbox2">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkTable" id="table2">
+ <property name="visible">True</property>
+ <property name="n_rows">3</property>
+ <property name="n_columns">2</property>
+ <property name="column_spacing">6</property>
+ <property name="row_spacing">6</property>
+ <child>
+ <object class="GtkHBox" id="hbox27">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="label8">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Device type:</property>
+ </object>
+ <packing>
+ <property name="expand">False</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="GtkComboBox" id="combobox_virtual_type">
+ <property name="visible">True</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>
+ <child>
+ <object class="GtkLabel" id="label10">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Manufacturer:</property>
+ </object>
+ <packing>
+ <property name="expand">False</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>
+ <child>
+ <object class="GtkLabel" id="label9">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Model:</property>
+ </object>
+ <packing>
+ <property name="expand">False</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="GtkExpander" id="expander1">
+ <property name="visible">True</property>
+ <property name="sensitive">False</property>
+ <property name="can_focus">True</property>
+ <child>
+ <object class="GtkAlignment" id="alignment10">
+ <property name="visible">True</property>
+ <property name="left_padding">12</property>
+ <child>
+ <object class="GtkVBox" id="vbox2">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">3</property>
+ <child>
+ <object class="GtkRadioButton" id="radiobutton_virtual_rgb">
+ <property name="label" translatable="yes">RGB</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="radiobutton_virtual_cmyk">
+ <property name="label" translatable="yes">CMYK</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">radiobutton_virtual_rgb</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="label">
+ <object class="GtkLabel" id="label11">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">More details</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox" id="dialog-action_area2">
+ <property name="visible">True</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_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</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_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="pack_type">end</property>
+ <property name="position">0</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>
</interface>
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index 64cc129..a2cc61a 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -39,6 +39,7 @@
#include "gcm-client.h"
#include "gcm-colorimeter.h"
#include "gcm-device-xrandr.h"
+#include "gcm-device-virtual.h"
#include "gcm-profile.h"
#include "gcm-profile-store.h"
#include "gcm-trc-widget.h"
@@ -854,6 +855,97 @@ out:
}
/**
+ * gcm_prefs_device_add_cb:
+ **/
+static void
+gcm_prefs_device_add_cb (GtkWidget *widget, gpointer data)
+{
+ /* show ui */
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_virtual"));
+ gtk_widget_show (widget);
+
+ /* clear entries */
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_virtual_model"));
+ gtk_entry_set_text (GTK_ENTRY (widget), "");
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_virtual_manufacturer"));
+ gtk_entry_set_text (GTK_ENTRY (widget), "");
+}
+
+/**
+ * gcm_prefs_button_virtual_add_cb:
+ **/
+static void
+gcm_prefs_button_virtual_add_cb (GtkWidget *widget, gpointer data)
+{
+ GcmDeviceTypeEnum device_type;
+ GcmDevice *device;
+ const gchar *model;
+ const gchar *manufacturer;
+ gboolean ret;
+ GError *error = NULL;
+
+ /* get device details */
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_virtual_type"));
+ device_type = gtk_combo_box_get_active (GTK_COMBO_BOX(widget)) + 2;
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_virtual_model"));
+ model = gtk_entry_get_text (GTK_ENTRY (widget));
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_virtual_manufacturer"));
+ manufacturer = gtk_entry_get_text (GTK_ENTRY (widget));
+
+ /* create device */
+ device = gcm_device_virtual_new ();
+ ret = gcm_device_virtual_create_from_params (GCM_DEVICE_VIRTUAL (device), device_type, model, manufacturer, GCM_COLORSPACE_ENUM_RGB);
+ if (!ret) {
+ /* TRANSLATORS: could not add virtual device */
+ gcm_prefs_error_dialog (_("Failed to create virtual device"), NULL);
+ goto out;
+ }
+
+ /* save what we've got */
+ ret = gcm_device_save (device, &error);
+ if (!ret) {
+ /* TRANSLATORS: could not add virtual device */
+ gcm_prefs_error_dialog (_("Failed to save virtual device"), error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* add to the device list */
+ ret = gcm_client_add_device (gcm_client, device, &error);
+ if (!ret) {
+ /* TRANSLATORS: could not add virtual device */
+ gcm_prefs_error_dialog (_("Failed to add virtual device"), error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+out:
+ /* we're done */
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_virtual"));
+ gtk_widget_hide (widget);
+}
+
+/**
+ * gcm_prefs_button_virtual_cancel_cb:
+ **/
+static void
+gcm_prefs_button_virtual_cancel_cb (GtkWidget *widget, gpointer data)
+{
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_virtual"));
+ gtk_widget_hide (widget);
+}
+
+/**
+ * gcm_prefs_virtual_delete_event_cb:
+ **/
+static gboolean
+gcm_prefs_virtual_delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+ gcm_prefs_button_virtual_cancel_cb (widget, data);
+ return TRUE;
+}
+
+/**
* gcm_prefs_delete_cb:
**/
static void
@@ -2591,6 +2683,67 @@ gcm_prefs_info_bar_response_cb (GtkDialog *dialog, GtkResponseType response, gpo
}
/**
+ * gcm_device_type_enum_to_localised_string:
+ **/
+static const gchar *
+gcm_device_type_enum_to_localised_string (GcmDeviceTypeEnum device_type)
+{
+ if (device_type == GCM_DEVICE_TYPE_ENUM_DISPLAY) {
+ /* TRANSLATORS: device type */
+ return _("Display");
+ }
+ if (device_type == GCM_DEVICE_TYPE_ENUM_SCANNER) {
+ /* TRANSLATORS: device type */
+ return _("Scanner");
+ }
+ if (device_type == GCM_DEVICE_TYPE_ENUM_PRINTER) {
+ /* TRANSLATORS: device type */
+ return _("Printer");
+ }
+ if (device_type == GCM_DEVICE_TYPE_ENUM_CAMERA) {
+ /* TRANSLATORS: device type */
+ return _("Camera");
+ }
+ return NULL;
+}
+
+/**
+ * gcm_prefs_setup_virtual_combobox:
+ **/
+static void
+gcm_prefs_setup_virtual_combobox (GtkWidget *widget)
+{
+ guint i;
+ const gchar *text;
+
+ for (i=GCM_DEVICE_TYPE_ENUM_SCANNER; i<GCM_DEVICE_TYPE_ENUM_LAST; i++) {
+ text = gcm_device_type_enum_to_localised_string (i);
+ gtk_combo_box_append_text (GTK_COMBO_BOX(widget), text);
+ }
+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), GCM_DEVICE_TYPE_ENUM_PRINTER - 2);
+}
+
+/**
+ * gpk_update_viewer_notify_network_state_cb:
+ **/
+static void
+gcm_prefs_button_virtual_entry_changed_cb (GtkEntry *entry, GParamSpec *pspec, gpointer user_data)
+{
+ const gchar *model;
+ const gchar *manufacturer;
+ GtkWidget *widget;
+
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_virtual_model"));
+ model = gtk_entry_get_text (GTK_ENTRY (widget));
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_virtual_manufacturer"));
+ manufacturer = gtk_entry_get_text (GTK_ENTRY (widget));
+
+ /* only set the add button sensitive if both sections have text */
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_virtual_add"));
+ gtk_widget_set_sensitive (widget, (model != NULL && model[0] != '\0' && manufacturer != NULL && manufacturer[0] != '\0'));
+}
+
+/**
* main:
**/
int
@@ -2722,6 +2875,9 @@ main (int argc, char **argv)
g_signal_connect (widget, "clicked",
G_CALLBACK (gcm_prefs_delete_cb), NULL);
gtk_widget_set_sensitive (widget, FALSE);
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_device_add"));
+ g_signal_connect (widget, "clicked",
+ G_CALLBACK (gcm_prefs_device_add_cb), NULL);
widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_calibrate"));
g_signal_connect (widget, "clicked",
G_CALLBACK (gcm_prefs_calibrate_cb), NULL);
@@ -2753,6 +2909,35 @@ main (int argc, char **argv)
widget = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_serial"));
gtk_widget_hide (widget);
+ /* set up virtual device */
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_virtual"));
+ gtk_window_set_icon_name (GTK_WINDOW (widget), GCM_STOCK_ICON);
+ gtk_window_set_transient_for (GTK_WINDOW (widget), GTK_WINDOW (main_window));
+ gtk_window_set_modal (GTK_WINDOW (widget), TRUE);
+ g_signal_connect (widget, "delete-event",
+ G_CALLBACK (gcm_prefs_virtual_delete_event_cb), NULL);
+
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_virtual_add"));
+ g_signal_connect (widget, "clicked",
+ G_CALLBACK (gcm_prefs_button_virtual_add_cb), NULL);
+ gtk_widget_set_sensitive (widget, FALSE);
+
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_virtual_cancel"));
+ g_signal_connect (widget, "clicked",
+ G_CALLBACK (gcm_prefs_button_virtual_cancel_cb), NULL);
+
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_virtual_type"));
+ gcm_prefs_set_combo_simple_text (widget);
+ gcm_prefs_setup_virtual_combobox (widget);
+
+ /* disable the add button if nothing in either box */
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_virtual_model"));
+ g_signal_connect (widget, "notify::text",
+ G_CALLBACK (gcm_prefs_button_virtual_entry_changed_cb), NULL);
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_virtual_manufacturer"));
+ g_signal_connect (widget, "notify::text",
+ G_CALLBACK (gcm_prefs_button_virtual_entry_changed_cb), NULL);
+
/* setup icc profiles list */
widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_profile"));
gcm_prefs_set_combo_simple_text (widget);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]