[gnome-color-manager] Do not allow the user to remove automatically-added profiles from devices



commit 118f731a6ee93d292981a0f677c065815cd4743c
Author: Richard Hughes <richard hughsie com>
Date:   Wed Mar 9 16:25:54 2011 +0000

    Do not allow the user to remove automatically-added profiles from devices

 src/cc-color-panel.c          |   13 +++++++++++--
 src/gcm-list-store-profiles.c |   13 +++++++++++--
 src/gcm-list-store-profiles.h |    1 +
 3 files changed, 23 insertions(+), 4 deletions(-)
---
diff --git a/src/cc-color-panel.c b/src/cc-color-panel.c
index a7e8002..f174816 100644
--- a/src/cc-color-panel.c
+++ b/src/cc-color-panel.c
@@ -1480,6 +1480,7 @@ cc_color_panel_profile_treeview_clicked_cb (GtkTreeSelection *selection,
 	gboolean is_default;
 	GtkWidget *widget;
 	CdProfile *profile;
+	CdDeviceRelation relation;
 
 	/* This will only work in single or browse selection mode! */
 	if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
@@ -1499,6 +1500,7 @@ cc_color_panel_profile_treeview_clicked_cb (GtkTreeSelection *selection,
 	gtk_tree_model_get (model, &iter,
 			    GCM_LIST_STORE_PROFILES_COLUMN_PROFILE, &profile,
 			    GCM_LIST_STORE_PROFILES_COLUMN_IS_DEFAULT, &is_default,
+			    GCM_LIST_STORE_PROFILES_COLUMN_RELATION, &relation,
 			    -1);
 	g_debug ("selected profile = %s",
 		 cd_profile_get_filename (profile));
@@ -1508,10 +1510,17 @@ cc_color_panel_profile_treeview_clicked_cb (GtkTreeSelection *selection,
 						     "button_assign_make_default"));
 	gtk_widget_set_sensitive (widget, !is_default);
 
-	/* we can remove it now */
+	/* we can only remove hard relationships */
 	widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
 						     "button_assign_remove"));
-	gtk_widget_set_sensitive (widget, TRUE);
+	if (relation == CD_DEVICE_RELATION_HARD) {
+		gtk_widget_set_tooltip_text (widget, "");
+		gtk_widget_set_sensitive (widget, TRUE);
+	} else {
+		/* TRANSLATORS: this is when an auto-added profile cannot be removed */
+		gtk_widget_set_tooltip_text (widget, _("Cannot remove automatically added profile"));
+		gtk_widget_set_sensitive (widget, FALSE);
+	}
 	g_object_unref (profile);
 }
 
diff --git a/src/gcm-list-store-profiles.c b/src/gcm-list-store-profiles.c
index 08f8d84..a8b2f3b 100644
--- a/src/gcm-list-store-profiles.c
+++ b/src/gcm-list-store-profiles.c
@@ -66,6 +66,7 @@ gcm_list_store_refresh_profiles (GtkListStore *list_store)
 	CdProfile *profile;
 	guint i;
 	GcmListStoreProfilesPrivate *priv = GCM_LIST_STORE_PROFILES(list_store)->priv;
+	CdDeviceRelation relation = CD_DEVICE_RELATION_UNKNOWN;
 
 	/* clear existing list */
 	gtk_list_store_clear (list_store);
@@ -74,15 +75,23 @@ gcm_list_store_refresh_profiles (GtkListStore *list_store)
 	profiles = cd_device_get_profiles (priv->device);
 	for (i=0; i<profiles->len; i++) {
 		profile = g_ptr_array_index (profiles, i);
+
+#if CD_CHECK_VERSION(0,1,4)
+		/* find the profile relationship */
+		relation = cd_device_get_profile_relation (priv->device,
+							   profile,
+							   NULL, NULL);
+#endif
+
 		gtk_list_store_append (list_store, &iter);
 		gtk_list_store_set (list_store, &iter,
 				    GCM_LIST_STORE_PROFILES_COLUMN_PROFILE, profile,
 				    GCM_LIST_STORE_PROFILES_COLUMN_SORT, (i == 0) ? "0" : "1",
 				    GCM_LIST_STORE_PROFILES_COLUMN_IS_DEFAULT, (i == 0),
 				    GCM_LIST_STORE_PROFILES_COLUMN_TOOLTIP, cc_color_panel_profile_get_tooltip (profile),
+				    GCM_LIST_STORE_PROFILES_COLUMN_RELATION, relation,
 				    -1);
 	}
-
 	g_ptr_array_unref (profiles);
 }
 
@@ -125,7 +134,7 @@ gcm_list_store_profiles_set_from_device (GtkListStore *list_store, CdDevice *dev
 static void
 gcm_list_store_profiles_init (GcmListStoreProfiles *list_store)
 {
-	GType types[] = { G_TYPE_STRING, CD_TYPE_PROFILE, G_TYPE_BOOLEAN, G_TYPE_STRING };
+	GType types[] = { G_TYPE_STRING, CD_TYPE_PROFILE, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_UINT };
 	list_store->priv = GCM_LIST_STORE_PROFILES_GET_PRIVATE (list_store);
 	gtk_list_store_set_column_types (GTK_LIST_STORE (list_store), GCM_LIST_STORE_PROFILES_COLUMN_LAST, types);
 }
diff --git a/src/gcm-list-store-profiles.h b/src/gcm-list-store-profiles.h
index 73fcab4..d5a5ba0 100644
--- a/src/gcm-list-store-profiles.h
+++ b/src/gcm-list-store-profiles.h
@@ -39,6 +39,7 @@ enum {
 	GCM_LIST_STORE_PROFILES_COLUMN_PROFILE,
 	GCM_LIST_STORE_PROFILES_COLUMN_IS_DEFAULT,
 	GCM_LIST_STORE_PROFILES_COLUMN_TOOLTIP,
+	GCM_LIST_STORE_PROFILES_COLUMN_RELATION,
 	GCM_LIST_STORE_PROFILES_COLUMN_LAST
 };
 



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