[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: Re: [plasma-mediacenter] plugins: Add a basic Filesystem media source which is supposed to be very s
From: Shantanu Tushar Jha <shantanu () kde ! org>
Date: 2014-03-31 18:38:31
Message-ID: CABQ4Km_yfUMzqpbZopk-_5JzZuMaxJn5qH8A5jLw_5u+vDzF+w () mail ! gmail ! com
[Download RAW message or body]
Bah, someone just pointed out that you had comments inline, I didn't see
them at all.
On Sun, Mar 30, 2014 at 4:52 PM, Vishesh Handa <me@vhanda.in> wrote:
> On Sunday, March 30, 2014 08:38:27 AM Shantanu Tushar wrote:
> > 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.
> >
>
> You may want to follow the standard commit format.
>
> http://techbase.kde.org/Development/Git/Configuration#Commit_Template
>
> > 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/c140e2382a56c4bfde2fe99b2fdaf19897
> > 424e88
> >
> > 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;
>
> Coding style? There is similar stuff all over.
>
Laziness peril, shouldn't have.
>
> > +
> > + 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;
> > +}
>
> oh boy. This is going to take quite some time.
>
Oh yep it is, though I should add the word "slow" along with "limited" in
the CMake messages.
>
> > +
> > +bool FilesystemSearchMediaSource::shouldQuit() const
> > +{
> > + QMutexLocker l(&m_quitMutex);
> > + return m_quit;
> > +}
> > +
> > +void FilesystemSearchMediaSource::stop()
> > +{
> > + QMutexLocker l(&m_quitMutex);
> > + m_quit = true;
> > +}
>
> If you want you can also use a QAtomicInt instead of the bool + mutex.
>
Thanks for the tip.
>
> > +
> > +bool FilesystemSearchMediaSource::checkAndAddFile(const QFileInfo&
> > fileInfo) +{
> > + const QString mimeType = KMimeType::findByUrl(
> > + KUrl::fromLocalFile(fileInfo.absoluteFilePath()))->name();
> > +
>
> Warning: This will cause very high io usage since it is looking into the
> file
> to determine the mimetype. And considering that you're doing this for every
> file in $HOME ...
>
Yeah, I initially used KMimeType::findByPath exactly because of this but it
always returned application/octet-stream for mp3 files. Ever happened to
you?
Also, just to make things clear, this plugin is just for those few people
who's want to try PMC on a non-KDE installation (as few such users asked
for it). Might even write a plugin for Tracker et al (if that is still the
stuff used on other DEs).
> > + 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
>
> --
> Vishesh Handa
>
--
Shantanu Tushar (UTC +0530)
http://www.shantanutushar.com
[Attachment #3 (text/html)]
<div dir="ltr"><br><div class="gmail_extra">Bah, someone just pointed out that you \
had comments inline, I didn't see them at all.<br></div><div \
class="gmail_extra"><br><div class="gmail_quote">On Sun, Mar 30, 2014 at 4:52 PM, \
Vishesh Handa <span dir="ltr"><<a href="mailto:me@vhanda.in" \
target="_blank">me@vhanda.in</a>></span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex">On Sunday, March 30, 2014 08:38:27 AM Shantanu \
Tushar wrote:<br> > Git commit c140e2382a56c4bfde2fe99b2fdaf19897424e88 by \
Shantanu Tushar.<br> > Committed on 30/03/2014 at 08:38.<br>
> Pushed by shantanu into branch 'master'.<br>
><br>
> Add a basic Filesystem media source which is supposed to be very simple and<br>
> only scan the home dir. CMake output makes it clear that this is a limited<br>
> source and should only be used when Baloo and Nepomuk can't be \
installed.<br> ><br>
<br>
You may want to follow the standard commit format.<br>
<br>
<a href="http://techbase.kde.org/Development/Git/Configuration#Commit_Template" \
target="_blank">http://techbase.kde.org/Development/Git/Configuration#Commit_Template</a><br>
<br>
> M +20 -7 plugins/CMakeLists.txt<br>
> A +16 -0 plugins/filesystemsearch/CMakeLists.txt<br>
> A +14 -0 plugins/filesystemsearch/filesystemsearch.desktop<br>
> A +108 -0 plugins/filesystemsearch/filesystemsearchmediasource.cpp<br>
> [License: LGPL (v2.1+)] A +57 -0<br>
> plugins/filesystemsearch/filesystemsearchmediasource.h [License: LGPL<br>
> (v2.1+)]<br>
><br>
> <a href="http://commits.kde.org/plasma-mediacenter/c140e2382a56c4bfde2fe99b2fdaf19897" \
target="_blank">http://commits.kde.org/plasma-mediacenter/c140e2382a56c4bfde2fe99b2fdaf19897</a><br>
> 424e88<br>
><br>
> diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt<br>
> index 7f89498..7458861 100644<br>
> --- a/plugins/CMakeLists.txt<br>
> +++ b/plugins/CMakeLists.txt<br>
> @@ -1,11 +1,24 @@<br>
> -find_package(NepomukCore)<br>
> -if(NepomukCore_FOUND)<br>
> - message(STATUS "********** Found Nepomuk, building Nepomuk Search<br>
> plugin") - add_subdirectory(kdedesktopsearch)<br>
> -endif(NepomukCore_FOUND)<br>
> -<br>
> -find_package(Baloo)<br>
> +find_package(Baloo QUIET)<br>
> if(Baloo_FOUND)<br>
> message(STATUS "********** Found Baloo, building Baloo Search \
plugin")<br> > add_subdirectory(baloosearch)<br>
> +else(Baloo_FOUND)<br>
> + find_package(NepomukCore QUIET)<br>
> +<br>
> + if(NepomukCore_FOUND)<br>
> + message(STATUS "********** Found Nepomuk, building Nepomuk \
Search<br> > plugin") + add_subdirectory(kdedesktopsearch)<br>
> + else(NepomukCore_FOUND)<br>
> + message(STATUS "********** Neither Baloo nor Nepomuk was \
found,<br> > install one of them to get more functionality") +<br>
> + if(USE_FILESYSTEM_MEDIA_SOURCE)<br>
> + message(STATUS "********** Building the limited Filesystem<br>
> Search plugin") + add_subdirectory(filesystemsearch)<br>
> + else(USE_FILESYSTEM_MEDIA_SOURCE)<br>
> + message(STATUS "********** Because of this, no media \
sources<br> > are being built. Only local browsing will be available") +<br>
> message(STATUS "********** If you not on KDE or cannot install Baloo or<br>
> Nepomuk, set USE_FILESYSTEM_MEDIA_SOURCE=ON to cmake to build the limited<br>
> Filesystem Search plugin") + endif(USE_FILESYSTEM_MEDIA_SOURCE)<br>
> +<br>
> + endif(NepomukCore_FOUND)<br>
> +<br>
> endif(Baloo_FOUND)<br>
> diff --git a/plugins/filesystemsearch/CMakeLists.txt<br>
> b/plugins/filesystemsearch/CMakeLists.txt new file mode 100644<br>
> index 0000000..e6c6b6b<br>
> --- /dev/null<br>
> +++ b/plugins/filesystemsearch/CMakeLists.txt<br>
> @@ -0,0 +1,16 @@<br>
> +set(filesystemsearch_SRCS<br>
> + filesystemsearchmediasource.cpp<br>
> +)<br>
> +<br>
> +qt4_automoc(${filesystemsearch_SRCS})<br>
> +<br>
> +kde4_add_plugin(pmc_filesystemsearch ${filesystemsearch_SRCS})<br>
> +<br>
> +target_link_libraries(pmc_filesystemsearch<br>
> + plasmamediacenter<br>
> + ${KDE4_KDECORE_LIBS}<br>
> + ${QT_QTGUI_LIBRARIES}<br>
> +)<br>
> +<br>
> +install(TARGETS pmc_filesystemsearch DESTINATION ${PLUGIN_INSTALL_DIR})<br>
> +install(FILES filesystemsearch.desktop DESTINATION ${SERVICES_INSTALL_DIR})<br>
> diff --git a/plugins/filesystemsearch/filesystemsearch.desktop<br>
> b/plugins/filesystemsearch/filesystemsearch.desktop new file mode 100644<br>
> index 0000000..f1c63e5<br>
> --- /dev/null<br>
> +++ b/plugins/filesystemsearch/filesystemsearch.desktop<br>
> @@ -0,0 +1,14 @@<br>
> +[Desktop Entry]<br>
> +Type=Service<br>
> +Icon=drive-harddisk<br>
> +Name=Filesystem Search<br>
> +Comment=Get media from your local files<br>
> +<br>
> +X-KDE-ServiceTypes=Plasma/MediaCenter/MediaSource<br>
> +<br>
> +X-KDE-PluginInfo-Author=Shantanu Tushar<br>
> +X-KDE-PluginInfo-Email=<a \
href="mailto:shantanu@kde.org">shantanu@kde.org</a><br> > \
+X-KDE-PluginInfo-Version=1.0<br> > +X-KDE-PluginInfo-License=GPL<br>
> +X-KDE-PluginInfo-EnabledByDefault=true<br>
> +X-KDE-Library=pmc_filesystemsearch<br>
> diff --git a/plugins/filesystemsearch/filesystemsearchmediasource.cpp<br>
> b/plugins/filesystemsearch/filesystemsearchmediasource.cpp new file mode<br>
> 100644<br>
> index 0000000..44ba844<br>
> --- /dev/null<br>
> +++ b/plugins/filesystemsearch/filesystemsearchmediasource.cpp<br>
> @@ -0,0 +1,108 @@<br>
> +/**************************************************************************<br>
> ********* + * Copyright 2014 Shantanu Tushar <<a \
href="mailto:shantanu@kde.org">shantanu@kde.org</a>><br> > * + \
*<br> > * + * This library is free software; you \
can<br> > redistribute it and/or * + * modify it under the terms \
of<br> > the GNU Lesser General Public * + * License as<br>
> published by the Free Software Foundation; either * + *<br>
> version 2.1 of the License, or (at your option) any later version.<br>
> * + *<br>
> * + * This library is distributed in the hope that it will be<br>
> useful, * + * but WITHOUT ANY WARRANTY; without even the<br>
> implied warranty of * + * MERCHANTABILITY or FITNESS FOR A<br>
> PARTICULAR PURPOSE. See the GNU * + * Lesser General Public<br>
> License for more details. * + *<br>
> * + *<br>
> You should have received a copy of the GNU Lesser General Public<br>
> * + * License along with this library. If not, see<br>
> <<a href="http://www.gnu.org/licenses/" \
target="_blank">http://www.gnu.org/licenses/</a>>. * +<br> > \
***************************************************************************<br> > \
********/ +<br> > +#include "filesystemsearchmediasource.h"<br>
> +<br>
> +#include <mediacenter/singletonfactory.h><br>
> +#include <mediacenter/medialibrary.h><br>
> +#include <mediacenter/mediacenter.h><br>
> +<br>
> +#include <KMimeType><br>
> +<br>
> +#include <QDir><br>
> +#include <QDebug><br>
> +<br>
> +MEDIACENTER_EXPORT_MEDIASOURCE(FilesystemSearchMediaSource)<br>
> +<br>
> +FilesystemSearchMediaSource::FilesystemSearchMediaSource(QObject* parent,<br>
> const QVariantList&) + : m_quit(false)<br>
> +{<br>
> + m_allowedMimes << "audio" << "image" \
<< "video";<br> > +}<br>
> +<br>
> +FilesystemSearchMediaSource::~FilesystemSearchMediaSource()<br>
> +{<br>
> + qDebug() << "Waiting for Filesystem Search to quit...";<br>
> + stop();<br>
> + wait();<br>
> +}<br>
> +<br>
> +void FilesystemSearchMediaSource::run()<br>
> +{<br>
> + setPriority(IdlePriority);<br>
> + recursiveSearch(QDir::home());<br>
> + qDebug() << "Done scanning the Filesystem";<br>
> +}<br>
> +<br>
> +bool FilesystemSearchMediaSource::recursiveSearch(const QDir &dir)<br>
> +{<br>
> + if (shouldQuit()) return false;<br>
<br>
Coding style? There is similar stuff all \
over.<br></blockquote><div><br></div><div>Laziness peril, shouldn't \
have.<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +<br>
> + foreach(const QFileInfo &fileInfo, dir.entryInfoList(QDir::Files)) \
{<br> > + if (shouldQuit()) return false;<br>
> + checkAndAddFile(fileInfo);<br>
> + }<br>
> +<br>
> + foreach(const QFileInfo &dirInfo, dir.entryInfoList(QDir::Dirs |<br>
> QDir::NoDotAndDotDot)) { + if (shouldQuit()) return false;<br>
> + if (!recursiveSearch(QDir(dirInfo.absoluteFilePath()))) {<br>
> + break;<br>
> + }<br>
> + }<br>
> +<br>
> + return true;<br>
> +}<br>
<br>
oh boy. This is going to take quite some time.<br></blockquote><div><br></div><div>Oh \
yep it is, though I should add the word "slow" along with \
"limited" in the CMake messages.<br></div><blockquote class="gmail_quote" \
style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex">
<br>
> +<br>
> +bool FilesystemSearchMediaSource::shouldQuit() const<br>
> +{<br>
> + QMutexLocker l(&m_quitMutex);<br>
> + return m_quit;<br>
> +}<br>
> +<br>
> +void FilesystemSearchMediaSource::stop()<br>
> +{<br>
> + QMutexLocker l(&m_quitMutex);<br>
> + m_quit = true;<br>
> +}<br>
<br>
If you want you can also use a QAtomicInt instead of the bool + \
mutex.<br></blockquote><div><br></div><div>Thanks for the tip.<br> \
<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +<br>
> +bool FilesystemSearchMediaSource::checkAndAddFile(const QFileInfo&<br>
> fileInfo) +{<br>
> + const QString mimeType = KMimeType::findByUrl(<br>
> + KUrl::fromLocalFile(fileInfo.absoluteFilePath()))->name();<br>
> +<br>
<br>
Warning: This will cause very high io usage since it is looking into the file<br>
to determine the mimetype. And considering that you're doing this for every<br>
file in $HOME ...<br></blockquote><div><br></div><div>Yeah, I initially used \
KMimeType::findByPath exactly because of this but it always returned \
application/octet-stream for mp3 files. Ever happened to you?<br><br></div> \
<div>Also, just to make things clear, this plugin is just for those few people \
who's want to try PMC on a non-KDE installation (as few such users asked for it). \
Might even write a plugin for Tracker et al (if that is still the stuff used on other \
DEs).<br> </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px \
0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <br>
> + const QString topLevelTypeName = mimeType.split("/").at(0);<br>
> +<br>
> + if (!topLevelTypeName.isEmpty() &&<br>
> m_allowedMimes.contains(topLevelTypeName)) { + addFile(fileInfo,<br>
> topLevelTypeName);<br>
> + return true;<br>
> + }<br>
> +<br>
> + return false;<br>
> +}<br>
> +<br>
> +void FilesystemSearchMediaSource::addFile(const QFileInfo& fileInfo,<br>
> + const QString &type)<br>
> +{<br>
> + qDebug() << "Adding " << type << \
fileInfo.fileName();<br> > + QHash<int, QVariant> values;<br>
> +<br>
> + values.insert(Qt::DisplayRole, fileInfo.fileName());<br>
> + values.insert(MediaCenter::MediaUrlRole,<br>
> QUrl::fromLocalFile(fileInfo.absoluteFilePath()).toString()); +<br>
> values.insert(MediaCenter::MediaTypeRole, type);<br>
> +<br>
> + SingletonFactory::instanceFor<MediaLibrary>()->updateMedia(values);<br>
> +}<br>
> diff --git a/plugins/filesystemsearch/filesystemsearchmediasource.h<br>
> b/plugins/filesystemsearch/filesystemsearchmediasource.h new file mode<br>
> 100644<br>
> index 0000000..88740b8<br>
> --- /dev/null<br>
> +++ b/plugins/filesystemsearch/filesystemsearchmediasource.h<br>
> @@ -0,0 +1,57 @@<br>
> +/**************************************************************************<br>
> ********* + * Copyright 2014 Shantanu Tushar <<a \
href="mailto:shantanu@kde.org">shantanu@kde.org</a>><br> > * + \
*<br> > * + * This library is free software; you \
can<br> > redistribute it and/or * + * modify it under the terms \
of<br> > the GNU Lesser General Public * + * License as<br>
> published by the Free Software Foundation; either * + *<br>
> version 2.1 of the License, or (at your option) any later version.<br>
> * + *<br>
> * + * This library is distributed in the hope that it will be<br>
> useful, * + * but WITHOUT ANY WARRANTY; without even the<br>
> implied warranty of * + * MERCHANTABILITY or FITNESS FOR A<br>
> PARTICULAR PURPOSE. See the GNU * + * Lesser General Public<br>
> License for more details. * + *<br>
> * + *<br>
> You should have received a copy of the GNU Lesser General Public<br>
> * + * License along with this library. If not, see<br>
> <<a href="http://www.gnu.org/licenses/" \
target="_blank">http://www.gnu.org/licenses/</a>>. * +<br> > \
***************************************************************************<br> > \
********/ +<br> > +#ifndef FILESYSTEMSEARCHMEDIASOURCE_H<br>
> +#define FILESYSTEMSEARCHMEDIASOURCE_H<br>
> +<br>
> +#include <mediacenter/abstractmediasource.h><br>
> +<br>
> +#include <QMutex><br>
> +<br>
> +class QFileInfo;<br>
> +class QDir;<br>
> +<br>
> +/**<br>
> + * \brief Goes through the user's home dir and searches for media<br>
> + *<br>
> + * This MediaSource is supposed to be used for a better-than-nothing<br>
> scenario + * when none of Baloo or Nepomuk are installed. As such this<br>
> MediaSource does + * not attempt 100% correctness and is not configurable<br>
> at all.<br>
> + */<br>
> +class FilesystemSearchMediaSource : public MediaCenter::AbstractMediaSource<br>
> +{<br>
> +public:<br>
> + explicit FilesystemSearchMediaSource(QObject* parent = 0, const<br>
> QVariantList& = QVariantList()); + virtual<br>
> ~FilesystemSearchMediaSource();<br>
> +<br>
> +protected:<br>
> + virtual void run();<br>
> +<br>
> +private:<br>
> + mutable QMutex m_quitMutex;<br>
> + bool m_quit;<br>
> +<br>
> + QStringList m_allowedMimes;<br>
> +<br>
> + bool shouldQuit() const;<br>
> + bool recursiveSearch(const QDir& dir);<br>
> + void stop();<br>
> + bool checkAndAddFile(const QFileInfo &fileInfo);<br>
> + void addFile(const QFileInfo &fileInfo, const QString &type);<br>
> +};<br>
> +<br>
> +#endif // FILESYSTEMSEARCHMEDIASOURCE_H<br>
<span class=""><font color="#888888"><br>
--<br>
Vishesh Handa<br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br>Shantanu Tushar \
(UTC +0530)<br><a href="http://www.shantanutushar.com" \
target="_blank">http://www.shantanutushar.com</a> </div></div>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic