kateprojectworker.h 3.57 KB
Newer Older
Christoph Cullmann's avatar
Christoph Cullmann committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*  This file is part of the Kate project.
 *
 *  Copyright (C) 2010 Christoph Cullmann <cullmann@kde.org>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 */

21 22
#ifndef KATE_PROJECT_WORKER_H
#define KATE_PROJECT_WORKER_H
Christoph Cullmann's avatar
Christoph Cullmann committed
23

24 25 26 27 28
#include "kateprojectitem.h"
#include "kateproject.h"

#include <ThreadWeaver/Job>

Christoph Cullmann's avatar
Christoph Cullmann committed
29 30
#include <QStandardItemModel>
#include <QMap>
Christoph Cullmann's avatar
Christoph Cullmann committed
31

32 33
class QDir;

Christoph Cullmann's avatar
Christoph Cullmann committed
34
/**
35 36
 * Class representing a project background worker.
 * This worker will build up the model for the project on load and do other stuff in the background.
Christoph Cullmann's avatar
Christoph Cullmann committed
37
 */
38
class KateProjectWorker : public QObject, public ThreadWeaver::Job
Christoph Cullmann's avatar
Christoph Cullmann committed
39
{
40
    Q_OBJECT
Christoph Cullmann's avatar
Christoph Cullmann committed
41

42
public:
Christoph Cullmann's avatar
Christoph Cullmann committed
43 44 45
    /**
     * Type for QueuedConnection
     */
46
    typedef QMap<QString, KateProjectItem *> MapString2Item;
47

48
    explicit KateProjectWorker(const QString &baseDir, const QString &indexDir, const QVariantMap &projectMap, bool force);
Christoph Cullmann's avatar
Christoph Cullmann committed
49

Kevin Funk's avatar
Kevin Funk committed
50
    void run(ThreadWeaver::JobPointer self, ThreadWeaver::Thread *thread) override;
51

52 53 54
Q_SIGNALS:
    void loadDone(KateProjectSharedQStandardItem topLevel, KateProjectSharedQMapStringItem file2Item);
    void loadIndexDone(KateProjectSharedProjectIndex index);
55 56

private:
Christoph Cullmann's avatar
Christoph Cullmann committed
57 58 59 60 61 62 63
    /**
     * Load one project inside the project tree.
     * Fill data from JSON storage to model and recurse to sub-projects.
     * @param parent parent standard item in the model
     * @param project variant map for this group
     * @param file2Item mapping file => item, will be filled
     */
64
    void loadProject(QStandardItem *parent, const QVariantMap &project, QMap<QString, KateProjectItem *> *file2Item);
Christoph Cullmann's avatar
Christoph Cullmann committed
65 66 67 68 69 70 71

    /**
     * Load one files entry in the current parent item.
     * @param parent parent standard item in the model
     * @param filesEntry one files entry specification to load
     * @param file2Item mapping file => item, will be filled
     */
72 73
    void loadFilesEntry(QStandardItem *parent, const QVariantMap &filesEntry, QMap<QString, KateProjectItem *> *file2Item);

74
    /**
75 76
     * Load index for whole project.
     * @param files list of all project files to index
77
     */
78
    void loadIndex(const QStringList &files, bool force);
79

80 81 82 83 84
    QStringList findFiles(const QDir &dir, const QVariantMap &filesEntry);

    QStringList filesFromGit(const QDir &dir, bool recursive);
    QStringList filesFromMercurial(const QDir &dir, bool recursive);
    QStringList filesFromSubversion(const QDir &dir, bool recursive);
85
    QStringList filesFromDarcs(const QDir &dir, bool recursive);
86 87
    QStringList filesFromDirectory(const QDir &dir, bool recursive, const QStringList &filters);

88 89
    QStringList gitLsFiles(const QDir &dir);

90
private:
Christoph Cullmann's avatar
Christoph Cullmann committed
91
    /**
Christoph Cullmann's avatar
Christoph Cullmann committed
92 93
     * our project, only as QObject, we only send messages back and forth!
     */
94
    QObject *m_project;
95

Christoph Cullmann's avatar
Christoph Cullmann committed
96
    /**
97
     * project base directory name
Christoph Cullmann's avatar
Christoph Cullmann committed
98
     */
99
    const QString m_baseDir;
100 101 102 103 104 105

    /**
     * index directory
     */
    const QString m_indexDir;

106
    const QVariantMap m_projectMap;
107
    const bool m_force;
Christoph Cullmann's avatar
Christoph Cullmann committed
108 109 110
};

#endif