2
* Copyright 2011 Sebastian Kügler <sebas@kde.org>
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.
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
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.
23
#include <KActivities/Controller>
24
#include <KActivities/Info>
26
#include <Nepomuk/Query/QueryServiceClient>
27
#include <Nepomuk/Resource>
28
#include <Nepomuk/Variant>
30
#include <Plasma/DataEngine>
31
#include <Plasma/DataEngineManager>
34
#include <soprano/vocabulary.h>
36
#include <QDBusConnection>
37
#include <QDBusServiceWatcher>
40
FirstRun::FirstRun(QObject* parent)
42
m_activityController(0)
44
m_initialActivities << "Introduction" << "Vacation Planning" << "My First Activity";
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()));
51
m_queryServiceWatcher = new QDBusServiceWatcher(QLatin1String("org.kde.nepomuk.services.nepomukqueryservice"),
52
QDBusConnection::sessionBus(),
53
QDBusServiceWatcher::WatchForRegistration,
55
connect(m_queryServiceWatcher, SIGNAL(serviceRegistered(QString)), this, SLOT(serviceRegistered(QString)));
59
void FirstRun::serviceRegistered(const QString &service)
61
if (service == "org.kde.nepomuk.services.nepomukqueryservice") {
68
KConfig* scfg = new KConfig("active-firstrunrc");
69
KConfigGroup grp = scfg->group("general");
70
bool hasRun = grp.readEntry("hasRun", false);
72
kError() << "Starting first run ..." << !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) {
80
connect(m_activityController, SIGNAL(activityAdded(QString)), this, SLOT(activityAdded(QString)));
82
kError() << "Already ran, doing nothing";
91
void FirstRun::activityAdded(const QString& source)
93
KActivities::Info* info = new KActivities::Info(source);
94
kError() << "------> Source added: " << info->name() << source;
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";
101
if (m_completedActivities.contains(info->name())) {
102
//kError() << "completed";
105
m_completedActivities << info->name();
106
kError() << "------> Source added: " << info->name() << source;
108
QString appPath = "/usr/share/applications/kde4/";
110
//kError() << "AAA: " << info->name();
111
if (info->name() == "Introduction") {
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") {
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");
125
connectToActivity(source, appPath + "active-image-viewer.desktop");
126
connectToActivity(source, appPath + "kwrite.desktop");
127
connectToActivity(source, appPath + "korganizer-mobile.desktop");
130
if (m_completedActivities.size() == m_initialActivities.size()) {
132
kError() << "All done. Quitting.";
137
void FirstRun::connectToActivity(const QString &activityId, const QString &resourceUrl, const QString &description)
139
Nepomuk::Resource fileRes(resourceUrl);
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);
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());
154
fileRes.setLabel(service->name());
155
fileRes.setSymbols(QStringList() << service->icon());
159
kError() << " Added resource " << description << " to " << activityId;
160
Nepomuk::Resource acRes(activityId, Nepomuk::Vocabulary::KEXT::Activity());
161
acRes.addProperty(Soprano::Vocabulary::NAO::isRelated(), fileRes);
164
void FirstRun::markDone()
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);
174
#include "firstrun.moc"
b'\\ No newline at end of file'