~ubuntu-branches/ubuntu/oneiric/kdeplasma-addons/oneiric

« back to all changes in this revision

Viewing changes to libs/lancelot-datamodels/SystemServices.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-05-25 09:50:14 UTC
  • mto: (0.4.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 68.
  • Revision ID: james.westby@ubuntu.com-20100525095014-e3cebfkdenjrx3xg
Tags: upstream-4.4.80
ImportĀ upstreamĀ versionĀ 4.4.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2007, 2008, 2009, 2010 Ivan Cukic <ivan.cukic(at)kde.org>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU Lesser/Library General Public License version 2,
 
6
 *   or (at your option) any later version, as published by the Free
 
7
 *   Software Foundation
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *   GNU Lesser/Library General Public License for more details
 
13
 *
 
14
 *   You should have received a copy of the GNU Lesser/Library General Public
 
15
 *   License along with this program; if not, write to the
 
16
 *   Free Software Foundation, Inc.,
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
#include "SystemServices.h"
 
21
 
 
22
#include <KDebug>
 
23
#include <KStandardDirs>
 
24
#include <KIcon>
 
25
 
 
26
namespace Lancelot {
 
27
namespace Models {
 
28
 
 
29
#define LinkOrCopy(source, destination)           \
 
30
    kDebug() << "Models::LinkOrCopy:"             \
 
31
                 << source << destination;        \
 
32
    if (!QFile::link((source), (destination))) {  \
 
33
        kDebug() << "Models::LinkOrCopy:"         \
 
34
                 << "Linking failed ... copying"; \
 
35
        QFile::copy((source), (destination));     \
 
36
    }
 
37
 
 
38
SystemServices::SystemServices()
 
39
    : FolderModel(SystemServices::path(), QDir::Name)
 
40
{
 
41
    setSelfTitle(i18n("System"));
 
42
    setSelfIcon(KIcon("computer"));
 
43
 
 
44
    QDir dir(path());
 
45
    if (dir.entryList(QDir::Files | QDir::NoDotAndDotDot).size() == 0) {
 
46
 
 
47
        QStringList applications;
 
48
        applications
 
49
            << "systemsettings"
 
50
            << "ksysguard"
 
51
            << "kinfocenter";
 
52
 
 
53
        int index = 0;
 
54
 
 
55
        foreach (const QString & serviceAlternatives, applications) {
 
56
            foreach (const QString & serviceName, serviceAlternatives.split('|')) {
 
57
                const KService::Ptr service = KService::serviceByStorageId(serviceName);
 
58
                if (service) {
 
59
                    QFileInfo file(service->entryPath());
 
60
                    LinkOrCopy(
 
61
                        service->entryPath(),
 
62
                        dir.absolutePath() + '/' +
 
63
                        QString::number(index++) + '_' + file.fileName());
 
64
                    break;
 
65
                }
 
66
            }
 
67
        }
 
68
    }
 
69
}
 
70
 
 
71
SystemServices::~SystemServices()
 
72
{
 
73
}
 
74
 
 
75
QString SystemServices::path()
 
76
{
 
77
    QString path = KStandardDirs::locateLocal("data", "lancelot", true);
 
78
    if (!path.endsWith('/')) {
 
79
        path += '/';
 
80
    }
 
81
    path += "/systemservices/";
 
82
 
 
83
    QDir dir;
 
84
    dir.mkpath(path);
 
85
 
 
86
    return path;
 
87
}
 
88
 
 
89
} // namespace Models
 
90
} // namespace Lancelot