[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [nepomuktvnamer] service: Use KDirNotify to update tvshow:/latest automatically.
From: Sebastian Trueg <trueg () kde ! org>
Date: 2012-02-29 22:57:27
Message-ID: 20120229225727.CE2D3A60A9 () git ! kde ! org
[Download RAW message or body]
Git commit 35a6aa978300deab820415d4f35015281e7ba7ec by Sebastian Trueg.
Committed on 29/02/2012 at 23:55.
Pushed by trueg into branch 'master'.
Use KDirNotify to update tvshow:/latest automatically.
M +33 -0 service/tvnamerservice.cpp
M +1 -0 service/tvnamerservice.h
http://commits.kde.org/nepomuktvnamer/35a6aa978300deab820415d4f35015281e7ba7ec
diff --git a/service/tvnamerservice.cpp b/service/tvnamerservice.cpp
index e7884c9..e7f3ae0 100644
--- a/service/tvnamerservice.cpp
+++ b/service/tvnamerservice.cpp
@@ -24,6 +24,7 @@
#include <nepomuk/resourcewatcher.h>
#include <Nepomuk/Vocabulary/NFO>
#include <Nepomuk/Vocabulary/NMM>
+#include <Nepomuk/Vocabulary/NUAO>
#include <Nepomuk/File>
#include <Soprano/Model>
@@ -57,6 +58,14 @@ TVNamerService::TVNamerService(QObject *parent, const QVariantList \
&)
connect(watcher, \
SIGNAL(resourceTypeAdded(Nepomuk::Resource,Nepomuk::Types::Class)), this, \
SLOT(slotTVShowResourceCreated(Nepomuk::Resource))); watcher->start();
+
+ // set up the watcher for watched TV Shows
+ watcher = new Nepomuk::ResourceWatcher(this);
+ watcher->addType(NMM::TVShow());
+ watcher->addProperty(NUAO::usageCount());
+ connect(watcher, \
SIGNAL(propertyAdded(Nepomuk::Resource,Nepomuk::Types::Property,QVariant)), + \
this, SLOT(slotTVShowUsageCountChanged(Nepomuk::Resource))); + watcher->start();
}
TVNamerService::~TVNamerService()
@@ -95,6 +104,30 @@ void TVNamerService::slotTVShowResourceCreated(const \
Nepomuk::Resource &res) }
}
+void TVNamerService::slotTVShowUsageCountChanged(const Nepomuk::Resource &res)
+{
+ // fetch the changed show's details and tell KIO to remove it in any case
+ Soprano::QueryResultIterator it
+ = mainModel()->executeQuery(QString::fromLatin1("select ?s ?e ?st ?t \
where { " + "%1 \
nmm:episodeNumber ?e ; " + \
"nmm:season ?s ; " + \
"nmm:series [ a nmm:TVSeries ; nie:title ?st ] ; " + \
"nie:title ?t . } LIMIT 1") + \
.arg(Soprano::Node::resourceToN3(res.resourceUri())), + \
Soprano::Query::QueryLanguageSparql); + if(it.next()) {
+ const QString title = i18n("Next episode of %1: %2x%3 - %4",
+ it["st"].toString(),
+ \
QString::number(it["s"].literal().toInt()).rightJustified(2, QLatin1Char('0')), + \
QString::number(it["e"].literal().toInt()).rightJustified(2, QLatin1Char('0')), + \
it["t"].toString()); + org::kde::KDirNotify::emitFilesRemoved(QStringList() << \
(QLatin1String("tvshow:/latest/") + title)); + }
+
+ // now simply tell KIO to check for added files
+ org::kde::KDirNotify::emitFilesAdded(QLatin1String("tvshow:/latest"));
+}
+
#include <kpluginfactory.h>
#include <kpluginloader.h>
diff --git a/service/tvnamerservice.h b/service/tvnamerservice.h
index 37afabf..f90ff12 100644
--- a/service/tvnamerservice.h
+++ b/service/tvnamerservice.h
@@ -40,6 +40,7 @@ public:
private Q_SLOTS:
void slotVideoResourceCreated(const Nepomuk::Resource& res, const QList<QUrl>& \
types); void slotTVShowResourceCreated(const Nepomuk::Resource& res);
+ void slotTVShowUsageCountChanged(const Nepomuk::Resource& res);
};
#endif // TVNAMERSERVICE_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic