-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpanel-xfconf.c
160 lines (128 loc) · 4.79 KB
/
panel-xfconf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* Copyright (C) 2009-2010 Nick Schermer <[email protected]>
*
* This library 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 library 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 Lesser General Public
* License along with this library; 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
#include <dbus/dbus-glib.h>
#include <panel-private.h>
#include <panel-xfconf.h>
#include <libxfce4panel/xfce-panel-macros.h>
static void
panel_properties_store_value (XfconfChannel *channel,
const gchar *xfconf_property,
GType xfconf_property_type,
GObject *object,
const gchar *object_property)
{
GValue value = { 0, };
GdkColor *color;
guint16 alpha = 0xffff;
#ifndef NDEBUG
GParamSpec *pspec;
#endif
panel_return_if_fail (G_IS_OBJECT (object));
panel_return_if_fail (XFCONF_IS_CHANNEL (channel));
#ifndef NDEBUG
/* check if the types match */
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), object_property);
panel_assert (pspec != NULL);
panel_assert (G_PARAM_SPEC_VALUE_TYPE (pspec) == xfconf_property_type);
#endif
/* write the property to the xfconf channel */
g_value_init (&value, xfconf_property_type);
g_object_get_property (G_OBJECT (object), object_property, &value);
if (G_LIKELY (xfconf_property_type != GDK_TYPE_COLOR))
{
xfconf_channel_set_property (channel, xfconf_property, &value);
}
else
{
/* work around xfconf's lack of storing colors (bug #7117) and
* do the same as xfconf_g_property_bind_gdkcolor() does */
color = g_value_get_boxed (&value);
xfconf_channel_set_array (channel, xfconf_property,
XFCONF_TYPE_UINT16, &color->red,
XFCONF_TYPE_UINT16, &color->green,
XFCONF_TYPE_UINT16, &color->blue,
XFCONF_TYPE_UINT16, &alpha,
G_TYPE_INVALID);
}
g_value_unset (&value);
}
XfconfChannel *
panel_properties_get_channel (GObject *object_for_weak_ref)
{
GError *error = NULL;
XfconfChannel *channel;
panel_return_val_if_fail (G_IS_OBJECT (object_for_weak_ref), NULL);
if (!xfconf_init (&error))
{
g_critical ("Failed to initialize Xfconf: %s", error->message);
g_error_free (error);
return NULL;
}
channel = xfconf_channel_get (XFCE_PANEL_CHANNEL_NAME);
g_object_weak_ref (object_for_weak_ref, (GWeakNotify) xfconf_shutdown, NULL);
return channel;
}
void
panel_properties_bind (XfconfChannel *channel,
GObject *object,
const gchar *property_base,
const PanelProperty *properties,
gboolean save_properties)
{
const PanelProperty *prop;
gchar *property;
panel_return_if_fail (channel == NULL || XFCONF_IS_CHANNEL (channel));
panel_return_if_fail (G_IS_OBJECT (object));
panel_return_if_fail (property_base != NULL && *property_base == '/');
panel_return_if_fail (properties != NULL);
if (G_LIKELY (channel == NULL))
channel = panel_properties_get_channel (object);
panel_return_if_fail (XFCONF_IS_CHANNEL (channel));
/* walk the properties array */
for (prop = properties; prop->property != NULL; prop++)
{
property = g_strconcat (property_base, "/", prop->property, NULL);
if (save_properties)
panel_properties_store_value (channel, property, prop->type, object, prop->property);
if (G_LIKELY (prop->type != GDK_TYPE_COLOR))
xfconf_g_property_bind (channel, property, prop->type, object, prop->property);
else
xfconf_g_property_bind_gdkcolor (channel, property, object, prop->property);
g_free (property);
}
}
void
panel_properties_unbind (GObject *object)
{
xfconf_g_property_unbind_all (object);
}
GType
panel_properties_value_array_get_type (void)
{
static volatile gsize type__volatile = 0;
GType type;
if (g_once_init_enter (&type__volatile))
{
type = dbus_g_type_get_collection ("GPtrArray", G_TYPE_VALUE);
g_once_init_leave (&type__volatile, type);
}
return type__volatile;
}