[gnome-color-manager] Allow image files to be dragged and dropped on the virtual device dialog
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Allow image files to be dragged and dropped on the virtual device dialog
- Date: Fri, 21 May 2010 11:49:39 +0000 (UTC)
commit fde6eed311c524e0a2c39eb3ac14d6f6d6904b14
Author: Richard Hughes <richard hughsie com>
Date: Fri May 21 12:49:22 2010 +0100
Allow image files to be dragged and dropped on the virtual device dialog
data/gcm-prefs.ui | 81 ++++++++++++++++++++++++++++++++-----------
src/gcm-prefs.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 160 insertions(+), 20 deletions(-)
---
diff --git a/data/gcm-prefs.ui b/data/gcm-prefs.ui
index 6bc8c6d..243a35c 100644
--- a/data/gcm-prefs.ui
+++ b/data/gcm-prefs.ui
@@ -1778,7 +1778,7 @@
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
- <property name="spacing">6</property>
+ <property name="spacing">9</property>
<child>
<object class="GtkTable" id="table2">
<property name="visible">True</property>
@@ -1890,6 +1890,47 @@
</packing>
</child>
<child>
+ <object class="GtkHBox" id="hbox_virtual_info">
+ <property name="visible">True</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkImage" id="image1">
+ <property name="visible">True</property>
+ <property name="stock">gtk-dialog-info</property>
+ <property name="icon-size">6</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="hbox56">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="label_virtual_info">
+ <property name="visible">True</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="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</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>
+ <child>
<object class="GtkExpander" id="expander1">
<property name="visible">True</property>
<property name="sensitive">False</property>
@@ -1945,7 +1986,7 @@
</child>
</object>
<packing>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
</object>
@@ -2001,45 +2042,45 @@
</object>
<object class="GtkSizeGroup" id="sizegroup_lists">
<widgets>
- <widget name="scrolledwindow1"/>
<widget name="scrolledwindow2"/>
+ <widget name="scrolledwindow1"/>
</widgets>
</object>
<object class="GtkSizeGroup" id="sizegroup_defaults">
<widgets>
- <widget name="hbox43"/>
- <widget name="hbox46"/>
- <widget name="hbox15"/>
<widget name="hbox17"/>
+ <widget name="hbox15"/>
+ <widget name="hbox46"/>
+ <widget name="hbox43"/>
</widgets>
</object>
<object class="GtkSizeGroup" id="sizegroup_devices">
<widgets>
- <widget name="hbox21"/>
- <widget name="hbox22"/>
- <widget name="hbox23"/>
<widget name="hbox53"/>
+ <widget name="hbox23"/>
+ <widget name="hbox22"/>
+ <widget name="hbox21"/>
</widgets>
</object>
<object class="GtkSizeGroup" id="sizegroup_profiles">
<widgets>
- <widget name="hbox6"/>
- <widget name="hbox39"/>
- <widget name="hbox36"/>
- <widget name="hbox10"/>
- <widget name="hbox34"/>
- <widget name="hbox48"/>
- <widget name="hbox12"/>
- <widget name="hbox31"/>
<widget name="hbox33"/>
+ <widget name="hbox31"/>
+ <widget name="hbox12"/>
+ <widget name="hbox48"/>
+ <widget name="hbox34"/>
+ <widget name="hbox10"/>
+ <widget name="hbox36"/>
+ <widget name="hbox39"/>
+ <widget name="hbox6"/>
</widgets>
</object>
<object class="GtkSizeGroup" id="sizegroup_combos">
<widgets>
- <widget name="combobox_rendering_softproof"/>
- <widget name="combobox_rendering_display"/>
- <widget name="combobox_space_cmyk"/>
<widget name="combobox_space_rgb"/>
+ <widget name="combobox_space_cmyk"/>
+ <widget name="combobox_rendering_display"/>
+ <widget name="combobox_rendering_softproof"/>
</widgets>
</object>
</interface>
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index ea4386d..1654d7e 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -39,6 +39,7 @@
#include "gcm-colorimeter.h"
#include "gcm-device-xrandr.h"
#include "gcm-device-virtual.h"
+#include "gcm-exif.h"
#include "gcm-profile.h"
#include "gcm-profile-store.h"
#include "gcm-trc-widget.h"
@@ -661,6 +662,99 @@ out:
}
/**
+ * gcm_prefs_virtual_set_from_file:
+ **/
+static gboolean
+gcm_prefs_virtual_set_from_file (GFile *file)
+{
+ gboolean ret;
+ GcmExif *exif;
+ GError *error = NULL;
+ const gchar *model;
+ const gchar *manufacturer;
+ GtkWidget *widget;
+
+ /* parse file */
+ exif = gcm_exif_new ();
+ ret = gcm_exif_parse (exif, file, &error);
+ if (!ret) {
+ egg_warning ("failed to parse file: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* set model and manufacturer */
+ model = gcm_exif_get_model (exif);
+ if (model != NULL) {
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_virtual_model"));
+ gtk_entry_set_text (GTK_ENTRY (widget), model);
+ }
+ manufacturer = gcm_exif_get_manufacturer (exif);
+ if (manufacturer != NULL) {
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_virtual_manufacturer"));
+ gtk_entry_set_text (GTK_ENTRY (widget), manufacturer);
+ }
+
+ /* set type */
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_virtual_type"));
+ gtk_combo_box_set_active (GTK_COMBO_BOX(widget), GCM_DEVICE_KIND_CAMERA - 2);
+out:
+ g_object_unref (exif);
+ return ret;
+}
+
+/**
+ * gcm_prefs_virtual_drag_data_received_cb:
+ **/
+static void
+gcm_prefs_virtual_drag_data_received_cb (GtkWidget *widget, GdkDragContext *context, gint x, gint y,
+ GtkSelectionData *data, guint _time, gpointer user_data)
+{
+ 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 */
+ egg_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 an ICC profile */
+ egg_debug ("trying to set %s", filenames[i]);
+ file = g_file_new_for_uri (filenames[i]);
+ ret = gcm_prefs_virtual_set_from_file (file);
+ if (!ret) {
+ egg_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);
+}
+
+/**
* gcm_prefs_ensure_argyllcms_installed:
**/
static gboolean
@@ -842,6 +936,8 @@ gcm_prefs_device_add_cb (GtkWidget *widget, gpointer data)
gtk_widget_show (widget);
/* clear entries */
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_virtual_type"));
+ gtk_combo_box_set_active (GTK_COMBO_BOX(widget), 0);
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"));
@@ -2801,6 +2897,9 @@ main (int argc, char **argv)
gtk_window_set_modal (GTK_WINDOW (widget), TRUE);
g_signal_connect (widget, "delete-event",
G_CALLBACK (gcm_prefs_virtual_delete_event_cb), NULL);
+ g_signal_connect (widget, "drag-data-received",
+ G_CALLBACK (gcm_prefs_virtual_drag_data_received_cb), NULL);
+ gcm_prefs_setup_drag_and_drop (widget);
widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_virtual_add"));
g_signal_connect (widget, "clicked",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]