[network-manager-applet] applet: add InfiniBand device support (rh #867273)
- From: Jiří Klimeš <jklimes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet] applet: add InfiniBand device support (rh #867273)
- Date: Fri, 31 May 2013 19:23:58 +0000 (UTC)
commit e80223407978318eea5accf86a87b36c98d20af3
Author: Jiří Klimeš <jklimes redhat com>
Date: Fri May 31 20:52:05 2013 +0200
applet: add InfiniBand device support (rh #867273)
po/POTFILES.in | 3 +-
src/Makefile.am | 2 +
src/applet-device-infiniband.c | 213 ++++++++++++++++++++++++++++++++++++++++
src/applet-device-infiniband.h | 30 ++++++
src/applet.c | 7 ++
src/applet.h | 1 +
6 files changed, 255 insertions(+), 1 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 115e5c5..daef9f3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -8,11 +8,12 @@ org.gnome.nm-applet.gschema.xml.in
src/applet.c
src/applet-device-bond.c
src/applet-device-bridge.c
+src/applet-device-broadband.c
src/applet-device-bt.c
src/applet-device-cdma.c
src/applet-device-ethernet.c
-src/applet-device-broadband.c
src/applet-device-gsm.c
+src/applet-device-infiniband.c
src/applet-device-vlan.c
src/applet-device-wifi.c
src/applet-device-wimax.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 23bae47..e9fd33b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -63,6 +63,8 @@ nm_applet_SOURCES = \
applet-device-bond.c \
applet-device-bridge.h \
applet-device-bridge.c \
+ applet-device-infiniband.h \
+ applet-device-infiniband.c \
fallback-icon.h \
shell-watcher.h \
shell-watcher.c
diff --git a/src/applet-device-infiniband.c b/src/applet-device-infiniband.c
new file mode 100644
index 0000000..d72cb09
--- /dev/null
+++ b/src/applet-device-infiniband.c
@@ -0,0 +1,213 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Applet -- allow user control over networking
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * 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.
+ *
+ * (C) Copyright 2013 Red Hat, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include <nm-device.h>
+#include <nm-setting-connection.h>
+#include <nm-setting-infiniband.h>
+#include <nm-device-infiniband.h>
+#include <nm-utils.h>
+
+#include "applet.h"
+#include "applet-device-infiniband.h"
+#include "nm-ui-utils.h"
+
+#define DEFAULT_INFINIBAND_NAME _("Auto InfiniBand")
+
+static gboolean
+infiniband_new_auto_connection (NMDevice *device,
+ gpointer dclass_data,
+ AppletNewAutoConnectionCallback callback,
+ gpointer callback_data)
+{
+ NMConnection *connection;
+ NMSettingInfiniband *s_infiniband = NULL;
+ NMSettingConnection *s_con;
+ char *uuid;
+
+ connection = nm_connection_new ();
+
+ s_infiniband = NM_SETTING_INFINIBAND (nm_setting_infiniband_new ());
+ nm_connection_add_setting (connection, NM_SETTING (s_infiniband));
+
+ s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
+ uuid = nm_utils_uuid_generate ();
+ g_object_set (s_con,
+ NM_SETTING_CONNECTION_ID, DEFAULT_INFINIBAND_NAME,
+ NM_SETTING_CONNECTION_TYPE, NM_SETTING_INFINIBAND_SETTING_NAME,
+ NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
+ NM_SETTING_CONNECTION_UUID, uuid,
+ NULL);
+ g_free (uuid);
+
+ nm_connection_add_setting (connection, NM_SETTING (s_con));
+
+ (*callback) (connection, TRUE, FALSE, callback_data);
+ return TRUE;
+}
+
+static void
+infiniband_add_menu_item (NMDevice *device,
+ gboolean multiple_devices,
+ GSList *connections,
+ NMConnection *active,
+ GtkWidget *menu,
+ NMApplet *applet)
+{
+ char *text;
+ GtkWidget *item;
+ gboolean carrier = TRUE;
+
+ if (multiple_devices) {
+ const char *desc;
+
+ desc = nma_utils_get_device_description (device);
+
+ if (g_slist_length (connections) > 1)
+ text = g_strdup_printf (_("InfiniBand Networks (%s)"), desc);
+ else
+ text = g_strdup_printf (_("InfiniBand Network (%s)"), desc);
+ } else {
+ if (g_slist_length (connections) > 1)
+ text = g_strdup (_("InfiniBand Networks"));
+ else
+ text = g_strdup (_("InfiniBand Network"));
+ }
+
+ item = applet_menu_item_create_device_item_helper (device, applet, text);
+ g_free (text);
+
+ /* Only dim the item if the device supports carrier detection AND
+ * we know it doesn't have a link.
+ */
+ if (nm_device_get_capabilities (device) & NM_DEVICE_CAP_CARRIER_DETECT)
+ carrier = nm_device_infiniband_get_carrier (NM_DEVICE_INFINIBAND (device));
+
+ gtk_widget_set_sensitive (item, FALSE);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+ if (g_slist_length (connections))
+ applet_add_connection_items (device, connections, carrier, active, NMA_ADD_ACTIVE, menu,
applet);
+
+ /* Notify user of unmanaged or unavailable device */
+ item = nma_menu_device_get_menu_item (device, applet, carrier ? NULL : _("disconnected"));
+ if (item) {
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+ }
+
+ if (!nma_menu_device_check_unusable (device)) {
+ if ((!active && g_slist_length (connections)) || (active && g_slist_length (connections) > 1))
+ applet_menu_item_add_complex_separator_helper (menu, applet, _("Available"), -1);
+
+ if (g_slist_length (connections))
+ applet_add_connection_items (device, connections, carrier, active, NMA_ADD_INACTIVE,
menu, applet);
+ else
+ applet_add_default_connection_item (device, DEFAULT_INFINIBAND_NAME, carrier, menu,
applet);
+ }
+}
+
+static void
+infiniband_notify_connected (NMDevice *device,
+ const char *msg,
+ NMApplet *applet)
+{
+ applet_do_notify_with_pref (applet,
+ _("Connection Established"),
+ msg ? msg : _("You are now connected to the InfiniBand network."),
+ "nm-device-wired",
+ PREF_DISABLE_CONNECTED_NOTIFICATIONS);
+}
+
+static GdkPixbuf *
+infiniband_get_icon (NMDevice *device,
+ NMDeviceState state,
+ NMConnection *connection,
+ char **tip,
+ NMApplet *applet)
+{
+ NMSettingConnection *s_con;
+ GdkPixbuf *pixbuf = NULL;
+ const char *id;
+
+ id = nm_device_get_iface (NM_DEVICE (device));
+ if (connection) {
+ s_con = nm_connection_get_setting_connection (connection);
+ id = nm_setting_connection_get_id (s_con);
+ }
+
+ switch (state) {
+ case NM_DEVICE_STATE_PREPARE:
+ *tip = g_strdup_printf (_("Preparing InfiniBand connection '%s'..."), id);
+ break;
+ case NM_DEVICE_STATE_CONFIG:
+ *tip = g_strdup_printf (_("Configuring InfiniBand connection '%s'..."), id);
+ break;
+ case NM_DEVICE_STATE_NEED_AUTH:
+ *tip = g_strdup_printf (_("User authentication required for InfiniBand connection '%s'..."),
id);
+ break;
+ case NM_DEVICE_STATE_IP_CONFIG:
+ *tip = g_strdup_printf (_("Requesting address for '%s'..."), id);
+ break;
+ case NM_DEVICE_STATE_ACTIVATED:
+ pixbuf = nma_icon_check_and_load ("nm-device-wired", &applet->ethernet_icon, applet);
+ *tip = g_strdup_printf (_("InfiniBand connection '%s' active"), id);
+ break;
+ default:
+ break;
+ }
+
+ return pixbuf ? g_object_ref (pixbuf) : NULL;
+}
+
+
+static gboolean
+infiniband_get_secrets (SecretsRequest *req, GError **error)
+{
+ /* No 802.1X possible yet on InfiniBand */
+ return FALSE;
+}
+
+NMADeviceClass *
+applet_device_infiniband_get_class (NMApplet *applet)
+{
+ NMADeviceClass *dclass;
+
+ dclass = g_slice_new0 (NMADeviceClass);
+ if (!dclass)
+ return NULL;
+
+ dclass->new_auto_connection = infiniband_new_auto_connection;
+ dclass->add_menu_item = infiniband_add_menu_item;
+ dclass->notify_connected = infiniband_notify_connected;
+ dclass->get_icon = infiniband_get_icon;
+ dclass->get_secrets = infiniband_get_secrets;
+
+ return dclass;
+}
diff --git a/src/applet-device-infiniband.h b/src/applet-device-infiniband.h
new file mode 100644
index 0000000..4622955
--- /dev/null
+++ b/src/applet-device-infiniband.h
@@ -0,0 +1,30 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * 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.
+ *
+ * (C) Copyright 2013 Red Hat, Inc.
+ */
+
+#ifndef __APPLET_DEVICE_INFINIBAND_H__
+#define __APPLET_DEVICE_INFINIBAND_H__
+
+#include "applet.h"
+
+NMADeviceClass *applet_device_infiniband_get_class (NMApplet *applet);
+
+#endif /* __APPLET_DEVICE_INFINIBAND_H__ */
diff --git a/src/applet.c b/src/applet.c
index 9ffaafe..6c3e87b 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -76,6 +76,7 @@
#include "applet-device-bt.h"
#include "applet-device-cdma.h"
#include "applet-device-ethernet.h"
+#include "applet-device-infiniband.h"
#include "applet-device-gsm.h"
#include "applet-device-vlan.h"
#include "applet-device-wifi.h"
@@ -271,6 +272,8 @@ get_device_class (NMDevice *device, NMApplet *applet)
return applet->bond_class;
else if (NM_IS_DEVICE_BRIDGE (device))
return applet->bridge_class;
+ else if (NM_IS_DEVICE_INFINIBAND (device))
+ return applet->infiniband_class;
else
g_debug ("%s: Unknown device type '%s'", __func__, G_OBJECT_TYPE_NAME (device));
return NULL;
@@ -3723,6 +3726,9 @@ constructor (GType type,
applet->bridge_class = applet_device_bridge_get_class (applet);
g_assert (applet->bridge_class);
+ applet->infiniband_class = applet_device_infiniband_get_class (applet);
+ g_assert (applet->infiniband_class);
+
foo_client_setup (applet);
#if WITH_MODEM_MANAGER_1
@@ -3768,6 +3774,7 @@ static void finalize (GObject *object)
g_slice_free (NMADeviceClass, applet->vlan_class);
g_slice_free (NMADeviceClass, applet->bond_class);
g_slice_free (NMADeviceClass, applet->bridge_class);
+ g_slice_free (NMADeviceClass, applet->infiniband_class);
if (applet->update_icon_id)
g_source_remove (applet->update_icon_id);
diff --git a/src/applet.h b/src/applet.h
index 1040fe5..c567367 100644
--- a/src/applet.h
+++ b/src/applet.h
@@ -119,6 +119,7 @@ typedef struct
NMADeviceClass *vlan_class;
NMADeviceClass *bond_class;
NMADeviceClass *bridge_class;
+ NMADeviceClass *infiniband_class;
/* Data model elements */
guint update_icon_id;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]