network: Split the mobile broadband device from the .c and .ui file

This commit is contained in:
Richard Hughes 2012-07-20 09:21:57 +01:00
parent 62b8a4c8bb
commit 26b5169bee
5 changed files with 636 additions and 759 deletions

View file

@ -22,6 +22,8 @@ libnetwork_la_SOURCES = \
net-device.h \
net-device-wired.c \
net-device-wired.h \
net-device-mobile.c \
net-device-mobile.h \
net-vpn.c \
net-vpn.h \
net-proxy.c \
@ -45,6 +47,7 @@ dist_ui_DATA = \
network-proxy.ui \
network-vpn.ui \
network-wired.ui \
network-mobile.ui \
network.ui
@INTLTOOL_DESKTOP_RULE@

View file

@ -46,6 +46,7 @@
#include "net-object.h"
#include "net-device.h"
#include "net-device-wired.h"
#include "net-device-mobile.h"
#include "net-proxy.h"
#include "net-vpn.h"
@ -312,108 +313,6 @@ select_tree_iter (CcNetworkPanel *panel, GtkTreeIter *iter)
gtk_tree_selection_select_iter (selection, iter);
}
static void
panel_device_got_modem_manager_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GError *error = NULL;
GVariant *result = NULL;
GDBusProxy *proxy;
NMDevice *device = (NMDevice *) user_data;
proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
if (proxy == NULL) {
g_warning ("Error creating ModemManager proxy: %s",
error->message);
g_error_free (error);
goto out;
}
/* get the IMEI */
result = g_dbus_proxy_get_cached_property (proxy,
"EquipmentIdentifier");
/* save */
g_object_set_data_full (G_OBJECT (device),
"ControlCenter::EquipmentIdentifier",
g_variant_dup_string (result, NULL),
g_free);
out:
if (result != NULL)
g_variant_unref (result);
if (proxy != NULL)
g_object_unref (proxy);
}
static void
panel_get_registration_info_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
gchar *operator_code = NULL;
GError *error = NULL;
guint registration_status;
GVariant *result = NULL;
gchar *operator_name = NULL;
gchar *operator_name_safe = NULL;
NMDevice *device = (NMDevice *) user_data;
result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
if (result == NULL) {
g_warning ("Error getting registration info: %s\n",
error->message);
g_error_free (error);
return;
}
/* get values */
g_variant_get (result, "((uss))",
&registration_status,
&operator_code,
&operator_name);
if (operator_name != NULL && operator_name[0] != '\0')
operator_name_safe = g_strescape (operator_name, NULL);
/* save */
g_object_set_data_full (G_OBJECT (device),
"ControlCenter::OperatorName",
operator_name_safe,
g_free);
g_free (operator_name);
g_free (operator_code);
g_variant_unref (result);
}
static void
panel_device_got_modem_manager_gsm_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GError *error = NULL;
GDBusProxy *proxy;
NMDevice *device = (NMDevice *) user_data;
proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
if (proxy == NULL) {
g_warning ("Error creating ModemManager GSM proxy: %s\n",
error->message);
g_error_free (error);
goto out;
}
g_dbus_proxy_call (proxy,
"GetRegistrationInfo",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
panel_get_registration_info_cb,
device);
out:
if (proxy != NULL)
g_object_unref (proxy);
}
static void
device_state_notify_changed_cb (NMDevice *device,
GParamSpec *pspec,
@ -553,33 +452,14 @@ panel_add_device (CcNetworkPanel *panel, NMDevice *device)
g_signal_connect_object (G_OBJECT (device), "notify::state",
(GCallback) device_state_notify_changed_cb, panel, 0);
/* do we have to get additonal data from ModemManager */
if (type == NM_DEVICE_TYPE_MODEM) {
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"org.freedesktop.ModemManager",
nm_device_get_udi (device),
"org.freedesktop.ModemManager.Modem",
panel->priv->cancellable,
panel_device_got_modem_manager_cb,
device);
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"org.freedesktop.ModemManager",
nm_device_get_udi (device),
"org.freedesktop.ModemManager.Modem.Gsm.Network",
panel->priv->cancellable,
panel_device_got_modem_manager_gsm_cb,
device);
}
/* map the NMDeviceType to the GType */
switch (type) {
case NM_DEVICE_TYPE_ETHERNET:
device_g_type = NET_TYPE_DEVICE_WIRED;
break;
case NM_DEVICE_TYPE_MODEM:
device_g_type = NET_TYPE_DEVICE_MOBILE;
break;
default:
device_g_type = NET_TYPE_DEVICE;
break;
@ -1200,33 +1080,6 @@ wimax_enabled_toggled (NMClient *client,
panel->priv->updating_device = FALSE;
}
static void
mobilebb_enabled_toggled (NMClient *client,
GParamSpec *pspec,
CcNetworkPanel *panel)
{
gboolean enabled;
GtkSwitch *sw;
NMDevice *device;
NetObject *object;
object = get_selected_object (panel);
if (object == NULL)
return;
device = net_device_get_nm_device (NET_DEVICE (object));
if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_MODEM)
return;
enabled = nm_client_wwan_get_enabled (client);
sw = GTK_SWITCH (gtk_builder_get_object (panel->priv->builder,
"device_mobilebb_off_switch"));
panel->priv->updating_device = TRUE;
gtk_switch_set_active (sw, enabled);
panel->priv->updating_device = FALSE;
}
static gboolean
device_is_hotspot (CcNetworkPanel *panel,
NMDevice *device)
@ -1397,8 +1250,6 @@ refresh_header_ui (CcNetworkPanel *panel, NMDevice *device, const char *page_nam
wimax_enabled_toggled (panel->priv->client, NULL, panel);
break;
case NM_DEVICE_TYPE_MODEM:
gtk_widget_show (widget);
mobilebb_enabled_toggled (panel->priv->client, NULL, panel);
break;
default:
gtk_widget_hide (widget);
@ -1575,101 +1426,6 @@ device_refresh_wimax_ui (CcNetworkPanel *panel, NetDevice *device)
refresh_header_ui (panel, nm_device, "wimax");
}
static void
device_add_device_connections (CcNetworkPanel *panel,
NMDevice *nm_device,
GtkListStore *liststore,
GtkComboBox *combobox)
{
CcNetworkPanelPrivate *priv = panel->priv;
GSList *filtered;
GSList *list, *l;
GtkTreeIter treeiter;
NMActiveConnection *active_connection;
NMConnection *connection;
/* get the list of available connections for this device */
list = nm_remote_settings_list_connections (panel->priv->remote_settings);
filtered = nm_device_filter_connections (nm_device, list);
gtk_list_store_clear (liststore);
active_connection = nm_device_get_active_connection (nm_device);
for (l = filtered; l; l = g_slist_next (l)) {
connection = NM_CONNECTION (l->data);
gtk_list_store_append (liststore, &treeiter);
gtk_list_store_set (liststore,
&treeiter,
PANEL_MOBILEBB_COLUMN_ID, nm_connection_get_uuid (connection),
PANEL_MOBILEBB_COLUMN_TITLE, nm_connection_get_id (connection),
-1);
/* is this already activated? */
if (active_connection != NULL &&
g_strcmp0 (nm_connection_get_path (connection),
nm_active_connection_get_connection (active_connection)) == 0) {
priv->updating_device = TRUE;
gtk_combo_box_set_active_iter (combobox, &treeiter);
priv->updating_device = FALSE;
}
}
/* add new connection entry */
gtk_list_store_append (liststore, &treeiter);
gtk_list_store_set (liststore,
&treeiter,
PANEL_MOBILEBB_COLUMN_ID, NULL,
PANEL_MOBILEBB_COLUMN_TITLE, _("Add new connection"),
-1);
g_slist_free (list);
g_slist_free (filtered);
}
static void
device_refresh_modem_ui (CcNetworkPanel *panel, NetDevice *device)
{
CcNetworkPanelPrivate *priv = panel->priv;
NMDeviceModemCapabilities caps;
NMDevice *nm_device;
const char *str;
GtkListStore *liststore;
GtkWidget *widget;
nm_device = net_device_get_nm_device (device);
refresh_header_ui (panel, nm_device, "mobilebb");
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (nm_device));
if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
(caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)) {
/* IMEI */
str = g_object_get_data (G_OBJECT (nm_device),
"ControlCenter::EquipmentIdentifier");
panel_set_widget_data (panel,
"mobilebb",
"imei",
str);
/* operator name */
str = g_object_get_data (G_OBJECT (nm_device),
"ControlCenter::OperatorName");
panel_set_widget_data (panel,
"mobilebb",
"provider",
str);
}
/* add possible connections to device */
liststore = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
"liststore_mobile_connections"));
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "combobox_mobilebb_network"));
device_add_device_connections (panel,
nm_device,
liststore,
GTK_COMBO_BOX (widget));
}
static void
nm_device_refresh_device_ui (CcNetworkPanel *panel, NetDevice *device)
{
@ -1706,17 +1462,6 @@ nm_device_refresh_device_ui (CcNetworkPanel *panel, NetDevice *device)
device_refresh_wimax_ui (panel, device);
break;
case NM_DEVICE_TYPE_MODEM:
{
NMDeviceModemCapabilities caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (nm_device));
if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
(caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)) {
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 1);
sub_pane = "mobilebb";
device_refresh_modem_ui (panel, device);
} else {
g_warning ("unknown modem capabilities: %i", caps);
}
}
break;
default:
g_assert_not_reached ();
@ -2475,61 +2220,6 @@ connect_to_hidden_network (CcNetworkPanel *panel)
cc_network_panel_connect_to_hidden_network (panel, priv->client, priv->remote_settings);
}
static void
mobile_connection_changed_cb (GtkComboBox *combo_box, CcNetworkPanel *panel)
{
gboolean ret;
gchar *object_path = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
NetObject *object;
NMConnection *connection;
NMDevice *device;
if (panel->priv->updating_device)
goto out;
ret = gtk_combo_box_get_active_iter (combo_box, &iter);
if (!ret)
goto out;
object = get_selected_object (panel);
if (object == NULL)
goto out;
device = net_device_get_nm_device (NET_DEVICE (object));
if (device == NULL)
goto out;
/* get entry */
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
gtk_tree_model_get (model, &iter,
PANEL_MOBILEBB_COLUMN_ID, &object_path,
-1);
if (g_strcmp0 (object_path, NULL) == 0) {
cc_network_panel_connect_to_3g_network (panel,
panel->priv->client,
panel->priv->remote_settings,
device);
goto out;
}
/* activate the connection */
g_debug ("try to switch to connection %s", object_path);
connection = (NMConnection*) nm_remote_settings_get_connection_by_path (panel->priv->remote_settings,
object_path);
if (connection != NULL) {
nm_device_disconnect (device, NULL, NULL);
nm_client_activate_connection (panel->priv->client,
connection,
device, NULL,
connection_activate_cb, panel);
goto out;
}
out:
g_free (object_path);
}
static void
wireless_ap_changed_cb (GtkComboBox *combo_box, CcNetworkPanel *panel)
{
@ -3160,20 +2850,6 @@ cc_network_panel_init (CcNetworkPanel *panel)
/* add the virtual proxy device */
panel_add_proxy_device (panel);
/* setup mobile combobox model */
combobox = GTK_COMBO_BOX (gtk_builder_get_object (panel->priv->builder,
"combobox_mobilebb_network"));
g_signal_connect (combobox, "changed",
G_CALLBACK (mobile_connection_changed_cb),
panel);
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
renderer,
FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
"text", PANEL_MOBILEBB_COLUMN_TITLE,
NULL);
/* setup wireless combobox model */
combobox = GTK_COMBO_BOX (gtk_builder_get_object (panel->priv->builder,
"combobox_wireless_network_name"));
@ -3235,17 +2911,11 @@ cc_network_panel_init (CcNetworkPanel *panel)
"device_wireless_off_switch"));
g_signal_connect (widget, "notify::active",
G_CALLBACK (device_off_toggled), panel);
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
"device_mobilebb_off_switch"));
g_signal_connect (widget, "notify::active",
G_CALLBACK (device_off_toggled), panel);
g_signal_connect (panel->priv->client, "notify::wireless-enabled",
G_CALLBACK (wireless_enabled_toggled), panel);
g_signal_connect (panel->priv->client, "notify::wimax-enabled",
G_CALLBACK (wimax_enabled_toggled), panel);
g_signal_connect (panel->priv->client, "notify::wwan-enabled",
G_CALLBACK (mobilebb_enabled_toggled), panel);
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
"start_hotspot_button"));
@ -3261,11 +2931,6 @@ cc_network_panel_init (CcNetworkPanel *panel)
g_signal_connect (widget, "clicked",
G_CALLBACK (edit_connection), panel);
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
"button_mobilebb_options"));
g_signal_connect (widget, "clicked",
G_CALLBACK (edit_connection), panel);
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
"add_toolbutton"));
g_signal_connect (widget, "clicked",

View file

@ -0,0 +1,570 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2011-2012 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include <glib-object.h>
#include <glib/gi18n.h>
#include <nm-client.h>
#include <nm-device.h>
#include <nm-device-modem.h>
#include <nm-remote-connection.h>
#include "panel-common.h"
#include "net-device-mobile.h"
#define NET_DEVICE_MOBILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NET_TYPE_DEVICE_MOBILE, NetDeviceMobilePrivate))
static void nm_device_mobile_refresh_ui (NetDeviceMobile *device_mobile);
struct _NetDeviceMobilePrivate
{
GtkBuilder *builder;
gboolean updating_device;
};
enum {
COLUMN_ID,
COLUMN_TITLE,
COLUMN_LAST
};
G_DEFINE_TYPE (NetDeviceMobile, net_device_mobile, NET_TYPE_DEVICE)
static GtkWidget *
device_mobile_proxy_add_to_notebook (NetObject *object,
GtkNotebook *notebook,
GtkSizeGroup *heading_size_group)
{
GtkWidget *widget;
GtkWindow *window;
NetDeviceMobile *device_mobile = NET_DEVICE_MOBILE (object);
/* add widgets to size group */
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder,
"heading_imei"));
gtk_size_group_add_widget (heading_size_group, widget);
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder,
"heading_network"));
gtk_size_group_add_widget (heading_size_group, widget);
/* reparent */
window = GTK_WINDOW (gtk_builder_get_object (device_mobile->priv->builder,
"window_tmp"));
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder,
"vbox7"));
g_object_ref (widget);
gtk_container_remove (GTK_CONTAINER (window), widget);
gtk_notebook_append_page (notebook, widget, NULL);
g_object_unref (widget);
return widget;
}
static void
connection_activate_cb (NMClient *client,
NMActiveConnection *connection,
GError *error,
gpointer user_data)
{
NetDeviceMobile *device_mobile = NET_DEVICE_MOBILE (user_data);
if (connection == NULL) {
/* failed to activate */
nm_device_mobile_refresh_ui (device_mobile);
}
}
static void
mobile_connection_changed_cb (GtkComboBox *combo_box, NetDeviceMobile *device_mobile)
{
gboolean ret;
gchar *object_path = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
NMConnection *connection;
NMDevice *device;
NMClient *client;
NMRemoteSettings *remote_settings;
if (device_mobile->priv->updating_device)
goto out;
ret = gtk_combo_box_get_active_iter (combo_box, &iter);
if (!ret)
goto out;
device = net_device_get_nm_device (NET_DEVICE (device_mobile));
if (device == NULL)
goto out;
client = net_object_get_client (NET_OBJECT (device_mobile));
remote_settings = net_object_get_remote_settings (NET_OBJECT (device_mobile));
/* get entry */
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
gtk_tree_model_get (model, &iter,
COLUMN_ID, &object_path,
-1);
if (g_strcmp0 (object_path, NULL) == 0) {
#if 0
cc_network_panel_connect_to_3g_network (panel,
client,
remote_settings,
device);
#endif
goto out;
}
/* activate the connection */
g_debug ("try to switch to connection %s", object_path);
connection = (NMConnection*) nm_remote_settings_get_connection_by_path (remote_settings,
object_path);
if (connection != NULL) {
nm_device_disconnect (device, NULL, NULL);
nm_client_activate_connection (client,
connection,
device, NULL,
connection_activate_cb,
device_mobile);
goto out;
}
out:
g_free (object_path);
}
static void
mobilebb_enabled_toggled (NMClient *client,
GParamSpec *pspec,
NetDeviceMobile *device_mobile)
{
gboolean enabled;
GtkSwitch *sw;
NMDevice *device;
device = net_device_get_nm_device (NET_DEVICE (device_mobile));
if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_MODEM)
return;
enabled = nm_client_wwan_get_enabled (client);
sw = GTK_SWITCH (gtk_builder_get_object (device_mobile->priv->builder,
"device_off_switch"));
device_mobile->priv->updating_device = TRUE;
gtk_switch_set_active (sw, enabled);
device_mobile->priv->updating_device = FALSE;
}
static void
device_add_device_connections (NetDeviceMobile *device_mobile,
NMDevice *nm_device,
GtkListStore *liststore,
GtkComboBox *combobox)
{
NetDeviceMobilePrivate *priv = device_mobile->priv;
GSList *filtered;
GSList *list, *l;
GtkTreeIter treeiter;
NMActiveConnection *active_connection;
NMConnection *connection;
NMRemoteSettings *remote_settings;
/* get the list of available connections for this device */
remote_settings = net_object_get_remote_settings (NET_OBJECT (device_mobile));
g_assert (remote_settings != NULL);
list = nm_remote_settings_list_connections (remote_settings);
filtered = nm_device_filter_connections (nm_device, list);
gtk_list_store_clear (liststore);
active_connection = nm_device_get_active_connection (nm_device);
for (l = filtered; l; l = g_slist_next (l)) {
connection = NM_CONNECTION (l->data);
gtk_list_store_append (liststore, &treeiter);
gtk_list_store_set (liststore,
&treeiter,
COLUMN_ID, nm_connection_get_uuid (connection),
COLUMN_TITLE, nm_connection_get_id (connection),
-1);
/* is this already activated? */
if (active_connection != NULL &&
g_strcmp0 (nm_connection_get_path (connection),
nm_active_connection_get_connection (active_connection)) == 0) {
priv->updating_device = TRUE;
gtk_combo_box_set_active_iter (combobox, &treeiter);
priv->updating_device = FALSE;
}
}
/* add new connection entry */
gtk_list_store_append (liststore, &treeiter);
gtk_list_store_set (liststore,
&treeiter,
COLUMN_ID, NULL,
COLUMN_TITLE, _("Add new connection"),
-1);
g_slist_free (list);
g_slist_free (filtered);
}
static void
nm_device_mobile_refresh_ui (NetDeviceMobile *device_mobile)
{
const char *str;
gboolean is_connected;
GString *status;
GtkListStore *liststore;
GtkWidget *widget;
guint speed = 0;
NetDeviceMobilePrivate *priv = device_mobile->priv;
NMClient *client;
NMDeviceModemCapabilities caps;
NMDevice *nm_device;
/* set device kind */
nm_device = net_device_get_nm_device (NET_DEVICE (device_mobile));
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder, "label_device"));
gtk_label_set_label (GTK_LABEL (widget),
panel_device_to_localized_string (nm_device));
/* set up the device on/off switch */
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder, "device_off_switch"));
gtk_widget_show (widget);
client = net_object_get_client (NET_OBJECT (device_mobile));
mobilebb_enabled_toggled (client, NULL, device_mobile);
/* set device state, with status and optionally speed */
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder, "label_status"));
status = g_string_new (panel_device_state_to_localized_string (nm_device));
if (speed > 0) {
g_string_append (status, " - ");
/* Translators: network device speed */
g_string_append_printf (status, _("%d Mb/s"), speed);
}
gtk_label_set_label (GTK_LABEL (widget), status->str);
g_string_free (status, TRUE);
gtk_widget_set_tooltip_text (widget, panel_device_state_reason_to_localized_string (nm_device));
/* sensitive for other connection types if the device is currently connected */
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder,
"button_options"));
is_connected = net_device_get_find_connection (NET_DEVICE (device_mobile)) != NULL;
gtk_widget_set_sensitive (widget, is_connected);
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (nm_device));
if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
(caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)) {
/* IMEI */
str = g_object_get_data (G_OBJECT (nm_device),
"ControlCenter::EquipmentIdentifier");
panel_set_device_widget_details (device_mobile->priv->builder,
"imei",
str);
/* operator name */
str = g_object_get_data (G_OBJECT (nm_device),
"ControlCenter::OperatorName");
panel_set_device_widget_details (device_mobile->priv->builder,
"provider",
str);
}
/* add possible connections to device */
liststore = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
"liststore_mobile_connections"));
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "combobox_network"));
device_add_device_connections (device_mobile,
nm_device,
liststore,
GTK_COMBO_BOX (widget));
/* set IP entries */
panel_set_device_widgets (priv->builder, nm_device);
}
static void
device_mobile_refresh (NetObject *object)
{
NetDeviceMobile *device_mobile = NET_DEVICE_MOBILE (object);
nm_device_mobile_refresh_ui (device_mobile);
}
static void
device_off_toggled (GtkSwitch *sw,
GParamSpec *pspec,
NetDeviceMobile *device_mobile)
{
const gchar *path;
const GPtrArray *acs;
gboolean active;
gint i;
NMActiveConnection *a;
NMConnection *connection;
NMClient *client;
if (device_mobile->priv->updating_device)
return;
active = gtk_switch_get_active (sw);
if (active) {
client = net_object_get_client (NET_OBJECT (device_mobile));
connection = net_device_get_find_connection (NET_DEVICE (device_mobile));
if (connection == NULL)
return;
nm_client_activate_connection (client,
connection, NULL, NULL,
NULL, NULL);
} else {
connection = net_device_get_find_connection (NET_DEVICE (device_mobile));
if (connection == NULL)
return;
path = nm_connection_get_path (connection);
client = net_object_get_client (NET_OBJECT (device_mobile));
acs = nm_client_get_active_connections (client);
for (i = 0; i < acs->len; i++) {
a = (NMActiveConnection*)acs->pdata[i];
if (strcmp (nm_active_connection_get_connection (a), path) == 0) {
nm_client_deactivate_connection (client, a);
break;
}
}
}
}
static void
edit_connection (GtkButton *button, NetDeviceMobile *device_mobile)
{
net_object_edit (NET_OBJECT (device_mobile));
}
static void
device_mobile_device_got_modem_manager_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GError *error = NULL;
GVariant *result = NULL;
GDBusProxy *proxy;
NMDevice *device = (NMDevice *) user_data;
proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
if (proxy == NULL) {
g_warning ("Error creating ModemManager proxy: %s",
error->message);
g_error_free (error);
goto out;
}
/* get the IMEI */
result = g_dbus_proxy_get_cached_property (proxy,
"EquipmentIdentifier");
/* save */
g_object_set_data_full (G_OBJECT (device),
"ControlCenter::EquipmentIdentifier",
g_variant_dup_string (result, NULL),
g_free);
out:
if (result != NULL)
g_variant_unref (result);
if (proxy != NULL)
g_object_unref (proxy);
}
static void
device_mobile_get_registration_info_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
gchar *operator_code = NULL;
GError *error = NULL;
guint registration_status;
GVariant *result = NULL;
gchar *operator_name = NULL;
gchar *operator_name_safe = NULL;
NMDevice *device = (NMDevice *) user_data;
result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
if (result == NULL) {
g_warning ("Error getting registration info: %s\n",
error->message);
g_error_free (error);
return;
}
/* get values */
g_variant_get (result, "((uss))",
&registration_status,
&operator_code,
&operator_name);
if (operator_name != NULL && operator_name[0] != '\0')
operator_name_safe = g_strescape (operator_name, NULL);
/* save */
g_object_set_data_full (G_OBJECT (device),
"ControlCenter::OperatorName",
operator_name_safe,
g_free);
g_free (operator_name);
g_free (operator_code);
g_variant_unref (result);
}
static void
device_mobile_device_got_modem_manager_gsm_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GError *error = NULL;
GDBusProxy *proxy;
NMDevice *device = (NMDevice *) user_data;
proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
if (proxy == NULL) {
g_warning ("Error creating ModemManager GSM proxy: %s\n",
error->message);
g_error_free (error);
goto out;
}
g_dbus_proxy_call (proxy,
"GetRegistrationInfo",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
device_mobile_get_registration_info_cb,
device);
out:
if (proxy != NULL)
g_object_unref (proxy);
}
static void
net_device_mobile_constructed (GObject *object)
{
GCancellable *cancellable;
NetDeviceMobile *device_mobile = NET_DEVICE_MOBILE (object);
NMClient *client;
NMDevice *device;
G_OBJECT_CLASS (net_device_mobile_parent_class)->constructed (object);
device = net_device_get_nm_device (NET_DEVICE (device_mobile));
cancellable = net_object_get_cancellable (NET_OBJECT (device_mobile));
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"org.freedesktop.ModemManager",
nm_device_get_udi (device),
"org.freedesktop.ModemManager.Modem",
cancellable,
device_mobile_device_got_modem_manager_cb,
device);
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"org.freedesktop.ModemManager",
nm_device_get_udi (device),
"org.freedesktop.ModemManager.Modem.Gsm.Network",
cancellable,
device_mobile_device_got_modem_manager_gsm_cb,
device);
client = net_object_get_client (NET_OBJECT (device_mobile));
g_signal_connect (client, "notify::wwan-enabled",
G_CALLBACK (mobilebb_enabled_toggled),
device_mobile);
nm_device_mobile_refresh_ui (device_mobile);
}
static void
net_device_mobile_finalize (GObject *object)
{
NetDeviceMobile *device_mobile = NET_DEVICE_MOBILE (object);
NetDeviceMobilePrivate *priv = device_mobile->priv;
g_object_unref (priv->builder);
G_OBJECT_CLASS (net_device_mobile_parent_class)->finalize (object);
}
static void
net_device_mobile_class_init (NetDeviceMobileClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NetObjectClass *parent_class = NET_OBJECT_CLASS (klass);
object_class->finalize = net_device_mobile_finalize;
object_class->constructed = net_device_mobile_constructed;
parent_class->add_to_notebook = device_mobile_proxy_add_to_notebook;
parent_class->refresh = device_mobile_refresh;
g_type_class_add_private (klass, sizeof (NetDeviceMobilePrivate));
}
static void
net_device_mobile_init (NetDeviceMobile *device_mobile)
{
GError *error = NULL;
GtkWidget *widget;
GtkCellRenderer *renderer;
GtkComboBox *combobox;
device_mobile->priv = NET_DEVICE_MOBILE_GET_PRIVATE (device_mobile);
device_mobile->priv->builder = gtk_builder_new ();
gtk_builder_add_from_file (device_mobile->priv->builder,
GNOMECC_UI_DIR "/network-mobile.ui",
&error);
if (error != NULL) {
g_warning ("Could not load interface file: %s", error->message);
g_error_free (error);
return;
}
/* setup mobile combobox model */
combobox = GTK_COMBO_BOX (gtk_builder_get_object (device_mobile->priv->builder,
"combobox_network"));
g_signal_connect (combobox, "changed",
G_CALLBACK (mobile_connection_changed_cb),
device_mobile);
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
renderer,
FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
"text", COLUMN_TITLE,
NULL);
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder,
"device_off_switch"));
g_signal_connect (widget, "notify::active",
G_CALLBACK (device_off_toggled), device_mobile);
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder,
"button_options"));
g_signal_connect (widget, "clicked",
G_CALLBACK (edit_connection), device_mobile);
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder,
"device_off_switch"));
g_signal_connect (widget, "notify::active",
G_CALLBACK (device_off_toggled), device_mobile);
}

View file

@ -0,0 +1,59 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2011-2012 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __NET_DEVICE_MOBILE_H
#define __NET_DEVICE_MOBILE_H
#include <glib-object.h>
#include "net-device.h"
#include "nm-connection.h"
G_BEGIN_DECLS
#define NET_TYPE_DEVICE_MOBILE (net_device_mobile_get_type ())
#define NET_DEVICE_MOBILE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), NET_TYPE_DEVICE_MOBILE, NetDeviceMobile))
#define NET_DEVICE_MOBILE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), NET_TYPE_DEVICE_MOBILE, NetDeviceMobileClass))
#define NET_IS_DEVICE_MOBILE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), NET_TYPE_DEVICE_MOBILE))
#define NET_IS_DEVICE_MOBILE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), NET_TYPE_DEVICE_MOBILE))
#define NET_DEVICE_MOBILE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), NET_TYPE_DEVICE_MOBILE, NetDeviceMobileClass))
typedef struct _NetDeviceMobilePrivate NetDeviceMobilePrivate;
typedef struct _NetDeviceMobile NetDeviceMobile;
typedef struct _NetDeviceMobileClass NetDeviceMobileClass;
struct _NetDeviceMobile
{
NetDevice parent;
NetDeviceMobilePrivate *priv;
};
struct _NetDeviceMobileClass
{
NetDeviceClass parent_class;
};
GType net_device_mobile_get_type (void);
G_END_DECLS
#endif /* __NET_DEVICE_MOBILE_H */

View file

@ -863,425 +863,6 @@
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox7">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">12</property>
<property name="spacing">6</property>
<child>
<object class="GtkGrid" id="grid3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">start</property>
<property name="row_spacing">10</property>
<property name="column_spacing">6</property>
<child>
<object class="GtkImage" id="image_mobilebb_device">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="valign">start</property>
<property name="xalign">1</property>
<property name="pixel_size">48</property>
<property name="icon_name">network-cellular-connected-symbolic</property>
<property name="icon-size">6</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox11">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">start</property>
<property name="hexpand">True</property>
<property name="spacing">3</property>
<child>
<object class="GtkLabel" id="label_mobilebb_device">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label">Mobile Broadband</property>
<property name="ellipsize">end</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.2"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_mobilebb_status">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label">Not connected</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="heading_mobilebb_imei">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">IMEI</property>
<property name="mnemonic_widget">label_mobilebb_imei</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="heading_mobilebb_provider">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Provider</property>
<property name="mnemonic_widget">label_mobilebb_provider</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_mobilebb_imei">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label">1234567890</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">2</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_mobilebb_provider">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label">SuperTel Supremo </property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
<property name="width">2</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_mobilebb_ipv4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label">127.0.0.1</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
<property name="width">2</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_mobilebb_ipv6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
<property name="width">2</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_mobilebb_route">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">6</property>
<property name="width">2</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_mobilebb_dns">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">7</property>
<property name="width">2</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkAlignment" id="alignment_mobilebb_switch">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="valign">start</property>
<child>
<object class="GtkSwitch" id="device_mobilebb_off_switch">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
<property name="valign">start</property>
<property name="use_action_appearance">False</property>
<child internal-child="accessible">
<object class="AtkObject" id="mobilebb_off_a11y">
<property name="accessible-name" translatable="yes">Device Off</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="heading_mobilebb_ipv4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">IP Address</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="heading_mobilebb_ipv6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">IPv6 Address</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="heading_mobilebb_route">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Default Route</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">6</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="heading_mobilebb_dns">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="yalign">0</property>
<property name="label" translatable="yes">DNS</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">7</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="heading_mobilebb_network">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="yalign">0.5</property>
<property name="label" translatable="yes">Network</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="combobox_mobilebb_network">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="model">liststore_mobile_connections</property>
<property name="entry_text_column">1</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkAlignment" id="alignment3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="yalign">1</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="top_padding">12</property>
<child>
<object class="GtkButton" id="button_mobilebb_options">
<property name="label" translatable="yes">_Options...</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="label17">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">mobilebb</property>
</object>
<packing>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
</child>
<child type="tab">
<object class="GtkLabel" id="label55">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">vpn</property>
</object>
<packing>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
</child>
<child type="tab">
<object class="GtkLabel" id="label46">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">proxy</property>
</object>
<packing>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="label37">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">other</property>
</object>
<packing>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
@ -1309,7 +890,6 @@
<object class="GtkSizeGroup" id="sizegroup1">
<widgets>
<widget name="heading_wireless_mac"/>
<widget name="heading_mobilebb_imei"/>
</widgets>
</object>
</interface>