2 * Copyright 2013 Canonical Ltd.
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.
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.
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/>.
17 * Alberto Ruiz <alberto.ruiz@canonical.com>
18 * Renato Araujo Oliveira Filho <renato@canonical.com>
21#include "networkagent.h"
24#include <QApplication>
27class NetworkAgentToken
30 NMConnection *connection;
31 NMSettingWirelessSecurity *wisec;
35 NetworkAgentToken(NMConnection *connection,
36 NMSettingWirelessSecurity *wisec,
39 : connection(connection),
45 g_object_ref(connection);
47 qWarning() << "invalid connection object";
54 g_object_unref(connection);
59NetworkAgent::NetworkAgent(QObject *parent)
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),
68 g_signal_connect(G_OBJECT(m_agent),
69 UNITY_SETTINGS_SECRET_AGENT_REQUEST_CANCELLED,
70 G_CALLBACK(onSecretRequestCancelled),
74NetworkAgent::~NetworkAgent()
76 nm_secret_agent_unregister(NM_SECRET_AGENT(m_agent));
77 g_object_unref(m_agent);
80void NetworkAgent::authenticate(const QVariant &token, const QString &key)
82 NetworkAgentToken *pToken = (NetworkAgentToken *) token.value<void *>();
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),
91 } else if (pToken->keyMgmt == "none") {
92 g_object_set(G_OBJECT(pToken->wisec),
93 NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, qPrintable(key),
97 GHashTable *settings = nm_connection_to_hash(pToken->connection,
98 NM_SETTING_HASH_FLAG_ALL);
100 unity_settings_secret_agent_provide_secret(m_agent,
101 pToken->id, settings);
102 g_hash_table_unref(settings);
106void NetworkAgent::cancel(const QVariant &token)
108 NetworkAgentToken *pToken = (NetworkAgentToken *) token.value<void *>();
109 if (pToken != NULL) {
110 unity_settings_secret_agent_cancel_request(m_agent, pToken->id);
115void NetworkAgent::onSecretRequested(UnitySettingsSecretAgent* /*agent*/,
117 NMConnection* connection,
118 const char* /*setting_name*/,
119 const char** /*hints*/,
120 NMSecretAgentGetSecretsFlags /*flags*/,
123 NetworkAgentToken *token = new NetworkAgentToken(connection,
128 token->wisec = nm_connection_get_setting_wireless_security(connection);
130 token->keyMgmt = nm_setting_wireless_security_get_key_mgmt(token->wisec);
133 QVariant varToken = qVariantFromValue((void *) token);
134 Q_EMIT self->secretRequested(varToken);
137void NetworkAgent::onSecretRequestCancelled(UnitySettingsSecretAgent* /*agent*/,
139 NMConnection* /*connection*/,
140 const char* /*setting_name*/,
141 const char** /*hints*/,
142 NMSecretAgentGetSecretsFlags /*flags*/,
143 NetworkAgent* /*self*/)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list