~ubuntu-branches/ubuntu/natty/xfce4-panel/natty

« back to all changes in this revision

Viewing changes to common/panel-xfconf.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc
  • Date: 2010-12-04 15:45:53 UTC
  • mfrom: (1.1.25 upstream)
  • Revision ID: james.westby@ubuntu.com-20101204154553-c1k0n2p2j83chld0
Tags: 4.7.5-0ubuntu1
Upload to natty (pkg-xfce svn r4611).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009 Nick Schermer <nick@xfce.org>
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License along
 
15
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
17
 */
 
18
 
 
19
#ifdef HAVE_CONFIG_H
 
20
#include <config.h>
 
21
#endif
 
22
 
 
23
#include <dbus/dbus-glib.h>
 
24
 
 
25
#include <common/panel-private.h>
 
26
#include <common/panel-xfconf.h>
 
27
#include <libxfce4panel/xfce-panel-macros.h>
 
28
 
 
29
 
 
30
 
 
31
static void
 
32
panel_properties_store_value (XfconfChannel *channel,
 
33
                              const gchar   *xfconf_property,
 
34
                              GType          xfconf_property_type,
 
35
                              GObject       *object,
 
36
                              const gchar   *object_property)
 
37
{
 
38
  GValue      value = { 0, };
 
39
#ifndef NDEBUG
 
40
  GParamSpec *pspec;
 
41
#endif
 
42
 
 
43
  panel_return_if_fail (G_IS_OBJECT (object));
 
44
  panel_return_if_fail (XFCONF_IS_CHANNEL (channel));
 
45
 
 
46
#ifndef NDEBUG
 
47
  /* check if the types match */
 
48
  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), object_property);
 
49
  panel_assert (pspec != NULL);
 
50
  panel_assert (G_PARAM_SPEC_VALUE_TYPE (pspec) == xfconf_property_type);
 
51
#endif
 
52
 
 
53
  /* write the property to the xfconf channel */
 
54
  g_value_init (&value, xfconf_property_type);
 
55
  g_object_get_property (G_OBJECT (object), object_property, &value);
 
56
  xfconf_channel_set_property (channel, xfconf_property, &value);
 
57
  g_value_unset (&value);
 
58
}
 
59
 
 
60
 
 
61
 
 
62
XfconfChannel *
 
63
panel_properties_get_channel (GObject *object_for_weak_ref)
 
64
{
 
65
  GError        *error = NULL;
 
66
  XfconfChannel *channel;
 
67
 
 
68
  panel_return_val_if_fail (G_IS_OBJECT (object_for_weak_ref), NULL);
 
69
 
 
70
  if (!xfconf_init (&error))
 
71
    {
 
72
      g_critical ("Failed to initialize Xfconf: %s", error->message);
 
73
      g_error_free (error);
 
74
      return NULL;
 
75
    }
 
76
 
 
77
  channel = xfconf_channel_get (XFCE_PANEL_CHANNEL_NAME);
 
78
  g_object_weak_ref (object_for_weak_ref, (GWeakNotify) xfconf_shutdown, NULL);
 
79
 
 
80
  return channel;
 
81
}
 
82
 
 
83
 
 
84
 
 
85
void
 
86
panel_properties_bind (XfconfChannel       *channel,
 
87
                       GObject             *object,
 
88
                       const gchar         *property_base,
 
89
                       const PanelProperty *properties,
 
90
                       gboolean             save_properties)
 
91
{
 
92
  const PanelProperty *prop;
 
93
  gchar               *property;
 
94
 
 
95
  panel_return_if_fail (channel == NULL || XFCONF_IS_CHANNEL (channel));
 
96
  panel_return_if_fail (G_IS_OBJECT (object));
 
97
  panel_return_if_fail (property_base != NULL && *property_base == '/');
 
98
  panel_return_if_fail (properties != NULL);
 
99
 
 
100
  if (G_LIKELY (channel == NULL))
 
101
    channel = panel_properties_get_channel (object);
 
102
  panel_return_if_fail (XFCONF_IS_CHANNEL (channel));
 
103
 
 
104
  /* walk the properties array */
 
105
  for (prop = properties; prop->property != NULL; prop++)
 
106
    {
 
107
      property = g_strconcat (property_base, "/", prop->property, NULL);
 
108
 
 
109
      if (save_properties)
 
110
        panel_properties_store_value (channel, property, prop->type, object, prop->property);
 
111
 
 
112
      if (G_LIKELY (prop->type != GDK_TYPE_COLOR))
 
113
        xfconf_g_property_bind (channel, property, prop->type, object, prop->property);
 
114
      else
 
115
        xfconf_g_property_bind_gdkcolor (channel, property, object, prop->property);
 
116
 
 
117
      g_free (property);
 
118
    }
 
119
}
 
120
 
 
121
 
 
122
 
 
123
void
 
124
panel_properties_unbind (GObject *object)
 
125
{
 
126
  xfconf_g_property_unbind_all (object);
 
127
}
 
128
 
 
129
 
 
130
 
 
131
GType
 
132
panel_properties_value_array_get_type (void)
 
133
{
 
134
  static volatile gsize type__volatile = 0;
 
135
  GType                 type;
 
136
 
 
137
  if (g_once_init_enter (&type__volatile))
 
138
    {
 
139
      type = dbus_g_type_get_collection ("GPtrArray", G_TYPE_VALUE);
 
140
      g_once_init_leave (&type__volatile, type);
 
141
    }
 
142
 
 
143
  return type__volatile;
 
144
}