~ubuntu-branches/ubuntu/lucid/network-manager-applet/lucid-updates

« back to all changes in this revision

Viewing changes to src/gconf-helpers/nma-gconf-settings.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack, Alexander Sack, Tony Espy
  • Date: 2009-09-14 11:32:57 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090914113257-47x5o2kfwwm95w3l
Tags: 0.8~a~git.20090913t161448.cc2f6be-0ubuntu1
* upstream snapshot 2009-09-13 16:14:48 (GMT)
  + cc2f6bea12daec5f0caf535a3534f07ade5b5cf2

[ Alexander Sack <asac@ubuntu.com> ]
* build depend on libpolkit-gobject-1-dev instead of libpolkit-dbus-dev
  - update debian/control

[ Tony Espy <espy@ubuntu.com> ]
* adjust patches for upstream code base
  - update debian/patches/20_use_full_vpn_dialog_service_name_path.patch
  - update debian/patches/lp328572_dxteam_connect_text.patch
  - update debian/patches/lp337960_dxteam_notification_icon_names.diff
  - update debian/patches/lp341684_device_sensitive_disconnect_notify.patch
* adjust build and runtime depends due to ABI changes in latest NM
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include <string.h>
22
22
#include <stdio.h>
 
23
 
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"
27
28
 
28
 
G_DEFINE_TYPE (NMAGConfSettings, nma_gconf_settings, NM_TYPE_SETTINGS)
 
29
G_DEFINE_TYPE (NMAGConfSettings, nma_gconf_settings, NM_TYPE_SETTINGS_SERVICE)
29
30
 
30
31
#define NMA_GCONF_SETTINGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMA_TYPE_GCONF_SETTINGS, NMAGConfSettingsPrivate))
31
32
 
49
50
 
50
51
 
51
52
NMAGConfSettings *
52
 
nma_gconf_settings_new (void)
 
53
nma_gconf_settings_new (DBusGConnection *bus)
53
54
{
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,
 
58
                                                  NULL);
55
59
}
56
60
 
57
61
static void
59
63
                                     const char *setting_name,
60
64
                                     const char **hints,
61
65
                                     gboolean ask_user,
62
 
                                     DBusGMethodInvocation *context,
 
66
                                     NMANewSecretsRequestedFunc callback,
 
67
                                     gpointer callback_data,
63
68
                                     gpointer user_data)
64
69
{
65
70
        NMAGConfSettings *self = NMA_GCONF_SETTINGS (user_data);
74
79
                       setting_name,
75
80
                       hints,
76
81
                       ask_user,
77
 
                       context);
 
82
                       callback,
 
83
                       callback_data);
78
84
}
79
85
 
80
86
static void
87
93
}
88
94
 
89
95
static void
90
 
add_connection_real (NMAGConfSettings *self, NMAGConfConnection *connection)
 
96
internal_add_connection (NMAGConfSettings *self, NMAGConfConnection *connection)
91
97
{
92
98
        NMAGConfSettingsPrivate *priv = NMA_GCONF_SETTINGS_GET_PRIVATE (self);
93
 
 
94
 
        if (connection) {
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),
98
 
                                           self);
99
 
 
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;
 
100
 
 
101
        g_return_if_fail (connection != NULL);
 
102
 
 
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),
 
106
                          self);
 
107
 
 
108
        g_signal_connect (connection, "removed", G_CALLBACK (connection_removed), self);
 
109
 
 
110
        g_object_get (G_OBJECT (self), NM_SETTINGS_SERVICE_BUS, &bus, NULL);
 
111
        if (bus) {
 
112
                nm_settings_service_export_connection (NM_SETTINGS_SERVICE (self),
 
113
                                                       NM_SETTINGS_CONNECTION_INTERFACE (connection));
 
114
                dbus_g_connection_unref (bus);
 
115
        }
 
116
 
 
117
        g_signal_emit_by_name (self, NM_SETTINGS_INTERFACE_NEW_CONNECTION, NM_CONNECTION (connection));
 
118
}
 
119
 
 
120
static void
 
121
update_cb (NMSettingsConnectionInterface *connection,
 
122
           GError *error,
 
123
           gpointer user_data)
 
124
{
 
125
        if (error) {
 
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)");
103
131
        }
104
132
}
105
133
 
134
162
 
135
163
        exported = nma_gconf_connection_new_from_connection (priv->client, path, connection);
136
164
        g_free (path);
137
 
        if (!exported)
138
 
                return NULL;
139
 
 
140
 
        add_connection_real (self, exported);
141
 
 
142
 
        /* Must save connection to GConf _after_ adding it to the connections
143
 
         * list to avoid races with GConf notifications.
144
 
         */
145
 
        nma_gconf_connection_save (exported);
 
165
        if (exported) {
 
166
                internal_add_connection (self, exported);
 
167
 
 
168
                /* Must save connection to GConf _after_ adding it to the connections
 
169
                 * list to avoid races with GConf notifications.
 
170
                 */
 
171
                nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (exported), update_cb, NULL);
 
172
        }
146
173
 
147
174
        return exported;
148
175
}
149
176
 
150
 
NMAGConfConnection *
151
 
nma_gconf_settings_get_by_path (NMAGConfSettings *self, const char *path)
 
177
static void
 
178
add_connection (NMSettingsService *settings,
 
179
                NMConnection *connection,
 
180
                DBusGMethodInvocation *context, /* Only present for D-Bus calls */
 
181
                NMSettingsAddConnectionFunc callback,
 
182
                gpointer user_data)
 
183
{
 
184
        NMAGConfSettings *self = NMA_GCONF_SETTINGS (settings);
 
185
 
 
186
        /* For now, we don't support additions via D-Bus until we figure out
 
187
         * the security implications.
 
188
         */
 
189
        if (context) {
 
190
                GError *error;
 
191
 
 
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);
 
195
                return;
 
196
        }
 
197
 
 
198
        nma_gconf_settings_add_connection (self, connection);
 
199
        callback (NM_SETTINGS_INTERFACE (settings), NULL, user_data);
 
200
}
 
201
 
 
202
static NMAGConfConnection *
 
203
get_connection_by_gconf_path (NMAGConfSettings *self, const char *path)
152
204
{
153
205
        NMAGConfSettingsPrivate *priv;
154
206
        GSList *iter;
161
213
                NMAGConfConnection *connection = NMA_GCONF_CONNECTION (iter->data);
162
214
                const char *gconf_path;
163
215
 
164
 
                gconf_path = nma_gconf_connection_get_path (connection);
 
216
                gconf_path = nma_gconf_connection_get_gconf_path (connection);
165
217
                if (gconf_path && !strcmp (gconf_path, path))
166
218
                        return connection;
167
219
        }
169
221
        return NULL;
170
222
}
171
223
 
172
 
NMAGConfConnection *
173
 
nma_gconf_settings_get_by_dbus_path (NMAGConfSettings *self,
174
 
                                                          const char *path)
175
 
{
176
 
        NMAGConfSettingsPrivate *priv;
177
 
        GSList *iter;
178
 
 
179
 
        g_return_val_if_fail (NMA_IS_GCONF_SETTINGS (self), NULL);
180
 
        g_return_val_if_fail (path != NULL, NULL);
181
 
 
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;
186
 
                const char *sc_path;
187
 
 
188
 
                wrapped = nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (connection));
189
 
                sc_path = nm_connection_get_path (wrapped);
190
 
 
191
 
                if (sc_path && !strcmp (sc_path, path))
192
 
                        return connection;
193
 
        }
194
 
 
195
 
        return NULL;
196
 
}
197
 
 
198
 
NMAGConfConnection *
199
 
nma_gconf_settings_get_by_connection (NMAGConfSettings *self,
200
 
                                                           NMConnection *connection)
201
 
{
202
 
        NMAGConfSettingsPrivate *priv;
203
 
        GSList *iter;
204
 
 
205
 
        g_return_val_if_fail (NMA_IS_GCONF_SETTINGS (self), NULL);
206
 
        g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
207
 
 
208
 
        priv = NMA_GCONF_SETTINGS_GET_PRIVATE (self);
209
 
 
210
 
        for (iter = priv->connections; iter; iter = iter->next) {
211
 
                NMConnection *wrapped;
212
 
 
213
 
                wrapped = nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (iter->data));
214
 
                if (connection == wrapped)
215
 
                        return NMA_GCONF_CONNECTION (iter->data);
216
 
        }
217
 
 
218
 
        return NULL;
219
 
}
220
 
 
221
224
static void
222
225
read_connections (NMAGConfSettings *settings)
223
226
{
231
234
 
232
235
        for (iter = dir_list; iter; iter = iter->next) {
233
236
                char *dir = (char *) iter->data;
 
237
                NMAGConfConnection *connection;
234
238
 
235
 
                add_connection_real (settings, nma_gconf_connection_new (priv->client, dir));
 
239
                connection = nma_gconf_connection_new (priv->client, dir);
 
240
                if (connection)
 
241
                        internal_add_connection (settings, connection);
236
242
                g_free (dir);
237
243
        }
238
244
 
250
256
}
251
257
 
252
258
static GSList *
253
 
list_connections (NMSettings *settings)
 
259
list_connections (NMSettingsService *settings)
254
260
{
255
261
        NMAGConfSettingsPrivate *priv = NMA_GCONF_SETTINGS_GET_PRIVATE (settings);
256
262
 
285
291
        NMAGConfSettingsPrivate *priv = NMA_GCONF_SETTINGS_GET_PRIVATE (info->settings);
286
292
        NMAGConfConnection *connection;
287
293
 
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);
 
298
                if (connection)
 
299
                        internal_add_connection (info->settings, connection);
293
300
        } else {
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);
298
305
                }
299
306
        }
353
360
        g_source_remove (GPOINTER_TO_UINT (data));
354
361
}
355
362
 
356
 
/* GObject */
 
363
/************************************************************/
357
364
 
358
365
static void
359
 
nma_gconf_settings_init (NMAGConfSettings *settings)
 
366
nma_gconf_settings_init (NMAGConfSettings *self)
360
367
{
361
 
        NMAGConfSettingsPrivate *priv = NMA_GCONF_SETTINGS_GET_PRIVATE (settings);
 
368
        NMAGConfSettingsPrivate *priv = NMA_GCONF_SETTINGS_GET_PRIVATE (self);
362
369
 
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);
369
376
                              NULL);
370
377
 
371
378
        priv->conf_notify_id = gconf_client_notify_add (priv->client,
372
 
                                                                                   GCONF_PATH_CONNECTIONS,
373
 
                                                                                   (GConfClientNotifyFunc) connections_changed_cb,
374
 
                                                                                   settings,
375
 
                                                                                   NULL, NULL);
 
379
                                                        GCONF_PATH_CONNECTIONS,
 
380
                                                        (GConfClientNotifyFunc) connections_changed_cb,
 
381
                                                        self,
 
382
                                                        NULL, NULL);
376
383
}
377
384
 
378
385
static GObject *
381
388
                   GObjectConstructParam *construct_params)
382
389
{
383
390
        GObject *object;
384
 
        NMAGConfSettingsPrivate *priv;
385
391
 
386
392
        object = G_OBJECT_CLASS (nma_gconf_settings_parent_class)->constructor (type, n_construct_params, construct_params);
387
 
 
388
 
        if (!object)
389
 
                return NULL;
390
 
 
391
 
        priv = NMA_GCONF_SETTINGS_GET_PRIVATE (object);
392
 
 
393
 
        priv->read_connections_id = g_idle_add (read_connections_cb, object);
394
 
 
 
393
        if (object)
 
394
                NMA_GCONF_SETTINGS_GET_PRIVATE (object)->read_connections_id = g_idle_add (read_connections_cb, object);
395
395
        return object;
396
396
}
397
397
 
424
424
}
425
425
 
426
426
static void
427
 
nma_gconf_settings_class_init (NMAGConfSettingsClass *gconf_settings_class)
 
427
nma_gconf_settings_class_init (NMAGConfSettingsClass *class)
428
428
{
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);
431
431
 
432
 
        g_type_class_add_private (gconf_settings_class, sizeof (NMAGConfSettingsPrivate));
 
432
        g_type_class_add_private (class, sizeof (NMAGConfSettingsPrivate));
433
433
 
434
434
        /* Virtual methods */
435
435
        object_class->constructor = constructor;
436
436
        object_class->dispose = dispose;
437
437
 
438
438
        settings_class->list_connections = list_connections;
 
439
        settings_class->add_connection = add_connection;
439
440
 
440
441
        /* Signals */
441
442
        signals[NEW_SECRETS_REQUESTED] =
444
445
                                    G_SIGNAL_RUN_FIRST,
445
446
                                    G_STRUCT_OFFSET (NMAGConfSettingsClass, new_secrets_requested),
446
447
                                    NULL, NULL,
447
 
                                    nma_marshal_VOID__OBJECT_STRING_POINTER_BOOLEAN_POINTER,
448
 
                                    G_TYPE_NONE, 5,
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,
 
449
                                    G_TYPE_NONE, 6,
 
450
                                    G_TYPE_OBJECT, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN, G_TYPE_POINTER, G_TYPE_POINTER);
450
451
}