~ubuntu-branches/ubuntu/saucy/plasma-mobile/saucy

« back to all changes in this revision

Viewing changes to shell/firstrun/firstrun.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-07-17 12:04:43 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120717120443-q3ig9u2fnltx67yg
Tags: 2.0+git2012071701-0ubuntu1
* New upstream snapshot
* Remove build-dep on kde-runtime-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *   Copyright 2011 Sebastian Kügler <sebas@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 as
6
 
 *   published by the Free Software Foundation; either version 2, or
7
 
 *   (at your option) any later version.
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 General Public License for more details
13
 
 *
14
 
 *   You should have received a copy of the GNU 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 "firstrun.h"
21
 
#include "kext.h"
22
 
 
23
 
#include <KActivities/Controller>
24
 
#include <KActivities/Info>
25
 
 
26
 
#include <Nepomuk/Query/QueryServiceClient>
27
 
#include <Nepomuk/Resource>
28
 
#include <Nepomuk/Variant>
29
 
 
30
 
#include <Plasma/DataEngine>
31
 
#include <Plasma/DataEngineManager>
32
 
 
33
 
#include <KConfig>
34
 
#include <soprano/vocabulary.h>
35
 
 
36
 
#include <QDBusConnection>
37
 
#include <QDBusServiceWatcher>
38
 
#include <QTimer>
39
 
 
40
 
FirstRun::FirstRun(QObject* parent)
41
 
    : QObject(parent),
42
 
    m_activityController(0)
43
 
{
44
 
    m_initialActivities << "Introduction" << "Vacation Planning" << "My First Activity";
45
 
 
46
 
    // wait until the system has settled down
47
 
    // yep, hack, but needed to prevent race conditions when nepomuk is no up yet :/
48
 
    if (Nepomuk::Query::QueryServiceClient::serviceAvailable()) {
49
 
        QTimer::singleShot(5000, this, SLOT(init()));
50
 
    } else {
51
 
        m_queryServiceWatcher = new QDBusServiceWatcher(QLatin1String("org.kde.nepomuk.services.nepomukqueryservice"),
52
 
                            QDBusConnection::sessionBus(),
53
 
                            QDBusServiceWatcher::WatchForRegistration,
54
 
                            this);
55
 
        connect(m_queryServiceWatcher, SIGNAL(serviceRegistered(QString)), this, SLOT(serviceRegistered(QString)));
56
 
    }
57
 
}
58
 
 
59
 
void FirstRun::serviceRegistered(const QString &service)
60
 
{
61
 
    if (service == "org.kde.nepomuk.services.nepomukqueryservice") {
62
 
        init();
63
 
    }
64
 
}
65
 
 
66
 
void FirstRun::init()
67
 
{
68
 
    KConfig* scfg = new KConfig("active-firstrunrc");
69
 
    KConfigGroup grp = scfg->group("general");
70
 
    bool hasRun = grp.readEntry("hasRun", false);
71
 
    delete scfg;
72
 
    kError() << "Starting first run ..." << !hasRun;
73
 
    if (!hasRun) {
74
 
        m_activityController = new KActivities::Controller(this);
75
 
        m_currentActivity = m_activityController->currentActivity();
76
 
        QStringList activities = m_activityController->listActivities();
77
 
        foreach (const QString &id, activities) {
78
 
            activityAdded(id);
79
 
        }
80
 
        connect(m_activityController, SIGNAL(activityAdded(QString)), this, SLOT(activityAdded(QString)));
81
 
    } else {
82
 
        kError() << "Already ran, doing nothing";
83
 
        emit done();
84
 
    }
85
 
}
86
 
 
87
 
FirstRun::~FirstRun()
88
 
{
89
 
}
90
 
 
91
 
void FirstRun::activityAdded(const QString& source)
92
 
{
93
 
    KActivities::Info* info = new KActivities::Info(source);
94
 
    kError() << "------> Source added: " << info->name() << source;
95
 
 
96
 
    // Check if it's among the default activities and wether we've configured this actity already
97
 
    if (!m_initialActivities.contains(info->name())) {
98
 
        //kError() << "noinit";
99
 
        return;
100
 
    }
101
 
    if (m_completedActivities.contains(info->name())) {
102
 
        //kError() << "completed";
103
 
        return;
104
 
    }
105
 
    m_completedActivities << info->name();
106
 
    kError() << "------> Source added: " << info->name() << source;
107
 
 
108
 
    QString appPath = "/usr/share/applications/kde4/";
109
 
 
110
 
    //kError() << "AAA: " << info->name();
111
 
    if (info->name() == "Introduction") {
112
 
        // Bookmarks
113
 
        connectToActivity(source, "http://www.plasma-active.org", "Plasma Active");
114
 
        connectToActivity(source, "http://community.kde.org/Plasma/Active/Info/FAQ", "FAQ");
115
 
        connectToActivity(source, appPath + "adjust-time.desktop");
116
 
    } else if (info->name() == "My First Activity") {
117
 
        // leaving it empty to invite creativity
118
 
    } else if (info->name() == "Vacation Planning") {
119
 
        // Bookmarks
120
 
        connectToActivity(source, "http://www.deutschebahn.com", "Deutsche Bahn");
121
 
        connectToActivity(source, "http://wikitravel.org/en/Berlin", "Berlin Travel Guide");
122
 
        connectToActivity(source, "http://osm.org/go/0MbEYhO8-", "OpenStreetMap Berlin");
123
 
 
124
 
        // Apps
125
 
        connectToActivity(source, appPath + "active-image-viewer.desktop");
126
 
        connectToActivity(source, appPath + "kwrite.desktop");
127
 
        connectToActivity(source, appPath + "korganizer-mobile.desktop");
128
 
    }
129
 
 
130
 
    if (m_completedActivities.size() == m_initialActivities.size()) {
131
 
        markDone();
132
 
        kError() << "All done. Quitting.";
133
 
        emit done();
134
 
    }
135
 
}
136
 
 
137
 
void FirstRun::connectToActivity(const QString &activityId, const QString &resourceUrl, const QString &description)
138
 
{
139
 
    Nepomuk::Resource fileRes(resourceUrl);
140
 
    QUrl typeUrl;
141
 
 
142
 
    //Bookmark?
143
 
    if (QUrl(resourceUrl).scheme() == "http") {
144
 
        typeUrl = QUrl("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Bookmark");
145
 
        fileRes.addType(typeUrl);
146
 
        fileRes.setDescription(description);
147
 
        fileRes.setProperty(QUrl::fromEncoded("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#bookmarks"), resourceUrl);
148
 
    // App?
149
 
    } else if (resourceUrl.endsWith(".desktop")) {
150
 
        typeUrl = QUrl("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Application");
151
 
        fileRes.addType(typeUrl);
152
 
        KService::Ptr service = KService::serviceByDesktopPath(QUrl(resourceUrl).path());
153
 
        if (service) {
154
 
            fileRes.setLabel(service->name());
155
 
            fileRes.setSymbols(QStringList() << service->icon());
156
 
        }
157
 
    }
158
 
 
159
 
    kError() << "       Added resource " << description << " to " << activityId;
160
 
    Nepomuk::Resource acRes(activityId, Nepomuk::Vocabulary::KEXT::Activity());
161
 
    acRes.addProperty(Soprano::Vocabulary::NAO::isRelated(), fileRes);
162
 
}
163
 
 
164
 
void FirstRun::markDone()
165
 
{
166
 
    kError() << "Noting in kconfig that we've run once.";
167
 
    KConfig* scfg = new KConfig("active-firstrunrc");
168
 
    KConfigGroup grp = scfg->group("general");
169
 
    grp.writeEntry("hasRun", true);
170
 
    scfg->sync();
171
 
    delete scfg;
172
 
}
173
 
 
174
 
#include "firstrun.moc"
 
 
b'\\ No newline at end of file'