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

List:       kde-commits
Subject:    [plasma-mediacenter] plugins: Add a basic Filesystem media source which is supposed to be very simpl
From:       Shantanu Tushar <shantanu () kde ! org>
Date:       2014-03-30 8:38:27
Message-ID: E1WUBG7-0008Ah-5F () scm ! kde ! org
[Download RAW message or body]

Git commit c140e2382a56c4bfde2fe99b2fdaf19897424e88 by Shantanu Tushar.
Committed on 30/03/2014 at 08:38.
Pushed by shantanu into branch 'master'.

Add a basic Filesystem media source which is supposed to be very simple and only scan \
the home dir. CMake output makes it clear that this is a limited source and should \
only be used when Baloo and Nepomuk can't be installed.

M  +20   -7    plugins/CMakeLists.txt
A  +16   -0    plugins/filesystemsearch/CMakeLists.txt
A  +14   -0    plugins/filesystemsearch/filesystemsearch.desktop
A  +108  -0    plugins/filesystemsearch/filesystemsearchmediasource.cpp     [License: \
LGPL (v2.1+)] A  +57   -0    plugins/filesystemsearch/filesystemsearchmediasource.h   \
[License: LGPL (v2.1+)]

http://commits.kde.org/plasma-mediacenter/c140e2382a56c4bfde2fe99b2fdaf19897424e88

diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt
index 7f89498..7458861 100644
--- a/plugins/CMakeLists.txt
+++ b/plugins/CMakeLists.txt
@@ -1,11 +1,24 @@
-find_package(NepomukCore)
-if(NepomukCore_FOUND)
-    message(STATUS "********** Found Nepomuk, building Nepomuk Search plugin")
-    add_subdirectory(kdedesktopsearch)
-endif(NepomukCore_FOUND)
-
-find_package(Baloo)
+find_package(Baloo QUIET)
 if(Baloo_FOUND)
     message(STATUS "********** Found Baloo, building Baloo Search plugin")
     add_subdirectory(baloosearch)
+else(Baloo_FOUND)
+    find_package(NepomukCore QUIET)
+
+    if(NepomukCore_FOUND)
+        message(STATUS "********** Found Nepomuk, building Nepomuk Search plugin")
+        add_subdirectory(kdedesktopsearch)
+    else(NepomukCore_FOUND)
+        message(STATUS "********** Neither Baloo nor Nepomuk was found, install one \
of them to get more functionality") +
+        if(USE_FILESYSTEM_MEDIA_SOURCE)
+            message(STATUS "********** Building the limited Filesystem Search \
plugin") +            add_subdirectory(filesystemsearch)
+        else(USE_FILESYSTEM_MEDIA_SOURCE)
+            message(STATUS "********** Because of this, no media sources are being \
built. Only local browsing will be available") +            message(STATUS \
"********** If you not on KDE or cannot install Baloo or Nepomuk, set \
USE_FILESYSTEM_MEDIA_SOURCE=ON to cmake to build the limited Filesystem Search \
plugin") +        endif(USE_FILESYSTEM_MEDIA_SOURCE)
+
+    endif(NepomukCore_FOUND)
+
 endif(Baloo_FOUND)
diff --git a/plugins/filesystemsearch/CMakeLists.txt \
b/plugins/filesystemsearch/CMakeLists.txt new file mode 100644
index 0000000..e6c6b6b
--- /dev/null
+++ b/plugins/filesystemsearch/CMakeLists.txt
@@ -0,0 +1,16 @@
+set(filesystemsearch_SRCS
+    filesystemsearchmediasource.cpp
+)
+
+qt4_automoc(${filesystemsearch_SRCS})
+
+kde4_add_plugin(pmc_filesystemsearch ${filesystemsearch_SRCS})
+
+target_link_libraries(pmc_filesystemsearch
+    plasmamediacenter
+    ${KDE4_KDECORE_LIBS}
+    ${QT_QTGUI_LIBRARIES}
+)
+
+install(TARGETS pmc_filesystemsearch DESTINATION ${PLUGIN_INSTALL_DIR})
+install(FILES filesystemsearch.desktop DESTINATION ${SERVICES_INSTALL_DIR})
diff --git a/plugins/filesystemsearch/filesystemsearch.desktop \
b/plugins/filesystemsearch/filesystemsearch.desktop new file mode 100644
index 0000000..f1c63e5
--- /dev/null
+++ b/plugins/filesystemsearch/filesystemsearch.desktop
@@ -0,0 +1,14 @@
+[Desktop Entry]
+Type=Service
+Icon=drive-harddisk
+Name=Filesystem Search
+Comment=Get media from your local files
+
+X-KDE-ServiceTypes=Plasma/MediaCenter/MediaSource
+
+X-KDE-PluginInfo-Author=Shantanu Tushar
+X-KDE-PluginInfo-Email=shantanu@kde.org
+X-KDE-PluginInfo-Version=1.0
+X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-EnabledByDefault=true
+X-KDE-Library=pmc_filesystemsearch
diff --git a/plugins/filesystemsearch/filesystemsearchmediasource.cpp \
b/plugins/filesystemsearch/filesystemsearchmediasource.cpp new file mode 100644
index 0000000..44ba844
--- /dev/null
+++ b/plugins/filesystemsearch/filesystemsearchmediasource.cpp
@@ -0,0 +1,108 @@
+/***********************************************************************************
+ *   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 "filesystemsearchmediasource.h"
+
+#include <mediacenter/singletonfactory.h>
+#include <mediacenter/medialibrary.h>
+#include <mediacenter/mediacenter.h>
+
+#include <KMimeType>
+
+#include <QDir>
+#include <QDebug>
+
+MEDIACENTER_EXPORT_MEDIASOURCE(FilesystemSearchMediaSource)
+
+FilesystemSearchMediaSource::FilesystemSearchMediaSource(QObject* parent, const \
QVariantList&) +    : m_quit(false)
+{
+    m_allowedMimes << "audio" << "image" << "video";
+}
+
+FilesystemSearchMediaSource::~FilesystemSearchMediaSource()
+{
+    qDebug() << "Waiting for Filesystem Search to quit...";
+    stop();
+    wait();
+}
+
+void FilesystemSearchMediaSource::run()
+{
+    setPriority(IdlePriority);
+    recursiveSearch(QDir::home());
+    qDebug() << "Done scanning the Filesystem";
+}
+
+bool FilesystemSearchMediaSource::recursiveSearch(const QDir &dir)
+{
+    if (shouldQuit())   return false;
+
+    foreach(const QFileInfo &fileInfo, dir.entryInfoList(QDir::Files)) {
+        if (shouldQuit())   return false;
+        checkAndAddFile(fileInfo);
+    }
+
+    foreach(const QFileInfo &dirInfo, dir.entryInfoList(QDir::Dirs | \
QDir::NoDotAndDotDot)) { +        if (shouldQuit())   return false;
+        if (!recursiveSearch(QDir(dirInfo.absoluteFilePath()))) {
+            break;
+        }
+    }
+
+    return true;
+}
+
+bool FilesystemSearchMediaSource::shouldQuit() const
+{
+    QMutexLocker l(&m_quitMutex);
+    return m_quit;
+}
+
+void FilesystemSearchMediaSource::stop()
+{
+    QMutexLocker l(&m_quitMutex);
+    m_quit = true;
+}
+
+bool FilesystemSearchMediaSource::checkAndAddFile(const QFileInfo& fileInfo)
+{
+    const QString mimeType = KMimeType::findByUrl(
+        KUrl::fromLocalFile(fileInfo.absoluteFilePath()))->name();
+
+    const QString topLevelTypeName = mimeType.split("/").at(0);
+
+    if (!topLevelTypeName.isEmpty() && m_allowedMimes.contains(topLevelTypeName)) {
+        addFile(fileInfo, topLevelTypeName);
+        return true;
+    }
+
+    return false;
+}
+
+void FilesystemSearchMediaSource::addFile(const QFileInfo& fileInfo,
+                                          const QString &type)
+{
+    qDebug() << "Adding " << type << fileInfo.fileName();
+    QHash<int, QVariant> values;
+
+    values.insert(Qt::DisplayRole, fileInfo.fileName());
+    values.insert(MediaCenter::MediaUrlRole, \
QUrl::fromLocalFile(fileInfo.absoluteFilePath()).toString()); +    \
values.insert(MediaCenter::MediaTypeRole, type); +
+    SingletonFactory::instanceFor<MediaLibrary>()->updateMedia(values);
+}
diff --git a/plugins/filesystemsearch/filesystemsearchmediasource.h \
b/plugins/filesystemsearch/filesystemsearchmediasource.h new file mode 100644
index 0000000..88740b8
--- /dev/null
+++ b/plugins/filesystemsearch/filesystemsearchmediasource.h
@@ -0,0 +1,57 @@
+/***********************************************************************************
+ *   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/>. *
+ ***********************************************************************************/
 +
+#ifndef FILESYSTEMSEARCHMEDIASOURCE_H
+#define FILESYSTEMSEARCHMEDIASOURCE_H
+
+#include <mediacenter/abstractmediasource.h>
+
+#include <QMutex>
+
+class QFileInfo;
+class QDir;
+
+/**
+ * \brief Goes through the user's home dir and searches for media
+ *
+ * This MediaSource is supposed to be used for a better-than-nothing scenario
+ * when none of Baloo or Nepomuk are installed. As such this MediaSource does
+ * not attempt 100% correctness and is not configurable at all.
+ */
+class FilesystemSearchMediaSource : public MediaCenter::AbstractMediaSource
+{
+public:
+    explicit FilesystemSearchMediaSource(QObject* parent = 0, const QVariantList&  = \
QVariantList()); +    virtual ~FilesystemSearchMediaSource();
+
+protected:
+    virtual void run();
+
+private:
+    mutable QMutex m_quitMutex;
+    bool m_quit;
+
+    QStringList m_allowedMimes;
+
+    bool shouldQuit() const;
+    bool recursiveSearch(const QDir& dir);
+    void stop();
+    bool checkAndAddFile(const QFileInfo &fileInfo);
+    void addFile(const QFileInfo &fileInfo, const QString &type);
+};
+
+#endif // FILESYSTEMSEARCHMEDIASOURCE_H


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

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