~ubuntu-branches/ubuntu/vivid/kate/vivid-updates

« back to all changes in this revision

Viewing changes to addons/kate/project/kateproject.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  This file is part of the Kate project.
2
 
 *
3
 
 *  Copyright (C) 2010 Christoph Cullmann <cullmann@kde.org>
4
 
 *
5
 
 *  This library is free software; you can redistribute it and/or
6
 
 *  modify it under the terms of the GNU Library General Public
7
 
 *  License as published by the Free Software Foundation; either
8
 
 *  version 2 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
 
 *  Library General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU Library General Public License
16
 
 *  along with this library; see the file COPYING.LIB.  If not, write to
17
 
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 
 *  Boston, MA 02110-1301, USA.
19
 
 */
20
 
 
21
 
#ifndef KATE_PROJECT_H
22
 
#define KATE_PROJECT_H
23
 
 
24
 
#include <QThread>
25
 
#include <QMap>
26
 
#include <QSharedPointer>
27
 
#include <QTextDocument>
28
 
#include <KTextEditor/ModificationInterface>
29
 
#include "kateprojectindex.h"
30
 
#include "kateprojectitem.h"
31
 
 
32
 
/**
33
 
 * Shared pointer data types.
34
 
 * Used to pass pointers over queued connected slots
35
 
 */
36
 
typedef QSharedPointer<QStandardItem> KateProjectSharedQStandardItem;
37
 
Q_DECLARE_METATYPE(KateProjectSharedQStandardItem)
38
 
 
39
 
typedef QSharedPointer<QMap<QString, KateProjectItem *> > KateProjectSharedQMapStringItem;
40
 
Q_DECLARE_METATYPE(KateProjectSharedQMapStringItem)
41
 
 
42
 
typedef QSharedPointer<KateProjectIndex> KateProjectSharedProjectIndex;
43
 
Q_DECLARE_METATYPE(KateProjectSharedProjectIndex)
44
 
 
45
 
/**
46
 
 * Private worker thread.
47
 
 * Will take care of worker object deletion.
48
 
 */
49
 
class KateProjectWorkerThread : public QThread
50
 
{
51
 
    public:
52
 
        /**
53
 
         * Construct thread for given worker
54
 
         */
55
 
        KateProjectWorkerThread (QObject *worker)
56
 
          : QThread()
57
 
          , m_worker (worker)
58
 
        {
59
 
        }
60
 
 
61
 
    protected:
62
 
        /**
63
 
         * start the thread event loop
64
 
         */
65
 
        virtual void run()
66
 
        {
67
 
            /**
68
 
             * run event loop
69
 
             */
70
 
            exec ();
71
 
 
72
 
            /**
73
 
             * kill worker in THIS thread
74
 
             */
75
 
            delete m_worker;
76
 
        }
77
 
 
78
 
    private:
79
 
        /**
80
 
         * Worker object
81
 
         */
82
 
        QObject *m_worker;
83
 
};
84
 
 
85
 
/**
86
 
 * Class representing a project.
87
 
 * Holds project properties like name, groups, contained files, ...
88
 
 */
89
 
class KateProject : public QObject
90
 
{
91
 
  Q_OBJECT
92
 
 
93
 
  public:
94
 
    /**
95
 
     * construct empty project
96
 
     */
97
 
    KateProject ();
98
 
 
99
 
    /**
100
 
     * deconstruct project
101
 
     */
102
 
    ~KateProject ();
103
 
 
104
 
    /**
105
 
     * Load a project.
106
 
     * Only works once, afterwards use reload().
107
 
     * @param fileName name of project file
108
 
     * @return success
109
 
     */
110
 
    bool load (const QString &fileName);
111
 
 
112
 
    /**
113
 
     * Try to reload a project.
114
 
     * If the reload fails, e.g. because the file is not readable or corrupt, nothing will happen!
115
 
     * @param force will enforce the worker to update files list and co even if the content of the file was not changed!
116
 
     * @return success
117
 
     */
118
 
    bool reload (bool force = false);
119
 
 
120
 
    /**
121
 
     * Accessor to file name.
122
 
     * @return file name
123
 
     */
124
 
    const QString &fileName () const
125
 
    {
126
 
      return m_fileName;
127
 
    }
128
 
   
129
 
    /**
130
 
     * Return the base directory of this project.
131
 
     * @return base directory of project, might not be the directory of the fileName!
132
 
     */
133
 
    const QString &baseDir () const
134
 
    {
135
 
      return m_baseDir;
136
 
    }
137
 
 
138
 
    /**
139
 
     * Accessor to project map containing the whole project info.
140
 
     * @return project info
141
 
     */
142
 
    const QVariantMap &projectMap () const
143
 
    {
144
 
      return m_projectMap;
145
 
    }
146
 
 
147
 
    /**
148
 
     * Accessor to project name.
149
 
     * @return project name
150
 
     */
151
 
    QString name () const
152
 
    {
153
 
      return m_projectMap["name"].toString ();
154
 
    }
155
 
 
156
 
    /**
157
 
     * Accessor for the model.
158
 
     * @return model of this project
159
 
     */
160
 
    QStandardItemModel *model ()
161
 
    {
162
 
      return &m_model;
163
 
    }
164
 
 
165
 
    /**
166
 
     * Flat list of all files in the project
167
 
     * @return list of files in project
168
 
     */
169
 
    QStringList files ()
170
 
    {
171
 
      return m_file2Item ? m_file2Item->keys () : QStringList ();
172
 
    }
173
 
 
174
 
    /**
175
 
     * get item for file
176
 
     * @param file file to get item for
177
 
     * @return item for given file or 0
178
 
     */
179
 
    KateProjectItem *itemForFile (const QString &file)
180
 
    {
181
 
      return m_file2Item ? m_file2Item->value (file) : 0;
182
 
    }
183
 
 
184
 
    /**
185
 
     * Access to project index.
186
 
     * May be null.
187
 
     * Don't store this pointer, might change.
188
 
     * @return project index
189
 
     */
190
 
    KateProjectIndex *projectIndex ()
191
 
    {
192
 
      return m_projectIndex.data();
193
 
    }
194
 
    
195
 
    /**
196
 
     * Will try to open a project local file.
197
 
     * Such files will be stored as .kateproject.d/file in the project directory.
198
 
     * @param file wanted file name, relative to .kateproject.d folder in project directory
199
 
     * @return either a pointer to a read-write opened file or null on error
200
 
     */
201
 
    QFile *projectLocalFile (const QString &file) const;
202
 
 
203
 
    /**
204
 
     * Document with project local notes.
205
 
     * Will be stored in a projectLocalFile "notes.txt".
206
 
     * @return notes document
207
 
     */
208
 
    QTextDocument *notesDocument ();
209
 
    
210
 
    /**
211
 
     * Save the notes document to "notes.txt" if any document around.
212
 
     */
213
 
    void saveNotesDocument ();
214
 
    
215
 
    /**
216
 
     * Register a document for this project.
217
 
     * @param document document to register
218
 
     */
219
 
    void registerDocument (KTextEditor::Document *document);
220
 
    
221
 
    /**
222
 
     * Unregister a document for this project.
223
 
     * @param document document to unregister
224
 
     */
225
 
    void unregisterDocument (KTextEditor::Document *document);
226
 
    
227
 
  private Q_SLOTS:
228
 
    /**
229
 
     * Used for worker to send back the results of project loading
230
 
     * @param topLevel new toplevel element for model
231
 
     * @param file2Item new file => item mapping
232
 
     */
233
 
    void loadProjectDone (KateProjectSharedQStandardItem topLevel, KateProjectSharedQMapStringItem file2Item);
234
 
 
235
 
    /**
236
 
     * Used for worker to send back the results of index loading
237
 
     * @param projectIndex new project index
238
 
     */
239
 
    void loadIndexDone (KateProjectSharedProjectIndex projectIndex);
240
 
 
241
 
    void slotModifiedChanged(KTextEditor::Document*);
242
 
    
243
 
    
244
 
    void slotModifiedOnDisk (KTextEditor::Document *document,
245
 
      bool isModified, KTextEditor::ModificationInterface::ModifiedOnDiskReason reason);
246
 
 
247
 
    
248
 
  signals:
249
 
    /**
250
 
     * Emitted on project map changes.
251
 
     * This includes the name!
252
 
     */
253
 
    void projectMapChanged ();
254
 
 
255
 
    /**
256
 
     * Emitted on model changes.
257
 
     * This includes the files list, itemForFile mapping!
258
 
     */
259
 
    void modelChanged ();
260
 
 
261
 
    /**
262
 
     * Emitted when the index creation is finished.
263
 
     * This includes the ctags index.
264
 
     */
265
 
    void indexChanged ();
266
 
 
267
 
  private:
268
 
    /**
269
 
     * the worker inside the background thread
270
 
     * if this is NULL, we are in our deconstruction state and should
271
 
     * ignore the feedback of our already stopped thread that
272
 
     * may still come in because of queued connects
273
 
     * only DELETE all stuff we need to cleanup in the slots
274
 
     */
275
 
    QObject *m_worker;
276
 
 
277
 
    /**
278
 
     * our internal thread to load stuff and do things in background
279
 
     */
280
 
    KateProjectWorkerThread m_thread;
281
 
 
282
 
    /**
283
 
     * project file name
284
 
     */
285
 
    QString m_fileName;
286
 
 
287
 
    /**
288
 
     * base directory of the project
289
 
     */
290
 
    QString m_baseDir;
291
 
 
292
 
    /**
293
 
     * project name
294
 
     */
295
 
    QString m_name;
296
 
 
297
 
    /**
298
 
     * variant map representing the project
299
 
     */
300
 
    QVariantMap m_projectMap;
301
 
 
302
 
    /**
303
 
     * standard item model with content of this project
304
 
     */
305
 
    QStandardItemModel m_model;
306
 
 
307
 
    /**
308
 
     * mapping files => items
309
 
     */
310
 
    KateProjectSharedQMapStringItem m_file2Item;
311
 
 
312
 
    /**
313
 
     * project index, if any
314
 
     */
315
 
    KateProjectSharedProjectIndex m_projectIndex;
316
 
    
317
 
    /**
318
 
     * notes buffer for project local notes
319
 
     */
320
 
    QTextDocument *m_notesDocument;
321
 
    
322
 
    /**
323
 
     * Set of existing documents for this project.
324
 
     */
325
 
    QMap<KTextEditor::Document *, QString> m_documents;
326
 
    
327
 
    /**
328
 
     * Parent item for existing documents that are not in the project tree
329
 
     */
330
 
    QStandardItem *m_documentsParent;
331
 
};
332
 
 
333
 
#endif
334
 
 
335
 
// kate: space-indent on; indent-width 2; replace-tabs on;