wifi: Hide when no Wi-Fi adapter is available

It's WIP.
parent 10cf920f
......@@ -23,6 +23,8 @@
#include "net-device-wifi.h"
#include "network-dialogs.h"
#include "shell/cc-application.h"
#include "shell/cc-debug.h"
#include "shell/cc-object-storage.h"
#include "list-box-helper.h"
......@@ -81,6 +83,67 @@ enum
N_PROPS
};
/* Static init function */
static void
update_panel_visibility (NMClient *client)
{
const GPtrArray *devices;
CcApplication *application;
gboolean visible;
guint i;
CC_TRACE_MSG ("Updating Wi-Fi panel visibility");
devices = nm_client_get_devices (client);
visible = FALSE;
for (i = 0; devices && i < devices->len; i++)
{
NMDevice *device = g_ptr_array_index (devices, i);
visible |= NM_IS_DEVICE_WIFI (device);
if (visible)
break;
}
/* Set the new visibility */
application = CC_APPLICATION (g_application_get_default ());
cc_shell_model_set_panel_visibility (cc_application_get_model (application),
"wifi",
visible ? CC_PANEL_VISIBLE : CC_PANEL_VISIBLE_IN_SEARCH);
CC_TRACE_MSG ("Wi-Fi panel visible: %s", visible ? "yes" : "no");
}
void
cc_wifi_panel_static_init_func (void)
{
NMClient *client;
g_debug ("Monitoring NetworkManager for Wi-Fi devices");
/* Create and store a NMClient instance if it doesn't exist yet */
if (!cc_object_storage_has_object (CC_OBJECT_NMCLIENT))
{
client = nm_client_new (NULL, NULL);
cc_object_storage_add_object (CC_OBJECT_NMCLIENT, client);
g_object_unref (client);
}
client = cc_object_storage_get_object (CC_OBJECT_NMCLIENT);
/* Update the panel visibility and monitor for changes */
g_signal_connect (client, "device-added", G_CALLBACK (update_panel_visibility), NULL);
g_signal_connect (client, "device-removed", G_CALLBACK (update_panel_visibility), NULL);
update_panel_visibility (client);
g_object_unref (client);
}
/* Auxiliary methods */
static void
......
......@@ -28,6 +28,8 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (CcWifiPanel, cc_wifi_panel, CC, WIFI_PANEL, CcPanel)
void cc_wifi_panel_static_init_func (void);
G_END_DECLS
#endif /* CC_WIFI_PANEL_H */
......
......@@ -64,6 +64,11 @@ extern GType cc_user_panel_get_type (void);
extern GType cc_wacom_panel_get_type (void);
#endif /* BUILD_WACOM */
/* Static init functions */
#ifdef BUILD_NETWORK
extern void cc_wifi_panel_static_init_func (void);
#endif /* BUILD_NETWORK */
#define PANEL_TYPE(name, get_type, init_func) { name, get_type, init_func }
#else /* CC_PANEL_LOADER_NO_GTYPES */
......@@ -93,7 +98,7 @@ static struct {
PANEL_TYPE("mouse", cc_mouse_panel_get_type, NULL),
#ifdef BUILD_NETWORK
PANEL_TYPE("network", cc_network_panel_get_type, NULL),
PANEL_TYPE("wifi", cc_wifi_panel_get_type, NULL),
PANEL_TYPE("wifi", cc_wifi_panel_get_type, cc_wifi_panel_static_init_func),
#endif
PANEL_TYPE("notifications", cc_notifications_panel_get_type, NULL),
PANEL_TYPE("online-accounts", cc_goa_panel_get_type, NULL),
......
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