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

« back to all changes in this revision

Viewing changes to src/applet-dialogs.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:
20
20
 * (C) Copyright 2008 - 2010 Red Hat, Inc.
21
21
 */
22
22
 
 
23
#include "config.h"
 
24
 
23
25
#include <netinet/in.h>
24
26
#include <sys/socket.h>
25
27
#include <arpa/inet.h>
27
29
 
28
30
#include <nm-device-ethernet.h>
29
31
#include <nm-device-wifi.h>
30
 
#include <nm-gsm-device.h>
31
 
#include <nm-cdma-device.h>
 
32
#include <nm-device-modem.h>
 
33
#include <nm-device-wimax.h>
32
34
 
33
35
#include <nm-setting-connection.h>
34
36
#include <nm-setting-wireless.h>
43
45
#include <glib/gi18n.h>
44
46
 
45
47
#include "applet-dialogs.h"
46
 
#include "utils.h"
47
 
#include "nma-bling-spinner.h"
48
48
 
49
49
 
50
50
static void
86
86
                g_string_append_printf (ip6_str, "%02X", ip->s6_addr[0]);
87
87
                for (j = 1; j < 16; j++)
88
88
                        g_string_append_printf (ip6_str, " %02X", ip->s6_addr[j]);
89
 
                nm_warning ("%s: error converting IP6 address %s",
90
 
                            __func__, ip6_str->str);
 
89
                g_warning ("%s: error converting IP6 address %s", __func__, ip6_str->str);
91
90
                g_string_free (ip6_str, TRUE);
92
91
                return NULL;
93
92
        }
145
144
{
146
145
        GSList *list, *iter;
147
146
        NMConnection *connection = NULL;
148
 
        NMConnectionScope scope;
149
147
        const char *path;
150
148
 
151
 
        scope = nm_active_connection_get_scope (active);
152
 
        g_return_val_if_fail (scope != NM_CONNECTION_SCOPE_UNKNOWN, NULL);
153
 
 
154
149
        path = nm_active_connection_get_connection (active);
155
150
        g_return_val_if_fail (path != NULL, NULL);
156
151
 
158
153
        for (iter = list; iter; iter = g_slist_next (iter)) {
159
154
                NMConnection *candidate = NM_CONNECTION (iter->data);
160
155
 
161
 
                if (   (nm_connection_get_scope (candidate) == scope)
162
 
                           && !strcmp (nm_connection_get_path (candidate), path)) {
 
156
                if (!strcmp (nm_connection_get_path (candidate), path)) {
163
157
                        connection = candidate;
164
158
                        break;
165
159
                }
166
160
        }
167
 
 
168
161
        g_slist_free (list);
169
162
 
170
163
        return connection;
200
193
{
201
194
        NMSettingConnection *s_con;
202
195
        char *label = NULL;
203
 
        GtkWidget *w;
 
196
        GtkWidget *w = NULL;
204
197
        const char *connection_type;
205
198
 
206
199
        s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
243
236
                        label = g_strdup (C_("Wifi/wired security", "None"));
244
237
        }
245
238
 
246
 
        w = create_info_label (label ? label : C_("Wifi/wired security", "Unknown"), TRUE);
 
239
        if (label)
 
240
                w = create_info_label (label, TRUE);
247
241
        g_free (label);
248
242
 
249
243
        return w;
274
268
        NMDevice *device;
275
269
        GtkWidget *label;
276
270
        guint32 id;
277
 
} SpeedInfo;
 
271
} LabelInfo;
278
272
 
279
273
static void
280
274
device_destroyed (gpointer data, GObject *device_ptr)
281
275
{
282
 
        SpeedInfo *info = data;
 
276
        LabelInfo *info = data;
283
277
 
284
278
        /* Device is destroyed, notify handler won't fire
285
279
         * anymore anyway.  Let the label destroy handler
292
286
static void
293
287
label_destroyed (gpointer data, GObject *label_ptr)
294
288
{
295
 
        SpeedInfo *info = data;
 
289
        LabelInfo *info = data;
 
290
 
296
291
        /* Remove the notify handler from the device */
297
292
        if (info->device) {
298
293
                if (info->id)
299
294
                        g_signal_handler_disconnect (info->device, info->id);
300
295
                /* destroy our info data */
301
296
                g_object_weak_unref (G_OBJECT (info->device), device_destroyed, info);
302
 
                memset (info, 0, sizeof (SpeedInfo));
 
297
                memset (info, 0, sizeof (LabelInfo));
303
298
                g_free (info);
304
299
        }
305
300
}
306
301
 
307
302
static void
 
303
label_info_new (NMDevice *device,
 
304
                GtkWidget *label,
 
305
                const char *notify_prop,
 
306
                GCallback callback)
 
307
{
 
308
        LabelInfo *info;
 
309
 
 
310
        info = g_malloc0 (sizeof (LabelInfo));
 
311
        info->device = device;
 
312
        info->label = label;
 
313
        info->id = g_signal_connect (device, notify_prop, callback, label);
 
314
        g_object_weak_ref (G_OBJECT (label), label_destroyed, info);
 
315
        g_object_weak_ref (G_OBJECT (device), device_destroyed, info);
 
316
}
 
317
 
 
318
static void
308
319
bitrate_changed_cb (GObject *device, GParamSpec *pspec, gpointer user_data)
309
320
{
310
321
        GtkWidget *speed_label = GTK_WIDGET (user_data);
320
331
}
321
332
 
322
333
static void
 
334
wimax_cinr_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
 
335
{
 
336
        GtkWidget *label = GTK_WIDGET (user_data);
 
337
        gint cinr;
 
338
        char *str = NULL;
 
339
 
 
340
        cinr = nm_device_wimax_get_cinr (NM_DEVICE_WIMAX (device));
 
341
        if (cinr)
 
342
                str = g_strdup_printf (_("%d dB"), cinr);
 
343
 
 
344
        gtk_label_set_text (GTK_LABEL (label), str ? str : C_("WiMAX CINR", "unknown"));
 
345
        g_free (str);
 
346
}
 
347
 
 
348
static void
 
349
wimax_bsid_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
 
350
{
 
351
        GtkWidget *label = GTK_WIDGET (user_data);
 
352
        const char *str = NULL;
 
353
 
 
354
        str = nm_device_wimax_get_bsid (NM_DEVICE_WIMAX (device));
 
355
        if (!str)
 
356
                str = C_("WiMAX Base Station ID", "unknown");
 
357
        gtk_label_set_text (GTK_LABEL (label), str);
 
358
}
 
359
 
 
360
static void
323
361
info_dialog_add_page (GtkNotebook *notebook,
324
362
                      NMConnection *connection,
325
363
                      gboolean is_default,
328
366
        GtkTable *table;
329
367
        guint32 speed = 0;
330
368
        char *str;
331
 
        const char *iface, *method;
 
369
        const char *iface, *method = NULL;
332
370
        NMIP4Config *ip4_config;
333
371
        NMIP6Config *ip6_config;
334
372
        const GArray *dns;
338
376
        NMSettingIP6Config *s_ip6;
339
377
        guint32 hostmask, network, bcast, netmask;
340
378
        int i, row = 0;
341
 
        SpeedInfo* info = NULL;
342
 
        GtkWidget* speed_label;
 
379
        GtkWidget* speed_label, *sec_label = NULL;
343
380
        const GSList *addresses;
 
381
        gboolean show_security = FALSE;
344
382
 
345
383
        table = GTK_TABLE (gtk_table_new (12, 2, FALSE));
346
384
        gtk_table_set_col_spacings (table, 12);
349
387
 
350
388
        /* Interface */
351
389
        iface = nm_device_get_iface (device);
352
 
        if (NM_IS_DEVICE_ETHERNET (device))
 
390
        if (NM_IS_DEVICE_ETHERNET (device)) {
353
391
                str = g_strdup_printf (_("Ethernet (%s)"), iface);
354
 
        else if (NM_IS_DEVICE_WIFI (device))
 
392
                show_security = TRUE;
 
393
        } else if (NM_IS_DEVICE_WIFI (device)) {
355
394
                str = g_strdup_printf (_("802.11 WiFi (%s)"), iface);
356
 
        else if (NM_IS_GSM_DEVICE (device))
357
 
                str = g_strdup_printf (_("GSM (%s)"), iface);
358
 
        else if (NM_IS_CDMA_DEVICE (device))
359
 
                str = g_strdup_printf (_("CDMA (%s)"), iface);
 
395
                show_security = TRUE;
 
396
        } else if (NM_IS_DEVICE_MODEM (device)) {
 
397
                NMDeviceModemCapabilities caps;
 
398
 
 
399
                caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
 
400
                if (caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
 
401
                        str = g_strdup_printf (_("GSM (%s)"), iface);
 
402
                else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
 
403
                        str = g_strdup_printf (_("CDMA (%s)"), iface);
 
404
                else
 
405
                        str = g_strdup_printf (_("Mobile Broadband (%s)"), iface);
 
406
        } else if (NM_IS_DEVICE_WIMAX (device))
 
407
                str = g_strdup_printf (_("WiMAX (%s)"), iface);
360
408
        else
361
409
                str = g_strdup (iface);
362
410
 
379
427
                str = g_strdup (nm_device_ethernet_get_hw_address (NM_DEVICE_ETHERNET (device)));
380
428
        else if (NM_IS_DEVICE_WIFI (device))
381
429
                str = g_strdup (nm_device_wifi_get_hw_address (NM_DEVICE_WIFI (device)));
 
430
        else if (NM_IS_DEVICE_WIMAX (device))
 
431
                str = g_strdup (nm_device_wimax_get_hw_address (NM_DEVICE_WIMAX (device)));
382
432
 
383
433
        gtk_table_attach (table, create_info_label (_("Hardware Address:"), FALSE),
384
434
                          0, 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
405
455
                /* Wireless speed in Kb/s */
406
456
                speed = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (device)) / 1000;
407
457
 
408
 
                /* Listen for wifi speed changes */
409
 
                info = g_malloc0 (sizeof (SpeedInfo));
410
 
                info->device = device;
411
 
                info->label = speed_label;
412
 
                info->id = g_signal_connect (device,
413
 
                                             "notify::" NM_DEVICE_WIFI_BITRATE,
414
 
                                             G_CALLBACK (bitrate_changed_cb),
415
 
                                             speed_label);
416
 
 
417
 
                g_object_weak_ref (G_OBJECT(speed_label), label_destroyed, info);
418
 
                g_object_weak_ref (G_OBJECT(device), device_destroyed, info);
 
458
                label_info_new (device,
 
459
                                speed_label,
 
460
                                "notify::" NM_DEVICE_WIFI_BITRATE,
 
461
                                G_CALLBACK (bitrate_changed_cb));
419
462
        }
420
463
 
421
464
        if (speed)
431
474
        row++;
432
475
 
433
476
        /* Security */
434
 
        gtk_table_attach (table, create_info_label (_("Security:"), FALSE),
435
 
                          0, 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
436
 
        gtk_table_attach (table, create_info_label_security (connection),
437
 
                          1, 2, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
438
 
        row++;
 
477
        if (show_security) {
 
478
                sec_label = create_info_label_security (connection);
 
479
                if (sec_label) {
 
480
                        gtk_table_attach (table, create_info_label (_("Security:"), FALSE),
 
481
                                              0, 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
 
482
                        gtk_table_attach (table, sec_label,
 
483
                                              1, 2, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
 
484
                        row++;
 
485
                }
 
486
        }
 
487
 
 
488
        if (NM_IS_DEVICE_WIMAX (device)) {
 
489
                GtkWidget *bsid_label, *cinr_label;
 
490
 
 
491
                /* CINR */
 
492
                cinr_label = create_info_label ("", TRUE);
 
493
                gtk_table_attach (table, create_info_label (_("CINR:"), FALSE),
 
494
                                      0, 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
 
495
                gtk_table_attach (table, cinr_label,
 
496
                                      1, 2, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
 
497
                label_info_new (device,
 
498
                                cinr_label,
 
499
                                "notify::" NM_DEVICE_WIMAX_CINR,
 
500
                                G_CALLBACK (wimax_cinr_changed_cb));
 
501
                wimax_cinr_changed_cb (device, NULL, cinr_label);
 
502
                row++;
 
503
 
 
504
                /* Base Station ID */
 
505
                bsid_label = create_info_label ("", TRUE);
 
506
                gtk_table_attach (table, create_info_label (_("BSID:"), FALSE),
 
507
                                      0, 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
 
508
                gtk_table_attach (table, bsid_label,
 
509
                                      1, 2, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
 
510
                label_info_new (device,
 
511
                                bsid_label,
 
512
                                "notify::" NM_DEVICE_WIMAX_BSID,
 
513
                                G_CALLBACK (wimax_bsid_changed_cb));
 
514
                wimax_bsid_changed_cb (device, NULL, bsid_label);
 
515
                row++;
 
516
        }
439
517
 
440
518
        /* Empty line */
441
519
        gtk_table_attach (table, gtk_label_new (""), 0, 2, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
737
815
}
738
816
 
739
817
GtkWidget *
740
 
applet_mobile_password_dialog_new (NMDevice *device,
741
 
                                   NMConnection *connection,
 
818
applet_mobile_password_dialog_new (NMConnection *connection,
742
819
                                   GtkEntry **out_secret_entry)
743
820
{
744
821
        GtkDialog *dialog;
745
822
        GtkWidget *w;
746
823
        GtkBox *box = NULL, *vbox = NULL;
747
 
        char *dev_str;
748
824
        NMSettingConnection *s_con;
749
825
        char *tmp;
750
826
        const char *id;
768
844
 
769
845
        gtk_box_pack_start (vbox, w, TRUE, TRUE, 0);
770
846
 
771
 
        dev_str = g_strdup_printf ("<b>%s</b>", utils_get_device_description (device));
772
 
        w = gtk_label_new (NULL);
773
 
        gtk_label_set_markup (GTK_LABEL (w), dev_str);
774
 
        g_free (dev_str);
775
 
        gtk_box_pack_start (vbox, w, TRUE, TRUE, 0);
776
 
 
777
847
        w = gtk_alignment_new (0.5, 0.5, 0, 1.0);
778
848
        gtk_box_pack_start (vbox, w, TRUE, TRUE, 0);
779
849
 
1141
1211
        builder = g_object_get_data (G_OBJECT (dialog), "builder");
1142
1212
        g_return_if_fail (builder != NULL);
1143
1213
 
1144
 
        spinner = nma_bling_spinner_new ();
 
1214
        spinner = gtk_spinner_new ();
1145
1215
        g_return_if_fail (spinner != NULL);
1146
1216
        g_object_set_data (G_OBJECT (dialog), "spinner", spinner);
1147
1217
 
1148
1218
        align = GTK_WIDGET (gtk_builder_get_object (builder, "spinner_alignment"));
1149
1219
        gtk_container_add (GTK_CONTAINER (align), spinner);
1150
 
        nma_bling_spinner_start (NMA_BLING_SPINNER (spinner));
 
1220
        gtk_spinner_start (GTK_SPINNER (spinner));
1151
1221
 
1152
1222
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "progress_label"));
1153
1223
        gtk_label_set_text (GTK_LABEL (widget), text);
1185
1255
 
1186
1256
        spinner = g_object_get_data (G_OBJECT (dialog), "spinner");
1187
1257
        g_return_if_fail (spinner != NULL);
1188
 
        nma_bling_spinner_stop (NMA_BLING_SPINNER (spinner));
 
1258
        gtk_spinner_stop (GTK_SPINNER (spinner));
1189
1259
        g_object_set_data (G_OBJECT (dialog), "spinner", NULL);
1190
1260
 
1191
1261
        /* Remove it from the alignment */