1
/***************************************************************************
3
* knetworkmanager-nminfo.cpp - A NetworkManager frontend for KDE
5
* Copyright (C) 2005, 2006 Novell, Inc.
7
* Author: Timo Hoenig <thoenig@suse.de>, <thoenig@nouse.net>
8
* Valentine Sinitsyn <e_val@inbox.ru>
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
**************************************************************************/
29
#include "knetworkmanager.h"
30
#include "knetworkmanager-nminfo_dbus.h"
31
#include "knetworkmanager-dialogfab.h"
32
#include "knetworkmanager-encryption.h"
33
#include "knetworkmanager-storage.h"
34
#include "knetworkmanager-synchronizer.h"
35
#include "knetworkmanager-vpn.h"
37
#include "knetworkmanager-nminfo.h"
39
PassphraseRequest::PassphraseRequest(KNetworkManager* ctx, QString obj_path, QString net_path, QString essid, bool new_key, DBusMessage* msg)
52
PassphraseRequest::~PassphraseRequest()
58
PassphraseRequest::slotKeyEntered(Network* /*net*/)
60
DeviceStore *store = _ctx->getDeviceStore ();
61
Device *dev = store->getDevice (_obj_path);
62
Network* net = dev->getNetwork(_net_path);
64
_ctx->getNetworkManagerInfo()->sendPassphrase(net, _msg);
68
PassphraseRequest::slotCancelRequest()
71
_ctx->getNetworkManagerInfo()->sendPassphraseError(_msg);
75
PassphraseRequest::acquireKeyFromDialog()
77
QString msg = QString::null;
79
msg = i18n("The connection could not be established. Please verify your settings and try again.");
80
_dlg = new AcquirePasswordDialog (_ctx->getTray (), "PassphraseDialog", true, 0, _ctx, _obj_path, _net_path, _essid, msg);
81
connect(_dlg, SIGNAL(sendPassphrase(Network*)), this, SLOT(slotKeyEntered(Network*)));
82
connect(_dlg, SIGNAL(cancelClicked()), this, SLOT(slotCancelRequest()));
87
PassphraseRequest::slotKeyRestored(bool result, bool canceled)
89
DeviceStore *store = _ctx->getDeviceStore ();
90
Device *dev = store->getDevice (_obj_path);
91
Network* net = dev->getNetwork(_net_path);
97
// if the user decided to use an other device throw the retrieved key away
100
// fake a canceled activation stage and send a reply to NM
101
dev->setActivationStage(NM_ACT_STAGE_CANCELLED);
102
this->slotCancelRequest();
106
// if the key was successful restored we can proceed
109
Encryption *enc = net->getEncryption ();
110
// check if encryption is now valid
111
if (enc->isValid(_essid))
113
// ok, lets send the new key
115
_ctx->getNetworkManagerInfo()->sendPassphrase(net, _msg);
119
// not handled -> ask the user
122
acquireKeyFromDialog();
127
PassphraseRequest::request()
129
bool handled = false;
130
DeviceStore *store = _ctx->getDeviceStore ();
131
Device *dev = store->getDevice (_obj_path);
132
Network* net = dev->getNetwork(_net_path);
134
/* Steps for obtaining the key:
135
* First, look in the Encryption object - maybe it was already loaded
136
* Second, look in the wallet - maybe it is here
137
* Third, ask the user
140
Encryption *enc = net->getEncryption ();
141
if (enc->isValid (_essid) ) {
142
// the encryption is valid -> send it immediatly
144
_ctx->getNetworkManagerInfo()->sendPassphrase(net, _msg);
146
else if (enc->hasStoredKey()) {
147
// the key is stored in the wallet -> try to restore and wait for restoration
148
connect(enc, SIGNAL(keyRestored(bool, bool)), this, SLOT(slotKeyRestored(bool, bool)));
149
enc->restoreKeyAsync();
155
// the encryption is not valid and no key exists in kwallet -> ask the user
156
acquireKeyFromDialog();
161
NetworkManagerInfo::userInteraction (void)
163
NetworkManagerInfoDBus::userInteraction ();
167
NetworkManagerInfo::sendPassphrase (Network* net, DBusMessage* msg)
169
NetworkManagerInfoDBus::sendKeyForNetwork (net, msg);
173
NetworkManagerInfo::sendPassphraseError (DBusMessage* msg)
175
NetworkManagerInfoDBus::sendGetKeyError (msg);
179
NetworkManagerInfo::acquirePassphrase (QString obj_path, QString net_path, QString essid, bool new_key, DBusMessage* msg)
181
kdDebug () << k_funcinfo << " fork ahead: user or storage" << endl;
183
DeviceStore *store = _ctx->getDeviceStore ();
184
Device *dev = store->getDevice (obj_path);
185
Synchronizer sync(dev);
186
sync.setSources(Synchronizer::Storage | Synchronizer::New);
187
sync.synchronize(essid, net_path);
190
drop the current pending passphrase request without sending an answer to NM
191
because NM cant handle multiple passphrase replies for now.
194
delete _currentRequest;
196
_currentRequest = new PassphraseRequest(_ctx, obj_path, net_path, essid, new_key, msg);
197
_currentRequest->request();
201
NetworkManagerInfo::getNetworks ()
203
return KNetworkManagerStorage::getInstance ()->networks ();
207
NetworkManagerInfo::getNetworkProperties (const QString & essid)
209
return KNetworkManagerStorage::getInstance ()->networkProperties (essid);
213
NetworkManagerInfo::emitNetworkUpdated (Network* net, bool automatic)
215
emit networkUpdated (net, automatic);
219
NetworkManagerInfo::getVPNConnection (const QString & name)
221
VPN* vpn = _ctx->getVPN ();
222
VPNConnection* vpnConnection = NULL;
224
if (vpn && vpn->isAvailable ()) {
225
VPNList* vpnList = vpn->getVPNList ();
227
for (VPNList::iterator i = vpnList->begin (); i != vpnList->end (); ++i) {
228
if ((*i)->getName () == name)
233
return vpnConnection;
237
NetworkManagerInfo::getVPNConnectionNames ()
239
VPN* vpn = _ctx->getVPN ();
240
QStringList vpnConnectionNames;
242
if (vpn && vpn->isAvailable ()) {
243
VPNList* vpnList = vpn->getVPNList ();
245
for (VPNList::iterator i = vpnList->begin (); i != vpnList->end (); ++i) {
246
vpnConnectionNames.append ((*i)->getName ());
250
return vpnConnectionNames;
254
NetworkManagerInfo::push (KNetworkManager* ctx)
256
NetworkManagerInfoDBus::push (ctx);
260
NetworkManagerInfo::NetworkManagerInfo ()
262
_currentRequest = NULL;
265
NetworkManagerInfo::~NetworkManagerInfo ()
270
#include "knetworkmanager-nminfo.moc"