~dylanmccall/ubuntu/oneiric/network-manager-applet/lp852961-disable-autostart-for-gnome-shell

« back to all changes in this revision

Viewing changes to src/applet.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2011-05-30 13:25:18 UTC
  • mto: This revision was merged to the branch mainline in revision 68.
  • Revision ID: james.westby@ubuntu.com-20110530132518-ya5i5mcrl8szsmoj
Tags: upstream-0.8.9997+git.20110529t170033.9ec4c5d
ImportĀ upstreamĀ versionĀ 0.8.9997+git.20110529t170033.9ec4c5d

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include <unistd.h>
40
40
#include <sys/socket.h>
41
41
 
 
42
#include <dbus/dbus-glib.h>
 
43
#include <dbus/dbus-glib-lowlevel.h>
 
44
 
42
45
#include <NetworkManagerVPN.h>
43
46
#include <nm-device-ethernet.h>
44
47
#include <nm-device-wifi.h>
45
 
#include <nm-gsm-device.h>
46
 
#include <nm-cdma-device.h>
 
48
#include <nm-device-modem.h>
47
49
#include <nm-device-bt.h>
 
50
#include <nm-device-wimax.h>
48
51
#include <nm-utils.h>
49
52
#include <nm-connection.h>
50
53
#include <nm-vpn-connection.h>
51
54
#include <nm-setting-connection.h>
 
55
#include <nm-setting-wired.h>
 
56
#include <nm-setting-wireless.h>
 
57
#include <nm-setting-pppoe.h>
 
58
#include <nm-setting-gsm.h>
 
59
#include <nm-setting-cdma.h>
 
60
#include <nm-setting-bluetooth.h>
52
61
#include <nm-setting-vpn.h>
53
62
#include <nm-active-connection.h>
54
 
#include <nm-setting-wireless.h>
 
63
#include <nm-secret-agent.h>
55
64
 
56
65
#include <gconf/gconf-client.h>
57
66
#include <gnome-keyring.h>
63
72
#include "applet-device-gsm.h"
64
73
#include "applet-device-cdma.h"
65
74
#include "applet-device-bt.h"
 
75
#include "applet-device-wimax.h"
66
76
#include "applet-dialogs.h"
67
 
#include "vpn-password-dialog.h"
68
 
#include "applet-dbus-manager.h"
 
77
#include "wireless-dialog.h"
 
78
#include "applet-vpn-request.h"
69
79
#include "utils.h"
70
80
#include "gconf-helpers.h"
71
81
 
72
82
#define NOTIFY_CAPS_ACTIONS_KEY "actions"
73
83
 
 
84
extern gboolean shell_debug;
 
85
 
74
86
G_DEFINE_TYPE(NMApplet, nma, G_TYPE_OBJECT)
75
87
 
 
88
/********************************************************************/
 
89
/* Temporary dbus interface stuff */
 
90
 
 
91
static gboolean
 
92
impl_dbus_connect_to_hidden_network (NMApplet *applet, GError **error)
 
93
{
 
94
        if (!applet_wifi_connect_to_hidden_network (applet)) {
 
95
                g_set_error_literal (error,
 
96
                                     NM_SECRET_AGENT_ERROR,
 
97
                                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
98
                                     "Failed to create wireless dialog");
 
99
                return FALSE;
 
100
        }
 
101
 
 
102
        return TRUE;
 
103
}
 
104
 
 
105
static gboolean
 
106
impl_dbus_create_wifi_network (NMApplet *applet, GError **error)
 
107
{
 
108
        if (!applet_wifi_can_create_wifi_network (applet)) {
 
109
                g_set_error_literal (error,
 
110
                                     NM_SECRET_AGENT_ERROR,
 
111
                                     NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED,
 
112
                                     "Creation of wifi networks has been disabled by system policy.");
 
113
                return FALSE;
 
114
        }
 
115
 
 
116
        if (!applet_wifi_create_wifi_network (applet)) {
 
117
                g_set_error_literal (error,
 
118
                                     NM_SECRET_AGENT_ERROR,
 
119
                                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
120
                                     "Failed to create wireless dialog");
 
121
                return FALSE;
 
122
        }
 
123
 
 
124
        return TRUE;
 
125
}
 
126
 
 
127
static gboolean
 
128
impl_dbus_connect_to_8021x_network (NMApplet *applet,
 
129
                                    const char *device_path,
 
130
                                    const char *ap_path,
 
131
                                    GError **error)
 
132
{
 
133
        NMDevice *device;
 
134
        NMAccessPoint *ap;
 
135
 
 
136
        device = nm_client_get_device_by_path (applet->nm_client, device_path);
 
137
        if (!device || NM_IS_DEVICE_WIFI (device) == FALSE) {
 
138
                g_set_error_literal (error,
 
139
                                     NM_SECRET_AGENT_ERROR,
 
140
                                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
141
                                     "The device could not be found.");
 
142
                return FALSE;
 
143
        }
 
144
 
 
145
        ap = nm_device_wifi_get_access_point_by_path (NM_DEVICE_WIFI (device), ap_path);
 
146
        if (!ap) {
 
147
                g_set_error_literal (error,
 
148
                                     NM_SECRET_AGENT_ERROR,
 
149
                                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
150
                                     "The access point could not be found.");
 
151
                return FALSE;
 
152
        }
 
153
 
 
154
        /* FIXME: this doesn't account for Dynamic WEP */
 
155
        if (   !(nm_access_point_get_wpa_flags (ap) & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
 
156
            && !(nm_access_point_get_rsn_flags (ap) & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) {
 
157
                g_set_error_literal (error,
 
158
                                     NM_SECRET_AGENT_ERROR,
 
159
                                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
160
                                     "The access point had no 802.1x capabilities");
 
161
                return FALSE;
 
162
        }
 
163
 
 
164
        if (!applet_wifi_connect_to_8021x_network (applet, device, ap)) {
 
165
                g_set_error_literal (error,
 
166
                                     NM_SECRET_AGENT_ERROR,
 
167
                                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
168
                                     "Failed to create wireless dialog");
 
169
                return FALSE;
 
170
        }
 
171
 
 
172
        return TRUE;
 
173
}
 
174
 
 
175
static gboolean
 
176
impl_dbus_connect_to_3g_network (NMApplet *applet,
 
177
                                 const char *device_path,
 
178
                                 GError **error)
 
179
{
 
180
        NMDevice *device;
 
181
        NMDeviceModemCapabilities caps;
 
182
 
 
183
        device = nm_client_get_device_by_path (applet->nm_client, device_path);
 
184
        if (!device || NM_IS_DEVICE_MODEM (device) == FALSE) {
 
185
                g_set_error_literal (error,
 
186
                                     NM_SECRET_AGENT_ERROR,
 
187
                                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
188
                                     "The device could not be found.");
 
189
                return FALSE;
 
190
        }
 
191
 
 
192
        caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
 
193
        if (caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) {
 
194
                applet_gsm_connect_network (applet, device);
 
195
        } else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) {
 
196
                applet_cdma_connect_network (applet, device);
 
197
        } else {
 
198
                g_set_error_literal (error,
 
199
                                     NM_SECRET_AGENT_ERROR,
 
200
                                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
201
                                     "The device had no GSM or CDMA capabilities.");
 
202
                return FALSE;
 
203
        }
 
204
 
 
205
        return TRUE;
 
206
}
 
207
 
 
208
#include "applet-dbus-bindings.h"
 
209
 
 
210
/********************************************************************/
 
211
 
76
212
static NMActiveConnection *
77
213
applet_get_best_activating_connection (NMApplet *applet, NMDevice **device)
78
214
{
110
246
                                best_dev = candidate_dev;
111
247
                                best = candidate;
112
248
                        }
113
 
                } else if (NM_IS_CDMA_DEVICE (best_dev)) {
114
 
                        if (   NM_IS_DEVICE_ETHERNET (candidate_dev)
115
 
                            || NM_IS_DEVICE_WIFI (candidate_dev)) {
116
 
                                best_dev = candidate_dev;
117
 
                                best = candidate;
118
 
                        }
119
 
                } else if (NM_IS_GSM_DEVICE (best_dev)) {
120
 
                        if (   NM_IS_DEVICE_ETHERNET (candidate_dev)
121
 
                            || NM_IS_DEVICE_WIFI (candidate_dev)
122
 
                            || NM_IS_CDMA_DEVICE (candidate_dev)) {
123
 
                                best_dev = candidate_dev;
124
 
                                best = candidate;
 
249
                } else if (NM_IS_DEVICE_MODEM (best_dev)) {
 
250
                        NMDeviceModemCapabilities best_caps;
 
251
                        NMDeviceModemCapabilities candidate_caps = NM_DEVICE_MODEM_CAPABILITY_NONE;
 
252
 
 
253
                        best_caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (best_dev));
 
254
                        if (NM_IS_DEVICE_MODEM (candidate_dev))
 
255
                                candidate_caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (candidate_dev));
 
256
 
 
257
                        if (best_caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) {
 
258
                                if (   NM_IS_DEVICE_ETHERNET (candidate_dev)
 
259
                                    || NM_IS_DEVICE_WIFI (candidate_dev)) {
 
260
                                        best_dev = candidate_dev;
 
261
                                        best = candidate;
 
262
                                }
 
263
                        } else if (best_caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) {
 
264
                                if (   NM_IS_DEVICE_ETHERNET (candidate_dev)
 
265
                                        || NM_IS_DEVICE_WIFI (candidate_dev)
 
266
                                        || (candidate_caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)) {
 
267
                                        best_dev = candidate_dev;
 
268
                                        best = candidate;
 
269
                                }
125
270
                        }
126
271
                }
127
272
        }
175
320
        return default_ac;
176
321
}
177
322
 
178
 
NMSettingsInterface *
 
323
NMRemoteSettings *
179
324
applet_get_settings (NMApplet *applet)
180
325
{
181
 
        return NM_SETTINGS_INTERFACE (applet->gconf_settings);
 
326
        return applet->settings;
182
327
}
183
328
 
184
329
GSList *
185
330
applet_get_all_connections (NMApplet *applet)
186
331
{
187
 
        return g_slist_concat (nm_settings_interface_list_connections (NM_SETTINGS_INTERFACE (applet->system_settings)),
188
 
                               nm_settings_interface_list_connections (NM_SETTINGS_INTERFACE (applet->gconf_settings)));
 
332
        return nm_remote_settings_list_connections (applet->settings);
189
333
}
190
334
 
191
335
static NMConnection *
193
337
{
194
338
        GSList *list, *iter;
195
339
        NMConnection *connection = NULL;
196
 
        NMConnectionScope scope;
197
340
        const char *path;
198
341
 
199
 
        scope = nm_active_connection_get_scope (active);
200
 
        g_return_val_if_fail (scope != NM_CONNECTION_SCOPE_UNKNOWN, NULL);
201
 
 
202
342
        path = nm_active_connection_get_connection (active);
203
343
        g_return_val_if_fail (path != NULL, NULL);
204
344
 
206
346
        for (iter = list; iter; iter = g_slist_next (iter)) {
207
347
                NMConnection *candidate = NM_CONNECTION (iter->data);
208
348
 
209
 
                if (   (nm_connection_get_scope (candidate) == scope)
210
 
                           && !strcmp (nm_connection_get_path (candidate), path)) {
 
349
                if (!strcmp (nm_connection_get_path (candidate), path)) {
211
350
                        connection = candidate;
212
351
                        break;
213
352
                }
214
353
        }
215
 
 
216
354
        g_slist_free (list);
217
355
 
218
356
        return connection;
224
362
        const GPtrArray *active_list;
225
363
        int i;
226
364
        const char *cpath;
227
 
        NMConnectionScope scope;
228
 
 
229
 
        scope = nm_connection_get_scope (connection);
230
 
        g_return_val_if_fail (scope != NM_CONNECTION_SCOPE_UNKNOWN, NULL);
231
365
 
232
366
        cpath = nm_connection_get_path (connection);
233
367
        g_return_val_if_fail (cpath != NULL, NULL);
237
371
                NMActiveConnection *active = NM_ACTIVE_CONNECTION (g_ptr_array_index (active_list, i));
238
372
                const char *active_cpath = nm_active_connection_get_connection (active);
239
373
 
240
 
                if (   (nm_active_connection_get_scope (active) == scope)
241
 
                    && active_cpath
242
 
                    && !strcmp (active_cpath, cpath))
 
374
                if (active_cpath && !strcmp (active_cpath, cpath))
243
375
                        return active;
244
376
        }
245
377
        return NULL;
246
378
}
247
379
 
 
380
NMDevice *
 
381
applet_get_device_for_connection (NMApplet *applet, NMConnection *connection)
 
382
{
 
383
        const GPtrArray *active_list;
 
384
        const char *cpath;
 
385
        int i;
 
386
 
 
387
        cpath = nm_connection_get_path (connection);
 
388
        g_return_val_if_fail (cpath != NULL, NULL);
 
389
 
 
390
        active_list = nm_client_get_active_connections (applet->nm_client);
 
391
        for (i = 0; active_list && (i < active_list->len); i++) {
 
392
                NMActiveConnection *active = NM_ACTIVE_CONNECTION (g_ptr_array_index (active_list, i));
 
393
 
 
394
                if (!g_strcmp0 (nm_active_connection_get_connection (active), cpath))
 
395
                        return g_ptr_array_index (nm_active_connection_get_devices (active), 0);
 
396
        }
 
397
        return NULL;
 
398
}
 
399
 
248
400
static inline NMADeviceClass *
249
401
get_device_class (NMDevice *device, NMApplet *applet)
250
402
{
255
407
                return applet->wired_class;
256
408
        else if (NM_IS_DEVICE_WIFI (device))
257
409
                return applet->wifi_class;
258
 
        else if (NM_IS_GSM_DEVICE (device))
 
410
        else if (NM_IS_DEVICE_MODEM (device)) {
 
411
                NMDeviceModemCapabilities caps;
 
412
 
 
413
                caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
 
414
                if (caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
 
415
                        return applet->gsm_class;
 
416
                else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
 
417
                        return applet->cdma_class;
 
418
                else
 
419
                        g_message ("%s: unhandled modem capabilities 0x%X", __func__, caps);
 
420
        } else if (NM_IS_DEVICE_BT (device))
 
421
                return applet->bt_class;
 
422
        else if (NM_IS_DEVICE_WIMAX (device))
 
423
                return applet->wimax_class;
 
424
        else
 
425
                g_message ("%s: Unknown device type '%s'", __func__, G_OBJECT_TYPE_NAME (device));
 
426
        return NULL;
 
427
}
 
428
 
 
429
static inline NMADeviceClass *
 
430
get_device_class_from_connection (NMConnection *connection, NMApplet *applet)
 
431
{
 
432
        NMSettingConnection *s_con;
 
433
        const char *ctype;
 
434
 
 
435
        g_return_val_if_fail (connection != NULL, NULL);
 
436
        g_return_val_if_fail (applet != NULL, NULL);
 
437
 
 
438
        s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
 
439
        g_return_val_if_fail (s_con != NULL, NULL);
 
440
 
 
441
        ctype = nm_setting_connection_get_connection_type (s_con);
 
442
        g_return_val_if_fail (ctype != NULL, NULL);
 
443
 
 
444
        if (!strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME) || !strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME))
 
445
                return applet->wired_class;
 
446
        else if (!strcmp (ctype, NM_SETTING_WIRELESS_SETTING_NAME))
 
447
                return applet->wifi_class;
 
448
        else if (!strcmp (ctype, NM_SETTING_GSM_SETTING_NAME))
259
449
                return applet->gsm_class;
260
 
        else if (NM_IS_CDMA_DEVICE (device))
 
450
        else if (!strcmp (ctype, NM_SETTING_CDMA_SETTING_NAME))
261
451
                return applet->cdma_class;
262
 
        else if (NM_IS_DEVICE_BT (device))
 
452
        else if (!strcmp (ctype, NM_SETTING_BLUETOOTH_SETTING_NAME))
263
453
                return applet->bt_class;
264
454
        else
265
 
                g_message ("%s: Unknown device type '%s'", __func__, G_OBJECT_TYPE_NAME (device));
 
455
                g_warning ("%s: unhandled connection type '%s'", __func__, ctype);
266
456
        return NULL;
267
457
}
268
458
 
269
 
static gboolean
270
 
is_system_connection (NMConnection *connection)
271
 
{
272
 
        return (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) ? TRUE : FALSE;
273
 
}
274
 
 
275
 
static void
276
 
activate_connection_cb (gpointer user_data, const char *path, GError *error)
277
 
{
278
 
        if (error)
279
 
                nm_warning ("Connection activation failed: %s", error->message);
280
 
 
281
 
        applet_schedule_update_icon (NM_APPLET (user_data));
282
 
}
283
 
 
284
459
typedef struct {
285
460
        NMApplet *applet;
286
461
        NMDevice *device;
287
462
        char *specific_object;
288
 
        gpointer dclass_data;
 
463
        NMConnection *connection;
289
464
} AppletItemActivateInfo;
290
465
 
291
466
static void
296
471
        if (info->device)
297
472
                g_object_unref (info->device);
298
473
        g_free (info->specific_object);
 
474
        if (info->connection)
 
475
                g_object_unref (info->connection);
299
476
        memset (info, 0, sizeof (AppletItemActivateInfo));
300
477
        g_free (info);
301
478
}
302
479
 
303
480
static void
304
 
applet_menu_item_activate_helper_part2 (NMConnection *connection,
305
 
                                        gboolean auto_created,
306
 
                                        gboolean canceled,
307
 
                                        gpointer user_data)
 
481
add_and_activate_cb (NMClient *client,
 
482
                     NMActiveConnection *active,
 
483
                     const char *connection_path,
 
484
                     GError *error,
 
485
                     gpointer user_data)
 
486
{
 
487
        if (error)
 
488
                g_warning ("Failed to add/activate connection: (%d) %s", error->code, error->message);
 
489
 
 
490
        applet_schedule_update_icon (NM_APPLET (user_data));
 
491
}
 
492
 
 
493
static void
 
494
applet_menu_item_activate_helper_new_connection (NMConnection *connection,
 
495
                                                 gboolean auto_created,
 
496
                                                 gboolean canceled,
 
497
                                                 gpointer user_data)
308
498
{
309
499
        AppletItemActivateInfo *info = user_data;
310
 
        const char *con_path;
311
 
        gboolean is_system = FALSE;
312
500
 
313
501
        if (canceled) {
314
502
                applet_item_activate_info_destroy (info);
317
505
 
318
506
        g_return_if_fail (connection != NULL);
319
507
 
320
 
        if (!auto_created)
321
 
                is_system = is_system_connection (connection);
322
 
        else {
323
 
                NMAGConfConnection *exported;
324
 
 
325
 
                exported = nma_gconf_settings_add_connection (info->applet->gconf_settings, connection);
326
 
                if (!exported) {
327
 
                        NMADeviceClass *dclass = get_device_class (info->device, info->applet);
328
 
 
329
 
                        /* If the setting isn't valid, because it needs more authentication
330
 
                         * or something, ask the user for it.
331
 
                         */
332
 
 
333
 
                        g_assert (dclass);
334
 
                        nm_warning ("Invalid connection; asking for more information.");
335
 
                        if (dclass->get_more_info)
336
 
                                dclass->get_more_info (info->device, connection, info->applet, info->dclass_data);
337
 
                        g_object_unref (connection);
338
 
 
339
 
                        applet_item_activate_info_destroy (info);
340
 
                        return;
341
 
                }
342
 
                g_object_unref (connection);
343
 
                connection = NM_CONNECTION (exported);
344
 
        }
345
 
 
346
 
        g_assert (connection);
347
 
        con_path = nm_connection_get_path (connection);
348
 
        g_assert (con_path);
349
 
 
350
 
        /* Finally, tell NM to activate the connection */
351
 
        nm_client_activate_connection (info->applet->nm_client,
352
 
                                       is_system ? NM_DBUS_SERVICE_SYSTEM_SETTINGS : NM_DBUS_SERVICE_USER_SETTINGS,
353
 
                                       con_path,
354
 
                                       info->device,
355
 
                                       info->specific_object,
356
 
                                       activate_connection_cb,
357
 
                                       info->applet);
 
508
        /* Ask NM to add the new connection and activate it; NM will fill in the
 
509
         * missing details based on the specific object and the device.
 
510
         */
 
511
        nm_client_add_and_activate_connection (info->applet->nm_client,
 
512
                                               connection,
 
513
                                               info->device,
 
514
                                               info->specific_object,
 
515
                                               add_and_activate_cb,
 
516
                                               info->applet);
 
517
 
358
518
        applet_item_activate_info_destroy (info);
359
519
}
360
520
 
378
538
        nm_device_disconnect (device, disconnect_cb, NULL);
379
539
}
380
540
 
 
541
static void
 
542
activate_connection_cb (NMClient *client,
 
543
                        NMActiveConnection *active,
 
544
                        GError *error,
 
545
                        gpointer user_data)
 
546
{
 
547
        if (error)
 
548
                g_warning ("Connection activation failed: %s", error->message);
 
549
 
 
550
        applet_schedule_update_icon (NM_APPLET (user_data));
 
551
}
381
552
 
382
553
void
383
554
applet_menu_item_activate_helper (NMDevice *device,
391
562
 
392
563
        g_return_if_fail (NM_IS_DEVICE (device));
393
564
 
 
565
        if (connection) {
 
566
                /* If the menu item had an associated connection already, just tell
 
567
                 * NM to activate that connection.
 
568
                 */
 
569
                nm_client_activate_connection (applet->nm_client,
 
570
                                                   connection,
 
571
                                                   device,
 
572
                                                   specific_object,
 
573
                                                   activate_connection_cb,
 
574
                                                   applet);
 
575
                return;
 
576
        }
 
577
 
 
578
        /* If no connection was given, ask the device class to create a new
 
579
         * default connection for this device type.  This could be a wizard,
 
580
         * and thus take a while.
 
581
         */
 
582
 
394
583
        info = g_malloc0 (sizeof (AppletItemActivateInfo));
395
584
        info->applet = applet;
396
585
        info->specific_object = g_strdup (specific_object);
397
586
        info->device = g_object_ref (device);
398
 
        info->dclass_data = dclass_data;
399
 
 
400
 
        if (connection) {
401
 
                applet_menu_item_activate_helper_part2 (connection, FALSE, FALSE, info);
402
 
                return;
403
 
        }
404
587
 
405
588
        dclass = get_device_class (device, applet);
406
 
 
407
 
        /* If no connection was passed in, ask the device class to create a new
408
 
         * default connection for this device type.  This could be a wizard,
409
 
         * and thus take a while.
410
 
         */
411
589
        g_assert (dclass);
412
590
        if (!dclass->new_auto_connection (device, dclass_data,
413
 
                                          applet_menu_item_activate_helper_part2,
 
591
                                          applet_menu_item_activate_helper_new_connection,
414
592
                                          info)) {
415
 
                nm_warning ("Couldn't create default connection.");
 
593
                g_warning ("Couldn't create default connection.");
416
594
                applet_item_activate_info_destroy (info);
417
595
        }
418
596
}
478
656
#define TITLE_TEXT_G ((double) 0x5e / 255.0 )
479
657
#define TITLE_TEXT_B ((double) 0x5e / 255.0 )
480
658
 
481
 
static gboolean
482
 
menu_title_item_expose (GtkWidget *widget, GdkEventExpose *event)
 
659
static void
 
660
menu_item_draw_generic (GtkWidget *widget, cairo_t *cr)
483
661
{
484
 
        GtkAllocation allocation;
485
 
        GtkStyle *style;
486
662
        GtkWidget *label;
487
663
        PangoFontDescription *desc;
488
 
        cairo_t *cr;
489
664
        PangoLayout *layout;
490
665
        int width = 0, height = 0, owidth, oheight;
491
666
        gdouble extraheight = 0, extrawidth = 0;
495
670
        gdouble postpadding = 0.0;
496
671
 
497
672
        label = gtk_bin_get_child (GTK_BIN (widget));
498
 
 
499
 
        cr = gdk_cairo_create (gtk_widget_get_window (widget));
500
 
 
501
 
        /* The drawing area we get is the whole menu; clip the drawing to the
502
 
         * event area, which should just be our menu item.
503
 
         */
504
 
        cairo_rectangle (cr,
505
 
                         event->area.x, event->area.y,
506
 
                         event->area.width, event->area.height);
507
 
        cairo_clip (cr);
508
 
 
509
 
        /* We also need to reposition the cairo context so that (0, 0) is the
510
 
         * top-left of where we're supposed to start drawing.
511
 
         */
512
 
#if GTK_CHECK_VERSION(2,18,0)
513
 
        gtk_widget_get_allocation (widget, &allocation);
514
 
#else
515
 
        allocation = widget->allocation;
516
 
#endif
517
 
        cairo_translate (cr, widget->allocation.x, widget->allocation.y);
518
 
 
519
673
        text = gtk_label_get_text (GTK_LABEL (label));
520
674
 
521
675
        layout = pango_cairo_create_layout (cr);
522
 
        style = gtk_widget_get_style (widget);
523
 
        desc = pango_font_description_copy (style->font_desc);
 
676
#if GTK_CHECK_VERSION(2,20,0) && !GTK_CHECK_VERSION(2,91,6)
 
677
        {
 
678
                GtkStyle *style;
 
679
                style = gtk_widget_get_style (widget);
 
680
                desc = pango_font_description_copy (style->font_desc);
 
681
        }
 
682
#else
 
683
        {
 
684
                GtkStyleContext *style;
 
685
                style = gtk_widget_get_style_context (widget);
 
686
                gtk_style_context_get (style, gtk_style_context_get_state (style),
 
687
                                       "font", &desc,
 
688
                                       NULL);
 
689
        }
 
690
#endif
524
691
        pango_font_description_set_variant (desc, PANGO_VARIANT_SMALL_CAPS);
525
692
        pango_font_description_set_weight (desc, PANGO_WEIGHT_SEMIBOLD);
526
693
        pango_layout_set_font_description (layout, desc);
548
715
 
549
716
        pango_font_description_free (desc);
550
717
        g_object_unref (layout);
 
718
 
 
719
        gtk_widget_set_size_request (widget, width + 2 * xpadding, height + ypadding + postpadding);
 
720
}
 
721
 
 
722
#if GTK_CHECK_VERSION(2,90,7)
 
723
static gboolean
 
724
menu_title_item_draw (GtkWidget *widget, cairo_t *cr, gpointer user_data)
 
725
{
 
726
        menu_item_draw_generic (widget, cr);
 
727
        return TRUE;
 
728
}
 
729
#else
 
730
static gboolean
 
731
menu_title_item_expose (GtkWidget *widget, GdkEventExpose *event)
 
732
{
 
733
        GtkAllocation allocation;
 
734
        cairo_t *cr;
 
735
 
 
736
        cr = gdk_cairo_create (gtk_widget_get_window (widget));
 
737
 
 
738
        /* The drawing area we get is the whole menu; clip the drawing to the
 
739
         * event area, which should just be our menu item.
 
740
         */
 
741
        cairo_rectangle (cr,
 
742
                         event->area.x, event->area.y,
 
743
                         event->area.width, event->area.height);
 
744
        cairo_clip (cr);
 
745
 
 
746
        /* We also need to reposition the cairo context so that (0, 0) is the
 
747
         * top-left of where we're supposed to start drawing.
 
748
         */
 
749
        gtk_widget_get_allocation (widget, &allocation);
 
750
        cairo_translate (cr, allocation.x, allocation.y);
 
751
 
 
752
        menu_item_draw_generic (widget, cr);
 
753
 
551
754
        cairo_destroy (cr);
552
 
 
553
 
        gtk_widget_set_size_request (widget, width + 2 * xpadding, height + ypadding + postpadding);
554
755
        return TRUE;
555
756
}
556
 
 
 
757
#endif
557
758
 
558
759
GtkWidget *
559
760
applet_menu_item_create_device_item_helper (NMDevice *device,
564
765
 
565
766
        item = gtk_menu_item_new_with_mnemonic (text);
566
767
        gtk_widget_set_sensitive (item, FALSE);
 
768
#if GTK_CHECK_VERSION(2,90,7)
 
769
        g_signal_connect (item, "draw", G_CALLBACK (menu_title_item_draw), NULL);
 
770
#else
567
771
        g_signal_connect (item, "expose-event", G_CALLBACK (menu_title_item_expose), NULL);
 
772
#endif
568
773
        return item;
569
774
}
570
775
 
754
959
        return FALSE;
755
960
}
756
961
 
757
 
static void
758
 
update_connection_timestamp (NMActiveConnection *active,
759
 
                             NMConnection *connection,
760
 
                             NMApplet *applet)
761
 
{
762
 
        NMSettingsConnectionInterface *gconf_connection;
763
 
        NMSettingConnection *s_con;
764
 
 
765
 
        if (nm_active_connection_get_scope (active) != NM_CONNECTION_SCOPE_USER)
766
 
                return;
767
 
 
768
 
        gconf_connection = nm_settings_interface_get_connection_by_path (NM_SETTINGS_INTERFACE (applet->gconf_settings),
769
 
                                                                         nm_connection_get_path (connection));
770
 
        if (!gconf_connection || !NMA_IS_GCONF_CONNECTION (gconf_connection))
771
 
                return;
772
 
 
773
 
        s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
774
 
        g_assert (s_con);
775
 
 
776
 
        g_object_set (s_con, NM_SETTING_CONNECTION_TIMESTAMP, (guint64) time (NULL), NULL);
777
 
        /* Ignore secrets since we're just updating the timestamp */
778
 
        nma_gconf_connection_update (NMA_GCONF_CONNECTION (gconf_connection), TRUE);
779
 
}
780
 
 
781
962
static char *
782
963
make_vpn_failure_message (NMVPNConnection *vpn,
783
964
                          NMVPNConnectionStateReason reason,
858
1039
                              gpointer user_data)
859
1040
{
860
1041
        NMApplet *applet = NM_APPLET (user_data);
861
 
        NMConnection *connection;
862
1042
        const char *banner;
863
1043
        char *title = NULL, *msg;
864
1044
        gboolean device_activating, vpn_activating;
887
1067
                applet_do_notify_with_pref (applet, title, msg, "gnome-lockscreen",
888
1068
                                            PREF_DISABLE_VPN_NOTIFICATIONS);
889
1069
                g_free (msg);
890
 
 
891
 
                connection = applet_get_connection_for_active (applet, NM_ACTIVE_CONNECTION (vpn));
892
 
                if (connection)
893
 
                        update_connection_timestamp (NM_ACTIVE_CONNECTION (vpn), connection, applet);
894
1070
                break;
895
1071
        case NM_VPN_CONNECTION_STATE_FAILED:
896
1072
                title = _("VPN Connection Failed");
940
1116
} VPNActivateInfo;
941
1117
 
942
1118
static void
943
 
activate_vpn_cb (gpointer user_data, const char *path, GError *error)
 
1119
activate_vpn_cb (NMClient *client,
 
1120
                 NMActiveConnection *active,
 
1121
                 GError *error,
 
1122
                 gpointer user_data)
944
1123
{
945
1124
        VPNActivateInfo *info = (VPNActivateInfo *) user_data;
946
1125
        char *title, *msg, *name;
966
1145
                                            PREF_DISABLE_VPN_NOTIFICATIONS);
967
1146
                g_free (msg);
968
1147
 
969
 
                nm_warning ("VPN Connection activation failed: (%s) %s", name, error->message);
 
1148
                g_warning ("VPN Connection activation failed: (%s) %s", name, error->message);
970
1149
        }
971
1150
 
972
1151
        applet_schedule_update_icon (info->applet);
983
1162
        NMSettingConnection *s_con;
984
1163
        NMActiveConnection *active;
985
1164
        NMDevice *device = NULL;
986
 
        gboolean is_system;
987
1165
 
988
1166
        active = applet_get_default_active_connection (applet, &device);
989
1167
        if (!active || !device) {
1007
1185
        info->vpn_name = g_strdup (nm_setting_connection_get_id (s_con));
1008
1186
 
1009
1187
        /* Connection inactive, activate */
1010
 
        is_system = is_system_connection (connection);
1011
1188
        nm_client_activate_connection (applet->nm_client,
1012
 
                                       is_system ? NM_DBUS_SERVICE_SYSTEM_SETTINGS : NM_DBUS_SERVICE_USER_SETTINGS,
1013
 
                                       nm_connection_get_path (connection),
 
1189
                                       connection,
1014
1190
                                       device,
1015
1191
                                       nm_object_get_path (NM_OBJECT (active)),
1016
1192
                                       activate_vpn_cb,
1130
1306
{
1131
1307
        NMDevice *aa = NM_DEVICE (a);
1132
1308
        NMDevice *bb = NM_DEVICE (b);
1133
 
        GType aa_type;
1134
 
        GType bb_type;
1135
 
 
1136
 
        aa_type = G_OBJECT_TYPE (G_OBJECT (aa));
1137
 
        bb_type = G_OBJECT_TYPE (G_OBJECT (bb));
 
1309
        GType aa_type = G_OBJECT_TYPE (G_OBJECT (aa));
 
1310
        GType bb_type = G_OBJECT_TYPE (G_OBJECT (bb));
1138
1311
 
1139
1312
        if (aa_type == bb_type) {
1140
1313
                char *aa_desc = NULL;
1148
1321
                if (!bb_desc)
1149
1322
                        bb_desc = (char *) nm_device_get_iface (bb);
1150
1323
 
1151
 
                if (!aa_desc && bb_desc)
1152
 
                        return -1;
1153
 
                else if (aa_desc && !bb_desc)
1154
 
                        return 1;
1155
 
                else if (!aa_desc && !bb_desc)
1156
 
                        return 0;
1157
 
 
1158
 
                g_assert (aa_desc);
1159
 
                g_assert (bb_desc);
1160
 
                return strcmp (aa_desc, bb_desc);
 
1324
                return g_strcmp0 (aa_desc, bb_desc);
1161
1325
        }
1162
1326
 
1163
 
        if (aa_type == NM_TYPE_DEVICE_ETHERNET && bb_type == NM_TYPE_DEVICE_WIFI)
1164
 
                return -1;
1165
 
        if (aa_type == NM_TYPE_DEVICE_ETHERNET && bb_type == NM_TYPE_GSM_DEVICE)
1166
 
                return -1;
1167
 
        if (aa_type == NM_TYPE_DEVICE_ETHERNET && bb_type == NM_TYPE_CDMA_DEVICE)
1168
 
                return -1;
1169
 
        if (aa_type == NM_TYPE_DEVICE_ETHERNET && bb_type == NM_TYPE_DEVICE_BT)
1170
 
                return -1;
1171
 
 
1172
 
        if (aa_type == NM_TYPE_GSM_DEVICE && bb_type == NM_TYPE_CDMA_DEVICE)
1173
 
                return -1;
1174
 
        if (aa_type == NM_TYPE_GSM_DEVICE && bb_type == NM_TYPE_DEVICE_WIFI)
1175
 
                return -1;
1176
 
        if (aa_type == NM_TYPE_GSM_DEVICE && bb_type == NM_TYPE_DEVICE_BT)
1177
 
                return -1;
1178
 
 
1179
 
        if (aa_type == NM_TYPE_CDMA_DEVICE && bb_type == NM_TYPE_DEVICE_WIFI)
1180
 
                return -1;
1181
 
        if (aa_type == NM_TYPE_CDMA_DEVICE && bb_type == NM_TYPE_DEVICE_BT)
1182
 
                return -1;
1183
 
 
1184
 
        if (aa_type == NM_TYPE_DEVICE_BT && bb_type == NM_TYPE_DEVICE_WIFI)
1185
 
                return -1;
1186
 
 
 
1327
        /* Ethernet always first */
 
1328
        if (aa_type == NM_TYPE_DEVICE_ETHERNET)
 
1329
                return -1;
 
1330
        if (bb_type == NM_TYPE_DEVICE_ETHERNET)
 
1331
                return 1;
 
1332
 
 
1333
        /* Modems next */
 
1334
        if (aa_type == NM_TYPE_DEVICE_MODEM)
 
1335
                return -1;
 
1336
        if (bb_type == NM_TYPE_DEVICE_MODEM)
 
1337
                return 1;
 
1338
 
 
1339
        /* Bluetooth next */
 
1340
        if (aa_type == NM_TYPE_DEVICE_BT)
 
1341
                return -1;
 
1342
        if (bb_type == NM_TYPE_DEVICE_BT)
 
1343
                return 1;
 
1344
 
 
1345
        /* WiMAX next */
 
1346
        if (aa_type == NM_TYPE_DEVICE_WIMAX)
 
1347
                return -1;
 
1348
        if (bb_type == NM_TYPE_DEVICE_WIMAX)
 
1349
                return 1;
 
1350
 
 
1351
        /* WiFi last because it has many menu items */
1187
1352
        return 1;
1188
1353
}
1189
1354
 
1215
1380
 
1216
1381
        active_connections = nm_client_get_active_connections (applet->nm_client);
1217
1382
        for (i = 0; active_connections && (i < active_connections->len); i++) {
1218
 
                NMSettingsConnectionInterface *tmp;
1219
 
                NMSettingsInterface *settings = NULL;
 
1383
                NMRemoteConnection *tmp;
1220
1384
                NMActiveConnection *active;
1221
 
                const char *service_name;
1222
1385
                const char *connection_path;
1223
1386
                const GPtrArray *devices;
1224
1387
 
1225
1388
                active = NM_ACTIVE_CONNECTION (g_ptr_array_index (active_connections, i));
1226
1389
                devices = nm_active_connection_get_devices (active);
1227
 
                service_name = nm_active_connection_get_service_name (active);
1228
1390
                connection_path = nm_active_connection_get_connection (active);
1229
1391
 
1230
 
                if (!devices || !service_name || !connection_path)
 
1392
                if (!devices || !connection_path)
1231
1393
                        continue;
1232
1394
 
1233
1395
                if (!nm_g_ptr_array_contains (devices, device))
1234
1396
                        continue;
1235
1397
 
1236
 
                if (!strcmp (service_name, NM_DBUS_SERVICE_SYSTEM_SETTINGS))
1237
 
                        settings = NM_SETTINGS_INTERFACE (applet->system_settings);
1238
 
                else if (!strcmp (service_name, NM_DBUS_SERVICE_USER_SETTINGS))
1239
 
                        settings = NM_SETTINGS_INTERFACE (applet->gconf_settings);
1240
 
                else
1241
 
                        g_assert_not_reached ();
1242
 
 
1243
 
                tmp = nm_settings_interface_get_connection_by_path (settings, connection_path);
 
1398
                tmp = nm_remote_settings_get_connection_by_path (applet->settings, connection_path);
1244
1399
                if (tmp) {
1245
1400
                        connection = NM_CONNECTION (tmp);
1246
1401
                        if (out_active)
1365
1520
 
1366
1521
        temp = nm_client_get_devices (applet->nm_client);
1367
1522
        for (i = 0; temp && (i < temp->len); i++)
1368
 
                devices = g_slist_append (devices, g_ptr_array_index (temp, i));
1369
 
        if (devices)
1370
 
                devices = g_slist_sort (devices, sort_devices);
 
1523
                devices = g_slist_insert_sorted (devices, g_ptr_array_index (temp, i), sort_devices);
1371
1524
 
1372
1525
        for (iter = devices; iter; iter = iter->next) {
1373
1526
                NMDevice *device = NM_DEVICE (iter->data);
1383
1536
                                n_usable_wifi_devices++;
1384
1537
                } else if (NM_IS_DEVICE_ETHERNET (device))
1385
1538
                        n_wired_devices++;
1386
 
                else if (NM_IS_CDMA_DEVICE (device) || NM_IS_GSM_DEVICE (device))
 
1539
                else if (NM_IS_DEVICE_MODEM (device))
1387
1540
                        n_mb_devices++;
1388
1541
                else if (NM_IS_DEVICE_BT (device))
1389
1542
                        n_bt_devices++;
1409
1562
                        n_devices = n_wifi_devices;
1410
1563
                else if (NM_IS_DEVICE_ETHERNET (device))
1411
1564
                        n_devices = n_wired_devices;
1412
 
                else if (NM_IS_CDMA_DEVICE (device) || NM_IS_GSM_DEVICE (device))
 
1565
                else if (NM_IS_DEVICE_MODEM (device))
1413
1566
                        n_devices = n_mb_devices;
1414
1567
 
1415
1568
                active = applet_find_active_connection_for_device (device, applet, NULL);
1495
1648
                NMActiveConnection *active;
1496
1649
                const char *name;
1497
1650
                GtkWidget *image;
 
1651
                NMState state;
1498
1652
 
1499
1653
                name = get_connection_id (connection);
1500
1654
 
1507
1661
                 */
1508
1662
                active = applet_get_active_for_connection (applet, connection);
1509
1663
 
1510
 
                if (nm_client_get_state (applet->nm_client) != NM_STATE_CONNECTED)
 
1664
                state = nm_client_get_state (applet->nm_client);
 
1665
                if (   state != NM_STATE_CONNECTED_LOCAL
 
1666
                    && state != NM_STATE_CONNECTED_SITE
 
1667
                    && state != NM_STATE_CONNECTED_GLOBAL)
1511
1668
                        gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
1512
1669
                else if ((num_vpn_active == 0) || active)
1513
1670
                        gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
1568
1725
}
1569
1726
 
1570
1727
static void
 
1728
nma_set_wimax_enabled_cb (GtkWidget *widget, NMApplet *applet)
 
1729
{
 
1730
        gboolean state;
 
1731
 
 
1732
        g_return_if_fail (applet != NULL);
 
1733
 
 
1734
        state = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget));
 
1735
        nm_client_wimax_set_enabled (applet->nm_client, state);
 
1736
}
 
1737
 
 
1738
static void
1571
1739
nma_set_networking_enabled_cb (GtkWidget *widget, NMApplet *applet)
1572
1740
{
1573
1741
        gboolean state;
1619
1787
        g_return_if_fail (menu != NULL);
1620
1788
        g_return_if_fail (applet != NULL);
1621
1789
 
1622
 
#if GTK_CHECK_VERSION(2, 15, 0)
1623
1790
        gtk_status_icon_set_tooltip_text (applet->status_icon, NULL);
1624
 
#else
1625
 
        gtk_status_icon_set_tooltip (applet->status_icon, NULL);
1626
 
#endif
1627
1791
 
1628
1792
        if (!nm_client_get_manager_running (applet->nm_client)) {
1629
1793
                nma_menu_add_text_item (menu, _("NetworkManager is not running..."));
1651
1815
//      nmi_dbus_signal_user_interface_activated (applet->connection);
1652
1816
}
1653
1817
 
1654
 
static gboolean nma_menu_clear (NMApplet *applet);
 
1818
static gboolean
 
1819
destroy_old_menu (gpointer user_data)
 
1820
{
 
1821
        g_object_unref (user_data);
 
1822
        return FALSE;
 
1823
}
1655
1824
 
1656
1825
static void
1657
1826
nma_menu_deactivate_cb (GtkWidget *widget, NMApplet *applet)
1660
1829
         * the menu items don't get destroyed before any 'activate' signal
1661
1830
         * fires for an item.
1662
1831
         */
1663
 
        g_idle_add_full (G_PRIORITY_LOW, (GSourceFunc) nma_menu_clear, applet, NULL);
 
1832
        g_signal_handlers_disconnect_by_func (applet->menu, G_CALLBACK (nma_menu_deactivate_cb), applet);
 
1833
        g_idle_add_full (G_PRIORITY_LOW, destroy_old_menu, applet->menu, NULL);
 
1834
        applet->menu = NULL;
1664
1835
 
1665
1836
        /* Re-set the tooltip */
1666
 
#if GTK_CHECK_VERSION(2, 15, 0)
1667
1837
        gtk_status_icon_set_tooltip_text (applet->status_icon, applet->tip);
1668
 
#else
1669
 
        gtk_status_icon_set_tooltip (applet->status_icon, applet->tip);
1670
 
#endif
1671
 
}
1672
 
 
1673
 
/*
1674
 
 * nma_menu_create
1675
 
 *
1676
 
 * Create the applet's dropdown menu
1677
 
 *
1678
 
 */
1679
 
static GtkWidget *
1680
 
nma_menu_create (NMApplet *applet)
1681
 
{
1682
 
        GtkWidget       *menu;
1683
 
 
1684
 
        g_return_val_if_fail (applet != NULL, NULL);
1685
 
 
1686
 
        menu = gtk_menu_new ();
1687
 
        gtk_container_set_border_width (GTK_CONTAINER (menu), 0);
1688
 
        g_signal_connect (menu, "show", G_CALLBACK (nma_menu_show_cb), applet);
1689
 
        g_signal_connect (menu, "deactivate", G_CALLBACK (nma_menu_deactivate_cb), applet);
1690
 
        return menu;
1691
 
}
1692
 
 
1693
 
/*
1694
 
 * nma_menu_clear
1695
 
 *
1696
 
 * Destroy the menu and each of its items data tags
1697
 
 *
1698
 
 */
1699
 
static gboolean nma_menu_clear (NMApplet *applet)
1700
 
{
1701
 
        g_return_val_if_fail (applet != NULL, FALSE);
1702
 
 
1703
 
        if (applet->menu)
1704
 
                gtk_widget_destroy (applet->menu);
1705
 
        applet->menu = nma_menu_create (applet);
1706
 
        return FALSE;
1707
1838
}
1708
1839
 
1709
1840
static gboolean
1726
1857
        gboolean net_enabled = TRUE;
1727
1858
        gboolean have_wireless = FALSE;
1728
1859
        gboolean have_wwan = FALSE;
 
1860
        gboolean have_wimax = FALSE;
1729
1861
        gboolean wireless_hw_enabled;
1730
1862
        gboolean wwan_hw_enabled;
 
1863
        gboolean wimax_hw_enabled;
1731
1864
        gboolean notifications_enabled = TRUE;
 
1865
        gboolean sensitive = FALSE;
1732
1866
 
1733
1867
        state = nm_client_get_state (applet->nm_client);
1734
 
 
1735
 
        gtk_widget_set_sensitive (applet->info_menu_item, state == NM_STATE_CONNECTED);
 
1868
        sensitive = (   state == NM_STATE_CONNECTED_LOCAL
 
1869
                     || state == NM_STATE_CONNECTED_SITE
 
1870
                     || state == NM_STATE_CONNECTED_GLOBAL);
 
1871
        gtk_widget_set_sensitive (applet->info_menu_item, sensitive);
1736
1872
 
1737
1873
        /* Update checkboxes, and block 'toggled' signal when updating so that the
1738
1874
         * callback doesn't get triggered.
1773
1909
        gtk_widget_set_sensitive (GTK_WIDGET (applet->wwan_enabled_item),
1774
1910
                                  wwan_hw_enabled && is_permission_yes (applet, NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN));
1775
1911
 
 
1912
        /* Enable WiMAX */
 
1913
        g_signal_handler_block (G_OBJECT (applet->wimax_enabled_item),
 
1914
                                applet->wimax_enabled_toggled_id);
 
1915
        gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (applet->wimax_enabled_item),
 
1916
                                        nm_client_wimax_get_enabled (applet->nm_client));
 
1917
        g_signal_handler_unblock (G_OBJECT (applet->wimax_enabled_item),
 
1918
                                  applet->wimax_enabled_toggled_id);
 
1919
 
 
1920
        wimax_hw_enabled = nm_client_wimax_hardware_get_enabled (applet->nm_client);
 
1921
        gtk_widget_set_sensitive (GTK_WIDGET (applet->wimax_enabled_item),
 
1922
                                  wimax_hw_enabled && is_permission_yes (applet, NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX));
 
1923
 
1776
1924
        /* Enabled notifications */
1777
1925
        g_signal_handler_block (G_OBJECT (applet->notifications_enabled_item),
1778
1926
                                applet->notifications_enabled_toggled_id);
1796
1944
 
1797
1945
                        if (NM_IS_DEVICE_WIFI (candidate))
1798
1946
                                have_wireless = TRUE;
1799
 
                        else if (NM_IS_SERIAL_DEVICE (candidate))
 
1947
                        else if (NM_IS_DEVICE_MODEM (candidate))
1800
1948
                                have_wwan = TRUE;
 
1949
                        else if (NM_IS_DEVICE_WIMAX (candidate))
 
1950
                                have_wimax = TRUE;
1801
1951
                }
1802
1952
        }
1803
1953
 
1810
1960
                gtk_widget_show_all (applet->wwan_enabled_item);
1811
1961
        else
1812
1962
                gtk_widget_hide (applet->wwan_enabled_item);
 
1963
 
 
1964
        if (have_wimax)
 
1965
                gtk_widget_show_all (applet->wimax_enabled_item);
 
1966
        else
 
1967
                gtk_widget_hide (applet->wimax_enabled_item);
1813
1968
}
1814
1969
 
1815
1970
static void
1887
2042
        applet->wwan_enabled_toggled_id = id;
1888
2043
        gtk_menu_shell_append (menu, applet->wwan_enabled_item);
1889
2044
 
 
2045
        /* 'Enable WiMAX Mobile Broadband' item */
 
2046
        applet->wimax_enabled_item = gtk_check_menu_item_new_with_mnemonic (_("Enable WiMA_X Mobile Broadband"));
 
2047
        id = g_signal_connect (applet->wimax_enabled_item,
 
2048
                               "toggled",
 
2049
                               G_CALLBACK (nma_set_wimax_enabled_cb),
 
2050
                               applet);
 
2051
        applet->wimax_enabled_toggled_id = id;
 
2052
        gtk_menu_shell_append (menu, applet->wimax_enabled_item);
 
2053
 
1890
2054
        nma_menu_add_separator_item (GTK_WIDGET (menu));
1891
2055
 
1892
2056
        /* Toggle notifications item */
1994
2158
}
1995
2159
 
1996
2160
 
1997
 
NMSettingsConnectionInterface *
 
2161
NMRemoteConnection *
1998
2162
applet_get_exported_connection_for_device (NMDevice *device, NMApplet *applet)
1999
2163
{
2000
2164
        const GPtrArray *active_connections;
2003
2167
        active_connections = nm_client_get_active_connections (applet->nm_client);
2004
2168
        for (i = 0; active_connections && (i < active_connections->len); i++) {
2005
2169
                NMActiveConnection *active;
2006
 
                NMSettingsConnectionInterface *connection;
2007
 
                const char *service_name;
 
2170
                NMRemoteConnection *connection;
2008
2171
                const char *connection_path;
2009
2172
                const GPtrArray *devices;
2010
2173
 
2013
2176
                        continue;
2014
2177
 
2015
2178
                devices = nm_active_connection_get_devices (active);
2016
 
                service_name = nm_active_connection_get_service_name (active);
2017
2179
                connection_path = nm_active_connection_get_connection (active);
2018
 
                if (!devices || !service_name || !connection_path)
2019
 
                        continue;
2020
 
 
2021
 
                if (strcmp (service_name, NM_DBUS_SERVICE_USER_SETTINGS) != 0)
 
2180
                if (!devices || !connection_path)
2022
2181
                        continue;
2023
2182
 
2024
2183
                if (!nm_g_ptr_array_contains (devices, device))
2025
2184
                        continue;
2026
2185
 
2027
 
                connection = nm_settings_interface_get_connection_by_path (NM_SETTINGS_INTERFACE (applet->gconf_settings), connection_path);
 
2186
                connection = nm_remote_settings_get_connection_by_path (applet->settings, connection_path);
2028
2187
                if (connection)
2029
2188
                        return connection;
2030
2189
        }
2039
2198
                                    NMApplet *applet)
2040
2199
{
2041
2200
        gboolean device_activating = FALSE, vpn_activating = FALSE;
2042
 
        NMConnection *connection;
2043
 
        NMActiveConnection *active = NULL;
2044
2201
 
2045
2202
        device_activating = applet_is_any_device_activating (applet);
2046
2203
        vpn_activating = applet_is_any_vpn_activating (applet);
2056
2213
                device_activating = TRUE;
2057
2214
                break;
2058
2215
        case NM_DEVICE_STATE_ACTIVATED:
2059
 
                /* If the device activation was successful, update the corresponding
2060
 
                 * connection object with a current timestamp.
2061
 
                 */
2062
 
                connection = applet_find_active_connection_for_device (device, applet, &active);
2063
 
                if (connection && (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_USER))
2064
 
                        update_connection_timestamp (active, connection, applet);
2065
 
                break;
2066
2216
        default:
2067
2217
                break;
2068
2218
        }
2240
2390
        applet->permissions[NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK] = nm_client_get_permission_result (applet->nm_client, NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK);
2241
2391
        applet->permissions[NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI] = nm_client_get_permission_result (applet->nm_client, NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI);
2242
2392
        applet->permissions[NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN] = nm_client_get_permission_result (applet->nm_client, NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN);
2243
 
        applet->permissions[NM_CLIENT_PERMISSION_USE_USER_CONNECTIONS] = nm_client_get_permission_result (applet->nm_client, NM_CLIENT_PERMISSION_USE_USER_CONNECTIONS);
 
2393
        applet->permissions[NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX] = nm_client_get_permission_result (applet->nm_client, NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX);
2244
2394
 
2245
2395
        if (nm_client_get_manager_running (applet->nm_client))
2246
2396
                g_idle_add (foo_set_initial_state, applet);
2368
2518
static char *
2369
2519
get_tip_for_vpn (NMActiveConnection *active, NMVPNConnectionState state, NMApplet *applet)
2370
2520
{
2371
 
        NMConnectionScope scope;
2372
2521
        char *tip = NULL;
2373
2522
        const char *path, *id = NULL;
2374
2523
        GSList *iter, *list;
2375
2524
 
2376
 
        scope = nm_active_connection_get_scope (active);
2377
2525
        path = nm_active_connection_get_connection (active);
2378
2526
        g_return_val_if_fail (path != NULL, NULL);
2379
2527
 
2382
2530
                NMConnection *candidate = NM_CONNECTION (iter->data);
2383
2531
                NMSettingConnection *s_con;
2384
2532
 
2385
 
                if (   (nm_connection_get_scope (candidate) == scope)
2386
 
                    && !strcmp (nm_connection_get_path (candidate), path)) {
 
2533
                if (!strcmp (nm_connection_get_path (candidate), path)) {
2387
2534
                        s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (candidate, NM_TYPE_SETTING_CONNECTION));
2388
2535
                        id = nm_setting_connection_get_id (s_con);
2389
2536
                        break;
2489
2636
        }
2490
2637
        foo_set_icon (applet, pixbuf, ICON_LAYER_VPN);
2491
2638
 
2492
 
        if (applet->tip) {
2493
 
                g_free (applet->tip);
2494
 
                applet->tip = NULL;
2495
 
        }
 
2639
        g_free (applet->tip);
 
2640
        applet->tip = NULL;
2496
2641
 
2497
2642
        if (dev_tip || vpn_tip) {
2498
2643
                GString *tip;
2510
2655
                g_string_free (tip, FALSE);
2511
2656
        }
2512
2657
 
2513
 
#if GTK_CHECK_VERSION(2, 15, 0)
2514
2658
        gtk_status_icon_set_tooltip_text (applet->status_icon, applet->tip);
2515
 
#else
2516
 
        gtk_status_icon_set_tooltip (applet->status_icon, applet->tip);
2517
 
#endif
2518
2659
 
2519
2660
        return FALSE;
2520
2661
}
2526
2667
                applet->update_icon_id = g_idle_add (applet_update_icon, applet);
2527
2668
}
2528
2669
 
2529
 
static NMDevice *
2530
 
find_active_device (NMAGConfConnection *connection,
2531
 
                    NMApplet *applet,
2532
 
                    NMActiveConnection **out_active_connection)
 
2670
/*****************************************************************************/
 
2671
 
 
2672
static SecretsRequest *
 
2673
applet_secrets_request_new (size_t totsize,
 
2674
                            NMConnection *connection,
 
2675
                            gpointer request_id,
 
2676
                            const char *setting_name,
 
2677
                            const char **hints,
 
2678
                            guint32 flags,
 
2679
                            AppletAgentSecretsCallback callback,
 
2680
                            gpointer callback_data,
 
2681
                            NMApplet *applet)
2533
2682
{
2534
 
        const GPtrArray *active_connections;
2535
 
        int i;
 
2683
        SecretsRequest *req;
2536
2684
 
 
2685
        g_return_val_if_fail (totsize >= sizeof (SecretsRequest), NULL);
2537
2686
        g_return_val_if_fail (connection != NULL, NULL);
2538
 
        g_return_val_if_fail (applet != NULL, NULL);
2539
 
        g_return_val_if_fail (out_active_connection != NULL, NULL);
2540
 
        g_return_val_if_fail (*out_active_connection == NULL, NULL);
2541
 
 
2542
 
        /* Look through the active connection list trying to find the D-Bus
2543
 
         * object path of applet_connection.
2544
 
         */
2545
 
        active_connections = nm_client_get_active_connections (applet->nm_client);
2546
 
        for (i = 0; active_connections && (i < active_connections->len); i++) {
2547
 
                NMActiveConnection *active;
2548
 
                const char *service_name;
2549
 
                const char *connection_path;
2550
 
                const GPtrArray *devices;
2551
 
 
2552
 
                active = NM_ACTIVE_CONNECTION (g_ptr_array_index (active_connections, i));
2553
 
                service_name = nm_active_connection_get_service_name (active);
2554
 
                if (!service_name) {
2555
 
                        /* Shouldn't happen; but we shouldn't crash either */
2556
 
                        g_warning ("%s: couldn't get service name for active connection!", __func__);
2557
 
                        continue;
2558
 
                }
2559
 
 
2560
 
                if (strcmp (service_name, NM_DBUS_SERVICE_USER_SETTINGS))
2561
 
                        continue;
2562
 
 
2563
 
                connection_path = nm_active_connection_get_connection (active);
2564
 
                if (!connection_path) {
2565
 
                        /* Shouldn't happen; but we shouldn't crash either */
2566
 
                        g_warning ("%s: couldn't get connection path for active connection!", __func__);
2567
 
                        continue;
2568
 
                }
2569
 
 
2570
 
                if (!strcmp (connection_path, nm_connection_get_path (NM_CONNECTION (connection)))) {
2571
 
                        devices = nm_active_connection_get_devices (active);
2572
 
                        if (devices)
2573
 
                                *out_active_connection = active;
2574
 
                        return devices ? NM_DEVICE (g_ptr_array_index (devices, 0)) : NULL;
2575
 
                }
2576
 
        }
2577
 
 
2578
 
        return NULL;
2579
 
}
2580
 
 
2581
 
static void
2582
 
applet_settings_new_secrets_requested_cb (NMAGConfSettings *settings,
2583
 
                                          NMAGConfConnection *connection,
2584
 
                                          const char *setting_name,
2585
 
                                          const char **hints,
2586
 
                                          gboolean ask_user,
2587
 
                                          NMANewSecretsRequestedFunc callback,
2588
 
                                          gpointer callback_data,
2589
 
                                          gpointer user_data)
 
2687
 
 
2688
        req = g_malloc0 (totsize);
 
2689
        req->totsize = totsize;
 
2690
        req->connection = g_object_ref (connection);
 
2691
        req->reqid = request_id;
 
2692
        req->setting_name = g_strdup (setting_name);
 
2693
        req->hints = g_strdupv ((char **) hints);
 
2694
        req->flags = flags;
 
2695
        req->callback = callback;
 
2696
        req->callback_data = callback_data;
 
2697
        req->applet = applet;
 
2698
        return req;
 
2699
}
 
2700
 
 
2701
void
 
2702
applet_secrets_request_set_free_func (SecretsRequest *req,
 
2703
                                      SecretsRequestFreeFunc free_func)
 
2704
{
 
2705
        req->free_func = free_func;
 
2706
}
 
2707
 
 
2708
void
 
2709
applet_secrets_request_complete (SecretsRequest *req,
 
2710
                                 GHashTable *settings,
 
2711
                                 GError *error)
 
2712
{
 
2713
        req->callback (req->applet->agent, error ? NULL : settings, error, req->callback_data);
 
2714
}
 
2715
 
 
2716
void
 
2717
applet_secrets_request_complete_setting (SecretsRequest *req,
 
2718
                                         const char *setting_name,
 
2719
                                         GError *error)
 
2720
{
 
2721
        NMSetting *setting;
 
2722
        GHashTable *settings = NULL, *secrets;
 
2723
 
 
2724
        if (setting_name && !error) {
 
2725
                setting = nm_connection_get_setting_by_name (req->connection, setting_name);
 
2726
                if (setting) {
 
2727
                        secrets = nm_setting_to_hash (NM_SETTING (setting), NM_SETTING_HASH_FLAG_ALL);
 
2728
                        if (secrets) {
 
2729
                                /* Returned secrets are a{sa{sv}}; this is the outer a{s...} hash that
 
2730
                                 * will contain all the individual settings hashes.
 
2731
                                 */
 
2732
                                settings = g_hash_table_new_full (g_str_hash,
 
2733
                                                                  g_str_equal,
 
2734
                                                                  g_free,
 
2735
                                                                  (GDestroyNotify) g_hash_table_destroy);
 
2736
                                g_hash_table_insert (settings, g_strdup (setting_name), secrets);
 
2737
                        } else {
 
2738
                                g_set_error (&error,
 
2739
                                                     NM_SECRET_AGENT_ERROR,
 
2740
                                                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
2741
                                                     "%s.%d (%s): failed to hash setting '%s'.",
 
2742
                                                     __FILE__, __LINE__, __func__, setting_name);
 
2743
                        }
 
2744
                } else {
 
2745
                        g_set_error (&error,
 
2746
                                         NM_SECRET_AGENT_ERROR,
 
2747
                                         NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
2748
                                         "%s.%d (%s): unhandled setting '%s'",
 
2749
                                         __FILE__, __LINE__, __func__, setting_name);
 
2750
                }
 
2751
        }
 
2752
 
 
2753
        req->callback (req->applet->agent, settings, error, req->callback_data);
 
2754
}
 
2755
 
 
2756
void
 
2757
applet_secrets_request_free (SecretsRequest *req)
 
2758
{
 
2759
        g_return_if_fail (req != NULL);
 
2760
 
 
2761
        if (req->free_func)
 
2762
                req->free_func (req);
 
2763
 
 
2764
        req->applet->secrets_reqs = g_slist_remove (req->applet->secrets_reqs, req);
 
2765
 
 
2766
        g_object_unref (req->connection);
 
2767
        g_free (req->setting_name);
 
2768
        g_strfreev (req->hints);
 
2769
        memset (req, 0, req->totsize);
 
2770
        g_free (req);
 
2771
}
 
2772
 
 
2773
static void
 
2774
get_existing_secrets_cb (NMSecretAgent *agent,
 
2775
                         NMConnection *connection,
 
2776
                         GHashTable *secrets,
 
2777
                         GError *secrets_error,
 
2778
                         gpointer user_data)
 
2779
{
 
2780
        SecretsRequest *req = user_data;
 
2781
        NMADeviceClass *dclass;
 
2782
        GError *error = NULL;
 
2783
 
 
2784
        /* Merge existing secrets into connection; ignore errors */
 
2785
        nm_connection_update_secrets (connection, req->setting_name, secrets, NULL);
 
2786
 
 
2787
        dclass = get_device_class_from_connection (connection, req->applet);
 
2788
        g_assert (dclass);
 
2789
 
 
2790
        /* Let the device class handle secrets */
 
2791
        if (!dclass->get_secrets (req, &error)) {
 
2792
                g_warning ("%s:%d - %s", __func__, __LINE__, error ? error->message : "(unknown)");
 
2793
                applet_secrets_request_complete (req, NULL, error);
 
2794
                applet_secrets_request_free (req);
 
2795
                g_error_free (error);
 
2796
        }
 
2797
        /* Otherwise success; wait for the secrets callback */
 
2798
}
 
2799
 
 
2800
static void
 
2801
applet_agent_get_secrets_cb (AppletAgent *agent,
 
2802
                             gpointer request_id,
 
2803
                             NMConnection *connection,
 
2804
                             const char *setting_name,
 
2805
                             const char **hints,
 
2806
                             guint32 flags,
 
2807
                             AppletAgentSecretsCallback callback,
 
2808
                             gpointer callback_data,
 
2809
                             gpointer user_data)
2590
2810
{
2591
2811
        NMApplet *applet = NM_APPLET (user_data);
2592
 
        NMActiveConnection *active_connection = NULL;
2593
2812
        NMSettingConnection *s_con;
2594
 
        NMDevice *device;
2595
2813
        NMADeviceClass *dclass;
2596
2814
        GError *error = NULL;
 
2815
        SecretsRequest *req = NULL;
2597
2816
 
2598
 
        s_con = (NMSettingConnection *) nm_connection_get_setting (NM_CONNECTION (connection), NM_TYPE_SETTING_CONNECTION);
 
2817
        s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
2599
2818
        g_return_if_fail (s_con != NULL);
2600
2819
 
2601
2820
        /* VPN secrets get handled a bit differently */
2602
2821
        if (!strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_VPN_SETTING_NAME)) {
2603
 
                nma_vpn_request_password (NM_SETTINGS_CONNECTION_INTERFACE (connection), ask_user, callback, callback_data);
 
2822
                req = applet_secrets_request_new (applet_vpn_request_get_secrets_size (),
 
2823
                                                  connection,
 
2824
                                                  request_id,
 
2825
                                                  setting_name,
 
2826
                                                  hints,
 
2827
                                                  flags,
 
2828
                                                  callback,
 
2829
                                                  callback_data,
 
2830
                                                  applet);
 
2831
                if (!applet_vpn_request_get_secrets (req, &error))
 
2832
                        goto error;
 
2833
 
 
2834
                applet->secrets_reqs = g_slist_prepend (applet->secrets_reqs, req);
2604
2835
                return;
2605
2836
        }
2606
2837
 
2607
 
        /* Find the active device for this connection */
2608
 
        device = find_active_device (connection, applet, &active_connection);
2609
 
        if (!device || !active_connection) {
2610
 
                g_set_error (&error,
2611
 
                             NM_SETTINGS_INTERFACE_ERROR,
2612
 
                             NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
2613
 
                             "%s.%d (%s): couldn't find details for connection",
2614
 
                             __FILE__, __LINE__, __func__);
2615
 
                goto error;
2616
 
        }
2617
 
 
2618
 
        dclass = get_device_class (device, applet);
 
2838
        dclass = get_device_class_from_connection (connection, applet);
2619
2839
        if (!dclass) {
2620
 
                g_set_error (&error,
2621
 
                             NM_SETTINGS_INTERFACE_ERROR,
2622
 
                             NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
2623
 
                             "%s.%d (%s): device type unknown",
2624
 
                             __FILE__, __LINE__, __func__);
 
2840
                error = g_error_new (NM_SECRET_AGENT_ERROR,
 
2841
                                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
2842
                                     "%s.%d (%s): device type unknown",
 
2843
                                     __FILE__, __LINE__, __func__);
2625
2844
                goto error;
2626
2845
        }
2627
2846
 
2628
2847
        if (!dclass->get_secrets) {
2629
 
                g_set_error (&error,
2630
 
                             NM_SETTINGS_INTERFACE_ERROR,
2631
 
                             NM_SETTINGS_INTERFACE_ERROR_SECRETS_UNAVAILABLE,
2632
 
                             "%s.%d (%s): no secrets found",
2633
 
                             __FILE__, __LINE__, __func__);
 
2848
                error = g_error_new (NM_SECRET_AGENT_ERROR,
 
2849
                                     NM_SECRET_AGENT_ERROR_NO_SECRETS,
 
2850
                                     "%s.%d (%s): no secrets found",
 
2851
                                     __FILE__, __LINE__, __func__);
2634
2852
                goto error;
2635
2853
        }
2636
2854
 
2637
 
        // FIXME: get secrets locally and populate connection with previous secrets
2638
 
        // before asking user for other secrets
 
2855
        g_assert (dclass->secrets_request_size);
 
2856
        req = applet_secrets_request_new (dclass->secrets_request_size,
 
2857
                                          connection,
 
2858
                                          request_id,
 
2859
                                          setting_name,
 
2860
                                          hints,
 
2861
                                          flags,
 
2862
                                          callback,
 
2863
                                          callback_data,
 
2864
                                          applet);
 
2865
        applet->secrets_reqs = g_slist_prepend (applet->secrets_reqs, req);
2639
2866
 
2640
 
        /* Let the device class handle secrets */
2641
 
        if (dclass->get_secrets (device, NM_SETTINGS_CONNECTION_INTERFACE (connection),
2642
 
                                 active_connection, setting_name, hints, callback,
2643
 
                                 callback_data, applet, &error))
2644
 
                return;  /* success */
 
2867
        /* Get existing secrets, if any */
 
2868
        nm_secret_agent_get_secrets (NM_SECRET_AGENT (applet->agent),
 
2869
                                             connection,
 
2870
                                             setting_name,
 
2871
                                             hints,
 
2872
                                             NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE,
 
2873
                                             get_existing_secrets_cb,
 
2874
                                             req);
 
2875
        return;
2645
2876
 
2646
2877
error:
2647
2878
        g_warning ("%s", error->message);
2648
 
        callback (NM_SETTINGS_CONNECTION_INTERFACE (connection), NULL, error, callback_data);
 
2879
        callback (agent, NULL, error, callback_data);
2649
2880
        g_error_free (error);
 
2881
 
 
2882
        if (req)
 
2883
                applet_secrets_request_free (req);
2650
2884
}
2651
2885
 
2652
 
static gboolean
2653
 
periodic_update_active_connection_timestamps (gpointer user_data)
 
2886
static void
 
2887
applet_agent_cancel_secrets_cb (AppletAgent *agent,
 
2888
                                gpointer request_id,
 
2889
                                gpointer user_data)
2654
2890
{
2655
2891
        NMApplet *applet = NM_APPLET (user_data);
2656
 
        const GPtrArray *connections;
2657
 
        int i;
2658
 
 
2659
 
        if (!applet->nm_client || !nm_client_get_manager_running (applet->nm_client))
2660
 
                return TRUE;
2661
 
 
2662
 
        connections = nm_client_get_active_connections (applet->nm_client);
2663
 
        for (i = 0; connections && (i < connections->len); i++) {
2664
 
                NMActiveConnection *active = NM_ACTIVE_CONNECTION (g_ptr_array_index (connections, i));
2665
 
                const char *path;
2666
 
                NMSettingsConnectionInterface *connection;
2667
 
                const GPtrArray *devices;
2668
 
                int k;
2669
 
 
2670
 
                if (nm_active_connection_get_scope (active) == NM_CONNECTION_SCOPE_SYSTEM)
2671
 
                        continue;
2672
 
 
2673
 
                path = nm_active_connection_get_connection (active);
2674
 
                connection = nm_settings_interface_get_connection_by_path (NM_SETTINGS_INTERFACE (applet->gconf_settings), path);
2675
 
                if (!connection || !NMA_IS_GCONF_CONNECTION (connection))
2676
 
                        continue;
2677
 
 
2678
 
                devices = nm_active_connection_get_devices (active);
2679
 
                if (!devices || !devices->len)
2680
 
                        continue;
2681
 
 
2682
 
                /* Check if a device owned by the active connection is completely
2683
 
                 * activated before updating timestamp.
2684
 
                 */
2685
 
                for (k = 0; devices && (k < devices->len); k++) {
2686
 
                        NMDevice *device = NM_DEVICE (g_ptr_array_index (devices, k));
2687
 
 
2688
 
                        if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) {
2689
 
                                NMSettingConnection *s_con;
2690
 
 
2691
 
                                s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (NM_CONNECTION (connection), NM_TYPE_SETTING_CONNECTION));
2692
 
                                g_assert (s_con);
2693
 
 
2694
 
                                g_object_set (s_con, NM_SETTING_CONNECTION_TIMESTAMP, (guint64) time (NULL), NULL);
2695
 
                                /* Ignore secrets since we're just updating the timestamp */
2696
 
                                nma_gconf_connection_update (NMA_GCONF_CONNECTION (connection), TRUE);
2697
 
                                break;
2698
 
                        }
 
2892
        GSList *iter;
 
2893
 
 
2894
        for (iter = applet->secrets_reqs; iter; iter = g_slist_next (iter)) {
 
2895
                SecretsRequest *req = iter->data;
 
2896
 
 
2897
                if (req->reqid == request_id) {
 
2898
                        /* cancel and free this password request */
 
2899
                        applet_secrets_request_free (req);
2699
2900
                }
2700
2901
        }
2701
 
 
2702
 
        return TRUE;
2703
2902
}
2704
2903
 
2705
2904
/*****************************************************************************/
2896
3095
         */
2897
3096
        applet_clear_notify (applet);
2898
3097
 
2899
 
        nma_menu_clear (applet);
 
3098
        /* Kill any old menu */
 
3099
        if (applet->menu)
 
3100
                g_object_unref (applet->menu);
 
3101
 
 
3102
        /* And make a fresh new one */
 
3103
        applet->menu = gtk_menu_new ();
 
3104
        /* Sink the ref so we can explicitly destroy the menu later */
 
3105
        g_object_ref_sink (G_OBJECT (applet->menu));
 
3106
 
 
3107
        gtk_container_set_border_width (GTK_CONTAINER (applet->menu), 0);
 
3108
        g_signal_connect (applet->menu, "show", G_CALLBACK (nma_menu_show_cb), applet);
 
3109
        g_signal_connect (applet->menu, "deactivate", G_CALLBACK (nma_menu_deactivate_cb), applet);
 
3110
 
 
3111
        /* Display the new menu */
2900
3112
        gtk_menu_popup (GTK_MENU (applet->menu), NULL, NULL,
2901
 
                        gtk_status_icon_position_menu, icon,
2902
 
                        1, gtk_get_current_event_time ());
 
3113
                        gtk_status_icon_position_menu, icon,
 
3114
                        1, gtk_get_current_event_time ());
2903
3115
}
2904
3116
 
2905
3117
static void
2927
3139
        applet->status_icon = gtk_status_icon_new ();
2928
3140
        if (!applet->status_icon)
2929
3141
                return FALSE;
 
3142
        if (shell_debug)
 
3143
                gtk_status_icon_set_name (applet->status_icon, "adsfasdfasdfadfasdf");
2930
3144
 
2931
3145
        g_signal_connect (applet->status_icon, "notify::screen",
2932
3146
                          G_CALLBACK (status_icon_screen_changed_cb), applet);
2937
3151
        g_signal_connect (applet->status_icon, "popup-menu",
2938
3152
                          G_CALLBACK (status_icon_popup_menu_cb), applet);
2939
3153
 
2940
 
        applet->menu = nma_menu_create (applet);
2941
 
        if (!applet->menu)
2942
 
                return FALSE;
2943
 
 
2944
3154
        applet->context_menu = nma_context_menu_create (applet);
2945
3155
        if (!applet->context_menu)
2946
3156
                return FALSE;
2949
3159
}
2950
3160
 
2951
3161
static void
2952
 
applet_pre_keyring_callback (gpointer user_data)
2953
 
{
2954
 
        NMApplet *applet = NM_APPLET (user_data);
2955
 
        GdkScreen *screen;
2956
 
        GdkDisplay *display;
2957
 
        GdkWindow *window = NULL;
2958
 
 
2959
 
        if (applet->menu)
2960
 
                window = gtk_widget_get_window (applet->menu);
2961
 
        if (window) {
2962
 
#if GTK_CHECK_VERSION(2,23,0)
2963
 
                screen = gdk_window_get_screen (window);
2964
 
#else
2965
 
                screen = gdk_drawable_get_screen (window);
2966
 
#endif
2967
 
                display = gdk_screen_get_display (screen);
2968
 
                g_object_ref (display);
2969
 
 
2970
 
                gtk_widget_hide (applet->menu);
2971
 
                gtk_widget_destroy (applet->menu);
2972
 
                applet->menu = NULL;
2973
 
 
2974
 
                /* Ensure that the widget really gets destroyed before letting the
2975
 
                 * keyring calls happen; if the X events haven't all gone through when
2976
 
                 * the keyring dialog comes up, then the menu will actually still have
2977
 
                 * the screen grab even after we've called gtk_widget_destroy().
2978
 
                 */
2979
 
                gdk_display_sync (display);
2980
 
                g_object_unref (display);
2981
 
        }
2982
 
 
2983
 
        window = NULL;
2984
 
        if (applet->context_menu)
2985
 
                window = gtk_widget_get_window (applet->context_menu);
2986
 
        if (window) {
2987
 
#if GTK_CHECK_VERSION(2,23,0)
2988
 
                screen = gdk_window_get_screen (window);
2989
 
#else
2990
 
                screen = gdk_drawable_get_screen (window);
2991
 
#endif
2992
 
                display = gdk_screen_get_display (screen);
2993
 
                g_object_ref (display);
2994
 
 
2995
 
                gtk_widget_hide (applet->context_menu);
2996
 
 
2997
 
                /* Ensure that the widget really gets hidden before letting the
2998
 
                 * keyring calls happen; if the X events haven't all gone through when
2999
 
                 * the keyring dialog comes up, then the menu will actually still have
3000
 
                 * the screen grab even after we've called gtk_widget_hide().
3001
 
                 */
3002
 
                gdk_display_sync (display);
3003
 
                g_object_unref (display);
3004
 
        }
3005
 
}
3006
 
 
3007
 
static void
3008
 
exit_cb (GObject *ignored, gpointer user_data)
3009
 
{
3010
 
        NMApplet *applet = user_data;
3011
 
 
3012
 
        g_main_loop_quit (applet->loop);
3013
 
}
3014
 
 
3015
 
static void
3016
3162
applet_embedded_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
3017
3163
{
3018
3164
        gboolean embedded = gtk_status_icon_is_embedded (GTK_STATUS_ICON (object));
3021
3167
                   embedded ? "embedded in" : "removed from");
3022
3168
}
3023
3169
 
 
3170
static gboolean
 
3171
dbus_setup (NMApplet *applet, GError **error)
 
3172
{
 
3173
        DBusConnection *connection;
 
3174
        DBusGProxy *proxy;
 
3175
        guint result;
 
3176
        gboolean success;
 
3177
 
 
3178
        applet->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, error);
 
3179
        if (!applet->bus)
 
3180
                return FALSE;
 
3181
 
 
3182
        connection = dbus_g_connection_get_connection (applet->bus);
 
3183
        dbus_connection_set_exit_on_disconnect (connection, FALSE);
 
3184
 
 
3185
        applet->session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, error);
 
3186
        if (!applet->session_bus)
 
3187
                return FALSE;
 
3188
 
 
3189
        dbus_g_connection_register_g_object (applet->session_bus,
 
3190
                                             "/org/gnome/network_manager_applet",
 
3191
                                             G_OBJECT (applet));
 
3192
 
 
3193
        proxy = dbus_g_proxy_new_for_name (applet->session_bus,
 
3194
                                           DBUS_SERVICE_DBUS,
 
3195
                                           DBUS_PATH_DBUS,
 
3196
                                           DBUS_INTERFACE_DBUS);
 
3197
        success = dbus_g_proxy_call (proxy, "RequestName", error,
 
3198
                                     G_TYPE_STRING, "org.gnome.network_manager_applet",
 
3199
                                     G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
 
3200
                                     G_TYPE_INVALID,
 
3201
                                     G_TYPE_UINT, &result,
 
3202
                                     G_TYPE_INVALID);
 
3203
        g_object_unref (proxy);
 
3204
 
 
3205
        return success;
 
3206
}
 
3207
 
 
3208
static void
 
3209
add_cb (NMRemoteSettings *settings,
 
3210
        NMRemoteConnection *connection,
 
3211
        GError *error,
 
3212
        gpointer user_data)
 
3213
{
 
3214
        NMConnection *c = user_data;
 
3215
 
 
3216
        if (error) {
 
3217
                g_warning ("Failed to move connection '%s' to NetworkManager system settings: %s",
 
3218
                           nm_connection_get_id (c),
 
3219
                           error->message);
 
3220
        }
 
3221
        g_object_unref (c);
 
3222
}
 
3223
 
 
3224
static void
 
3225
import_cb (NMConnection *connection, gpointer user_data)
 
3226
{
 
3227
        NMApplet *applet = user_data;
 
3228
 
 
3229
        if (!nm_remote_settings_add_connection (applet->settings, connection, add_cb, g_object_ref (connection))) {
 
3230
                g_warning ("Failed to move connection '%s' to NetworkManager system settings.",
 
3231
                           nm_connection_get_id (connection));
 
3232
        }
 
3233
}
 
3234
 
3024
3235
static GObject *
3025
3236
constructor (GType type,
3026
3237
             guint n_props,
3027
3238
             GObjectConstructParam *construct_props)
3028
3239
{
3029
3240
        NMApplet *applet;
3030
 
        AppletDBusManager *dbus_mgr;
3031
3241
        GError* error = NULL;
3032
3242
 
3033
3243
        applet = NM_APPLET (G_OBJECT_CLASS (nma_parent_class)->constructor (type, n_props, construct_props));
3061
3271
        if (!notify_is_initted ())
3062
3272
                notify_init ("NetworkManager");
3063
3273
 
3064
 
        dbus_mgr = applet_dbus_manager_get ();
3065
 
        if (dbus_mgr == NULL) {
3066
 
                nm_warning ("Couldn't initialize the D-Bus manager.");
3067
 
                g_object_unref (applet);
3068
 
                return NULL;
3069
 
        }
3070
 
        g_signal_connect (G_OBJECT (dbus_mgr), "exit-now", G_CALLBACK (exit_cb), applet);
3071
 
 
3072
 
        applet->system_settings = nm_remote_settings_system_new (applet_dbus_manager_get_connection (dbus_mgr));
3073
 
 
3074
 
        applet->gconf_settings = nma_gconf_settings_new (applet_dbus_manager_get_connection (dbus_mgr));
3075
 
        g_signal_connect (applet->gconf_settings, "new-secrets-requested",
3076
 
                          G_CALLBACK (applet_settings_new_secrets_requested_cb),
3077
 
                          applet);
3078
 
 
3079
 
        nm_settings_service_export (NM_SETTINGS_SERVICE (applet->gconf_settings));
3080
 
 
3081
 
        /* Start our DBus service */
3082
 
        if (!applet_dbus_manager_start_service (dbus_mgr)) {
3083
 
                g_object_unref (applet);
3084
 
                return NULL;
3085
 
        }
 
3274
        if (!dbus_setup (applet, &error)) {
 
3275
                g_warning ("Failed to initialize D-Bus: %s", error->message);
 
3276
                g_error_free (error);
 
3277
                goto error;
 
3278
        }
 
3279
        applet->settings = nm_remote_settings_new (applet->bus);
 
3280
 
 
3281
        /* Move user connections to the system */
 
3282
        nm_gconf_move_connections_to_system (import_cb, applet);
 
3283
 
 
3284
        applet->agent = applet_agent_new ();
 
3285
        g_assert (applet->agent);
 
3286
        g_signal_connect (applet->agent, APPLET_AGENT_GET_SECRETS,
 
3287
                          G_CALLBACK (applet_agent_get_secrets_cb), applet);
 
3288
        g_signal_connect (applet->agent, APPLET_AGENT_CANCEL_SECRETS,
 
3289
                          G_CALLBACK (applet_agent_cancel_secrets_cb), applet);
3086
3290
 
3087
3291
        /* Initialize device classes */
3088
3292
        applet->wired_class = applet_device_wired_get_class (applet);
3100
3304
        applet->bt_class = applet_device_bt_get_class (applet);
3101
3305
        g_assert (applet->bt_class);
3102
3306
 
 
3307
        applet->wimax_class = applet_device_wimax_get_class (applet);
 
3308
        g_assert (applet->wimax_class);
 
3309
 
3103
3310
        foo_client_setup (applet);
3104
3311
 
3105
 
        /* timeout to update connection timestamps every 5 minutes */
3106
 
        applet->update_timestamps_id = g_timeout_add_seconds (300,
3107
 
                        (GSourceFunc) periodic_update_active_connection_timestamps, applet);
3108
 
 
3109
 
        nm_gconf_set_pre_keyring_callback (applet_pre_keyring_callback, applet);
3110
 
 
3111
3312
        /* Track embedding to help debug issues where user has removed the
3112
3313
         * notification area applet from the panel, and thus nm-applet too.
3113
3314
         */
3128
3329
{
3129
3330
        NMApplet *applet = NM_APPLET (object);
3130
3331
 
3131
 
        nm_gconf_set_pre_keyring_callback (NULL, NULL);
3132
 
 
3133
 
        if (applet->update_timestamps_id)
3134
 
                g_source_remove (applet->update_timestamps_id);
3135
 
 
3136
3332
        g_slice_free (NMADeviceClass, applet->wired_class);
3137
3333
        g_slice_free (NMADeviceClass, applet->wifi_class);
3138
3334
        g_slice_free (NMADeviceClass, applet->gsm_class);
 
3335
        g_slice_free (NMADeviceClass, applet->cdma_class);
 
3336
        g_slice_free (NMADeviceClass, applet->bt_class);
 
3337
        g_slice_free (NMADeviceClass, applet->wimax_class);
3139
3338
 
3140
3339
        if (applet->update_icon_id)
3141
3340
                g_source_remove (applet->update_icon_id);
3142
3341
 
3143
 
        nma_menu_clear (applet);
 
3342
        if (applet->menu)
 
3343
                g_object_unref (applet->menu);
3144
3344
        nma_icons_free (applet);
3145
3345
 
3146
3346
        g_free (applet->tip);
3147
3347
 
 
3348
        while (g_slist_length (applet->secrets_reqs))
 
3349
                applet_secrets_request_free ((SecretsRequest *) applet->secrets_reqs->data);
 
3350
 
3148
3351
        if (applet->notification) {
3149
3352
                notify_notification_close (applet->notification, NULL);
3150
3353
                g_object_unref (applet->notification);
3169
3372
        if (applet->fallback_icon)
3170
3373
                g_object_unref (applet->fallback_icon);
3171
3374
 
3172
 
        if (applet->gconf_settings) {
3173
 
                g_object_unref (applet->gconf_settings);
3174
 
                applet->gconf_settings = NULL;
3175
 
        }
3176
 
        if (applet->system_settings) {
3177
 
                g_object_unref (applet->system_settings);
3178
 
                applet->system_settings = NULL;
3179
 
        }
 
3375
        if (applet->agent)
 
3376
                g_object_unref (applet->agent);
 
3377
 
 
3378
        if (applet->settings)
 
3379
                g_object_unref (applet->settings);
 
3380
 
 
3381
        if (applet->bus)
 
3382
                dbus_g_connection_unref (applet->bus);
 
3383
 
 
3384
        if (applet->session_bus)
 
3385
                dbus_g_connection_unref (applet->session_bus);
3180
3386
 
3181
3387
        G_OBJECT_CLASS (nma_parent_class)->finalize (object);
3182
3388
}
3223
3429
 
3224
3430
        pspec = g_param_spec_pointer ("loop", "Loop", "Applet mainloop", G_PARAM_CONSTRUCT | G_PARAM_WRITABLE);
3225
3431
        g_object_class_install_property (oclass, PROP_LOOP, pspec);
 
3432
 
 
3433
        dbus_g_object_type_install_info (NM_TYPE_APPLET, &dbus_glib_nma_object_info);
3226
3434
}
3227
3435
 
3228
3436
NMApplet *