Commit 4d4428c4b201395a8b3b459ba07892a2b31d7ba8

  • avatar
  • ssam
  • Mon Aug 17 03:12:24 CEST 2009
[gsettings] Add gsettings-ui plugin, and GtkSettingsList widget
  
281281plugins/gnome/icons/Makefile
282282plugins/gnome/icons/16x16/Makefile
283283plugins/gnome/icons/22x22/Makefile
284plugins/gsettings-ui/Makefile
284285plugins/python/Makefile
285286po/Makefile.in
286287doc/Makefile
  
1010SUBDIRS += python
1111endif
1212
13if BUILD_GSETTINGS_UI
14SUBDIRS += gsettings-ui
15endif
16
1317dtddir = $(pkgdatadir)/catalogs
1418dtd_DATA = glade-catalog.dtd
1519
  
1## Process this file with automake to produce Makefile.in
2
3SUBDIRS =
4
5libgladeui = $(top_builddir)/gladeui/libgladeui-1.la
6
7
8# libgladegsettings
9
10gladegsettings_LTLIBRARIES = libgladegsettings.la
11gladegsettingsdir = $(pkglibdir)/modules
12
13libgladegsettings_la_SOURCES = glade-gsettings.c
14libgladegsettings_la_CPPFLAGS = $(AM_CPPFLAGS)
15libgladegsettings_la_CFLAGS = \
16 -DG_LOG_DOMAIN=\"GladeUI-GSettings\" \
17 -I$(top_srcdir) \
18 -I$(top_builddir) \
19 -I$(top_srcdir)/plugins/gtk+ \
20 $(PLUGINS_WARN_CFLAGS) \
21 $(GTK_CFLAGS) \
22 $(AM_CPPFLAGS)
23libgladegsettings_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS)
24libgladegsettings_la_LIBADD = $(libgladeui) $(GTK_LIBS) $(GLADE_LIBS)
25
26if PLATFORM_WIN32
27libgladegsettings_la_LDFLAGS += -no-undefined
28endif
29
30
31# catalog data
32
33catalogsdir = $(pkgdatadir)/catalogs
34catalogs_DATA = gsettings-ui.xml \
35 gsettings-ui.xml.in
36@INTLTOOL_XML_NOMERGE_RULE@
37
38
39CLEANFILES = gsettings-ui.xml
40
41EXTRA_DIST = $(catalogs_DATA)
  
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/*
3 * Copyright (C) 2009 Sam Thursfield
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2.1 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 * Authors:
20 * Sam Thursfield <ssssam@gmail.com>
21 */
22
23#include <config.h>
24
25#include <glib/gi18n-lib.h>
26
27#include "glade-gsettings.h"
28#include "glade-gtk.h"
29#include "glade-column-types.h"
30#include "glade-model-data.h"
31
32#include <string.h>
33
34/*--------------------------- GtkSettingsList ---------------------------------*/
35
36/* A real GtkSettingsList is a GSettingsList that implements GtkBuildable. This stores its data in
37 * GSettings, which requires a schema. Since the schema will be generated from our output, and
38 * the user doesn't need the data he inputs in GLADE stored in persistant settings storage medium,
39 * we take a totally different approach. Our GtkSettingsList is basically a GtkListStore with a
40 * fixed number of columns.
41 *
42 * The data is set as the default in the schema by gsettings-scan-ui, and a real GtkSettingsList is
43 * created in the application when it loads the .ui file.
44 */
45
46/* FIXME: one problem with this setup is now GLADE can't link against gsettings-ui if it ever
47 * wants to. I can't see a way to give 'fake' widgets like this a different name, so I guess it will
48 * need to be implemented if GLADE ever starts using GSettings UI. (Although normal GSettings will
49 * be fine.)
50 */
51
52#define GTK_TYPE_SETTINGS_LIST (gtk_settings_list_get_type())
53#define GTK_SETTINGS_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SETTINGS_LIST, GtkSettingsList))
54
55typedef struct
56{
57 GtkListStore parent;
58} GtkSettingsList;
59
60typedef struct
61{
62 GtkListStoreClass parent_class;
63} GtkSettingsListClass;
64
65enum {
66 GTK_SETTINGS_LIST_PROP_0,
67 GTK_SETTINGS_LIST_PROP_COLUMNS
68};
69
70G_DEFINE_TYPE (GtkSettingsList, gtk_settings_list, GTK_TYPE_LIST_STORE)
71
72static void
73gtk_settings_list_init (GtkSettingsList *self)
74{
75 static const GType column_types[1] = { G_TYPE_STRING };
76 gtk_list_store_set_column_types (GTK_LIST_STORE (self), 1, column_types);
77}
78
79static void
80gtk_settings_list_class_init (GtkSettingsListClass *klass)
81{
82}
83
84
85void
86glade_gtk_settings_list_post_create (GladeWidgetAdaptor *adaptor,
87 GObject *container,
88 GladeCreateReason reason)
89{
90 GladeWidget *glade_widget = glade_widget_get_from_gobject (container);
91}
92void
93glade_gtk_settings_list_set_property (GladeWidgetAdaptor *adaptor,
94 GObject *object,
95 const gchar *property_name,
96 const GValue *value)
97{
98 if (strcmp (property_name, "columns") == 0)
99 {
100 /* glade_gtk_store_set_columns (object, value); */
101 }
102 else if (strcmp (property_name, "data") == 0)
103 {
104 glade_gtk_store_set_data (object, value);
105 }
106 else
107 /* Chain Up */
108 GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor,
109 object,
110 property_name,
111 value);
112}
113
114void
115glade_gtk_settings_list_write_widget (GladeWidgetAdaptor *adaptor,
116 GladeWidget *widget,
117 GladeXmlContext *context,
118 GladeXmlNode *node)
119{
120 if (!glade_xml_node_verify
121 (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
122 return;
123
124 /* First chain up and write all the normal properties.. */
125 GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node);
126
127 glade_gtk_store_write_data (widget, context, node);
128}
129
130void
131glade_gtk_settings_list_read_widget (GladeWidgetAdaptor *adaptor,
132 GladeWidget *widget,
133 GladeXmlNode *node)
134{
135 if (!glade_xml_node_verify
136 (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
137 return;
138
139 GValue value = { 0 };
140 GList *column_list = NULL;
141 GladeColumnType *column;
142 GladeProperty *property;
143
144 /* Set column info which is hardcoded. */
145
146 /* Column 0: G_TYPE_STRING */
147 column = g_new (GladeColumnType, 1);
148 column->type = G_TYPE_STRING;
149 column->column_name = g_strdup (_("Name"));
150 column_list = g_list_append (column_list, column);
151
152 /* Column 1: G_TYPE_SETTINGS */
153 /* this one is not currently editable. */
154
155 g_value_init (&value, GLADE_TYPE_COLUMN_TYPE_LIST);
156 g_value_take_boxed (&value, column_list);
157 property = glade_widget_get_property (widget, "columns");
158 glade_property_set_value (property, &value);
159 g_value_unset (&value);
160
161 /* First chain up and read in all the normal properties.. */
162 GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node);
163
164 if (GTK_IS_LIST_STORE (widget->object))
165 glade_gtk_store_read_data (widget, node);
166}
  
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/*
3 * Copyright (C) 2001 Ximian, Inc.
4 * Copyright (C) 2004 - 2008 Tristan Van Berkom, Juan Pablo Ugarte et al.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 * Authors:
21 * Sam Thursfield <ssssam@gmail.com>
22 */
23
24/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
25#ifndef __GLADE_GSETTINGS_H__
26#define __GLADE_GSETTINGS_H__
27
28#include <gladeui/glade.h>
29#include <gtk/gtk.h>
30
31
32/* Types */
33
34GParamSpec *glade_gsettings_gnome_ui_info_spec (void);
35
36
37#endif /* __GLADE_GTK_H__ */
  
1<glade-catalog name="gsettings-ui"
2 version="0.2"
3 supports="gtkbuilder"
4 icon-prefix="gsettings-ui"
5 library="gladegsettings"
6 domain="glade3"
7 depends="gtk+">
8 <glade-widget-classes>
9
10 <glade-widget-class name="GtkSettingsList" generic-name="settingslist" _title="Settings List"
11 libglade-unsupported="True" toplevel="True">
12 <post-create-function>glade_gtk_settings_list_post_create</post-create-function>
13 <set-property-function>glade_gtk_settings_list_set_property</set-property-function>
14 <create-editor-property-function>glade_gtk_store_create_eprop</create-editor-property-function>
15 <create-editable-function>glade_gtk_store_create_editable</create-editable-function>
16 <string-from-value-function>glade_gtk_store_string_from_value</string-from-value-function>
17 <write-widget-function>glade_gtk_settings_list_write_widget</write-widget-function>
18 <read-widget-function>glade_gtk_settings_list_read_widget</read-widget-function>
19 <properties>
20
21 <!-- Columns is a fake read-only property, because a GSettingsList has fixed columns. -->
22 <property id="columns" _name="Columns" save="False" custom-layout="True">
23 <parameter-spec>
24 <type>GParamBoxed</type>
25 <value-type>GladeColumnTypeList</value-type>
26 </parameter-spec>
27 <_tooltip>Column names and types - read-only</_tooltip>
28 </property>
29
30 <property id="data" _name="Data" save="False" custom-layout="True">
31 <parameter-spec>
32 <type>GParamBoxed</type>
33 <value-type>GladeModelDataTree</value-type>
34 </parameter-spec>
35 <_tooltip>Enter a list of values to be applied on each row</_tooltip>
36 </property>
37 </properties>
38 </glade-widget-class>
39
40 </glade-widget-classes>
41
42 <!-- FIXME: I would rather these went in with the Gtk+ widgets, but this requires either:
43 - implementing widget group merging (and might mislead users into thinking they don't need
44 to depend on libgsettings-ui)
45 - merging with the Gtk+ plugin, which only makes sense if the gsettings-ui widgets are merged
46 into Gtk+. In turn, this would only happen if it gets decided that Gtk+ will depend hard on
47 Gsettings.
48 -->
49 <glade-widget-group name="gsettings" _title="GSettings">
50 <glade-widget-class-ref name="GtkSettingsList"/>
51 </glade-widget-group>
52
53</glade-catalog>
  
98399839 gtk_tree_store_set_column_types (GTK_TREE_STORE (object), n, types);
98409840}
98419841
9842static void
9842void
98439843glade_gtk_store_set_data (GObject *object,
98449844 const GValue *value)
98459845{
1006910069
1007010070}
1007110071
10072static void
10072void
1007310073glade_gtk_store_write_data (GladeWidget *widget,
1007410074 GladeXmlContext *context,
1007510075 GladeXmlNode *node)
1022410224 g_value_unset (&value);
1022510225}
1022610226
10227static void
10227void
1022810228glade_gtk_store_read_data (GladeWidget *widget, GladeXmlNode *node)
1022910229{
1023010230 GladeXmlNode *data_node, *row_node, *col_node;
  
1010
1111GParamSpec *glade_gtk_gnome_ui_info_spec (void);
1212
13
13/* Utilities for other plugins */
14
15void glade_gtk_store_write_data (GladeWidget *widget, GladeXmlContext *context,
16 GladeXmlNode *node);
17void glade_gtk_store_read_data (GladeWidget *widget, GladeXmlNode *node);
18void glade_gtk_store_set_data (GObject *object, const GValue *value);
19
20
1421#endif /* __GLADE_GTK_H__ */
  
112112 g_object_weak_ref (G_OBJECT (store_editor->loaded_widget->project),
113113 (GWeakNotify)project_finalized,
114114 store_editor);
115
116 /* Decide whether to show the column editor. */
117 if (strcmp (g_type_name (widget->adaptor->type), "GtkSettingsList") == 0)
118 store_editor->columns_editable = FALSE;
119 else
120 store_editor->columns_editable = TRUE;
121
122 if (store_editor->columns_editable)
123 gtk_widget_show (store_editor->column_editor_frame);
124 else
125 gtk_widget_hide (store_editor->column_editor_frame);
115126 }
116127
117128 /* load the embedded editable... */
192192 /* Label item in frame label widget on top.. */
193193 eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "columns", FALSE, TRUE);
194194 store_editor->properties = g_list_prepend (store_editor->properties, eprop);
195 frame = gtk_frame_new (NULL);
195 store_editor->column_editor_frame = frame = gtk_frame_new (NULL);
196196 gtk_frame_set_label_widget (GTK_FRAME (frame), eprop->item_label);
197197 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
198198 gtk_box_pack_start (GTK_BOX (store_editor), frame, FALSE, FALSE, 12);
  
4242
4343 GladeWidget *loaded_widget; /* A handy pointer to the loaded widget ... */
4444
45 GtkWidget *embed;
45 GtkWidget *embed, *column_editor_frame;
4646
4747 GList *properties; /* A list of eprops to update at load() time */
48
49 gboolean columns_editable; /* If false, the column editor is hidden. */
4850};
4951
5052struct _GladeStoreEditorClass