diff src/info.c @ 684:9f00d0d874fa

Save order of Properties dialog tabs to rc file. Users of GTK+ <2.10 can set tabs order directly in the rc file, others can move tabs using drag'n drop. The option is named properties.tabs_order, its default value is "123" which is General, Keywords, Exif tabs (left to right).
author zas_
date Sun, 18 May 2008 21:14:01 +0000
parents e34c1002e553
children a7289f9e8d29
line wrap: on
line diff
--- a/src/info.c	Sun May 18 12:56:18 2008 +0000
+++ b/src/info.c	Sun May 18 21:14:01 2008 +0000
@@ -488,20 +488,94 @@
 	return -1;
 }
 
+static gpointer info_tab_new_funcs[] = {
+	info_tab_general_new,
+	info_tab_meta_new,
+	info_tab_exif_new,
+};
+
+gchar *info_tab_default_order(void)
+{
+	gint i;
+	static gchar str[G_N_ELEMENTS(info_tab_new_funcs) + 1];
+
+	for (i = 0; i < G_N_ELEMENTS(info_tab_new_funcs); i++)
+		str[i] = i + '1';
+	str[i] = '\0';
+
+	return str;
+}
+
+static void info_tab_get_order_string(gchar **dest)
+{
+	GList *work;
+	gchar str[G_N_ELEMENTS(info_tab_new_funcs) + 1];
+
+	g_assert(dest);
+
+	if (!info_tabs_pos_list)
+		return;
+	
+	memset(str, 0, G_N_ELEMENTS(info_tab_new_funcs) + 1);
+
+	work = info_tabs_pos_list;
+	while (work)
+		{
+		gint i;
+		InfoTabsPos *t = work->data;
+		work = work->next;
+
+		for (i = 0; i < G_N_ELEMENTS(info_tab_new_funcs); i++)
+			{
+			if (t->func == info_tab_new_funcs[i])
+				{
+				g_assert(t->pos >= 0 && t->pos < G_N_ELEMENTS(info_tab_new_funcs));
+				str[t->pos] = i + '1';
+				}
+			}
+		}
+	
+	if (strlen(str) != G_N_ELEMENTS(info_tab_new_funcs)) return;
+
+	g_free(*dest);
+	*dest = g_strdup(str);
+}
+
 static void info_tabs_init(InfoData *id)
 {
 	GList *work;
 
 	if (!info_tabs_pos_list)
 		{
-		/* First run, default tabs order is defined here. */
-		info_tabs_pos_list_append(info_tab_general_new);
-		info_tabs_pos_list_append(info_tab_meta_new);
-		info_tabs_pos_list_append(info_tab_exif_new);
+		gint count = 0;
+		gint i;
+		gchar *order = options->properties.tabs_order;
+		
+		for (i = 0; i < strlen(order); i++)
+			{
+			gint n = order[i] - '1';
+
+			if (n < 0 || n >= G_N_ELEMENTS(info_tab_new_funcs)) break;
+			count++;
+			}
+
+		if (count != G_N_ELEMENTS(info_tab_new_funcs))
+			order = info_tab_default_order();
+
+		for (i = 0; i < strlen(order); i++)
+			{
+			gint n = order[i] - '1';
+
+			if (n < 0 || n >= G_N_ELEMENTS(info_tab_new_funcs)) continue;
+			if (g_list_find(info_tabs_pos_list, info_tab_new_funcs[n])) continue;
+			info_tabs_pos_list_append(info_tab_new_funcs[n]);
+			}
 		}
 	else
 		info_tabs_pos_list = g_list_sort(info_tabs_pos_list, compare_info_tabs_pos);
 
+	info_tab_get_order_string(&options->properties.tabs_order);
+
 	work = info_tabs_pos_list;
 	while (work)
 		{
@@ -568,6 +642,9 @@
 				}
 			}
 		}
+	
+	info_tabs_pos_list = g_list_sort(info_tabs_pos_list, compare_info_tabs_pos);
+	info_tab_get_order_string(&options->properties.tabs_order);
 }
 
 /*