[gnome-color-manager] Add and remove profiles from gcm-viewer as they are added and removed from the store



commit 5c64b50a76ab97e78a08f6c1dec95612b3b60c5d
Author: Richard Hughes <richard hughsie com>
Date:   Thu Oct 14 13:52:48 2010 +0100

    Add and remove profiles from gcm-viewer as they are added and removed from the store

 libcolor-glib/gcm-profile-store.c |    2 +-
 libcolor-glib/gcm-profile.c       |   10 ++++++++--
 src/gcm-viewer.c                  |   36 +++++++++++++++++++++++++++++++-----
 3 files changed, 40 insertions(+), 8 deletions(-)
---
diff --git a/libcolor-glib/gcm-profile-store.c b/libcolor-glib/gcm-profile-store.c
index a7bc04c..c6bb693 100644
--- a/libcolor-glib/gcm-profile-store.c
+++ b/libcolor-glib/gcm-profile-store.c
@@ -255,7 +255,7 @@ gcm_profile_store_add_profile (GcmProfileStore *profile_store, GFile *file)
 	/* add to array */
 	egg_debug ("parsed new profile '%s'", filename);
 	g_ptr_array_add (priv->profile_array, g_object_ref (profile));
-	g_signal_connect (profile, "notify::filename", G_CALLBACK(gcm_profile_store_notify_filename_cb), profile_store);
+	g_signal_connect (profile, "notify::file", G_CALLBACK(gcm_profile_store_notify_filename_cb), profile_store);
 
 	/* emit a signal */
 	egg_debug ("emit added (and changed): %s", filename);
diff --git a/libcolor-glib/gcm-profile.c b/libcolor-glib/gcm-profile.c
index e0c6a49..0493baa 100644
--- a/libcolor-glib/gcm-profile.c
+++ b/libcolor-glib/gcm-profile.c
@@ -878,7 +878,7 @@ out:
  * @file: A GFile pointing to a profile
  * @error: A #GError, or %NULL
  *
- * Parses a profile filename, filling in all the details possible.
+ * Parses a profile file, filling in all the details possible.
  *
  * Return value: %TRUE for success
  *
@@ -1120,7 +1120,10 @@ out:
 /**
  * gcm_profile_create_from_chroma:
  * @profile: A valid #GcmProfile
- * @filename: the data to parse
+ * @red: primary color data
+ * @green: primary color data
+ * @blue: primary color data
+ * @white: whitepoint data
  * @error: A #GError, or %NULL
  *
  * Saves the profile data to a file.
@@ -1484,6 +1487,9 @@ gcm_profile_file_monitor_changed_cb (GFileMonitor *monitor, GFile *file, GFile *
 	if (priv->file != NULL)
 		g_object_unref (priv->file);
 	priv->file = NULL;
+	g_free (priv->filename);
+	priv->filename = NULL;
+	g_object_notify (G_OBJECT (profile), "file");
 out:
 	return;
 }
diff --git a/src/gcm-viewer.c b/src/gcm-viewer.c
index bba788b..0ab319d 100644
--- a/src/gcm-viewer.c
+++ b/src/gcm-viewer.c
@@ -274,8 +274,9 @@ gcm_viewer_profile_delete_cb (GtkWidget *widget, GcmViewerPrivate *viewer)
 	GtkWidget *dialog;
 	GtkResponseType response;
 	GtkWindow *window;
-	gint retval;
-	const gchar *filename;
+	GError *error = NULL;
+	GFile *file = NULL;
+	gboolean ret;
 	GcmProfile *profile;
 	GtkTreeSelection *selection;
 	GtkTreeModel *model;
@@ -311,10 +312,13 @@ gcm_viewer_profile_delete_cb (GtkWidget *widget, GcmViewerPrivate *viewer)
 			    -1);
 
 	/* try to remove file */
-	filename = gcm_profile_get_filename (profile);
-	retval = g_unlink (filename);
-	if (retval != 0)
+	file = gcm_profile_get_file (profile);
+	ret = g_file_delete (file, NULL, &error);
+	if (!ret) {
+		egg_warning ("failed to be deleted: %s", error->message);
+		g_error_free (error);
 		goto out;
+	}
 out:
 	return;
 }
@@ -1019,6 +1023,24 @@ gcm_viewer_setup_graph_combobox (GcmViewerPrivate *viewer, GtkWidget *widget)
 }
 
 /**
+ * gcm_viewer_profile_store_added_cb:
+ **/
+static void
+gcm_viewer_profile_store_added_cb (GcmProfileStore *profile_store, GcmProfile *profile, GcmViewerPrivate *viewer)
+{
+	gcm_viewer_update_profile_list (viewer);
+}
+
+/**
+ * gcm_viewer_profile_store_removed_cb:
+ **/
+static void
+gcm_viewer_profile_store_removed_cb (GcmProfileStore *profile_store, GcmProfile *profile, GcmViewerPrivate *viewer)
+{
+	gcm_viewer_update_profile_list (viewer);
+}
+
+/**
  * main:
  **/
 int
@@ -1079,6 +1101,10 @@ main (int argc, char **argv)
 
 	/* maintain a list of profiles */
 	viewer->profile_store = gcm_profile_store_new ();
+	g_signal_connect (viewer->profile_store, "added",
+			  G_CALLBACK (gcm_viewer_profile_store_added_cb), viewer);
+	g_signal_connect (viewer->profile_store, "removed",
+			  G_CALLBACK (gcm_viewer_profile_store_removed_cb), viewer);
 
 	/* create list stores */
 	viewer->list_store_profiles = gtk_list_store_new (GCM_PROFILES_COLUMN_LAST, G_TYPE_STRING,



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