~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to panels/network/cc-network-panel.c

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette
  • Date: 2011-04-29 02:24:28 UTC
  • mfrom: (0.2.7 upstream)
  • mto: (0.3.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 165.
  • Revision ID: james.westby@ubuntu.com-20110429022428-ua1v4ck5shphkkku
Tags: 1:3.0.1.1-1
* New upstream release.
* gnome-control-center-data.install: drop GConf schemas.
* gnome-control-center-data.gconf-defaults: dropped, obsolete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
794
794
        }
795
795
}
796
796
 
 
797
static void
 
798
add_access_point_other (CcNetworkPanel *panel)
 
799
{
 
800
        CcNetworkPanelPrivate *priv = panel->priv;
 
801
        GtkListStore *liststore_wireless_network;
 
802
        GtkTreeIter treeiter;
 
803
 
 
804
        liststore_wireless_network = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
 
805
                                                     "liststore_wireless_network"));
 
806
 
 
807
        gtk_list_store_append (liststore_wireless_network, &treeiter);
 
808
        gtk_list_store_set (liststore_wireless_network,
 
809
                            &treeiter,
 
810
                            PANEL_WIRELESS_COLUMN_ID, "ap-other...",
 
811
                            /* TRANSLATORS: this is when the access point is not listed
 
812
                             * in the dropdown (or hidden) and the user has to select
 
813
                             * another entry manually */
 
814
                            PANEL_WIRELESS_COLUMN_TITLE, C_("Wireless access point", "Other..."),
 
815
                            /* always last */
 
816
                            PANEL_WIRELESS_COLUMN_SORT, "",
 
817
                            PANEL_WIRELESS_COLUMN_STRENGTH, 0,
 
818
                            PANEL_WIRELESS_COLUMN_MODE, NM_802_11_MODE_UNKNOWN,
 
819
                            PANEL_WIRELESS_COLUMN_SECURITY, NM_AP_SEC_UNKNOWN,
 
820
                            -1);
 
821
}
 
822
 
797
823
#if 0
798
824
static gchar *
799
825
ip4_address_as_string (guint32 ip)
1362
1388
                        ap = NM_ACCESS_POINT (g_ptr_array_index (aps_unique, i));
1363
1389
                        add_access_point (panel, ap, active_ap);
1364
1390
                }
 
1391
                add_access_point_other (panel);
1365
1392
                if (active_ap == NULL) {
1366
1393
                        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1367
1394
                                                                     "combobox_wireless_network_name"));
2187
2214
}
2188
2215
 
2189
2216
static void
 
2217
connect_to_hidden_network_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
 
2218
{
 
2219
        GError *error = NULL;
 
2220
        GVariant *result = NULL;
 
2221
 
 
2222
        result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
 
2223
        if (result == NULL) {
 
2224
                g_warning ("failed to connect to hidden network: %s",
 
2225
                           error->message);
 
2226
                g_error_free (error);
 
2227
                return;
 
2228
        }
 
2229
}
 
2230
 
 
2231
static void
 
2232
connect_to_hidden_network (CcNetworkPanel *panel)
 
2233
{
 
2234
        GDBusProxy *proxy;
 
2235
        GVariant *res = NULL;
 
2236
        GError *error = NULL;
 
2237
 
 
2238
        /* connect to NM applet */
 
2239
        proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
 
2240
                                               G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
 
2241
                                               G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
 
2242
                                               NULL,
 
2243
                                               "org.gnome.network_manager_applet",
 
2244
                                               "/org/gnome/network_manager_applet",
 
2245
                                               "org.gnome.network_manager_applet",
 
2246
                                               panel->priv->cancellable,
 
2247
                                               &error);
 
2248
        if (proxy == NULL) {
 
2249
                g_warning ("failed to connect to NM applet: %s",
 
2250
                           error->message);
 
2251
                g_error_free (error);
 
2252
                goto out;
 
2253
        }
 
2254
 
 
2255
        /* try to show the hidden network UI */
 
2256
        g_dbus_proxy_call (proxy,
 
2257
                           "ConnectToHiddenNetwork",
 
2258
                           NULL,
 
2259
                           G_DBUS_CALL_FLAGS_NONE,
 
2260
                           5000, /* don't wait forever */
 
2261
                           panel->priv->cancellable,
 
2262
                           connect_to_hidden_network_cb,
 
2263
                           panel);
 
2264
out:
 
2265
        if (proxy != NULL)
 
2266
                g_object_unref (proxy);
 
2267
        if (res != NULL)
 
2268
                g_variant_unref (res);
 
2269
}
 
2270
 
 
2271
static void
2190
2272
wireless_ap_changed_cb (GtkComboBox *combo_box, CcNetworkPanel *panel)
2191
2273
{
2192
2274
        const GByteArray *ssid;
2227
2309
                            -1);
2228
2310
        g_debug ("try to connect to WIFI network %s [%s]",
2229
2311
                 ssid_target, object_path);
 
2312
        if (g_strcmp0 (object_path, "ap-other...") == 0) {
 
2313
                connect_to_hidden_network (panel);
 
2314
                goto out;
 
2315
        }
2230
2316
 
2231
2317
        /* look for an existing connection we can use */
2232
2318
        list = nm_remote_settings_list_connections (panel->priv->remote_settings);
2276
2362
        g_free (object_path);
2277
2363
}
2278
2364
 
 
2365
static gint
 
2366
wireless_ap_model_sort_cb (GtkTreeModel *model,
 
2367
                           GtkTreeIter *a,
 
2368
                           GtkTreeIter *b,
 
2369
                           gpointer user_data)
 
2370
{
 
2371
        gchar *str_a;
 
2372
        gchar *str_b;
 
2373
        gint retval;
 
2374
 
 
2375
        gtk_tree_model_get (model, a,
 
2376
                            PANEL_WIRELESS_COLUMN_SORT, &str_a,
 
2377
                            -1);
 
2378
        gtk_tree_model_get (model, b,
 
2379
                            PANEL_WIRELESS_COLUMN_SORT, &str_b,
 
2380
                            -1);
 
2381
 
 
2382
        /* special case blank entries to the bottom */
 
2383
        if (g_strcmp0 (str_a, "") == 0) {
 
2384
                retval = 1;
 
2385
                goto out;
 
2386
        }
 
2387
        if (g_strcmp0 (str_b, "") == 0) {
 
2388
                retval = -1;
 
2389
                goto out;
 
2390
        }
 
2391
 
 
2392
        /* case sensitive search like before */
 
2393
        g_debug ("compare %s with %s", str_a, str_b);
 
2394
        retval = g_strcmp0 (str_a, str_b);
 
2395
out:
 
2396
        g_free (str_a);
 
2397
        g_free (str_b);
 
2398
        return retval;
 
2399
}
 
2400
 
2279
2401
static void
2280
2402
cc_network_panel_init (CcNetworkPanel *panel)
2281
2403
{
2437
2559
        gtk_tree_sortable_set_sort_column_id (sortable,
2438
2560
                                              PANEL_WIRELESS_COLUMN_SORT,
2439
2561
                                              GTK_SORT_ASCENDING);
 
2562
        gtk_tree_sortable_set_sort_func (sortable,
 
2563
                                         PANEL_WIRELESS_COLUMN_SORT,
 
2564
                                         wireless_ap_model_sort_cb,
 
2565
                                         sortable,
 
2566
                                         NULL);
2440
2567
 
2441
2568
        renderer = panel_cell_renderer_signal_new ();
2442
2569
        gtk_cell_renderer_set_padding (renderer, 4, 0);