~ubuntu-branches/debian/sid/knetworkmanager/sid

« back to all changes in this revision

Viewing changes to knetworkmanager/src/knetworkmanager-nminfo.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2006-09-28 11:47:00 UTC
  • Revision ID: james.westby@ubuntu.com-20060928114700-fbiktmk2woj1jww4
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *
 
3
 * knetworkmanager-nminfo.cpp - A NetworkManager frontend for KDE 
 
4
 *
 
5
 * Copyright (C) 2005, 2006 Novell, Inc.
 
6
 *
 
7
 * Author: Timo Hoenig        <thoenig@suse.de>, <thoenig@nouse.net>
 
8
 *         Valentine Sinitsyn <e_val@inbox.ru>
 
9
 *
 
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.
 
14
 *
 
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.
 
19
 * 
 
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
 
23
 *
 
24
 **************************************************************************/
 
25
 
 
26
#include <kdebug.h>
 
27
#include "knetworkmanager.h"
 
28
#include "knetworkmanager-nminfo_dbus.h"
 
29
#include "knetworkmanager-dialogfab.h"
 
30
#include "knetworkmanager-encryption.h"
 
31
#include "knetworkmanager-storage.h"
 
32
#include "knetworkmanager-synchronizer.h"
 
33
#include "knetworkmanager-vpn.h"
 
34
 
 
35
#include "knetworkmanager-nminfo.h"
 
36
 
 
37
void
 
38
NetworkManagerInfo::userInteraction (void)
 
39
{
 
40
        NetworkManagerInfoDBus::userInteraction ();
 
41
}
 
42
 
 
43
void
 
44
NetworkManagerInfo::sendPassphrase (Network* net)
 
45
{
 
46
        NetworkManagerInfoDBus::sendKeyForNetwork (net);
 
47
}
 
48
 
 
49
void
 
50
NetworkManagerInfo::sendPassphraseError ()
 
51
{
 
52
        NetworkManagerInfoDBus::sendGetKeyError ();
 
53
}
 
54
 
 
55
void
 
56
NetworkManagerInfo::acquirePassphrase (QString obj_path, QString net_path, QString essid, bool new_key)
 
57
{
 
58
        kdDebug () << k_funcinfo << " fork ahead: user or storage" << endl;
 
59
 
 
60
        DeviceStore *store = _ctx->getDeviceStore ();
 
61
        Device *dev = store->getDevice (obj_path);
 
62
        Synchronizer sync(dev);
 
63
        sync.setSources(Synchronizer::Storage | Synchronizer::New);
 
64
        Network *net = sync.synchronize(essid, net_path);
 
65
 
 
66
        bool handled = false;
 
67
 
 
68
        /* Steps for obtaining the key:
 
69
         *  First, look in the Encryption object - maybe it was already loaded
 
70
         *  Second, look in the wallet - maybe it is here
 
71
         *  Third, ask the user
 
72
         */
 
73
        if (!new_key) {
 
74
                Encryption *enc = net->getEncryption ();
 
75
 
 
76
                if (enc->isValid (essid) || (enc->restoreKey() && enc->isValid (essid))) {
 
77
                        kdDebug () << k_funcinfo << "responding to getKeyForNetwork " << net->getEssid () << endl;
 
78
                        handled = true;
 
79
                } 
 
80
        }
 
81
 
 
82
        if (!handled) {
 
83
                kdDebug () << k_funcinfo << " asking user: getKeyForNetwork " <<  essid << endl;
 
84
                AcquirePasswordDialog* dlg = new AcquirePasswordDialog (_ctx->getTray (), "PassphraseDialog", true, WDestructiveClose, _ctx, obj_path, net_path, essid);
 
85
                dlg->show ();
 
86
        }
 
87
        else {
 
88
                sendPassphrase (net);
 
89
        }
 
90
}
 
91
 
 
92
QStringList
 
93
NetworkManagerInfo::getNetworks ()
 
94
{
 
95
        return KNetworkManagerStorage::getInstance ()->networks ();
 
96
}
 
97
 
 
98
Network*
 
99
NetworkManagerInfo::getNetworkProperties (const QString & essid)
 
100
{
 
101
        return KNetworkManagerStorage::getInstance ()->networkProperties (essid);
 
102
}
 
103
 
 
104
void 
 
105
NetworkManagerInfo::emitNetworkUpdated (Network* net, bool automatic)
 
106
{
 
107
        emit networkUpdated (net, automatic);
 
108
}
 
109
 
 
110
VPNConnection*
 
111
NetworkManagerInfo::getVPNConnection (const QString & name)
 
112
{
 
113
        VPN*           vpn           = _ctx->getVPN ();
 
114
        VPNConnection* vpnConnection = NULL;
 
115
 
 
116
        if (vpn && vpn->isAvailable ()) {
 
117
                VPNList* vpnList = vpn->getVPNList ();
 
118
 
 
119
                for (VPNList::iterator i = vpnList->begin (); i != vpnList->end (); ++i) {
 
120
                        if ((*i)->getName () == name)
 
121
                                vpnConnection = *i;
 
122
                }
 
123
        }
 
124
 
 
125
        return vpnConnection;
 
126
}
 
127
 
 
128
QStringList
 
129
NetworkManagerInfo::getVPNConnectionNames ()
 
130
{
 
131
        VPN*        vpn = _ctx->getVPN ();
 
132
        QStringList vpnConnectionNames;
 
133
 
 
134
        if (vpn && vpn->isAvailable ()) {
 
135
                VPNList* vpnList = vpn->getVPNList ();
 
136
                
 
137
                for (VPNList::iterator i = vpnList->begin (); i != vpnList->end (); ++i) {
 
138
                        vpnConnectionNames.append ((*i)->getName ());
 
139
                }
 
140
        }
 
141
 
 
142
        return vpnConnectionNames;
 
143
}
 
144
 
 
145
void
 
146
NetworkManagerInfo::push (KNetworkManager* ctx)
 
147
{
 
148
        NetworkManagerInfoDBus::push (ctx);
 
149
        _ctx = ctx;
 
150
}
 
151
 
 
152
NetworkManagerInfo::NetworkManagerInfo ()
 
153
{
 
154
 
 
155
}
 
156
 
 
157
NetworkManagerInfo::~NetworkManagerInfo ()
 
158
{
 
159
 
 
160
}
 
161
 
 
162
#include "knetworkmanager-nminfo.moc"