2
* Copyright (C) 2009 Mark Lee <avant-wn@lazymalevolence.com>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library 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 GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
19
* Author : Mark Lee <avant-wn@lazymalevolence.com>
26
#include "awn-config.h"
30
* @short_description: Convenience functions for handling dock/applet
32
* @see_also: #DesktopAgnosticConfigClient
35
* Functions used by the dock, applets, and preferences dialogs to
36
* associate configuration options with the first two categories. Also
37
* handles their memory management.
40
#define SCHEMADIR PKGDATADIR "/schemas"
41
#define UID_SINGLE_INSTANCE_PREFIX "single-"
43
/* The config client cache. */
44
static GData* awn_config_clients = NULL;
48
on_config_destroy (gpointer data)
50
DesktopAgnosticConfigClient* cfg = (DesktopAgnosticConfigClient*)data;
56
* awn_config_get_default:
57
* @panel_id: The ID of the panel that is associated with the configuration
59
* @error: The address of the #GError object, if an error occurs.
61
* Looks up or creates a configuration client that is associated with the
64
* Returns: A borrowed reference to a configuration client object.
66
DesktopAgnosticConfigClient*
67
awn_config_get_default (gint panel_id, GError** error)
69
char *instance_id = NULL;
70
DesktopAgnosticConfigClient *client = NULL;
72
if (awn_config_clients == NULL)
74
/* initialize datalist */
75
g_datalist_init (&awn_config_clients);
77
instance_id = g_strdup_printf ("panel-%d", panel_id);
78
client = (DesktopAgnosticConfigClient*)g_datalist_get_data (&awn_config_clients,
82
char *schema_filename;
84
schema_filename = g_build_filename (SCHEMADIR, "avant-window-navigator.schema-ini", NULL);
85
client = desktop_agnostic_config_client_new_for_instance (schema_filename,
88
g_free (schema_filename);
89
if (error && *error != NULL)
93
g_object_unref (client);
98
g_datalist_set_data_full (&awn_config_clients, instance_id, client,
101
g_free (instance_id);
109
* Properly frees all of the config clients in the cache.
111
* Should be called on dock shutdown.
114
awn_config_free (void)
116
g_datalist_clear (&awn_config_clients);
121
* awn_config_get_default_for_applet:
122
* @applet: The applet.
123
* @error: The address of the #GError object, if an error occurs.
125
* Looks up or creates a configuration client that is associated with the
128
* Returns: A borrowed reference to the configuration client associated with
129
* the applet specified via the metadata.
131
DesktopAgnosticConfigClient*
132
awn_config_get_default_for_applet (AwnApplet *applet, GError **error)
134
g_return_val_if_fail (applet != NULL, NULL);
136
gchar *canonical_name = NULL;
138
DesktopAgnosticConfigClient *client = NULL;
140
g_object_get (G_OBJECT (applet),
141
"canonical-name", &canonical_name,
145
g_return_val_if_fail (canonical_name != NULL, NULL);
147
client = awn_config_get_default_for_applet_by_info (canonical_name,
156
g_free (canonical_name);
163
* awn_config_get_default_for_applet_by_info:
164
* @name: The canonical applet name.
165
* @uid: The UID of the applet (may be %NULL).
166
* @error: The address of the #GError object, if an error occurs.
168
* Looks up or creates a configuration client that is associated with the
169
* canonical name of an applet and an optional UID.
170
* Should only be used by code where the #AwnApplet object is not present,
171
* such as the dock's preferences dialog.
173
* Returns: A borrowed reference to the configuration client associated with
174
* the applet specified via the metadata.
176
DesktopAgnosticConfigClient*
177
awn_config_get_default_for_applet_by_info (const gchar *name,
181
g_return_val_if_fail (name != NULL, NULL);
183
gboolean single_instance;
185
DesktopAgnosticConfigClient *client = NULL;
187
if (awn_config_clients == NULL)
189
/* initialize datalist */
190
g_datalist_init (&awn_config_clients);
193
single_instance = (uid == NULL ||
194
g_str_has_prefix (uid, UID_SINGLE_INSTANCE_PREFIX));
198
instance_id = g_strdup_printf ("awn-applet-%s", name);
202
instance_id = g_strdup_printf ("awn-applet-%s-%s", name, uid);
205
client = (DesktopAgnosticConfigClient*)g_datalist_get_data (&awn_config_clients,
210
gchar *schema_basename;
211
gchar *schema_filename;
213
schema_basename = g_strdup_printf ("awn-applet-%s.schema-ini", name);
215
schema_filename = g_build_filename (SCHEMADIR, schema_basename, NULL);
217
g_free (schema_basename);
221
client = desktop_agnostic_config_client_new (schema_filename);
225
client = desktop_agnostic_config_client_new_for_instance (schema_filename,
230
g_free (schema_filename);
231
if (error && *error != NULL)
235
g_object_unref (client);
237
g_free (instance_id);
240
g_datalist_set_data_full (&awn_config_clients, instance_id, client,
243
g_free (instance_id);