21
21
#include <string.h>
23
24
#include "nma-gconf-settings.h"
24
25
#include "gconf-helpers.h"
25
26
#include "nma-marshal.h"
26
27
#include "nm-utils.h"
28
G_DEFINE_TYPE (NMAGConfSettings, nma_gconf_settings, NM_TYPE_SETTINGS)
29
G_DEFINE_TYPE (NMAGConfSettings, nma_gconf_settings, NM_TYPE_SETTINGS_SERVICE)
30
31
#define NMA_GCONF_SETTINGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMA_TYPE_GCONF_SETTINGS, NMAGConfSettingsPrivate))
52
nma_gconf_settings_new (void)
53
nma_gconf_settings_new (DBusGConnection *bus)
54
return (NMAGConfSettings *) g_object_new (NMA_TYPE_GCONF_SETTINGS, NULL);
55
return (NMAGConfSettings *) g_object_new (NMA_TYPE_GCONF_SETTINGS,
56
NM_SETTINGS_SERVICE_SCOPE, NM_CONNECTION_SCOPE_USER,
57
NM_SETTINGS_SERVICE_BUS, bus,
59
63
const char *setting_name,
60
64
const char **hints,
62
DBusGMethodInvocation *context,
66
NMANewSecretsRequestedFunc callback,
67
gpointer callback_data,
63
68
gpointer user_data)
65
70
NMAGConfSettings *self = NMA_GCONF_SETTINGS (user_data);
90
add_connection_real (NMAGConfSettings *self, NMAGConfConnection *connection)
96
internal_add_connection (NMAGConfSettings *self, NMAGConfConnection *connection)
92
98
NMAGConfSettingsPrivate *priv = NMA_GCONF_SETTINGS_GET_PRIVATE (self);
95
priv->connections = g_slist_prepend (priv->connections, connection);
96
g_signal_connect (connection, "new-secrets-requested",
97
G_CALLBACK (connection_new_secrets_requested_cb),
100
g_signal_connect (connection, "removed", G_CALLBACK (connection_removed), self);
101
nm_settings_signal_new_connection (NM_SETTINGS (self),
102
NM_EXPORTED_CONNECTION (connection));
99
DBusGConnection *bus = NULL;
101
g_return_if_fail (connection != NULL);
103
priv->connections = g_slist_prepend (priv->connections, connection);
104
g_signal_connect (connection, "new-secrets-requested",
105
G_CALLBACK (connection_new_secrets_requested_cb),
108
g_signal_connect (connection, "removed", G_CALLBACK (connection_removed), self);
110
g_object_get (G_OBJECT (self), NM_SETTINGS_SERVICE_BUS, &bus, NULL);
112
nm_settings_service_export_connection (NM_SETTINGS_SERVICE (self),
113
NM_SETTINGS_CONNECTION_INTERFACE (connection));
114
dbus_g_connection_unref (bus);
117
g_signal_emit_by_name (self, NM_SETTINGS_INTERFACE_NEW_CONNECTION, NM_CONNECTION (connection));
121
update_cb (NMSettingsConnectionInterface *connection,
126
g_warning ("%s: %s:%d error updating connection %s: (%d) %s",
127
__func__, __FILE__, __LINE__,
128
nma_gconf_connection_get_gconf_path (NMA_GCONF_CONNECTION (connection)),
129
error ? error->code : -1,
130
(error && error->message) ? error->message : "(unknown)");
135
163
exported = nma_gconf_connection_new_from_connection (priv->client, path, connection);
140
add_connection_real (self, exported);
142
/* Must save connection to GConf _after_ adding it to the connections
143
* list to avoid races with GConf notifications.
145
nma_gconf_connection_save (exported);
166
internal_add_connection (self, exported);
168
/* Must save connection to GConf _after_ adding it to the connections
169
* list to avoid races with GConf notifications.
171
nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (exported), update_cb, NULL);
151
nma_gconf_settings_get_by_path (NMAGConfSettings *self, const char *path)
178
add_connection (NMSettingsService *settings,
179
NMConnection *connection,
180
DBusGMethodInvocation *context, /* Only present for D-Bus calls */
181
NMSettingsAddConnectionFunc callback,
184
NMAGConfSettings *self = NMA_GCONF_SETTINGS (settings);
186
/* For now, we don't support additions via D-Bus until we figure out
187
* the security implications.
192
error = g_error_new (0, 0, "%s: adding connections via D-Bus is not (yet) supported", __func__);
193
callback (NM_SETTINGS_INTERFACE (settings), error, user_data);
194
g_error_free (error);
198
nma_gconf_settings_add_connection (self, connection);
199
callback (NM_SETTINGS_INTERFACE (settings), NULL, user_data);
202
static NMAGConfConnection *
203
get_connection_by_gconf_path (NMAGConfSettings *self, const char *path)
153
205
NMAGConfSettingsPrivate *priv;
173
nma_gconf_settings_get_by_dbus_path (NMAGConfSettings *self,
176
NMAGConfSettingsPrivate *priv;
179
g_return_val_if_fail (NMA_IS_GCONF_SETTINGS (self), NULL);
180
g_return_val_if_fail (path != NULL, NULL);
182
priv = NMA_GCONF_SETTINGS_GET_PRIVATE (self);
183
for (iter = priv->connections; iter; iter = iter->next) {
184
NMAGConfConnection *connection = NMA_GCONF_CONNECTION (iter->data);
185
NMConnection *wrapped;
188
wrapped = nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (connection));
189
sc_path = nm_connection_get_path (wrapped);
191
if (sc_path && !strcmp (sc_path, path))
199
nma_gconf_settings_get_by_connection (NMAGConfSettings *self,
200
NMConnection *connection)
202
NMAGConfSettingsPrivate *priv;
205
g_return_val_if_fail (NMA_IS_GCONF_SETTINGS (self), NULL);
206
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
208
priv = NMA_GCONF_SETTINGS_GET_PRIVATE (self);
210
for (iter = priv->connections; iter; iter = iter->next) {
211
NMConnection *wrapped;
213
wrapped = nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (iter->data));
214
if (connection == wrapped)
215
return NMA_GCONF_CONNECTION (iter->data);
222
225
read_connections (NMAGConfSettings *settings)
232
235
for (iter = dir_list; iter; iter = iter->next) {
233
236
char *dir = (char *) iter->data;
237
NMAGConfConnection *connection;
235
add_connection_real (settings, nma_gconf_connection_new (priv->client, dir));
239
connection = nma_gconf_connection_new (priv->client, dir);
241
internal_add_connection (settings, connection);
285
291
NMAGConfSettingsPrivate *priv = NMA_GCONF_SETTINGS_GET_PRIVATE (info->settings);
286
292
NMAGConfConnection *connection;
288
connection = nma_gconf_settings_get_by_path (info->settings, info->path);
294
connection = get_connection_by_gconf_path (info->settings, info->path);
289
295
if (!connection) {
290
296
/* New connection */
291
297
connection = nma_gconf_connection_new (priv->client, info->path);
292
add_connection_real (info->settings, connection);
299
internal_add_connection (info->settings, connection);
294
301
if (gconf_client_dir_exists (priv->client, info->path, NULL)) {
295
302
/* Updated connection */
296
if (!nma_gconf_connection_changed (connection))
303
if (!nma_gconf_connection_gconf_changed (connection))
297
304
priv->connections = g_slist_remove (priv->connections, connection);
353
360
g_source_remove (GPOINTER_TO_UINT (data));
363
/************************************************************/
359
nma_gconf_settings_init (NMAGConfSettings *settings)
366
nma_gconf_settings_init (NMAGConfSettings *self)
361
NMAGConfSettingsPrivate *priv = NMA_GCONF_SETTINGS_GET_PRIVATE (settings);
368
NMAGConfSettingsPrivate *priv = NMA_GCONF_SETTINGS_GET_PRIVATE (self);
363
370
priv->client = gconf_client_get_default ();
364
371
priv->pending_changes = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, remove_pending_change);
381
388
GObjectConstructParam *construct_params)
384
NMAGConfSettingsPrivate *priv;
386
392
object = G_OBJECT_CLASS (nma_gconf_settings_parent_class)->constructor (type, n_construct_params, construct_params);
391
priv = NMA_GCONF_SETTINGS_GET_PRIVATE (object);
393
priv->read_connections_id = g_idle_add (read_connections_cb, object);
394
NMA_GCONF_SETTINGS_GET_PRIVATE (object)->read_connections_id = g_idle_add (read_connections_cb, object);
427
nma_gconf_settings_class_init (NMAGConfSettingsClass *gconf_settings_class)
427
nma_gconf_settings_class_init (NMAGConfSettingsClass *class)
429
GObjectClass *object_class = G_OBJECT_CLASS (gconf_settings_class);
430
NMSettingsClass *settings_class = NM_SETTINGS_CLASS (gconf_settings_class);
429
GObjectClass *object_class = G_OBJECT_CLASS (class);
430
NMSettingsServiceClass *settings_class = NM_SETTINGS_SERVICE_CLASS (class);
432
g_type_class_add_private (gconf_settings_class, sizeof (NMAGConfSettingsPrivate));
432
g_type_class_add_private (class, sizeof (NMAGConfSettingsPrivate));
434
434
/* Virtual methods */
435
435
object_class->constructor = constructor;
436
436
object_class->dispose = dispose;
438
438
settings_class->list_connections = list_connections;
439
settings_class->add_connection = add_connection;
441
442
signals[NEW_SECRETS_REQUESTED] =
444
445
G_SIGNAL_RUN_FIRST,
445
446
G_STRUCT_OFFSET (NMAGConfSettingsClass, new_secrets_requested),
447
nma_marshal_VOID__OBJECT_STRING_POINTER_BOOLEAN_POINTER,
449
G_TYPE_OBJECT, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN, G_TYPE_POINTER);
448
nma_marshal_VOID__OBJECT_STRING_POINTER_BOOLEAN_POINTER_POINTER,
450
G_TYPE_OBJECT, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN, G_TYPE_POINTER, G_TYPE_POINTER);