• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

NepomukDaemons

searchfolder.h

Go to the documentation of this file.
00001 /*
00002    Copyright (C) 2008 by Sebastian Trueg <trueg at kde.org>
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software
00016    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017  */
00018 
00019 #ifndef _NEPOMUK_SEARCH_FOLDER_H_
00020 #define _NEPOMUK_SEARCH_FOLDER_H_
00021 
00022 #include <QtCore/QThread>
00023 #include <QtCore/QString>
00024 #include <QtCore/QList>
00025 #include <QtCore/QEventLoop>
00026 #include <QtCore/QQueue>
00027 #include <QtCore/QMutex>
00028 
00029 #include "term.h"
00030 #include "result.h"
00031 #include "query.h"
00032 
00033 #include <kio/udsentry.h>
00034 #include <kio/slavebase.h>
00035 #include <Nepomuk/Resource>
00036 #include <KUrl>
00037 
00038 
00039 uint qHash( const QUrl& );
00040 
00041 namespace Nepomuk {
00042     namespace Search {
00043         class QueryServiceClient;
00044     }
00045 
00046     class SearchFolder;
00047 
00048     class SearchEntry
00049     {
00050     public:
00051         SearchEntry( const QUrl& uri,
00052                      const KIO::UDSEntry& = KIO::UDSEntry() );
00053 
00054         QUrl resource() const { return m_resource; }
00055         KIO::UDSEntry entry() const { return m_entry; }
00056 
00057     private:
00058         QUrl m_resource;
00059         KIO::UDSEntry m_entry;
00060 
00061         friend class SearchFolder;
00062     };
00063 
00064 
00065     class SearchFolder : public QThread
00066     {
00067         Q_OBJECT
00068 
00069     public:
00070         SearchFolder();
00071         SearchFolder( const QString& name, const Search::Query& query, KIO::SlaveBase* slave );
00072         ~SearchFolder();
00073 
00074         Search::Query query() const { return m_query; }
00075         QString name() const { return m_name; }
00076         QList<SearchEntry*> entries() const { return m_entries.values(); }
00077 
00078         SearchEntry* findEntry( const QString& name ) const;
00079         SearchEntry* findEntry( const KUrl& url ) const;
00080 
00081         void list();
00082         void stat( const QString& name );
00083 
00084     private Q_SLOTS:
00085         void slotNewEntries( const QList<Nepomuk::Search::Result>& );
00086         void slotEntriesRemoved( const QList<QUrl>& );
00087         void slotFinishedListing();
00088         void slotStatNextResult();
00089 
00090     private:
00091         // reimplemented from QThread -> does handle the query
00092         // we run this in a different thread since SlaveBase does
00093         // not have an event loop but we need to deliver signals
00094         // anyway
00095         void run();
00096 
00100         SearchEntry* statResult( const Search::Result& result );
00101         void wrap();
00102 
00103         // folder properties
00104         QString m_name;
00105         Search::Query m_query;
00106 
00107         // result cache
00108         QQueue<Search::Result> m_results;
00109         QHash<QString, SearchEntry*> m_entries;
00110         QHash<QUrl, QString> m_resourceNameMap;
00111 
00112         // used to make sure we have unique names
00113         // FIXME: the changed names could clash again!
00114         QHash<QString, int> m_nameCntHash;
00115 
00116         // true if the client listed all results and new
00117         // ones do not need to be listed but emitted through
00118         // KDirNotify
00119         bool m_initialListingFinished;
00120 
00121         // the parent slave used for listing and stating
00122         KIO::SlaveBase* m_slave;
00123 
00124         // if set, this is the name that was requested through
00125         // stat(). Used during initial listing when not all results
00126         // are available yet
00127         QString m_nameToStat;
00128 
00129         // true if stating of an entry has been requested (name of entry in m_nameToStat)
00130         bool m_statEntry;
00131 
00132         // true if listing of entries has been requested
00133         bool m_listEntries;
00134 
00135         // true if the stat loop is running
00136         bool m_statingStarted;
00137 
00138         // used to make all calls sync
00139         QEventLoop m_loop;
00140 
00141         Search::QueryServiceClient* m_client;
00142 
00143         // mutex to protect the results
00144         QMutex m_resultMutex;
00145     };
00146 }
00147 
00148 #endif

NepomukDaemons

Skip menu "NepomukDaemons"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KCMShell
  • KNotify
  • KStyles
  • Nepomuk Daemons
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal