[gnome-color-manager] Add 'Import profile' and 'Delete profile' buttons into the preferences UI



commit 0692f253b4256fe373a999de4efc8c3a4dafa1a9
Author: Richard Hughes <richard hughsie com>
Date:   Sun Nov 29 21:39:12 2009 +0000

    Add 'Import profile' and 'Delete profile' buttons into the preferences UI

 data/gcm-prefs.ui |   30 +++++++++-
 src/gcm-client.c  |    2 +-
 src/gcm-prefs.c   |  181 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 209 insertions(+), 4 deletions(-)
---
diff --git a/data/gcm-prefs.ui b/data/gcm-prefs.ui
index 46aa454..e784c0a 100644
--- a/data/gcm-prefs.ui
+++ b/data/gcm-prefs.ui
@@ -243,6 +243,7 @@
                                 <child>
                                   <object class="GtkHBox" id="hbox3">
                                     <property name="visible">True</property>
+                                    <property name="spacing">6</property>
                                     <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>
@@ -477,9 +478,10 @@
                                 <child>
                                   <object class="GtkHBox" id="hbox4">
                                     <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">_Calibrate device</property>
+                                        <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</property>
                                         <property name="visible">True</property>
                                         <property name="can_focus">True</property>
                                         <property name="receives_default">True</property>
@@ -490,6 +492,32 @@
                                         <property name="position">0</property>
                                       </packing>
                                     </child>
+                                    <child>
+                                      <object class="GtkButton" id="button_profile_delete">
+                                        <property name="label" translatable="yes">Delete profile</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">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkButton" id="button_profile_import">
+                                        <property name="label" translatable="yes">_Import profile</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="position">2</property>
diff --git a/src/gcm-client.c b/src/gcm-client.c
index 0289dbd..af68a5a 100644
--- a/src/gcm-client.c
+++ b/src/gcm-client.c
@@ -405,7 +405,7 @@ out:
 		diag = sqrtf ((powf (width,2)) + (powf (height, 2)));
 
 		/* print it in inches */
-		g_string_append_printf (string, " (%i\")", (guint) ((gfloat) diag * 0.393700787f));
+		g_string_append_printf (string, " - %i\"", (guint) ((gfloat) diag * 0.393700787f));
 	}
 
 	g_free (name);
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index 516c01e..2061cd8 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -480,6 +480,172 @@ out:
 }
 
 /**
+ * gcm_prefs_profile_delete_cb:
+ **/
+static void
+gcm_prefs_profile_delete_cb (GtkWidget *widget, gpointer data)
+{
+	GtkWidget *dialog;
+	GtkResponseType response;
+	GtkWindow *window;
+	gint retval;
+	gchar *filename = NULL;
+	gchar *filename_tmp;
+	GcmProfile *profile;
+	GtkTreeSelection *selection;
+	guint i;
+
+	/* ask the user to confirm */
+	window = GTK_WINDOW(gtk_builder_get_object (builder, "dialog_prefs"));
+	dialog = gtk_message_dialog_new (window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_CANCEL,
+					 /* TRANSLATORS: title, usually we can tell based on the EDID data or output name */
+					 _("Permanently delete profile?"));
+	gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+						  /* TRANSLATORS: dialog message */
+						  _("Are you sure you want to remove this profile from your system permanently?"));
+	gtk_window_set_icon_name (GTK_WINDOW (dialog), GCM_STOCK_ICON);
+	/* TRANSLATORS: button, delete a profile */
+	gtk_dialog_add_button (GTK_DIALOG (dialog), _("Delete"), GTK_RESPONSE_YES);
+	response = gtk_dialog_run (GTK_DIALOG (dialog));
+	gtk_widget_destroy (dialog);
+	if (response != GTK_RESPONSE_YES)
+		goto out;
+
+	/* get device data */
+	g_object_get (current_device,
+		      "profile-filename", &filename,
+		      NULL);
+
+	/* try to remove file */
+	retval = g_unlink (filename);
+	if (retval != 0)
+		goto out;
+
+	/* find an existing profile of this name */
+	for (i=0; i<profiles_array->len; i++) {
+		profile = g_ptr_array_index (profiles_array, i);
+		g_object_get (profile,
+			      "filename", &filename_tmp,
+			      NULL);
+		if (g_strcmp0 (filename, filename_tmp) == 0) {
+			egg_debug ("found existing profile: %s", filename);
+			g_ptr_array_remove (profiles_array, profile);
+		}
+		g_free (filename_tmp);
+	}
+
+	/* re-get all the profiles for this device */
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_devices"));
+	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
+	gcm_prefs_devices_treeview_clicked_cb (selection, NULL);
+out:
+	g_free (filename);
+}
+
+/**
+ * gcm_prefs_calibrate_device_get_icc_profile:
+ **/
+static gchar *
+gcm_prefs_calibrate_device_get_icc_profile (void)
+{
+	gchar *filename = NULL;
+	GtkWindow *window;
+	GtkWidget *dialog;
+	GtkFileFilter *filter;
+
+	/* create new dialog */
+	window = GTK_WINDOW(gtk_builder_get_object (builder, "dialog_prefs"));
+	/* TRANSLATORS: dialog for file->open dialog */
+	dialog = gtk_file_chooser_dialog_new (_("Select ICC profile file"), window,
+					       GTK_FILE_CHOOSER_ACTION_OPEN,
+					       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+					       GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+					      NULL);
+	gtk_window_set_icon_name (GTK_WINDOW (dialog), GCM_STOCK_ICON);
+	gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog), g_get_home_dir ());
+	gtk_file_chooser_set_create_folders (GTK_FILE_CHOOSER(dialog), FALSE);
+
+	/* setup the filter */
+	filter = gtk_file_filter_new ();
+	gtk_file_filter_add_mime_type (filter, "application/vnd.iccprofile");
+	/* TRANSLATORS: filter name on the file->open dialog */
+	gtk_file_filter_set_name (filter, _("Supported ICC profiles"));
+	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(dialog), filter);
+//	g_object_unref (filter);
+
+	/* did user choose file */
+	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+		filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog));
+
+	/* we're done */
+	gtk_widget_destroy (dialog);
+
+	/* or NULL for missing */
+	return filename;
+}
+
+/**
+ * gcm_prefs_profile_import_cb:
+ **/
+static void
+gcm_prefs_profile_import_cb (GtkWidget *widget, gpointer data)
+{
+	gchar *filename;
+	GtkWidget *dialog;
+	GError *error = NULL;
+	gchar *destination = NULL;
+	GtkWindow *window;
+	GcmProfile *profile = NULL;
+	GtkTreeSelection *selection;
+	gboolean ret;
+
+	/* get new file */
+	filename = gcm_prefs_calibrate_device_get_icc_profile ();
+	if (filename == NULL)
+		goto out;
+
+	/* copy icc file to ~/.color/icc */
+	destination = gcm_utils_get_profile_destination (filename);
+	ret = gcm_utils_mkdir_and_copy (filename, destination, &error);
+	if (!ret) {
+		/* TRANSLATORS: could not read file */
+		window = GTK_WINDOW(gtk_builder_get_object (builder, "dialog_prefs"));
+		dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Failed to copy file"));
+		gtk_window_set_icon_name (GTK_WINDOW (dialog), GCM_STOCK_ICON);
+		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+		gtk_dialog_run (GTK_DIALOG (dialog));
+		g_error_free (error);
+		gtk_widget_destroy (dialog);
+		goto out;
+	}
+
+	/* add new profile */
+	profile = gcm_profile_new ();
+
+	/* parse the new file */
+	ret = gcm_profile_parse (profile, destination, &error);
+	if (!ret) {
+		egg_warning ("failed to parse: %s", error->message);
+		g_error_free (error);
+		g_object_unref (profile);
+		goto out;
+	}
+
+	/* add to arrays */
+	g_ptr_array_add (profiles_array, g_object_ref (profile));
+
+	/* re-get all the profiles for this device */
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_devices"));
+	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
+	gcm_prefs_devices_treeview_clicked_cb (selection, NULL);
+out:
+	if (profile != NULL)
+		g_object_unref (profile);
+	g_free (filename);
+	g_free (destination);
+}
+
+/**
  * gcm_prefs_calibrate_cb:
  **/
 static void
@@ -546,7 +712,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 	}
 
 	/* find an existing profile of this name */
-	for (i=0; i<profiles_array_in_combo->len; i++) {
+	for (i=0; i<profiles_array->len; i++) {
 		profile = g_ptr_array_index (profiles_array, i);
 		g_object_get (profile,
 			      "filename", &name,
@@ -560,7 +726,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 	}
 
 	/* we didn't find an existing profile */
-	if (i == profiles_array_in_combo->len) {
+	if (i == profiles_array->len) {
 		egg_debug ("adding: %s", destination);
 
 		/* set this default */
@@ -1272,6 +1438,11 @@ gcm_prefs_profile_combo_changed_cb (GtkWidget *widget, gpointer data)
 		gtk_widget_show (widget);
 	}
 
+	/* set delete sensitivity */
+	ret = (filename != NULL && g_str_has_prefix (filename, "/home/"));
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_profile_delete"));
+	gtk_widget_set_sensitive (widget, ret);
+
 	/* only save and set if changed */
 	if (changed) {
 
@@ -1807,6 +1978,12 @@ main (int argc, char **argv)
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_calibrate"));
 	g_signal_connect (widget, "clicked",
 			  G_CALLBACK (gcm_prefs_calibrate_cb), NULL);
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_profile_delete"));
+	g_signal_connect (widget, "clicked",
+			  G_CALLBACK (gcm_prefs_profile_delete_cb), NULL);
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_profile_import"));
+	g_signal_connect (widget, "clicked",
+			  G_CALLBACK (gcm_prefs_profile_import_cb), NULL);
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "expander1"));
 	gtk_widget_set_sensitive (widget, FALSE);
 



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