add more spacing
[personal-kdebase.git] / runtime / nepomuk / kioslaves / search / searchfolder.h
blob57346fd0ee6c5eec25c9ca782f6ba220873657e2
1 /*
2 Copyright (C) 2008 by Sebastian Trueg <trueg at kde.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #ifndef _NEPOMUK_SEARCH_FOLDER_H_
20 #define _NEPOMUK_SEARCH_FOLDER_H_
22 #include <QtCore/QThread>
23 #include <QtCore/QString>
24 #include <QtCore/QList>
25 #include <QtCore/QEventLoop>
26 #include <QtCore/QQueue>
27 #include <QtCore/QMutex>
29 #include "term.h"
30 #include "result.h"
31 #include "query.h"
33 #include <kio/udsentry.h>
34 #include <kio/slavebase.h>
35 #include <Nepomuk/Resource>
36 #include <KUrl>
39 uint qHash( const QUrl& );
41 namespace Nepomuk {
42 namespace Search {
43 class QueryServiceClient;
46 class SearchFolder;
48 class SearchEntry
50 public:
51 SearchEntry( const QUrl& uri,
52 const KIO::UDSEntry& = KIO::UDSEntry() );
54 QUrl resource() const { return m_resource; }
55 KIO::UDSEntry entry() const { return m_entry; }
57 private:
58 QUrl m_resource;
59 KIO::UDSEntry m_entry;
61 friend class SearchFolder;
65 class SearchFolder : public QThread
67 Q_OBJECT
69 public:
70 SearchFolder();
71 SearchFolder( const QString& name, const Search::Query& query, KIO::SlaveBase* slave );
72 ~SearchFolder();
74 Search::Query query() const { return m_query; }
75 QString name() const { return m_name; }
76 QList<SearchEntry*> entries() const { return m_entries.values(); }
78 SearchEntry* findEntry( const QString& name ) const;
79 SearchEntry* findEntry( const KUrl& url ) const;
81 void list();
82 void stat( const QString& name );
84 private Q_SLOTS:
85 void slotNewEntries( const QList<Nepomuk::Search::Result>& );
86 void slotEntriesRemoved( const QList<QUrl>& );
87 void slotFinishedListing();
88 void slotStatNextResult();
90 private:
91 // reimplemented from QThread -> does handle the query
92 // we run this in a different thread since SlaveBase does
93 // not have an event loop but we need to deliver signals
94 // anyway
95 void run();
97 /**
98 * Stats the result and returns the entry.
100 SearchEntry* statResult( const Search::Result& result );
101 void wrap();
103 // folder properties
104 QString m_name;
105 Search::Query m_query;
107 // result cache
108 QQueue<Search::Result> m_results;
109 QHash<QString, SearchEntry*> m_entries;
110 QHash<QUrl, QString> m_resourceNameMap;
112 // used to make sure we have unique names
113 // FIXME: the changed names could clash again!
114 QHash<QString, int> m_nameCntHash;
116 // true if the client listed all results and new
117 // ones do not need to be listed but emitted through
118 // KDirNotify
119 bool m_initialListingFinished;
121 // the parent slave used for listing and stating
122 KIO::SlaveBase* m_slave;
124 // if set, this is the name that was requested through
125 // stat(). Used during initial listing when not all results
126 // are available yet
127 QString m_nameToStat;
129 // true if stating of an entry has been requested (name of entry in m_nameToStat)
130 bool m_statEntry;
132 // true if listing of entries has been requested
133 bool m_listEntries;
135 // true if the stat loop is running
136 bool m_statingStarted;
138 // used to make all calls sync
139 QEventLoop m_loop;
141 Search::QueryServiceClient* m_client;
143 // mutex to protect the results
144 QMutex m_resultMutex;
148 #endif