1
/* This file is part of the Kate project.
3
* Copyright (C) 2010 Christoph Cullmann <cullmann@kde.org>
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.
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.
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.
21
#ifndef KATE_PROJECT_H
22
#define KATE_PROJECT_H
26
#include <QSharedPointer>
27
#include <QTextDocument>
28
#include <KTextEditor/ModificationInterface>
29
#include "kateprojectindex.h"
30
#include "kateprojectitem.h"
33
* Shared pointer data types.
34
* Used to pass pointers over queued connected slots
36
typedef QSharedPointer<QStandardItem> KateProjectSharedQStandardItem;
37
Q_DECLARE_METATYPE(KateProjectSharedQStandardItem)
39
typedef QSharedPointer<QMap<QString, KateProjectItem *> > KateProjectSharedQMapStringItem;
40
Q_DECLARE_METATYPE(KateProjectSharedQMapStringItem)
42
typedef QSharedPointer<KateProjectIndex> KateProjectSharedProjectIndex;
43
Q_DECLARE_METATYPE(KateProjectSharedProjectIndex)
46
* Private worker thread.
47
* Will take care of worker object deletion.
49
class KateProjectWorkerThread : public QThread
53
* Construct thread for given worker
55
KateProjectWorkerThread (QObject *worker)
63
* start the thread event loop
73
* kill worker in THIS thread
86
* Class representing a project.
87
* Holds project properties like name, groups, contained files, ...
89
class KateProject : public QObject
95
* construct empty project
100
* deconstruct project
106
* Only works once, afterwards use reload().
107
* @param fileName name of project file
110
bool load (const QString &fileName);
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!
118
bool reload (bool force = false);
121
* Accessor to file name.
124
const QString &fileName () const
130
* Return the base directory of this project.
131
* @return base directory of project, might not be the directory of the fileName!
133
const QString &baseDir () const
139
* Accessor to project map containing the whole project info.
140
* @return project info
142
const QVariantMap &projectMap () const
148
* Accessor to project name.
149
* @return project name
151
QString name () const
153
return m_projectMap["name"].toString ();
157
* Accessor for the model.
158
* @return model of this project
160
QStandardItemModel *model ()
166
* Flat list of all files in the project
167
* @return list of files in project
171
return m_file2Item ? m_file2Item->keys () : QStringList ();
176
* @param file file to get item for
177
* @return item for given file or 0
179
KateProjectItem *itemForFile (const QString &file)
181
return m_file2Item ? m_file2Item->value (file) : 0;
185
* Access to project index.
187
* Don't store this pointer, might change.
188
* @return project index
190
KateProjectIndex *projectIndex ()
192
return m_projectIndex.data();
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
201
QFile *projectLocalFile (const QString &file) const;
204
* Document with project local notes.
205
* Will be stored in a projectLocalFile "notes.txt".
206
* @return notes document
208
QTextDocument *notesDocument ();
211
* Save the notes document to "notes.txt" if any document around.
213
void saveNotesDocument ();
216
* Register a document for this project.
217
* @param document document to register
219
void registerDocument (KTextEditor::Document *document);
222
* Unregister a document for this project.
223
* @param document document to unregister
225
void unregisterDocument (KTextEditor::Document *document);
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
233
void loadProjectDone (KateProjectSharedQStandardItem topLevel, KateProjectSharedQMapStringItem file2Item);
236
* Used for worker to send back the results of index loading
237
* @param projectIndex new project index
239
void loadIndexDone (KateProjectSharedProjectIndex projectIndex);
241
void slotModifiedChanged(KTextEditor::Document*);
244
void slotModifiedOnDisk (KTextEditor::Document *document,
245
bool isModified, KTextEditor::ModificationInterface::ModifiedOnDiskReason reason);
250
* Emitted on project map changes.
251
* This includes the name!
253
void projectMapChanged ();
256
* Emitted on model changes.
257
* This includes the files list, itemForFile mapping!
259
void modelChanged ();
262
* Emitted when the index creation is finished.
263
* This includes the ctags index.
265
void indexChanged ();
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
278
* our internal thread to load stuff and do things in background
280
KateProjectWorkerThread m_thread;
288
* base directory of the project
298
* variant map representing the project
300
QVariantMap m_projectMap;
303
* standard item model with content of this project
305
QStandardItemModel m_model;
308
* mapping files => items
310
KateProjectSharedQMapStringItem m_file2Item;
313
* project index, if any
315
KateProjectSharedProjectIndex m_projectIndex;
318
* notes buffer for project local notes
320
QTextDocument *m_notesDocument;
323
* Set of existing documents for this project.
325
QMap<KTextEditor::Document *, QString> m_documents;
328
* Parent item for existing documents that are not in the project tree
330
QStandardItem *m_documentsParent;
335
// kate: space-indent on; indent-width 2; replace-tabs on;