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

List:       kde-commits
Subject:    [plasma-mediacenter] plugins/baloosearch: Fetch photo-taken Date/Time for Images and file created Da
From:       Shantanu Tushar <shantanu () kde ! org>
Date:       2014-05-01 6:06:31
Message-ID: E1Wfk8d-0004ko-AY () scm ! kde ! org
[Download RAW message or body]

Git commit 121e51d74ff50a3644f275d5cfb571326c7a7286 by Shantanu Tushar.
Committed on 01/05/2014 at 05:17.
Pushed by shantanu into branch 'master'.

Fetch photo-taken Date/Time for Images and file created Date/Time for other files

Just like the Nepomuk media source, the Baloo media source needs to
provide the date/time information for media. This is used to sort the
media to show the more recent media first.
For images, the date/time when the photo was actually taken is used,
and the file creation date/time is used for other media.

REVIEW: 117915

M  +4    -0    plugins/baloosearch/CMakeLists.txt
A  +64   -0    plugins/baloosearch/audiosearchresulthandler.cpp     [License: LGPL \
(v2.1+)] C  +13   -16   plugins/baloosearch/audiosearchresulthandler.h [from: \
plugins/baloosearch/baloosearchmediasource.h - 068% similarity] M  +20   -19   \
plugins/baloosearch/baloosearchmediasource.cpp M  +4    -1    \
plugins/baloosearch/baloosearchmediasource.h A  +70   -0    \
plugins/baloosearch/imagesearchresulthandler.cpp     [License: LGPL (v2.1+)] C  +12   \
-17   plugins/baloosearch/imagesearchresulthandler.h [from: \
plugins/baloosearch/baloosearchmediasource.h - 067% similarity] C  +30   -21   \
plugins/baloosearch/searchresulthandler.cpp [from: \
plugins/baloosearch/baloosearchmediasource.h - 050% similarity] C  +16   -17   \
plugins/baloosearch/searchresulthandler.h [from: \
plugins/baloosearch/baloosearchmediasource.h - 067% similarity] C  +35   -21   \
plugins/baloosearch/videosearchresulthandler.cpp [from: \
plugins/baloosearch/baloosearchmediasource.h - 051% similarity] C  +10   -16   \
plugins/baloosearch/videosearchresulthandler.h [from: \
plugins/baloosearch/baloosearchmediasource.h - 071% similarity]

http://commits.kde.org/plasma-mediacenter/121e51d74ff50a3644f275d5cfb571326c7a7286

diff --git a/plugins/baloosearch/CMakeLists.txt b/plugins/baloosearch/CMakeLists.txt
index 1ff81fb..bbe6e39 100644
--- a/plugins/baloosearch/CMakeLists.txt
+++ b/plugins/baloosearch/CMakeLists.txt
@@ -7,6 +7,10 @@ include_directories(
 )
 
 set(baloosearch_SRCS
+    audiosearchresulthandler.cpp
+    videosearchresulthandler.cpp
+    imagesearchresulthandler.cpp
+    searchresulthandler.cpp
     baloosearchmediasource.cpp
 )
 
diff --git a/plugins/baloosearch/audiosearchresulthandler.cpp \
b/plugins/baloosearch/audiosearchresulthandler.cpp new file mode 100644
index 0000000..de98bb7
--- /dev/null
+++ b/plugins/baloosearch/audiosearchresulthandler.cpp
@@ -0,0 +1,64 @@
+/***********************************************************************************
+ *   Copyright 2014 Shantanu Tushar <shantanu@kde.org>                             *
+ *                                                                                 *
+ *   This library is free software; you can redistribute it and/or                 *
+ *   modify it under the terms of the GNU Lesser General Public                    *
+ *   License as published by the Free Software Foundation; either                  *
+ *   version 2.1 of the License, or (at your option) any later version.            *
+ *                                                                                 *
+ *   This library is distributed in the hope that it will be useful,               *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of                *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
+ *   Lesser General Public License for more details.                               *
+ *                                                                                 *
+ *   You should have received a copy of the GNU Lesser General Public              *
+ *   License along with this library.  If not, see <http://www.gnu.org/licenses/>. *
+ ***********************************************************************************/
 +
+#include "audiosearchresulthandler.h"
+
+#include <mediacenter/mediacenter.h>
+#include <mediacenter/medialibrary.h>
+
+#include <baloo/file.h>
+#include <baloo/resultiterator.h>
+
+AudioSearchResultHandler::AudioSearchResultHandler(MediaLibrary* mediaLibrary,
+                                                   QObject* parent)
+    : SearchResultHandler(mediaLibrary, parent)
+{
+}
+
+QString AudioSearchResultHandler::supportedMediaType() const
+{
+    return "Audio";
+}
+
+void AudioSearchResultHandler::handleResultImpl(const Baloo::ResultIterator& \
resultIterator) +{
+    Baloo::FileFetchJob* job = new \
Baloo::FileFetchJob(resultIterator.url().toLocalFile()); +    connect(job, \
SIGNAL(fileReceived(Baloo::File)), +            this, \
SLOT(slotFileReceived(Baloo::File))); +
+    job->start();
+}
+
+void AudioSearchResultHandler::slotFileReceived(const Baloo::File &file)
+{
+    QHash<int, QVariant> values;
+
+    const int duration = file.property(KFileMetaData::Property::Duration).toInt();
+    if (duration) {
+        values.insert(MediaCenter::DurationRole, duration);
+    }
+
+    const QString title = file.property(KFileMetaData::Property::Title).toString();
+    if (!title.isEmpty()) {
+        values.insert(Qt::DisplayRole, title);
+    }
+
+    values.insert(MediaCenter::ArtistRole, \
file.property(KFileMetaData::Property::Artist)); +    \
values.insert(MediaCenter::AlbumRole, file.property(KFileMetaData::Property::Album)); \
+ +    m_mediaLibrary->updateMedia(QUrl::fromLocalFile(file.url()).toString(), \
values); +}
diff --git a/plugins/baloosearch/baloosearchmediasource.h \
b/plugins/baloosearch/audiosearchresulthandler.h similarity index 68%
copy from plugins/baloosearch/baloosearchmediasource.h
copy to plugins/baloosearch/audiosearchresulthandler.h
index e315de4..11b7219 100644
--- a/plugins/baloosearch/baloosearchmediasource.h
+++ b/plugins/baloosearch/audiosearchresulthandler.h
@@ -1,5 +1,5 @@
 /***********************************************************************************
- *   Copyright 2014 Sinny Kumari <ksinny@gmail.com>          `                     *
+ *   Copyright 2014 Shantanu Tushar <shantanu@kde.org>                             *
  *                                                                                 *
  *   This library is free software; you can redistribute it and/or                 *
  *   modify it under the terms of the GNU Lesser General Public                    *
@@ -15,32 +15,29 @@
  *   License along with this library.  If not, see <http://www.gnu.org/licenses/>. *
  ***********************************************************************************/
  
-#ifndef BALOOSEARCHMEDIASOURCE_H
-#define BALOOSEARCHMEDIASOURCE_H
+#ifndef AUDIOSEARCHRESULTHANDLER_H
+#define AUDIOSEARCHRESULTHANDLER_H
 
-#include <mediacenter/abstractmediasource.h>
+#include "searchresulthandler.h"
 
 namespace Baloo {
 class File;
 }
 
-class BalooSearchMediaSource : public MediaCenter::AbstractMediaSource
+class MediaLibrary;
+
+class AudioSearchResultHandler : public SearchResultHandler
 {
     Q_OBJECT
 public:
-    explicit BalooSearchMediaSource(QObject* parent = 0, const QVariantList& args = \
                QVariantList());
-    ~BalooSearchMediaSource();
+    AudioSearchResultHandler(MediaLibrary* mediaLibrary, QObject* parent);
+    virtual QString supportedMediaType() const;
 
 protected:
-    virtual void run();
-
-private slots:
-    void startQuerying();
-    void slotFileReceived(const Baloo::File &file);
+    virtual void handleResultImpl(const Baloo::ResultIterator& resultIterator);
 
-private:
-    void queryForMediaType(const QString &type);
-    void fetchUrlDetails(const QUrl &url);
+private Q_SLOTS:
+    void slotFileReceived(const Baloo::File& file);
 };
 
-#endif // BALOOSEARCHMEDIASOURCE_H
+#endif // AUDIOSEARCHRESULTHANDLER_H
diff --git a/plugins/baloosearch/baloosearchmediasource.cpp \
b/plugins/baloosearch/baloosearchmediasource.cpp index 7ebfa61..5be0b89 100644
--- a/plugins/baloosearch/baloosearchmediasource.cpp
+++ b/plugins/baloosearch/baloosearchmediasource.cpp
@@ -17,9 +17,14 @@
 
 #include "baloosearchmediasource.h"
 
+#include "imagesearchresulthandler.h"
+#include "videosearchresulthandler.h"
+#include "audiosearchresulthandler.h"
+
 #include <mediacenter/medialibrary.h>
 #include <mediacenter/singletonfactory.h>
 #include <mediacenter/mediacenter.h>
+
 #include <baloo/query.h>
 #include <baloo/result.h>
 #include <baloo/filefetchjob.h>
@@ -34,6 +39,16 @@ MEDIACENTER_EXPORT_MEDIASOURCE(BalooSearchMediaSource)
 BalooSearchMediaSource::BalooSearchMediaSource(QObject* parent, const QVariantList& \
args)  : AbstractMediaSource(parent, args)
 {
+    MediaLibrary *mediaLibrary = SingletonFactory::instanceFor<MediaLibrary>();
+
+    QList<SearchResultHandler*> searchResultHandlerList;
+    searchResultHandlerList << new ImageSearchResultHandler(mediaLibrary, this)
+                            << new VideoSearchResultHandler(mediaLibrary, this)
+                            << new AudioSearchResultHandler(mediaLibrary, this);
+
+    Q_FOREACH(SearchResultHandler* searchResultHandler, searchResultHandlerList) {
+        m_searchResultHandlers.insert(searchResultHandler->supportedMediaType(), \
searchResultHandler); +    }
 }
 
 BalooSearchMediaSource::~BalooSearchMediaSource()
@@ -52,9 +67,9 @@ void BalooSearchMediaSource::run()
 
 void BalooSearchMediaSource::startQuerying()
 {
-    queryForMediaType("Audio");
-    queryForMediaType("Image");
-    queryForMediaType("Video");
+    Q_FOREACH(const QString &type, m_searchResultHandlers.keys()) {
+        queryForMediaType(type);
+    }
 }
 
 void BalooSearchMediaSource::queryForMediaType(const QString& type)
@@ -63,21 +78,8 @@ void BalooSearchMediaSource::queryForMediaType(const QString& \
type)  query.addType(type);
 
     Baloo::ResultIterator it = query.exec();
-    while (it.next()) {
-        QHash<int, QVariant> values;
-
-        if (type == "Audio"){
-            fetchUrlDetails(it.url());
-        } else {
-            values.insert(Qt::DisplayRole, it.text());
-        }
-
-        values.insert(Qt::DecorationRole, it.icon());
-        values.insert(MediaCenter::MediaTypeRole, type.toLower());
-        values.insert(MediaCenter::MediaUrlRole, it.url());
-
-        SingletonFactory::instanceFor<MediaLibrary>()->updateMedia(values);
-    }
+    SearchResultHandler *handler = m_searchResultHandlers.value(type);
+    handler->handleResult(it);
 }
 
 void BalooSearchMediaSource::fetchUrlDetails(const QUrl& url)
@@ -107,5 +109,4 @@ void BalooSearchMediaSource::slotFileReceived(const Baloo::File& \
file)  SingletonFactory::instanceFor<MediaLibrary>()->updateMedia(values);
 }
 
-
 #include "baloosearchmediasource.moc"
diff --git a/plugins/baloosearch/baloosearchmediasource.h \
b/plugins/baloosearch/baloosearchmediasource.h index e315de4..52ff098 100644
--- a/plugins/baloosearch/baloosearchmediasource.h
+++ b/plugins/baloosearch/baloosearchmediasource.h
@@ -20,6 +20,7 @@
 
 #include <mediacenter/abstractmediasource.h>
 
+class SearchResultHandler;
 namespace Baloo {
 class File;
 }
@@ -34,11 +35,13 @@ public:
 protected:
     virtual void run();
 
-private slots:
+private Q_SLOTS:
     void startQuerying();
     void slotFileReceived(const Baloo::File &file);
 
 private:
+    QHash<QString, SearchResultHandler*> m_searchResultHandlers;
+
     void queryForMediaType(const QString &type);
     void fetchUrlDetails(const QUrl &url);
 };
diff --git a/plugins/baloosearch/imagesearchresulthandler.cpp \
b/plugins/baloosearch/imagesearchresulthandler.cpp new file mode 100644
index 0000000..272b476
--- /dev/null
+++ b/plugins/baloosearch/imagesearchresulthandler.cpp
@@ -0,0 +1,70 @@
+/***********************************************************************************
+ *   Copyright 2014 Shantanu Tushar <shantanu@kde.org>                             *
+ *                                                                                 *
+ *   This library is free software; you can redistribute it and/or                 *
+ *   modify it under the terms of the GNU Lesser General Public                    *
+ *   License as published by the Free Software Foundation; either                  *
+ *   version 2.1 of the License, or (at your option) any later version.            *
+ *                                                                                 *
+ *   This library is distributed in the hope that it will be useful,               *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of                *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
+ *   Lesser General Public License for more details.                               *
+ *                                                                                 *
+ *   You should have received a copy of the GNU Lesser General Public              *
+ *   License along with this library.  If not, see <http://www.gnu.org/licenses/>. *
+ ***********************************************************************************/
 +
+#include "imagesearchresulthandler.h"
+
+#include <mediacenter/medialibrary.h>
+#include <mediacenter/mediacenter.h>
+
+#include <baloo/resultiterator.h>
+#include <baloo/filefetchjob.h>
+#include <baloo/file.h>
+
+#include <QDateTime>
+
+ImageSearchResultHandler::ImageSearchResultHandler(MediaLibrary* mediaLibrary, \
QObject* parent) +    : SearchResultHandler(mediaLibrary, parent)
+{
+}
+
+QString ImageSearchResultHandler::supportedMediaType() const
+{
+    return "Image";
+}
+
+void ImageSearchResultHandler::handleResultImpl(const Baloo::ResultIterator& \
resultIterator) +{
+    Baloo::FileFetchJob* job = new \
Baloo::FileFetchJob(resultIterator.url().toLocalFile()); +    connect(job, \
SIGNAL(fileReceived(Baloo::File)), +            this, \
SLOT(slotFileReceived(Baloo::File))); +
+    job->start();
+}
+
+void ImageSearchResultHandler::slotFileReceived(const Baloo::File &file)
+{
+    //Properties that signify the actual date/time the image was taken by the
+    //camera
+    QList<KFileMetaData::Property::Property> properties;
+    properties << KFileMetaData::Property::PhotoDateTimeOriginal
+               << KFileMetaData::Property::ImageDateTime;
+
+    QDateTime created;
+    Q_FOREACH(KFileMetaData::Property::Property property, properties) {
+        created = file.property(property).toDateTime();
+        if (created.isValid()) {
+            break;
+        }
+    }
+
+    QHash<int, QVariant> values;
+    if (created.isValid()) {
+        values.insert(MediaCenter::CreatedAtRole, created);
+    }
+
+    m_mediaLibrary->updateMedia(QUrl::fromLocalFile(file.url()).toString(), values);
+}
diff --git a/plugins/baloosearch/baloosearchmediasource.h \
b/plugins/baloosearch/imagesearchresulthandler.h similarity index 67%
copy from plugins/baloosearch/baloosearchmediasource.h
copy to plugins/baloosearch/imagesearchresulthandler.h
index e315de4..200451e 100644
--- a/plugins/baloosearch/baloosearchmediasource.h
+++ b/plugins/baloosearch/imagesearchresulthandler.h
@@ -1,5 +1,5 @@
 /***********************************************************************************
- *   Copyright 2014 Sinny Kumari <ksinny@gmail.com>          `                     *
+ *   Copyright 2014 Shantanu Tushar <shantanu@kde.org>                             *
  *                                                                                 *
  *   This library is free software; you can redistribute it and/or                 *
  *   modify it under the terms of the GNU Lesser General Public                    *
@@ -15,32 +15,27 @@
  *   License along with this library.  If not, see <http://www.gnu.org/licenses/>. *
  ***********************************************************************************/
  
-#ifndef BALOOSEARCHMEDIASOURCE_H
-#define BALOOSEARCHMEDIASOURCE_H
+#ifndef IMAGESEARCHRESULTHANDLER_H
+#define IMAGESEARCHRESULTHANDLER_H
 
-#include <mediacenter/abstractmediasource.h>
+#include "searchresulthandler.h"
 
 namespace Baloo {
-class File;
+    class File;
 }
 
-class BalooSearchMediaSource : public MediaCenter::AbstractMediaSource
+class ImageSearchResultHandler : public SearchResultHandler
 {
     Q_OBJECT
 public:
-    explicit BalooSearchMediaSource(QObject* parent = 0, const QVariantList& args = \
                QVariantList());
-    ~BalooSearchMediaSource();
+    ImageSearchResultHandler(MediaLibrary* mediaLibrary, QObject* parent);
+    virtual QString supportedMediaType() const;
 
 protected:
-    virtual void run();
+    virtual void handleResultImpl(const Baloo::ResultIterator& resultIterator);
 
-private slots:
-    void startQuerying();
-    void slotFileReceived(const Baloo::File &file);
-
-private:
-    void queryForMediaType(const QString &type);
-    void fetchUrlDetails(const QUrl &url);
+private Q_SLOTS:
+    void slotFileReceived(const Baloo::File& file);
 };
 
-#endif // BALOOSEARCHMEDIASOURCE_H
+#endif // IMAGESEARCHRESULTHANDLER_H
diff --git a/plugins/baloosearch/baloosearchmediasource.h \
b/plugins/baloosearch/searchresulthandler.cpp similarity index 50%
copy from plugins/baloosearch/baloosearchmediasource.h
copy to plugins/baloosearch/searchresulthandler.cpp
index e315de4..78e41ea 100644
--- a/plugins/baloosearch/baloosearchmediasource.h
+++ b/plugins/baloosearch/searchresulthandler.cpp
@@ -1,5 +1,5 @@
 /***********************************************************************************
- *   Copyright 2014 Sinny Kumari <ksinny@gmail.com>          `                     *
+ *   Copyright 2014 Shantanu Tushar <shantanu@kde.org>                             *
  *                                                                                 *
  *   This library is free software; you can redistribute it and/or                 *
  *   modify it under the terms of the GNU Lesser General Public                    *
@@ -15,32 +15,41 @@
  *   License along with this library.  If not, see <http://www.gnu.org/licenses/>. *
  ***********************************************************************************/
  
-#ifndef BALOOSEARCHMEDIASOURCE_H
-#define BALOOSEARCHMEDIASOURCE_H
+#include "searchresulthandler.h"
 
-#include <mediacenter/abstractmediasource.h>
+#include <mediacenter/medialibrary.h>
+#include <mediacenter/mediacenter.h>
 
-namespace Baloo {
-class File;
+#include <baloo/resultiterator.h>
+
+#include <QFileInfo>
+#include <QDateTime>
+
+SearchResultHandler::SearchResultHandler(MediaLibrary *mediaLibrary, QObject* \
parent) +    : QObject(parent)
+    , m_mediaLibrary(mediaLibrary)
+{
 }
 
-class BalooSearchMediaSource : public MediaCenter::AbstractMediaSource
+void SearchResultHandler::handleResult(Baloo::ResultIterator& resultIterator)
 {
-    Q_OBJECT
-public:
-    explicit BalooSearchMediaSource(QObject* parent = 0, const QVariantList& args = \
                QVariantList());
-    ~BalooSearchMediaSource();
+    while (resultIterator.next()) {
+        //First collect common information
+        QHash<int, QVariant> values;
 
-protected:
-    virtual void run();
+        values.insert(Qt::DisplayRole, resultIterator.text());
+        values.insert(Qt::DecorationRole, resultIterator.icon());
+        values.insert(MediaCenter::MediaTypeRole, supportedMediaType().toLower());
+        values.insert(MediaCenter::MediaUrlRole, resultIterator.url());
 
-private slots:
-    void startQuerying();
-    void slotFileReceived(const Baloo::File &file);
+        //HACK: This is a workaround as Baloo does not provide creation or
+        // modification date/time through KFileMetaData::Property
+        values.insert(MediaCenter::CreatedAtRole,
+                      QFileInfo(resultIterator.url().toLocalFile()).created());
 
-private:
-    void queryForMediaType(const QString &type);
-    void fetchUrlDetails(const QUrl &url);
-};
+        m_mediaLibrary->updateMedia(values);
 
-#endif // BALOOSEARCHMEDIASOURCE_H
+        //Now collect information specific to this media type
+        handleResultImpl(resultIterator);
+    }
+}
diff --git a/plugins/baloosearch/baloosearchmediasource.h \
b/plugins/baloosearch/searchresulthandler.h similarity index 67%
copy from plugins/baloosearch/baloosearchmediasource.h
copy to plugins/baloosearch/searchresulthandler.h
index e315de4..0df0ba2 100644
--- a/plugins/baloosearch/baloosearchmediasource.h
+++ b/plugins/baloosearch/searchresulthandler.h
@@ -1,5 +1,5 @@
 /***********************************************************************************
- *   Copyright 2014 Sinny Kumari <ksinny@gmail.com>          `                     *
+ *   Copyright 2014 Shantanu Tushar <shantanu@kde.org>                             *
  *                                                                                 *
  *   This library is free software; you can redistribute it and/or                 *
  *   modify it under the terms of the GNU Lesser General Public                    *
@@ -15,32 +15,31 @@
  *   License along with this library.  If not, see <http://www.gnu.org/licenses/>. *
  ***********************************************************************************/
  
-#ifndef BALOOSEARCHMEDIASOURCE_H
-#define BALOOSEARCHMEDIASOURCE_H
+#ifndef SEARCHRESULTHANDLER_H
+#define SEARCHRESULTHANDLER_H
 
-#include <mediacenter/abstractmediasource.h>
+#include <QObject>
+#include <QString>
 
 namespace Baloo {
-class File;
+class ResultIterator;
 }
 
-class BalooSearchMediaSource : public MediaCenter::AbstractMediaSource
+class MediaLibrary;
+
+class SearchResultHandler : public QObject
 {
     Q_OBJECT
 public:
-    explicit BalooSearchMediaSource(QObject* parent = 0, const QVariantList& args = \
                QVariantList());
-    ~BalooSearchMediaSource();
+    SearchResultHandler(MediaLibrary *mediaLibrary, QObject* parent);
+    virtual QString supportedMediaType() const = 0;
 
-protected:
-    virtual void run();
+    virtual void handleResult(Baloo::ResultIterator &resultIterator);
 
-private slots:
-    void startQuerying();
-    void slotFileReceived(const Baloo::File &file);
+protected:
+    MediaLibrary *m_mediaLibrary;
 
-private:
-    void queryForMediaType(const QString &type);
-    void fetchUrlDetails(const QUrl &url);
+    virtual void handleResultImpl(const Baloo::ResultIterator &resultIterator) = 0;
 };
 
-#endif // BALOOSEARCHMEDIASOURCE_H
+#endif // SEARCHRESULTHANDLER_H
diff --git a/plugins/baloosearch/baloosearchmediasource.h \
b/plugins/baloosearch/videosearchresulthandler.cpp similarity index 51%
copy from plugins/baloosearch/baloosearchmediasource.h
copy to plugins/baloosearch/videosearchresulthandler.cpp
index e315de4..1295b30 100644
--- a/plugins/baloosearch/baloosearchmediasource.h
+++ b/plugins/baloosearch/videosearchresulthandler.cpp
@@ -1,5 +1,5 @@
 /***********************************************************************************
- *   Copyright 2014 Sinny Kumari <ksinny@gmail.com>          `                     *
+ *   Copyright 2014 Shantanu Tushar <shantanu@kde.org>                             *
  *                                                                                 *
  *   This library is free software; you can redistribute it and/or                 *
  *   modify it under the terms of the GNU Lesser General Public                    *
@@ -15,32 +15,46 @@
  *   License along with this library.  If not, see <http://www.gnu.org/licenses/>. *
  ***********************************************************************************/
  
-#ifndef BALOOSEARCHMEDIASOURCE_H
-#define BALOOSEARCHMEDIASOURCE_H
+#include "videosearchresulthandler.h"
 
-#include <mediacenter/abstractmediasource.h>
+#include <mediacenter/medialibrary.h>
+#include <mediacenter/mediacenter.h>
 
-namespace Baloo {
-class File;
+#include <baloo/filefetchjob.h>
+#include <baloo/file.h>
+#include <baloo/resultiterator.h>
+
+#include <QHash>
+
+VideoSearchResultHandler::VideoSearchResultHandler(MediaLibrary* mediaLibrary,
+                                                   QObject* parent)
+    : SearchResultHandler(mediaLibrary, parent)
+{
+
+}
+
+QString VideoSearchResultHandler::supportedMediaType() const
+{
+    return "Video";
 }
 
-class BalooSearchMediaSource : public MediaCenter::AbstractMediaSource
+void VideoSearchResultHandler::handleResultImpl(const Baloo::ResultIterator& \
resultIterator)  {
-    Q_OBJECT
-public:
-    explicit BalooSearchMediaSource(QObject* parent = 0, const QVariantList& args = \
                QVariantList());
-    ~BalooSearchMediaSource();
+    Baloo::FileFetchJob* job = new \
Baloo::FileFetchJob(resultIterator.url().toLocalFile()); +    connect(job, \
SIGNAL(fileReceived(Baloo::File)), +            this, \
SLOT(slotFileReceived(Baloo::File)));  
-protected:
-    virtual void run();
+    job->start();
+}
 
-private slots:
-    void startQuerying();
-    void slotFileReceived(const Baloo::File &file);
+void VideoSearchResultHandler::slotFileReceived(const Baloo::File& file)
+{
+    QHash<int, QVariant> values;
 
-private:
-    void queryForMediaType(const QString &type);
-    void fetchUrlDetails(const QUrl &url);
-};
+    const int duration = file.property(KFileMetaData::Property::Duration).toInt();
+    if (duration) {
+        values.insert(MediaCenter::DurationRole, duration);
+    }
 
-#endif // BALOOSEARCHMEDIASOURCE_H
+    m_mediaLibrary->updateMedia(QUrl::fromLocalFile(file.url()).toString(), values);
+}
diff --git a/plugins/baloosearch/baloosearchmediasource.h \
b/plugins/baloosearch/videosearchresulthandler.h similarity index 71%
copy from plugins/baloosearch/baloosearchmediasource.h
copy to plugins/baloosearch/videosearchresulthandler.h
index e315de4..146efca 100644
--- a/plugins/baloosearch/baloosearchmediasource.h
+++ b/plugins/baloosearch/videosearchresulthandler.h
@@ -1,5 +1,5 @@
 /***********************************************************************************
- *   Copyright 2014 Sinny Kumari <ksinny@gmail.com>          `                     *
+ *   Copyright 2014 Shantanu Tushar <shantanu@kde.org>                             *
  *                                                                                 *
  *   This library is free software; you can redistribute it and/or                 *
  *   modify it under the terms of the GNU Lesser General Public                    *
@@ -15,32 +15,26 @@
  *   License along with this library.  If not, see <http://www.gnu.org/licenses/>. *
  ***********************************************************************************/
  
-#ifndef BALOOSEARCHMEDIASOURCE_H
-#define BALOOSEARCHMEDIASOURCE_H
-
-#include <mediacenter/abstractmediasource.h>
+#ifndef VIDEOSEARCHRESULTHANDLER_H
+#define VIDEOSEARCHRESULTHANDLER_H
+#include "searchresulthandler.h"
 
 namespace Baloo {
 class File;
 }
 
-class BalooSearchMediaSource : public MediaCenter::AbstractMediaSource
+class VideoSearchResultHandler : public SearchResultHandler
 {
     Q_OBJECT
 public:
-    explicit BalooSearchMediaSource(QObject* parent = 0, const QVariantList& args = \
                QVariantList());
-    ~BalooSearchMediaSource();
+    VideoSearchResultHandler(MediaLibrary* mediaLibrary, QObject* parent);
+    virtual QString supportedMediaType() const;
 
 protected:
-    virtual void run();
+    virtual void handleResultImpl(const Baloo::ResultIterator& resultIterator);
 
-private slots:
-    void startQuerying();
+private Q_SLOTS:
     void slotFileReceived(const Baloo::File &file);
-
-private:
-    void queryForMediaType(const QString &type);
-    void fetchUrlDetails(const QUrl &url);
 };
 
-#endif // BALOOSEARCHMEDIASOURCE_H
+#endif // VIDEOSEARCHRESULTHANDLER_H


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

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