[gnome-color-manager] Migrate the old device-profiles.conf to the new location so the user does not have to do it manually
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Migrate the old device-profiles.conf to the new location so the user does not have to do it manually
- Date: Sun, 23 May 2010 17:42:10 +0000 (UTC)
commit a6c63ded454a8cde43ed9559c8b329da645e406e
Author: Richard Hughes <richard hughsie com>
Date: Sun May 23 11:01:39 2010 +0100
Migrate the old device-profiles.conf to the new location so the user does not have to do it manually
data/org.gnome.color-manager.gschema.xml | 5 ++
src/gcm-client.c | 71 ++++++++++++++++++++++++++++++
src/gcm-utils.c | 4 +-
src/gcm-utils.h | 1 +
4 files changed, 79 insertions(+), 2 deletions(-)
---
diff --git a/data/org.gnome.color-manager.gschema.xml b/data/org.gnome.color-manager.gschema.xml
index ce2c1fb..b31f9bb 100644
--- a/data/org.gnome.color-manager.gschema.xml
+++ b/data/org.gnome.color-manager.gschema.xml
@@ -65,5 +65,10 @@
<summary>The duration between sending notifications to recalibrate a printer</summary>
<description>This is the number of seconds in between notifying the user to recalibrate each printer device. Set to 0 to disable the notification.</description>
</key>
+ <key name="done-migration" type="b">
+ <default>false</default>
+ <summary>If the data migration has been done</summary>
+ <description>This is set to TRUE when the data migration does not need to be attempted.</description>
+ </key>
</schema>
</schemalist>
diff --git a/src/gcm-client.c b/src/gcm-client.c
index 962a7dd..1327bae 100644
--- a/src/gcm-client.c
+++ b/src/gcm-client.c
@@ -73,6 +73,7 @@ struct _GcmClientPrivate
gchar *display_name;
GPtrArray *array;
GUdevClient *gudev_client;
+ GSettings *settings;
GcmScreen *screen;
http_t *http;
gboolean loading;
@@ -975,6 +976,68 @@ out:
}
/**
+ * gcm_client_possibly_migrate_config_file:
+ *
+ * Copy the configuration file from ~/.config/gnome-color-manager to ~/.config/color
+ **/
+static gboolean
+gcm_client_possibly_migrate_config_file (GcmClient *client)
+{
+ gchar *dest = NULL;
+ gchar *source = NULL;
+ GFile *gdest = NULL;
+ GFile *gsource = NULL;
+ gboolean ret = FALSE;
+ gboolean done_migration;
+ GError *error = NULL;
+
+ /* have we already attempted this (check first to avoid stating a file */
+ done_migration = g_settings_get_boolean (client->priv->settings, GCM_SETTINGS_DONE_MIGRATION);
+ if (done_migration)
+ goto out;
+
+ /* create default path */
+ source = g_build_filename (g_get_user_config_dir (), "gnome-color-manager", "device-profiles.conf", NULL);
+ gsource = g_file_new_for_path (source);
+
+ /* no old profile */
+ ret = g_file_query_exists (gsource, NULL);
+ if (!ret) {
+ g_settings_set_boolean (client->priv->settings, GCM_SETTINGS_DONE_MIGRATION, TRUE);
+ goto out;
+ }
+
+ /* ensure new root exists */
+ dest = gcm_utils_get_default_config_location ();
+ ret = gcm_utils_mkdir_for_filename (dest, &error);
+ if (!ret) {
+ egg_warning ("failed to create new tree: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* copy to new root */
+ gdest = g_file_new_for_path (dest);
+ ret = g_file_copy (gsource, gdest, G_FILE_COPY_NONE, NULL, NULL, NULL, &error);
+ if (!ret) {
+ egg_warning ("failed to copy: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* do not attempt to migrate this again */
+ g_settings_set_boolean (client->priv->settings, GCM_SETTINGS_DONE_MIGRATION, TRUE);
+out:
+ g_free (source);
+ g_free (dest);
+ if (gsource != NULL)
+ g_object_unref (gsource);
+ if (gdest != NULL)
+ g_object_unref (gdest);
+ return ret;
+}
+
+/**
* gcm_client_add_saved:
**/
gboolean
@@ -987,6 +1050,9 @@ gcm_client_add_saved (GcmClient *client, GError **error)
guint i;
GcmDevice *device;
+ /* copy from old location */
+ gcm_client_possibly_migrate_config_file (client);
+
/* get the config file */
filename = gcm_utils_get_default_config_location ();
egg_debug ("using %s", filename);
@@ -1034,6 +1100,9 @@ gcm_client_add_connected (GcmClient *client, GcmClientColdplug coldplug, GError
g_return_val_if_fail (GCM_IS_CLIENT (client), FALSE);
+ /* copy from old location */
+ gcm_client_possibly_migrate_config_file (client);
+
/* reset */
client->priv->loading_refcount = 0;
@@ -1374,6 +1443,7 @@ gcm_client_init (GcmClient *client)
client->priv->use_threads = FALSE;
client->priv->init_cups = FALSE;
client->priv->init_sane = FALSE;
+ client->priv->settings = g_settings_new (GCM_SETTINGS_SCHEMA);
client->priv->array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
client->priv->screen = gcm_screen_new ();
g_signal_connect (client->priv->screen, "outputs-changed",
@@ -1406,6 +1476,7 @@ gcm_client_finalize (GObject *object)
g_ptr_array_unref (priv->array);
g_object_unref (priv->gudev_client);
g_object_unref (priv->screen);
+ g_object_unref (priv->settings);
if (client->priv->init_cups)
httpClose (priv->http);
#ifdef GCM_USE_SANE
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 10e3367..16be031 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -321,9 +321,9 @@ gcm_utils_mkdir_for_filename (const gchar *filename, GError **error)
GFile *parent_dir = NULL;
/* get a file from the URI / path */
- file = g_file_new_for_uri (filename);
+ file = g_file_new_for_path (filename);
if (file == NULL)
- file = g_file_new_for_path (filename);
+ file = g_file_new_for_uri (filename);
if (file == NULL) {
g_set_error (error, 1, 0, "could not resolve file for %s", filename);
goto out;
diff --git a/src/gcm-utils.h b/src/gcm-utils.h
index 7c1c380..384572f 100644
--- a/src/gcm-utils.h
+++ b/src/gcm-utils.h
@@ -46,6 +46,7 @@
#define GCM_SETTINGS_CALIBRATION_LENGTH "calibration-length"
#define GCM_SETTINGS_SHOW_FINE_TUNING "show-fine-tuning"
#define GCM_SETTINGS_SHOW_NOTIFICATIONS "show-notifications"
+#define GCM_SETTINGS_DONE_MIGRATION "done-migration"
#define GCM_SETTINGS_RECALIBRATE_PRINTER_THRESHOLD "recalibrate-printer-threshold"
#define GCM_SETTINGS_RECALIBRATE_DISPLAY_THRESHOLD "recalibrate-display-threshold"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]