1
/***************************************************************************
3
* knetworkmanager-connection_editor.cpp - A NetworkManager frontend for KDE
5
* Copyright (C) 2005, 2006 Novell, Inc.
7
* Author: Helmut Schaa <hschaa@suse.de>, <helmut.schaa@gmx.de>
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.
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.
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
23
**************************************************************************/
27
#include <qcombobox.h>
28
#include <qtabwidget.h>
29
#include <qpushbutton.h>
30
#include <qwidgetstack.h>
31
#include <qapplication.h>
33
#include <qpopupmenu.h>
36
#include <kiconloader.h>
38
#include <kpushbutton.h>
39
#include <klistview.h>
41
#include <kcombobox.h>
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"
56
using namespace ConnectionSettings;
59
* ConnectionListViewItem
61
class ConnectionListViewItem : public KListViewItem
65
ConnectionListViewItem(QListView* parent, GenericConnection* connection)
66
: KListViewItem(parent)
69
Info* info = _conn->getInfoSetting();
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));
82
setPixmap(0, KGlobal::iconLoader()->loadIcon("help", KIcon::Small));
86
GenericConnection* _conn;
92
ConnectionEditorImpl::ConnectionEditorImpl(QWidget* parent, const char* name, bool modal, WFlags fl)
93
: ConnectionEditor(parent, name, modal, fl)
96
// TODO: enable combobox if implemented
97
cboConnectionType->hide();
99
// TODO: Editmode is not ready yet, hide the button
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));
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()));
112
if (!VPNManager::getVPNServices().isEmpty())
113
popup->insertItem(KGlobal::iconLoader()->loadIcon("encrypted", KIcon::Small), i18n("VPN"), this, SLOT(slotNewVPNConnection()));
115
pbNew->setPopup(popup);
117
connect(pbClose, SIGNAL(clicked()), this, SLOT(close()));
118
connect(pbDelete, SIGNAL(clicked()), this, SLOT(slotRemoveCurrentConnection()));
119
connect(pbEdit, SIGNAL(clicked()), this, SLOT(slotEditCurrentConnection()));
121
// show all connections
122
fillConnectionList();
128
ConnectionEditorImpl::~ConnectionEditorImpl()
130
// remove the popupmenu
132
delete pbNew->popup();
136
* New Wireless connection
138
void ConnectionEditorImpl::slotNewWirelessConnection()
140
// create a new wireless connection
141
slotEditNewConnection(new WirelessConnection());
145
* New Wired connection
147
void ConnectionEditorImpl::slotNewWiredConnection()
149
slotEditNewConnection(new WiredConnection());
155
void ConnectionEditorImpl::slotNewVPNConnection()
157
slotEditNewConnection(new VPNConnection());
163
void ConnectionEditorImpl::slotEditNewConnection(Connection* conn)
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()));
171
void ConnectionEditorImpl::slotRefershConnectionList()
173
fillConnectionList();
177
* Edit the selected connection
179
void ConnectionEditorImpl::slotEditCurrentConnection()
181
ConnectionListViewItem* item = dynamic_cast<ConnectionListViewItem*>(lvConnections->currentItem());
185
Connection* conn = item->_conn;
186
Storage* storage = Storage::getInstance();
187
bool hasSecretsStored = storage->hasSecretsStored(conn);
189
// we need the secrets for editing
190
if (hasSecretsStored)
191
storage->restoreAllSecrets(conn);
193
ConnectionSettingsDialogImpl* dlg = new ConnectionSettingsDialogImpl(conn, false, NULL, this, "connect_something", false, Qt::WDestructiveClose);
199
* Delete the selected connection
201
void ConnectionEditorImpl::slotRemoveCurrentConnection()
203
ConnectionListViewItem* item = dynamic_cast<ConnectionListViewItem*>(lvConnections->currentItem());
207
ConnectionStore* cstore = ConnectionStore::getInstance();
208
Connection* conn = item->_conn;
210
lvConnections->takeItem(item);
213
cstore->removeConnection(conn);
217
* Fill the connection list
219
void ConnectionEditorImpl::fillConnectionList()
221
ConnectionStore* cstore = ConnectionStore::getInstance();
222
QValueList<Connection*> conns = cstore->getConnections();
223
QValueList<Connection*>::Iterator it = conns.begin();
225
lvConnections->clear();
227
for (; it != conns.end(); ++it)
229
GenericConnection* conn = dynamic_cast<GenericConnection*>(*it);
232
Info* info = conn->getInfoSetting();
235
new ConnectionListViewItem(lvConnections, conn);
238
kdWarning() << k_funcinfo << "Connection without Info setting, drop it." << endl;
241
kdWarning() << k_funcinfo << "non-generic connection, dropping it." << endl;
246
#include "knetworkmanager-connection_editor.moc"