[Xfce4-commits] <xfce4-taskmanager:master> Implement option "Toolbar style"

Mike Massonnet noreply at xfce.org
Wed Sep 29 16:52:06 CEST 2010


Updating branch refs/heads/master
         to 95c3ef3246474e18e0e5348f60519445903f9e6a (commit)
       from 8d594e0878752cebae8dbf5af4c93e264ce8dfb8 (commit)

commit 95c3ef3246474e18e0e5348f60519445903f9e6a
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Wed Sep 29 16:40:30 2010 +0200

    Implement option "Toolbar style"

 src/process-window.c   |   54 ++++++++++++++++++++++++++++++++++++++++--------
 src/process-window.ui  |   24 ---------------------
 src/settings-dialog.c  |   31 +++++++++++++++++++++++++++
 src/settings-dialog.ui |   10 +--------
 src/settings.c         |   47 ++++++++++++++++++++++++++++++++++++++++-
 src/settings.h         |   13 +++++++++++
 6 files changed, 135 insertions(+), 44 deletions(-)

diff --git a/src/process-window.c b/src/process-window.c
index 0a48abe..22372ee 100644
--- a/src/process-window.c
+++ b/src/process-window.c
@@ -46,6 +46,7 @@ struct _XtmProcessWindowPriv
 {
 	GtkBuilder *		builder;
 	GtkWidget *		window;
+	GtkWidget *		toolbar;
 	GtkWidget *		cpu_monitor;
 	GtkWidget *		mem_monitor;
 	GtkWidget *		treeview;
@@ -63,6 +64,7 @@ static void	xtm_process_window_hide				(GtkWidget *widget);
 
 static void	emit_destroy_signal				(XtmProcessWindow *window);
 static gboolean	emit_delete_event_signal			(XtmProcessWindow *window, GdkEvent *event);
+static void	toolbar_update_style				(XtmProcessWindow *window);
 static void	monitor_update_step_size			(XtmProcessWindow *window);
 static void	monitor_update_paint_box			(XtmProcessWindow *window);
 static void	show_about_dialog				(XtmProcessWindow *window);
@@ -104,6 +106,16 @@ xtm_process_window_init (XtmProcessWindow *window)
 	g_signal_connect_swapped (window->priv->window, "destroy", G_CALLBACK (emit_destroy_signal), window);
 	g_signal_connect_swapped (window->priv->window, "delete-event", G_CALLBACK (emit_delete_event_signal), window);
 
+	window->priv->toolbar = GTK_WIDGET (gtk_builder_get_object (window->priv->builder, "process-toolbar"));
+	g_signal_connect_swapped (window->priv->settings, "notify::toolbar-style", G_CALLBACK (toolbar_update_style), window);
+	g_object_notify (G_OBJECT (window->priv->settings), "toolbar-style");
+
+	window->priv->exec_button = xtm_exec_tool_button_new ();
+	gtk_toolbar_insert (GTK_TOOLBAR (window->priv->toolbar), GTK_TOOL_ITEM (window->priv->exec_button), 0);
+
+	window->priv->settings_button = xtm_settings_tool_button_new ();
+	gtk_toolbar_insert (GTK_TOOLBAR (window->priv->toolbar), GTK_TOOL_ITEM (window->priv->settings_button), 1);
+
 	{
 		GtkWidget *toolitem;
 		guint refresh_rate;
@@ -127,6 +139,9 @@ xtm_process_window_init (XtmProcessWindow *window)
 		g_signal_connect_swapped (window->priv->settings, "notify::refresh-rate", G_CALLBACK (monitor_update_step_size), window);
 	}
 
+	button = GTK_WIDGET (gtk_builder_get_object (window->priv->builder, "toolbutton-about"));
+	g_signal_connect_swapped (button, "clicked", G_CALLBACK (show_about_dialog), window);
+
 	if (geteuid () == 0)
 	{
 		gtk_rc_parse_string ("style\"root-warning-style\"{bg[NORMAL]=\"#b4254b\"\nfg[NORMAL]=\"#fefefe\"}\n"
@@ -144,15 +159,6 @@ xtm_process_window_init (XtmProcessWindow *window)
 	gtk_widget_show (window->priv->statusbar);
 	gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (window->priv->builder, "process-vbox")), window->priv->statusbar, FALSE, FALSE, 0);
 
-	window->priv->exec_button = xtm_exec_tool_button_new ();
-	gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (window->priv->builder, "toolbutton-execute")), window->priv->exec_button);
-
-	window->priv->settings_button = xtm_settings_tool_button_new ();
-	gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (window->priv->builder, "toolbutton-settings")), window->priv->settings_button);
-
-	button = GTK_WIDGET (gtk_builder_get_object (window->priv->builder, "toolbutton-about"));
-	g_signal_connect_swapped (button, "clicked", G_CALLBACK (show_about_dialog), window);
-
 	g_object_unref (window->priv->builder);
 	window->priv->builder = NULL;
 }
@@ -210,6 +216,36 @@ emit_delete_event_signal (XtmProcessWindow *window, GdkEvent *event)
 }
 
 static void
+toolbar_update_style (XtmProcessWindow *window)
+{
+	XtmToolbarStyle toolbar_style;
+	g_object_get (window->priv->settings, "toolbar-style", &toolbar_style, NULL);
+	switch (toolbar_style)
+	{
+		default:
+		case XTM_TOOLBAR_STYLE_DEFAULT:
+		gtk_toolbar_set_icon_size (GTK_TOOLBAR (window->priv->toolbar), GTK_ICON_SIZE_MENU);
+		gtk_toolbar_unset_style (GTK_TOOLBAR (window->priv->toolbar));
+		break;
+
+		case XTM_TOOLBAR_STYLE_SMALL:
+		gtk_toolbar_set_icon_size (GTK_TOOLBAR (window->priv->toolbar), GTK_ICON_SIZE_SMALL_TOOLBAR);
+		gtk_toolbar_set_style (GTK_TOOLBAR (window->priv->toolbar), GTK_TOOLBAR_ICONS);
+		break;
+
+		case XTM_TOOLBAR_STYLE_LARGE:
+		gtk_toolbar_set_icon_size (GTK_TOOLBAR (window->priv->toolbar), GTK_ICON_SIZE_LARGE_TOOLBAR);
+		gtk_toolbar_set_style (GTK_TOOLBAR (window->priv->toolbar), GTK_TOOLBAR_ICONS);
+		break;
+
+		case XTM_TOOLBAR_STYLE_TEXT:
+		gtk_toolbar_set_icon_size (GTK_TOOLBAR (window->priv->toolbar), GTK_ICON_SIZE_MENU);
+		gtk_toolbar_set_style (GTK_TOOLBAR (window->priv->toolbar), GTK_TOOLBAR_BOTH);
+		break;
+	}
+}
+
+static void
 monitor_update_paint_box (XtmProcessWindow *window)
 {
 	gboolean paint_box;
diff --git a/src/process-window.ui b/src/process-window.ui
index ad48f8f..81c4371 100644
--- a/src/process-window.ui
+++ b/src/process-window.ui
@@ -17,30 +17,6 @@
             <property name="show_arrow">False</property>
             <property name="icon_size">1</property>
             <child>
-              <object class="GtkToolItem" id="toolbutton-execute">
-                <property name="visible">True</property>
-                <property name="is_important">True</property>
-                <child>
-                  <placeholder/>
-                </child>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkToolItem" id="toolbutton-settings">
-                <property name="visible">True</property>
-                <property name="is_important">True</property>
-                <child>
-                  <placeholder/>
-                </child>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-              </packing>
-            </child>
-            <child>
               <object class="GtkToolItem" id="cpu-toolitem">
                 <property name="visible">True</property>
                 <property name="border_width">2</property>
diff --git a/src/settings-dialog.c b/src/settings-dialog.c
index 015e5e3..419af6d 100644
--- a/src/settings-dialog.c
+++ b/src/settings-dialog.c
@@ -77,6 +77,14 @@ builder_bind_toggle_button (GtkBuilder *builder, gchar *widget_name, XtmSettings
 }
 
 static void
+combobox_changed (GtkComboBox *combobox, XtmSettings *settings)
+{
+	guint active = gtk_combo_box_get_active (combobox);
+	gchar *setting_name = g_object_get_data (G_OBJECT (combobox), "setting-name");
+	g_object_set (settings, setting_name, active, NULL);
+}
+
+static void
 xtm_settings_dialog_init (XtmSettingsDialog *dialog)
 {
 	GtkBuilder *builder;
@@ -96,6 +104,29 @@ xtm_settings_dialog_init (XtmSettingsDialog *dialog)
 	builder_bind_toggle_button (builder, "button-prompt-terminate-task", dialog->settings, "prompt-terminate-task");
 	builder_bind_toggle_button (builder, "button-show-status-icon", dialog->settings, "show-status-icon");
 
+	{
+		guint n;
+		GEnumClass *klass;
+		GtkWidget *box;
+		GtkWidget *combobox;
+		XtmToolbarStyle toolbar_style;
+
+		box = GTK_WIDGET (gtk_builder_get_object (builder, "hbox-toolbar-style"));
+		combobox = gtk_combo_box_new_text ();
+		gtk_box_pack_start (GTK_BOX (box), combobox, FALSE, FALSE, 0);
+		gtk_widget_show (combobox);
+
+		klass = g_type_class_ref (XTM_TYPE_TOOLBAR_STYLE);
+		for (n = 0; n < klass->n_values; ++n)
+			gtk_combo_box_append_text (GTK_COMBO_BOX (combobox), _(klass->values[n].value_nick));
+		g_type_class_unref (klass);
+
+		g_object_get (dialog->settings, "toolbar-style", &toolbar_style, NULL);
+		g_object_set_data (G_OBJECT (combobox), "setting-name", "toolbar-style");
+		gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), toolbar_style);
+		g_signal_connect (combobox, "changed", G_CALLBACK (combobox_changed), dialog->settings);
+	}
+
 	g_object_unref (builder);
 }
 
diff --git a/src/settings-dialog.ui b/src/settings-dialog.ui
index e0c7224..51a3bee 100644
--- a/src/settings-dialog.ui
+++ b/src/settings-dialog.ui
@@ -91,7 +91,6 @@
                                 <child>
                                   <object class="GtkHBox" id="hbox-toolbar-style">
                                     <property name="visible">True</property>
-                                    <property name="sensitive">False</property>
                                     <property name="spacing">6</property>
                                     <child>
                                       <object class="GtkLabel" id="label-toolbar-style">
@@ -105,14 +104,7 @@
                                       </packing>
                                     </child>
                                     <child>
-                                      <object class="GtkComboBox" id="combobox-toolbar-style">
-                                        <property name="visible">True</property>
-                                      </object>
-                                      <packing>
-                                        <property name="expand">False</property>
-                                        <property name="fill">False</property>
-                                        <property name="position">1</property>
-                                      </packing>
+                                      <placeholder/>
                                     </child>
                                   </object>
                                   <packing>
diff --git a/src/settings.c b/src/settings.c
index 432193a..5224442 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -24,6 +24,7 @@
 
 #include <glib-object.h>
 #include <glib.h>
+#include <glib/gi18n.h>
 
 #include "settings.h"
 
@@ -93,8 +94,8 @@ xtm_settings_class_init (XtmSettingsClass *klass)
 		g_param_spec_boolean ("show-status-icon", "ShowStatusIcon", "Show/hide the status icon", TRUE, G_PARAM_READWRITE));
 	g_object_class_install_property (class, PROP_MONITOR_PAINT_BOX,
 		g_param_spec_boolean ("monitor-paint-box", "MonitorPaintBox", "Paint box around monitor", TRUE, G_PARAM_READWRITE));
-	//g_object_class_install_property (class, PROP_TOOLBAR_STYLE,
-	//	g_param_spec_... ("toolbar-style", "ToolbarStyle", "Toolbar style", ...));
+	g_object_class_install_property (class, PROP_TOOLBAR_STYLE,
+		g_param_spec_enum ("toolbar-style", "ToolbarStyle", "Toolbar style", XTM_TYPE_TOOLBAR_STYLE, XTM_TOOLBAR_STYLE_DEFAULT, G_PARAM_READWRITE));
 	g_object_class_install_property (class, PROP_PROMPT_TERMINATE_TASK,
 		g_param_spec_boolean ("prompt-terminate-task", "PromptTerminateTask", "Prompt dialog for terminating a task", TRUE, G_PARAM_READWRITE));
 	g_object_class_install_property (class, PROP_REFRESH_RATE,
@@ -180,6 +181,25 @@ transform_string_to_uint (const GValue *src, GValue *dst)
 }
 
 static void
+transform_string_to_enum (const GValue *src, GValue *dst)
+{
+	GEnumClass *klass;
+	gint value = 0;
+	guint n;
+
+	klass = g_type_class_ref (G_VALUE_TYPE (dst));
+	for (n = 0; n < klass->n_values; ++n)
+	{
+		value = klass->values[n].value;
+		if (!g_ascii_strcasecmp (klass->values[n].value_name, g_value_get_string (src)))
+			break;
+	}
+	g_type_class_unref (klass);
+
+	g_value_set_enum (dst, value);
+}
+
+static void
 register_transformable (void)
 {
 	if (!g_value_type_transformable (G_TYPE_STRING, G_TYPE_BOOLEAN))
@@ -190,6 +210,8 @@ register_transformable (void)
 
 	if (!g_value_type_transformable (G_TYPE_STRING, G_TYPE_UINT))
 		g_value_register_transform_func (G_TYPE_STRING, G_TYPE_UINT, transform_string_to_uint);
+
+	g_value_register_transform_func (G_TYPE_STRING, G_TYPE_ENUM, transform_string_to_enum);
 }
 
 static void
@@ -342,3 +364,24 @@ xtm_settings_get_default (void)
 	return settings;
 }
 
+
+
+GType
+xtm_toolbar_style_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	static const GEnumValue values[] = {
+		{ XTM_TOOLBAR_STYLE_DEFAULT, "DEFAULT", N_("Default") },
+		{ XTM_TOOLBAR_STYLE_SMALL, "SMALL", N_("Small") },
+		{ XTM_TOOLBAR_STYLE_LARGE, "LARGE", N_("Large") },
+		{ XTM_TOOLBAR_STYLE_TEXT, "TEXT", N_("Text") },
+		{ 0, NULL, NULL }
+	};
+
+	if (type != G_TYPE_INVALID)
+		return type;
+
+	type = g_enum_register_static ("XtmToolbarStyle", values);
+	return type;
+}
diff --git a/src/settings.h b/src/settings.h
index 9e143bb..64f0c9d 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -28,4 +28,17 @@ typedef struct _XtmSettings XtmSettings;
 GType		xtm_settings_get_type				(void);
 XtmSettings *	xtm_settings_get_default			();
 
+
+
+typedef enum
+{
+	XTM_TOOLBAR_STYLE_DEFAULT,
+	XTM_TOOLBAR_STYLE_SMALL,
+	XTM_TOOLBAR_STYLE_LARGE,
+	XTM_TOOLBAR_STYLE_TEXT,
+} XtmToolbarStyle;
+
+GType xtm_toolbar_style_get_type (void);
+#define XTM_TYPE_TOOLBAR_STYLE (xtm_toolbar_style_get_type ())
+
 #endif /* !SETTINGS_H */



More information about the Xfce4-commits mailing list