[plasma-mobile/sebas/firstrun] shell/firstrun: make it somehow work

Sebastian Kügler sebas at kde.org
Mon Oct 3 23:44:16 UTC 2011


Git commit 93e636c7509c0893f8f1c1f374637b60ec428b4f by Sebastian Kügler.
Committed on 04/10/2011 at 01:34.
Pushed by sebas into branch 'sebas/firstrun'.

make it somehow work

We have a binary /usr/bin/active-firstrun which waits for a bit, then
reads the configured activities, which are created on first start of
plasma-device. For preconfigured activities (chosen by name!), we add a
few bookmarks and apps on activity screen. This needs to cleaned this
list up with fania's specs, btw).

Caveats:
- waits for 60 seconds right now in order to have nepomuk start up,
  otherwise soprano can't find the server
- after first run, bookmarks and apps appear on all activities. this
  seems to 'fix itself' after restarting plasma-device. Maybe the
  activityscreen doesn't pay close enough attention when bookmarks / apps
  are added?
- For bookmarks, we don't get previews: bookmarks are likely to be added
  by active-firstrun before the network is up. Should probably show a
  suitable icon in that case and update the preview later on.
- .desktop file in /config/ coming up

I'm not overly happy with this, but it might be good enough for PA1, as
it makes the UI quite a bit more discoverable. What do you guys think?

CC:active at kde.org

M  +9    -0    shell/firstrun/CMakeLists.txt
M  +2    -2    shell/firstrun/app.cpp
M  +58   -25   shell/firstrun/firstrun.cpp
M  +5    -2    shell/firstrun/firstrun.h

http://commits.kde.org/plasma-mobile/93e636c7509c0893f8f1c1f374637b60ec428b4f

diff --git a/shell/firstrun/CMakeLists.txt b/shell/firstrun/CMakeLists.txt
index acaa627..e2fe17e 100644
--- a/shell/firstrun/CMakeLists.txt
+++ b/shell/firstrun/CMakeLists.txt
@@ -22,6 +22,15 @@ set(firstrun_SRCS
     firstrun.cpp
 )
 
+soprano_add_ontology(
+    firstrun_SRCS
+    ${CMAKE_CURRENT_SOURCE_DIR}/kext.trig
+    "KEXT" "Nepomuk::Vocabulary" "trig"
+)
+
+find_package(Nepomuk REQUIRED)
+find_package(KActivities REQUIRED)
+
 KDE4_ADD_EXECUTABLE(active-firstrun ${firstrun_SRCS})
 
 target_link_libraries(active-firstrun
diff --git a/shell/firstrun/app.cpp b/shell/firstrun/app.cpp
index 11b635c..75048b4 100644
--- a/shell/firstrun/app.cpp
+++ b/shell/firstrun/app.cpp
@@ -28,8 +28,8 @@ App::App(int argc, char **argv)
     m_firstRun = new FirstRun(this);
     kDebug() << "connecting...";
     connect(m_firstRun, SIGNAL(done()), SLOT(quit()));
-    quit();
-    exit();
+    //quit();
+    //exit();
 }
 
 App::~App()
diff --git a/shell/firstrun/firstrun.cpp b/shell/firstrun/firstrun.cpp
index 9ca3d4b..9296336 100644
--- a/shell/firstrun/firstrun.cpp
+++ b/shell/firstrun/firstrun.cpp
@@ -18,6 +18,7 @@
  */
 
 #include "firstrun.h"
+#include "kext.h"
 
 #include <kactivitycontroller.h>
 #include <kactivityinfo.h>
@@ -31,36 +32,38 @@
 #include <KConfig>
 #include <soprano/vocabulary.h>
 
+#include <QTimer>
+
 FirstRun::FirstRun(QObject* parent)
     : QObject(parent),
     m_activityController(0)
 {
-    init();
+    m_initialActivities << "Introduction" << "Vacation Planning" << "My First Activity";
+
+    // wait until the system has settled down
+    // yep, hack, but needed to prevent race conditions when nepomuk is no up yet :/
+    QTimer::singleShot(60000, this, SLOT(init()));
 }
 
 void FirstRun::init()
 {
-
     KConfig* scfg = new KConfig("active-firstrunrc");
     KConfigGroup grp = scfg->group("general");
     bool hasRun = grp.readEntry("hasRun", false);
     delete scfg;
-    kError() << "Starting first run ..." << hasRun;
+    kError() << "Starting first run ..." << !hasRun;
     if (!hasRun) {
         m_activityController = new KActivityController(this);
         m_currentActivity = m_activityController->currentActivity();
         QStringList activities = m_activityController->listActivities();
-        //setData("allActivities", activities);
         foreach (const QString &id, activities) {
-            kError() << "Activity: " << id;
-            activityAdded(id);        }
+            activityAdded(id);
+        }
         connect(m_activityController, SIGNAL(activityAdded(QString)), this, SLOT(activityAdded(QString)));
     } else {
         kError() << "Already ran, doing nothing";
+        emit done();
     }
-    kError() << "Done.";
-    emit done();
-    markDone();
 }
 
 FirstRun::~FirstRun()
@@ -69,27 +72,56 @@ FirstRun::~FirstRun()
 
 void FirstRun::activityAdded(const QString& source)
 {
-    kError() << "Source added: " << source;
-    if (!source.isEmpty()) {
-        KActivityInfo* info = new KActivityInfo(source);
-        kError() << "AAA: " << info->name();
-        if (info->name() == "Introduction") {
-            connectToActivity("http://en.wikipedia.org/wiki/Berlin", source, "Wikipedia: Berlin");
-            connectToActivity("http://wikitravel.org/wiki/Berlin", source, "Wikitravel: Berlin");
-            connectToActivity("http://maps.google.com", source);
-        } else if (info->name() == "My First Activity") {
-            connectToActivity("http://vizZzion.org", source, "VizZzion.org");
-        } else if (info->name() == "Vacation Planning") {
-            connectToActivity("http://seashepherd.org", source, "Seashepherd dot Org");
-        }
+    KActivityInfo* info = new KActivityInfo(source);
+    kError() << "------> Source added: " << info->name() << source;
+
+    // Check if it's among the default activities and wether we've configured this actity already
+    if (!m_initialActivities.contains(info->name())) {
+        //kError() << "noinit";
+        return;
+    }
+    if (m_completedActivities.contains(info->name())) {
+        //kError() << "completed";
+        return;
+    }
+    m_completedActivities << info->name();
+    kError() << "------> Source added: " << info->name() << source;
+
+    QString appPath = "/usr/share/applications/kde4/";
+
+    //kError() << "AAA: " << info->name();
+    if (info->name() == "Introduction") {
+        // Bookmarks
+        connectToActivity(source, "http://en.wikipedia.org/wiki/Berlin", "Wikipedia: Berlin");
+        connectToActivity(source, "http://wikitravel.org/en/Berlin", "Wikitravel: Berlin");
+        connectToActivity(source, "http://maps.google.com", "Google Maps");
+
+        // Apps
+        connectToActivity(source, appPath + "active-web-browser.desktop", "Browser");
+    } else if (info->name() == "My First Activity") {
+        connectToActivity(source, "http://vizZzion.org", "VizZzion.org");
+        connectToActivity(source, appPath + "active-news-reader.desktop");
+    } else if (info->name() == "Vacation Planning") {
+        connectToActivity(source, "http://seashepherd.org", "Seashepherd dot Org");
+        connectToActivity(source, appPath + "active-image-viewer.desktop");
+    }
+
+    kError() << "SSS" << m_completedActivities.size() << m_initialActivities.size();
+    if (m_completedActivities.size() == m_initialActivities.size()) {
+        markDone();
+        kError() << "Saved. Quitting.";
+        emit done();
     }
 }
 
-void FirstRun::connectToActivity(const QString &resourceUrl, const QString &activityId, const QString &description)
+void FirstRun::connectToActivity(const QString &activityId, const QString &resourceUrl, const QString &description)
 {
     Nepomuk::Resource fileRes(resourceUrl);
     QUrl typeUrl;
-    kError() << "Adding resource " << description << " [" << resourceUrl << "] to acivity " << activityId;
+
+    KActivityInfo* info = new KActivityInfo(activityId); // FIXME: remove
+
+    //kError() << "   Adding resource " << description << " [" << resourceUrl << "] to acivity " << activityId;
     //Bookmark?
     if (QUrl(resourceUrl).scheme() == "http") {
         typeUrl = QUrl("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Bookmark");
@@ -107,7 +139,8 @@ void FirstRun::connectToActivity(const QString &resourceUrl, const QString &acti
         }
     }
 
-    Nepomuk::Resource acRes("activities://" + activityId);
+    kError() << "       Added resource " << description << " to " << info->name();
+    Nepomuk::Resource acRes(activityId, Nepomuk::Vocabulary::KEXT::Activity());
     acRes.addProperty(Soprano::Vocabulary::NAO::isRelated(), fileRes);
 }
 
diff --git a/shell/firstrun/firstrun.h b/shell/firstrun/firstrun.h
index 1601f8a..9f8d937 100644
--- a/shell/firstrun/firstrun.h
+++ b/shell/firstrun/firstrun.h
@@ -21,6 +21,7 @@
 #define FIRSTRUN_H
 
 #include <QObject>
+#include <QStringList>
 #include <QUrl>
 
 namespace Plasma {
@@ -38,20 +39,22 @@ class FirstRun: public QObject
         FirstRun(QObject *parent = 0);
         ~FirstRun();
 
-        void init();
 
     Q_SIGNALS:
         void done();
 
     private Q_SLOTS:
+        void init();
         void activityAdded(const QString& source);
         void markDone();
 
     private:
-        void connectToActivity(const QString &resourceUrl, const QString &activityId, const QString &description = QString());
+        void connectToActivity(const QString &activityId, const QString &resourceUrl, const QString &description = QString());
         //Plasma::DataEngine* m_activityEngine;
         KActivityController *m_activityController;
         QString m_currentActivity;
+        QStringList m_initialActivities;
+        QStringList m_completedActivities;
 
 };
 



More information about the Active mailing list