From kde-commits Wed Feb 29 22:57:27 2012 From: Sebastian Trueg Date: Wed, 29 Feb 2012 22:57:27 +0000 To: kde-commits Subject: [nepomuktvnamer] service: Use KDirNotify to update tvshow:/latest automatically. Message-Id: <20120229225727.CE2D3A60A9 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=133055628808658 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/35a6aa978300deab820415d4f35015281e7ba= 7ec 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 #include #include +#include #include = #include @@ -57,6 +58,14 @@ TVNamerService::TVNamerService(QObject *parent, const QV= ariantList &) connect(watcher, SIGNAL(resourceTypeAdded(Nepomuk::Resource,Nepomuk::T= ypes::Class)), this, SLOT(slotTVShowResourceCreated(Nepomuk::Resource))); watcher->start(); + + // set up the watcher for watched TV Shows + watcher =3D 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 Ne= pomuk::Resource &res) } } = +void TVNamerService::slotTVShowUsageCountChanged(const Nepomuk::Resource &= res) +{ + // fetch the changed show's details and tell KIO to remove it in any c= ase + Soprano::QueryResultIterator it + =3D mainModel()->executeQuery(QString::fromLatin1("select ?s ?= e ?st ?t where { " + "%1 nmm:episod= eNumber ?e ; " + "nmm:season ?s= ; " + "nmm:series [ = a nmm:TVSeries ; nie:title ?st ] ; " + "nie:title ?t = . } LIMIT 1") + .arg(Soprano::Node::resourceToN3(r= es.resourceUri())), + Soprano::Query::QueryLanguageSparq= l); + if(it.next()) { + const QString title =3D 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() << (QLatin1St= ring("tvshow:/latest/") + title)); + } + + // now simply tell KIO to check for added files + org::kde::KDirNotify::emitFilesAdded(QLatin1String("tvshow:/latest")); +} + #include #include = 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 QLis= t& types); void slotTVShowResourceCreated(const Nepomuk::Resource& res); + void slotTVShowUsageCountChanged(const Nepomuk::Resource& res); }; = #endif // TVNAMERSERVICE_H