~ubuntu-branches/ubuntu/trusty/knetworkmanager/trusty

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-09-26 12:40:26 UTC
  • mfrom: (1.2.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080926124026-t5fr920l4lf2l6hz
Tags: 1:0.7svn864988-0ubuntu1
New upstream snapshot, now works with current NM API, 
closes LP: #259278

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *
3
 
 * knetworkmanager-connection_editor.cpp - A NetworkManager frontend for KDE
4
 
 *
5
 
 * Copyright (C) 2005, 2006 Novell, Inc.
6
 
 *
7
 
 * Author: Helmut Schaa        <hschaa@suse.de>, <helmut.schaa@gmx.de>
8
 
 *
9
 
 * This program is free software; you can redistribute it and/or modify
10
 
 * it under the terms of the GNU General Public License as published by
11
 
 * the Free Software Foundation; either version 2 of the License, or
12
 
 * (at your option) any later version.
13
 
 *
14
 
 * This program is distributed in the hope that it will be useful,
15
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
 * GNU General Public License for more details.
18
 
 * 
19
 
 * You should have received a copy of the GNU General Public License
20
 
 * along with this program; if not, write to the Free Software
21
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 
 *
23
 
 **************************************************************************/
24
 
 
25
 
// qt headers
26
 
#include <qwidget.h>
27
 
#include <qcombobox.h>
28
 
#include <qtabwidget.h>
29
 
#include <qpushbutton.h>
30
 
#include <qwidgetstack.h>
31
 
#include <qapplication.h>
32
 
#include <qlabel.h>
33
 
#include <qpopupmenu.h>
34
 
 
35
 
// kde headers
36
 
#include <kiconloader.h>
37
 
#include <kdebug.h>
38
 
#include <kpushbutton.h>
39
 
#include <klistview.h>
40
 
#include <klocale.h>
41
 
#include <kcombobox.h>
42
 
 
43
 
// knm headers
44
 
#include "knetworkmanager-connection_setting_info.h"
45
 
#include "knetworkmanager-connection.h"
46
 
#include "knetworkmanager-wired_connection.h"
47
 
#include "knetworkmanager-wireless_connection.h"
48
 
#include "knetworkmanager-vpn_connection.h"
49
 
#include "knetworkmanager-connection_store.h"
50
 
#include "knetworkmanager-connection_editor.h"
51
 
#include "knetworkmanager-connection_settings_dialog.h"
52
 
#include "knetworkmanager-storage.h"
53
 
#include "knetworkmanager-vpnservice.h"
54
 
#include "knetworkmanager-vpnmanager.h"
55
 
 
56
 
using namespace ConnectionSettings;
57
 
 
58
 
/*
59
 
 * ConnectionListViewItem
60
 
 */
61
 
class ConnectionListViewItem : public KListViewItem
62
 
{
63
 
        public:
64
 
 
65
 
        ConnectionListViewItem(QListView* parent, GenericConnection* connection)
66
 
                : KListViewItem(parent)
67
 
                , _conn(connection)
68
 
        {
69
 
                Info* info = _conn->getInfoSetting();
70
 
                if (info)
71
 
                {
72
 
                        setText(0, info->getName());
73
 
                        setText(1, info->getDevType());
74
 
                        // TODO: Move to a Factory
75
 
                        if (info->getDevType() == NM_SETTING_WIRED_SETTING_NAME)
76
 
                                setPixmap(0, KGlobal::iconLoader()->loadIcon("wired", KIcon::Small));
77
 
                        else if (info->getDevType() == NM_SETTING_WIRELESS_SETTING_NAME)
78
 
                                setPixmap(0, KGlobal::iconLoader()->loadIcon("wireless", KIcon::Small));
79
 
                        else if (info->getDevType() == NM_SETTING_VPN_SETTING_NAME)
80
 
                                setPixmap(0, KGlobal::iconLoader()->loadIcon("encrypted", KIcon::Small));
81
 
                        else
82
 
                                setPixmap(0, KGlobal::iconLoader()->loadIcon("help", KIcon::Small));
83
 
                }
84
 
        }
85
 
 
86
 
        GenericConnection* _conn;
87
 
};
88
 
 
89
 
/*
90
 
 * Constructor
91
 
 */
92
 
ConnectionEditorImpl::ConnectionEditorImpl(QWidget* parent, const char* name, bool modal, WFlags fl)
93
 
        : ConnectionEditor(parent, name, modal, fl)
94
 
{
95
 
 
96
 
        // TODO: enable combobox if implemented
97
 
        cboConnectionType->hide();
98
 
 
99
 
        // TODO: Editmode is not ready yet, hide the button
100
 
//      pbEdit->hide();
101
 
 
102
 
 
103
 
        pbNew->setIconSet(KGlobal::iconLoader()->loadIcon("add", KIcon::Small));
104
 
        pbDelete->setIconSet(KGlobal::iconLoader()->loadIcon("remove", KIcon::Small));
105
 
        pbEdit->setIconSet(KGlobal::iconLoader()->loadIcon("edit", KIcon::Small));
106
 
 
107
 
        QPopupMenu* popup = new QPopupMenu(pbNew);
108
 
        // TODO: move to a factory class
109
 
        popup->insertItem(KGlobal::iconLoader()->loadIcon("wireless", KIcon::Small), i18n("Wireless"), this, SLOT(slotNewWirelessConnection()));
110
 
        popup->insertItem(KGlobal::iconLoader()->loadIcon("wired", KIcon::Small), i18n("Wired"), this, SLOT(slotNewWiredConnection()));
111
 
 
112
 
        if (!VPNManager::getVPNServices().isEmpty())
113
 
                popup->insertItem(KGlobal::iconLoader()->loadIcon("encrypted", KIcon::Small), i18n("VPN"), this, SLOT(slotNewVPNConnection()));
114
 
 
115
 
        pbNew->setPopup(popup);
116
 
 
117
 
        connect(pbClose, SIGNAL(clicked()), this, SLOT(close()));
118
 
        connect(pbDelete, SIGNAL(clicked()), this, SLOT(slotRemoveCurrentConnection()));
119
 
        connect(pbEdit, SIGNAL(clicked()), this, SLOT(slotEditCurrentConnection()));
120
 
 
121
 
        // show all connections
122
 
        fillConnectionList();
123
 
}
124
 
 
125
 
/*
126
 
 * Destructor
127
 
 */
128
 
ConnectionEditorImpl::~ConnectionEditorImpl()
129
 
{
130
 
        // remove the popupmenu
131
 
        if (pbNew->popup())
132
 
                delete pbNew->popup();
133
 
}
134
 
 
135
 
/*
136
 
 * New Wireless connection
137
 
 */
138
 
void ConnectionEditorImpl::slotNewWirelessConnection()
139
 
{
140
 
                // create a new wireless connection
141
 
        slotEditNewConnection(new WirelessConnection());
142
 
}
143
 
 
144
 
/*
145
 
 * New Wired connection
146
 
 */
147
 
void ConnectionEditorImpl::slotNewWiredConnection()
148
 
{
149
 
        slotEditNewConnection(new WiredConnection());
150
 
}
151
 
 
152
 
/*
153
 
 * New VPN connection
154
 
 */
155
 
void ConnectionEditorImpl::slotNewVPNConnection()
156
 
{
157
 
        slotEditNewConnection(new VPNConnection());
158
 
}
159
 
 
160
 
/*
161
 
 *
162
 
 */
163
 
void ConnectionEditorImpl::slotEditNewConnection(Connection* conn)
164
 
{
165
 
        // open a dialog for editing the connection
166
 
        ConnectionSettingsDialogImpl* dlg = new ConnectionSettingsDialogImpl(conn, true, NULL, this, "connect_something", false, Qt::WDestructiveClose);
167
 
        connect(dlg, SIGNAL(connectionSaved()), this, SLOT(slotRefershConnectionList()));
168
 
        dlg->show();
169
 
}
170
 
 
171
 
void ConnectionEditorImpl::slotRefershConnectionList()
172
 
{
173
 
        fillConnectionList();
174
 
}
175
 
 
176
 
/*
177
 
 * Edit the selected connection
178
 
 */
179
 
void ConnectionEditorImpl::slotEditCurrentConnection()
180
 
{
181
 
        ConnectionListViewItem* item = dynamic_cast<ConnectionListViewItem*>(lvConnections->currentItem());
182
 
        if (!item)
183
 
                return;
184
 
 
185
 
        Connection* conn = item->_conn;
186
 
        Storage* storage = Storage::getInstance();
187
 
        bool hasSecretsStored = storage->hasSecretsStored(conn);
188
 
 
189
 
        // we need the secrets for editing
190
 
        if (hasSecretsStored)
191
 
                storage->restoreAllSecrets(conn);
192
 
 
193
 
        ConnectionSettingsDialogImpl* dlg = new ConnectionSettingsDialogImpl(conn, false, NULL, this, "connect_something", false, Qt::WDestructiveClose);
194
 
        dlg->show();
195
 
}
196
 
 
197
 
 
198
 
/*
199
 
 * Delete the selected connection
200
 
 */
201
 
void ConnectionEditorImpl::slotRemoveCurrentConnection()
202
 
{
203
 
        ConnectionListViewItem* item = dynamic_cast<ConnectionListViewItem*>(lvConnections->currentItem());
204
 
        if (!item)
205
 
                return;
206
 
 
207
 
        ConnectionStore* cstore = ConnectionStore::getInstance();
208
 
        Connection* conn = item->_conn;
209
 
 
210
 
        lvConnections->takeItem(item);
211
 
        delete item;
212
 
        
213
 
        cstore->removeConnection(conn);
214
 
}
215
 
 
216
 
/*
217
 
 * Fill the connection list
218
 
 */
219
 
void ConnectionEditorImpl::fillConnectionList()
220
 
{
221
 
        ConnectionStore* cstore = ConnectionStore::getInstance();
222
 
        QValueList<Connection*> conns = cstore->getConnections();
223
 
        QValueList<Connection*>::Iterator it = conns.begin();
224
 
 
225
 
        lvConnections->clear();
226
 
 
227
 
        for (; it != conns.end(); ++it)
228
 
        {
229
 
                GenericConnection* conn = dynamic_cast<GenericConnection*>(*it);
230
 
                if (conn)
231
 
                {
232
 
                        Info* info = conn->getInfoSetting();
233
 
                        if (info)
234
 
                        {
235
 
                                new ConnectionListViewItem(lvConnections, conn);
236
 
                        }
237
 
                        else
238
 
                                kdWarning() << k_funcinfo << "Connection without Info setting, drop it." << endl;
239
 
                }
240
 
                else
241
 
                        kdWarning() << k_funcinfo << "non-generic connection, dropping it." << endl;
242
 
                
243
 
        }
244
 
}
245
 
 
246
 
#include "knetworkmanager-connection_editor.moc"