[gnome-system-tools/users-ui-redesign] Support user profiles descriptions



commit 8ca696c69ea2387e2bd71d9ea2e7372da2098e90
Author: Milan Bouchet-Valat <nalimilan club fr>
Date:   Tue Nov 17 19:52:35 2009 +0100

    Support user profiles descriptions
    
    Profiles configuration file can now provide a description that is displayed in a label associated with radio buttons. For this gst_user_profiles_get_names() becomes _get_list(), and simply returns a pointer to the internal profiles list, so that we can access names and descriptions. Add Pango to the dependencies as we now access it directly.

 configure.in              |    1 +
 interfaces/users.ui       |    4 +-
 src/users/table.c         |   60 ++++++++++++++++++++++++++++++++++++--------
 src/users/user-profiles.c |   13 +++------
 src/users/user-profiles.h |    3 +-
 src/users/user-settings.c |    4 +++
 src/users/users-tool.c    |   10 +++----
 7 files changed, 67 insertions(+), 28 deletions(-)
---
diff --git a/configure.in b/configure.in
index 3e9064b..3eab918 100644
--- a/configure.in
+++ b/configure.in
@@ -78,6 +78,7 @@ dnl =====================================================
 PKG_CHECK_MODULES(GST_DEPENDS,[
 			   gtk+-2.0 >= $GTK_REQUIRED
 			   gmodule-export-2.0
+			   pango
 			   gconf-2.0 >= $GCONF_REQUIRED
 			   liboobs-1 >= $LIBOOBS_REQUIRED
 			   system-tools-backends-2.0 >= $STB_REQUIRED
diff --git a/interfaces/users.ui b/interfaces/users.ui
index 3ae6d21..3c2fc47 100644
--- a/interfaces/users.ui
+++ b/interfaces/users.ui
@@ -2746,10 +2746,10 @@
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="label2">
+              <object class="GtkLabel" id="user_profile_custom_label">
                 <property name="visible">True</property>
+                <property name="xalign">0</property>
                 <property name="label" translatable="yes">This account is using special settings that have been defined manually. Use the Advanced dialog to tune them.</property>
-                <property name="justify">fill</property>
                 <property name="wrap">True</property>
                 <attributes>
                   <attribute name="size" value="9500"/>
diff --git a/src/users/table.c b/src/users/table.c
index 99bff20..75e7d66 100644
--- a/src/users/table.c
+++ b/src/users/table.c
@@ -18,12 +18,14 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  *
- * Authors: Carlos Garnacho Parro <garparr teleline es>
+ * Authors: Carlos Garnacho Parro <garparr teleline es>,
+ *          Milan Bouchet-Valat <nalimilan club fr>.
  */
 
 #include <config.h>
 #include "gst.h"
 #include <glib/gi18n.h>
+#include <pango/pango.h>
 
 #include "table.h"
 #include "users-table.h"
@@ -120,53 +122,89 @@ setup_shells_combo (GstUsersTool *tool)
 
 void
 table_populate_profiles (GstUsersTool *tool,
-			 GList        *names)
+                         GList *profiles)
 {
+	GstUserProfile *profile;
 	GtkWidget *table;
 	GtkWidget *radio;
+	GtkWidget *label;
 	GHashTable *radios;
+	GHashTable *labels;
 	GHashTableIter iter;
 	gpointer value;
+	GList *l;
 	static int ncols, nrows; /* original size of the table */
+	PangoAttribute *attribute;
+	PangoAttrList *attributes;
 	int i;
 
 	table = gst_dialog_get_widget (GST_TOOL (tool)->main_dialog, "user_profile_table");
 	radios = g_object_get_data (G_OBJECT (table), "radio_buttons");
+	labels = g_object_get_data (G_OBJECT (table), "labels");
 
-	/* create the hash table to hold references to radio buttons */
+	/* create the hash table to hold references to radio buttons and their labels */
 	if (radios == NULL) {
 		/* keys are names owned by GstUserProfiles, values are pointers:
 		 * no need to free anything */
 		radios = g_hash_table_new (g_str_hash, g_str_equal);
+		labels = g_hash_table_new (g_str_hash, g_str_equal);
 		g_object_set_data (G_OBJECT (table), "radio_buttons", radios);
+		g_object_set_data (G_OBJECT (table), "labels", labels);
 		g_object_get (G_OBJECT (table), "n-rows", &nrows, "n-columns", &ncols, NULL);
 	}
 	else {
-		/* free the radio buttons if they were already here */
+		/* free the radio buttons and labels if they were already here */
 		g_hash_table_iter_init (&iter, radios);
 		while (g_hash_table_iter_next (&iter, NULL, &value)) {
 			gtk_widget_destroy (GTK_WIDGET (value));
 		}
 
+		g_hash_table_iter_init (&iter, labels);
+		while (g_hash_table_iter_next (&iter, NULL, &value)) {
+			gtk_widget_destroy (GTK_WIDGET (value));
+		}
+
 		g_hash_table_remove_all (radios);
+		g_hash_table_remove_all (labels);
 	}
 
-	/* increase table's size based on it's "empty" size */
-	gtk_table_resize (GTK_TABLE (table), g_list_length (names) + nrows, ncols);
+	/* increase table's size based on it's "empty" size
+	 * we leave an empty line after a radio and its decription label */
+	gtk_table_resize (GTK_TABLE (table), g_list_length (profiles) * 3 + nrows, ncols);
 
 	radio = gst_dialog_get_widget (GST_TOOL (tool)->main_dialog, "user_profile_custom");
-
-	for (i = 0; names; i++) {
+	label = gst_dialog_get_widget (GST_TOOL (tool)->main_dialog, "user_profile_custom_label");
+
+	attributes = pango_attr_list_new ();
+	attribute = pango_attr_size_new (9 * PANGO_SCALE);
+	pango_attr_list_insert (attributes, attribute);
+	attribute = pango_attr_style_new (PANGO_STYLE_ITALIC);
+	pango_attr_list_insert (attributes, attribute);
+	gtk_label_set_attributes (GTK_LABEL (label), attributes);
+
+	i = 1; /* empty line after "Custom" radio and label */
+	for (l = profiles; l; l = l->next) {
+		profile = (GstUserProfile *) l->data;
 		radio = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
-		                                                     (char *) names->data);
+		                                                     profile->name);
+		label = gtk_label_new (profile->description);
+		gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+		gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+		gtk_misc_set_padding (GTK_MISC (label), 16, 0);
+		gtk_label_set_attributes (GTK_LABEL (label), attributes);
 
 		gtk_table_attach_defaults (GTK_TABLE (table),
 		                           radio, 0, ncols,
 		                           nrows + i, nrows + i + 1);
+		gtk_table_attach_defaults (GTK_TABLE (table),
+		                           label, 1, ncols,
+		                           nrows + i + 1, nrows + i + 2);
 		gtk_widget_show (radio);
+		gtk_widget_show (label);
 
-		g_hash_table_replace (radios, (char *) names->data, radio);
-		names = names->next;
+		g_hash_table_replace (radios, profile->name, radio);
+		g_hash_table_replace (labels, profile->name, label);
+		i += 3;
 	}
 }
 
diff --git a/src/users/user-profiles.c b/src/users/user-profiles.c
index 07939a6..94dd9a7 100644
--- a/src/users/user-profiles.c
+++ b/src/users/user-profiles.c
@@ -65,6 +65,8 @@ create_profile (GKeyFile    *key_file,
 
 	profile = g_new0 (GstUserProfile, 1);
 	profile->name = g_key_file_get_locale_string (key_file, group, "name", NULL, NULL);
+	profile->description = g_key_file_get_locale_string (key_file, group,
+	                                                     "description", NULL, NULL);
 	profile->is_default = g_key_file_get_boolean (key_file, group, "default", NULL);
 	profile->shell = g_key_file_get_string (key_file, group, "shell", NULL);
 	profile->home_prefix = g_key_file_get_string (key_file, group, "home-prefix", NULL);
@@ -128,6 +130,7 @@ static void
 free_profile (GstUserProfile *profile)
 {
 	g_free (profile->name);
+	g_free (profile->description);
 	g_free (profile->shell);
 	g_free (profile->home_prefix);
 	g_strfreev (profile->groups);
@@ -196,22 +199,16 @@ gst_user_profiles_get_from_name (GstUserProfiles *profiles,
 }
 
 GList*
-gst_user_profiles_get_names (GstUserProfiles *profiles)
+gst_user_profiles_get_list (GstUserProfiles *profiles)
 {
 	GstUserProfilesPrivate *priv;
 	GstUserProfile *profile;
-	GList *names = NULL;
 	GList *l;
 
 	g_return_val_if_fail (GST_IS_USER_PROFILES (profiles), NULL);
 	priv = GST_USER_PROFILES_GET_PRIVATE (profiles);
 
-	for (l = priv->profiles; l; l = l->next) {
-		profile = l->data;
-		names = g_list_prepend (names, profile->name);
-	}
-
-	return names;
+	return priv->profiles;
 }
 
 GstUserProfile*
diff --git a/src/users/user-profiles.h b/src/users/user-profiles.h
index 77d7dae..ed020ed 100644
--- a/src/users/user-profiles.h
+++ b/src/users/user-profiles.h
@@ -52,6 +52,7 @@ struct _GstUserProfilesClass
 struct _GstUserProfile
 {
 	gchar *name;
+	gchar  *description;
 	gboolean is_default;
 
 	/* profile data */
@@ -67,7 +68,7 @@ GstUserProfiles* gst_user_profiles_get                 (void);
 
 GstUserProfile*  gst_user_profiles_get_from_name       (GstUserProfiles *profiles,
                                                         const gchar *name);
-GList*           gst_user_profiles_get_names           (GstUserProfiles *profiles);
+GList*           gst_user_profiles_get_list            (GstUserProfiles *profiles);
 GstUserProfile*  gst_user_profiles_get_default_profile (GstUserProfiles *profiles);
 GstUserProfile*  gst_user_profiles_get_for_user        (GstUserProfiles *profiles,
                                                         OobsUser        *user,
diff --git a/src/users/user-settings.c b/src/users/user-settings.c
index bbd51b6..7f00e6e 100644
--- a/src/users/user-settings.c
+++ b/src/users/user-settings.c
@@ -1005,6 +1005,7 @@ on_edit_user_profile (GtkButton *button, gpointer user_data)
 	GtkWidget *table;
 	GtkWidget *radio;
 	GtkWidget *custom_radio;
+	GtkWidget *custom_label;
 	GHashTable *radios;
 	GHashTableIter iter;
 	gpointer key;
@@ -1018,6 +1019,7 @@ on_edit_user_profile (GtkButton *button, gpointer user_data)
 	name_label = gst_dialog_get_widget (tool->main_dialog, "user_profile_name");
 	table = gst_dialog_get_widget (tool->main_dialog, "user_profile_table");
 	custom_radio = gst_dialog_get_widget (tool->main_dialog, "user_profile_custom");
+	custom_label = gst_dialog_get_widget (tool->main_dialog, "user_profile_custom_label");
 
 	user = users_table_get_current ();
 
@@ -1030,10 +1032,12 @@ on_edit_user_profile (GtkButton *button, gpointer user_data)
 		radio = g_hash_table_lookup (radios, profile->name);
 		gtk_widget_set_sensitive (custom_radio, FALSE);
 		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
+		gtk_widget_set_sensitive (custom_label, FALSE);
 	}
 	else {
 		gtk_widget_set_sensitive (custom_radio, TRUE);
 		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (custom_radio), TRUE);
+		gtk_widget_set_sensitive (custom_label, FALSE);
 	}
 
 	response = run_edit_dialog (GTK_DIALOG (user_profile_dialog),
diff --git a/src/users/users-tool.c b/src/users/users-tool.c
index ca3c166..93cd208 100644
--- a/src/users/users-tool.c
+++ b/src/users/users-tool.c
@@ -176,11 +176,11 @@ update_groups (GstUsersTool *tool)
 static void
 update_profiles (GstUsersTool *tool)
 {
-	GList *names = NULL;
+	GList *list;
 	GtkWidget *label1, *label2, *button;
 
-	names = gst_user_profiles_get_names (tool->profiles);
-	table_populate_profiles (tool, names);
+	list = gst_user_profiles_get_list (tool->profiles);
+	table_populate_profiles (tool, list);
 
 	/* Hide profiles line in main dialog if only one profile is available */
 	label1 = gst_dialog_get_widget (GST_TOOL (tool)->main_dialog,
@@ -190,7 +190,7 @@ update_profiles (GstUsersTool *tool)
 	button = gst_dialog_get_widget (GST_TOOL (tool)->main_dialog,
 	                                "edit_user_profile_button");
 
-	if (g_list_length (names) > 1) {
+	if (g_list_length (list) > 1) {
 		gtk_widget_show (label1);
 		gtk_widget_show (label2);
 		gtk_widget_show (button);
@@ -200,8 +200,6 @@ update_profiles (GstUsersTool *tool)
 		gtk_widget_hide (label2);
 		gtk_widget_hide (button);
 	}
-
-	g_list_free (names);
 }
 
 void



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