[gnome-color-manager] Copy the calibrated profile into the correct directory and set it as the default profile
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Copy the calibrated profile into the correct directory and set it as the default profile
- Date: Fri, 30 Oct 2009 18:52:55 +0000 (UTC)
commit f33fb92d6229507cc18d3db12c141787f1735741
Author: Richard Hughes <richard hughsie com>
Date: Fri Oct 30 18:52:07 2009 +0000
Copy the calibrated profile into the correct directory and set it as the default profile
src/gcm-import.c | 60 +----------------------------------------------------
src/gcm-prefs.c | 40 ++++++++++++++++++++++++-----------
src/gcm-utils.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/gcm-utils.h | 4 +++
4 files changed, 89 insertions(+), 71 deletions(-)
---
diff --git a/src/gcm-import.c b/src/gcm-import.c
index 87fbd31..5be77d6 100644
--- a/src/gcm-import.c
+++ b/src/gcm-import.c
@@ -29,62 +29,6 @@
#include "gcm-utils.h"
/**
- * gcm_import_get_destination:
- **/
-static gchar *
-gcm_import_get_destination (const gchar *filename)
-{
- gchar *basename;
- gchar *destination;
-
- /* get destination filename for this source file */
- basename = g_path_get_basename (filename);
- destination = g_build_filename (g_get_home_dir (), GCM_PROFILE_PATH, basename, NULL);
-
- g_free (basename);
- return destination;
-}
-
-/**
- * gcm_import_copy_file:
- **/
-static gboolean
-gcm_import_copy_file (const gchar *filename, const gchar *destination, GError **error)
-{
- gboolean ret;
- gchar *path;
- GFile *source;
- GFile *destfile;
- GFile *destpath;
-
- /* setup paths */
- source = g_file_new_for_path (filename);
- path = g_path_get_dirname (destination);
- destpath = g_file_new_for_path (path);
- destfile = g_file_new_for_path (destination);
-
- /* ensure desination exists */
- ret = g_file_test (path, G_FILE_TEST_EXISTS);
- if (!ret) {
- ret = g_file_make_directory_with_parents (destpath, NULL, error);
- if (!ret)
- goto out;
- }
-
- /* do the copy */
- egg_debug ("copying from %s to %s", filename, path);
- ret = g_file_copy (source, destfile, G_FILE_COPY_NONE, NULL, NULL, NULL, error);
- if (!ret)
- goto out;
-out:
- g_free (path);
- g_object_unref (source);
- g_object_unref (destpath);
- g_object_unref (destfile);
- return ret;
-}
-
-/**
* main:
**/
int
@@ -154,7 +98,7 @@ main (int argc, char **argv)
NULL);
/* check file does't already exist */
- destination = gcm_import_get_destination (files[0]);
+ destination = gcm_utils_get_profile_destination (files[0]);
ret = g_file_test (destination, G_FILE_TEST_EXISTS);
if (ret) {
/* TRANSLATORS: color profile already been installed */
@@ -194,7 +138,7 @@ main (int argc, char **argv)
goto out;
/* copy icc file to ~/.color/icc */
- ret = gcm_import_copy_file (files[0], destination, &error);
+ ret = gcm_utils_mkdir_and_copy (files[0], destination, &error);
if (!ret) {
/* TRANSLATORS: could not read file */
dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Failed to copy file"));
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index 88a845e..5768a5f 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -23,6 +23,7 @@
#include <gtk/gtk.h>
#include <math.h>
#include <unique/unique.h>
+#include <glib/gstdio.h>
#include "egg-debug.h"
@@ -86,7 +87,8 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
GtkWindow *window;
GnomeRROutput *output;
const gchar *output_name;
- gchar *filename;
+ gchar *filename = NULL;
+ gchar *destination = NULL;
/* get the device */
output = gnome_rr_screen_get_output_by_id (rr_screen, current_device);
@@ -110,7 +112,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
if (!ret) {
egg_warning ("failed to setup: %s", error->message);
g_error_free (error);
- goto out;
+ goto finish_calibrate;
}
/* step 1 */
@@ -118,7 +120,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
if (!ret) {
egg_warning ("failed to calibrate: %s", error->message);
g_error_free (error);
- goto out;
+ goto finish_calibrate;
}
/* step 2 */
@@ -126,7 +128,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
if (!ret) {
egg_warning ("failed to calibrate: %s", error->message);
g_error_free (error);
- goto out;
+ goto finish_calibrate;
}
/* step 3 */
@@ -134,7 +136,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
if (!ret) {
egg_warning ("failed to calibrate: %s", error->message);
g_error_free (error);
- goto out;
+ goto finish_calibrate;
}
/* step 4 */
@@ -142,24 +144,35 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
if (!ret) {
egg_warning ("failed to calibrate: %s", error->message);
g_error_free (error);
- goto out;
+ goto finish_calibrate;
}
-out:
+
+finish_calibrate:
/* step 4 */
filename = gcm_calibrate_finish (calib, &error);
if (filename == NULL) {
egg_warning ("failed to finish calibrate: %s", error->message);
g_error_free (error);
+ goto out;
}
- /* completed okay */
- if (filename != NULL) {
- /* TODO: need to copy the ICC file to the proper location */
- /* TODO: need to set the new profile and save config */
- /* TODO: need to remove temporary files */
- egg_warning ("need to copy file");
+ /* copy the ICC file to the proper location */
+ destination = gcm_utils_get_profile_destination (filename);
+ ret = gcm_utils_mkdir_and_copy (filename, destination, &error);
+ if (!ret) {
+ egg_warning ("failed to calibrate: %s", error->message);
+ g_error_free (error);
+ goto out;
}
+ /* set the new profile and save config */
+ g_ptr_array_add (profiles_array, g_strdup (destination));
+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), profiles_array->len - 1);
+
+ /* remove temporary file */
+ g_unlink (filename);
+
+out:
if (calib != NULL)
g_object_unref (calib);
@@ -170,6 +183,7 @@ out:
g_error_free (error);
}
g_free (filename);
+ g_free (destination);
}
/**
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 6493d90..6f1d71e 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -311,3 +311,59 @@ gcm_utils_get_profile_filenames (void)
return array;
}
+/**
+ * gcm_utils_mkdir_and_copy:
+ **/
+gboolean
+gcm_utils_mkdir_and_copy (const gchar *source, const gchar *destination, GError **error)
+{
+ gboolean ret;
+ gchar *path;
+ GFile *sourcefile;
+ GFile *destfile;
+ GFile *destpath;
+
+ /* setup paths */
+ sourcefile = g_file_new_for_path (source);
+ path = g_path_get_dirname (destination);
+ destpath = g_file_new_for_path (path);
+ destfile = g_file_new_for_path (destination);
+
+ /* ensure desination exists */
+ ret = g_file_test (path, G_FILE_TEST_EXISTS);
+ if (!ret) {
+ ret = g_file_make_directory_with_parents (destpath, NULL, error);
+ if (!ret)
+ goto out;
+ }
+
+ /* do the copy */
+ egg_debug ("copying from %s to %s", source, path);
+ ret = g_file_copy (sourcefile, destfile, G_FILE_COPY_NONE, NULL, NULL, NULL, error);
+ if (!ret)
+ goto out;
+out:
+ g_free (path);
+ g_object_unref (sourcefile);
+ g_object_unref (destpath);
+ g_object_unref (destfile);
+ return ret;
+}
+
+/**
+ * gcm_utils_get_profile_destination:
+ **/
+gchar *
+gcm_utils_get_profile_destination (const gchar *filename)
+{
+ gchar *basename;
+ gchar *destination;
+
+ /* get destination filename for this source file */
+ basename = g_path_get_basename (filename);
+ destination = g_build_filename (g_get_home_dir (), GCM_PROFILE_PATH, basename, NULL);
+
+ g_free (basename);
+ return destination;
+}
+
diff --git a/src/gcm-utils.h b/src/gcm-utils.h
index a3b492e..59d488b 100644
--- a/src/gcm-utils.h
+++ b/src/gcm-utils.h
@@ -45,6 +45,10 @@ gboolean gcm_utils_set_output_gamma (GnomeRROutput *output,
GcmClut *gcm_utils_get_clut_for_output (GnomeRROutput *output,
GError **error);
GPtrArray *gcm_utils_get_profile_filenames (void);
+gboolean gcm_utils_mkdir_and_copy (const gchar *source,
+ const gchar *destination,
+ GError **error);
+gchar *gcm_utils_get_profile_destination (const gchar *filename);
#endif /* __GCM_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]