[network-manager-applet/jk/bluetooth-editor: 1/3] editor: Add support for editing Bluetooth connections
- From: Jiří Klimeš <jklimes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/jk/bluetooth-editor: 1/3] editor: Add support for editing Bluetooth connections
- Date: Mon, 13 Oct 2014 16:37:36 +0000 (UTC)
commit fdd9b97bd9b6df59f0aed4c827b8635d21197b7d
Author: Lubomir Rintel <lkundrak v3 sk>
Date: Mon Sep 29 07:52:32 2014 +0200
editor: Add support for editing Bluetooth connections
Only existing DUN & PAN connections, no creation of new ones.
src/connection-editor/Makefile.am | 3 +
src/connection-editor/ce-page-bluetooth.ui | 42 ++++++
src/connection-editor/nm-connection-editor.c | 13 ++
src/connection-editor/page-bluetooth.c | 179 ++++++++++++++++++++++++++
src/connection-editor/page-bluetooth.h | 63 +++++++++
5 files changed, 300 insertions(+), 0 deletions(-)
---
diff --git a/src/connection-editor/Makefile.am b/src/connection-editor/Makefile.am
index 89923e7..a597458 100644
--- a/src/connection-editor/Makefile.am
+++ b/src/connection-editor/Makefile.am
@@ -48,6 +48,8 @@ nm_connection_editor_SOURCES = \
page-dsl.c \
page-mobile.h \
page-mobile.c \
+ page-bluetooth.h \
+ page-bluetooth.c \
page-ppp.h \
page-ppp.c \
page-vpn.h \
@@ -114,6 +116,7 @@ ui_DATA = \
ce-ip6-routes.ui \
ce-page-dsl.ui \
ce-page-mobile.ui \
+ ce-page-bluetooth.ui \
ce-page-ppp.ui \
ce-ppp-auth-methods.ui \
ce-page-vlan.ui \
diff --git a/src/connection-editor/ce-page-bluetooth.ui b/src/connection-editor/ce-page-bluetooth.ui
new file mode 100644
index 0000000..b378586
--- /dev/null
+++ b/src/connection-editor/ce-page-bluetooth.ui
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <!-- interface-naming-policy toplevel-contextual -->
+ <object class="GtkTable" id="BluetoothPage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">12</property>
+ <property name="n_columns">2</property>
+ <property name="column_spacing">12</property>
+ <property name="row_spacing">6</property>
+ <child>
+ <object class="GtkEntry" id="bluetooth_bdaddr">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="primary_icon_activatable">False</property>
+ <property name="secondary_icon_activatable">False</property>
+ <property name="primary_icon_sensitive">True</property>
+ <property name="secondary_icon_sensitive">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="y_options"/>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label26">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">_Device:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">bluetooth_bdaddr</property>
+ </object>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"/>
+ </packing>
+ </child>
+ </object>
+</interface>
diff --git a/src/connection-editor/nm-connection-editor.c b/src/connection-editor/nm-connection-editor.c
index bdc63a7..269446c 100644
--- a/src/connection-editor/nm-connection-editor.c
+++ b/src/connection-editor/nm-connection-editor.c
@@ -67,6 +67,7 @@
#include "page-ip6.h"
#include "page-dsl.h"
#include "page-mobile.h"
+#include "page-bluetooth.h"
#include "page-ppp.h"
#include "page-vpn.h"
#include "page-wimax.h"
@@ -778,6 +779,18 @@ nm_connection_editor_set_connection (NMConnectionEditor *editor,
goto out;
if (!add_page (editor, ce_page_ppp_new, editor->connection, error))
goto out;
+ } else if (!strcmp (connection_type, NM_SETTING_BLUETOOTH_SETTING_NAME)) {
+ NMSettingBluetooth *s_bt = nm_connection_get_setting_bluetooth (editor->connection);
+ const char *type = nm_setting_bluetooth_get_connection_type (s_bt);
+
+ if (!add_page (editor, ce_page_bluetooth_new, editor->connection, error))
+ goto out;
+ if (!strcmp (type, "dun")) {
+ if (!add_page (editor, ce_page_mobile_new, editor->connection, error))
+ goto out;
+ if (!add_page (editor, ce_page_ppp_new, editor->connection, error))
+ goto out;
+ }
} else if (!strcmp (connection_type, NM_SETTING_WIMAX_SETTING_NAME)) {
if (!add_page (editor, ce_page_wimax_new, editor->connection, error))
goto out;
diff --git a/src/connection-editor/page-bluetooth.c b/src/connection-editor/page-bluetooth.c
new file mode 100644
index 0000000..cfce857
--- /dev/null
+++ b/src/connection-editor/page-bluetooth.c
@@ -0,0 +1,179 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Connection editor -- Connection editor for NetworkManager
+ *
+ * Lubomir Rintel <lkundrak v3 sk>
+ *
+ * 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 2014 Red Hat, Inc.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+
+#include <nm-setting-connection.h>
+#include <nm-setting-bluetooth.h>
+#include <nm-setting-ppp.h>
+#include <nm-setting-wired.h>
+
+#include "page-bluetooth.h"
+#include "nm-connection-editor.h"
+
+G_DEFINE_TYPE (CEPageBluetooth, ce_page_bluetooth, CE_TYPE_PAGE)
+
+#define CE_PAGE_BLUETOOTH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CE_TYPE_PAGE_BLUETOOTH,
CEPageBluetoothPrivate))
+
+typedef struct {
+ NMSettingBluetooth *setting;
+
+ GtkEntry *bdaddr;
+
+ gboolean disposed;
+} CEPageBluetoothPrivate;
+
+static void
+bluetooth_private_init (CEPageBluetooth *self)
+{
+ CEPageBluetoothPrivate *priv = CE_PAGE_BLUETOOTH_GET_PRIVATE (self);
+ GtkBuilder *builder;
+
+ builder = CE_PAGE (self)->builder;
+
+ priv->bdaddr = GTK_ENTRY (gtk_builder_get_object (builder, "bluetooth_bdaddr"));
+
+}
+
+static void
+populate_ui (CEPageBluetooth *self, NMConnection *connection)
+{
+ CEPageBluetoothPrivate *priv = CE_PAGE_BLUETOOTH_GET_PRIVATE (self);
+ NMSettingBluetooth *setting = priv->setting;
+
+ ce_page_mac_to_entry (nm_setting_bluetooth_get_bdaddr (setting),
+ ARPHRD_ETHER, priv->bdaddr);
+}
+
+static void
+stuff_changed (GtkEditable *editable, gpointer user_data)
+{
+ ce_page_changed (CE_PAGE (user_data));
+}
+
+static void
+finish_setup (CEPageBluetooth *self, gpointer unused, GError *error, gpointer user_data)
+{
+ CEPage *parent = CE_PAGE (self);
+ CEPageBluetoothPrivate *priv = CE_PAGE_BLUETOOTH_GET_PRIVATE (self);
+
+ if (error)
+ return;
+
+ populate_ui (self, parent->connection);
+
+ g_signal_connect (priv->bdaddr, "changed", G_CALLBACK (stuff_changed), self);
+}
+
+CEPage *
+ce_page_bluetooth_new (NMConnection *connection,
+ GtkWindow *parent_window,
+ NMClient *client,
+ NMRemoteSettings *settings,
+ const char **out_secrets_setting_name,
+ GError **error)
+{
+ CEPageBluetooth *self;
+ CEPageBluetoothPrivate *priv;
+
+ self = CE_PAGE_BLUETOOTH (ce_page_new (CE_TYPE_PAGE_BLUETOOTH,
+ connection,
+ parent_window,
+ client,
+ settings,
+ UIDIR "/ce-page-bluetooth.ui",
+ "BluetoothPage",
+ _("Bluetooth")));
+ if (!self) {
+ g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Could not load Bluetooth user
interface."));
+ return NULL;
+ }
+
+ bluetooth_private_init (self);
+ priv = CE_PAGE_BLUETOOTH_GET_PRIVATE (self);
+
+ priv->setting = nm_connection_get_setting_bluetooth (connection);
+ if (!priv->setting) {
+ priv->setting = NM_SETTING_BLUETOOTH (nm_setting_bluetooth_new ());
+ nm_connection_add_setting (connection, NM_SETTING (priv->setting));
+ }
+
+ g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL);
+
+ *out_secrets_setting_name = NM_SETTING_BLUETOOTH_SETTING_NAME;
+
+ return CE_PAGE (self);
+}
+
+static void
+ui_to_setting (CEPageBluetooth *self)
+{
+ CEPageBluetoothPrivate *priv = CE_PAGE_BLUETOOTH_GET_PRIVATE (self);
+ GByteArray *bdaddr;
+
+ bdaddr = ce_page_entry_to_mac (priv->bdaddr, ARPHRD_ETHER, NULL);
+ g_object_set (priv->setting,
+ NM_SETTING_BLUETOOTH_BDADDR, bdaddr,
+ NULL);
+ if (bdaddr)
+ g_byte_array_free (bdaddr, TRUE);
+}
+
+static gboolean
+validate (CEPage *page, NMConnection *connection, GError **error)
+{
+ CEPageBluetooth *self = CE_PAGE_BLUETOOTH (page);
+ CEPageBluetoothPrivate *priv = CE_PAGE_BLUETOOTH_GET_PRIVATE (self);
+ GByteArray *bdaddr;
+ gboolean invalid;
+
+ bdaddr = ce_page_entry_to_mac (priv->bdaddr, ARPHRD_ETHER, &invalid);
+ if (invalid)
+ return FALSE;
+ if (bdaddr)
+ g_byte_array_free (bdaddr, TRUE);
+
+ ui_to_setting (self);
+ return nm_setting_verify (NM_SETTING (priv->setting), NULL, error);
+}
+
+static void
+ce_page_bluetooth_init (CEPageBluetooth *self)
+{
+}
+
+static void
+ce_page_bluetooth_class_init (CEPageBluetoothClass *bluetooth_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (bluetooth_class);
+ CEPageClass *parent_class = CE_PAGE_CLASS (bluetooth_class);
+
+ g_type_class_add_private (object_class, sizeof (CEPageBluetoothPrivate));
+
+ /* virtual methods */
+ parent_class->validate = validate;
+}
diff --git a/src/connection-editor/page-bluetooth.h b/src/connection-editor/page-bluetooth.h
new file mode 100644
index 0000000..202d0c9
--- /dev/null
+++ b/src/connection-editor/page-bluetooth.h
@@ -0,0 +1,63 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Connection editor -- Connection editor for NetworkManager
+ *
+ * Lubomir Rintel <lkundrak v3 sk>
+ *
+ * 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 2014 Red Hat, Inc.
+ */
+
+#ifndef __PAGE_BLUETOOTH_H__
+#define __PAGE_BLUETOOTH_H__
+
+#include <nm-connection.h>
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "ce-page.h"
+
+#define CE_TYPE_PAGE_BLUETOOTH (ce_page_bluetooth_get_type ())
+#define CE_PAGE_BLUETOOTH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CE_TYPE_PAGE_BLUETOOTH,
CEPageBluetooth))
+#define CE_PAGE_BLUETOOTH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CE_TYPE_PAGE_BLUETOOTH,
CEPageBluetoothClass))
+#define CE_IS_PAGE_BLUETOOTH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CE_TYPE_PAGE_BLUETOOTH))
+#define CE_IS_PAGE_BLUETOOTH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CE_TYPE_PAGE_BLUETOOTH))
+#define CE_PAGE_BLUETOOTH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CE_TYPE_PAGE_BLUETOOTH,
CEPageBluetoothClass))
+
+typedef struct {
+ CEPage parent;
+} CEPageBluetooth;
+
+typedef struct {
+ CEPageClass parent;
+} CEPageBluetoothClass;
+
+GType ce_page_bluetooth_get_type (void);
+
+CEPage *ce_page_bluetooth_new (NMConnection *connection,
+ GtkWindow *parent,
+ NMClient *client,
+ NMRemoteSettings *settings,
+ const char **out_secrets_setting_name,
+ GError **error);
+
+void bluetooth_connection_new (GtkWindow *parent,
+ const char *detail,
+ NMRemoteSettings *settings,
+ PageNewConnectionResultFunc result_func,
+ gpointer user_data);
+
+#endif /* __PAGE_BLUETOOTH_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]