Port to xfconf
The internal XtmSettings object is retained so we don't have to refactor everything, but the backend now uses Xfconf over the rc file.
This commit is contained in:
committed by
Simon Steinbeiß
parent
99c3deee8e
commit
a5aeafc15f
@@ -70,6 +70,7 @@ XDT_CHECK_PACKAGE([LIBXMU], [xmu], [1.1.2])
|
||||
XDT_CHECK_PACKAGE([GTK3], [gtk+-3.0], [3.22.0])
|
||||
XDT_CHECK_PACKAGE([CAIRO], [cairo], [1.5.0])
|
||||
XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-2], [4.14.0])
|
||||
XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0], [4.14.0])
|
||||
|
||||
dnl ***********************************
|
||||
dnl *** Check for optional packages ***
|
||||
|
||||
@@ -13,6 +13,7 @@ xfce4_taskmanager_CFLAGS = \
|
||||
$(GTK3_CFLAGS) \
|
||||
$(WNCK_CFLAGS) \
|
||||
$(LIBXFCE4UI_CFLAGS) \
|
||||
$(XFCONF_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
xfce4_taskmanager_LDADD = \
|
||||
@@ -22,6 +23,7 @@ xfce4_taskmanager_LDADD = \
|
||||
$(GTK3_LIBS) \
|
||||
$(WNCK_LIBS) \
|
||||
$(LIBXFCE4UI_LIBS) \
|
||||
$(XFCONF_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
xfce4_taskmanager_SOURCES = \
|
||||
|
||||
21
src/main.c
21
src/main.c
@@ -18,6 +18,9 @@
|
||||
#include <gio/gio.h>
|
||||
#endif
|
||||
|
||||
#include <xfconf/xfconf.h>
|
||||
#include <libxfce4ui/libxfce4ui.h>
|
||||
|
||||
#include "settings.h"
|
||||
#include "process-window.h"
|
||||
#include "task-manager.h"
|
||||
@@ -102,7 +105,7 @@ static void
|
||||
destroy_window (void)
|
||||
{
|
||||
if (gtk_main_level () > 0) {
|
||||
xtm_settings_save_settings(settings);
|
||||
xfconf_shutdown();
|
||||
gtk_main_quit ();
|
||||
}
|
||||
}
|
||||
@@ -112,7 +115,7 @@ delete_window (void)
|
||||
{
|
||||
if (!status_icon_get_visible ())
|
||||
{
|
||||
xtm_settings_save_settings(settings);
|
||||
xfconf_shutdown();
|
||||
gtk_main_quit ();
|
||||
return FALSE;
|
||||
}
|
||||
@@ -194,6 +197,7 @@ refresh_rate_changed (void)
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
XfconfChannel *channel;
|
||||
#if GLIB_CHECK_VERSION(2, 28, 0)
|
||||
GApplication *app;
|
||||
GError *error = NULL;
|
||||
@@ -236,7 +240,20 @@ int main (int argc, char *argv[])
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!xfconf_init (&error))
|
||||
{
|
||||
xfce_message_dialog (NULL, _("Xfce Notify Daemon"),
|
||||
"dialog-error",
|
||||
_("Settings daemon is unavailable"),
|
||||
error->message,
|
||||
"application-exit", GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
channel = xfconf_channel_new (CHANNEL);
|
||||
settings = xtm_settings_get_default ();
|
||||
xtm_settings_bind_xfconf (settings, channel);
|
||||
show_hide_status_icon ();
|
||||
|
||||
window = xtm_process_window_new ();
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
#include <xfconf/xfconf.h>
|
||||
#include <libxfce4ui/libxfce4ui.h>
|
||||
|
||||
#include "settings.h"
|
||||
@@ -61,6 +62,10 @@ struct _XtmProcessWindow
|
||||
GtkWidget * statusbar;
|
||||
GtkWidget * settings_button;
|
||||
XtmSettings * settings;
|
||||
XfconfChannel * channel;
|
||||
gint width;
|
||||
gint height;
|
||||
gulong handler;
|
||||
};
|
||||
G_DEFINE_TYPE (XtmProcessWindow, xtm_process_window, GTK_TYPE_WIDGET)
|
||||
|
||||
@@ -68,8 +73,6 @@ static void xtm_process_window_finalize (GObject *object);
|
||||
static void xtm_process_window_hide (GtkWidget *widget);
|
||||
|
||||
static void emit_destroy_signal (XtmProcessWindow *window);
|
||||
static gboolean xtm_process_window_configure_event (XtmProcessWindow *window, GdkEvent *event);
|
||||
static gboolean xtm_process_vpaned_move_event (XtmProcessWindow *window, GdkEventButton *event);
|
||||
static gboolean xtm_process_window_key_pressed (XtmProcessWindow *window, GdkEventKey *event);
|
||||
static void monitor_update_step_size (XtmProcessWindow *window);
|
||||
|
||||
@@ -208,59 +211,62 @@ xtm_process_window_class_init (XtmProcessWindowClass *klass)
|
||||
}
|
||||
|
||||
static void
|
||||
show_settings_dialog (GtkButton *button, GtkWidget *parent)
|
||||
xtm_process_window_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer user_data)
|
||||
{
|
||||
xtm_settings_dialog_run (parent);
|
||||
XtmProcessWindow *window = (XtmProcessWindow *) user_data;
|
||||
|
||||
g_return_if_fail (GTK_IS_WINDOW (XTM_PROCESS_WINDOW (widget)->window));
|
||||
|
||||
gtk_window_get_size (GTK_WINDOW (XTM_PROCESS_WINDOW (widget)->window), &window->width, &window->height);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
xtm_process_window_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
|
||||
{
|
||||
XtmProcessWindow *window = (XtmProcessWindow *) user_data;
|
||||
|
||||
xfconf_channel_set_int (XTM_PROCESS_WINDOW (widget)->channel, SETTING_WINDOW_WIDTH, window->width);
|
||||
xfconf_channel_set_int (XTM_PROCESS_WINDOW (widget)->channel, SETTING_WINDOW_HEIGHT, window->height);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
xtm_show_legend (XtmProcessWindow *window)
|
||||
show_settings_dialog (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
gboolean show_legend;
|
||||
XtmProcessWindow *window = (XtmProcessWindow *) user_data;
|
||||
|
||||
g_object_get (window->settings,
|
||||
"show-legend", &show_legend,
|
||||
NULL);
|
||||
gtk_widget_set_visible (GTK_WIDGET (gtk_builder_get_object (window->builder, "legend")), show_legend);
|
||||
}
|
||||
|
||||
static void
|
||||
show_filter_toggled_cb (GtkToggleButton *button, gpointer user_data)
|
||||
{
|
||||
XtmProcessWindow *window = user_data;
|
||||
gboolean active;
|
||||
|
||||
active = gtk_toggle_button_get_active (button);
|
||||
gtk_revealer_set_reveal_child (GTK_REVEALER (gtk_bin_get_child (GTK_BIN (window->filter_searchbar))), active);
|
||||
g_signal_handler_block (G_OBJECT (window->window), window->handler);
|
||||
xtm_settings_dialog_run (window->window);
|
||||
g_signal_handler_unblock (G_OBJECT (window->window), window->handler);
|
||||
}
|
||||
|
||||
static void
|
||||
xtm_process_window_init (XtmProcessWindow *window)
|
||||
{
|
||||
GtkWidget *button;
|
||||
gint width, height;
|
||||
gboolean show_legend;
|
||||
gboolean active;
|
||||
|
||||
window->settings = xtm_settings_get_default ();
|
||||
window->channel = xfconf_channel_new (CHANNEL);
|
||||
|
||||
window->builder = gtk_builder_new ();
|
||||
gtk_builder_add_from_string (window->builder, process_window_ui, process_window_ui_length, NULL);
|
||||
|
||||
window->window = GTK_WIDGET (gtk_builder_get_object (window->builder, "process-window"));
|
||||
g_object_get (window->settings, "window-width", &width, "window-height", &height, NULL);
|
||||
if (width >= 1 && height >= 1)
|
||||
gtk_window_resize (GTK_WINDOW (window->window), width, height);
|
||||
g_signal_connect_swapped (window->window, "destroy", G_CALLBACK (emit_destroy_signal), window);
|
||||
g_signal_connect_swapped (window->window, "key-press-event", G_CALLBACK(xtm_process_window_key_pressed), window);
|
||||
g_signal_connect_swapped(window->window, "configure-event",
|
||||
G_CALLBACK(xtm_process_window_configure_event), window);
|
||||
window->width = xfconf_channel_get_int (window->channel, SETTING_WINDOW_WIDTH, DEFAULT_WINDOW_WIDTH);
|
||||
window->height = xfconf_channel_get_int (window->channel, SETTING_WINDOW_HEIGHT, DEFAULT_WINDOW_HEIGHT);
|
||||
if (window->width >= 1 && window->height >= 1)
|
||||
gtk_window_set_default_size (GTK_WINDOW (window->window), window->width, window->height);
|
||||
|
||||
g_signal_connect_swapped (window->settings, "notify::show-legend", G_CALLBACK (xtm_show_legend), window);
|
||||
g_object_notify (G_OBJECT (window->settings), "show-legend");
|
||||
g_signal_connect_swapped (window->window, "destroy", G_CALLBACK (emit_destroy_signal), window);
|
||||
window->handler = g_signal_connect_swapped (window->window, "size-allocate", G_CALLBACK (xtm_process_window_size_allocate), window);
|
||||
g_signal_connect_swapped (window->window, "delete-event", G_CALLBACK (xtm_process_window_delete_event), window);
|
||||
g_signal_connect_swapped (window->window, "key-press-event", G_CALLBACK(xtm_process_window_key_pressed), window);
|
||||
|
||||
button = GTK_WIDGET (gtk_builder_get_object (window->builder, "button-settings"));
|
||||
g_signal_connect (G_OBJECT (button), "clicked",
|
||||
G_CALLBACK (show_settings_dialog), GTK_WIDGET (window->window));
|
||||
G_CALLBACK (show_settings_dialog), window);
|
||||
|
||||
button = GTK_WIDGET (gtk_builder_get_object (window->builder, "button-identify"));
|
||||
g_signal_connect (G_OBJECT (button), "clicked",
|
||||
@@ -268,11 +274,11 @@ xtm_process_window_init (XtmProcessWindow *window)
|
||||
|
||||
window->filter_searchbar = GTK_WIDGET (gtk_builder_get_object (window->builder, "filter-searchbar"));
|
||||
button = GTK_WIDGET (gtk_builder_get_object (window->builder, "button-show-filter"));
|
||||
gtk_revealer_set_reveal_child (GTK_REVEALER (gtk_bin_get_child (GTK_BIN (window->filter_searchbar))), FALSE);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
||||
gtk_revealer_get_reveal_child (GTK_REVEALER (gtk_bin_get_child (GTK_BIN (window->filter_searchbar)))));
|
||||
g_signal_connect (G_OBJECT (button), "toggled",
|
||||
G_CALLBACK (show_filter_toggled_cb), window);
|
||||
xfconf_g_property_bind (window->channel, SETTING_SHOW_FILTER, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (button), "active");
|
||||
active = xfconf_channel_get_bool (window->channel, SETTING_SHOW_FILTER, FALSE);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), active);
|
||||
gtk_revealer_set_reveal_child (GTK_REVEALER (gtk_bin_get_child (GTK_BIN (window->filter_searchbar))), active);
|
||||
g_object_bind_property (G_OBJECT (gtk_bin_get_child (GTK_BIN (window->filter_searchbar))), "reveal-child",
|
||||
G_OBJECT (button), "active", G_BINDING_BIDIRECTIONAL);
|
||||
|
||||
@@ -287,10 +293,8 @@ xtm_process_window_init (XtmProcessWindow *window)
|
||||
NULL);
|
||||
|
||||
window->vpaned = GTK_WIDGET (gtk_builder_get_object (window->builder, "mainview-vpaned"));
|
||||
if (handle_position > -1)
|
||||
gtk_paned_set_position (GTK_PANED (window->vpaned), handle_position);
|
||||
g_signal_connect_swapped(window->vpaned, "button-release-event",
|
||||
G_CALLBACK(xtm_process_vpaned_move_event), window);
|
||||
xfconf_g_property_bind (window->channel, SETTING_HANDLE_POSITION, G_TYPE_INT,
|
||||
G_OBJECT (window->vpaned), "position");
|
||||
|
||||
toolitem = GTK_WIDGET (gtk_builder_get_object (window->builder, "graph-cpu"));
|
||||
window->cpu_monitor = xtm_process_monitor_new ();
|
||||
@@ -319,10 +323,8 @@ xtm_process_window_init (XtmProcessWindow *window)
|
||||
gtk_widget_show (window->treeview);
|
||||
gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (window->builder, "scrolledwindow")), window->treeview);
|
||||
|
||||
g_object_get (window->settings,
|
||||
"show-legend", &show_legend,
|
||||
NULL);
|
||||
gtk_widget_set_visible (GTK_WIDGET (gtk_builder_get_object (window->builder, "legend")), show_legend);
|
||||
xfconf_g_property_bind (window->channel, SETTING_SHOW_LEGEND, G_TYPE_BOOLEAN,
|
||||
gtk_builder_get_object (window->builder, "legend"), "visible");
|
||||
|
||||
window->filter_entry = GTK_WIDGET(gtk_builder_get_object (window->builder, "filter-entry"));
|
||||
g_signal_connect (G_OBJECT(window->filter_entry), "icon-press", G_CALLBACK(filter_entry_icon_pressed_cb), NULL);
|
||||
@@ -360,36 +362,6 @@ emit_destroy_signal (XtmProcessWindow *window)
|
||||
g_signal_emit_by_name (window, "destroy", G_TYPE_NONE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
xtm_process_window_configure_event(XtmProcessWindow *window,
|
||||
GdkEvent *event) {
|
||||
|
||||
if (NULL != window &&
|
||||
NULL != event && GDK_CONFIGURE == event->configure.type) {
|
||||
g_object_set (window->settings,
|
||||
"window-width", event->configure.width,
|
||||
"window-height", event->configure.height,
|
||||
NULL);
|
||||
}
|
||||
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
xtm_process_vpaned_move_event(XtmProcessWindow *window,
|
||||
GdkEventButton *event __unused) {
|
||||
gint handle_position;
|
||||
|
||||
if (NULL != window) {
|
||||
handle_position = gtk_paned_get_position(GTK_PANED(window->vpaned));
|
||||
g_object_set (window->settings,
|
||||
"handle-position", handle_position,
|
||||
NULL);
|
||||
}
|
||||
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
xtm_process_window_key_pressed (XtmProcessWindow *window, GdkEventKey *event)
|
||||
{
|
||||
@@ -397,7 +369,6 @@ xtm_process_window_key_pressed (XtmProcessWindow *window, GdkEventKey *event)
|
||||
|
||||
if (event->keyval == GDK_KEY_Escape ||
|
||||
(event->keyval == GDK_KEY_q && (event->state & GDK_CONTROL_MASK))) {
|
||||
xtm_settings_save_settings (window->settings);
|
||||
g_signal_emit_by_name (window, "delete-event", event, &ret, G_TYPE_BOOLEAN);
|
||||
ret = TRUE;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ typedef struct _XtmProcessWindow XtmProcessWindow;
|
||||
|
||||
GType xtm_process_window_get_type (void);
|
||||
GtkWidget * xtm_process_window_new (void);
|
||||
void xtm_process_window_settings_init (XtmProcessWindow *window, XfconfChannel *channel);
|
||||
void xtm_process_window_show (GtkWidget *widget);
|
||||
GtkTreeModel * xtm_process_window_get_model (XtmProcessWindow *window);
|
||||
void xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar* memory_str, gfloat swap, gchar* swap_str);
|
||||
|
||||
251
src/settings.c
251
src/settings.c
@@ -37,9 +37,7 @@ enum
|
||||
PROP_MORE_PRECISION,
|
||||
PROP_FULL_COMMAND_LINE,
|
||||
PROP_SHOW_STATUS_ICON,
|
||||
PROP_MONITOR_PAINT_BOX,
|
||||
PROP_SHOW_APPLICATION_ICONS,
|
||||
PROP_TOOLBAR_STYLE,
|
||||
PROP_PROMPT_TERMINATE_TASK,
|
||||
PROP_REFRESH_RATE,
|
||||
PROP_COLUMNS_POSITIONS,
|
||||
@@ -53,8 +51,6 @@ enum
|
||||
PROP_COLUMN_PRIORITY,
|
||||
PROP_SORT_COLUMN_ID,
|
||||
PROP_SORT_TYPE,
|
||||
PROP_WINDOW_WIDTH,
|
||||
PROP_WINDOW_HEIGHT,
|
||||
PROP_HANDLE_POSITION,
|
||||
PROP_PROCESS_TREE,
|
||||
N_PROPS,
|
||||
@@ -69,16 +65,12 @@ struct _XtmSettings
|
||||
GObject parent;
|
||||
/*<private>*/
|
||||
GValue values[N_PROPS];
|
||||
gint loading; /* Setting loading now, do not save. */
|
||||
};
|
||||
G_DEFINE_TYPE (XtmSettings, xtm_settings, G_TYPE_OBJECT)
|
||||
|
||||
static void xtm_settings_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
|
||||
static void xtm_settings_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
|
||||
|
||||
static void xtm_settings_load_settings (XtmSettings *settings);
|
||||
|
||||
|
||||
static void
|
||||
xtm_settings_class_init (XtmSettingsClass *klass)
|
||||
{
|
||||
@@ -96,8 +88,6 @@ xtm_settings_class_init (XtmSettingsClass *klass)
|
||||
g_param_spec_boolean ("full-command-line", "FullCommandLine", "Full command line", FALSE, G_PARAM_READWRITE));
|
||||
g_object_class_install_property (class, PROP_SHOW_STATUS_ICON,
|
||||
g_param_spec_boolean ("show-status-icon", "ShowStatusIcon", "Show/hide the status icon", FALSE, 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_SHOW_APPLICATION_ICONS,
|
||||
g_param_spec_boolean ("show-application-icons", "ShowApplicationIcons", "Show application icons", TRUE, G_PARAM_READWRITE));
|
||||
g_object_class_install_property (class, PROP_PROMPT_TERMINATE_TASK,
|
||||
@@ -126,10 +116,6 @@ xtm_settings_class_init (XtmSettingsClass *klass)
|
||||
g_param_spec_uint ("sort-column-id", "SortColumn", "Sort by column id", 0, G_MAXUINT, 0, G_PARAM_READWRITE));
|
||||
g_object_class_install_property (class, PROP_SORT_TYPE,
|
||||
g_param_spec_uint ("sort-type", "SortType", "Sort type (asc/dsc)", 0, 1, 0, G_PARAM_READWRITE));
|
||||
g_object_class_install_property (class, PROP_WINDOW_WIDTH,
|
||||
g_param_spec_int ("window-width", "WindowWidth", "Window width", -1, G_MAXINT, -1, G_PARAM_READWRITE));
|
||||
g_object_class_install_property (class, PROP_WINDOW_HEIGHT,
|
||||
g_param_spec_int ("window-height", "WindowHeight", "Window height", -1, G_MAXINT, -1, G_PARAM_READWRITE));
|
||||
g_object_class_install_property (class, PROP_HANDLE_POSITION,
|
||||
g_param_spec_int ("handle-position", "HandlePosition", "Handle position", -1, G_MAXINT, -1, G_PARAM_READWRITE));
|
||||
g_object_class_install_property (class, PROP_PROCESS_TREE,
|
||||
@@ -139,7 +125,7 @@ xtm_settings_class_init (XtmSettingsClass *klass)
|
||||
static void
|
||||
xtm_settings_init (XtmSettings *settings)
|
||||
{
|
||||
xtm_settings_load_settings (settings);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -156,7 +142,7 @@ static void
|
||||
xtm_settings_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
GValue *dest = XTM_SETTINGS (object)->values + property_id;
|
||||
if (!G_IS_VALUE(dest))
|
||||
if (!G_IS_VALUE (dest))
|
||||
{
|
||||
g_value_init (dest, pspec->value_type);
|
||||
g_param_value_set_default (pspec, dest);
|
||||
@@ -164,210 +150,53 @@ xtm_settings_set_property (GObject *object, guint property_id, const GValue *val
|
||||
if (g_param_values_cmp (pspec, value, dest) != 0)
|
||||
{
|
||||
g_value_copy (value, dest);
|
||||
/* Do not save some noisy changed props on fly. */
|
||||
switch (property_id) {
|
||||
case PROP_WINDOW_WIDTH:
|
||||
case PROP_WINDOW_HEIGHT:
|
||||
break;
|
||||
default:
|
||||
xtm_settings_save_settings (XTM_SETTINGS (object));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
transform_string_to_boolean (const GValue *src, GValue *dst)
|
||||
{
|
||||
g_value_set_boolean (dst, (gboolean)strcmp (g_value_get_string (src), "FALSE") != 0);
|
||||
}
|
||||
|
||||
static void
|
||||
transform_string_to_int (const GValue *src, GValue *dst)
|
||||
{
|
||||
g_value_set_int (dst, (gint)strtol (g_value_get_string (src), NULL, 10));
|
||||
}
|
||||
|
||||
static void
|
||||
transform_string_to_uint (const GValue *src, GValue *dst)
|
||||
{
|
||||
g_value_set_uint (dst, (guint)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)
|
||||
{
|
||||
if (!g_value_type_transformable (G_TYPE_STRING, G_TYPE_BOOLEAN))
|
||||
g_value_register_transform_func (G_TYPE_STRING, G_TYPE_BOOLEAN, transform_string_to_boolean);
|
||||
|
||||
if (!g_value_type_transformable (G_TYPE_STRING, G_TYPE_INT))
|
||||
g_value_register_transform_func (G_TYPE_STRING, G_TYPE_INT, transform_string_to_int);
|
||||
|
||||
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
|
||||
xtm_settings_load_settings (XtmSettings *settings)
|
||||
{
|
||||
GKeyFile *rc;
|
||||
gchar *filename;
|
||||
|
||||
register_transformable ();
|
||||
|
||||
settings->loading = 1;
|
||||
g_object_freeze_notify (G_OBJECT (settings));
|
||||
|
||||
rc = g_key_file_new ();
|
||||
filename = g_strdup_printf ("%s/xfce4/xfce4-taskmanager.rc", g_get_user_config_dir ());
|
||||
|
||||
if (g_key_file_load_from_file (rc, filename, G_KEY_FILE_NONE, NULL))
|
||||
{
|
||||
gchar *string;
|
||||
GValue dst = {0};
|
||||
GValue src = {0};
|
||||
GParamSpec **specs;
|
||||
GParamSpec *spec;
|
||||
guint nspecs;
|
||||
guint n;
|
||||
|
||||
specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), &nspecs);
|
||||
for (n = 0; n < nspecs; ++n)
|
||||
{
|
||||
spec = specs[n];
|
||||
string = g_key_file_get_string (rc, "Settings", g_param_spec_get_nick (spec), NULL);
|
||||
if (string == NULL)
|
||||
continue;
|
||||
|
||||
g_value_init (&src, G_TYPE_STRING);
|
||||
g_value_set_string (&src, string);
|
||||
g_free (string);
|
||||
|
||||
if (spec->value_type == G_TYPE_STRING)
|
||||
{
|
||||
g_object_set_property (G_OBJECT (settings), spec->name, &src);
|
||||
}
|
||||
else if (g_value_type_transformable (G_TYPE_STRING, spec->value_type))
|
||||
{
|
||||
g_value_init (&dst, spec->value_type);
|
||||
if (g_value_transform (&src, &dst))
|
||||
g_object_set_property (G_OBJECT (settings), spec->name, &dst);
|
||||
g_value_unset (&dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning ("Failed to load property \"%s\"", spec->name);
|
||||
}
|
||||
|
||||
g_value_unset (&src);
|
||||
}
|
||||
g_free (specs);
|
||||
}
|
||||
|
||||
g_free (filename);
|
||||
g_key_file_free (rc);
|
||||
|
||||
g_object_thaw_notify (G_OBJECT (settings));
|
||||
settings->loading = 0;
|
||||
}
|
||||
|
||||
void
|
||||
xtm_settings_save_settings (XtmSettings *settings)
|
||||
xtm_settings_bind_xfconf (XtmSettings *settings, XfconfChannel *channel)
|
||||
{
|
||||
GKeyFile *rc;
|
||||
gchar *filename;
|
||||
/* general settings */
|
||||
xfconf_g_property_bind (channel, SETTING_SHOW_STATUS_ICON, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "show-status-icon");
|
||||
xfconf_g_property_bind (channel, SETTING_PROMPT_TERMINATE_TASK, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "prompt-terminate-task");
|
||||
|
||||
if (0 != settings->loading)
|
||||
return;
|
||||
rc = g_key_file_new ();
|
||||
filename = g_strdup_printf ("%s/xfce4/xfce4-taskmanager.rc", g_get_user_config_dir ());
|
||||
/* interface settings */
|
||||
xfconf_g_property_bind (channel, SETTING_SHOW_ALL_PROCESSES, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "show-all-processes");
|
||||
xfconf_g_property_bind (channel, SETTING_SHOW_APPLICATION_ICONS, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "show-application-icons");
|
||||
xfconf_g_property_bind (channel, SETTING_FULL_COMMAND_LINE, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "full-command-line");
|
||||
xfconf_g_property_bind (channel, SETTING_MORE_PRECISION, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "more-precision");
|
||||
xfconf_g_property_bind (channel, SETTING_PROCESS_TREE, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "process-tree");
|
||||
xfconf_g_property_bind (channel, SETTING_REFRESH_RATE, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "prompt-terminate-task");
|
||||
xfconf_g_property_bind (channel, SETTING_REFRESH_RATE, G_TYPE_UINT,
|
||||
G_OBJECT (settings), "refresh-rate");
|
||||
|
||||
{
|
||||
const gchar *string;
|
||||
GValue dst = {0};
|
||||
GValue src = {0};
|
||||
GParamSpec **specs;
|
||||
GParamSpec *spec;
|
||||
guint nspecs;
|
||||
guint n;
|
||||
|
||||
specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), &nspecs);
|
||||
for (n = 0; n < nspecs; ++n)
|
||||
{
|
||||
spec = specs[n];
|
||||
g_value_init (&dst, G_TYPE_STRING);
|
||||
if (spec->value_type == G_TYPE_STRING)
|
||||
{
|
||||
g_object_get_property (G_OBJECT (settings), spec->name, &dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_value_init (&src, spec->value_type);
|
||||
g_object_get_property (G_OBJECT (settings), spec->name, &src);
|
||||
g_value_transform (&src, &dst);
|
||||
g_value_unset (&src);
|
||||
}
|
||||
string = g_value_get_string (&dst);
|
||||
|
||||
if (string != NULL)
|
||||
g_key_file_set_string (rc, "Settings", g_param_spec_get_nick (spec), string);
|
||||
|
||||
g_value_unset (&dst);
|
||||
}
|
||||
g_free (specs);
|
||||
}
|
||||
|
||||
{
|
||||
GError *error = NULL;
|
||||
gchar *data;
|
||||
gsize length;
|
||||
|
||||
if (!g_file_test (filename, G_FILE_TEST_EXISTS))
|
||||
{
|
||||
gchar *path = g_strdup_printf ("%s/xfce4", g_get_user_config_dir ());
|
||||
g_mkdir_with_parents (path, 0700);
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
data = g_key_file_to_data (rc, &length, NULL);
|
||||
if (!g_file_set_contents (filename, data, (gssize)length, &error))
|
||||
{
|
||||
g_warning ("Unable to save settings: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
g_free (filename);
|
||||
g_key_file_free (rc);
|
||||
/* column visibility */
|
||||
xfconf_g_property_bind (channel, SETTING_COLUMN_PID, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "column-pid");
|
||||
xfconf_g_property_bind (channel, SETTING_COLUMN_PPID, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "column-ppid");
|
||||
xfconf_g_property_bind (channel, SETTING_COLUMN_STATE, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "column-state");
|
||||
xfconf_g_property_bind (channel, SETTING_COLUMN_VSZ, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "column-vsz");
|
||||
xfconf_g_property_bind (channel, SETTING_COLUMN_RSS, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "column-rss");
|
||||
xfconf_g_property_bind (channel, SETTING_COLUMN_UID, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "column-uid");
|
||||
xfconf_g_property_bind (channel, SETTING_COLUMN_CPU, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "column-cpu");
|
||||
xfconf_g_property_bind (channel, SETTING_COLUMN_PRIORITY, G_TYPE_BOOLEAN,
|
||||
G_OBJECT (settings), "column-priority");
|
||||
}
|
||||
|
||||
|
||||
|
||||
XtmSettings *
|
||||
xtm_settings_get_default (void)
|
||||
{
|
||||
|
||||
@@ -16,6 +16,41 @@
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <xfconf/xfconf.h>
|
||||
|
||||
#define DEFAULT_WINDOW_HEIGHT 600
|
||||
#define DEFAULT_WINDOW_WIDTH 400
|
||||
|
||||
#define CHANNEL "xfce4-taskmanager"
|
||||
|
||||
/* general settings */
|
||||
#define SETTING_SHOW_STATUS_ICON "/show-status-icon"
|
||||
#define SETTING_PROMPT_TERMINATE_TASK "/prompt-terminate-task"
|
||||
#define SETTING_WINDOW_WIDTH "/window-width"
|
||||
#define SETTING_WINDOW_HEIGHT "/window-height"
|
||||
|
||||
/* interface settings */
|
||||
#define SETTING_SHOW_FILTER "/interface/show-filter"
|
||||
#define SETTING_HANDLE_POSITION "/interface/handle-position"
|
||||
#define SETTING_SHOW_LEGEND "/interface/show-legend"
|
||||
|
||||
#define SETTING_SHOW_ALL_PROCESSES "/interface/show-all-processes"
|
||||
#define SETTING_SHOW_APPLICATION_ICONS "/interface/show-application-icons"
|
||||
#define SETTING_FULL_COMMAND_LINE "/interface/full-command-line"
|
||||
#define SETTING_MORE_PRECISION "/interface/more-precision"
|
||||
#define SETTING_PROCESS_TREE "/interface/process-tree"
|
||||
#define SETTING_REFRESH_RATE "/interface/refresh-rate"
|
||||
|
||||
/* column visibility */
|
||||
#define SETTING_COLUMN_PID "/columns/column-pid"
|
||||
#define SETTING_COLUMN_PPID "/columns/column-ppid"
|
||||
#define SETTING_COLUMN_STATE "/columns/column-state"
|
||||
#define SETTING_COLUMN_VSZ "/columns/column-vsz"
|
||||
#define SETTING_COLUMN_RSS "/columns/column-rss"
|
||||
#define SETTING_COLUMN_UID "/columns/column-uid"
|
||||
#define SETTING_COLUMN_CPU "/columns/column-cpu"
|
||||
#define SETTING_COLUMN_PRIORITY "/columns/column-priority"
|
||||
|
||||
#define XTM_TYPE_SETTINGS (xtm_settings_get_type ())
|
||||
#define XTM_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_SETTINGS, XtmSettings))
|
||||
#define XTM_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_SETTINGS, XtmSettingsClass))
|
||||
@@ -25,7 +60,7 @@
|
||||
|
||||
typedef struct _XtmSettings XtmSettings;
|
||||
|
||||
void xtm_settings_save_settings (XtmSettings *settings);
|
||||
void xtm_settings_bind_xfconf (XtmSettings *settings, XfconfChannel *channel);
|
||||
GType xtm_settings_get_type (void);
|
||||
XtmSettings * xtm_settings_get_default (void);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user