summaryrefslogtreecommitdiffstats
path: root/tdenetworkmanager/src/tdenetman-cellular_device_tray.cpp
blob: 29cf61f3b60a4969d9c58aeeed3de812c5c586d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/***************************************************************************
 *
 * tdenetman-cellular_device_tray.cpp - A NetworkManager frontend for TDE
 *
 * 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 <tqwidget.h> // for TQt::WidgetFlags

// TDE includes
#include <kdebug.h>
#include <klocale.h>
#include <kiconloader.h>

// TDENM includes
#include "tdenetman-cellular_device_tray.h"
#include "tdenetman-menuitem.h"
#include "tdenetman-menu_subhead.h"

#include "tdenetman-connection_settings_dialog.h"

using namespace ConnectionSettings;

class CellularDeviceTrayPrivate
{
	public:
		CellularDeviceTrayPrivate() {}
		~CellularDeviceTrayPrivate() {}

		TQString dev;
};

void CellularDeviceTray::newConnection()
{
	TDEGlobalNetworkManager* nm = TDEGlobal::networkManager();
	TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(d->dev));

	// create an appropriate connection
	TDENetworkConnection* conn = 0;
	TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
	switch (deviceConnMan->deviceType()) {
		case TDENetworkDeviceType::Modem:
			conn = new TDEModemConnection();
			nm->loadConnectionAllowedValues(conn);
			break;

		default:
			break;
	}

	// edit the new connection
	ConnectionSettingsDialogImpl* dlg = new ConnectionSettingsDialogImpl(conn, true, TQByteArray(), tray(), "connect_something", false, TQt::WDestructiveClose);
	dlg->show();
}


void CellularDeviceTray::addMenuItems(TDEPopupMenu* menu)
{
	TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(d->dev));

	// device title
	Subhead* subhead = new Subhead (menu, "subhead", dev->deviceNode(), SmallIcon("nm_device_wwan", TQIconSet::Automatic));
	menu->insertItem (subhead, -1, -1);

	//menu->insertSeparator();
	TDEGlobalNetworkManager* nm = TDEGlobal::networkManager();
	TDENetworkConnectionManager* deviceConnMan = 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 cellular devices

	TDENetworkConnectionList* allconmap = nm->connections();
	for (TDENetworkConnectionList::Iterator it = allconmap->begin(); it != allconmap->end(); ++it) {
		TDEModemConnection* conn = dynamic_cast<TDEModemConnection*>(*it);
		if (!conn) {
			continue;
		}

		// 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->UUID, TQT_TQOBJECT(menu));

		int id = menu->insertItem(title, item, TQT_SLOT(slotActivate()));
		menu->setItemChecked(id, ((*it) == active_conn));
	}

	// bring the device down
	TDEAction* deactivate = tray()->actionCollection()->action("deactivate_device");
	if (deactivate) {
		deactivate->plug(menu);
	}

	menu->insertSeparator();
}

CellularDeviceTray::CellularDeviceTray (TQString dev, KSystemTray * parent, const char * name)
	: DeviceTrayComponent (dev, parent, name)
{
	hwdevices = TDEGlobal::hardwareDevices();
	d = new CellularDeviceTrayPrivate();
	d->dev = dev;

	setPixmapForState(TDENetworkConnectionStatus::Connected, "nm_device_wwan");
}

CellularDeviceTray::~CellularDeviceTray ()
{
	delete d;
}


#include "tdenetman-cellular_device_tray.moc"