/*************************************************************************** * * tdenetman-connection_editor.cpp - A NetworkManager frontend for TDE * * Copyright (C) 2005, 2006 Novell, Inc. * * Author: Helmut Schaa , * Author: Timothy Pearson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * **************************************************************************/ // qt headers #include #include #include #include #include #include #include #include // kde headers #include #include #include #include #include #include // tdenm headers #include "tdenetman-connection_editor.h" #include "tdenetman-connection_settings_dialog.h" using namespace ConnectionSettings; /* * ConnectionListViewItem */ class ConnectionListViewItem : public KListViewItem { public: ConnectionListViewItem(TQListView* parent, TDENetworkConnection* connection) : KListViewItem(parent) , _conn(connection) { if (_conn) { setText(0, _conn->friendlyName); setText(1, TDENetworkConnectionManager::friendlyConnectionTypeName(_conn->type())); // TODO: Move to a Factory if (_conn->type() == TDENetworkConnectionType::WiredEthernet) { setPixmap(0, KGlobal::iconLoader()->loadIcon("wired", KIcon::Small)); } else if (_conn->type() == TDENetworkConnectionType::WiFi) { setPixmap(0, KGlobal::iconLoader()->loadIcon("wireless", KIcon::Small)); } // else if (_conn->type() == TDENetworkConnectionType::VPN) { // setPixmap(0, KGlobal::iconLoader()->loadIcon("encrypted", KIcon::Small)); // } else { setPixmap(0, KGlobal::iconLoader()->loadIcon("help", KIcon::Small)); } } } TDENetworkConnection* _conn; }; /* * Constructor */ ConnectionEditorImpl::ConnectionEditorImpl(TQWidget* parent, const char* name, bool modal, WFlags fl) : ConnectionEditor(parent, name, modal, fl) { // TODO: enable combobox if implemented cboConnectionType->hide(); // TODO: Editmode is not ready yet, hide the button // pbEdit->hide(); pbNew->setIconSet(KGlobal::iconLoader()->loadIcon("add", KIcon::Small)); pbDelete->setIconSet(KGlobal::iconLoader()->loadIcon("remove", KIcon::Small)); pbEdit->setIconSet(KGlobal::iconLoader()->loadIcon("edit", KIcon::Small)); TQPopupMenu* popup = new TQPopupMenu(pbNew); // TODO: move to a factory class popup->insertItem(KGlobal::iconLoader()->loadIcon("wireless", KIcon::Small), i18n("Wireless"), this, TQT_SLOT(slotNewWirelessConnection())); popup->insertItem(KGlobal::iconLoader()->loadIcon("wired", KIcon::Small), i18n("Wired"), this, TQT_SLOT(slotNewWiredConnection())); // if (!VPNManager::getVPNServices().isEmpty()) { // popup->insertItem(KGlobal::iconLoader()->loadIcon("encrypted", KIcon::Small), i18n("VPN"), this, TQT_SLOT(slotNewVPNConnection())); // } pbNew->setPopup(popup); connect(pbClose, TQT_SIGNAL(clicked()), this, TQT_SLOT(close())); connect(pbDelete, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotRemoveCurrentConnection())); connect(pbEdit, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotEditCurrentConnection())); // show all connections fillConnectionList(); } /* * Destructor */ ConnectionEditorImpl::~ConnectionEditorImpl() { // remove the popupmenu if (pbNew->popup()) { delete pbNew->popup(); } } /* * New Wireless connection */ void ConnectionEditorImpl::slotNewWirelessConnection() { // create a new wireless connection slotEditNewConnection(new TDEWiFiConnection()); } /* * New Wired connection */ void ConnectionEditorImpl::slotNewWiredConnection() { slotEditNewConnection(new TDEWiredEthernetConnection()); } /* * New VPN connection */ void ConnectionEditorImpl::slotNewVPNConnection() { // slotEditNewConnection(new TDEVPNConnection()); } /* * */ void ConnectionEditorImpl::slotEditNewConnection(TDENetworkConnection* conn) { // open a dialog for editing the connection ConnectionSettingsDialogImpl* dlg = new ConnectionSettingsDialogImpl(conn, true, TQByteArray(), this, "connect_something", false, TQt::WDestructiveClose); connect(dlg, TQT_SIGNAL(connectionSaved()), this, TQT_SLOT(slotRefreshConnectionList())); dlg->show(); } void ConnectionEditorImpl::slotRefreshConnectionList() { fillConnectionList(); } /* * Edit the selected connection */ void ConnectionEditorImpl::slotEditCurrentConnection() { ConnectionListViewItem* item = dynamic_cast(lvConnections->currentItem()); if (!item) { return; } TDEGlobalNetworkManager* nm = KGlobal::networkManager(); if (!nm) { return; } TDENetworkConnection* conn = item->_conn; // we need the secrets for editing nm->loadConnectionSecrets(conn->UUID); ConnectionSettingsDialogImpl* dlg = new ConnectionSettingsDialogImpl(conn, false, TQByteArray(), this, "connect_something", false, TQt::WDestructiveClose); dlg->show(); // save all connections (if not done already) nm->saveConnection(conn); } /* * Delete the selected connection */ void ConnectionEditorImpl::slotRemoveCurrentConnection() { ConnectionListViewItem* item = dynamic_cast(lvConnections->currentItem()); if (!item) { return; } TDEGlobalNetworkManager* nm = KGlobal::networkManager(); if (!nm) { return; } TDENetworkConnection* conn = item->_conn; lvConnections->takeItem(item); delete item; nm->deleteConnection(conn->UUID); } /* * Fill the connection list */ void ConnectionEditorImpl::fillConnectionList() { TDEGlobalNetworkManager* nm = KGlobal::networkManager(); if (!nm) { return; } lvConnections->clear(); TDENetworkConnectionList* allconmap = nm->connections(); for (TDENetworkConnectionList::Iterator it = allconmap->begin(); it != allconmap->end(); ++it) { TDENetworkConnection* conn = *it; new ConnectionListViewItem(lvConnections, conn); } } #include "tdenetman-connection_editor.moc"