[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&#39;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">&lt;<a href="mailto:me@vhanda.in" \
target="_blank">me@vhanda.in</a>&gt;</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> &gt; Git commit c140e2382a56c4bfde2fe99b2fdaf19897424e88 by \
Shantanu Tushar.<br> &gt; Committed on 30/03/2014 at 08:38.<br>
&gt; Pushed by shantanu into branch &#39;master&#39;.<br>
&gt;<br>
&gt; Add a basic Filesystem media source which is supposed to be very simple and<br>
&gt; only scan the home dir. CMake output makes it clear that this is a limited<br>
&gt; source and should only be used when Baloo and Nepomuk can&#39;t be \
installed.<br> &gt;<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>
&gt; M  +20   -7    plugins/CMakeLists.txt<br>
&gt; A  +16   -0    plugins/filesystemsearch/CMakeLists.txt<br>
&gt; A  +14   -0    plugins/filesystemsearch/filesystemsearch.desktop<br>
&gt; A  +108  -0    plugins/filesystemsearch/filesystemsearchmediasource.cpp<br>
&gt; [License: LGPL (v2.1+)] A  +57   -0<br>
&gt; plugins/filesystemsearch/filesystemsearchmediasource.h     [License: LGPL<br>
&gt; (v2.1+)]<br>
&gt;<br>
&gt; <a href="http://commits.kde.org/plasma-mediacenter/c140e2382a56c4bfde2fe99b2fdaf19897" \
target="_blank">http://commits.kde.org/plasma-mediacenter/c140e2382a56c4bfde2fe99b2fdaf19897</a><br>
 &gt; 424e88<br>
&gt;<br>
&gt; diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt<br>
&gt; index 7f89498..7458861 100644<br>
&gt; --- a/plugins/CMakeLists.txt<br>
&gt; +++ b/plugins/CMakeLists.txt<br>
&gt; @@ -1,11 +1,24 @@<br>
&gt; -find_package(NepomukCore)<br>
&gt; -if(NepomukCore_FOUND)<br>
&gt; -    message(STATUS &quot;********** Found Nepomuk, building Nepomuk Search<br>
&gt; plugin&quot;) -    add_subdirectory(kdedesktopsearch)<br>
&gt; -endif(NepomukCore_FOUND)<br>
&gt; -<br>
&gt; -find_package(Baloo)<br>
&gt; +find_package(Baloo QUIET)<br>
&gt;  if(Baloo_FOUND)<br>
&gt;      message(STATUS &quot;********** Found Baloo, building Baloo Search \
plugin&quot;)<br> &gt;      add_subdirectory(baloosearch)<br>
&gt; +else(Baloo_FOUND)<br>
&gt; +    find_package(NepomukCore QUIET)<br>
&gt; +<br>
&gt; +    if(NepomukCore_FOUND)<br>
&gt; +        message(STATUS &quot;********** Found Nepomuk, building Nepomuk \
Search<br> &gt; plugin&quot;) +        add_subdirectory(kdedesktopsearch)<br>
&gt; +    else(NepomukCore_FOUND)<br>
&gt; +        message(STATUS &quot;********** Neither Baloo nor Nepomuk was \
found,<br> &gt; install one of them to get more functionality&quot;) +<br>
&gt; +        if(USE_FILESYSTEM_MEDIA_SOURCE)<br>
&gt; +            message(STATUS &quot;********** Building the limited Filesystem<br>
&gt; Search plugin&quot;) +            add_subdirectory(filesystemsearch)<br>
&gt; +        else(USE_FILESYSTEM_MEDIA_SOURCE)<br>
&gt; +            message(STATUS &quot;********** Because of this, no media \
sources<br> &gt; are being built. Only local browsing will be available&quot;) +<br>
&gt; message(STATUS &quot;********** If you not on KDE or cannot install Baloo or<br>
&gt; Nepomuk, set USE_FILESYSTEM_MEDIA_SOURCE=ON to cmake to build the limited<br>
&gt; Filesystem Search plugin&quot;) +        endif(USE_FILESYSTEM_MEDIA_SOURCE)<br>
&gt; +<br>
&gt; +    endif(NepomukCore_FOUND)<br>
&gt; +<br>
&gt;  endif(Baloo_FOUND)<br>
&gt; diff --git a/plugins/filesystemsearch/CMakeLists.txt<br>
&gt; b/plugins/filesystemsearch/CMakeLists.txt new file mode 100644<br>
&gt; index 0000000..e6c6b6b<br>
&gt; --- /dev/null<br>
&gt; +++ b/plugins/filesystemsearch/CMakeLists.txt<br>
&gt; @@ -0,0 +1,16 @@<br>
&gt; +set(filesystemsearch_SRCS<br>
&gt; +    filesystemsearchmediasource.cpp<br>
&gt; +)<br>
&gt; +<br>
&gt; +qt4_automoc(${filesystemsearch_SRCS})<br>
&gt; +<br>
&gt; +kde4_add_plugin(pmc_filesystemsearch ${filesystemsearch_SRCS})<br>
&gt; +<br>
&gt; +target_link_libraries(pmc_filesystemsearch<br>
&gt; +    plasmamediacenter<br>
&gt; +    ${KDE4_KDECORE_LIBS}<br>
&gt; +    ${QT_QTGUI_LIBRARIES}<br>
&gt; +)<br>
&gt; +<br>
&gt; +install(TARGETS pmc_filesystemsearch DESTINATION ${PLUGIN_INSTALL_DIR})<br>
&gt; +install(FILES filesystemsearch.desktop DESTINATION ${SERVICES_INSTALL_DIR})<br>
&gt; diff --git a/plugins/filesystemsearch/filesystemsearch.desktop<br>
&gt; b/plugins/filesystemsearch/filesystemsearch.desktop new file mode 100644<br>
&gt; index 0000000..f1c63e5<br>
&gt; --- /dev/null<br>
&gt; +++ b/plugins/filesystemsearch/filesystemsearch.desktop<br>
&gt; @@ -0,0 +1,14 @@<br>
&gt; +[Desktop Entry]<br>
&gt; +Type=Service<br>
&gt; +Icon=drive-harddisk<br>
&gt; +Name=Filesystem Search<br>
&gt; +Comment=Get media from your local files<br>
&gt; +<br>
&gt; +X-KDE-ServiceTypes=Plasma/MediaCenter/MediaSource<br>
&gt; +<br>
&gt; +X-KDE-PluginInfo-Author=Shantanu Tushar<br>
&gt; +X-KDE-PluginInfo-Email=<a \
href="mailto:shantanu@kde.org">shantanu@kde.org</a><br> &gt; \
+X-KDE-PluginInfo-Version=1.0<br> &gt; +X-KDE-PluginInfo-License=GPL<br>
&gt; +X-KDE-PluginInfo-EnabledByDefault=true<br>
&gt; +X-KDE-Library=pmc_filesystemsearch<br>
&gt; diff --git a/plugins/filesystemsearch/filesystemsearchmediasource.cpp<br>
&gt; b/plugins/filesystemsearch/filesystemsearchmediasource.cpp new file mode<br>
&gt; 100644<br>
&gt; index 0000000..44ba844<br>
&gt; --- /dev/null<br>
&gt; +++ b/plugins/filesystemsearch/filesystemsearchmediasource.cpp<br>
&gt; @@ -0,0 +1,108 @@<br>
&gt; +/**************************************************************************<br>
&gt; ********* + *   Copyright 2014 Shantanu Tushar &lt;<a \
href="mailto:shantanu@kde.org">shantanu@kde.org</a>&gt;<br> &gt;                  * + \
*<br> &gt;                            * + *   This library is free software; you \
can<br> &gt; redistribute it and/or                 * + *   modify it under the terms \
of<br> &gt; the GNU Lesser General Public                    * + *   License as<br>
&gt; published by the Free Software Foundation; either                  * + *<br>
&gt; version 2.1 of the License, or (at your option) any later version.<br>
&gt;   * + *<br>
&gt;             * + *   This library is distributed in the hope that it will be<br>
&gt; useful,               * + *   but WITHOUT ANY WARRANTY; without even the<br>
&gt; implied warranty of                * + *   MERCHANTABILITY or FITNESS FOR A<br>
&gt; PARTICULAR PURPOSE.  See the GNU             * + *   Lesser General Public<br>
&gt; License for more details.                               * + *<br>
&gt;                                                                   * + *<br>
&gt; You should have received a copy of the GNU Lesser General Public<br>
&gt;   * + *   License along with this library.  If not, see<br>
&gt; &lt;<a href="http://www.gnu.org/licenses/" \
target="_blank">http://www.gnu.org/licenses/</a>&gt;. * +<br> &gt; \
***************************************************************************<br> &gt; \
********/ +<br> &gt; +#include &quot;filesystemsearchmediasource.h&quot;<br>
&gt; +<br>
&gt; +#include &lt;mediacenter/singletonfactory.h&gt;<br>
&gt; +#include &lt;mediacenter/medialibrary.h&gt;<br>
&gt; +#include &lt;mediacenter/mediacenter.h&gt;<br>
&gt; +<br>
&gt; +#include &lt;KMimeType&gt;<br>
&gt; +<br>
&gt; +#include &lt;QDir&gt;<br>
&gt; +#include &lt;QDebug&gt;<br>
&gt; +<br>
&gt; +MEDIACENTER_EXPORT_MEDIASOURCE(FilesystemSearchMediaSource)<br>
&gt; +<br>
&gt; +FilesystemSearchMediaSource::FilesystemSearchMediaSource(QObject* parent,<br>
&gt; const QVariantList&amp;) +    : m_quit(false)<br>
&gt; +{<br>
&gt; +    m_allowedMimes &lt;&lt; &quot;audio&quot; &lt;&lt; &quot;image&quot; \
&lt;&lt; &quot;video&quot;;<br> &gt; +}<br>
&gt; +<br>
&gt; +FilesystemSearchMediaSource::~FilesystemSearchMediaSource()<br>
&gt; +{<br>
&gt; +    qDebug() &lt;&lt; &quot;Waiting for Filesystem Search to quit...&quot;;<br>
&gt; +    stop();<br>
&gt; +    wait();<br>
&gt; +}<br>
&gt; +<br>
&gt; +void FilesystemSearchMediaSource::run()<br>
&gt; +{<br>
&gt; +    setPriority(IdlePriority);<br>
&gt; +    recursiveSearch(QDir::home());<br>
&gt; +    qDebug() &lt;&lt; &quot;Done scanning the Filesystem&quot;;<br>
&gt; +}<br>
&gt; +<br>
&gt; +bool FilesystemSearchMediaSource::recursiveSearch(const QDir &amp;dir)<br>
&gt; +{<br>
&gt; +    if (shouldQuit())   return false;<br>
<br>
Coding style? There is similar stuff all \
over.<br></blockquote><div><br></div><div>Laziness peril, shouldn&#39;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>
&gt; +<br>
&gt; +    foreach(const QFileInfo &amp;fileInfo, dir.entryInfoList(QDir::Files)) \
{<br> &gt; +        if (shouldQuit())   return false;<br>
&gt; +        checkAndAddFile(fileInfo);<br>
&gt; +    }<br>
&gt; +<br>
&gt; +    foreach(const QFileInfo &amp;dirInfo, dir.entryInfoList(QDir::Dirs |<br>
&gt; QDir::NoDotAndDotDot)) { +        if (shouldQuit())   return false;<br>
&gt; +        if (!recursiveSearch(QDir(dirInfo.absoluteFilePath()))) {<br>
&gt; +            break;<br>
&gt; +        }<br>
&gt; +    }<br>
&gt; +<br>
&gt; +    return true;<br>
&gt; +}<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 &quot;slow&quot; along with \
&quot;limited&quot; 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>
&gt; +<br>
&gt; +bool FilesystemSearchMediaSource::shouldQuit() const<br>
&gt; +{<br>
&gt; +    QMutexLocker l(&amp;m_quitMutex);<br>
&gt; +    return m_quit;<br>
&gt; +}<br>
&gt; +<br>
&gt; +void FilesystemSearchMediaSource::stop()<br>
&gt; +{<br>
&gt; +    QMutexLocker l(&amp;m_quitMutex);<br>
&gt; +    m_quit = true;<br>
&gt; +}<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>
&gt; +<br>
&gt; +bool FilesystemSearchMediaSource::checkAndAddFile(const QFileInfo&amp;<br>
&gt; fileInfo) +{<br>
&gt; +    const QString mimeType = KMimeType::findByUrl(<br>
&gt; +        KUrl::fromLocalFile(fileInfo.absoluteFilePath()))-&gt;name();<br>
&gt; +<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&#39;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&#39;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>
&gt; +    const QString topLevelTypeName = mimeType.split(&quot;/&quot;).at(0);<br>
&gt; +<br>
&gt; +    if (!topLevelTypeName.isEmpty() &amp;&amp;<br>
&gt; m_allowedMimes.contains(topLevelTypeName)) { +        addFile(fileInfo,<br>
&gt; topLevelTypeName);<br>
&gt; +        return true;<br>
&gt; +    }<br>
&gt; +<br>
&gt; +    return false;<br>
&gt; +}<br>
&gt; +<br>
&gt; +void FilesystemSearchMediaSource::addFile(const QFileInfo&amp; fileInfo,<br>
&gt; +                                          const QString &amp;type)<br>
&gt; +{<br>
&gt; +    qDebug() &lt;&lt; &quot;Adding &quot; &lt;&lt; type &lt;&lt; \
fileInfo.fileName();<br> &gt; +    QHash&lt;int, QVariant&gt; values;<br>
&gt; +<br>
&gt; +    values.insert(Qt::DisplayRole, fileInfo.fileName());<br>
&gt; +    values.insert(MediaCenter::MediaUrlRole,<br>
&gt; QUrl::fromLocalFile(fileInfo.absoluteFilePath()).toString()); +<br>
&gt; values.insert(MediaCenter::MediaTypeRole, type);<br>
&gt; +<br>
&gt; +    SingletonFactory::instanceFor&lt;MediaLibrary&gt;()-&gt;updateMedia(values);<br>
 &gt; +}<br>
&gt; diff --git a/plugins/filesystemsearch/filesystemsearchmediasource.h<br>
&gt; b/plugins/filesystemsearch/filesystemsearchmediasource.h new file mode<br>
&gt; 100644<br>
&gt; index 0000000..88740b8<br>
&gt; --- /dev/null<br>
&gt; +++ b/plugins/filesystemsearch/filesystemsearchmediasource.h<br>
&gt; @@ -0,0 +1,57 @@<br>
&gt; +/**************************************************************************<br>
&gt; ********* + *   Copyright 2014 Shantanu Tushar &lt;<a \
href="mailto:shantanu@kde.org">shantanu@kde.org</a>&gt;<br> &gt;                  * + \
*<br> &gt;                            * + *   This library is free software; you \
can<br> &gt; redistribute it and/or                 * + *   modify it under the terms \
of<br> &gt; the GNU Lesser General Public                    * + *   License as<br>
&gt; published by the Free Software Foundation; either                  * + *<br>
&gt; version 2.1 of the License, or (at your option) any later version.<br>
&gt;   * + *<br>
&gt;             * + *   This library is distributed in the hope that it will be<br>
&gt; useful,               * + *   but WITHOUT ANY WARRANTY; without even the<br>
&gt; implied warranty of                * + *   MERCHANTABILITY or FITNESS FOR A<br>
&gt; PARTICULAR PURPOSE.  See the GNU             * + *   Lesser General Public<br>
&gt; License for more details.                               * + *<br>
&gt;                                                                   * + *<br>
&gt; You should have received a copy of the GNU Lesser General Public<br>
&gt;   * + *   License along with this library.  If not, see<br>
&gt; &lt;<a href="http://www.gnu.org/licenses/" \
target="_blank">http://www.gnu.org/licenses/</a>&gt;. * +<br> &gt; \
***************************************************************************<br> &gt; \
********/ +<br> &gt; +#ifndef FILESYSTEMSEARCHMEDIASOURCE_H<br>
&gt; +#define FILESYSTEMSEARCHMEDIASOURCE_H<br>
&gt; +<br>
&gt; +#include &lt;mediacenter/abstractmediasource.h&gt;<br>
&gt; +<br>
&gt; +#include &lt;QMutex&gt;<br>
&gt; +<br>
&gt; +class QFileInfo;<br>
&gt; +class QDir;<br>
&gt; +<br>
&gt; +/**<br>
&gt; + * \brief Goes through the user&#39;s home dir and searches for media<br>
&gt; + *<br>
&gt; + * This MediaSource is supposed to be used for a better-than-nothing<br>
&gt; scenario + * when none of Baloo or Nepomuk are installed. As such this<br>
&gt; MediaSource does + * not attempt 100% correctness and is not configurable<br>
&gt; at all.<br>
&gt; + */<br>
&gt; +class FilesystemSearchMediaSource : public MediaCenter::AbstractMediaSource<br>
&gt; +{<br>
&gt; +public:<br>
&gt; +    explicit FilesystemSearchMediaSource(QObject* parent = 0, const<br>
&gt; QVariantList&amp;  = QVariantList()); +    virtual<br>
&gt; ~FilesystemSearchMediaSource();<br>
&gt; +<br>
&gt; +protected:<br>
&gt; +    virtual void run();<br>
&gt; +<br>
&gt; +private:<br>
&gt; +    mutable QMutex m_quitMutex;<br>
&gt; +    bool m_quit;<br>
&gt; +<br>
&gt; +    QStringList m_allowedMimes;<br>
&gt; +<br>
&gt; +    bool shouldQuit() const;<br>
&gt; +    bool recursiveSearch(const QDir&amp; dir);<br>
&gt; +    void stop();<br>
&gt; +    bool checkAndAddFile(const QFileInfo &amp;fileInfo);<br>
&gt; +    void addFile(const QFileInfo &amp;fileInfo, const QString &amp;type);<br>
&gt; +};<br>
&gt; +<br>
&gt; +#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