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

« back to all changes in this revision

Viewing changes to src/file/basicindexingqueue.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
    <one line to give the library's name and an idea of what it does.>
 
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) any later version.
 
9
 
 
10
    This library is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
    Lesser General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Lesser General Public
 
16
    License along with this library; if not, write to the Free Software
 
17
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
18
*/
 
19
 
 
20
 
 
21
#ifndef BASICINDEXINGQUEUE_H
 
22
#define BASICINDEXINGQUEUE_H
 
23
 
 
24
#include "indexingqueue.h"
 
25
#include "filemapping.h"
 
26
 
 
27
#include <QStack>
 
28
#include <QPair>
 
29
#include <QMimeDatabase>
 
30
#include <xapian.h>
 
31
 
 
32
 
 
33
class Database;
 
34
 
 
35
namespace Baloo
 
36
{
 
37
 
 
38
class FileIndexerConfig;
 
39
 
 
40
enum UpdateDirFlag {
 
41
    /**
 
42
     * No flags, only used to make code more readable
 
43
     */
 
44
    NoUpdateFlags = 0x0,
 
45
 
 
46
    /**
 
47
     * The folder should be updated recursive
 
48
     */
 
49
    UpdateRecursive = 0x1,
 
50
 
 
51
    /**
 
52
     * The folder has been scheduled to update by the
 
53
     * update system, not by a call to updateDir
 
54
     */
 
55
    AutoUpdateFolder = 0x2,
 
56
 
 
57
    /**
 
58
     * The files in the folder should be updated regardless
 
59
     * of their state.
 
60
     */
 
61
    ForceUpdate = 0x4
 
62
};
 
63
Q_DECLARE_FLAGS(UpdateDirFlags, UpdateDirFlag)
 
64
 
 
65
/**
 
66
 * This class represents a simple queue that iterates over the file system tree
 
67
 * and indexes each file which meets certain critera. The indexing performed by this
 
68
 * queue is very basic. It just pushes the mimetype, url and stat results of the file.
 
69
 */
 
70
class BasicIndexingQueue: public IndexingQueue
 
71
{
 
72
    Q_OBJECT
 
73
public:
 
74
    explicit BasicIndexingQueue(Database* db, FileIndexerConfig* config, QObject* parent = 0);
 
75
 
 
76
    virtual bool isEmpty();
 
77
 
 
78
Q_SIGNALS:
 
79
    void newDocument(unsigned id, Xapian::Document doc);
 
80
 
 
81
public Q_SLOTS:
 
82
    void enqueue(const FileMapping& file);
 
83
    void enqueue(const FileMapping& file, UpdateDirFlags flags);
 
84
 
 
85
    void clear();
 
86
    void clear(const QString& path);
 
87
 
 
88
protected:
 
89
    virtual void processNextIteration();
 
90
 
 
91
private:
 
92
    /**
 
93
     * This method does not need to be synchronous. The indexing operation may be started
 
94
     * and on completion, the finishedIndexing method should be called
 
95
     */
 
96
    void index(const FileMapping& file, const QString& mimetype);
 
97
 
 
98
    bool shouldIndex(FileMapping& file, const QString& mimetype) const;
 
99
    bool shouldIndexContents(const QString& dir);
 
100
 
 
101
    /**
 
102
     * Check if the \p path needs to be indexed based on the \p flags
 
103
     * and the path. If it needs to be indexed, then start indexing
 
104
     * it.
 
105
     *
 
106
     * \return \c true the path is being indexed
 
107
     * \return \c false the path did not meet the criteria
 
108
     */
 
109
    bool process(FileMapping& file, UpdateDirFlags flags);
 
110
 
 
111
    QStack< QPair<FileMapping, UpdateDirFlags> > m_paths;
 
112
 
 
113
    Database* m_db;
 
114
    FileIndexerConfig* m_config;
 
115
    QMimeDatabase m_mimeDb;
 
116
};
 
117
 
 
118
}
 
119
 
 
120
Q_DECLARE_OPERATORS_FOR_FLAGS(Baloo::UpdateDirFlags)
 
121
 
 
122
#endif // BASICINDEXINGQUEUE_H