Implement option "Toolbar style"
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -209,6 +215,36 @@ emit_delete_event_signal (XtmProcessWindow *window, GdkEvent *event)
|
||||
return ret;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -16,30 +16,6 @@
|
||||
<property name="visible">True</property>
|
||||
<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>
|
||||
|
||||
@@ -76,6 +76,14 @@ builder_bind_toggle_button (GtkBuilder *builder, gchar *widget_name, XtmSettings
|
||||
g_signal_connect (button, "toggled", G_CALLBACK (button_toggled), settings);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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,
|
||||
@@ -179,6 +180,25 @@ transform_string_to_uint (const GValue *src, GValue *dst)
|
||||
g_value_set_uint (dst, (gint)strtoul (g_value_get_string (src), NULL, 10));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user