[gnome-color-manager] Add two fixes to cope with a missing profile, which happens the first time you start gcm-prefs
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Add two fixes to cope with a missing profile, which happens the first time you start gcm-prefs
- Date: Thu, 5 Nov 2009 11:13:14 +0000 (UTC)
commit de903c2a9c5634c9b97ca19b02fef77a10398543
Author: Richard Hughes <richard hughsie com>
Date: Thu Nov 5 11:12:29 2009 +0000
Add two fixes to cope with a missing profile, which happens the first time you start gcm-prefs
src/gcm-device.c | 51 +++++++++++++++++++++++++++++++--------------------
src/gcm-prefs.c | 3 +--
2 files changed, 32 insertions(+), 22 deletions(-)
---
diff --git a/src/gcm-device.c b/src/gcm-device.c
index b211212..20870df 100644
--- a/src/gcm-device.c
+++ b/src/gcm-device.c
@@ -115,25 +115,27 @@ gcm_device_load_from_profile (GcmDevice *device, GError **error)
goto out;
}
- /* create new profile instance */
- profile = gcm_profile_new ();
+ /* load the profile if it's set */
+ if (device->priv->profile != NULL) {
+
+ /* create new profile instance */
+ profile = gcm_profile_new ();
+ ret = gcm_profile_parse (profile, device->priv->profile, &error_local);
+ if (!ret) {
+ if (error != NULL)
+ *error = g_error_new (1, 0, "failed to set from profile: %s", error_local->message);
+ g_error_free (error_local);
+ goto out;
+ }
- /* load the profile */
- ret = gcm_profile_parse (profile, device->priv->profile, &error_local);
- if (!ret) {
- if (error != NULL)
- *error = g_error_new (1, 0, "failed to set from profile: %s", error_local->message);
- g_error_free (error_local);
- goto out;
+ /* copy the description */
+ g_free (device->priv->copyright);
+ g_free (device->priv->description);
+ g_object_get (profile,
+ "copyright", &device->priv->copyright,
+ "description", &device->priv->description,
+ NULL);
}
-
- /* copy the description */
- g_free (device->priv->copyright);
- g_free (device->priv->description);
- g_object_get (profile,
- "copyright", &device->priv->copyright,
- "description", &device->priv->description,
- NULL);
out:
if (profile != NULL)
g_object_unref (profile);
@@ -157,7 +159,7 @@ gboolean
gcm_device_load (GcmDevice *device, GError **error)
{
gboolean ret;
- GKeyFile *file;
+ GKeyFile *file = NULL;
GError *error_local = NULL;
gchar *filename = NULL;
@@ -167,6 +169,14 @@ gcm_device_load (GcmDevice *device, GError **error)
/* get default config */
filename = gcm_device_get_default_config_location ();
+ /* check we have a config, or is this first start */
+ ret = g_file_test (filename, G_FILE_TEST_EXISTS);
+ if (!ret) {
+ /* we have no profile to load from */
+ ret = TRUE;
+ goto out;
+ }
+
/* load existing file */
file = g_key_file_new ();
ret = g_key_file_load_from_file (file, filename, G_KEY_FILE_NONE, &error_local);
@@ -208,7 +218,8 @@ gcm_device_load (GcmDevice *device, GError **error)
}
out:
g_free (filename);
- g_key_file_free (file);
+ if (file != NULL)
+ g_key_file_free (file);
return ret;
}
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index aa83a05..d16e33e 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -532,14 +532,13 @@ gcm_prefs_profile_combo_changed_cb (GtkWidget *widget, gpointer data)
if (active < profiles_array->len)
filename = g_ptr_array_index (profiles_array, active);
- egg_debug ("profile=%s", filename);
/* see if it's changed */
g_object_get (current_device,
"profile", &profile_old,
"type", &type,
NULL);
- egg_warning ("old: %s, new:%s", profile_old, filename);
+ egg_debug ("old: %s, new:%s", profile_old, filename);
changed = ((g_strcmp0 (profile_old, filename) != 0));
/* set new profile */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]