~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/dataengines/apps/appsengine.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2009 Chani Armitage <chani@kde.org>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU Library General Public License version 2 as
 
6
 *   published by the Free Software Foundation
 
7
 *
 
8
 *   This program is distributed in the hope that it will be useful,
 
9
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 *   GNU General Public License for more details
 
12
 *
 
13
 *   You should have received a copy of the GNU Library General Public
 
14
 *   License along with this program; if not, write to the
 
15
 *   Free Software Foundation, Inc.,
 
16
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
17
 */
 
18
 
 
19
#include "appsengine.h"
 
20
#include "appsource.h"
 
21
 
 
22
#include <KSycoca>
 
23
 
 
24
AppsEngine::AppsEngine(QObject *parent, const QVariantList &args) :
 
25
    Plasma::DataEngine(parent, args)
 
26
{
 
27
    Q_UNUSED(args);
 
28
}
 
29
 
 
30
AppsEngine::~AppsEngine()
 
31
{
 
32
}
 
33
 
 
34
void AppsEngine::init()
 
35
{
 
36
    addGroup(KServiceGroup::root());
 
37
    connect(KSycoca::self(), SIGNAL(databaseChanged(QStringList)), this, SLOT(sycocaChanged(QStringList)));
 
38
}
 
39
 
 
40
void AppsEngine::sycocaChanged(const QStringList &changes)
 
41
{
 
42
    if (changes.contains("apps") || changes.contains("xdgdata-apps")) {
 
43
        removeAllSources();
 
44
        addGroup(KServiceGroup::root());
 
45
    }
 
46
}
 
47
 
 
48
Plasma::Service *AppsEngine::serviceForSource(const QString &name)
 
49
{
 
50
    AppSource *source = dynamic_cast<AppSource*>(containerForSource(name));
 
51
    // if source does not exist, return null service
 
52
    if (!source) {
 
53
        return Plasma::DataEngine::serviceForSource(name);
 
54
    }
 
55
 
 
56
    // if source represents a group or something, return null service
 
57
    if (!source->isApp()) {
 
58
        return Plasma::DataEngine::serviceForSource(name);
 
59
    }
 
60
    // if source represent a proper app, return real service
 
61
    Plasma::Service *service = source->createService();
 
62
    service->setParent(this);
 
63
    return service;
 
64
}
 
65
 
 
66
void AppsEngine::addGroup(KServiceGroup::Ptr group)
 
67
{
 
68
    if (!(group && group->isValid())) {
 
69
        return;
 
70
    }
 
71
    AppSource *appSource = new AppSource(group, this);
 
72
    //TODO listen for changes
 
73
    addSource(appSource);
 
74
    //do children
 
75
    foreach (const KServiceGroup::Ptr subGroup, group->groupEntries(KServiceGroup::NoOptions)) {
 
76
        addGroup(subGroup);
 
77
    }
 
78
    foreach (const KService::Ptr app, group->serviceEntries(KServiceGroup::NoOptions)) {
 
79
        addApp(app);
 
80
    }
 
81
}
 
82
 
 
83
void AppsEngine::addApp(KService::Ptr app)
 
84
{
 
85
    AppSource *appSource = new AppSource(app, this);
 
86
    //TODO listen for changes
 
87
    addSource(appSource);
 
88
}
 
89
 
 
90
K_EXPORT_PLASMA_DATAENGINE(apps, AppsEngine)
 
91
 
 
92
#include "appsengine.moc"