[plasma-mobile] applications/webbrowser/src: Nepomuk magic for downloading files

Sebastian Kügler sebas at kde.org
Thu Feb 2 22:59:52 UTC 2012


Git commit 38861fb962d889ae5e654e619161f68ba36f1b3f by Sebastian Kügler.
Committed on 02/02/2012 at 23:44.
Pushed by sebas into branch 'master'.

Nepomuk magic for downloading files

With this patch, the browser
- adds downloaded files to Nepomuk,
- tags them as "Download" (not translated -- maybe we should do that?),
- and adds them to the current Activity, as Ivan described and
- adds the source URL of the file as comment to the downloaded file's
  metadata

Ivan, could you check that the activity part works?

CCMAIL:active at kde.org

M  +21   -9    applications/webbrowser/src/kdeclarativewebview.cpp

http://commits.kde.org/plasma-mobile/38861fb962d889ae5e654e619161f68ba36f1b3f

diff --git a/applications/webbrowser/src/kdeclarativewebview.cpp b/applications/webbrowser/src/kdeclarativewebview.cpp
index 9446685..f23bcfd 100644
--- a/applications/webbrowser/src/kdeclarativewebview.cpp
+++ b/applications/webbrowser/src/kdeclarativewebview.cpp
@@ -42,6 +42,7 @@
 #include <qwebpage.h>
 #include <qwebsettings.h>
 
+#include <KActivities/Info>
 #include <KDirWatch>
 #include <KUrl>
 #include <KGlobalSettings>
@@ -62,7 +63,6 @@
 #include <Nepomuk/Tag>
 #include <Nepomuk/Variant>
 
-
 QT_BEGIN_NAMESPACE
 
 class KDeclarativeWebViewPrivate {
@@ -1249,7 +1249,6 @@ bool QDeclarativeWebPage::downloadResource (const KUrl& srcUrl, const QString& s
     const QString fileName ((suggestedName.isEmpty() ? srcUrl.fileName() : suggestedName));
     const KUrl &destUrl(QString("file://%1/%2").arg(QDir::homePath()).arg(fileName));
 
-
     if (!destUrl.isValid()) {
         return false;
     }
@@ -1271,18 +1270,31 @@ bool QDeclarativeWebPage::downloadResource (const KUrl& srcUrl, const QString& s
 
 void QDeclarativeWebPage::downloadFinished(KJob *job)
 {
-    //FIXME: this breaks all resources currently connected to the current activity
-    //reactivate as soon as the nepomuk bug is fixed
-    /*KIO::CopyJob *cj = qobject_cast<KIO::CopyJob *>(job);
+    KIO::CopyJob *cj = qobject_cast<KIO::CopyJob*>(job);
     if (cj && job->error() == KJob::NoError) {
-        QString activityId = m_activityConsumer->currentActivity();
+
+        // Create a FileDataObject Nepomuk Resource ...
         Nepomuk::Resource fileRes(cj->destUrl());
         fileRes.addType(QUrl("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#FileDataObject"));
+
+        // ... tag it as "Download"
         fileRes.addTag(Nepomuk::Tag("Download"));
 
-        Nepomuk::Resource acRes(activityId, Nepomuk::Vocabulary::KEXT::Activity());
-        acRes.addProperty(Soprano::Vocabulary::NAO::isRelated(), fileRes);
-    }*/
+        // ... add source URLs, there might be more than one, but common case is just one
+        QString u;
+        foreach (const KUrl &_u, cj->srcUrls()) {
+            u.append(_u.pathOrUrl() + " ");
+        }
+        fileRes.setDescription(i18n("Downloaded from %1", u));
+
+        // And link it to the currently active Activity
+        QString activityId = m_activityConsumer->currentActivity();
+        KActivities::Info aInfo(activityId);
+        aInfo.linkResource(cj->destUrl());
+    } else {
+        // TODO: handle download errors.
+        kError() << "Error downloading file: " << job->errorString();
+    }
 }
 
 void QDeclarativeWebPage::downloadRequest(const QNetworkRequest &request)


More information about the Active mailing list