You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
767 lines
24 KiB
767 lines
24 KiB
13 years ago
|
/***************************************************************************
|
||
|
*
|
||
12 years ago
|
* tdenetman-tray.cpp - A NetworkManager frontend for KDE
|
||
13 years ago
|
*
|
||
|
* Copyright (C) 2005, 2006 Novell, Inc.
|
||
|
*
|
||
|
* Author: Timo Hoenig <thoenig@suse.de>, <thoenig@nouse.net>
|
||
|
* Will Stephenson <wstephenson@suse.de>, <wstephenson@kde.org>
|
||
|
* Valentine Sinitsyn <e_val@inbox.ru>
|
||
|
* Helmut Schaa <hschaa@suse.de>, <helmut.schaa@gmx.de>
|
||
|
* Alexander Naumov <anaumov@suse.de>, <posix.ru@gmail.com>
|
||
|
* Author: Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||
|
*
|
||
|
* 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
|
||
|
*
|
||
|
**************************************************************************/
|
||
|
|
||
|
#include <tqsignalmapper.h>
|
||
|
#include <tqevent.h>
|
||
|
#include <tqvbox.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
13 years ago
|
#include <tqpushbutton.h>
|
||
|
#include <tqpixmap.h>
|
||
|
#include <tqpixmapcache.h>
|
||
|
#include <tqpainter.h>
|
||
|
#include <tqstyle.h>
|
||
|
#include <tqvaluelist.h>
|
||
|
#include <dcopclient.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kdialogbase.h>
|
||
|
#include <knotifyclient.h>
|
||
|
#include <knotifydialog.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kstdguiitem.h>
|
||
|
#include <khelpmenu.h>
|
||
|
#include <kprocess.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <kconfig.h>
|
||
|
#include <kmessagebox.h>
|
||
|
|
||
|
#include <tqpushbutton.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
13 years ago
|
#include <tqlabel.h>
|
||
|
#include <tqapplication.h>
|
||
|
#include <tqdialog.h>
|
||
|
|
||
|
#include "devicetraycomponent.h"
|
||
12 years ago
|
#include "tdenetman-tray.h"
|
||
12 years ago
|
|
||
12 years ago
|
#include "tdenetman-connection_settings_dialog.h"
|
||
|
#include "tdenetman-connection_editor.h"
|
||
|
#include "tdenetman-menu_subhead.h"
|
||
12 years ago
|
|
||
12 years ago
|
#include "tdenetman-wired_device_tray.h"
|
||
|
#include "tdenetman-wireless_device_tray.h"
|
||
|
#include "tdenetman-cellular_device_tray.h"
|
||
13 years ago
|
|
||
|
#include <stdio.h>
|
||
|
|
||
12 years ago
|
TDENetworkConnectionStatus::TDENetworkConnectionStatus nm_device_state_global;
|
||
13 years ago
|
|
||
12 years ago
|
NewSecretsDialog::NewSecretsDialog(TDENetworkConnection *connection, TQWidget * parent, const char * name, bool modal, TQt::WFlags f)
|
||
13 years ago
|
: TQDialog(parent, name, modal, f)
|
||
|
{
|
||
|
_connection = connection;
|
||
|
init();
|
||
|
}
|
||
|
|
||
|
NewSecretsDialog::~NewSecretsDialog ()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
void NewSecretsDialog::slotDialogEdit()
|
||
|
{
|
||
12 years ago
|
ConnectionSettingsDialogImpl* dlg = new ConnectionSettingsDialogImpl(_connection, false, Tray::getInstance(), "Edit connection");
|
||
13 years ago
|
dlg->show();
|
||
|
close();
|
||
|
}
|
||
|
|
||
|
void NewSecretsDialog::reject()
|
||
|
{
|
||
|
TQDialog::reject();
|
||
|
}
|
||
|
|
||
|
void NewSecretsDialog::init()
|
||
|
{
|
||
12 years ago
|
TDENetworkConnection* conn = _connection;
|
||
13 years ago
|
|
||
|
// if we do not have a connection bail out
|
||
|
if (!conn)
|
||
|
{
|
||
|
reject();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// show a message to the user that the connection failed
|
||
|
// and allow edit or cancel
|
||
|
|
||
12 years ago
|
TQLabel* label = new TQLabel(tqtr(" The connection %1 could not be established ").arg(conn->friendlyName), this);
|
||
13 years ago
|
TQPushButton* buttonEdit = new TQPushButton(tr("&Edit"), this);
|
||
|
TQPushButton* buttonCancel = new TQPushButton(tr("&Cancel"), this);
|
||
|
|
||
|
TQHBoxLayout *topLeftLayout = new TQHBoxLayout();
|
||
|
topLeftLayout->addWidget(buttonEdit);
|
||
|
topLeftLayout->addWidget(buttonCancel);
|
||
|
|
||
|
TQVBoxLayout *mainLayout = new TQVBoxLayout(this);
|
||
|
mainLayout->setMargin(15);
|
||
|
mainLayout->setSpacing(10);
|
||
|
mainLayout->addWidget(label);
|
||
|
mainLayout->addLayout(topLeftLayout);
|
||
|
|
||
|
connect(buttonEdit, TQT_SIGNAL(clicked()), TQT_SLOT(slotDialogEdit()));
|
||
|
connect(buttonCancel, TQT_SIGNAL(clicked()), this, TQT_SLOT(close()));
|
||
|
}
|
||
|
|
||
|
class TrayPrivate
|
||
|
{
|
||
|
public:
|
||
|
TrayPrivate(TQObject* parent)
|
||
|
: foregroundTrayComponent(0)
|
||
|
, signalMapper(parent, "signal_mapper")
|
||
|
, current_idx(0)
|
||
|
{}
|
||
|
~TrayPrivate() {}
|
||
|
|
||
|
static Tray* tray;
|
||
|
TQValueList<TrayComponent*> trayComponents;
|
||
|
DeviceTrayComponent * foregroundTrayComponent;
|
||
|
TQSignalMapper signalMapper;
|
||
12 years ago
|
TQMap<int, TDENetworkConnection*> act_conn_map;
|
||
13 years ago
|
int current_idx;
|
||
|
};
|
||
|
|
||
|
Tray* TrayPrivate::tray = NULL;
|
||
|
|
||
|
Tray* Tray::getInstance()
|
||
|
{
|
||
|
if (TrayPrivate::tray)
|
||
|
return TrayPrivate::tray;
|
||
|
else return (TrayPrivate::tray = new Tray());
|
||
|
}
|
||
|
|
||
|
void Tray::slotEditConnections()
|
||
|
{
|
||
|
ConnectionEditorImpl* dlg = new ConnectionEditorImpl(this);
|
||
|
dlg->show();
|
||
|
}
|
||
|
|
||
|
|
||
|
void Tray::slotEnableWireless()
|
||
|
{
|
||
12 years ago
|
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
|
||
13 years ago
|
if (!nm) return;
|
||
12 years ago
|
nm->enableWiFi(true);
|
||
13 years ago
|
}
|
||
|
|
||
|
void Tray::slotDisableWireless()
|
||
|
{
|
||
12 years ago
|
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
|
||
13 years ago
|
if (!nm) return;
|
||
12 years ago
|
nm->enableWiFi(false);
|
||
13 years ago
|
}
|
||
|
|
||
|
void Tray::slotOfflineMode()
|
||
|
{
|
||
12 years ago
|
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
|
||
13 years ago
|
if (!nm) return;
|
||
12 years ago
|
nm->enableNetworking(false);
|
||
13 years ago
|
}
|
||
|
|
||
|
void Tray::slotOnlineMode()
|
||
|
{
|
||
12 years ago
|
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
|
||
13 years ago
|
if (!nm) return;
|
||
12 years ago
|
nm->enableNetworking(true);
|
||
13 years ago
|
}
|
||
|
|
||
|
void Tray::contextMenuAboutToShow (KPopupMenu* menu)
|
||
|
{
|
||
12 years ago
|
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
|
||
13 years ago
|
|
||
|
// clear menu
|
||
|
menu->clear();
|
||
|
|
||
12 years ago
|
if (!(nm->backendStatus() & TDENetworkGlobalManagerFlags::BackendUnavailable)) {
|
||
|
// actions for each Device
|
||
|
for (TQValueList<TrayComponent*>::Iterator it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it) {
|
||
|
(*it)->addMenuItems(menu);
|
||
|
}
|
||
13 years ago
|
|
||
|
// Submenu title
|
||
12 years ago
|
Subhead* subhead = new Subhead (menu, "subhead", TQString("Connection Management"), SmallIcon("tdenetworkmanager_disabled", TQIconSet::Automatic));
|
||
13 years ago
|
menu->insertItem (subhead, -1, -1);
|
||
|
|
||
|
// New connection
|
||
|
KAction * newConnAction = 0;
|
||
|
int devices = d->trayComponents.count();
|
||
|
if ( devices > 1 ) {
|
||
|
newConnAction = actionCollection ()->action ("new_connection_menu");
|
||
|
KActionMenu* newConnActionMenu = static_cast<KActionMenu*>(newConnAction);
|
||
|
newConnActionMenu->popupMenu()->clear();
|
||
|
TQValueList<TrayComponent*>::Iterator it;
|
||
12 years ago
|
for (it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it) {
|
||
13 years ago
|
DeviceTrayComponent* dev_comp = dynamic_cast<DeviceTrayComponent*> (*it);
|
||
|
KAction * deviceNewConnAction = 0;
|
||
12 years ago
|
if (dev_comp) {
|
||
|
TQString actionName = TQString("new_connection_%1").arg(dev_comp->device()->deviceNode());
|
||
|
TQString menuCaption = TQString("%1").arg(dev_comp->device()->deviceNode());
|
||
13 years ago
|
if (menuCaption.contains("eth", FALSE) > 0) {
|
||
|
menuCaption = menuCaption.insert(0, "Wired Connection (");
|
||
|
}
|
||
|
else if (menuCaption.contains("wlan", FALSE) > 0) {
|
||
|
menuCaption = menuCaption.insert(0, "Wireless Connection (");
|
||
|
}
|
||
|
else if (menuCaption.contains("pan", FALSE) > 0) {
|
||
|
menuCaption = menuCaption.insert(0, "Private Area Connection (");
|
||
|
}
|
||
|
else {
|
||
|
menuCaption = menuCaption.insert(0, "Unknown Connection (");
|
||
|
}
|
||
|
menuCaption = menuCaption.append(")");
|
||
|
deviceNewConnAction = actionCollection ()->action (actionName);
|
||
|
if (!deviceNewConnAction) {
|
||
|
deviceNewConnAction = new KAction (menuCaption, 0, (*it), TQT_SLOT(newConnection()), actionCollection(), actionName);
|
||
|
}
|
||
|
newConnActionMenu->insert(deviceNewConnAction);
|
||
|
}
|
||
|
}
|
||
12 years ago
|
}
|
||
|
else if ( devices == 1 ) {
|
||
13 years ago
|
newConnAction = actionCollection ()->action ("new_connection");
|
||
|
TQT_BASE_OBJECT_NAME::disconnect( newConnAction, TQT_SIGNAL(activated()) );
|
||
|
TQT_BASE_OBJECT_NAME::connect( newConnAction, TQT_SIGNAL(activated()), d->trayComponents[0], TQT_SLOT(newConnection()));
|
||
|
}
|
||
|
if (newConnAction) {
|
||
|
newConnAction->plug(menu);
|
||
|
}
|
||
|
|
||
12 years ago
|
// turn things off
|
||
|
if (nm) {
|
||
13 years ago
|
KActionMenu* disableStuffActionMenu = static_cast<KActionMenu*>(actionCollection ()->action ("deactivate_menu") );
|
||
|
disableStuffActionMenu->popupMenu()->clear();
|
||
12 years ago
|
TDENetworkConnectionList* map = nm->connections();
|
||
13 years ago
|
d->act_conn_map.clear();
|
||
|
|
||
12 years ago
|
for (TDENetworkConnectionList::Iterator it = map->begin(); it != map->end(); ++it) {
|
||
|
TDENetworkConnection* conn = (*it);
|
||
13 years ago
|
|
||
12 years ago
|
if (!conn) {
|
||
13 years ago
|
continue;
|
||
12 years ago
|
}
|
||
13 years ago
|
|
||
12 years ago
|
if ((nm->checkConnectionStatus(conn->UUID) & TDENetworkConnectionStatus::Disconnected)
|
||
|
|| (nm->checkConnectionStatus(conn->UUID) & TDENetworkConnectionStatus::Invalid)) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
TQString actionName = TQString("disable_connection_%1").arg(conn->UUID);
|
||
13 years ago
|
KAction * deviceNewConnAction = actionCollection ()->action (actionName);
|
||
12 years ago
|
TQString actionText = conn->friendlyName;
|
||
13 years ago
|
|
||
|
if (!deviceNewConnAction) {
|
||
|
deviceNewConnAction = new KAction (actionText, 0, &d->signalMapper, TQT_SLOT(map()), actionCollection(), actionName);
|
||
|
}
|
||
|
d->signalMapper.setMapping(deviceNewConnAction, d->current_idx);
|
||
12 years ago
|
d->act_conn_map.insert(d->current_idx, conn);
|
||
13 years ago
|
d->current_idx++;
|
||
|
disableStuffActionMenu->insert(deviceNewConnAction);
|
||
|
}
|
||
|
|
||
|
// disable wireless
|
||
12 years ago
|
if (nm->wiFiHardwareEnabled()) {
|
||
13 years ago
|
KAction* wireless = NULL;
|
||
12 years ago
|
if (nm->wiFiEnabled()) {
|
||
13 years ago
|
wireless = actionCollection ()->action ("disable_wireless");
|
||
|
} else {
|
||
|
wireless = actionCollection ()->action ("enable_wireless");
|
||
|
}
|
||
|
disableStuffActionMenu->insert(wireless);
|
||
|
}
|
||
|
|
||
|
// offline vs. online mode
|
||
|
KAction* switch_mode = NULL;
|
||
12 years ago
|
if (nm->backendStatus() != TDENetworkGlobalManagerFlags::Sleeping) {
|
||
13 years ago
|
switch_mode = actionCollection ()->action ("offline_mode");
|
||
|
}
|
||
|
else {
|
||
|
switch_mode = actionCollection ()->action ("online_mode");
|
||
|
}
|
||
|
disableStuffActionMenu->insert(switch_mode);
|
||
|
|
||
|
disableStuffActionMenu->plug(menu);
|
||
|
}
|
||
|
}
|
||
12 years ago
|
else {
|
||
13 years ago
|
Subhead* subhead = new Subhead (menu, "subhead", i18n("NetworkManager is not running"), SmallIcon("stop", TQIconSet::Automatic));
|
||
|
menu->insertItem (subhead, -1, -1);
|
||
|
}
|
||
|
|
||
|
// Notifications
|
||
|
KAction* notif = actionCollection()->action("configure_notifications");
|
||
|
notif->plug(menu);
|
||
|
|
||
|
// Connection Editor
|
||
|
KAction* edit = actionCollection ()->action ("edit_connections");
|
||
|
edit->plug(menu);
|
||
|
|
||
|
// quit
|
||
|
menu->insertSeparator ();
|
||
|
KAction* quitAction = actionCollection ()->action (KStdAction::name (KStdAction::Quit));
|
||
12 years ago
|
if (quitAction) {
|
||
13 years ago
|
quitAction->plug (menu);
|
||
12 years ago
|
}
|
||
13 years ago
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
Tray::slotStateChanged(TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags newState, TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags prevState)
|
||
13 years ago
|
{
|
||
12 years ago
|
TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags nm_state = newState;
|
||
13 years ago
|
// change tray icon according to NM's state
|
||
12 years ago
|
|
||
|
if ((nm_state & TDENetworkGlobalManagerFlags::Unknown)
|
||
|
|| (nm_state & TDENetworkGlobalManagerFlags::Sleeping)
|
||
|
|| (nm_state & TDENetworkGlobalManagerFlags::EstablishingLink)
|
||
|
|| (nm_state & TDENetworkGlobalManagerFlags::Disconnected)
|
||
|
|| (nm_state & TDENetworkGlobalManagerFlags::BackendUnavailable)) {
|
||
12 years ago
|
setPixmap (loadIcon ("tdenetworkmanager_disabled"));
|
||
13 years ago
|
}
|
||
12 years ago
|
else if (nm_state & TDENetworkGlobalManagerFlags::Connected) {
|
||
12 years ago
|
setPixmap (loadIcon ("tdenetworkmanager"));
|
||
12 years ago
|
}
|
||
|
|
||
13 years ago
|
printf("NM state: %d\n\r", nm_state);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
Tray::enterEvent (TQEvent* /*e*/)
|
||
|
{
|
||
|
// show tooltip
|
||
|
TQToolTip::remove (this);
|
||
|
TQString tooltip = "";
|
||
|
|
||
|
// build up the tooltip from all tray components
|
||
|
for (TQValueList<TrayComponent*>::Iterator it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it)
|
||
|
{
|
||
|
TrayComponent* comp = *it;
|
||
|
if (comp->getToolTipText().isEmpty())
|
||
|
continue;
|
||
|
if (!tooltip.isEmpty())
|
||
|
tooltip += "\n\n";
|
||
|
tooltip += comp->getToolTipText().join("\n");
|
||
|
}
|
||
|
if (!tooltip.isEmpty())
|
||
|
TQToolTip::add (this, tooltip);
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
Tray::slotSecretsNeeded(TDENetworkConnection* connection, const TQStringList& hints, bool request_new)
|
||
13 years ago
|
{
|
||
12 years ago
|
// For now assume secrets are already in NM...
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
void Tray::slotAddDeviceTrayComponent(TDENetworkDevice* dev)
|
||
13 years ago
|
{
|
||
12 years ago
|
if (dev) {
|
||
13 years ago
|
createDeviceTrayComponent(dev);
|
||
12 years ago
|
}
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
void Tray::slotRemoveDeviceTrayComponent(TDENetworkDevice* dev)
|
||
13 years ago
|
{
|
||
|
for (TQValueList<TrayComponent*>::Iterator it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it)
|
||
|
{
|
||
|
DeviceTrayComponent* dev_comp = dynamic_cast<DeviceTrayComponent*>(*it);
|
||
|
if (!dev_comp)
|
||
|
continue;
|
||
|
|
||
|
if (dev_comp->device() == dev)
|
||
|
{
|
||
|
if (d->foregroundTrayComponent && dev_comp->device() == d->foregroundTrayComponent->device() ) {
|
||
|
d->foregroundTrayComponent = 0;
|
||
|
}
|
||
|
|
||
|
// remove the appropriate action
|
||
12 years ago
|
TQString actionName = TQString("new_connection_%1").arg(dev_comp->device()->deviceNode());
|
||
13 years ago
|
KAction * deviceNewConnAction = actionCollection ()->action (actionName);
|
||
|
|
||
|
if (!deviceNewConnAction)
|
||
|
{
|
||
|
delete deviceNewConnAction;
|
||
|
deviceNewConnAction = NULL;
|
||
|
}
|
||
|
// remove device_tray and delete it
|
||
|
d->trayComponents.remove(it);
|
||
|
delete dev_comp;
|
||
|
|
||
|
if (contextMenu()->isVisible()) {
|
||
|
contextMenu()->hide();
|
||
|
}
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void Tray::createDeviceTrayComponent(TDENetworkDevice* dev)
|
||
13 years ago
|
{
|
||
|
bool trayExists = false;
|
||
|
|
||
|
if (!dev) return;
|
||
|
|
||
|
// check if we have already a trayicon for this device
|
||
|
for (TQValueList<TrayComponent*>::Iterator it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it)
|
||
|
{
|
||
|
DeviceTrayComponent* dev_comp = dynamic_cast<DeviceTrayComponent*> (*it);
|
||
|
if (dev_comp)
|
||
|
if (dev_comp->device() == dev)
|
||
|
{
|
||
|
trayExists = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// create the appropriate device tray icon
|
||
|
if (!trayExists)
|
||
|
{
|
||
|
DeviceTrayComponent* devTray = 0;
|
||
12 years ago
|
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
|
||
13 years ago
|
// different tray icons for different device types!
|
||
12 years ago
|
switch (deviceConnMan->deviceType())
|
||
13 years ago
|
{
|
||
12 years ago
|
case TDENetworkDeviceType::WiredEthernet:
|
||
|
devTray = new WiredDeviceTray(dev, this, "wired_device_tray");
|
||
13 years ago
|
break;
|
||
12 years ago
|
case TDENetworkDeviceType::WiFi:
|
||
|
devTray = new WirelessDeviceTray(dev, this, "wireless_device_tray");
|
||
13 years ago
|
break;
|
||
12 years ago
|
case TDENetworkDeviceType::Modem:
|
||
|
devTray = new CellularDeviceTray(dev, this, "cellular_device_tray");
|
||
13 years ago
|
break;
|
||
|
default:
|
||
12 years ago
|
kdWarning() << k_funcinfo << "UDI: " << dev->uniqueID() << " has unknown devicetype: " << deviceConnMan->deviceType() << endl;
|
||
13 years ago
|
}
|
||
|
if(devTray)
|
||
|
{
|
||
|
connect( devTray, TQT_SIGNAL(needsCenterStage(TrayComponent*,bool)),
|
||
|
TQT_SLOT(trayComponentNeedsCenterStage(TrayComponent*,bool)));
|
||
|
connect( devTray, TQT_SIGNAL(uiUpdated()), TQT_SLOT(trayUiChanged()));
|
||
|
d->trayComponents.append(devTray);
|
||
|
//WILLTODO: sort
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Tray::updateDeviceTrays()
|
||
|
{
|
||
12 years ago
|
TDEHardwareDevices *hwdevices = KGlobal::hardwareDevices();
|
||
|
if (!hwdevices) return;
|
||
|
|
||
|
// create one tray-icon for each device
|
||
|
TDEGenericHardwareList devices = hwdevices->listByDeviceClass(TDEGenericDeviceType::Network);
|
||
13 years ago
|
|
||
|
// check for newly added devices
|
||
12 years ago
|
for (TDEGenericHardwareList::iterator it = devices.begin(); it != devices.end(); ++it)
|
||
13 years ago
|
{
|
||
12 years ago
|
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(*it);
|
||
|
if (dev) {
|
||
13 years ago
|
createDeviceTrayComponent(dev);
|
||
12 years ago
|
}
|
||
|
else {
|
||
13 years ago
|
kdWarning() << k_funcinfo << "got a NULL-Device" << endl;
|
||
12 years ago
|
}
|
||
13 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void Tray::mousePressEvent( TQMouseEvent *e )
|
||
|
{
|
||
|
if ( !TQT_TQRECT_OBJECT(rect()).contains( e->pos() ) ) {
|
||
|
return;
|
||
|
}
|
||
|
switch ( e->button() ) {
|
||
|
case Qt::LeftButton:
|
||
|
contextMenuAboutToShow(contextMenu());
|
||
|
contextMenu()->popup(e->globalPos());
|
||
|
break;
|
||
|
default:
|
||
|
KSystemTray::mousePressEvent( e );
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Tray::slotDeactivateConnection(int index)
|
||
|
{
|
||
12 years ago
|
TDENetworkConnection* conn = d->act_conn_map[index];
|
||
|
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
|
||
|
if (!nm) return;
|
||
13 years ago
|
|
||
|
if (conn) {
|
||
12 years ago
|
nm->deactivateConnection(conn->UUID);
|
||
13 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void Tray::trayComponentNeedsCenterStage(TrayComponent *component, bool needsIt)
|
||
|
{
|
||
|
DeviceTrayComponent * dtc = dynamic_cast<DeviceTrayComponent*>(component);
|
||
|
if (dtc) {
|
||
12 years ago
|
kdDebug() << k_funcinfo << dtc->device()->deviceNode() << " : " << needsIt << endl;
|
||
|
TDENetworkDevice * device = dtc->device();
|
||
13 years ago
|
if (needsIt) {
|
||
|
if (d->foregroundTrayComponent) {
|
||
|
disconnect(d->foregroundTrayComponent->device(), TQT_SIGNAL(StateChanged(NMDeviceState)), this, 0 );
|
||
|
}
|
||
|
d->foregroundTrayComponent = dtc;
|
||
|
connect(device, TQT_SIGNAL(StateChanged(NMDeviceState)),
|
||
|
TQT_SLOT(slotUpdateDeviceState(NMDeviceState)));
|
||
|
} else {
|
||
|
disconnect(device, TQT_SIGNAL(StateChanged(NMDeviceState)), this, 0 );
|
||
12 years ago
|
// use active default
|
||
|
#if 0
|
||
|
// FIXME
|
||
|
// The TDE network backend has no concept of a default device
|
||
|
// Should it?
|
||
13 years ago
|
device = nm->getDefaultDevice();
|
||
|
if ( device ) {
|
||
|
// identify the new foreground
|
||
|
for (TQValueList<TrayComponent*>::Iterator it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it)
|
||
|
{
|
||
|
DeviceTrayComponent* newDtc = dynamic_cast<DeviceTrayComponent*> (*it);
|
||
|
if ( newDtc && newDtc->device() == device ) {
|
||
|
d->foregroundTrayComponent = newDtc;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
12 years ago
|
kdDebug() << " Device " << dtc->device()->deviceNode() << " background, new foreground device: " << device->deviceNode() << endl;
|
||
13 years ago
|
connect(device, TQT_SIGNAL(StateChanged(NMDeviceState)),
|
||
|
TQT_SLOT(slotUpdateDeviceState(NMDeviceState)));
|
||
|
slotUpdateDeviceState(device->getState());
|
||
|
}
|
||
12 years ago
|
#endif
|
||
13 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Tray::slotUpdateDeviceState()
|
||
|
{
|
||
|
// FIXME
|
||
|
}
|
||
|
|
||
12 years ago
|
void Tray::slotUpdateDeviceState(TDENetworkConnectionStatus::TDENetworkConnectionStatus state)
|
||
13 years ago
|
{
|
||
|
updateTrayIcon(state);
|
||
|
updateActiveConnection(state);
|
||
|
}
|
||
|
|
||
|
void Tray::trayUiChanged()
|
||
|
{
|
||
|
DeviceTrayComponent * dtc = d->foregroundTrayComponent;
|
||
|
if (dtc) {
|
||
12 years ago
|
TDENetworkConnectionManager* deviceConnMan = dtc->device()->connectionManager();
|
||
|
updateTrayIcon(deviceConnMan->deviceInformation().statusFlags);
|
||
13 years ago
|
}
|
||
|
}
|
||
12 years ago
|
void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus state)
|
||
13 years ago
|
{
|
||
|
// Get all active connections
|
||
|
char found_any_active_connection=0;
|
||
|
|
||
12 years ago
|
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
|
||
13 years ago
|
|
||
|
found_any_active_connection = 0;
|
||
|
// Get all active connections
|
||
12 years ago
|
TDENetworkConnectionList* allconmap = nm->connections();
|
||
|
for (TDENetworkConnectionList::Iterator it = allconmap->begin(); it != allconmap->end(); ++it) {
|
||
|
TDENetworkConnection* conn = (*it);
|
||
13 years ago
|
|
||
12 years ago
|
if (!conn) {
|
||
13 years ago
|
continue;
|
||
12 years ago
|
}
|
||
|
|
||
|
if ((nm->checkConnectionStatus(conn->UUID) & TDENetworkConnectionStatus::Disconnected)
|
||
|
|| (nm->checkConnectionStatus(conn->UUID) & TDENetworkConnectionStatus::Invalid)) {
|
||
|
continue;
|
||
|
}
|
||
13 years ago
|
|
||
|
// Found an active connection
|
||
|
found_any_active_connection = 1;
|
||
|
}
|
||
|
|
||
|
// if (found_any_active_connection == 1) {
|
||
|
// printf("Active connection found\n\r");
|
||
|
// }
|
||
|
|
||
12 years ago
|
// stop the old movie to avoid unnecessary wakups
|
||
|
DeviceTrayComponent * dtc = d->foregroundTrayComponent;
|
||
13 years ago
|
|
||
12 years ago
|
if (movie())
|
||
|
movie()->pause();
|
||
|
|
||
|
if ((dtc) && (found_any_active_connection == 1)) {
|
||
|
|
||
|
if (!dtc->movieForState(state).isNull())
|
||
|
{
|
||
|
// animation desired
|
||
|
int frame = -1;
|
||
|
if (movie())
|
||
|
frame = movie()->frameNumber();
|
||
|
|
||
|
// set the movie
|
||
|
setMovie(dtc->movieForState(state));
|
||
|
|
||
|
// start at the same frame as the movie before
|
||
|
if (frame > 0)
|
||
|
movie()->step(frame);
|
||
|
|
||
|
// start the animation
|
||
|
movie()->unpause();
|
||
13 years ago
|
}
|
||
12 years ago
|
else if (!dtc->pixmapForState(state).isNull())
|
||
|
setPixmap(dtc->pixmapForState(state));
|
||
|
else
|
||
12 years ago
|
setPixmap(loadIcon("tdenetworkmanager"));
|
||
13 years ago
|
}
|
||
|
else {
|
||
12 years ago
|
setPixmap(loadIcon("tdenetworkmanager"));
|
||
13 years ago
|
}
|
||
|
|
||
|
nm_device_state_global = state;
|
||
|
//printf("Device state: %d\n\r", nm_device_state_global);
|
||
|
}
|
||
|
|
||
12 years ago
|
void Tray::updateActiveConnection(TDENetworkConnectionStatus::TDENetworkConnectionStatus state)
|
||
13 years ago
|
{
|
||
12 years ago
|
if (state != TDENetworkConnectionStatus::Connected) {
|
||
13 years ago
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void Tray::slotDeviceAddedNotify(TDENetworkDevice* dev)
|
||
13 years ago
|
{
|
||
|
kdDebug() << "Tray::slotDeviceAddedNotify" << endl;
|
||
12 years ago
|
KNotifyClient::event( winId(), "knm-nm-device-added", i18n("New network device %1 found").arg(dev->deviceNode()) );
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
void Tray::slotDeviceRemovedNotify(TDENetworkDevice* dev)
|
||
13 years ago
|
{
|
||
|
kdDebug() << "Tray::slotDeviceRemovedNotify" << endl;
|
||
12 years ago
|
KNotifyClient::event( winId(), "knm-nm-device-removed", i18n("Network device %1 removed").arg(dev->deviceNode()) );
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
void Tray::slotStateChangedNotify(TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags newState, TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags prevState)
|
||
13 years ago
|
{
|
||
12 years ago
|
TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags nm_state = newState;
|
||
13 years ago
|
|
||
|
// change tray icon according to NM's state
|
||
12 years ago
|
if (nm_state & TDENetworkGlobalManagerFlags::EstablishingLink) {
|
||
|
KNotifyClient::event( winId(), "knm-nm-connecting", i18n("NetworkManager is connecting") );
|
||
|
}
|
||
|
else if (nm_state & TDENetworkGlobalManagerFlags::Disconnected) {
|
||
|
KNotifyClient::event( winId(), "knm-nm-disconnected", i18n("NetworkManager is now disconnected") );
|
||
|
}
|
||
|
else if (nm_state & TDENetworkGlobalManagerFlags::Connected) {
|
||
|
KNotifyClient::event( winId(), "knm-nm-connected", i18n("NetworkManager is now connected") );
|
||
|
}
|
||
|
else if (nm_state & TDENetworkGlobalManagerFlags::Sleeping) {
|
||
|
KNotifyClient::event( winId(), "knm-nm-sleeping", i18n("KNetworkManager Offline") );
|
||
|
}
|
||
|
else if (nm_state & TDENetworkGlobalManagerFlags::Unknown) {
|
||
|
//
|
||
13 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void Tray::slotEditNotifications()
|
||
|
{
|
||
|
KNotifyDialog::configure(this);
|
||
|
}
|
||
|
|
||
|
Tray::Tray () : KSystemTray ()
|
||
|
{
|
||
|
d = new TrayPrivate(TQT_TQOBJECT(this));
|
||
|
|
||
|
connect(&d->signalMapper, TQT_SIGNAL(mapped(int)), this, TQT_SLOT(slotDeactivateConnection(int)));
|
||
|
|
||
12 years ago
|
setPixmap (loadIcon ("tdenetworkmanager"));
|
||
13 years ago
|
setMouseTracking (true);
|
||
|
|
||
|
// Actions used for plugging into the menu
|
||
|
new KAction (i18n ("Switch to offline mode"),
|
||
|
SmallIcon ("no", TQIconSet::Automatic), 0,
|
||
|
TQT_TQOBJECT(this), TQT_SLOT (slotOfflineMode()), actionCollection (), "offline_mode");
|
||
|
|
||
|
new KAction (i18n ("Switch to online mode"),
|
||
|
SmallIcon ("ok", TQIconSet::Automatic), 0,
|
||
|
TQT_TQOBJECT(this), TQT_SLOT (slotOnlineMode()), actionCollection (), "online_mode");
|
||
|
|
||
|
new KAction (i18n ("Disable Wireless"),
|
||
|
SmallIcon ("wireless_off", TQIconSet::Automatic), 0,
|
||
|
TQT_TQOBJECT(this), TQT_SLOT (slotDisableWireless()), actionCollection (), "disable_wireless");
|
||
|
|
||
|
new KAction (i18n ("Enable Wireless"),
|
||
|
SmallIcon ("wireless", TQIconSet::Automatic), 0,
|
||
|
TQT_TQOBJECT(this), TQT_SLOT (slotEnableWireless()), actionCollection (), "enable_wireless");
|
||
|
|
||
|
new KAction (i18n ("Edit Connections"),
|
||
|
SmallIcon ("edit", TQIconSet::Automatic), 0,
|
||
|
TQT_TQOBJECT(this), TQT_SLOT (slotEditConnections()), actionCollection (), "edit_connections");
|
||
|
|
||
|
new KAction (i18n ("Configure Notifications"),
|
||
|
SmallIcon ("knotify", TQIconSet::Automatic), 0,
|
||
|
TQT_TQOBJECT(this), TQT_SLOT (slotEditNotifications()), actionCollection (), "configure_notifications");
|
||
|
|
||
|
// this action is only connected when the menu is shown, hence the 0 receiver
|
||
|
new KAction (i18n ("New connection ..."),
|
||
|
SmallIcon ("filenew", TQIconSet::Automatic), 0,
|
||
|
TQT_TQOBJECT(this), 0, actionCollection (), "new_connection");
|
||
|
|
||
|
new KActionMenu (i18n ("New connection ..."),
|
||
|
SmallIcon ("filenew", TQIconSet::Automatic),
|
||
|
actionCollection(), "new_connection_menu");
|
||
|
|
||
|
new KActionMenu (i18n ("Deactivate connection..."),
|
||
|
SmallIcon ("no", TQIconSet::Automatic),
|
||
|
actionCollection (), "deactivate_menu");
|
||
|
|
||
|
// get notified when NM's state changes
|
||
12 years ago
|
connect(KGlobal::networkManager(), TQT_SIGNAL(networkConnectionStateChanged(TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags, TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags)), this, TQT_SLOT(slotStateChanged(TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags, TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags)));
|
||
13 years ago
|
|
||
|
// get notified about new/removed devices
|
||
12 years ago
|
// FIXME
|
||
|
// DeviceStore* store = DeviceStore::getInstance();
|
||
|
// connect(store, TQT_SIGNAL(DeviceStoreChanged()), this, TQT_SLOT(updateDeviceTrays()));
|
||
|
// connect(store, TQT_SIGNAL(DeviceAdded(TDENetworkDevice*)), this, TQT_SLOT(slotAddDeviceTrayComponent(TDENetworkDevice*)));
|
||
|
// connect(store, TQT_SIGNAL(DeviceRemoved(TDENetworkDevice*)), this, TQT_SLOT(slotRemoveDeviceTrayComponent(TDENetworkDevice*)));
|
||
13 years ago
|
|
||
|
// Notifications
|
||
12 years ago
|
connect(KGlobal::networkManager(), TQT_SIGNAL(networkConnectionStateChanged(TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags, TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags)), this, TQT_SLOT(slotStateChangedNotify(TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags, TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags)));
|
||
|
// connect(store, TQT_SIGNAL(DeviceAdded(TDENetworkDevice*)), this, TQT_SLOT(slotDeviceAddedNotify(TDENetworkDevice*)));
|
||
|
// connect(store, TQT_SIGNAL(DeviceRemoved(TDENetworkDevice*)), this, TQT_SLOT(slotDeviceRemovedNotify(TDENetworkDevice*)));
|
||
13 years ago
|
|
||
|
|
||
|
// initial setup of the device-trays
|
||
|
updateDeviceTrays();
|
||
|
|
||
12 years ago
|
slotStateChanged(KGlobal::networkManager()->backendStatus(), TDENetworkGlobalManagerFlags::Unknown);
|
||
13 years ago
|
}
|
||
|
|
||
|
Tray::~Tray ()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "tdenetman-tray.moc"
|
||
13 years ago
|
|