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)
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>
33 #include <kio/udsentry.h>
34 #include <kio/slavebase.h>
35 #include <Nepomuk/Resource>
39 uint
qHash( const QUrl
& );
43 class QueryServiceClient
;
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
; }
59 KIO::UDSEntry m_entry
;
61 friend class SearchFolder
;
65 class SearchFolder
: public QThread
71 SearchFolder( const QString
& name
, const Search::Query
& query
, KIO::SlaveBase
* slave
);
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;
82 void stat( const QString
& name
);
85 void slotNewEntries( const QList
<Nepomuk::Search::Result
>& );
86 void slotEntriesRemoved( const QList
<QUrl
>& );
87 void slotFinishedListing();
88 void slotStatNextResult();
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
98 * Stats the result and returns the entry.
100 SearchEntry
* statResult( const Search::Result
& result
);
105 Search::Query m_query
;
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
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
127 QString m_nameToStat
;
129 // true if stating of an entry has been requested (name of entry in m_nameToStat)
132 // true if listing of entries has been requested
135 // true if the stat loop is running
136 bool m_statingStarted
;
138 // used to make all calls sync
141 Search::QueryServiceClient
* m_client
;
143 // mutex to protect the results
144 QMutex m_resultMutex
;