[gnome-color-manager] Add gcm_profile_get_can_delete() and get the permissions from GIO rather than hardcoding a hack



commit 7aaa0648f5791e8e27315f3cd5d32a62a7689833
Author: Richard Hughes <richard hughsie com>
Date:   Tue Jun 1 11:22:15 2010 +0100

    Add gcm_profile_get_can_delete() and get the permissions from GIO rather than hardcoding a hack

 src/gcm-prefs.c   |    3 +--
 src/gcm-profile.c |   36 +++++++++++++++++++++++++++++++++++-
 src/gcm-profile.h |    1 +
 3 files changed, 37 insertions(+), 3 deletions(-)
---
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index 667ba07..c6d09fc 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -2182,8 +2182,7 @@ gcm_prefs_profiles_treeview_clicked_cb (GtkTreeSelection *selection, gpointer us
 	}
 
 	/* set delete sensitivity */
-	ret = (filename != NULL && g_str_has_prefix (filename, "/home/"));
-	egg_debug ("filename: %s", filename);
+	ret = gcm_profile_get_can_delete (profile);
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_profile_delete"));
 	gtk_widget_set_sensitive (widget, ret);
 	if (ret) {
diff --git a/src/gcm-profile.c b/src/gcm-profile.c
index 162e05f..7088452 100644
--- a/src/gcm-profile.c
+++ b/src/gcm-profile.c
@@ -55,6 +55,7 @@ struct _GcmProfilePrivate
 	GcmColorspace		 colorspace;
 	guint			 size;
 	gboolean		 has_vcgt;
+	gboolean		 can_delete;
 	gchar			*description;
 	gchar			*filename;
 	gchar			*copyright;
@@ -83,6 +84,7 @@ enum {
 	PROP_COLORSPACE,
 	PROP_SIZE,
 	PROP_HAS_VCGT,
+	PROP_CAN_DELETE,
 	PROP_WHITE,
 	PROP_BLACK,
 	PROP_RED,
@@ -412,6 +414,16 @@ gcm_profile_set_has_vcgt (GcmProfile *profile, gboolean has_vcgt)
 }
 
 /**
+ * gcm_profile_get_can_delete:
+ **/
+gboolean
+gcm_profile_get_can_delete (GcmProfile *profile)
+{
+	g_return_val_if_fail (GCM_IS_PROFILE (profile), FALSE);
+	return profile->priv->can_delete;
+}
+
+/**
  * gcm_profile_parse_data:
  **/
 gboolean
@@ -451,14 +463,22 @@ gboolean
 gcm_profile_parse (GcmProfile *profile, GFile *file, GError **error)
 {
 	gchar *data = NULL;
-	gboolean ret;
+	gboolean ret = FALSE;
 	gsize length;
 	gchar *filename = NULL;
 	GError *error_local = NULL;
+	GFileInfo *info;
 
 	g_return_val_if_fail (GCM_IS_PROFILE (profile), FALSE);
 	g_return_val_if_fail (file != NULL, FALSE);
 
+	/* find out if the user could delete this profile */
+	info = g_file_query_info (file, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE,
+				  G_FILE_QUERY_INFO_NONE, NULL, error);
+	if (info == NULL)
+		goto out;
+	profile->priv->can_delete = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE);
+
 	/* load files */
 	ret = g_file_load_contents (file, NULL, &data, &length, NULL, &error_local);
 	if (!ret) {
@@ -476,6 +496,8 @@ gcm_profile_parse (GcmProfile *profile, GFile *file, GError **error)
 	filename = g_file_get_path (file);
 	gcm_profile_set_filename (profile, filename);
 out:
+	if (info != NULL)
+		g_object_unref (info);
 	g_free (filename);
 	g_free (data);
 	return ret;
@@ -613,6 +635,9 @@ gcm_profile_get_property (GObject *object, guint prop_id, GValue *value, GParamS
 	case PROP_HAS_VCGT:
 		g_value_set_boolean (value, priv->has_vcgt);
 		break;
+	case PROP_CAN_DELETE:
+		g_value_set_boolean (value, priv->can_delete);
+		break;
 	case PROP_WHITE:
 		g_value_set_object (value, priv->white);
 		break;
@@ -796,6 +821,14 @@ gcm_profile_class_init (GcmProfileClass *klass)
 	g_object_class_install_property (object_class, PROP_HAS_VCGT, pspec);
 
 	/**
+	 * GcmProfile:can-delete:
+	 */
+	pspec = g_param_spec_boolean ("can-delete", NULL, NULL,
+				      FALSE,
+				      G_PARAM_READABLE);
+	g_object_class_install_property (object_class, PROP_CAN_DELETE, pspec);
+
+	/**
 	 * GcmProfile:white:
 	 */
 	pspec = g_param_spec_object ("white", NULL, NULL,
@@ -845,6 +878,7 @@ static void
 gcm_profile_init (GcmProfile *profile)
 {
 	profile->priv = GCM_PROFILE_GET_PRIVATE (profile);
+	profile->priv->can_delete = FALSE;
 	profile->priv->monitor = NULL;
 	profile->priv->kind = GCM_PROFILE_KIND_UNKNOWN;
 	profile->priv->colorspace = GCM_COLORSPACE_UNKNOWN;
diff --git a/src/gcm-profile.h b/src/gcm-profile.h
index afbe776..c42299b 100644
--- a/src/gcm-profile.h
+++ b/src/gcm-profile.h
@@ -84,6 +84,7 @@ gboolean	 gcm_profile_save			(GcmProfile	*profile,
 							 const gchar	*filename,
 							 GError		**error);
 const gchar	*gcm_profile_get_checksum		(GcmProfile	*profile);
+gboolean	 gcm_profile_get_can_delete		(GcmProfile	*profile);
 GcmClut		*gcm_profile_generate_vcgt		(GcmProfile	*profile,
 							 guint		 size);
 GcmClut		*gcm_profile_generate_curve		(GcmProfile	*profile,



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