on xenial help sign in
Remove old Network Indicator code.
commite805de9036ca451ad94cacf5b2ee3423e48d0227 authorMichał Sawicz <michal.sawicz@canonical.com> dateMon 30 Sep 2013, 22:22 (13 years ago) parent1344ba3
12 files changed−1045
Panel/Indicators/NetworkIndicatorPage.qml−82 Panel/IndicatorsDataModel.qml−2 plugins/Unity/Indicators/Network/CMakeLists.txt−44 plugins/Unity/Indicators/Network/networkagent.cpp−146 plugins/Unity/Indicators/Network/networkagent.h−65 plugins/Unity/Indicators/Network/plugin.cpp−31 plugins/Unity/Indicators/Network/plugin.h−32 plugins/Unity/Indicators/Network/qml/PasswordPage.qml−88 plugins/Unity/Indicators/Network/qml/PasswordTextField.qml−68 plugins/Unity/Indicators/Network/qml/qmldir−3 plugins/Unity/Indicators/Network/secret-agent.c−382 plugins/Unity/Indicators/Network/secret-agent.h−102
Panel/Indicators/NetworkIndicatorPage.qmldeleted−82
@@ -1,82 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors:
17− * Renato Araujo Oliveira Filho <renato@canonical.com>
18− */
19−
20−import QtQuick 2.0
21−import Unity.Indicators 0.1 as Indicators
22−import Unity.Indicators.Network 0.1 as ICNetwork
23−import Ubuntu.Components 0.1
24−
25−PageStack {
26− id: networkPage
27− // Stops the search for a parent tree node.
28− // We don't want it going up to the indicator tabs.
29− // FIXME: need a better way of doing this.
30− // https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1211704
31− __propagated: null
32−
33− property alias title: _mainPage.title
34− property alias emptyText: pluginItem.emptyText
35− property alias busName: pluginItem.busName
36− property alias actionsObjectPath : pluginItem.actionsObjectPath
37− property alias menuObjectPaths : pluginItem.menuObjectPaths
38−
39− anchors.fill: parent
40−
41− Page {
42− id: _mainPage
43−
44− Indicators.IndicatorPage {
45− id: pluginItem
46− anchors.fill: parent
47− }
48− }
49−
50− Component {
51− id: passwordPageComponent
52−
53− ICNetwork.PasswordPage {
54− agent: networkAgent
55− }
56− }
57−
58− ICNetwork.NetworkAgent {
59− id: networkAgent
60−
61− onSecretRequested: {
62− networkPage.push(passwordPageComponent, {"token": token});
63− }
64− }
65−
66− function start()
67− {
68− push(_mainPage);
69− pluginItem.start();
70− }
71−
72− function stop()
73− {
74− clear();
75− pluginItem.stop();
76− }
77−
78− function reset()
79− {
80− pluginItem.reset();
81− }
82−}
Panel/IndicatorsDataModel.qml−2
@@ -46,8 +46,6 @@ Indicators.IndicatorsModel {
4646 'indicator-network' : {
4747 'title': 'Networks',
4848 'description' : '',
49− 'widgetSource' : ApplicationPaths.shellAppDirectory()+'/Panel/Indicators/DefaultIndicatorWidget.qml',
50− 'pageSource' : ApplicationPaths.shellAppDirectory()+'/Panel/Indicators/NetworkIndicatorPage.qml'
5149 },
5250 'indicator-power' : {
5351 'title': 'Battery',
plugins/Unity/Indicators/Network/CMakeLists.txt−44
@@ -1,45 +1 @@
1−# export_qmlplugin macro
2−include(Plugins)
3−
4−project(IndicatorsNetworkQml)
5−
6−pkg_check_modules(GLIB glib-2.0>=2.32)
7−pkg_check_modules(LIBNM_GLIB libnm-glib>=0.9.6)
8−pkg_check_modules(LIBNM_UTIL libnm-util>=0.9.6)
9−
10−if(LIBNM_GLIB_FOUND AND LIBNM_UTIL_FOUND AND GLIB_FOUND)
11− set(INDICATORS_NETWORK_SRC
12− networkagent.cpp
13− plugin.cpp
14− secret-agent.c
15− )
16−
17− add_library(IndicatorsNetworkQml MODULE
18− ${INDICATORS_NETWORK_SRC}
19− )
20−
21− qt5_use_modules(IndicatorsNetworkQml Core Qml Widgets)
22−
23− set_target_properties(IndicatorsNetworkQml PROPERTIES COMPILE_FLAGS -fPIC)
24−
25− include_directories(
26− ${CMAKE_CURRENT_SOURCE_DIR}
27− ${GLIB_INCLUDE_DIRS}
28− ${LIBNM_GLIB_INCLUDE_DIRS}
29− ${LIBNM_UTIL_INCLUDE_DIRS}
30− )
31−
32− target_link_libraries(IndicatorsNetworkQml
33− ${GLIB_LIBRARIES}
34− ${LIBNM_GLIB_LIBRARIES}
35− ${LIBNM_UTIL_LIBRARIES}
36− )
37−
38− # export the qmltypes and plugin files
39− export_qmlplugin(Unity.Indicators.Network 0.1 Unity/Indicators/Network TARGETS IndicatorsNetworkQml)
40−
41−else()
42− message(WARNING "Missing glib or libnm dependency for the network plugin, not building")
43−endif()
44−
451add_subdirectory(qml)
plugins/Unity/Indicators/Network/networkagent.cppdeleted−146
@@ -1,146 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors:
17− * Alberto Ruiz <alberto.ruiz@canonical.com>
18− * Renato Araujo Oliveira Filho <renato@canonical.com>
19− */
20−
21−#include "networkagent.h"
22−
23−#include <QVariant>
24−#include <QApplication>
25−#include <QDebug>
26−
27−class NetworkAgentToken
28−{
29−public:
30− NMConnection *connection;
31− NMSettingWirelessSecurity *wisec;
32− guint id;
33− QByteArray keyMgmt;
34−
35− NetworkAgentToken(NMConnection *connection,
36− NMSettingWirelessSecurity *wisec,
37− guint id,
38− QByteArray keyMgmt)
39− : connection(connection),
40− wisec(wisec),
41− id(id),
42− keyMgmt(keyMgmt)
43− {
44− if (connection) {
45− g_object_ref(connection);
46− } else {
47− qWarning() << "invalid connection object";
48− }
49− }
50−
51− ~NetworkAgentToken()
52− {
53− if (connection) {
54− g_object_unref(connection);
55− }
56− }
57−};
58−
59−NetworkAgent::NetworkAgent(QObject *parent)
60− : QObject(parent)
61−{
62− m_agent = unity_settings_secret_agent_new();
63− g_signal_connect(G_OBJECT(m_agent),
64− UNITY_SETTINGS_SECRET_AGENT_SECRET_REQUESTED,
65− G_CALLBACK(onSecretRequested),
66− this);
67−
68− g_signal_connect(G_OBJECT(m_agent),
69− UNITY_SETTINGS_SECRET_AGENT_REQUEST_CANCELLED,
70− G_CALLBACK(onSecretRequestCancelled),
71− this);
72−}
73−
74−NetworkAgent::~NetworkAgent()
75−{
76− nm_secret_agent_unregister(NM_SECRET_AGENT(m_agent));
77− g_object_unref(m_agent);
78−}
79−
80−void NetworkAgent::authenticate(const QVariant &token, const QString &key)
81−{
82− NetworkAgentToken *pToken = (NetworkAgentToken *) token.value<void *>();
83− if (pToken == NULL) {
84− return;
85− }
86−
87− if ((pToken->keyMgmt == "wpa-none") || (pToken->keyMgmt == "wpa-psk")) {
88− g_object_set(G_OBJECT(pToken->wisec),
89− NM_SETTING_WIRELESS_SECURITY_PSK, qPrintable(key),
90− NULL);
91− } else if (pToken->keyMgmt == "none") {
92− g_object_set(G_OBJECT(pToken->wisec),
93− NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, qPrintable(key),
94− NULL);
95− }
96−
97− GHashTable *settings = nm_connection_to_hash(pToken->connection,
98− NM_SETTING_HASH_FLAG_ALL);
99−
100− unity_settings_secret_agent_provide_secret(m_agent,
101− pToken->id, settings);
102− g_hash_table_unref(settings);
103− delete pToken;
104−}
105−
106−void NetworkAgent::cancel(const QVariant &token)
107−{
108− NetworkAgentToken *pToken = (NetworkAgentToken *) token.value<void *>();
109− if (pToken != NULL) {
110− unity_settings_secret_agent_cancel_request(m_agent, pToken->id);
111− delete pToken;
112− }
113−}
114−
115−void NetworkAgent::onSecretRequested(UnitySettingsSecretAgent* /*agent*/,
116− guint id,
117− NMConnection* connection,
118− const char* /*setting_name*/,
119− const char** /*hints*/,
120− NMSecretAgentGetSecretsFlags /*flags*/,
121− NetworkAgent* self)
122−{
123− NetworkAgentToken *token = new NetworkAgentToken(connection,
124− NULL,
125− id,
126− NULL);
127−
128− token->wisec = nm_connection_get_setting_wireless_security(connection);
129− if (token->wisec) {
130− token->keyMgmt = nm_setting_wireless_security_get_key_mgmt(token->wisec);
131− }
132−
133− QVariant varToken = qVariantFromValue((void *) token);
134− Q_EMIT self->secretRequested(varToken);
135−}
136−
137−void NetworkAgent::onSecretRequestCancelled(UnitySettingsSecretAgent* /*agent*/,
138− guint /*id*/,
139− NMConnection* /*connection*/,
140− const char* /*setting_name*/,
141− const char** /*hints*/,
142− NMSecretAgentGetSecretsFlags /*flags*/,
143− NetworkAgent* /*self*/)
144−{
145− //Do nothing for now
146−}
plugins/Unity/Indicators/Network/networkagent.hdeleted−65
@@ -1,65 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors:
17− * Alberto Ruiz <alberto.ruiz@canonical.com>
18− * Renato Araujo Oliveira Filho <renato@canonical.com>
19− */
20−
21−#ifndef NETWORKAGENT_H
22−#define NETWORKAGENT_H
23−
24−#include "secret-agent.h"
25−
26−#include <QObject>
27−
28−class NetworkAgentToken;
29−
30−class NetworkAgent : public QObject
31−{
32− Q_OBJECT
33−public:
34− NetworkAgent(QObject *parent=0);
35− ~NetworkAgent();
36−
37− Q_INVOKABLE void authenticate(const QVariant &token, const QString &key);
38− Q_INVOKABLE void cancel(const QVariant &token);
39−
40−Q_SIGNALS:
41− void secretRequested(const QVariant &token);
42− void secretRequestCancelled();
43−
44−private:
45− UnitySettingsSecretAgent *m_agent;
46−
47− static void onSecretRequested(UnitySettingsSecretAgent *agent,
48− guint id,
49− NMConnection *connection,
50− const char *setting_name,
51− const char **hints,
52− NMSecretAgentGetSecretsFlags flags,
53− NetworkAgent *self);
54−
55− static void onSecretRequestCancelled(UnitySettingsSecretAgent *agent,
56− guint id,
57− NMConnection *connection,
58− const char *setting_name,
59− const char **hints,
60− NMSecretAgentGetSecretsFlags flags,
61− NetworkAgent *self);
62−
63−};
64−
65−#endif
plugins/Unity/Indicators/Network/plugin.cppdeleted−31
@@ -1,31 +0,0 @@
1−/*
2− * Copyright (C) 2012 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Author: Nick Dedekind <nick.dedekind@canonical.com>
17− */
18−
19−// Qt
20−#include <QtQml/qqml.h>
21−
22−// self
23−#include "plugin.h"
24−
25−// local
26−#include "networkagent.h"
27−
28−void IndicatorsNetworkPlugin::registerTypes(const char *uri)
29−{
30− qmlRegisterType<NetworkAgent>(uri, 0, 1, "NetworkAgent");
31−}
plugins/Unity/Indicators/Network/plugin.hdeleted−32
@@ -1,32 +0,0 @@
1−/*
2− * Copyright (C) 2012 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Author: Nick Dedekind <nick.dedekind@canonical.com>
17− */
18−
19−#ifndef INDICATORS_NETWORK_PLUGIN_H
20−#define INDICATORS_NETWORK_PLUGIN_H
21−
22−#include <QtQml/QQmlExtensionPlugin>
23−
24−class IndicatorsNetworkPlugin : public QQmlExtensionPlugin
25−{
26− Q_OBJECT
27− Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
28−public:
29− void registerTypes(const char *uri);
30−};
31−
32−#endif // INDICATORS_NETWORK_PLUGIN_H
plugins/Unity/Indicators/Network/qml/PasswordPage.qmldeleted−88
@@ -1,88 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors:
17− * Renato Araujo Oliveira Filho <renato@canonical.com>
18− */
19−
20−import QtQuick 2.0
21−import Ubuntu.Components 0.1
22−import Ubuntu.Components.ListItems 0.1 as ListItem
23−import Unity.Indicators 0.1 as Indicators
24−
25−Page {
26− id: pagePassword
27−
28− property variant agent
29− property variant token
30−
31− anchors.fill: parent
32− title: "Network Authentication"
33−
34− Column {
35− anchors {
36− left: parent.left
37− right: parent.right
38− }
39−
40− Indicators.SectionMenuItem {
41− text: "Authentication"
42− }
43−
44− Indicators.FramedMenuItem {
45− implicitHeight: password.height + units.gu(1)
46−
47− PasswordTextField {
48− id: password
49− anchors {
50− left: parent.left
51− right: parent.right
52− margins: units.gu(3)
53− verticalCenter: parent.verticalCenter
54− }
55− }
56− }
57−
58− Indicators.FramedMenuItem {
59− Row {
60− anchors {
61− right: parent.right
62− verticalCenter: parent.verticalCenter
63− margins: units.gu(3)
64− }
65−
66− spacing: units.gu(1)
67−
68− Button {
69− text: "Cancel"
70− width: units.gu(10)
71− onClicked: {
72− agent.cancel(token);
73− pageStack.pop();
74− }
75− }
76−
77− Button {
78− text: "OK"
79− width: units.gu(10)
80− onClicked: {
81− agent.authenticate(token, password.text);
82− pageStack.pop();
83− }
84− }
85− }
86− }
87− }
88−}
plugins/Unity/Indicators/Network/qml/PasswordTextField.qmldeleted−68
@@ -1,68 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors:
17− * Renato Araujo Oliveira Filho <renato@canonical.com>
18− */
19−
20−import QtQuick 2.0
21−import Ubuntu.Components 0.1
22−
23−Item {
24− id: textMenu
25−
26− property alias text: textField.text
27−
28− height: contentColumn.height
29−
30− Column {
31− id: contentColumn
32− spacing: units.gu(0.5)
33− anchors {
34− left: parent.left
35− right: parent.right
36− }
37−
38− TextField {
39− id: textField
40−
41− anchors {
42− left: parent.left
43− right: parent.right
44− }
45−
46− placeholderText: "Password"
47− echoMode: showPassword.checked ? TextInput.Normal : TextInput.Password
48− }
49−
50− Row {
51− anchors {
52− left: parent.left
53− right: parent.right
54− }
55−
56− spacing: units.gu(1)
57−
58− CheckBox {
59− id: showPassword
60− }
61−
62− Label {
63− text: "Show password"
64− anchors.verticalCenter: showPassword.verticalCenter
65− }
66− }
67− }
68−}
plugins/Unity/Indicators/Network/qml/qmldir−3
@@ -2,7 +2,4 @@ module Unity.Indicators.Network
22plugin IndicatorsNetworkQml
33typeinfo plugin.qmltypes
44
5−NetworkPage 0.1 NetworkPage.qml
65AccessPoint 0.1 AccessPoint.qml
7−PasswordPage 0.1 PasswordPage.qml
8−PasswordTextField 0.1 PasswordTextField.qml
plugins/Unity/Indicators/Network/secret-agent.cdeleted−382
@@ -1,382 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors:
17− * Alberto Ruiz <alberto.ruiz@canonical.com>
18− * Renato Araujo Oliveira Filho <renato@canonical.com>
19− */
20−
21−
22−#include <glib.h>
23−#include <glib-object.h>
24−#include <nm-secret-agent.h>
25−#include "secret-agent.h"
26−
27−#define UNITY_SETTINGS_TYPE_SECRET_AGENT (unity_settings_secret_agent_get_type ())
28−#define UNITY_SETTINGS_SECRET_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UNITY_SETTINGS_TYPE_SECRET_AGENT, UnitySettingsSecretAgent))
29−#define UNITY_SETTINGS_SECRET_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UNITY_SETTINGS_TYPE_SECRET_AGENT, UnitySettingsSecretAgentClass))
30−#define UNITY_SETTINGS_IS_SECRET_AGENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UNITY_SETTINGS_TYPE_SECRET_AGENT))
31−#define UNITY_SETTINGS_IS_SECRET_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UNITY_SETTINGS_TYPE_SECRET_AGENT))
32−#define UNITY_SETTINGS_SECRET_AGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UNITY_SETTINGS_TYPE_SECRET_AGENT, UnitySettingsSecretAgentClass))
33−#define UNITY_SETTINGS_SECRET_AGENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UNITY_SETTINGS_TYPE_SECRET_AGENT, UnitySettingsSecretAgentPrivate))
34−
35−#define AGENT_ID "com.canonical.settings.network.nm-agent"
36−
37−static gpointer unity_settings_secret_agent_parent_class = NULL;
38−
39−typedef struct _UnitySettingsSecretAgentPrivate UnitySettingsSecretAgentPrivate;
40−
41−struct _UnitySettingsSecretAgentPrivate {
42− GQueue *requests;
43−};
44−
45−typedef struct _SecretRequest {
46− gint id;
47− NMSecretAgent *agent;
48− NMConnection *connection;
49− const char *connection_path;
50− const char *setting_name;
51− const char **hints;
52− NMSecretAgentGetSecretsFlags flags;
53− NMSecretAgentGetSecretsFunc callback;
54− gpointer callback_data;
55−} SecretRequest;
56−
57−GType unity_settings_secret_agent_get_type (void) G_GNUC_CONST;
58−enum {
59− UNITY_SETTINGS_SECRET_AGENT_DUMMY_PROPERTY
60−};
61−
62−enum {
63− SECRET_REQUESTED,
64− REQUEST_CANCELLED,
65− LAST_SIGNAL
66−};
67−
68−static guint signals[LAST_SIGNAL] = { 0 };
69−
70−UnitySettingsSecretAgent* unity_settings_secret_agent_new (void);
71−UnitySettingsSecretAgent* unity_settings_secret_agent_construct (GType object_type);
72−
73−int
74−secret_request_find (SecretRequest *req,
75− guint *id)
76−{
77− if (req->id > *id)
78− return -1;
79−
80− if (req->id < *id)
81− return 1;
82−
83− return 0;
84−}
85−
86−void
87−unity_settings_secret_agent_provide_secret (UnitySettingsSecretAgent *agent,
88− guint request,
89− GHashTable *secrets)
90−{
91− GList *iter;
92− SecretRequest *req;
93− UnitySettingsSecretAgentPrivate *priv = agent->priv;
94−
95− iter = g_queue_find_custom (priv->requests,
96− &request,
97− (GCompareFunc)secret_request_find);
98−
99− if (iter == NULL || iter->data == NULL)
100− {
101− g_warning ("Secret request with id <%d> was not found", (int)request);
102− return;
103− }
104−
105− req = iter->data;
106−
107− req->callback (NM_SECRET_AGENT (agent),
108− req->connection,
109− secrets,
110− NULL,
111− req->callback_data);
112−
113− g_queue_remove_all (priv->requests, req);
114− g_free (req);
115− return;
116−}
117−
118−void
119−free_request (SecretRequest *req)
120−{
121− g_object_unref (req->connection);
122− g_free (req);
123−}
124−
125−void
126−unity_settings_secret_agent_cancel_request (UnitySettingsSecretAgent *agent,
127− guint request)
128−{
129− GList *iter;
130− SecretRequest *req;
131− UnitySettingsSecretAgentPrivate *priv = agent->priv;
132− GError *error;
133−
134− iter = g_queue_find_custom (priv->requests,
135− &request,
136− (GCompareFunc)secret_request_find);
137−
138− if (iter == NULL || iter->data == NULL)
139− {
140− g_warning ("Secret request with id <%d> was not found", (int)request);
141− return;
142− }
143−
144− req = iter->data;
145− error = g_error_new (NM_SECRET_AGENT_ERROR,
146− NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
147− "This secret request was canceled by the user.");
148−
149− req->callback (NM_SECRET_AGENT (agent),
150− req->connection,
151− NULL,
152− error,
153− req->callback_data);
154−
155− g_queue_remove_all (priv->requests, req);
156− free_request (req);
157− return;
158−}
159−
160−static void
161−delete_secrets (NMSecretAgent *agent,
162− NMConnection *connection,
163− const char *connection_path,
164− NMSecretAgentDeleteSecretsFunc callback,
165− gpointer callback_data)
166−{
167− g_debug ("delete secrets");
168−}
169−
170−/* If it returns G_MAXUINT it's considered an error */
171−static guint
172−find_available_id (UnitySettingsSecretAgentPrivate *priv)
173−{
174− guint i = 0;
175− guint candidate = 0;
176−
177− if (g_queue_get_length (priv->requests) == G_MAXUINT)
178− return G_MAXUINT;
179−
180− while (i < g_queue_get_length (priv->requests))
181− {
182− SecretRequest *req = (SecretRequest*)g_queue_peek_nth (priv->requests, i);
183−
184− if (req->id == candidate)
185− {
186− candidate++;
187− i = 0;
188− }
189− else
190− {
191− i++;
192− }
193− }
194−
195− return i;
196−}
197−
198−static void
199−get_secrets (NMSecretAgent *agent,
200− NMConnection *connection,
201− const char *connection_path,
202− const char *setting_name,
203− const char **hints,
204− NMSecretAgentGetSecretsFlags flags,
205− NMSecretAgentGetSecretsFunc callback,
206− gpointer callback_data)
207−{
208− guint id;
209− UnitySettingsSecretAgentPrivate *priv = UNITY_SETTINGS_SECRET_AGENT_GET_PRIVATE (agent);
210− SecretRequest *req = NULL;
211−
212− if (flags == NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE)
213− {
214− GError *error = g_error_new (NM_SECRET_AGENT_ERROR,
215− NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
216− "No password found for this connection.");
217− callback (agent, connection, NULL, error, callback_data);
218− g_error_free (error);
219− return;
220− }
221−
222− id = find_available_id (priv);
223− if (id == G_MAXUINT)
224− {
225− GError *error = g_error_new (NM_SECRET_AGENT_ERROR,
226− NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
227− "Reached maximum number of requests.");
228− callback (agent, connection, NULL, error, callback_data);
229− g_error_free (error);
230− return;
231− }
232−
233− /* Adding a request */
234− req = (SecretRequest*) g_malloc0 (sizeof (SecretRequest));
235− *req = ((SecretRequest)
236− { id,
237− agent,
238− connection,
239− connection_path,
240− setting_name,
241− hints,
242− flags,
243− callback,
244− callback_data });
245−
246− g_object_ref (connection);
247−
248− g_queue_push_tail (priv->requests, req);
249−
250− g_signal_emit_by_name (agent,
251− UNITY_SETTINGS_SECRET_AGENT_SECRET_REQUESTED,
252− id,
253− connection,
254− setting_name,
255− hints,
256− flags);
257−}
258−
259−static void
260−save_secrets (NMSecretAgent *agent,
261− NMConnection *connection,
262− const char *connection_path,
263− NMSecretAgentSaveSecretsFunc callback,
264− gpointer callback_data)
265−{
266− g_debug ("save secrets");
267−}
268−
269−static void
270−cancel_get_secrets (NMSecretAgent *agent,
271− const char *connection_path,
272− const char *setting_name)
273−{
274− g_debug ("cancel get secrets");
275−}
276−
277−UnitySettingsSecretAgent*
278−unity_settings_secret_agent_construct (GType object_type)
279−{
280− UnitySettingsSecretAgent * self = NULL;
281− self = (UnitySettingsSecretAgent*) g_object_new (object_type,
282− NM_SECRET_AGENT_IDENTIFIER, AGENT_ID,
283− NULL);
284− return self;
285−}
286−
287−
288−UnitySettingsSecretAgent*
289−unity_settings_secret_agent_new (void)
290−{
291− return unity_settings_secret_agent_construct (UNITY_SETTINGS_TYPE_SECRET_AGENT);
292−}
293−
294−static void
295−destroy_pending_request (gpointer data)
296−{
297− SecretRequest* req = (SecretRequest*)data;
298− /* Reporting the cancellation of all pending requests */
299− g_signal_emit_by_name (req->agent,
300− UNITY_SETTINGS_SECRET_AGENT_REQUEST_CANCELLED,
301− req->id);
302−
303− free_request (req);
304−}
305−
306−static void
307−unity_settings_secret_agent_finalize (GObject *agent)
308−{
309− UnitySettingsSecretAgentPrivate *priv = UNITY_SETTINGS_SECRET_AGENT_GET_PRIVATE (agent);
310−
311− g_queue_free_full (priv->requests, destroy_pending_request);
312−}
313−
314−static void
315−unity_settings_secret_agent_class_init (UnitySettingsSecretAgentClass *klass)
316−{
317− unity_settings_secret_agent_parent_class = g_type_class_peek_parent (klass);
318− NMSecretAgentClass *parent_class = NM_SECRET_AGENT_CLASS (klass);
319− parent_class->get_secrets = get_secrets;
320− parent_class->save_secrets = save_secrets;
321− parent_class->delete_secrets = delete_secrets;
322− parent_class->cancel_get_secrets = cancel_get_secrets;
323−
324− g_type_class_add_private (klass, sizeof(UnitySettingsSecretAgentPrivate));
325− G_OBJECT_CLASS (klass)->finalize = unity_settings_secret_agent_finalize;
326−
327−
328− signals[SECRET_REQUESTED] = g_signal_new (UNITY_SETTINGS_SECRET_AGENT_SECRET_REQUESTED,
329− G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)),
330− G_SIGNAL_RUN_FIRST,
331− G_STRUCT_OFFSET (UnitySettingsSecretAgentClass, secret_requested),
332− NULL, NULL, NULL,
333− G_TYPE_NONE, 5,
334− G_TYPE_UINT, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_UINT);
335−
336− signals[REQUEST_CANCELLED] = g_signal_new (UNITY_SETTINGS_SECRET_AGENT_REQUEST_CANCELLED,
337− G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)),
338− G_SIGNAL_RUN_FIRST,
339− G_STRUCT_OFFSET (UnitySettingsSecretAgentClass, request_cancelled),
340− NULL, NULL, NULL,
341− G_TYPE_NONE, 1,
342− G_TYPE_UINT);
343−}
344−
345−
346−static void
347−unity_settings_secret_agent_instance_init (UnitySettingsSecretAgent *self)
348−{
349− self->priv = UNITY_SETTINGS_SECRET_AGENT_GET_PRIVATE (self);
350− self->priv->requests = g_queue_new ();
351−}
352−
353−GType
354−unity_settings_secret_agent_get_type (void)
355−{
356− static volatile gsize unity_settings_secret_agent_type_id__volatile = 0;
357− if (g_once_init_enter (&unity_settings_secret_agent_type_id__volatile))
358− {
359− static const GTypeInfo g_define_type_info =
360− {
361− sizeof (UnitySettingsSecretAgentClass),
362− (GBaseInitFunc) NULL,
363− (GBaseFinalizeFunc) NULL,
364− (GClassInitFunc) unity_settings_secret_agent_class_init,
365− (GClassFinalizeFunc) NULL,
366− NULL,
367− sizeof (UnitySettingsSecretAgent),
368− 0,
369− (GInstanceInitFunc) unity_settings_secret_agent_instance_init,
370− NULL
371− };
372− GType unity_settings_secret_agent_type_id;
373− unity_settings_secret_agent_type_id = g_type_register_static (NM_TYPE_SECRET_AGENT,
374− "UnitySettingsSecretAgent",
375− &g_define_type_info,
376− 0);
377− g_once_init_leave (&unity_settings_secret_agent_type_id__volatile,
378− unity_settings_secret_agent_type_id);
379− }
380−
381− return unity_settings_secret_agent_type_id__volatile;
382−}
plugins/Unity/Indicators/Network/secret-agent.hdeleted−102
@@ -1,102 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors:
17− * Alberto Ruiz <alberto.ruiz@canonical.com>
18− * Renato Araujo Oliveira Filho <renato@canonical.com>
19− */
20−
21−#ifndef __SECRET_AGENT_H__
22−#define __SECRET_AGENT_H__
23−
24−#include <glib.h>
25−#include <glib-object.h>
26−#include <nm-secret-agent.h>
27−
28−/*
29− * This class is a basic implementation of the NetworkManager SecretAgent base class.
30− *
31− * The purpose of this class is to handle credential requests from the network,
32− * for example, from a WiFi hotspot or a VPN network.
33− *
34− * It queues requests objects (SecretRequest) on a GQueue in the private struct
35− * of the class. And notifies the consumer of the class through the "secret-request"
36− * and the "request-cancelled" signals with the following callback prototypes:
37− *
38− * void (*secret_requested) (UnitySettingsSecretAgent *self,
39− * guint id,
40− * NMConnection *connection,
41− * const char *setting_name,
42− * const char **hints,
43− * NMSecretAgentGetSecretsFlags flags,
44− * gpointer user_data);
45− *
46− * void (*request_cancelled) (UnitySettingsSecretAgent *self,
47− * guint id,
48− * gpointer user_data);
49− *
50− */
51−
52−
53−G_BEGIN_DECLS
54−
55−
56−#define UNITY_SETTINGS_TYPE_SECRET_AGENT (unity_settings_secret_agent_get_type ())
57−#define UNITY_SETTINGS_SECRET_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UNITY_SETTINGS_TYPE_SECRET_AGENT, UnitySettingsSecretAgent))
58−#define UNITY_SETTINGS_SECRET_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UNITY_SETTINGS_TYPE_SECRET_AGENT, UnitySettingsSecretAgentClass))
59−#define UNITY_SETTINGS_IS_SECRET_AGENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UNITY_SETTINGS_TYPE_SECRET_AGENT))
60−#define UNITY_SETTINGS_IS_SECRET_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UNITY_SETTINGS_TYPE_SECRET_AGENT))
61−#define UNITY_SETTINGS_SECRET_AGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UNITY_SETTINGS_TYPE_SECRET_AGENT, UnitySettingsSecretAgentClass))
62−
63−#define UNITY_SETTINGS_SECRET_AGENT_SECRET_REQUESTED "secret-requested"
64−#define UNITY_SETTINGS_SECRET_AGENT_REQUEST_CANCELLED "request-cancelled"
65−
66−typedef struct _UnitySettingsSecretAgent UnitySettingsSecretAgent;
67−typedef struct _UnitySettingsSecretAgentClass UnitySettingsSecretAgentClass;
68−typedef struct _UnitySettingsSecretAgentPrivate UnitySettingsSecretAgentPrivate;
69−
70−struct _UnitySettingsSecretAgent {
71− NMSecretAgent parent_instance;
72− UnitySettingsSecretAgentPrivate * priv;
73−};
74−
75−struct _UnitySettingsSecretAgentClass {
76− NMSecretAgentClass parent_class;
77−
78− void (*secret_requested) (UnitySettingsSecretAgent *self,
79− guint id,
80− NMConnection *connection,
81− const char *setting_name,
82− const char **hints,
83− NMSecretAgentGetSecretsFlags flags);
84−
85− void (*request_cancelled) (UnitySettingsSecretAgent *self,
86− guint id);
87−};
88−
89−
90−GType unity_settings_secret_agent_get_type (void) G_GNUC_CONST;
91−UnitySettingsSecretAgent* unity_settings_secret_agent_new (void);
92−UnitySettingsSecretAgent* unity_settings_secret_agent_construct (GType object_type);
93−
94−void unity_settings_secret_agent_provide_secret (UnitySettingsSecretAgent *agent,
95− guint request,
96− GHashTable *secrets);
97−void unity_settings_secret_agent_cancel_request (UnitySettingsSecretAgent *agent,
98− guint request);
99−
100−G_END_DECLS
101−
102−#endif