~ubuntu-branches/debian/sid/baloo-kf5/sid

« back to all changes in this revision

Viewing changes to src/file/indexingqueue.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-07-10 21:13:07 UTC
  • Revision ID: package-import@ubuntu.com-20140710211307-iku0qs6vlplgn06m
Tags: upstream-5.0.0b
ImportĀ upstreamĀ versionĀ 5.0.0b

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of the KDE Baloo Project
 
3
 * Copyright (C) 2012  Vishesh Handa <me@vhanda.in>
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Lesser General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2.1 of the License, or (at your option) version 3, or any
 
9
 * later version accepted by the membership of KDE e.V. (or its
 
10
 * successor approved by the membership of KDE e.V.), which shall
 
11
 * act as a proxy defined in Section 6 of version 3 of the license.
 
12
 *
 
13
 * This library is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * Lesser General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Lesser General Public
 
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
20
 *
 
21
 */
 
22
 
 
23
 
 
24
#ifndef FILEINDEXER_INDEXINGQUEUE_H
 
25
#define FILEINDEXER_INDEXINGQUEUE_H
 
26
 
 
27
#include <QtCore/QObject>
 
28
#include <QtCore/QQueue>
 
29
#include <QtCore/QDirIterator>
 
30
 
 
31
namespace Baloo
 
32
{
 
33
 
 
34
/**
 
35
 * An abstract class representing the queue. All indexing queues
 
36
 * should be derived from this queue.
 
37
 *
 
38
 */
 
39
class IndexingQueue : public QObject
 
40
{
 
41
    Q_OBJECT
 
42
public:
 
43
    explicit IndexingQueue(QObject* parent = 0);
 
44
 
 
45
    virtual bool isEmpty() = 0;
 
46
 
 
47
    /**
 
48
     * fill the queue if there is available data, return true if something
 
49
     * is enqueued. Should be used in combinition with isEmpty()
 
50
     *
 
51
     * Default implementation will do nothing.
 
52
     */
 
53
    virtual void fillQueue();
 
54
 
 
55
    /**
 
56
     * Sets a artificial delay between each call to processNextIteration.
 
57
     * This can be used to slow down the indexing, in order to conserve
 
58
     * resources.
 
59
     */
 
60
    void setDelay(int msec);
 
61
    int delay() const;
 
62
 
 
63
    bool isSuspended() const;
 
64
 
 
65
public Q_SLOTS:
 
66
    void suspend();
 
67
    void resume();
 
68
 
 
69
Q_SIGNALS:
 
70
    /**
 
71
     * This signal will be emitted when the queue starts
 
72
     * processing items
 
73
     */
 
74
    void startedIndexing();
 
75
 
 
76
    /**
 
77
     * The signal be emitted once the queue is empty
 
78
     */
 
79
    void finishedIndexing();
 
80
 
 
81
protected:
 
82
    /**
 
83
     * Process the next iteration in your queue. Once you are done
 
84
     * processing the file call finishIndexingFile so that the queue
 
85
     * can continue processing and call this function when it is
 
86
     * ready for the next iteration.
 
87
     *
 
88
     * \sa finishIndexingFile
 
89
     */
 
90
    virtual void processNextIteration() = 0;
 
91
    virtual void doSuspend();
 
92
    virtual void doResume();
 
93
 
 
94
protected Q_SLOTS:
 
95
    /**
 
96
     * Call this function when you have finished processing the
 
97
     * iteration from processNextIteration.
 
98
     *
 
99
     * \sa processNextIteration
 
100
     */
 
101
    void finishIteration();
 
102
 
 
103
    void callForNextIteration();
 
104
 
 
105
private Q_SLOTS:
 
106
    void processNext();
 
107
 
 
108
private:
 
109
    bool m_suspended;
 
110
    bool m_sentEvent;
 
111
    bool m_shouldEmitStartSignal;
 
112
    int m_delay;
 
113
};
 
114
 
 
115
}
 
116
 
 
117
 
 
118
#endif // FILEINDEXER_INDEXINGQUEUE_H