[gnome-color-manager] Add GcmProfileSearchFlags so we can control what kind of profiles are loaded



commit 6dcc2533d218a9f00b79e5308fb0cfda1a6fca4d
Author: Richard Hughes <richard hughsie com>
Date:   Fri Jun 25 11:23:12 2010 +0100

    Add GcmProfileSearchFlags so we can control what kind of profiles are loaded

 src/cc-color-panel.c    |    2 +-
 src/gcm-import.c        |    4 +-
 src/gcm-profile-store.c |  126 +++++++++++++++++++++++++++-------------------
 src/gcm-profile-store.h |   13 ++++-
 src/gcm-self-test.c     |    2 +-
 src/gcm-viewer.c        |    2 +-
 6 files changed, 90 insertions(+), 59 deletions(-)
---
diff --git a/src/cc-color-panel.c b/src/cc-color-panel.c
index 680bec0..abc4dcf 100644
--- a/src/cc-color-panel.c
+++ b/src/cc-color-panel.c
@@ -2318,7 +2318,7 @@ cc_color_panel_startup_idle_cb (CcColorPanel *panel)
 	gint intent_softproof = -1;
 
 	/* search the disk for profiles */
-	gcm_profile_store_search_default (panel->priv->profile_store);
+	gcm_profile_store_search (panel->priv->profile_store, GCM_PROFILE_STORE_SEARCH_ALL);
 	g_signal_connect (panel->priv->profile_store, "changed", G_CALLBACK(cc_color_panel_profile_store_changed_cb), panel);
 
 	/* setup RGB combobox */
diff --git a/src/gcm-import.c b/src/gcm-import.c
index 0b3bacd..1e77a45 100644
--- a/src/gcm-import.c
+++ b/src/gcm-import.c
@@ -164,9 +164,9 @@ main (int argc, char **argv)
 		goto out;
 	}
 
-	/* check file does't already exist as systemwide */
+	/* check file does't already exist as system-wide */
 	profile_store = gcm_profile_store_new ();
-	gcm_profile_store_search_default (profile_store);
+	gcm_profile_store_search (profile_store, GCM_PROFILE_STORE_SEARCH_SYSTEM);
 	profile_tmp = gcm_profile_store_get_by_checksum (profile_store, gcm_profile_get_checksum (profile));
 	if (profile_tmp != NULL) {
 		/* TRANSLATORS: color profile already been installed */
diff --git a/src/gcm-profile-store.c b/src/gcm-profile-store.c
index c165ebb..a1d9922 100644
--- a/src/gcm-profile-store.c
+++ b/src/gcm-profile-store.c
@@ -273,33 +273,43 @@ out:
  * gcm_profile_store_file_monitor_changed_cb:
  **/
 static void
-gcm_profile_store_file_monitor_changed_cb (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, GcmProfileStore *profile_store)
+gcm_profile_store_file_monitor_changed_cb (GFileMonitor *monitor, GFile *file, GFile *other_file,
+					   GFileMonitorEvent event_type, GcmProfileStore *profile_store)
 {
 	gchar *path = NULL;
+	gchar *parent_path = NULL;
+	GFile *parent = NULL;
 
 	/* only care about created objects */
 	if (event_type != G_FILE_MONITOR_EVENT_CREATED)
 		goto out;
 
-	/* just rescan everything */
+	/* ignore temp files */
 	path = g_file_get_path (file);
 	if (g_strrstr (path, ".goutputstream") != NULL) {
 		egg_debug ("ignoring gvfs temporary file");
 		goto out;
 	}
-	egg_debug ("%s was added, rescanning everything", path);
-	gcm_profile_store_search_default (profile_store);
+
+	/* just rescan the correct directory */
+	parent = g_file_get_parent (file);
+	parent_path = g_file_get_path (parent);
+	egg_debug ("%s was added, rescanning %s", path, parent_path);
+	gcm_profile_store_search_path (profile_store, parent_path);
 out:
+	if (parent != NULL)
+		g_object_unref (parent);
 	g_free (path);
+	g_free (parent_path);
 }
 
 /**
- * gcm_profile_store_search_by_path:
+ * gcm_profile_store_search_path:
  *
  * Return value: if any profile were added
  **/
 gboolean
-gcm_profile_store_search_by_path (GcmProfileStore *profile_store, const gchar *path)
+gcm_profile_store_search_path (GcmProfileStore *profile_store, const gchar *path)
 {
 	GDir *dir = NULL;
 	GError *error = NULL;
@@ -361,7 +371,7 @@ gcm_profile_store_search_by_path (GcmProfileStore *profile_store, const gchar *p
 
 		/* make the compete path */
 		full_path = g_build_filename (path, name, NULL);
-		ret = gcm_profile_store_search_by_path (profile_store, full_path);
+		ret = gcm_profile_store_search_path (profile_store, full_path);
 		if (ret)
 			success = TRUE;
 		g_free (full_path);
@@ -410,7 +420,7 @@ gcm_profile_store_add_profiles_from_mounted_volume (GcmProfileStore *profile_sto
 	/* only scan hfs volumes for OSX */
 	if (g_strcmp0 (type, "hfs") == 0) {
 		path = g_build_filename (path_root, "Library", "ColorSync", "Profiles", "Displays", NULL);
-		ret = gcm_profile_store_search_by_path (profile_store, path);
+		ret = gcm_profile_store_search_path (profile_store, path);
 		if (ret)
 			success = TRUE;
 		g_free (path);
@@ -424,21 +434,21 @@ gcm_profile_store_add_profiles_from_mounted_volume (GcmProfileStore *profile_sto
 
 		/* Windows XP */
 		path = g_build_filename (path_root, "Windows", "system32", "spool", "drivers", "color", NULL);
-		ret = gcm_profile_store_search_by_path (profile_store, path);
+		ret = gcm_profile_store_search_path (profile_store, path);
 		if (ret)
 			success = TRUE;
 		g_free (path);
 
 		/* Windows 2000 */
 		path = g_build_filename (path_root, "Winnt", "system32", "spool", "drivers", "color", NULL);
-		ret = gcm_profile_store_search_by_path (profile_store, path);
+		ret = gcm_profile_store_search_path (profile_store, path);
 		if (ret)
 			success = TRUE;
 		g_free (path);
 
 		/* Windows 98 and ME */
 		path = g_build_filename (path_root, "Windows", "System", "Color", NULL);
-		ret = gcm_profile_store_search_by_path (profile_store, path);
+		ret = gcm_profile_store_search_path (profile_store, path);
 		if (ret)
 			success = TRUE;
 		g_free (path);
@@ -478,12 +488,12 @@ gcm_profile_store_add_profiles_from_mounted_volumes (GcmProfileStore *profile_st
 }
 
 /**
- * gcm_profile_store_add_profiles:
+ * gcm_profile_store_search:
  *
  * Return value: if any profile were added
  **/
 gboolean
-gcm_profile_store_search_default (GcmProfileStore *profile_store)
+gcm_profile_store_search (GcmProfileStore *profile_store, GcmProfileSearchFlags flags)
 {
 	gchar *path;
 	gboolean ret;
@@ -492,55 +502,67 @@ gcm_profile_store_search_default (GcmProfileStore *profile_store)
 	GcmProfileStorePrivate *priv = profile_store->priv;
 
 	/* get OSX and Linux system-wide profiles */
-	ret = gcm_profile_store_search_by_path (profile_store, "/usr/share/color/icc");
-	if (ret)
-		success = TRUE;
-	ret = gcm_profile_store_search_by_path (profile_store, "/usr/local/share/color/icc");
-	if (ret)
-		success = TRUE;
-	ret = gcm_profile_store_search_by_path (profile_store, "/Library/ColorSync/Profiles/Displays");
-	if (ret)
-		success = TRUE;
-
-	/* get OSX and Windows system-wide profiles when using Linux */
-	ret = g_settings_get_boolean (priv->settings, GCM_SETTINGS_USE_PROFILES_FROM_VOLUMES);
-	if (ret) {
-		ret = gcm_profile_store_add_profiles_from_mounted_volumes (profile_store);
+	if (flags == GCM_PROFILE_STORE_SEARCH_ALL ||
+	    flags & GCM_PROFILE_STORE_SEARCH_SYSTEM) {
+		ret = gcm_profile_store_search_path (profile_store, "/usr/share/color/icc");
+		if (ret)
+			success = TRUE;
+		ret = gcm_profile_store_search_path (profile_store, "/usr/local/share/color/icc");
+		if (ret)
+			success = TRUE;
+		ret = gcm_profile_store_search_path (profile_store, "/Library/ColorSync/Profiles/Displays");
 		if (ret)
 			success = TRUE;
 	}
 
+	/* get OSX and Windows system-wide profiles when using Linux */
+	if (flags == GCM_PROFILE_STORE_SEARCH_ALL ||
+	    flags & GCM_PROFILE_STORE_SEARCH_VOLUMES) {
+		ret = g_settings_get_boolean (priv->settings, GCM_SETTINGS_USE_PROFILES_FROM_VOLUMES);
+		if (ret) {
+			ret = gcm_profile_store_add_profiles_from_mounted_volumes (profile_store);
+			if (ret)
+				success = TRUE;
+		}
+	}
+
 	/* get Linux per-user profiles */
-	path = g_build_filename (g_get_user_data_dir (), "icc", NULL);
-	ret = gcm_utils_mkdir_with_parents (path, &error);
-	if (!ret) {
-		egg_error ("failed to create directory on startup: %s", error->message);
-		g_error_free (error);
-	} else {
-		ret = gcm_profile_store_search_by_path (profile_store, path);
+	if (flags == GCM_PROFILE_STORE_SEARCH_ALL ||
+	    flags & GCM_PROFILE_STORE_SEARCH_USER) {
+		path = g_build_filename (g_get_user_data_dir (), "icc", NULL);
+		ret = gcm_utils_mkdir_with_parents (path, &error);
+		if (!ret) {
+			egg_error ("failed to create directory on startup: %s", error->message);
+			g_error_free (error);
+		} else {
+			ret = gcm_profile_store_search_path (profile_store, path);
+			if (ret)
+				success = TRUE;
+		}
+		g_free (path);
+
+		/* get per-user profiles from obsolete location */
+		path = g_build_filename (g_get_home_dir (), ".color", "icc", NULL);
+		ret = gcm_profile_store_search_path (profile_store, path);
 		if (ret)
 			success = TRUE;
-	}
-	g_free (path);
-
-	/* get per-user profiles from obsolete location */
-	path = g_build_filename (g_get_home_dir (), ".color", "icc", NULL);
-	ret = gcm_profile_store_search_by_path (profile_store, path);
-	if (ret)
-		success = TRUE;
-	g_free (path);
+		g_free (path);
 
-	/* get OSX per-user profiles */
-	path = g_build_filename (g_get_home_dir (), "Library", "ColorSync", "Profiles", NULL);
-	ret = gcm_profile_store_search_by_path (profile_store, path);
-	if (ret)
-		success = TRUE;
-	g_free (path);
+		/* get OSX per-user profiles */
+		path = g_build_filename (g_get_home_dir (), "Library", "ColorSync", "Profiles", NULL);
+		ret = gcm_profile_store_search_path (profile_store, path);
+		if (ret)
+			success = TRUE;
+		g_free (path);
+	}
 
 	/* get machine specific profiles */
-	ret = gcm_profile_store_search_by_path (profile_store, "/var/lib/color/icc");
-	if (ret)
-		success = TRUE;
+	if (flags == GCM_PROFILE_STORE_SEARCH_ALL ||
+	    flags & GCM_PROFILE_STORE_SEARCH_MACHINE) {
+		ret = gcm_profile_store_search_path (profile_store, "/var/lib/color/icc");
+		if (ret)
+			success = TRUE;
+	}
 
 	return success;
 }
diff --git a/src/gcm-profile-store.h b/src/gcm-profile-store.h
index 7546ae3..5a648e6 100644
--- a/src/gcm-profile-store.h
+++ b/src/gcm-profile-store.h
@@ -59,6 +59,14 @@ struct _GcmProfileStoreClass
 	void (*_gcm_reserved5) (void);
 };
 
+typedef enum {
+	GCM_PROFILE_STORE_SEARCH_ALL		= 0,
+	GCM_PROFILE_STORE_SEARCH_SYSTEM		= 1,
+	GCM_PROFILE_STORE_SEARCH_VOLUMES	= 2,
+	GCM_PROFILE_STORE_SEARCH_USER		= 4,
+	GCM_PROFILE_STORE_SEARCH_MACHINE	= 8
+} GcmProfileSearchFlags;
+
 GType		 gcm_profile_store_get_type		(void);
 GcmProfileStore	*gcm_profile_store_new			(void);
 
@@ -67,8 +75,9 @@ GcmProfile	*gcm_profile_store_get_by_filename	(GcmProfileStore	*profile_store,
 GcmProfile	*gcm_profile_store_get_by_checksum	(GcmProfileStore	*profile_store,
 							 const gchar		*checksum);
 GPtrArray	*gcm_profile_store_get_array		(GcmProfileStore	*profile_store);
-gboolean	 gcm_profile_store_search_default	(GcmProfileStore	*profile_store);
-gboolean	 gcm_profile_store_search_by_path	(GcmProfileStore	*profile_store,
+gboolean	 gcm_profile_store_search		(GcmProfileStore	*profile_store,
+							 GcmProfileSearchFlags	 search_flags);
+gboolean	 gcm_profile_store_search_path		(GcmProfileStore	*profile_store,
 							 const gchar		*path);
 
 G_END_DECLS
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index a2a2cce..d23b7f8 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -874,7 +874,7 @@ gcm_test_profile_store_func (void)
 
 	/* add test files */
 	filename = gcm_test_get_data_file (".");
-	ret = gcm_profile_store_search_by_path (store, filename);
+	ret = gcm_profile_store_search_path (store, filename);
 	g_assert (ret);
 	g_free (filename);
 
diff --git a/src/gcm-viewer.c b/src/gcm-viewer.c
index e65f039..2a44c5b 100644
--- a/src/gcm-viewer.c
+++ b/src/gcm-viewer.c
@@ -859,7 +859,7 @@ gcm_viewer_startup_phase1_idle_cb (GcmViewerPrivate *viewer)
 	GtkTreePath *path;
 
 	/* search the disk for profiles */
-	gcm_profile_store_search_default (viewer->profile_store);
+	gcm_profile_store_search (viewer->profile_store, GCM_PROFILE_STORE_SEARCH_ALL);
 	g_signal_connect (viewer->profile_store, "changed", G_CALLBACK(gcm_viewer_profile_store_changed_cb), viewer);
 
 	/* update list of profiles */



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