summaryrefslogtreecommitdiffstats
path: root/knetworkmanager-0.8/src/knetworkmanager-vpnservice.cpp
blob: efedce3fc69e5bc431f643b70165b25be1ef6d9f (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
/***************************************************************************
 *
 * knetworkmanager-vpnservice.cpp - A NetworkManager frontend for KDE 
 *
 * Copyright (C) 2006 Novell, Inc.
 *
 * Author: Timo Hoenig <[email protected]>, <[email protected]>
 *         Helmut Schaa <[email protected]>, <[email protected]>
 *
 * 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
 *
 **************************************************************************/

#define SERVICE_DIR "/etc/NetworkManager/VPN"

#include <stdlib.h>
#include <tdeconfig.h>
#include <tqdom.h> 
#include <tqdir.h>
#include <tdelocale.h>
#include <kdebug.h>
#include <kstddirs.h>
#include <kprocess.h>
#include <tdeconfig.h>
#include <kplugininfo.h>

#include "knetworkmanager-pluginmanager.h"
#include "knetworkmanager-vpnservice.h"
#include "knetworkmanager-vpnplugin.h"

/*
 *  class VPNService
 *
 */

VPNService::VPNService(const TQString& serviceName, const TQString& service, TQObject* parent, const char* name)
	: TQObject(parent, name)
{
	_name = serviceName;
	_service = service;
	_vpnPlugin = NULL;

	// query if a plugin for this vpn service is available
	PluginManager* plugMan = PluginManager::getInstance();
	if (plugMan)
	{
		TQStringList list = plugMan->getPluginList("KNetworkManager/VPNPlugin", "X-NetworkManager-Services", serviceName);
		if (list.size() > 0)
		{
			// get the first VPN Plugin	handling our VPNService
			VPNPlugin* vpnPlugin = dynamic_cast<VPNPlugin*>( plugMan->getPlugin(list.first()) );
			if (vpnPlugin)
			{
				kdDebug() << k_funcinfo << i18n("Using VPN plugin '%1' for service '%2'").arg(list.first()).arg(serviceName) << endl;
				_vpnPlugin = vpnPlugin;
			}
		}
	}
}

VPNService::~VPNService()
{

}

TQString VPNService::getIcon()
{
	if (!_vpnPlugin.isNull())
	{
		PluginManager* plugMan = PluginManager::getInstance();
		if (plugMan)
		{
			const KPluginInfo* info = plugMan->getPluginInfo(_vpnPlugin);
			if (info)
			{
				TQString icon = info->icon();
				if (!icon.isEmpty())
					return icon;
			}
		}
	}
	return "encrypted";
}

VPNPlugin* VPNService::getVPNPlugin()
{
	return _vpnPlugin;
}

TQString VPNService::getService() const
{
	return _service;
}

TQString VPNService::getDisplayName() const
{
	const KPluginInfo* info = NULL;
	PluginManager* plugMan = PluginManager::getInstance();
	if (_vpnPlugin && plugMan)
		if ( (info = plugMan->getPluginInfo(_vpnPlugin)) )
			if (!info->name().isEmpty())
				return info->name();
	return _name;
}

TQString VPNService::getName() const
{
	return _name;
}

#include "knetworkmanager-vpnservice.moc"