2 Copyright (c) 2008 Sebastian Trueg <trueg@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #ifndef _NEPOMUK_VIRTUAL_FOLDER_H_
20 #define _NEPOMUK_VIRTUAL_FOLDER_H_
22 #include <QtCore/QObject>
26 #include "searchcore.h"
28 #include <QtCore/QHash>
29 #include <QtCore/QTimer>
36 class FolderConnection
;
39 * One search folder which automatically updates itself.
40 * Once all connections to the folder have been deleted,
41 * the folder deletes itself.
43 class Folder
: public QObject
48 Folder( const Query
& query
, QObject
* parent
= 0 );
52 * \return A list of all cached results in the folder.
53 * If initial listing is not finished yet, the results found
54 * so far are returned.
56 QList
<Result
> entries() const;
59 * \return true if the initial listing is done, ie. further
60 * signals only mean a change in the folder.
62 bool initialListingDone() const;
64 QList
<FolderConnection
*> openConnections() const;
70 void newEntries( const QList
<Nepomuk::Search::Result
>& entries
);
71 void entriesRemoved( const QList
<QUrl
>& entries
);
72 void finishedListing();
75 void slotSearchNewResult( const Nepomuk::Search::Result
& );
76 void slotSearchScoreChanged( const Nepomuk::Search::Result
& );
77 void slotSearchFinished();
78 void slotStorageChanged();
79 void slotUpdateTimeout();
83 * Called by the FolderConnection constructor.
85 void addConnection( FolderConnection
* );
88 * Called by the FolderConnection destructor.
90 void removeConnection( FolderConnection
* );
93 QList
<FolderConnection
*> m_connections
;
95 bool m_initialListingDone
;
96 QHash
<QUrl
, Result
> m_results
; // the actual current results
97 QHash
<QUrl
, Result
> m_newResults
; // the results gathered during an update, needed to find removed items
99 SearchCore
* m_searchCore
;
101 bool m_storageChanged
; // did the nepomuk store change after the last update
102 QTimer m_updateTimer
; // used to ensure that we do not update all the time if the storage changes a lot
104 friend class FolderConnection
; // for addConnection and removeConnection