[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kio
From:       Sebastian Trueg <sebastian () trueg ! de>
Date:       2010-07-06 17:20:16
Message-ID: 20100706172016.1BB3CAC8E6 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1146794 by trueg:

Format download source and referrer url the ugly way - we need to put this in a lib.

 M  +7 -1      CMakeLists.txt  
 M  +71 -6     kfile/kloadfilemetadatathread.cpp  
 M  +1 -1      kfile/kloadfilemetadatathread_p.h  


--- trunk/KDE/kdelibs/kio/CMakeLists.txt #1146793:1146794
@@ -189,6 +189,12 @@
     kfile/kcommentwidget.cpp
     kfile/kloadfilemetadatathread.cpp
   )
+
+  if(HAVE_NEPOMUK_WITH_SDO_0_5)
+    soprano_add_ontology(kfile_STAT_SRCS \
"${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nfo.trig" "NFO" "Nepomuk::Vocabulary" \
"trig") +    soprano_add_ontology(kfile_STAT_SRCS \
"${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nepomuk/ndo.trig" "NDO" "Nepomuk::Vocabulary" \
"trig") +    soprano_add_ontology(kfile_STAT_SRCS \
"${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nepomuk/nuao.trig" "NUAO" "Nepomuk::Vocabulary" \
"trig") +  endif(HAVE_NEPOMUK_WITH_SDO_0_5)
 endif(HAVE_NEPOMUK)
 
 if(NOT WIN32)
@@ -253,7 +259,7 @@
 kde4_add_library(kio SHARED ${kio_LIB_SRCS})
 
 if(HAVE_NEPOMUK)
-  target_link_libraries(kio ${KDE4_NEPOMUK_LIBRARY})
+  target_link_libraries(kio ${KDE4_NEPOMUK_LIBRARY} nepomukquery)
 endif(HAVE_NEPOMUK)
 target_link_libraries(kio ${KDE4_KDEUI_LIBS} ${ZLIB_LIBRARY} \
${STRIGI_STREAMANALYZER_LIBRARY} ${STRIGI_STREAMS_LIBRARY} ${KDE4_SOLID_LIBS} \
${QT_QTNETWORK_LIBRARY} ${QT_QTXML_LIBRARY} ${X11_LIBRARIES})  \
target_link_libraries(kio LINK_INTERFACE_LIBRARIES kdeui kdecore \
                ${QT_QTNETWORK_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTGUI_LIBRARY} )
--- trunk/KDE/kdelibs/kio/kfile/kloadfilemetadatathread.cpp #1146793:1146794
@@ -1,6 +1,6 @@
 /*****************************************************************************
  * Copyright (C) 2009-2010 by Peter Penz <peter.penz@gmx.at>                 *
- * Copyright (C) 2009 by Sebastian Trueg <trueg@kde.org>                     *
+ * Copyright (C) 2009-2010 by Sebastian Trueg <trueg@kde.org>                *
  *                                                                           *
  * This library is free software; you can redistribute it and/or             *
  * modify it under the terms of the GNU Library General Public               *
@@ -28,8 +28,28 @@
 #include <kprotocolinfo.h>
 
 #include <resource.h>
+#include <thing.h>
 #include <resourcemanager.h>
 
+#include "config-nepomuk.h"
+
+#ifdef HAVE_NEPOMUK_WITH_SDO_0_5
+#include <query/query.h>
+#include <query/andterm.h>
+#include <query/comparisonterm.h>
+#include <query/resourceterm.h>
+#include <query/resourcetypeterm.h>
+#include <query/optionalterm.h>
+
+#include "nfo.h"
+#include "nuao.h"
+#include "ndo.h"
+
+#include <Soprano/Model>
+#include <Soprano/QueryResultIterator>
+#include <Soprano/NodeIterator>
+#endif
+
 #include <QMutexLocker>
 
 KLoadFileMetaDataThread::KLoadFileMetaDataThread() :
@@ -113,7 +133,7 @@
             while (it != variants.constEnd()) {
                 Nepomuk::Types::Property prop(it.key());
                 const QString uriString = prop.uri().toString();
-                data.insert(uriString, formatValue(it.value()));
+                data.insert(uriString, formatValue(prop, it.value()));
                 ++it;
             }
 
@@ -126,7 +146,7 @@
                 foreach (const KFileMetaInfoItem& metaInfoItem, metaInfoItems) {
                     const QString uriString = metaInfoItem.name();
                     const Nepomuk::Variant value(metaInfoItem.value());
-                    data.insert(uriString, formatValue(value));
+                    data.insert(uriString, formatValue(Nepomuk::Types::Property(), \
value));  }
             }
         }
@@ -154,7 +174,7 @@
     emit finished(this);
 }
 
-QString  KLoadFileMetaDataThread::formatValue(const Nepomuk::Variant& value)
+QString  KLoadFileMetaDataThread::formatValue(const Nepomuk::Types::Property& prop, \
const Nepomuk::Variant& value)  {
     if (value.isDateTime()) {
         return KGlobal::locale()->formatDateTime(value.toDateTime(), \
KLocale::FancyLongDate); @@ -165,12 +185,57 @@
     }
 
     else if (value.isResource() || value.isResourceList()) {
+#ifdef HAVE_NEPOMUK_WITH_SDO_0_5
+        //
+        // We handle the one special case of referrer URLs of downloads
+        // TODO: put stuff like this in a generic rule-based framework
+        //
+        if(prop == Nepomuk::Vocabulary::NDO::copiedFrom()) {
+            Nepomuk::Query::Query query(
+                Nepomuk::Query::AndTerm(
+                    Nepomuk::Query::ResourceTypeTerm(
+                        Nepomuk::Vocabulary::NDO::DownloadEvent()
+                        ),
+                    Nepomuk::Query::ComparisonTerm(
+                        Nepomuk::Vocabulary::NUAO::involves(),
+                        Nepomuk::Query::ResourceTerm(m_urls.first())
+                        )
+                    )
+                );
+            query.setLimit(1);
+
+            QList<Soprano::Node> results =
+                Nepomuk::ResourceManager::instance()->mainModel()->executeQuery(
+                    query.toSparqlQuery(),
+                    \
Soprano::Query::QueryLanguageSparql).iterateBindings(0).allNodes(); +            \
if(!results.isEmpty()) { +                Nepomuk::Resource \
dlRes(results.first().uri()); +                KUrl url;
+                QString label;
+                if(dlRes.hasProperty(Nepomuk::Vocabulary::NDO::referrer())) {
+                    url = \
dlRes.property(Nepomuk::Vocabulary::NDO::referrer()).toUrl(); +                    \
KUrl referrerDomain(url); +                    referrerDomain.setPath(QString());
+                    referrerDomain.setQuery(QString());
+                    label = referrerDomain.prettyUrl();
+                }
+                else {
+                    Nepomuk::Resource res(value.toResource());
+                    url = res.resourceUri();
+                    label = res.genericLabel();
+                }
+
+                return QString::fromLatin1("<a href=\"%1\">%2</a>")
+                    .arg(url.url(), label);
+            }
+        }
+#endif
         QStringList links;
         foreach(const Nepomuk::Resource& res, value.toResourceList()) {
             if (KProtocolInfo::isKnownProtocol(res.resourceUri())) {
                 links << QString::fromLatin1("<a href=\"%1\">%2</a>")
-                         .arg(KUrl(res.resourceUri()).url())
-                         .arg(res.genericLabel());
+                         .arg(KUrl(res.resourceUri()).url(),
+                              res.genericLabel());
             } else {
                 links << res.genericLabel();
             }
--- trunk/KDE/kdelibs/kio/kfile/kloadfilemetadatathread_p.h #1146793:1146794
@@ -92,7 +92,7 @@
      * Here we simply handle the most common formatting situations that do not look \
                nice
      * when using Nepomuk::Variant::toString().
      */
-    QString formatValue(const Nepomuk::Variant& value);
+    QString formatValue(const Nepomuk::Types::Property&, const Nepomuk::Variant& \
value);  
 private:
     mutable QMutex m_mutex;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic