~ubuntu-branches/ubuntu/trusty/knetworkmanager/trusty

« back to all changes in this revision

Viewing changes to knetworkmanager-0.7/src/knetworkmanager-vpnmanager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-09-26 12:40:26 UTC
  • mfrom: (1.2.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080926124026-t5fr920l4lf2l6hz
Tags: 1:0.7svn864988-0ubuntu1
New upstream snapshot, now works with current NM API, 
closes LP: #259278

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *
 
3
 * knetworkmanager-vpnmanager.cpp - A NetworkManager frontend for KDE 
 
4
 *
 
5
 * Copyright (C) 2006 Novell, Inc.
 
6
 *
 
7
 * Author: Timo Hoenig <thoenig@suse.de>, <thoenig@nouse.net>
 
8
 *         Helmut Schaa <hschaa@suse.de>, <helmut.schaa@gmx.de>
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 2 of the License, or
 
13
 * (at your option) any later version.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 * 
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program; if not, write to the Free Software
 
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
 *
 
24
 **************************************************************************/
 
25
 
 
26
#define SERVICE_DIR "/etc/NetworkManager/VPN"
 
27
 
 
28
#include <klocale.h>
 
29
#include <qdir.h>
 
30
#include <kdebug.h>
 
31
#include <kconfig.h>
 
32
 
 
33
#include "knetworkmanager-vpnmanager.h"
 
34
#include "knetworkmanager-vpnservice.h"
 
35
#include "knetworkmanager-vpnplugin.h"
 
36
 
 
37
/*
 
38
 *  class VPNManager
 
39
 *
 
40
 */
 
41
VPNServiceList
 
42
VPNManager::getVPNServices ()
 
43
{
 
44
        bool status = false;
 
45
        VPNServiceList list;
 
46
        
 
47
        QDir serviceDir(SERVICE_DIR, QString::null, QDir::Name|QDir::IgnoreCase, QDir::Files);
 
48
        QStringList services = serviceDir.entryList ().grep (".name", true);
 
49
 
 
50
        if (services.count () > 0)
 
51
        {       
 
52
                status = true;
 
53
                // read in all available Services
 
54
                for (QStringList::Iterator i = services.begin (); i != services.end (); ++i) {
 
55
                        QString service = SERVICE_DIR + QString ("/") + *i;
 
56
                        KConfig* kconfig = new KConfig (service, true, true, "config");
 
57
                        kconfig->setGroup ("VPN Connection");
 
58
 
 
59
printf("VPN Service %s\n", kconfig->readEntry ("name", QString::null).ascii());
 
60
 
 
61
                        // create new VPNService Object
 
62
                        VPNService* vpnservice = new VPNService(kconfig->readEntry ("name", QString::null), kconfig->readEntry ("service", QString::null), KNetworkManager::getInstance());
 
63
                        if (!vpnservice->getVPNPlugin())
 
64
                                delete vpnservice;
 
65
                        else
 
66
                                list.push_back(vpnservice);
 
67
                        delete kconfig;
 
68
                }
 
69
        }
 
70
 
 
71
        return list;
 
72
}
 
73
 
 
74
VPNService*
 
75
VPNManager::getVPNService(QString service_type)
 
76
{
 
77
        bool status = false;
 
78
        VPNServiceList list;
 
79
        
 
80
        QDir serviceDir(SERVICE_DIR, QString::null, QDir::Name|QDir::IgnoreCase, QDir::Files);
 
81
        QStringList services = serviceDir.entryList ().grep (".name", true);
 
82
 
 
83
        if (services.count () > 0)
 
84
        {       
 
85
                status = true;
 
86
                // read in all available Services
 
87
                for (QStringList::Iterator i = services.begin (); i != services.end (); ++i) {
 
88
                        QString service = SERVICE_DIR + QString ("/") + *i;
 
89
                        KConfig* kconfig = new KConfig (service, true, true, "config");
 
90
                        kconfig->setGroup ("VPN Connection");
 
91
 
 
92
                        if (kconfig->readEntry ("service", QString::null) == service_type)
 
93
                        {
 
94
                                // create new VPNService Object
 
95
                                VPNService* vpnservice = new VPNService(kconfig->readEntry ("name", QString::null), kconfig->readEntry ("service", QString::null), KNetworkManager::getInstance());
 
96
                                if (!vpnservice->getVPNPlugin())
 
97
                                        delete vpnservice;
 
98
                                else
 
99
                                        return vpnservice;
 
100
                        }
 
101
                }
 
102
        }
 
103
        return NULL;
 
104
 
 
105
}
 
106
 
 
107
#include "knetworkmanager-vpnmanager.moc"