[Xfce4-commits] <xfce4-settings:nick/settings-editor> Rework settings editor.
Nick Schermer
noreply at xfce.org
Sat Jan 28 22:12:02 CET 2012
Updating branch refs/heads/nick/settings-editor
to 27bb989dfb31d83416809017d970984123e1930b (commit)
from 57c2f204fe8c1156153fd22cd8097fd98554a7b9 (commit)
commit 27bb989dfb31d83416809017d970984123e1930b
Author: Nick Schermer <nick at xfce.org>
Date: Sat Jan 28 21:55:33 2012 +0100
Rework settings editor.
- Update the model when a property changes.
- Only limited UI, so but it directly in the code, no glade.
- Add property monitoring in separate window.
- Channel refresh from interface.
TODO:
- Add the settings edit dialog.
xfce4-settings-editor/Makefile.am | 24 +-
xfce4-settings-editor/main.c | 18 +-
xfce4-settings-editor/main_window.c | 1105 -----------------
xfce4-settings-editor/main_window.h | 21 -
.../xfce-settings-editor-dialog.c | 1290 ++++++++++++++++++++
.../xfce-settings-editor-dialog.h | 46 +
xfce4-settings-editor/xfce4-settings-editor.glade | 407 ------
7 files changed, 1346 insertions(+), 1565 deletions(-)
diff --git a/xfce4-settings-editor/Makefile.am b/xfce4-settings-editor/Makefile.am
index c6c9a2d..657a1f7 100644
--- a/xfce4-settings-editor/Makefile.am
+++ b/xfce4-settings-editor/Makefile.am
@@ -1,9 +1,6 @@
-# $Id: Makefile.am 27279 2008-07-13 19:24:20Z nick $
INCLUDES = \
-I${top_srcdir} \
- -DDATADIR=\"$(datadir)\" \
- -DSRCDIR=\"$(top_srcdir)\" \
-DLOCALEDIR=\"$(localedir)\" \
-DG_LOG_DOMAIN=\"xfce4-settings-editor\" \
$(PLATFORM_CPPFLAGS)
@@ -13,15 +10,14 @@ bin_PROGRAMS = \
xfce4_settings_editor_SOURCES = \
main.c \
- main_window.c main_window.h \
- xfce4-settings-editor_ui.h
+ xfce-settings-editor-dialog.c \
+ xfce-settings-editor-dialog.h
xfce4_settings_editor_CFLAGS = \
$(GTK_CFLAGS) \
$(LIBXFCE4UTIL_CFLAGS) \
$(LIBXFCE4UI_CFLAGS) \
$(XFCONF_CFLAGS) \
- $(EXO_CFLAGS) \
$(PLATFORM_CFLAGS)
xfce4_settings_editor_LDFLAGS = \
@@ -32,8 +28,7 @@ xfce4_settings_editor_LDADD = \
$(GTK_LIBS) \
$(LIBXFCE4UTIL_LIBS) \
$(LIBXFCE4UI_LIBS) \
- $(XFCONF_LIBS) \
- $(EXO_LIBS)
+ $(XFCONF_LIBS)
desktopdir = $(datadir)/applications
desktop_in_files = xfce4-settings-editor.desktop.in
@@ -42,20 +37,9 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
@INTLTOOL_DESKTOP_RULE@
EXTRA_DIST = \
- $(desktop_in_files) \
- xfce4-settings-editor.glade
+ $(desktop_in_files)
DISTCLEANFILES = \
$(desktop_DATA)
-if MAINTAINER_MODE
-
-BUILT_SOURCES = \
- xfce4-settings-editor_ui.h
-
-xfce4-settings-editor_ui.h: xfce4-settings-editor.glade
- exo-csource --static --strip-comments --strip-content --name=xfce4_settings_editor_ui $< >$@
-
-endif
-
# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
diff --git a/xfce4-settings-editor/main.c b/xfce4-settings-editor/main.c
index cda9cde..296fd39 100644
--- a/xfce4-settings-editor/main.c
+++ b/xfce4-settings-editor/main.c
@@ -33,7 +33,7 @@
#include <libxfce4util/libxfce4util.h>
#include <libxfce4ui/libxfce4ui.h>
-#include "main_window.h"
+#include "xfce-settings-editor-dialog.h"
/* option entries */
static gboolean opt_version = FALSE;
@@ -47,8 +47,8 @@ static GOptionEntry option_entries[] =
gint
main(gint argc, gchar **argv)
{
- GtkDialog *dialog;
- GError *error = NULL;
+ GtkWidget *dialog;
+ GError *error = NULL;
/* setup translation domain */
xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
@@ -96,16 +96,10 @@ main(gint argc, gchar **argv)
return EXIT_FAILURE;
}
- /* We don't want a gradient on our toolbar */
- gtk_rc_parse_string ("style \"xfce-no-shadow\"\n"
- "{\n"
- "GtkToolbar::shadow-type = GTK_SHADOW_NONE\n"
- "}\n"
- "class \"*\" style \"xfce-no-shadow\"\n");
+ dialog = xfce_settings_editor_dialog_new ();
+ gtk_window_present (GTK_WINDOW (dialog));
- dialog = xfce4_settings_editor_main_window_new();
-
- gtk_dialog_run (dialog);
+ gtk_main ();
/* shutdown xfconf */
xfconf_shutdown ();
diff --git a/xfce4-settings-editor/main_window.c b/xfce4-settings-editor/main_window.c
deleted file mode 100644
index 144c979..0000000
--- a/xfce4-settings-editor/main_window.c
+++ /dev/null
@@ -1,1105 +0,0 @@
-/*
- * Copyright (c) 2008 Stephan Arts <stephan at xfce.org>
- * Copyright (c) 2009-2010 Jérôme Guelfucci <jeromeg at xfce.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#include <gtk/gtk.h>
-#include <gdk/gdkkeysyms.h>
-
-#include <xfconf/xfconf.h>
-#include <libxfce4util/libxfce4util.h>
-#include <libxfce4ui/libxfce4ui.h>
-
-#include "xfce4-settings-editor_ui.h"
-#include "main_window.h"
-
-#define WINDOW_WIDTH 600
-#define WINDOW_HEIGHT 380
-#define HPANED_POSITION 200
-
-static XfconfChannel *current_channel = NULL;
-static gchar *current_property = NULL;
-
-enum {
- PROP_TYPE_EMPTY,
- PROP_TYPE_STRING,
- PROP_TYPE_INT,
- PROP_TYPE_UINT,
- PROP_TYPE_INT64,
- PROP_TYPE_UINT64,
- PROP_TYPE_DOUBLE,
- PROP_TYPE_BOOLEAN,
- PROP_TYPE_ARRAY /* Not used yet */
-};
-
-static void
-load_channels (GtkListStore *store, GtkTreeView *treeview);
-static void
-update_iter (gboolean empty, XfconfChannel *channel, gchar *key, GtkTreeStore *store, GtkTreeIter *child_iter);
-static void
-load_properties (XfconfChannel *channel, GtkTreeStore *store, GtkTreeView *treeview);
-
-static void
-cb_channel_treeview_selection_changed (GtkTreeSelection *selection, GtkBuilder *builder);
-static void
-cb_property_treeview_selection_changed (GtkTreeSelection *selection, GtkBuilder *builder);
-static void
-cb_property_treeview_row_activated (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, GtkBuilder *builder);
-static gboolean
-cb_property_treeview_key_pressed (GtkWidget *widget, GdkEventKey *event, GtkBuilder *builder);
-static void
-cb_property_new_button_clicked (GtkButton *button, GtkBuilder *builder);
-static void
-cb_property_edit_button_clicked (GtkButton *button, GtkBuilder *builder);
-static void
-cb_property_revert_button_clicked (GtkButton *button, GtkBuilder *builder);
-static void
-cb_settings_editor_dialog_response (GtkWidget *dialog, gint response, GtkBuilder *builder);
-static void
-cb_channel_property_changed (XfconfChannel *channel, gchar *property, GValue *value, GtkBuilder *builder);
-static gboolean
-xfconf_property_is_valid(const gchar *property, GError **error);
-static void
-channel_treeview_popup_menu (GtkWidget *widget, GdkEventButton *event, GtkBuilder *builder);
-static gboolean
-cb_channel_treeview_button_press_event (GtkWidget *widget, GdkEventButton *event, GtkBuilder *builder);
-static gboolean
-cb_channel_treeview_popup_menu (GtkWidget *widget, GtkBuilder *builder);
-static void
-cb_channel_popup_menu_remove_item_activate (GtkMenuItem *item, GtkBuilder *builder);
-static void
-print_list (gpointer data, gpointer user_data);
-
-
-GtkDialog *
-xfce4_settings_editor_main_window_new(void)
-{
- gint width, height, position, i;
- GObject *dialog;
- GObject *channel_treeview;
- GObject *property_treeview;
- GObject *hpaned;
- XfconfChannel *channel;
- GtkBuilder *builder = NULL;
- GtkListStore *channel_list_store;
- GtkTreeStore *property_tree_store;
- GtkCellRenderer *renderer;
- GtkTreeSelection *selection;
- GObject *property_edit_button, *property_new_button, *property_revert_button;
-
- /* hook to make sure the libxfce4ui library is linked */
- if (xfce_titled_dialog_get_type () == 0)
- return NULL;
-
- builder = gtk_builder_new ();
- gtk_builder_add_from_string (builder, xfce4_settings_editor_ui, xfce4_settings_editor_ui_length, NULL);
-
- dialog = gtk_builder_get_object (builder, "main_dialog");
- g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) g_object_unref, builder);
-
- gtk_widget_add_events (GTK_WIDGET (dialog), GDK_KEY_PRESS_MASK);
-
- hpaned = gtk_builder_get_object (builder, "hpaned2");
-
- /* Set the default size of the window */
- channel = xfconf_channel_get ("xfce4-settings-editor");
- width = xfconf_channel_get_int (channel, "/window-width", WINDOW_WIDTH);
- height = xfconf_channel_get_int (channel, "/window-height", WINDOW_HEIGHT);
- position = xfconf_channel_get_int (channel, "/hpaned-position", HPANED_POSITION);
- gtk_window_set_default_size (GTK_WINDOW (dialog), width, height);
- gtk_paned_set_position (GTK_PANED (hpaned), position);
-
- g_signal_connect (dialog, "response", G_CALLBACK (cb_settings_editor_dialog_response), builder);
-
- channel_treeview = gtk_builder_get_object (builder, "channel_treeview");
- property_treeview = gtk_builder_get_object (builder, "property_treeview");
-
- property_edit_button = gtk_builder_get_object (builder, "property_edit_button");
- property_new_button = gtk_builder_get_object (builder, "property_new_button");
- property_revert_button = gtk_builder_get_object (builder, "property_revert_button");
-
- gtk_widget_set_sensitive (GTK_WIDGET (property_edit_button), FALSE);
- gtk_widget_set_sensitive (GTK_WIDGET (property_revert_button), FALSE);
-
- /*
- * Channel List
- */
- channel_list_store = gtk_list_store_new (1, G_TYPE_STRING);
-
- gtk_tree_view_set_model (GTK_TREE_VIEW (channel_treeview), GTK_TREE_MODEL (channel_list_store));
-
- renderer = gtk_cell_renderer_text_new();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (channel_treeview), 1, _("Channel"), renderer, "text", 0, NULL);
-
- /* Set sorting */
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (channel_list_store), 0, GTK_SORT_ASCENDING);
-
- /*
- * property list
- */
- property_tree_store = gtk_tree_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
-
- gtk_tree_view_set_model (GTK_TREE_VIEW (property_treeview), GTK_TREE_MODEL (property_tree_store));
-
- renderer = gtk_cell_renderer_text_new();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (property_treeview), 0, _("Property"), renderer, "text", 0, NULL);
-
- renderer = gtk_cell_renderer_text_new();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (property_treeview), 1, _("Type"), renderer, "text", 1, NULL);
-
- renderer = gtk_cell_renderer_toggle_new();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (property_treeview), 2, _("Locked"), renderer, "active", 2, NULL);
-
- renderer = gtk_cell_renderer_text_new();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (property_treeview), 3, _("Value"), renderer, "text", 3, NULL);
-
- /* Allow the user to sort the column items by clicking on headers */
- for (i = 0; i < 4; i++)
- gtk_tree_view_column_set_sort_column_id (gtk_tree_view_get_column (GTK_TREE_VIEW (property_treeview), i), i);
-
- /* Allow the user to resize the columns */
- gtk_tree_view_column_set_resizable (gtk_tree_view_get_column (GTK_TREE_VIEW (property_treeview), 0), TRUE);
- gtk_tree_view_column_set_resizable (gtk_tree_view_get_column (GTK_TREE_VIEW (property_treeview), 1), TRUE);
- gtk_tree_view_column_set_resizable (gtk_tree_view_get_column (GTK_TREE_VIEW (property_treeview), 2), TRUE);
- gtk_tree_view_column_set_resizable (gtk_tree_view_get_column (GTK_TREE_VIEW (property_treeview), 3), TRUE);
-
- /* Set sorting */
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (property_tree_store), 0, GTK_SORT_ASCENDING);
-
- /* improve usability by expanding nodes when clicking on them */
- g_signal_connect (G_OBJECT (property_treeview), "row-activated", G_CALLBACK (cb_property_treeview_row_activated), builder);
-
- /* Set a handler for key-press-event */
- g_signal_connect (G_OBJECT (property_treeview), "key-press-event", G_CALLBACK (cb_property_treeview_key_pressed), builder);
-
- /* selection handling */
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (channel_treeview));
- g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK (cb_channel_treeview_selection_changed), builder);
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (property_treeview));
- g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK (cb_property_treeview_selection_changed), builder);
-
- /* Connect signal-handlers for the popup-menu and button-press-event events */
- g_signal_connect (G_OBJECT (channel_treeview), "popup-menu", G_CALLBACK (cb_channel_treeview_popup_menu), builder);
- g_signal_connect (G_OBJECT (channel_treeview), "button-press-event", G_CALLBACK (cb_channel_treeview_button_press_event), builder);
-
- /* Connect signal-handlers to toolbar buttons */
- g_signal_connect (G_OBJECT (property_new_button), "clicked", G_CALLBACK (cb_property_new_button_clicked), builder);
- g_signal_connect (G_OBJECT (property_edit_button), "clicked", G_CALLBACK (cb_property_edit_button_clicked), builder);
- g_signal_connect (G_OBJECT (property_revert_button), "clicked", G_CALLBACK (cb_property_revert_button_clicked), builder);
-
- load_channels (channel_list_store, GTK_TREE_VIEW (channel_treeview));
-
- return GTK_DIALOG (dialog);
-}
-
-/**
- * load_channels
- *
- * get the available channels from xfconf and put them in the treemodel
- */
-static void
-load_channels (GtkListStore *store, GtkTreeView *treeview)
-{
- GtkTreeIter iter;
- gchar **channel_names;
- guint i;
- GtkTreeSelection *selection;
-
- channel_names = xfconf_list_channels();
- if (channel_names != NULL)
- {
- for (i = 0; channel_names[i] != NULL; i++)
- {
- gtk_list_store_insert_with_values (store, NULL, i,
- 0, channel_names[i], -1);
- }
-
- g_strfreev (channel_names);
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
- if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter))
- gtk_tree_selection_select_iter (selection, &iter);
- }
-}
-
-static void print_list (gpointer data, gpointer user_data)
-{
- TRACE ("%s", (gchar *) data);
-}
-
-static void update_iter (gboolean not_empty, XfconfChannel *channel, gchar *key, GtkTreeStore *store, GtkTreeIter *child_iter)
-{
- GValue child_locked = {0, };
- GValue child_type = {0, };
- GValue child_value = {0, };
-
- g_value_init (&child_locked, G_TYPE_BOOLEAN);
- g_value_init (&child_type, G_TYPE_STRING);
- g_value_init (&child_value, G_TYPE_STRING);
-
- if (not_empty)
- {
- GValue property_value = {0, };
-
- xfconf_channel_get_property (channel, key, &property_value);
-
- switch (G_VALUE_TYPE(&property_value))
- {
- case G_TYPE_INT:
- g_value_set_string (&child_type, "Int");
- g_value_transform (&property_value, &child_value);
- break;
- case G_TYPE_UINT:
- g_value_set_string (&child_type, "Unsigned Int");
- g_value_transform (&property_value, &child_value);
- break;
- case G_TYPE_INT64:
- g_value_set_string (&child_type, "Int64");
- g_value_transform (&property_value, &child_value);
- break;
- case G_TYPE_UINT64:
- g_value_set_string (&child_type, "Unsigned Int64");
- g_value_transform (&property_value, &child_value);
- break;
- case G_TYPE_DOUBLE:
- g_value_set_string (&child_type, "Double");
- g_value_transform (&property_value, &child_value);
- break;
- case G_TYPE_STRING:
- g_value_set_string (&child_type, "String");
- g_value_copy (&property_value, &child_value);
- break;
- case G_TYPE_BOOLEAN:
- g_value_set_string (&child_type, "Bool");
- g_value_transform (&property_value, &child_value);
- break;
- default:
- g_value_set_string (&child_type, g_type_name (G_VALUE_TYPE(&property_value)));
- break;
- }
-
- g_value_unset (&property_value);
- }
- else
- g_value_set_string (&child_type, _("Empty"));
-
- gtk_tree_store_set_value (store, child_iter, 1, &child_type);
- g_value_unset (&child_type);
-
- g_value_set_boolean (&child_locked, xfconf_channel_is_property_locked (channel, key));
- gtk_tree_store_set_value (store, child_iter, 2, &child_locked);
- g_value_unset (&child_locked);
-
- gtk_tree_store_set_value (store, child_iter, 3, &child_value);
- g_value_unset (&child_value);
-}
-
-/**
- * load_properties
- *
- * get the available properties from xfconf and put them in the treemodel
- */
-static void
-load_properties (XfconfChannel *channel, GtkTreeStore *store, GtkTreeView *treeview)
-{
- gint i = 0;
- gchar *key;
- GList *keys, *_keys;
- GtkTreeIter parent_iter;
- GtkTreeIter child_iter;
- GValue parent_val = {0,};
-
- GValue child_name = {0,};
-
- GHashTable *hash_table;
- gchar **components;
-
- g_value_init (&child_name, G_TYPE_STRING);
-
- hash_table = xfconf_channel_get_properties (channel, NULL);
-
- if (hash_table != NULL)
- {
- keys = g_hash_table_get_keys (hash_table);
- g_list_foreach (keys, (GFunc) print_list, NULL);
- for(_keys = keys; _keys != NULL; _keys = g_list_next (_keys))
- {
- key = _keys->data;
- TRACE ("Key: %s", key);
- components = g_strsplit (key, "/", 0);
-
- /* components[0] will be empty because properties start with '/'*/
- for (i = 1; components[i]; ++i)
- {
- TRACE ("Component: %s", components[i]);
-
- /* Check if this parent has children */
- if (gtk_tree_model_iter_children (GTK_TREE_MODEL (store), &child_iter, i==1?NULL:&parent_iter))
- {
- TRACE ("Parent has children");
-
- while (1)
- {
- /* Check if the component already exists, if so, return this child */
- gtk_tree_model_get_value (GTK_TREE_MODEL(store), &child_iter, 0, &parent_val);
- if (!g_strcmp0 (components[i], g_value_get_string (&parent_val)))
- {
- GValue current_parent_value = {0, };
-
- TRACE ("Component already exists");
- g_value_unset (&parent_val);
-
- gtk_tree_model_get_value (GTK_TREE_MODEL(store), &child_iter, 3, ¤t_parent_value);
-
- if (!g_value_get_string (¤t_parent_value))
- update_iter (!components[i+1], channel, key, store, &child_iter);
-
- g_value_unset (¤t_parent_value);
-
- break;
- }
- else
- g_value_unset (&parent_val);
-
- /* If we are at the end of the list of children, the required child is not available and should be created */
- if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &child_iter))
- {
- TRACE ("Create the children");
- gtk_tree_store_append (store, &child_iter, i==1?NULL:&parent_iter);
- g_value_set_string (&child_name, components[i]);
- gtk_tree_store_set_value (store, &child_iter, 0, &child_name);
- g_value_reset (&child_name);
-
- update_iter (!components[i+1], channel, key, store, &child_iter);
-
- break;
- }
- }
- }
- else
- {
- /* If the parent does not have any children, create this one */
- TRACE ("Parent has no children");
- gtk_tree_store_append (store, &child_iter, i==1?NULL:&parent_iter);
- g_value_set_string (&child_name, components[i]);
- gtk_tree_store_set_value (store, &child_iter, 0, &child_name);
- g_value_reset (&child_name);
-
- update_iter (!components[i+1], channel, key, store, &child_iter);
- }
- parent_iter = child_iter;
- }
-
- g_strfreev (components);
-
- }
-
- g_list_free (keys);
- g_hash_table_destroy (hash_table);
- }
-}
-
-static void
-cb_property_treeview_row_activated (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, GtkBuilder *builder)
-{
- GtkTreeModel *model;
- GtkTreeIter iter;
-
- model = gtk_tree_view_get_model (tree_view);
- gtk_tree_model_get_iter (model, &iter, path);
-
- if (gtk_tree_model_iter_has_child (model, &iter))
- {
- if (gtk_tree_view_row_expanded (tree_view, path))
- gtk_tree_view_collapse_row (tree_view, path);
- else
- gtk_tree_view_expand_row (tree_view, path, FALSE);
-
- }
- else
- cb_property_edit_button_clicked (NULL, builder);
-}
-
-static void
-cb_channel_treeview_selection_changed (GtkTreeSelection *selection, GtkBuilder *builder)
-{
- GtkTreeModel *model;
- GtkTreeIter iter;
- XfconfChannel *channel;
- GObject *property_treeview;
- GObject *property_new_button;
- GtkTreeModel *tree_store = NULL;
- GValue value = {0, };
-
- property_new_button = gtk_builder_get_object (builder, "property_new_button");
-
- if (current_channel)
- {
- g_object_unref (G_OBJECT(current_channel));
- current_channel = NULL;
- }
-
- if (!gtk_tree_selection_get_selected (selection, &model, &iter))
- {
- gtk_widget_set_sensitive (GTK_WIDGET (property_new_button), FALSE);
- return;
- }
-
- gtk_widget_set_sensitive (GTK_WIDGET (property_new_button), TRUE);
-
- property_treeview = gtk_builder_get_object (builder, "property_treeview");
- tree_store = gtk_tree_view_get_model (GTK_TREE_VIEW (property_treeview));
-
- gtk_tree_model_get_value (model, &iter, 0, &value);
-
- g_return_if_fail (G_VALUE_HOLDS_STRING (&value));
-
- channel = xfconf_channel_new (g_value_get_string (&value));
-
- gtk_tree_store_clear (GTK_TREE_STORE(tree_store));
- load_properties (channel, GTK_TREE_STORE(tree_store), GTK_TREE_VIEW(property_treeview));
-
- current_channel = channel;
-
- g_signal_connect (channel, "property-changed", G_CALLBACK (cb_channel_property_changed), builder);
-}
-
-static gboolean
-cb_channel_treeview_button_press_event (GtkWidget *widget, GdkEventButton *event, GtkBuilder *builder)
-{
- if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
- channel_treeview_popup_menu (widget, event, builder);
-
- return FALSE;
-}
-
-static gboolean
-cb_channel_treeview_popup_menu (GtkWidget *widget, GtkBuilder *builder)
-{
- channel_treeview_popup_menu (widget, NULL, builder);
- return TRUE;
-}
-
-static void
-cb_property_treeview_selection_changed (GtkTreeSelection *selection, GtkBuilder *builder)
-{
- GtkTreeModel *model;
- GtkTreeIter iter;
- GtkTreeIter p_iter;
- gboolean locked;
- GObject *property_edit_button;
- GObject *property_revert_button;
- GValue value = {0, };
- gchar *prop_name = NULL;
- const gchar *prop_type;
- gchar *temp = NULL;
-
- property_edit_button = gtk_builder_get_object (builder, "property_edit_button");
- property_revert_button = gtk_builder_get_object (builder, "property_revert_button");
-
- if (current_property)
- {
- g_free (prop_name);
- current_property = NULL;
- }
-
- /* return if no property is selected */
- if (!gtk_tree_selection_get_selected (selection, &model, &iter))
- {
- gtk_widget_set_sensitive (GTK_WIDGET (property_edit_button), FALSE);
- gtk_widget_set_sensitive (GTK_WIDGET (property_revert_button), FALSE);
-
- return;
- }
-
- /* create the complete property-name */
- gtk_tree_model_get_value (model, &iter, 0, &value);
- prop_name = g_strconcat ("/", g_value_get_string(&value), NULL);
- g_value_unset (&value);
-
- /* to create the complete property-name, we need it's parents too */
- while (gtk_tree_model_iter_parent (model, &p_iter, &iter))
- {
- gtk_tree_model_get_value (model, &p_iter, 0, &value);
- temp = g_strconcat ("/", g_value_get_string(&value), prop_name, NULL);
- g_value_unset (&value);
-
- if (prop_name)
- g_free (prop_name);
- prop_name = temp;
-
- iter = p_iter;
- }
-
- current_property = prop_name;
-
- /* Set the state of the edit and reset buttons */
- locked = xfconf_channel_is_property_locked (current_channel, current_property);
-
- gtk_widget_set_sensitive (GTK_WIDGET (property_edit_button), !locked);
- gtk_widget_set_sensitive (GTK_WIDGET (property_revert_button), !locked);
-
- /* If type is Empty, we don't want the user to edit the property */
- gtk_tree_selection_get_selected (selection, &model, &iter);
- gtk_tree_model_get_value (model, &iter, 1, &value);
-
- prop_type = g_value_get_string (&value);
-
- if ((g_strcmp0 (prop_type, "Empty") == 0) || g_strcmp0 (prop_type, "GPtrArray_GValue_") == 0)
- gtk_widget_set_sensitive (GTK_WIDGET (property_edit_button), FALSE);
- g_value_unset (&value);
-}
-
-static gboolean
-cb_property_treeview_key_pressed (GtkWidget *widget, GdkEventKey *event, GtkBuilder *builder)
-{
- GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
-
- if (event->keyval == GDK_Delete && gtk_tree_selection_get_selected (selection, NULL, NULL))
- {
- cb_property_revert_button_clicked (NULL, builder);
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-cb_type_combo_changed (GtkComboBox *widget, GtkBuilder *builder)
-{
- GObject *prop_value_text_entry = gtk_builder_get_object (builder, "property_value_text_entry");
- GObject *prop_value_spin_button = gtk_builder_get_object (builder, "property_value_spin_button");
- GObject *prop_value_sw = gtk_builder_get_object (builder, "property_value_sw");
- GObject *prop_value_checkbox = gtk_builder_get_object (builder, "property_value_checkbutton");
-
- switch (gtk_combo_box_get_active (widget))
- {
- case PROP_TYPE_STRING:
- gtk_widget_hide (GTK_WIDGET (prop_value_spin_button));
- gtk_widget_show (GTK_WIDGET (prop_value_text_entry));
- gtk_widget_hide (GTK_WIDGET (prop_value_sw));
- gtk_widget_hide (GTK_WIDGET (prop_value_checkbox));
- break;
- case PROP_TYPE_INT:
- gtk_widget_show (GTK_WIDGET (prop_value_spin_button));
- gtk_widget_hide (GTK_WIDGET (prop_value_text_entry));
- gtk_widget_hide (GTK_WIDGET (prop_value_sw));
- gtk_widget_hide (GTK_WIDGET (prop_value_checkbox));
- gtk_spin_button_set_range (GTK_SPIN_BUTTON (prop_value_spin_button), G_MININT, G_MAXINT);
- gtk_spin_button_set_digits (GTK_SPIN_BUTTON (prop_value_spin_button), 0);
- break;
- case PROP_TYPE_UINT:
- gtk_widget_show (GTK_WIDGET (prop_value_spin_button));
- gtk_widget_hide (GTK_WIDGET (prop_value_text_entry));
- gtk_widget_hide (GTK_WIDGET (prop_value_sw));
- gtk_widget_hide (GTK_WIDGET (prop_value_checkbox));
- gtk_spin_button_set_range (GTK_SPIN_BUTTON (prop_value_spin_button), 0, G_MAXINT);
- gtk_spin_button_set_digits (GTK_SPIN_BUTTON (prop_value_spin_button), 0);
- break;
- case PROP_TYPE_INT64:
- gtk_widget_show (GTK_WIDGET (prop_value_spin_button));
- gtk_widget_hide (GTK_WIDGET (prop_value_text_entry));
- gtk_widget_hide (GTK_WIDGET (prop_value_sw));
- gtk_widget_hide (GTK_WIDGET (prop_value_checkbox));
- gtk_spin_button_set_range (GTK_SPIN_BUTTON (prop_value_spin_button), G_MININT64, G_MAXINT64);
- gtk_spin_button_set_digits (GTK_SPIN_BUTTON (prop_value_spin_button), 0);
- break;
- case PROP_TYPE_UINT64:
- gtk_widget_show (GTK_WIDGET (prop_value_spin_button));
- gtk_widget_hide (GTK_WIDGET (prop_value_text_entry));
- gtk_widget_hide (GTK_WIDGET (prop_value_sw));
- gtk_widget_hide (GTK_WIDGET (prop_value_checkbox));
- gtk_spin_button_set_range (GTK_SPIN_BUTTON (prop_value_spin_button), 0, G_MAXUINT64);
- gtk_spin_button_set_digits (GTK_SPIN_BUTTON (prop_value_spin_button), 0);
- break;
- case PROP_TYPE_DOUBLE:
- gtk_widget_show (GTK_WIDGET (prop_value_spin_button));
- gtk_widget_hide (GTK_WIDGET (prop_value_text_entry));
- gtk_widget_hide (GTK_WIDGET (prop_value_sw));
- gtk_widget_hide (GTK_WIDGET (prop_value_checkbox));
- gtk_spin_button_set_range (GTK_SPIN_BUTTON (prop_value_spin_button), G_MINDOUBLE, G_MAXDOUBLE);
- gtk_spin_button_set_digits (GTK_SPIN_BUTTON (prop_value_spin_button), 2);
- break;
- case PROP_TYPE_BOOLEAN:
- gtk_widget_hide (GTK_WIDGET (prop_value_spin_button));
- gtk_widget_hide (GTK_WIDGET (prop_value_text_entry));
- gtk_widget_hide (GTK_WIDGET (prop_value_sw));
- gtk_widget_show (GTK_WIDGET (prop_value_checkbox));
- break;
- default:
- return;
- break;
- }
-}
-
-static void
-cb_property_new_button_clicked (GtkButton *button, GtkBuilder *builder)
-{
- GObject *dialog = gtk_builder_get_object (builder, "edit_settings_dialog");
- GObject *prop_name_entry = gtk_builder_get_object (builder, "property_name_entry");
- GObject *prop_type_combo = gtk_builder_get_object (builder, "property_type_combo");
-
- GObject *prop_value_text_entry = gtk_builder_get_object (builder, "property_value_text_entry");
- GObject *prop_value_spin_button = gtk_builder_get_object (builder, "property_value_spin_button");
- GObject *prop_value_checkbox = gtk_builder_get_object (builder, "property_value_checkbutton");
-
- g_signal_connect (prop_type_combo, "changed", G_CALLBACK (cb_type_combo_changed), builder);
-
- /* Default to string properties */
- gtk_combo_box_set_active (GTK_COMBO_BOX (prop_type_combo), PROP_TYPE_STRING);
- gtk_widget_set_sensitive (GTK_WIDGET (prop_type_combo), TRUE);
-
- /* Reset all the value fields */
- gtk_entry_set_text (GTK_ENTRY (prop_name_entry), "");
- gtk_entry_set_text (GTK_ENTRY (prop_value_text_entry), "");
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (prop_value_spin_button), 0);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prop_value_checkbox), TRUE);
-
- if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_APPLY)
- {
- const gchar *prop_name = gtk_entry_get_text (GTK_ENTRY (prop_name_entry));
- GValue value = {0, };
- GError *error = NULL;
- GObject *property_treeview;
- GtkTreeModel *tree_store;
-
- gtk_widget_hide (GTK_WIDGET (dialog));
-
- if (!xfconf_property_is_valid (prop_name, &error))
- {
- GObject *main_window = gtk_builder_get_object (builder, "main_dialog");
-
- xfce_dialog_show_error (GTK_WINDOW (main_window), error, _("This property name is not valid."));
-
- g_error_free (error);
- return;
- }
-
- switch (gtk_combo_box_get_active (GTK_COMBO_BOX (prop_type_combo)))
- {
- case PROP_TYPE_EMPTY:
- break;
- case PROP_TYPE_STRING:
- g_value_init (&value, G_TYPE_STRING);
- g_value_set_string (&value, gtk_entry_get_text (GTK_ENTRY (prop_value_text_entry)));
- break;
- case PROP_TYPE_INT:
- g_value_init (&value, G_TYPE_INT);
- g_value_set_int (&value, gtk_spin_button_get_value (GTK_SPIN_BUTTON (prop_value_spin_button)));
- break;
- case PROP_TYPE_UINT:
- g_value_init (&value, G_TYPE_UINT);
- g_value_set_uint (&value, gtk_spin_button_get_value (GTK_SPIN_BUTTON (prop_value_spin_button)));
- break;
- case PROP_TYPE_INT64:
- g_value_init (&value, G_TYPE_INT64);
- g_value_set_int64 (&value, gtk_spin_button_get_value (GTK_SPIN_BUTTON (prop_value_spin_button)));
- break;
- case PROP_TYPE_UINT64:
- g_value_init (&value, G_TYPE_UINT64);
- g_value_set_uint64 (&value, gtk_spin_button_get_value (GTK_SPIN_BUTTON (prop_value_spin_button)));
- break;
- case PROP_TYPE_DOUBLE:
- g_value_init (&value, G_TYPE_DOUBLE);
- g_value_set_double (&value, gtk_spin_button_get_value (GTK_SPIN_BUTTON (prop_value_spin_button)));
- break;
- case PROP_TYPE_BOOLEAN:
- g_value_init (&value, G_TYPE_BOOLEAN);
- g_value_set_boolean (&value, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prop_value_checkbox)));
- break;
- case PROP_TYPE_ARRAY:
- break;
- }
-
- xfconf_channel_set_property (current_channel, prop_name, &value);
-
- /* Refresh the view */
- property_treeview = gtk_builder_get_object (builder, "property_treeview");
- tree_store = gtk_tree_view_get_model (GTK_TREE_VIEW (property_treeview));
-
- gtk_tree_store_clear (GTK_TREE_STORE(tree_store));
- load_properties (current_channel, GTK_TREE_STORE (tree_store), GTK_TREE_VIEW (property_treeview));
- }
- else
- gtk_widget_hide (GTK_WIDGET (dialog));
-}
-
-static void
-cb_property_edit_button_clicked (GtkButton *button, GtkBuilder *builder)
-{
- GValue value = {0, };
-
- GObject *dialog = gtk_builder_get_object (builder, "edit_settings_dialog");
- GObject *prop_name_entry = gtk_builder_get_object (builder, "property_name_entry");
- GObject *prop_type_combo = gtk_builder_get_object (builder, "property_type_combo");
-
- GObject *prop_value_text_entry = gtk_builder_get_object (builder, "property_value_text_entry");
- GObject *prop_value_spin_button = gtk_builder_get_object (builder, "property_value_spin_button");
- GObject *prop_value_sw = gtk_builder_get_object (builder, "property_value_sw");
- GObject *prop_value_checkbox = gtk_builder_get_object (builder, "property_value_checkbutton");
-
- /* Set the correct properties in the ui */
- gtk_entry_set_text (GTK_ENTRY(prop_name_entry), current_property);
- gtk_widget_set_sensitive (GTK_WIDGET (prop_type_combo), FALSE);
-
- if (xfconf_channel_get_property (current_channel, current_property, &value))
- {
- switch (G_VALUE_TYPE(&value))
- {
- case G_TYPE_STRING:
- gtk_combo_box_set_active (GTK_COMBO_BOX (prop_type_combo), PROP_TYPE_STRING);
- gtk_widget_hide (GTK_WIDGET (prop_value_spin_button));
- gtk_widget_show (GTK_WIDGET (prop_value_text_entry));
- gtk_widget_hide (GTK_WIDGET (prop_value_sw));
- gtk_widget_hide (GTK_WIDGET (prop_value_checkbox));
- gtk_entry_set_text (GTK_ENTRY (prop_value_text_entry), g_value_get_string (&value));
- break;
- case G_TYPE_INT:
- gtk_combo_box_set_active (GTK_COMBO_BOX (prop_type_combo), PROP_TYPE_INT);
- gtk_widget_show (GTK_WIDGET (prop_value_spin_button));
- gtk_widget_hide (GTK_WIDGET (prop_value_text_entry));
- gtk_widget_hide (GTK_WIDGET (prop_value_sw));
- gtk_widget_hide (GTK_WIDGET (prop_value_checkbox));
- gtk_spin_button_set_range (GTK_SPIN_BUTTON (prop_value_spin_button), G_MININT, G_MAXINT);
- gtk_spin_button_set_digits (GTK_SPIN_BUTTON (prop_value_spin_button), 0);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (prop_value_spin_button), g_value_get_int (&value));
- break;
- case G_TYPE_UINT:
- gtk_combo_box_set_active (GTK_COMBO_BOX (prop_type_combo), PROP_TYPE_UINT);
- gtk_widget_show (GTK_WIDGET (prop_value_spin_button));
- gtk_widget_hide (GTK_WIDGET (prop_value_text_entry));
- gtk_widget_hide (GTK_WIDGET (prop_value_sw));
- gtk_widget_hide (GTK_WIDGET (prop_value_checkbox));
- gtk_spin_button_set_range (GTK_SPIN_BUTTON (prop_value_spin_button), 0, G_MAXUINT);
- gtk_spin_button_set_digits (GTK_SPIN_BUTTON (prop_value_spin_button), 0);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (prop_value_spin_button), g_value_get_uint (&value));
- break;
- case G_TYPE_INT64:
- gtk_combo_box_set_active (GTK_COMBO_BOX (prop_type_combo), PROP_TYPE_INT64);
- gtk_widget_show (GTK_WIDGET (prop_value_spin_button));
- gtk_widget_hide (GTK_WIDGET (prop_value_text_entry));
- gtk_widget_hide (GTK_WIDGET (prop_value_sw));
- gtk_widget_hide (GTK_WIDGET (prop_value_checkbox));
- gtk_spin_button_set_range (GTK_SPIN_BUTTON (prop_value_spin_button), G_MININT64, G_MAXINT64);
- gtk_spin_button_set_digits (GTK_SPIN_BUTTON (prop_value_spin_button), 0);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (prop_value_spin_button), g_value_get_int64 (&value));
- break;
- case G_TYPE_UINT64:
- gtk_combo_box_set_active (GTK_COMBO_BOX (prop_type_combo), PROP_TYPE_UINT64);
- gtk_widget_show (GTK_WIDGET (prop_value_spin_button));
- gtk_widget_hide (GTK_WIDGET (prop_value_text_entry));
- gtk_widget_hide (GTK_WIDGET (prop_value_sw));
- gtk_widget_hide (GTK_WIDGET (prop_value_checkbox));
- gtk_spin_button_set_range (GTK_SPIN_BUTTON (prop_value_spin_button), 0, G_MAXUINT64);
- gtk_spin_button_set_digits (GTK_SPIN_BUTTON (prop_value_spin_button), 0);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (prop_value_spin_button), g_value_get_uint64 (&value));
- break;
- case G_TYPE_DOUBLE:
- gtk_combo_box_set_active (GTK_COMBO_BOX (prop_type_combo), PROP_TYPE_DOUBLE);
- gtk_widget_show (GTK_WIDGET (prop_value_spin_button));
- gtk_widget_hide (GTK_WIDGET (prop_value_text_entry));
- gtk_widget_hide (GTK_WIDGET (prop_value_sw));
- gtk_widget_hide (GTK_WIDGET (prop_value_checkbox));
- gtk_spin_button_set_range (GTK_SPIN_BUTTON (prop_value_spin_button), G_MINDOUBLE, G_MAXDOUBLE);
- gtk_spin_button_set_digits (GTK_SPIN_BUTTON (prop_value_spin_button), 2);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (prop_value_spin_button), g_value_get_double (&value));
- break;
- case G_TYPE_BOOLEAN:
- gtk_combo_box_set_active (GTK_COMBO_BOX (prop_type_combo), PROP_TYPE_BOOLEAN);
- gtk_widget_hide (GTK_WIDGET (prop_value_spin_button));
- gtk_widget_hide (GTK_WIDGET (prop_value_text_entry));
- gtk_widget_hide (GTK_WIDGET (prop_value_sw));
- gtk_widget_show (GTK_WIDGET (prop_value_checkbox));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prop_value_checkbox), g_value_get_boolean (&value));
- break;
- default:
- return;
- break;
- }
- }
- else
- gtk_combo_box_set_active (GTK_COMBO_BOX (prop_type_combo), PROP_TYPE_EMPTY);
-
- if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_APPLY)
- {
- gchar *prop_name;
- GError *error = NULL;
-
- gtk_widget_hide (GTK_WIDGET (dialog));
- switch (gtk_combo_box_get_active (GTK_COMBO_BOX (prop_type_combo)))
- {
- case PROP_TYPE_EMPTY:
- break;
- case PROP_TYPE_STRING:
- g_value_set_string (&value, gtk_entry_get_text (GTK_ENTRY (prop_value_text_entry)));
- break;
- case PROP_TYPE_INT:
- g_value_set_int (&value, gtk_spin_button_get_value (GTK_SPIN_BUTTON (prop_value_spin_button)));
- break;
- case PROP_TYPE_UINT:
- g_value_set_uint (&value, gtk_spin_button_get_value (GTK_SPIN_BUTTON (prop_value_spin_button)));
- break;
- case PROP_TYPE_INT64:
- g_value_set_int64 (&value, gtk_spin_button_get_value (GTK_SPIN_BUTTON (prop_value_spin_button)));
- break;
- case PROP_TYPE_UINT64:
- g_value_set_uint64 (&value, gtk_spin_button_get_value (GTK_SPIN_BUTTON (prop_value_spin_button)));
- break;
- case PROP_TYPE_DOUBLE:
- g_value_set_double (&value, gtk_spin_button_get_value (GTK_SPIN_BUTTON (prop_value_spin_button)));
- break;
- case PROP_TYPE_BOOLEAN:
- g_value_set_boolean (&value, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prop_value_checkbox)));
- break;
- case PROP_TYPE_ARRAY:
- break;
- }
-
- prop_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (prop_name_entry)));
-
- if (!xfconf_property_is_valid (prop_name, &error))
- {
- GObject *main_window = gtk_builder_get_object (builder, "main_dialog");
-
- xfce_dialog_show_error (GTK_WINDOW (main_window), error, _("This property name is not valid."));
-
- g_error_free (error);
- g_free (prop_name);
-
- return;
- }
-
- if (g_strcmp0 (prop_name, current_property) != 0)
- {
- xfconf_channel_reset_property (current_channel, current_property, FALSE);
- g_free (current_property);
- current_property = prop_name;
- }
- else
- g_free (prop_name);
-
- xfconf_channel_set_property (current_channel, current_property, &value);
- }
- else
- gtk_widget_hide (GTK_WIDGET (dialog));
-}
-
-/**
- * cb_property_revert_button_clicked
- *
- * Resets a property to it's system-default, it removes the property if it does not exist as a system default.
- */
-static void
-cb_property_revert_button_clicked (GtkButton *button, GtkBuilder *builder)
-{
- gboolean response;
-
- response = xfce_dialog_confirm (GTK_WINDOW (gtk_builder_get_object (builder, "main_window")),
- GTK_STOCK_YES,
- _("Reset"),
- _("Resetting a property will permanently remove those custom settings."),
- _("Are you sure you want to reset property \"%s\"?"),
- current_property);
-
- if (response)
- xfconf_channel_reset_property (current_channel, current_property, FALSE);
-}
-
-static void
-cb_settings_editor_dialog_response (GtkWidget *dialog, gint response, GtkBuilder *builder)
-{
- XfconfChannel *channel;
- gint width, height;
- GObject *hpaned;
-
- hpaned = gtk_builder_get_object (builder, "hpaned2");
-
- channel = xfconf_channel_get ("xfce4-settings-editor");
- gtk_window_get_size (GTK_WINDOW (dialog), &width, &height);
- xfconf_channel_set_int (channel, "/window-width", width);
- xfconf_channel_set_int (channel, "/window-height", height);
- xfconf_channel_set_int (channel, "/hpaned-position", gtk_paned_get_position (GTK_PANED (hpaned)));
-
- gtk_widget_destroy (dialog);
-
- if (current_channel)
- {
- g_object_unref (G_OBJECT(current_channel));
- current_channel = NULL;
- }
-}
-
-static void
-cb_channel_property_changed (XfconfChannel *channel, gchar *property, GValue *value, GtkBuilder *builder)
-{
- if (g_strcmp0 (property, current_property) == 0)
- {
- GObject *property_treeview;
- GtkTreeModel *tree_store = NULL;
-
- property_treeview = gtk_builder_get_object (builder, "property_treeview");
- tree_store = gtk_tree_view_get_model (GTK_TREE_VIEW (property_treeview));
-
- gtk_tree_store_clear (GTK_TREE_STORE(tree_store));
- load_properties (current_channel, GTK_TREE_STORE (tree_store), GTK_TREE_VIEW (property_treeview));
- }
-}
-
-/* Copied from xfconfd/xfconf-backend.c */
-static gboolean
-xfconf_property_is_valid(const gchar *property, GError **error)
-{
- const gchar *p = property;
-
- if(!p || *p != '/') {
- if(error) {
- g_set_error(error, XFCONF_ERROR, XFCONF_ERROR_INVALID_PROPERTY,
- _("Property names must start with a '/' character"));
- }
- return FALSE;
- }
-
- p++;
- if(!*p) {
- if(error) {
- g_set_error(error, XFCONF_ERROR, XFCONF_ERROR_INVALID_PROPERTY,
- _("The root element ('/') is not a valid property name"));
- }
- return FALSE;
- }
-
- while(*p) {
- if(!(*p >= 'A' && *p <= 'Z') && !(*p >= 'a' && *p <= 'z')
- && !(*p >= '0' && *p <= '9')
- && *p != '_' && *p != '-' && *p != '/'
- && !(*p == '<' || *p == '>'))
- {
- if(error) {
- g_set_error(error, XFCONF_ERROR,
- XFCONF_ERROR_INVALID_PROPERTY,
- _("Property names can only include the ASCII characters A-Z, a-z, 0-9, '_', '-', '<' and '>', as well as '/' as a separator"));
- }
- return FALSE;
- }
-
- if('/' == *p && '/' == *(p-1)) {
- if(error) {
- g_set_error(error, XFCONF_ERROR,
- XFCONF_ERROR_INVALID_PROPERTY,
- _("Property names cannot have two or more consecutive '/' characters"));
- }
- return FALSE;
- }
-
- p++;
- }
-
- if(*(p-1) == '/') {
- if(error) {
- g_set_error(error, XFCONF_ERROR, XFCONF_ERROR_INVALID_PROPERTY,
- _("Property names cannot end with a '/' character"));
- }
- return FALSE;
- }
-
- return TRUE;
-}
-
-static void
-channel_treeview_popup_menu (GtkWidget *widget, GdkEventButton *event, GtkBuilder *builder)
-{
- GtkWidget *menu;
- GtkWidget *menu_item;
- GtkWidget *image;
- int button, event_time;
-
- menu = gtk_menu_new ();
- g_signal_connect (menu, "deactivate", G_CALLBACK (gtk_menu_popdown), NULL);
-
- menu_item = gtk_image_menu_item_new_with_mnemonic (_("_Reset"));
- image = gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU);
- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
- g_signal_connect (G_OBJECT (menu_item), "activate", G_CALLBACK (cb_channel_popup_menu_remove_item_activate), builder);
- gtk_widget_set_sensitive (menu_item, !xfconf_channel_is_property_locked (current_channel, "/"));
- gtk_widget_show_all (menu_item);
-
- if (event)
- {
- button = event->button;
- event_time = event->time;
- }
- else
- {
- button = 0;
- event_time = gtk_get_current_event_time ();
- }
-
- gtk_menu_attach_to_widget (GTK_MENU (menu), widget, NULL);
- gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button, event_time);
-}
-
-static void
-cb_channel_popup_menu_remove_item_activate (GtkMenuItem *item, GtkBuilder *builder)
-{
- gboolean response;
- gchar *channel_name;
-
- g_object_get (G_OBJECT (current_channel), "channel-name", &channel_name, NULL);
-
- response = xfce_dialog_confirm (GTK_WINDOW (gtk_builder_get_object (builder, "main_window")),
- GTK_STOCK_REVERT_TO_SAVED,
- _("Reset"),
- _("Resetting a channel will permanently remove those custom settings."),
- _("Are you sure you want to reset channel \"%s\" and all its properties?"),
- channel_name);
-
- if (response)
- {
- GObject *channel_treeview;
- GObject *property_treeview;
- GtkTreeModel *list_store = NULL;
- GtkTreeModel *tree_store = NULL;
-
- channel_treeview = gtk_builder_get_object (builder, "channel_treeview");
- list_store = gtk_tree_view_get_model (GTK_TREE_VIEW (channel_treeview));
- xfconf_channel_reset_property (current_channel, "/", TRUE);
-
- gtk_list_store_clear (GTK_LIST_STORE(list_store));
- load_channels (GTK_LIST_STORE (list_store), GTK_TREE_VIEW (channel_treeview));
-
- property_treeview = gtk_builder_get_object (builder, "property_treeview");
- tree_store = gtk_tree_view_get_model (GTK_TREE_VIEW (property_treeview));
-
- gtk_tree_store_clear (GTK_TREE_STORE(tree_store));
- load_properties (current_channel, GTK_TREE_STORE (tree_store), GTK_TREE_VIEW (property_treeview));
- }
-
- g_free (channel_name);
-}
diff --git a/xfce4-settings-editor/main_window.h b/xfce4-settings-editor/main_window.h
deleted file mode 100644
index 223e2a7..0000000
--- a/xfce4-settings-editor/main_window.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2008 Stephan Arts <stephan at xfce.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-
-GtkDialog *
-xfce4_settings_editor_main_window_new(void);
diff --git a/xfce4-settings-editor/xfce-settings-editor-dialog.c b/xfce4-settings-editor/xfce-settings-editor-dialog.c
new file mode 100644
index 0000000..931cfa4
--- /dev/null
+++ b/xfce4-settings-editor/xfce-settings-editor-dialog.c
@@ -0,0 +1,1290 @@
+/*
+ * xfce4-settings-editor
+ *
+ * Copyright (c) 2008 Brian Tarricone <bjt23 at cornell.edu>
+ * Copyright (c) 2008 Stephan Arts <stephan at xfce.org>
+ * Copyright (c) 2009-2010 Jérôme Guelfucci <jeromeg at xfce.org>
+ * Copyright (c) 2012 Nick Schermer <nick at xfce.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License ONLY.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+#include <dbus/dbus-glib.h>
+
+#include <libxfce4util/libxfce4util.h>
+#include <libxfce4ui/libxfce4ui.h>
+#include <xfconf/xfconf.h>
+
+#include "xfce-settings-editor-dialog.h"
+
+
+
+
+struct _XfceSettingsEditorDialogClass
+{
+ XfceTitledDialogClass __parent__;
+};
+
+struct _XfceSettingsEditorDialog
+{
+ XfceTitledDialog __parent__;
+
+ XfconfChannel *channel;
+
+ GtkWidget *paned;
+
+ GtkListStore *channels_store;
+ GtkWidget *channels_treeview;
+
+ GtkTreeStore *props_store;
+ XfconfChannel *props_channel;
+ GtkWidget *props_treeview;
+
+ GtkWidget *button_new;
+ GtkWidget *button_edit;
+ GtkWidget *button_reset;
+};
+
+
+
+enum
+{
+ CHANNEL_COLUMN_NAME,
+ N_CHANNEL_COLUMNS
+};
+
+enum
+{
+ PROP_COLUMN_FULL,
+ PROP_COLUMN_NAME,
+ PROP_COLUMN_TYPE_NAME,
+ PROP_COLUMN_TYPE,
+ PROP_COLUMN_VALUE_TEXT,
+ PROP_COLUMN_LOCKED,
+ N_PROP_COLUMNS
+};
+
+
+
+static GType TYPE_PTR_ARRAY = 0;
+static GSList *monitor_dialogs = NULL;
+
+
+
+static void xfce_settings_editor_dialog_finalize (GObject *object);
+static void xfce_settings_editor_dialog_response (GtkDialog *widget,
+ gint response_id);
+static void xfce_settings_editor_dialog_load_channels (XfceSettingsEditorDialog *dialog);
+static void xfce_settings_editor_dialog_channel_changed (GtkTreeSelection *selection,
+ XfceSettingsEditorDialog *dialog);
+static gboolean xfce_settings_editor_dialog_channel_menu (XfceSettingsEditorDialog *dialog);
+static gboolean xfce_settings_editor_dialog_channel_button_press (GtkWidget *treeview,
+ GdkEventButton *event,
+ XfceSettingsEditorDialog *dialog);
+static void xfce_settings_editor_dialog_selection_changed (GtkTreeSelection *selection,
+ XfceSettingsEditorDialog *dialog);
+static gboolean xfce_settings_editor_dialog_query_tooltip (GtkWidget *treeview,
+ gint x,
+ gint y,
+ gboolean keyboard_mode,
+ GtkTooltip *tooltip,
+ XfceSettingsEditorDialog *dialog);
+static void xfce_settings_editor_dialog_row_activated (GtkTreeView *treeview,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ XfceSettingsEditorDialog *dialog);
+static gboolean xfce_settings_editor_dialog_key_press_event (GtkTreeView *treeview,
+ GdkEventKey *event,
+ XfceSettingsEditorDialog *dialog);
+static void xfce_settings_editor_dialog_property_new (XfceSettingsEditorDialog *dialog);
+static void xfce_settings_editor_dialog_property_edit (XfceSettingsEditorDialog *dialog);
+static void xfce_settings_editor_dialog_property_reset (XfceSettingsEditorDialog *dialog);
+static void xfce_settings_editor_dialog_ptr_array_transform (const GValue *src_value,
+ GValue *dest_value);
+
+
+
+G_DEFINE_TYPE (XfceSettingsEditorDialog, xfce_settings_editor_dialog, XFCE_TYPE_TITLED_DIALOG)
+
+
+
+static void
+xfce_settings_editor_dialog_class_init (XfceSettingsEditorDialogClass *klass)
+{
+ GObjectClass *gobject_class;
+ GtkDialogClass *gtkdialog_class;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->finalize = xfce_settings_editor_dialog_finalize;
+
+ gtkdialog_class = GTK_DIALOG_CLASS (klass);
+ gtkdialog_class->response = xfce_settings_editor_dialog_response;
+
+ TYPE_PTR_ARRAY = dbus_g_type_get_collection ("GPtrArray", G_TYPE_VALUE);
+ g_value_register_transform_func (TYPE_PTR_ARRAY, G_TYPE_STRING,
+ xfce_settings_editor_dialog_ptr_array_transform);
+}
+
+
+
+static void
+xfce_settings_editor_dialog_init (XfceSettingsEditorDialog *dialog)
+{
+ GtkWidget *paned;
+ GtkWidget *content_area;
+ GtkWidget *scroll;
+ GtkWidget *treeview;
+ GtkCellRenderer *render;
+ GtkTreeViewColumn *column;
+ GtkTreeSelection *selection;
+ GtkWidget *vbox;
+ GtkWidget *bbox;
+ GtkWidget *button;
+
+ dialog->channel = xfconf_channel_new ("xfce4-settings-editor");
+
+ dialog->channels_store = gtk_list_store_new (N_CHANNEL_COLUMNS,
+ G_TYPE_STRING);
+ xfce_settings_editor_dialog_load_channels (dialog);
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dialog->channels_store),
+ CHANNEL_COLUMN_NAME, GTK_SORT_ASCENDING);
+
+ dialog->props_store = gtk_tree_store_new (N_PROP_COLUMNS,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_BOOLEAN);
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dialog->props_store),
+ PROP_COLUMN_NAME, GTK_SORT_ASCENDING);
+
+ gtk_window_set_title (GTK_WINDOW (dialog), _("Settings Editor"));
+ xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dialog), _("Customize settings stored by Xfconf"));
+ gtk_window_set_icon_name (GTK_WINDOW (dialog), "preferences-system");
+ gtk_window_set_default_size (GTK_WINDOW (dialog),
+ xfconf_channel_get_int (dialog->channel, "/last/window-width", 640),
+ xfconf_channel_get_int (dialog->channel, "/last/window-height", 500));
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ GTK_STOCK_HELP, GTK_RESPONSE_HELP,
+ GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
+
+ dialog->paned = paned = gtk_hpaned_new ();
+ content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+ gtk_box_pack_start (GTK_BOX (content_area), paned, TRUE, TRUE, 0);
+ gtk_paned_set_position (GTK_PANED (paned),
+ xfconf_channel_get_int (dialog->channel, "/last/paned-position", 180));
+ gtk_container_set_border_width (GTK_CONTAINER (paned), 6);
+ gtk_widget_show (paned);
+
+ scroll = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_ETCHED_IN);
+ gtk_paned_add1 (GTK_PANED (paned), scroll);
+ gtk_widget_show (scroll);
+
+ treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (dialog->channels_store));
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), TRUE);
+ gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW (treeview), FALSE);
+ gtk_tree_view_set_fixed_height_mode (GTK_TREE_VIEW (treeview), TRUE);
+ gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), FALSE);
+ gtk_container_add (GTK_CONTAINER (scroll), treeview);
+ dialog->channels_treeview = treeview;
+ gtk_widget_show (treeview);
+
+ g_signal_connect_swapped (G_OBJECT (treeview), "popup-menu",
+ G_CALLBACK (xfce_settings_editor_dialog_channel_menu), dialog);
+ g_signal_connect (G_OBJECT (treeview), "button-press-event",
+ G_CALLBACK (xfce_settings_editor_dialog_channel_button_press), dialog);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
+ g_signal_connect (G_OBJECT (selection), "changed",
+ G_CALLBACK (xfce_settings_editor_dialog_channel_changed), dialog);
+
+ render = gtk_cell_renderer_text_new ();
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), 0,
+ _("Channel"), render,
+ "text", CHANNEL_COLUMN_NAME, NULL);
+
+ vbox = gtk_vbox_new (FALSE, 6);
+ gtk_paned_add2 (GTK_PANED (paned), vbox);
+ gtk_widget_show (vbox);
+
+ scroll = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_ETCHED_IN);
+ gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
+ gtk_widget_show (scroll);
+
+ treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (dialog->props_store));
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), TRUE);
+ gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW (treeview), FALSE);
+ gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), FALSE);
+ gtk_container_add (GTK_CONTAINER (scroll), treeview);
+ dialog->props_treeview = treeview;
+ gtk_widget_show (treeview);
+
+ gtk_widget_set_has_tooltip (treeview, TRUE);
+ g_signal_connect (G_OBJECT (treeview), "query-tooltip",
+ G_CALLBACK (xfce_settings_editor_dialog_query_tooltip), dialog);
+ g_signal_connect (G_OBJECT (treeview), "row-activated",
+ G_CALLBACK (xfce_settings_editor_dialog_row_activated), dialog);
+ g_signal_connect (G_OBJECT (treeview), "key-press-event",
+ G_CALLBACK (xfce_settings_editor_dialog_key_press_event), dialog);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+ g_signal_connect (G_OBJECT (selection), "changed",
+ G_CALLBACK (xfce_settings_editor_dialog_selection_changed), dialog);
+
+ render = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes (_("Property"), render,
+ "text", PROP_COLUMN_NAME,
+ NULL);
+ gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+
+ render = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes (_("Type"), render,
+ "text", PROP_COLUMN_TYPE_NAME,
+ NULL);
+ gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+
+ render = gtk_cell_renderer_toggle_new ();
+ column = gtk_tree_view_column_new_with_attributes (_("Locked"), render,
+ "active", PROP_COLUMN_LOCKED,
+ NULL);
+ gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+
+ render = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes (_("Value"), render,
+ "text", PROP_COLUMN_VALUE_TEXT,
+ NULL);
+ gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+
+ bbox = gtk_hbutton_box_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, TRUE, 0);
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_START);
+ gtk_widget_show (bbox);
+
+ button = gtk_button_new_from_stock (GTK_STOCK_NEW);
+ gtk_container_add (GTK_CONTAINER (bbox), button);
+ gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
+ gtk_widget_set_tooltip_text (button, _("New property"));
+ gtk_widget_set_sensitive (button, FALSE);
+ gtk_widget_set_can_focus (button, FALSE);
+ dialog->button_new = button;
+ gtk_widget_show (button);
+ g_signal_connect_swapped (G_OBJECT (button), "clicked",
+ G_CALLBACK (xfce_settings_editor_dialog_property_new), dialog);
+
+ button = gtk_button_new_from_stock (GTK_STOCK_EDIT);
+ gtk_container_add (GTK_CONTAINER (bbox), button);
+ gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
+ gtk_widget_set_tooltip_text (button, _("Edit selected property"));
+ gtk_widget_set_sensitive (button, FALSE);
+ gtk_widget_set_can_focus (button, FALSE);
+ dialog->button_edit = button;
+ gtk_widget_show (button);
+ g_signal_connect_swapped (G_OBJECT (button), "clicked",
+ G_CALLBACK (xfce_settings_editor_dialog_property_edit), dialog);
+
+ button = xfce_gtk_button_new_mixed (GTK_STOCK_REVERT_TO_SAVED, _("_Reset"));
+ gtk_container_add (GTK_CONTAINER (bbox), button);
+ gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
+ gtk_widget_set_tooltip_text (button, _("Reset selected property"));
+ gtk_widget_set_sensitive (button, FALSE);
+ gtk_widget_set_can_focus (button, FALSE);
+ dialog->button_reset = button;
+ gtk_widget_show (button);
+ g_signal_connect_swapped (G_OBJECT (button), "clicked",
+ G_CALLBACK (xfce_settings_editor_dialog_property_reset), dialog);
+}
+
+
+
+static void
+xfce_settings_editor_dialog_finalize (GObject *object)
+{
+ GSList *li, *lnext;
+
+ XfceSettingsEditorDialog *dialog = XFCE_SETTINGS_EDITOR_DIALOG (object);
+
+ for (li = monitor_dialogs; li != NULL; li = lnext)
+ {
+ lnext = li->next;
+ gtk_dialog_response (GTK_DIALOG (li->data), GTK_RESPONSE_CLOSE);
+ }
+
+ g_object_unref (G_OBJECT (dialog->channels_store));
+
+ g_object_unref (G_OBJECT (dialog->props_store));
+ if (dialog->props_channel != NULL)
+ g_object_unref (G_OBJECT (dialog->props_channel));
+
+ g_object_unref (G_OBJECT (dialog->channel));
+
+ G_OBJECT_CLASS (xfce_settings_editor_dialog_parent_class)->finalize (object);
+}
+
+
+
+static void
+xfce_settings_editor_dialog_response (GtkDialog *widget,
+ gint response_id)
+{
+ XfceSettingsEditorDialog *dialog = XFCE_SETTINGS_EDITOR_DIALOG (widget);
+ gint width, height;
+ GdkWindowState state;
+
+ if (response_id == GTK_RESPONSE_HELP)
+ {
+ xfce_dialog_show_help (GTK_WINDOW (widget),
+ "xfce4-settings",
+ "settings-editor", NULL);
+ }
+ else
+ {
+ /* don't save the state for full-screen windows */
+ state = gdk_window_get_state (GTK_WIDGET (widget)->window);
+ if ((state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)) == 0)
+ {
+ /* save window size */
+ gtk_window_get_size (GTK_WINDOW (widget), &width, &height);
+ xfconf_channel_set_int (dialog->channel, "/last/window-width", width),
+ xfconf_channel_set_int (dialog->channel, "/last/window-height", height);
+
+ xfconf_channel_set_int (dialog->channel, "/last/paned-position",
+ gtk_paned_get_position (GTK_PANED (dialog->paned)));
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (widget));
+ gtk_main_quit ();
+ }
+}
+
+
+
+static void
+xfce_settings_editor_dialog_load_channels (XfceSettingsEditorDialog *dialog)
+{
+ gchar **channel_names;
+ guint i;
+
+ g_return_if_fail (GTK_IS_LIST_STORE (dialog->channels_store));
+
+ gtk_list_store_clear (dialog->channels_store);
+
+ channel_names = xfconf_list_channels ();
+ if (G_LIKELY (channel_names != NULL))
+ {
+ for (i = 0; channel_names[i] != NULL; i++)
+ {
+ gtk_list_store_insert_with_values (dialog->channels_store, NULL, i,
+ CHANNEL_COLUMN_NAME, channel_names[i],
+ -1);
+ }
+ g_strfreev (channel_names);
+ }
+}
+
+
+
+static const gchar *
+xfce_settings_editor_dialog_type_name (const GValue *value)
+{
+ if (G_UNLIKELY (value == NULL))
+ return _("Empty");
+
+ if (G_UNLIKELY (G_VALUE_TYPE (value) == TYPE_PTR_ARRAY))
+ return _("Array");
+
+ switch (G_VALUE_TYPE (value))
+ {
+ case G_TYPE_STRING:
+ return _("String");
+ case G_TYPE_INT:
+ case G_TYPE_UINT:
+ case G_TYPE_INT64:
+ case G_TYPE_UINT64:
+ return _("Integer");
+ case G_TYPE_BOOLEAN:
+ return _("Boolean");
+ case G_TYPE_DOUBLE:
+ return _("Double");
+ default:
+ return G_VALUE_TYPE_NAME (value);
+ }
+}
+
+
+
+static void
+xfce_settings_editor_dialog_property_load (const gchar *property,
+ const GValue *value,
+ XfceSettingsEditorDialog *dialog,
+ GtkTreePath **expand_path)
+{
+ gchar **paths;
+ guint i;
+ GtkTreeIter child_iter;
+ GtkTreeIter parent_iter;
+ GValue parent_val = { 0,};
+ gboolean found_parent;
+ GValue string_value = { 0, };
+ GtkTreeModel *model = GTK_TREE_MODEL (dialog->props_store);
+
+ g_return_if_fail (GTK_IS_TREE_STORE (dialog->props_store));
+ g_return_if_fail (G_IS_VALUE (value));
+ g_return_if_fail (property != NULL && *property == '/');
+
+ paths = g_strsplit (property, "/", -1);
+ if (paths == NULL)
+ return;
+
+ for (i = 1; paths[i] != NULL; i++)
+ {
+ found_parent = FALSE;
+
+ if (gtk_tree_model_iter_children (model, &child_iter, i == 1 ? NULL : &parent_iter))
+ {
+ for (;;)
+ {
+ /* look if one of the paths already exists */
+ gtk_tree_model_get_value (model, &child_iter, PROP_COLUMN_NAME, &parent_val);
+ found_parent = g_strcmp0 (g_value_get_string (&parent_val), paths[i]) == 0;
+ g_value_unset (&parent_val);
+
+ /* maybe we still need to set the value */
+ if (found_parent)
+ {
+ /* set this property in case it is the last value */
+ if (paths[i + 1] == NULL)
+ goto set_child_values;
+ break;
+ }
+
+ /* append at the end of this parent */
+ if (!gtk_tree_model_iter_next (model, &child_iter))
+ break;
+ }
+ }
+
+ if (!found_parent)
+ {
+ gtk_tree_store_append (GTK_TREE_STORE (model), &child_iter,
+ i == 1 ? NULL : &parent_iter);
+
+ if (G_LIKELY (paths[i + 1] != NULL))
+ {
+ gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter,
+ PROP_COLUMN_NAME, paths[i],
+ PROP_COLUMN_TYPE_NAME, _("Empty"), -1);
+ }
+ else
+ {
+ set_child_values:
+
+ g_value_init (&string_value, G_TYPE_STRING);
+ if (!g_value_transform (value, &string_value))
+ g_value_set_string (&string_value, "Unknown");
+
+ gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter,
+ PROP_COLUMN_NAME, paths[i],
+ PROP_COLUMN_FULL, property,
+ PROP_COLUMN_TYPE, G_VALUE_TYPE_NAME (value),
+ PROP_COLUMN_TYPE_NAME, xfce_settings_editor_dialog_type_name (value),
+ PROP_COLUMN_VALUE_TEXT, g_value_get_string (&string_value),
+ PROP_COLUMN_LOCKED, xfconf_channel_is_property_locked (dialog->props_channel, property),
+ -1);
+
+ if (expand_path != NULL)
+ *expand_path = gtk_tree_model_get_path (model, &child_iter);
+
+ g_value_unset (&string_value);
+ }
+ }
+
+ parent_iter = child_iter;
+ }
+
+ g_strfreev (paths);
+}
+
+
+
+typedef struct
+{
+ const gchar *prop;
+ GtkTreePath *path;
+}
+DeleteContext;
+
+
+
+static gboolean
+xfce_settings_editor_dialog_property_find (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ GValue prop = { 0, };
+ DeleteContext *context = data;
+ gboolean found = FALSE;
+
+ gtk_tree_model_get_value (model, iter, PROP_COLUMN_FULL, &prop);
+
+ if (g_strcmp0 (g_value_get_string (&prop), context->prop) == 0)
+ {
+ found = TRUE;
+ context->path = gtk_tree_path_copy (path);
+ }
+
+ g_value_unset (&prop);
+
+ return found;
+}
+
+
+
+static void
+xfce_settings_editor_dialog_property_changed (XfconfChannel *channel,
+ const gchar *property,
+ const GValue *value,
+ XfceSettingsEditorDialog *dialog)
+{
+ GtkTreePath *path = NULL;
+ DeleteContext *context;
+ GtkTreeIter child_iter;
+ GtkTreeModel *model;
+ GValue parent_val = { 0, };
+ GtkTreeIter parent_iter;
+ gboolean empty_prop;
+ gboolean has_parent;
+
+ g_return_if_fail (GTK_IS_TREE_STORE (dialog->props_store));
+ g_return_if_fail (XFCONF_IS_CHANNEL (channel));
+ g_return_if_fail (dialog->props_channel == channel);
+
+ if (value != NULL && G_IS_VALUE (value))
+ {
+ xfce_settings_editor_dialog_property_load (property, value, dialog, &path);
+
+ if (path != NULL)
+ {
+ /* show the new value */
+ gtk_tree_view_expand_to_path (GTK_TREE_VIEW (dialog->props_treeview), path);
+ gtk_tree_path_free (path);
+ }
+ }
+ else
+ {
+ /* we only get here when the property must be deleted, this means there
+ * is also no reset value in one of the xdg channels */
+ context = g_slice_new0 (DeleteContext);
+ context->prop = property;
+
+ model = GTK_TREE_MODEL (dialog->props_store);
+ gtk_tree_model_foreach (model, xfce_settings_editor_dialog_property_find, context);
+
+ if (context->path != NULL)
+ {
+ if (gtk_tree_model_get_iter (model, &child_iter, context->path))
+ {
+ /* delete the value */
+ has_parent = gtk_tree_model_iter_parent (model, &parent_iter, &child_iter);
+ gtk_tree_store_remove (GTK_TREE_STORE (model), &child_iter);
+
+ /* remove the parent nodes if they are empty */
+ while (has_parent)
+ {
+ /* if the parent still has children, stop cleaning */
+ if (gtk_tree_model_iter_has_child (model, &parent_iter))
+ break;
+
+ /* maybe the parent has a value */
+ gtk_tree_model_get_value (model, &parent_iter, PROP_COLUMN_FULL, &parent_val);
+ empty_prop = g_value_get_string (&parent_val) == NULL;
+ g_value_unset (&parent_val);
+
+ /* nope it points to a real xfconf property */
+ if (!empty_prop)
+ break;
+
+ /* get the parent and remove the empty row */
+ child_iter = parent_iter;
+ has_parent = gtk_tree_model_iter_parent (model, &parent_iter, &child_iter);
+ gtk_tree_store_remove (GTK_TREE_STORE (model), &child_iter);
+ }
+ }
+
+ gtk_tree_path_free (context->path);
+ }
+
+ g_slice_free (DeleteContext, context);
+ }
+}
+
+
+
+static void
+xfce_settings_editor_dialog_property_load_hash (gpointer key,
+ gpointer value,
+ gpointer data)
+{
+ xfce_settings_editor_dialog_property_load (key, value, data, NULL);
+}
+
+
+
+static void
+xfce_settings_editor_dialog_properties_load (XfceSettingsEditorDialog *dialog,
+ XfconfChannel *channel)
+{
+ GHashTable *props;
+
+ g_return_if_fail (GTK_IS_TREE_STORE (dialog->props_store));
+ g_return_if_fail (XFCONF_IS_CHANNEL (channel));
+
+ if (dialog->props_channel != NULL)
+ {
+ g_signal_handlers_block_by_func (G_OBJECT (dialog->props_channel),
+ G_CALLBACK (xfce_settings_editor_dialog_property_changed), dialog);
+ g_object_unref (G_OBJECT (dialog->props_channel));
+ dialog->props_channel = NULL;
+ }
+
+ gtk_tree_store_clear (dialog->props_store);
+
+ dialog->props_channel = g_object_ref (G_OBJECT (channel));
+
+ props = xfconf_channel_get_properties (channel, NULL);
+ if (G_LIKELY (props != NULL))
+ {
+ g_hash_table_foreach (props, xfce_settings_editor_dialog_property_load_hash, dialog);
+ g_hash_table_destroy (props);
+ }
+
+ gtk_tree_view_expand_all (GTK_TREE_VIEW (dialog->props_treeview));
+
+ g_signal_connect (G_OBJECT (dialog->props_channel), "property-changed",
+ G_CALLBACK (xfce_settings_editor_dialog_property_changed), dialog);
+}
+
+
+
+static void
+xfce_settings_editor_dialog_channel_changed (GtkTreeSelection *selection,
+ XfceSettingsEditorDialog *dialog)
+{
+ GtkTreeIter iter;
+ GValue value = { 0, };
+ XfconfChannel *channel;
+ gboolean locked;
+
+ if (gtk_tree_selection_get_selected (selection, NULL, &iter))
+ {
+ gtk_tree_model_get_value (GTK_TREE_MODEL (dialog->channels_store), &iter,
+ CHANNEL_COLUMN_NAME, &value);
+
+ channel = xfconf_channel_new (g_value_get_string (&value));
+
+ locked = xfconf_channel_is_property_locked (channel, "/");
+ gtk_widget_set_sensitive (dialog->button_new, !locked);
+
+ xfce_settings_editor_dialog_properties_load (dialog, channel);
+
+ g_object_unref (G_OBJECT (channel));
+
+ g_value_unset (&value);
+ }
+ else
+ {
+ gtk_widget_set_sensitive (dialog->button_new, FALSE);
+ gtk_tree_store_clear (dialog->props_store);
+ }
+}
+
+
+
+static void
+xfce_settings_editor_dialog_channel_reset (XfceSettingsEditorDialog *dialog)
+{
+ gchar *channel_name;
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ gchar **channels;
+ gboolean found;
+ guint i;
+
+ if (dialog->props_channel == NULL)
+ return;
+
+ g_object_get (dialog->props_channel, "channel-name", &channel_name, NULL);
+
+ if (xfce_dialog_confirm (GTK_WINDOW (dialog),
+ GTK_STOCK_REVERT_TO_SAVED,
+ _("_Reset Channel"),
+ _("Resetting a channel will permanently remove those custom settings."),
+ _("Are you sure you want to reset channel \"%s\" and all its properties?"),
+ channel_name))
+ {
+ /* reset all channel properties */
+ xfconf_channel_reset_property (dialog->props_channel, "/", TRUE);
+
+ /* check if the channel still exists */
+ channels = xfconf_list_channels ();
+ if (G_LIKELY (channels != NULL))
+ {
+ for (i = 0, found = FALSE; !found && channels[i] != NULL; i++)
+ found = g_strcmp0 (channels[i], channel_name) == 0;
+ g_strfreev (channels);
+ }
+
+ if (!found)
+ {
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->channels_treeview));
+ if (gtk_tree_selection_get_selected (selection, NULL, &iter))
+ {
+ if (gtk_list_store_remove (dialog->channels_store, &iter))
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (dialog->channels_store), &iter);
+ else
+ path = gtk_tree_path_new_first ();
+
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (dialog->channels_treeview), path, NULL, FALSE);
+ gtk_tree_path_free (path);
+ }
+ }
+ }
+
+ g_free (channel_name);
+}
+
+
+
+static void
+xfce_settings_editor_dialog_channel_monitor_changed (XfconfChannel *channel,
+ const gchar *property,
+ const GValue *value,
+ GtkWidget *window)
+{
+ GtkTextBuffer *buffer;
+ GTimeVal timeval;
+ gchar *str;
+ GValue str_value = { 0, };
+ GtkTextIter iter;
+
+ buffer = g_object_get_data (G_OBJECT (window), "buffer");
+ g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
+
+ g_get_current_time (&timeval);
+
+ if (value != NULL && G_IS_VALUE (value))
+ {
+ g_value_init (&str_value, G_TYPE_STRING);
+ if (g_value_transform (value, &str_value))
+ {
+ str = g_strdup_printf ("%ld: %s (%s: %s)\n",
+ timeval.tv_sec, property,
+ G_VALUE_TYPE_NAME (value),
+ g_value_get_string (&str_value));
+ }
+ else
+ {
+ str = g_strdup_printf ("%ld: %s (%s)\n",
+ timeval.tv_sec, property,
+ G_VALUE_TYPE_NAME (value));
+ }
+ g_value_unset (&str_value);
+ }
+ else
+ {
+ /* I18N: if a property is removed from the channel */
+ str = g_strdup_printf ("%ld: %s (%s)\n", timeval.tv_sec,
+ property, _("reset"));
+ }
+
+ /* prepend to the buffer */
+ gtk_text_buffer_get_start_iter (buffer, &iter);
+ gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, str, -1, "monospace", NULL);
+ g_free (str);
+}
+
+
+
+static void
+xfce_settings_editor_dialog_channel_monitor_response (GtkWidget *window,
+ gint response_id,
+ XfconfChannel *channel)
+{
+ g_signal_handlers_disconnect_by_func (G_OBJECT (channel),
+ G_CALLBACK (xfce_settings_editor_dialog_channel_monitor_changed), window);
+
+ g_object_unref (G_OBJECT (channel));
+
+ monitor_dialogs = g_slist_remove (monitor_dialogs, window);
+
+ gtk_widget_destroy (window);
+}
+
+
+
+static void
+xfce_settings_editor_dialog_channel_monitor (XfceSettingsEditorDialog *dialog)
+{
+ GtkWidget *window;
+ gchar *channel_name;
+ gchar *title;
+ GtkWidget *scroll;
+ GtkWidget *textview;
+ GtkWidget *content_area;
+ GtkTextBuffer *buffer;
+ GTimeVal timeval;
+ gchar *str;
+ GtkTextIter iter;
+
+ if (dialog->props_channel == NULL)
+ return;
+
+ g_object_get (dialog->props_channel, "channel-name", &channel_name, NULL);
+ title = g_strdup_printf (_("Monitor %s"), channel_name);
+
+ window = xfce_titled_dialog_new ();
+ gtk_window_set_title (GTK_WINDOW (window), title);
+ gtk_window_set_icon_name (GTK_WINDOW (window), "utilities-system-monitor");
+ gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
+ xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (window),
+ _("Watch an Xfconf Channel for property changes"));
+ gtk_dialog_add_button (GTK_DIALOG (window), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
+ g_signal_connect (G_OBJECT (window), "response",
+ G_CALLBACK (xfce_settings_editor_dialog_channel_monitor_response),
+ g_object_ref (G_OBJECT (dialog->props_channel)));
+ g_free (title);
+
+ monitor_dialogs = g_slist_prepend (monitor_dialogs, window);
+
+ scroll = gtk_scrolled_window_new (NULL, NULL);
+ content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
+ gtk_box_pack_start (GTK_BOX (content_area), scroll, TRUE, TRUE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (scroll), 6);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_ETCHED_IN);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_widget_show (scroll);
+
+ buffer = gtk_text_buffer_new (NULL);
+ g_object_set_data_full (G_OBJECT (window), "buffer", buffer, g_object_unref);
+ gtk_text_buffer_create_tag (buffer, "monospace", "font", "monospace", NULL);
+ g_signal_connect (G_OBJECT (dialog->props_channel), "property-changed",
+ G_CALLBACK (xfce_settings_editor_dialog_channel_monitor_changed), window);
+
+ g_get_current_time (&timeval);
+ gtk_text_buffer_get_start_iter (buffer, &iter);
+ str = g_strdup_printf ("%ld: ", timeval.tv_sec);
+ gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, str, -1, "monospace", NULL);
+ g_free (str);
+
+ str = g_strdup_printf (_("start monitoring channel \"%s\""), channel_name);
+ gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, str, -1, "monospace", NULL);
+ g_free (str);
+
+ textview = gtk_text_view_new_with_buffer (buffer);
+ gtk_container_add (GTK_CONTAINER (scroll), textview);
+ gtk_text_view_set_editable (GTK_TEXT_VIEW (textview), FALSE);
+ gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (textview), FALSE);
+ gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview), GTK_WRAP_NONE);
+ gtk_widget_show (textview);
+
+ gtk_window_present_with_time (GTK_WINDOW (window), gtk_get_current_event_time ());
+
+ g_free (channel_name);
+}
+
+
+
+static gboolean
+xfce_settings_editor_dialog_channel_menu (XfceSettingsEditorDialog *dialog)
+{
+ GtkWidget *menu;
+ GtkWidget *mi;
+ gchar *channel_name;
+ GtkWidget *image;
+
+ if (dialog->props_channel == NULL)
+ return FALSE;
+
+ menu = gtk_menu_new ();
+ g_signal_connect (G_OBJECT (menu), "selection-done",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+
+ g_object_get (dialog->props_channel, "channel-name", &channel_name, NULL);
+ mi = gtk_menu_item_new_with_label (channel_name);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+ gtk_widget_set_sensitive (mi, FALSE);
+ gtk_widget_show (mi);
+ g_free (channel_name);
+
+ mi = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+ gtk_widget_show (mi);
+
+ mi = gtk_image_menu_item_new_with_mnemonic (_("_Reset"));
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+ g_signal_connect_swapped (G_OBJECT (mi), "activate",
+ G_CALLBACK (xfce_settings_editor_dialog_channel_reset), dialog);
+ gtk_widget_show (mi);
+
+ image = gtk_image_new_from_stock (GTK_STOCK_REVERT_TO_SAVED, GTK_ICON_SIZE_MENU);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), image);
+ gtk_widget_show (image);
+
+ mi = gtk_image_menu_item_new_with_mnemonic (_("_Monitor"));
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+ gtk_widget_show (mi);
+
+ image = gtk_image_new_from_icon_name ("utilities-system-monitor", GTK_ICON_SIZE_MENU);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), image);
+ g_signal_connect_swapped (G_OBJECT (mi), "activate",
+ G_CALLBACK (xfce_settings_editor_dialog_channel_monitor), dialog);
+ gtk_widget_show (image);
+
+ mi = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+ gtk_widget_show (mi);
+
+ mi = gtk_image_menu_item_new_from_stock (GTK_STOCK_REFRESH, NULL);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+ g_signal_connect_swapped (G_OBJECT (mi), "activate",
+ G_CALLBACK (xfce_settings_editor_dialog_load_channels), dialog);
+ gtk_widget_show (mi);
+
+ gtk_menu_popup (GTK_MENU (menu),
+ NULL, NULL, NULL, NULL, 3,
+ gtk_get_current_event_time ());
+
+ return TRUE;
+}
+
+
+
+static gboolean
+xfce_settings_editor_dialog_channel_button_press (GtkWidget *treeview,
+ GdkEventButton *event,
+ XfceSettingsEditorDialog *dialog)
+{
+ guint modifiers;
+ GtkTreePath *path;
+
+ if (event->type == GDK_BUTTON_PRESS)
+ {
+ modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
+ if (event->button == 3 || (event->button == 1 && modifiers == GDK_CONTROL_MASK))
+ {
+ if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (treeview), event->x, event->y,
+ &path, NULL, NULL, NULL))
+ {
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (treeview), path, NULL, FALSE);
+ gtk_tree_path_free (path);
+
+ return xfce_settings_editor_dialog_channel_menu (dialog);;
+ }
+ }
+ }
+
+ return FALSE;
+}
+
+
+
+static gchar *
+xfce_settings_editor_dialog_selected (XfceSettingsEditorDialog *dialog,
+ gboolean *is_real_prop)
+{
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+ gchar *property = NULL;
+ GtkTreeModel *model;
+ GtkTreeIter parent_iter;
+ GValue name_val = { 0, };
+ GString *string_prop;
+ gboolean property_real = TRUE;
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->props_treeview));
+ if (gtk_tree_selection_get_selected (selection, NULL, &iter))
+ {
+ model = GTK_TREE_MODEL (dialog->props_store);
+ gtk_tree_model_get (model, &iter, PROP_COLUMN_FULL, &property, -1);
+
+ /* if this is not a real property, look it up by the tree structure */
+ if (property == NULL)
+ {
+ string_prop = g_string_new (NULL);
+ for (;;)
+ {
+ gtk_tree_model_get_value (model, &iter, PROP_COLUMN_NAME, &name_val);
+ g_string_prepend (string_prop, g_value_get_string (&name_val));
+ g_string_prepend_c (string_prop, '/');
+ g_value_unset (&name_val);
+
+ if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
+ break;
+
+ iter = parent_iter;
+ }
+ property = g_string_free (string_prop, FALSE);
+ property_real = FALSE;
+ }
+ }
+
+ if (is_real_prop != NULL)
+ *is_real_prop = property_real;
+
+ return property;
+}
+
+
+
+static void
+xfce_settings_editor_dialog_selection_changed (GtkTreeSelection *selection,
+ XfceSettingsEditorDialog *dialog)
+{
+ gchar *property;
+ gboolean can_edit = FALSE;
+ gboolean can_reset = FALSE;
+ gboolean is_real_prop = TRUE;
+
+ g_return_if_fail (dialog->props_channel == NULL
+ || XFCONF_IS_CHANNEL (dialog->props_channel));
+
+ /* do nothing if the entre channel is locked */
+ if (dialog->props_channel != NULL
+ && gtk_widget_get_sensitive (dialog->button_new))
+ {
+ property = xfce_settings_editor_dialog_selected (dialog, &is_real_prop);
+
+ can_edit = !xfconf_channel_is_property_locked (dialog->props_channel, property);
+ can_reset = can_edit && is_real_prop;
+
+ g_free (property);
+ }
+
+ gtk_widget_set_sensitive (dialog->button_edit, can_edit);
+ gtk_widget_set_sensitive (dialog->button_reset, can_reset);
+}
+
+
+
+static gboolean
+xfce_settings_editor_dialog_query_tooltip (GtkWidget *treeview,
+ gint x,
+ gint y,
+ gboolean keyboard_mode,
+ GtkTooltip *tooltip,
+ XfceSettingsEditorDialog *dialog)
+{
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ GValue value = { 0, };
+ GtkTreeModel *model;
+ gboolean show = FALSE;
+ const gchar *text;
+ GtkTreeViewColumn *column;
+ GList *columns;
+ gint idx;
+
+ gtk_tree_view_convert_widget_to_bin_window_coords (GTK_TREE_VIEW (treeview), x, y, &x, &y);
+
+ if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (treeview), x, y, &path,
+ &column, NULL, NULL))
+ {
+ columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (treeview));
+ idx = g_list_index (columns, column);
+ g_list_free (columns);
+
+ model = GTK_TREE_MODEL (dialog->props_store);
+ if (idx < 2 && gtk_tree_model_get_iter (model, &iter, path))
+ {
+ gtk_tree_model_get_value (model, &iter,
+ idx == 0 ? PROP_COLUMN_FULL : PROP_COLUMN_TYPE, &value);
+
+ text = g_value_get_string (&value);
+ if (text != NULL)
+ {
+ gtk_tooltip_set_text (tooltip, text);
+ show = TRUE;
+ }
+ g_value_unset (&value);
+ }
+
+ gtk_tree_path_free (path);
+ }
+
+ return show;
+}
+
+
+
+static void
+xfce_settings_editor_dialog_row_activated (GtkTreeView *treeview,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ XfceSettingsEditorDialog *dialog)
+{
+ GtkTreeModel *model = GTK_TREE_MODEL (dialog->props_store);
+ GtkTreeIter iter;
+
+ if (gtk_tree_model_get_iter (model, &iter, path))
+ {
+ if (gtk_tree_model_iter_has_child (model, &iter))
+ {
+ if (gtk_tree_view_row_expanded (treeview, path))
+ gtk_tree_view_collapse_row (treeview, path);
+ else
+ gtk_tree_view_expand_row (treeview, path, FALSE);
+ }
+ else if (gtk_widget_is_sensitive (dialog->button_edit))
+ {
+ xfce_settings_editor_dialog_property_edit (dialog);
+ }
+ }
+}
+
+
+
+static gboolean
+xfce_settings_editor_dialog_key_press_event (GtkTreeView *treeview,
+ GdkEventKey *event,
+ XfceSettingsEditorDialog *dialog)
+{
+ if (event->keyval == GDK_Delete
+ && gtk_widget_get_sensitive (dialog->button_reset))
+ {
+ xfce_settings_editor_dialog_property_reset (dialog);
+ return TRUE;
+ }
+ else if (event->keyval == GDK_Insert
+ && gtk_widget_get_sensitive (dialog->button_new))
+ {
+ xfce_settings_editor_dialog_property_new (dialog);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
+
+static void
+xfce_settings_editor_dialog_property_new (XfceSettingsEditorDialog *dialog)
+{
+
+}
+
+
+
+static void
+xfce_settings_editor_dialog_property_edit (XfceSettingsEditorDialog *dialog)
+{
+
+}
+
+
+
+static void
+xfce_settings_editor_dialog_property_reset (XfceSettingsEditorDialog *dialog)
+{
+ gchar *property;
+
+ property = xfce_settings_editor_dialog_selected (dialog, NULL);
+ if (property != NULL
+ && xfce_dialog_confirm (GTK_WINDOW (dialog),
+ GTK_STOCK_REVERT_TO_SAVED, _("_Reset"),
+ _("Resetting a property will permanently remove those custom settings."),
+ _("Are you sure you want to reset property \"%s\"?"), property))
+ {
+ xfconf_channel_reset_property (dialog->props_channel, property, FALSE);
+ }
+
+ g_free (property);
+}
+
+
+
+static void
+xfce_settings_editor_dialog_ptr_array_transform (const GValue *src_value,
+ GValue *dest_value)
+{
+ GString *str;
+ GPtrArray *array = g_value_get_boxed (src_value);
+ guint i;
+ const GValue *val;
+ GValue str_val = { 0, };
+
+ str = g_string_new ("[ ");
+
+ for (i = 0; i < array->len; i++)
+ {
+ val = g_ptr_array_index (array, i);
+
+ if (val == NULL)
+ {
+ g_string_append (str, "Null");
+ }
+ else if (G_VALUE_HOLDS_STRING (val))
+ {
+ g_string_append_printf (str, "\"%s\"",
+ g_value_get_string (val));
+ }
+ else
+ {
+ g_value_init (&str_val, G_TYPE_STRING);
+ if (g_value_transform (val, &str_val))
+ g_string_append (str, g_value_get_string (&str_val));
+ else
+ g_string_append (str, "?");
+ g_value_unset (&str_val);
+ }
+
+ if (i < array->len - 1)
+ g_string_append (str, ", ");
+ }
+
+ g_string_append (str, " ]");
+
+ g_value_take_string (dest_value, g_string_free (str, FALSE));
+}
+
+
+
+GtkWidget *
+xfce_settings_editor_dialog_new (void)
+{
+ return g_object_new (XFCE_TYPE_SETTINGS_EDITOR_DIALOG, NULL);
+}
diff --git a/xfce4-settings-editor/xfce-settings-editor-dialog.h b/xfce4-settings-editor/xfce-settings-editor-dialog.h
new file mode 100644
index 0000000..6acd90a
--- /dev/null
+++ b/xfce4-settings-editor/xfce-settings-editor-dialog.h
@@ -0,0 +1,46 @@
+/*
+ * xfce4-settings-editor
+ *
+ * Copyright (c) 2008 Brian Tarricone <bjt23 at cornell.edu>
+ * Copyright (c) 2008 Stephan Arts <stephan at xfce.org>
+ * Copyright (c) 2009-2010 Jérôme Guelfucci <jeromeg at xfce.org>
+ * Copyright (c) 2012 Nick Schermer <nick at xfce.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License ONLY.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __XFCE_SETTINGS_EDITOR_DIALOG_H__
+#define __XFCE_SETTINGS_EDITOR_DIALOG_H__
+
+#include <gtk/gtk.h>
+
+#define XFCE_TYPE_SETTINGS_EDITOR_DIALOG (xfce_settings_editor_dialog_get_type ())
+#define XFCE_SETTINGS_EDITOR_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_SETTINGS_EDITOR_DIALOG, XfceSettingsEditorDialog))
+#define XFCE_SETTINGS_EDITOR_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_SETTINGS_EDITOR_DIALOG, XfceSettingsEditorDialogClass))
+#define XFCE_IS_SETTINGS_EDITOR_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_SETTINGS_EDITOR_DIALOG))
+#define XFCE_IS_SETTINGS_EDITOR_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_SETTINGS_EDITOR_DIALOG))
+#define XFCE_SETTINGS_EDITOR_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_SETTINGS_EDITOR_DIALOG, XfceSettingsEditorDialogClass))
+
+G_BEGIN_DECLS
+
+typedef struct _XfceSettingsEditorDialog XfceSettingsEditorDialog;
+typedef struct _XfceSettingsEditorDialogClass XfceSettingsEditorDialogClass;
+
+GType xfce_settings_editor_dialog_get_type (void) G_GNUC_CONST;
+
+GtkWidget *xfce_settings_editor_dialog_new (void);
+
+G_END_DECLS
+
+#endif /* __XFCE_SETTINGS_EDITOR_DIALOG_H__ */
diff --git a/xfce4-settings-editor/xfce4-settings-editor.glade b/xfce4-settings-editor/xfce4-settings-editor.glade
deleted file mode 100644
index badc413..0000000
--- a/xfce4-settings-editor/xfce4-settings-editor.glade
+++ /dev/null
@@ -1,407 +0,0 @@
-<?xml version="1.0"?>
-<interface>
- <!-- interface-requires gtk+ 2.12 -->
- <!-- interface-requires libxfce4ui 4.5 -->
- <!-- interface-naming-policy toplevel-contextual -->
- <object class="GtkAdjustment" id="adjustment1">
- <property name="upper">100</property>
- <property name="step_increment">1</property>
- <property name="page_increment">10</property>
- </object>
- <object class="GtkListStore" id="model1">
- <columns>
- <!-- column-name gchararray -->
- <column type="gchararray"/>
- </columns>
- <data>
- <row>
- <col id="0" translatable="yes">Empty</col>
- </row>
- <row>
- <col id="0" translatable="yes">String</col>
- </row>
- <row>
- <col id="0" translatable="yes">Int</col>
- </row>
- <row>
- <col id="0" translatable="yes">Unsigned Int</col>
- </row>
- <row>
- <col id="0" translatable="yes">Int64</col>
- </row>
- <row>
- <col id="0" translatable="yes">Unsigned Int64</col>
- </row>
- <row>
- <col id="0" translatable="yes">Double</col>
- </row>
- <row>
- <col id="0" translatable="yes">Boolean</col>
- </row>
- </data>
- </object>
- <object class="XfceTitledDialog" id="edit_settings_dialog">
- <property name="title" translatable="yes">Edit Property</property>
- <property name="window_position">center-on-parent</property>
- <property name="icon_name">preferences-system</property>
- <property name="type_hint">dialog</property>
- <property name="transient_for">main_dialog</property>
- <property name="has_separator">False</property>
- <child internal-child="vbox">
- <object class="GtkVBox" id="dialog-vbox2">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">2</property>
- <child>
- <object class="GtkTable" id="table1">
- <property name="visible">True</property>
- <property name="border_width">6</property>
- <property name="n_rows">3</property>
- <property name="n_columns">2</property>
- <property name="column_spacing">12</property>
- <property name="row_spacing">6</property>
- <child>
- <object class="GtkVBox" id="vbox4">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkScrolledWindow" id="property_value_sw">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">automatic</property>
- <property name="vscrollbar_policy">automatic</property>
- <property name="shadow_type">in</property>
- <child>
- <object class="GtkTreeView" id="property_value_treeview">
- <property name="can_focus">True</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="property_value_text_entry">
- <property name="can_focus">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkSpinButton" id="property_value_spin_button">
- <property name="can_focus">True</property>
- <property name="adjustment">adjustment1</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkCheckButton" id="property_value_checkbutton">
- <property name="label" translatable="yes">Enabled</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">3</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label_type">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Type:</property>
- </object>
- <packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label_name">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Name:</property>
- </object>
- <packing>
- <property name="x_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label9">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="yalign">0</property>
- <property name="label" translatable="yes">Value:</property>
- </object>
- <packing>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="property_name_entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkComboBox" id="property_type_combo">
- <property name="visible">True</property>
- <property name="sensitive">False</property>
- <property name="model">model1</property>
- <child>
- <object class="GtkCellRendererText" id="renderer1"/>
- <attributes>
- <attribute name="text">0</attribute>
- </attributes>
- </child>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child internal-child="action_area">
- <object class="GtkHButtonBox" id="dialog-action_area2">
- <property name="visible">True</property>
- <property name="layout_style">end</property>
- <child>
- <object class="GtkButton" id="button3">
- <property name="label">gtk-cancel</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="button2">
- <property name="label">gtk-save</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- </child>
- <action-widgets>
- <action-widget response="-6">button3</action-widget>
- <action-widget response="-10">button2</action-widget>
- </action-widgets>
- </object>
- <object class="XfceTitledDialog" id="main_dialog">
- <property name="title" translatable="yes">Settings Editor</property>
- <property name="icon_name">preferences-system</property>
- <property name="type_hint">normal</property>
- <property name="has_separator">False</property>
- <property name="subtitle" translatable="yes">Customize settings stored by Xfconf</property>
- <child internal-child="vbox">
- <object class="GtkVBox" id="dialog-vbox4">
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkNotebook" id="notebook2">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="border_width">6</property>
- <property name="show_tabs">False</property>
- <property name="show_border">False</property>
- <child>
- <object class="GtkHPaned" id="hpaned2">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="position_set">True</property>
- <child>
- <object class="GtkScrolledWindow" id="scrolledwindow3">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">automatic</property>
- <property name="vscrollbar_policy">automatic</property>
- <property name="shadow_type">in</property>
- <child>
- <object class="GtkTreeView" id="channel_treeview">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="rules_hint">True</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="resize">False</property>
- <property name="shrink">True</property>
- </packing>
- </child>
- <child>
- <object class="GtkVBox" id="vbox1">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkToolbar" id="toolbar1">
- <property name="visible">True</property>
- <child>
- <object class="GtkToolButton" id="property_new_button">
- <property name="visible">True</property>
- <property name="sensitive">False</property>
- <property name="tooltip_text" translatable="yes">New property</property>
- <property name="stock_id">gtk-new</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="homogeneous">True</property>
- </packing>
- </child>
- <child>
- <object class="GtkToolButton" id="property_edit_button">
- <property name="visible">True</property>
- <property name="tooltip_text" translatable="yes">Edit property</property>
- <property name="stock_id">gtk-edit</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="homogeneous">True</property>
- </packing>
- </child>
- <child>
- <object class="GtkToolButton" id="property_revert_button">
- <property name="visible">True</property>
- <property name="tooltip_text" translatable="yes">Reset property</property>
- <property name="stock_id">gtk-revert-to-saved</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="homogeneous">True</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkScrolledWindow" id="scrolledwindow1">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">automatic</property>
- <property name="vscrollbar_policy">automatic</property>
- <property name="shadow_type">in</property>
- <child>
- <object class="GtkTreeView" id="property_treeview">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="resize">True</property>
- <property name="shrink">False</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="position">200</property>
- <property name="tab_expand">True</property>
- </packing>
- </child>
- <child type="tab">
- <object class="GtkLabel" id="label4">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Xfconf channels</property>
- </object>
- <packing>
- <property name="tab_fill">False</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="position">2</property>
- </packing>
- </child>
- <child internal-child="action_area">
- <object class="GtkHButtonBox" id="dialog-action_area4">
- <property name="layout_style">end</property>
- <child>
- <object class="GtkButton" id="button1">
- <property name="label">gtk-close</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- </child>
- <action-widgets>
- <action-widget response="-7">button1</action-widget>
- </action-widgets>
- </object>
-</interface>
More information about the Xfce4-commits
mailing list