diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-09-06 21:16:31 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-09-06 21:16:31 -0500 |
commit | 82102f3f7168b27e115f9f959bad75c99c1ae76a (patch) | |
tree | 100a1dc3ada92e5e969b68ac3f8b1d21aae10e27 /tdenetworkmanager/src/tdenetman-wired_device_tray.cpp | |
parent | d45099229d40b4850c68eb4a64f67ff3ad0dcbc5 (diff) | |
download | tdenetworkmanager-82102f3f7168b27e115f9f959bad75c99c1ae76a.tar.gz tdenetworkmanager-82102f3f7168b27e115f9f959bad75c99c1ae76a.zip |
Rename files to something more sensible
Diffstat (limited to 'tdenetworkmanager/src/tdenetman-wired_device_tray.cpp')
-rw-r--r-- | tdenetworkmanager/src/tdenetman-wired_device_tray.cpp | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/tdenetworkmanager/src/tdenetman-wired_device_tray.cpp b/tdenetworkmanager/src/tdenetman-wired_device_tray.cpp new file mode 100644 index 0000000..68a6069 --- /dev/null +++ b/tdenetworkmanager/src/tdenetman-wired_device_tray.cpp @@ -0,0 +1,149 @@ +/*************************************************************************** + * + * tdenetman-wired_device_tray.cpp - A NetworkManager frontend for KDE + * + * Copyright (C) 2005, 2006 Novell, Inc. + * + * Author: Helmut Schaa <hschaa@suse.de>, <helmut.schaa@gmx.de> + * + * 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 + * + **************************************************************************/ + +// TQt includes +#include <tqevent.h> +#include <tqvbox.h> +#include <tqlayout.h> +#include <tqpushbutton.h> +#include <tqbitmap.h> +#include <tqimage.h> +#include <tqpixmap.h> +#include <tqpixmapcache.h> +#include <tqpainter.h> +#include <tqstyle.h> +#include <tqstring.h> + +// KDE includes +#include <kdebug.h> +#include <klocale.h> +#include <kiconloader.h> + +// TQt DBus +#include <tqdbusobjectpath.h> + + +// KNM includes +#include "tdenetman-wired_device_tray.h" +#include "tdenetman-menuitem.h" +#include "tdenetman-menu_subhead.h" + +#include "tdenetman-connection_settings_dialog.h" + +using namespace ConnectionSettings; + +class WiredDeviceTrayPrivate +{ + public: + WiredDeviceTrayPrivate() {} + ~WiredDeviceTrayPrivate() {} + + TDENetworkDevice* dev; +}; + +void WiredDeviceTray::newConnection() +{ + // create a new wired connection + TDENetworkConnection* conn = new TDEWiredEthernetConnection(); + + // edit the new connection + ConnectionSettingsDialogImpl* dlg = new ConnectionSettingsDialogImpl(conn, true, tray(), "connect_something", false, TQt::WDestructiveClose); + dlg->show(); +} + + +void WiredDeviceTray::addMenuItems(KPopupMenu* menu) +{ + // device title + Subhead* subhead = new Subhead (menu, "subhead", TQString("Wired Connection (%1)").arg(d->dev->deviceNode()), SmallIcon("wired", TQIconSet::Automatic)); + menu->insertItem (subhead, -1, -1); + + // bolding subhead instead + //menu->insertSeparator(); + + TDENetworkConnectionManager* deviceConnMan = d->dev->connectionManager(); + if (deviceConnMan->deviceInformation().statusFlags & TDENetworkConnectionStatus::LinkUnavailable) { + // no carrier -> do not show any connections + subhead = new Subhead(menu, "subhead2", i18n("Cable disconnected"), SmallIcon("no", TQIconSet::Automatic)); + menu->insertItem(subhead, -1, -1); + } + else { + TDEGlobalNetworkManager* nm = KGlobal::networkManager(); + TDENetworkConnectionManager* deviceConnMan = d->dev->connectionManager(); + TDENetworkConnection* active_conn = NULL; + if ((!(deviceConnMan->deviceInformation().statusFlags & TDENetworkConnectionStatus::Disconnected)) + && (!(deviceConnMan->deviceInformation().statusFlags & TDENetworkConnectionStatus::Invalid))) { + active_conn = nm->findConnectionByUUID(deviceConnMan->deviceInformation().activeConnectionUUID); + } + + // get all available Connections for wired devices + TDENetworkConnectionList* connections = nm->connections(); + int connectionItems = 0; + for (TDENetworkConnectionList::Iterator it = connections->begin(); it != connections->end(); ++it) { + TDEWiredEthernetConnection* conn = dynamic_cast<TDEWiredEthernetConnection*>(*it); + if (!conn) { + continue; + } + + // wired connection found :) + // lets create a nice name for this connection + TQString title = conn->friendlyName; + if (conn->ipConfig.valid) { + title += TQString(" (%1)").arg((conn->ipConfig.connectionFlags & TDENetworkIPConfigurationFlags::IPV4DHCPIP) ? i18n("DHCP") : i18n("Manual IP config")); + } + + NetworkMenuItem* item = new NetworkMenuItem(d->dev, conn, TQT_TQOBJECT(menu)); + connectionItems += 1; + + int id = menu->insertItem(title, item, TQT_SLOT(slotActivate())); + menu->setItemChecked(id, ((*it) == active_conn)); + } + + if ( connectionItems == 0) { + // menu->insertSeparator(); + menu->insertItem(SmallIcon("filenew", TQIconSet::Automatic), i18n("Create new wired connection"), this, TQT_SLOT(newConnection())); + } + // bring the device down + KAction* deactivate = tray()->actionCollection()->action("deactivate_device"); + if (deactivate) + deactivate->plug(menu); + + } +} + +WiredDeviceTray::WiredDeviceTray (TDENetworkDevice* dev, KSystemTray * parent, const char * name ) + : DeviceTrayComponent (dev, parent, name) +{ + d = new WiredDeviceTrayPrivate(); + d->dev = dev; + + setPixmapForState(TDENetworkConnectionStatus::Connected, "nm_device_wired"); +} + +WiredDeviceTray::~WiredDeviceTray () +{ + delete d; +} + +#include "tdenetman-wired_device_tray.moc" |