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
139
140
141
142
143
144
145
146
147
148
149
150
|
/***************************************************************************
*
* vpn_tray_componenet.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
*
**************************************************************************/
// KDE includes
#include <kdebug.h>
#include <tdelocale.h>
#include <kiconloader.h>
// TQt DBus
#include <tqdbusobjectpath.h>
// KNM includes
#include "vpn_tray_component.h"
#include "knetworkmanager-menuitem.h"
#include "knetworkmanager-menu_subhead.h"
#include "knetworkmanager-connection_store.h"
#include "knetworkmanager-vpn_connection.h"
#include "knetworkmanager-nm_proxy.h"
#include "knetworkmanager-connection_setting_info.h"
#include "knetworkmanager-connection_setting_vpn.h"
#include "knetworkmanager-connection_settings_dialog.h"
#include <stdio.h>
using namespace ConnectionSettings;
void VPNTrayComponent::slotShowNewConnectionDialog()
{
// create a new VPN connection
Connection* conn = new VPNConnection();
// edit the new connection
ConnectionSettingsDialogImpl* dlg = new ConnectionSettingsDialogImpl(conn, true, NULL, tray(), "connect_something", false, TQt::WDestructiveClose);
dlg->show();
}
void VPNTrayComponent::addMenuItems(TDEPopupMenu* menu)
{
int inactive_vpn_connections = 0;
char vpn_found;
char any_vpn_found = 0;
ConnectionStore* connectionStore = ConnectionStore::getInstance();
// Get all active connections
NMProxy* nm = NMProxy::getInstance();
TQValueList<TQPair<ConnectionSettings::Connection*, Device*> > map = nm->getActiveConnectionsMap();
// get all available VPN Connections
TQValueList<Connection*> connections = connectionStore->getConnections(NM_SETTING_VPN_SETTING_NAME);
if (!connections.empty())
{
TQPopupMenu* popup = new TQPopupMenu(menu);
for (TQValueList<Connection*>::iterator it = connections.begin(); it != connections.end(); ++it)
{
VPNConnection* vpnconn = dynamic_cast<VPNConnection*>(*it);
if (vpnconn)
{
// VPN connection found :)
Info* info = vpnconn->getInfoSetting();
// lets create a nice name for this connection
if (info)
{
TQString title = info->getName();
NetworkMenuItem* item = new NetworkMenuItem(NULL, vpnconn, TQT_TQOBJECT(menu));
vpn_found = 0;
for (TQValueList<TQPair<ConnectionSettings::Connection*, Device*> >::Iterator it = map.begin(); it != map.end(); ++it)
{
ConnectionSettings::GenericConnection* conn = dynamic_cast<ConnectionSettings::GenericConnection*>((*it).first);
if (conn) {
if (strcmp(info->getName(), conn->getInfoSetting()->getName()) == 0) {
vpn_found = 1;
any_vpn_found = 1;
}
}
}
if (vpn_found == 1) {
printf("Active VPN connection found\n");
}
else {
int id = popup->insertItem(SmallIcon ("encrypted", TQIconSet::Automatic), title, item, TQT_SLOT(slotActivate()));
inactive_vpn_connections++;
}
//menu->setItemChecked(id, ((*it) == active_conn));
}
}
}
TQT_DBusObjectPath act_conn = nm->getDefaultActiveConnection();
TQT_DBusObjectPath device = nm->getDeviceForActiveConnection(act_conn);
if (any_vpn_found == 1) {
inactive_vpn_connections = 0;
}
if (device.isNull()) {
inactive_vpn_connections = 0;
}
if (inactive_vpn_connections > 0) {
menu->insertItem(SmallIcon ("encrypted", TQIconSet::Automatic), i18n("Start VPN connection"), popup);
menu->insertSeparator();
}
}
}
VPNTrayComponent::VPNTrayComponent (KSystemTray * parent, const char * name )
: TrayComponent (parent, name)
{
//Actions used for plugging into the menu
new TDEAction (i18n ("New connection ..."),
SmallIcon ("encrypted", TQIconSet::Automatic), 0,
this, TQT_SLOT (slotShowNewConnectionDialog()), parent->actionCollection (), "create_new_vpn_connection");
}
VPNTrayComponent::~VPNTrayComponent ()
{
}
#include "vpn_tray_component.moc"
|