Commit 3fb65309 authored by Benjamin Berg's avatar Benjamin Berg

network: Move AP list population into an idle handler

The AP list needs to be updated every time APs are added or removed.
However, such addition and removal generally happens in bulk (i.e. scan
results coming in) and doing so for every AP is wasteful.

So update the widget from an idle handler instead of updating it
immediately from the signal handler.

Fixes #152
parent 996fd237
Pipeline #40355 passed with stages
in 2 minutes and 33 seconds
......@@ -51,7 +51,7 @@ typedef enum {
static void nm_device_wifi_refresh_ui (NetDeviceWifi *device_wifi);
static void show_wifi_list (NetDeviceWifi *device_wifi);
static void populate_ap_list (NetDeviceWifi *device_wifi);
static void queue_populate_ap_list (NetDeviceWifi *device_wifi);
static void show_hotspot_ui (NetDeviceWifi *device_wifi);
struct _NetDeviceWifiPrivate
......@@ -64,6 +64,7 @@ struct _NetDeviceWifiPrivate
gchar *selected_connection_id;
gchar *selected_ap_id;
guint scan_id;
guint populate_id;
GCancellable *cancellable;
};
......@@ -299,7 +300,7 @@ net_device_wifi_access_point_added (NMDeviceWifi *nm_device_wifi,
{
NetDeviceWifi *device_wifi = NET_DEVICE_WIFI (user_data);
populate_ap_list (device_wifi);
queue_populate_ap_list (device_wifi);
nm_device_wifi_connect_access_points (nm_device_wifi, device_wifi);
}
......@@ -310,7 +311,7 @@ net_device_wifi_access_point_removed (NMDeviceWifi *nm_device_wifi,
{
NetDeviceWifi *device_wifi = NET_DEVICE_WIFI (user_data);
populate_ap_list (device_wifi);
queue_populate_ap_list (device_wifi);
}
static void
......@@ -708,7 +709,7 @@ nm_device_wifi_refresh_ui (NetDeviceWifi *device_wifi)
/* update list of APs */
show_wifi_list (device_wifi);
populate_ap_list (device_wifi);
queue_populate_ap_list (device_wifi);
}
static void
......@@ -1520,7 +1521,7 @@ client_connection_added_cb (NMClient *client,
return;
}
populate_ap_list (device_wifi);
queue_populate_ap_list (device_wifi);
show_wifi_list (device_wifi);
}
......@@ -1615,6 +1616,10 @@ net_device_wifi_finalize (GObject *object)
NetDeviceWifi *device_wifi = NET_DEVICE_WIFI (object);
NetDeviceWifiPrivate *priv = device_wifi->priv;
if (priv->populate_id) {
g_source_remove (priv->populate_id);
priv->populate_id = 0;
}
if (priv->cancellable) {
g_cancellable_cancel (priv->cancellable);
g_clear_object (&priv->cancellable);
......@@ -1687,7 +1692,7 @@ really_forgotten (GObject *source_object,
}
/* remove the entry from the list */
populate_ap_list (user_data);
queue_populate_ap_list (user_data);
}
static void
......@@ -2220,6 +2225,30 @@ populate_ap_list (NetDeviceWifi *device_wifi)
g_ptr_array_free (aps_unique, TRUE);
}
static gboolean
populate_ap_list_idle_cb (NetDeviceWifi *device_wifi)
{
NetDeviceWifiPrivate *priv = device_wifi->priv;
populate_ap_list (device_wifi);
priv->populate_id = 0;
return G_SOURCE_REMOVE;
}
static void
queue_populate_ap_list (NetDeviceWifi *device_wifi)
{
NetDeviceWifiPrivate *priv = device_wifi->priv;
if (priv->populate_id)
return;
/* Using the default idle could cause higher CPU usage. */
priv->populate_id = g_idle_add_full (G_PRIORITY_DEFAULT,
(GSourceFunc) populate_ap_list_idle_cb,
device_wifi,
NULL);
}
static void
ap_activated (GtkListBox *list, GtkListBoxRow *row, NetDeviceWifi *device_wifi)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment