summaryrefslogtreecommitdiffstats
path: root/knetworkmanager-0.8/src/knetworkmanager-connection_setting_vpn.cpp
blob: 1fe2401723e53d823916f614a09784b7d154947c (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/***************************************************************************
 *
 * knetworkmanager-connection_setting_vpn.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
 *
 **************************************************************************/

/* qt headers */
#include <tqhostaddress.h>
#include <tqvariant.h>

/* kde headers */
#include <kdebug.h>
#include <tdelocale.h>

/* TQT_DBus headers*/
#include <tqdbusdata.h>
#include <tqdbusdatamap.h>

/* knetworkmanager headers */
#include "knetworkmanager.h"
#include "knetworkmanager-connection_setting_vpn.h"

using namespace ConnectionSettings;

/*
	class VPN
*/
VPN::VPN(Connection* conn)
	: ConnectionSetting(conn, NM_SETTING_VPN_SETTING_NAME)
{

}

TQString VPN::getUserName() const
{
	return _userName;
}

void VPN::setUserName(const TQString& u)
{
	_userName = u;
	emitValidityChanged();
}

TQString VPN::getServiceType() const
{
	return _serviceType;
}

void VPN::setServiceType(const TQString& s)
{
	_serviceType = s;
	emitValidityChanged();
}

TQValueList<TQString> VPN::getRoutes() const
{
	return _routes;
}

void VPN::setRoutes(const TQValueList<TQString>& r)
{
	_routes = r;
	emitValidityChanged();
}

void VPN::setData(TQMap<TQString, TQString> data)
{
	_data = data;
	emitValidityChanged();
}

TQMap<TQString, TQString> VPN::getData() const
{
	return _data;
}

void VPN::setSecrets(const TQMap<TQString, TQString>& data)
{
	_secrets = data;
	emitValidityChanged();
}

TQMap<TQString, TQString> VPN::getSecrets() const
{
	return _secrets;
}


SettingsMap
VPN::toMap() const
{
	SettingsMap map;

	map.insert(NM_SETTING_VPN_SERVICE_TYPE, TQT_DBusData::fromString(_serviceType));
	map.insert(NM_SETTING_VPN_USER_NAME, TQT_DBusData::fromString(_userName));

	if (!_routes.isEmpty())
	{
		TQValueList<TQT_DBusData> list;
		for (TQValueList<TQString>::ConstIterator it = _routes.begin(); it != _routes.end(); ++it)
		{
			list.append(TQT_DBusData::fromString(*it));
		}
	}

	// NM expects a String/String map -> convert
	TQT_DBusDataMap<TQString> data;
	
	for (TQMap<TQString, TQString>::ConstIterator it = _data.begin(); it != _data.end(); ++it)
	{
		data.insert(it.key(), TQT_DBusData::fromString(it.data()));
	}

	map.insert(NM_SETTING_VPN_DATA, TQT_DBusData::fromStringKeyMap(data));


	return map;
}

void
VPN::fromMap(const SettingsMap& map)
{
	SettingsMap::ConstIterator it;

	if ((it = map.find(NM_SETTING_VPN_SERVICE_TYPE)) != map.end())
		_serviceType = it.data().toString();
	
	if ((it = map.find(NM_SETTING_VPN_USER_NAME)) != map.end())
		_userName = it.data().toString();

	TQT_DBusDataMap<TQString> data;
	_data.clear();

	if ((it = map.find(NM_SETTING_VPN_DATA)) != map.end())
	{
		data = it.data().toStringKeyMap();
		for (TQMap<TQString, TQT_DBusData>::ConstIterator it = data.begin(); it != data.end(); ++it)
		{
			_data.insert(it.key(), it.data().toString());
		} 
	}
}

SettingsMap
VPN::toSecretsMap(bool with_settings) const
{
	SettingsMap map;

	// NM does not want the settings too
/*	if (with_settings)
		map = toMap();*/

	// copy all secrets into the map
	for (TQMap<TQString, TQString>::ConstIterator it = _secrets.begin(); it != _secrets.end(); ++it)
		map.insert(it.key(), TQT_DBusData::fromString(it.data()));

	return map;
}

bool
VPN::fromSecretsMap(const SettingsMap& map)
{
/*	SettingsMap::ConstIterator it;
	TQT_DBusDataMap<TQString> data;
	
	if ((it = map.find(NM_SETTING_VPN_DATA)) != map.end())
	{
		data = it.data().toStringKeyMap();
		_data = data.toTQMap();
	}*/
	// FIXME
	return false;
}

bool
VPN::isValid() const
{
	// name is essential
	if (_userName.isEmpty() || _serviceType.isEmpty())
		return false;

	// data is essential
	if (_data.isEmpty())
		return false;

	return true;
}