1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
/* This file is part of the KDE project
Copyright (C) 2004 by Alexander Dymo <cloudtemple@mksat.net>
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.
*/
#ifndef TDEV_DOC_PLUGIN_H
#define TDEV_DOC_PLUGIN_H
#include <tqmap.h>
#include <tqvaluelist.h>
#include <tqpair.h>
#include <tdelistbox.h>
#include <tdelistview.h>
#include <kurl.h>
#include <tdefile.h>
#define CACHE_VERSION "3"
/**Documentation list item.
Stores the type of a documentation it represents and an URL.*/
class DocumentationItem: public TDEListViewItem
{
public:
/**Type of documentation which is represented by this item.*/
enum Type {
Collection /**<Collection - a collection of catalogs, folder with catalogs.*/,
Catalog /**<Catalog - a term which defines a document or a group of documents.*/,
Book /**<Book - a document with nested documents.*/,
Document /**<Document.*/
};
DocumentationItem(Type type, TDEListView *parent, const TQString &name);
DocumentationItem(Type type, TDEListView *parent, TDEListViewItem *after, const TQString &name);
DocumentationItem(Type type, TDEListViewItem *parent, const TQString &name);
DocumentationItem(Type type, TDEListViewItem *parent, TDEListViewItem *after, const TQString &name);
virtual void setURL(const KURL &url) { m_url = url; }
virtual KURL url() const { return m_url; }
Type type() const { return m_type; }
void setType(Type t) {
if(t != m_type) {
m_type = t;
init();
}
}
private:
void init();
KURL m_url;
Type m_type;
};
class DocumentationPlugin;
/**Documentation catalog list item.*/
class DocumentationCatalogItem: public DocumentationItem
{
public:
DocumentationCatalogItem(DocumentationPlugin* plugin, TDEListView *parent, const TQString &name);
DocumentationCatalogItem(DocumentationPlugin* plugin, DocumentationItem *parent, const TQString &name);
virtual ~DocumentationCatalogItem();
DocumentationPlugin* plugin() const { return m_plugin; }
virtual void setOpen(bool o);
void load();
virtual bool isProjectDocumentationItem() const { return m_isProjectDocumentationItem; }
virtual void setProjectDocumentationItem(bool b) { m_isProjectDocumentationItem = b; }
virtual TQString cacheVersion() const { return ""; } /// should return a short string that identifies the version of the catalog
protected:
virtual void activate();
private:
DocumentationPlugin* m_plugin;
bool isLoaded;
bool isActivated;
bool m_isProjectDocumentationItem;
};
class IndexBox;
/**Prototype of index item.
Prototypes represent an index are used to build index items after index generation.*/
class IndexItemProto
{
public:
IndexItemProto(DocumentationPlugin *plugin, DocumentationCatalogItem *catalog, IndexBox *listbox,
const TQString &text, const TQString &description);
~IndexItemProto();
void addURL(const KURL &url) { m_url = url; }
KURL url() const { return m_url; }
TQString text() const { return m_text; }
TQString description() const { return m_description; }
private:
KURL m_url;
IndexBox *m_listbox;
TQString m_text;
TQString m_description;
};
/**Documentation index item.*/
class IndexItem: public TQListBoxText {
public:
typedef TQPair<TQString, KURL> URL;
typedef TQValueList<URL> List;
IndexItem(IndexBox *listbox, const TQString &text);
List urls() const;
private:
IndexBox *m_listbox;
};
/**Documentation index view.*/
class IndexBox: public TDEListBox{
public:
IndexBox(TQWidget *parent = 0, const char *name = 0);
virtual void addIndexItem(IndexItemProto *item);
virtual void removeIndexItem(IndexItemProto *item);
virtual void fill();
virtual void refill();
virtual void setDirty(bool dirty);
// virtual void refill(TQValueList<IndexItemProto*> &items);
private:
TQMap<TQString, TQValueList<IndexItemProto*> > items;
friend class IndexItem;
bool m_dirty;
};
class TQPainter;
class TQColorGroup;
class TQFontMetrics;
class DocumentationPlugin;
/**Documentation configuration item.*/
class ConfigurationItem: public TQCheckListItem
{
public:
ConfigurationItem(TQListView *parent, DocumentationPlugin * plugin, const TQString &title, const TQString &url,
bool indexPossible, bool fullTextSearchPossible);
virtual TQString title() const { return m_title; }
virtual void setTitle(const TQString title) { setText(3, m_title = title); }
virtual TQString url() const { return m_url; }
virtual void setURL(const TQString url) { setText(4, m_url = url); }
virtual bool isChanged() const { return m_title == m_origTitle; }
virtual TQString origTitle() const {return m_origTitle; }
virtual void paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int align);
virtual int width(const TQFontMetrics &fm, const TQListView *lv, int c) const;
bool contents() const { return m_contents; }
void setContents(bool contents) { m_contents = contents; }
bool index() const { return m_index; }
void setIndex(bool index) { m_index = index; }
bool fullTextSearch() const { return m_fullTextSearch; }
void setFullTextSearch(bool fullTextSearch) { m_fullTextSearch = fullTextSearch; }
bool indexPossible() const { return m_indexPossible; }
bool fullTextSearchPossible() const { return m_fullTextSearchPossible; }
DocumentationPlugin * docPlugin() { return m_docPlugin; }
private:
TQString m_title;
TQString m_url;
TQString m_origTitle;
bool m_contents;
bool m_index;
bool m_fullTextSearch;
bool m_indexPossible;
bool m_fullTextSearchPossible;
DocumentationPlugin * m_docPlugin;
};
class ProjectDocumentationPlugin;
/**
@short Documentation Plugin Interface
All KDevelop documentation plugins must implement this interface.
Documentation plugin handles certain documentation type. It provides
methods to load documentation catalogs and indexes for a documentation
of that type. It also has methods to configure catalogs and provides
a list of URL's for the full text search tool.
*/
class DocumentationPlugin: public TQObject
{
Q_OBJECT
public:
/**Capability of documentation plugin.*/
enum Capability { Index=1 /**<index can be built for catalogs*/,
FullTextSearch=2 /**<full text search is possible in catalog locations*/,
CustomDocumentationTitles=4 /**<user can specify titles for documentation catalogs*/,
ProjectDocumentation=8 /**<plugin can handle project API documentation*/,
ProjectUserManual=16 /**<plugin can handle project user manual*/ };
/**Possible project documentation types.*/
enum ProjectDocType { APIDocs, UserManual };
/**Constructor. Should initialize capabilities of the plugin by using setCapabilities
protected method. For example,
@code
setCapabilities(Index | FullTextSearch);
@endcode
*/
DocumentationPlugin(TDEConfig *pluginConfig, TQObject *parent =0, const char *name =0);
virtual ~DocumentationPlugin();
/**Returns the i18n name of the plugin.*/
virtual TQString pluginName() const = 0;
/**Creates documentation catalog with given title and url.*/
virtual DocumentationCatalogItem *createCatalog(TDEListView *contents, const TQString &title, const TQString &url) = 0;
/**Initialize a list of catalogs.
@param contents the listview to fill with catalogs
*/
virtual void init(TDEListView *contents);
/**Reloads a list of catalogs. This method should add missing catalogs to the view,
update index for added catalogs and also delete restricted catalogs.
@param contents the listview to fill with catalogs
@param index the listbox with index to update
@param restrictions the list of catalogs names to remove
*/
virtual void reinit(TDEListView *contents, IndexBox *index, TQStringList restrictions);
/**Initializes plugin configuration. Documentation plugins should be able to
initialize the default configuration on startup without any user interaction.
Call this in the constructor of your plugin.*/
virtual void autoSetup();
/**Plugin specific automatic setup code. This method is called by @ref autoSetup.*/
virtual void autoSetupPlugin() = 0;
/**Indicates if a catalog with specified name is enabled. Documentation plugin
should check this and do not load catalogs disabled in configuration.
All catalogs are enabled by default.*/
virtual bool catalogEnabled(const TQString &name) const;
/**Enables or disables documentation catalog.*/
virtual void setCatalogEnabled(const TQString &name, bool e);
/**Indicates if an index of given catalog should be rebuilt. This method
is used by index caching algorythm to make a descision to rebuild index
or to load it from cache.*/
virtual bool needRefreshIndex(DocumentationCatalogItem *item) = 0;
/**Indicates if an index is enabled for given catalog. If documentation plugin
has Index capability, indices for it's catalogs can be enabled/disabled
in configuration dialog.*/
virtual bool indexEnabled(DocumentationCatalogItem *item) const;
/**Enables or disables index for documentation catalog.*/
virtual void setIndexEnabled(DocumentationCatalogItem *item, bool e);
/**Builds index for given catalog. This method should fill index with
IndexItem objects.
@param index the listbox which contains index items
@param item the catalog item that holds an index being built
*/
virtual void createIndex(IndexBox *index, DocumentationCatalogItem *item) = 0;
/**Creates a table of contents for given catalog. Documentation part uses
lazy loading of toc's to reduce startup time. This means that createTOC
will be called on expand event of catalog item.*/
virtual void createTOC(DocumentationCatalogItem *item) = 0;
/**Sets the URL to the catalog. This method will be called each time user
clicks the documentation item. If it is too much overhead to determine the
documentation catalog url in @ref createCatalog method then you can set it here.*/
virtual void setCatalogURL(DocumentationCatalogItem *item) = 0;
virtual TQStringList fullTextSearchLocations() = 0;
/**Loads catalog configuration and fills configurationView with ConfigurationItem objects.*/
virtual void loadCatalogConfiguration(TDEListView *configurationView);
/**Saves catalog configuration basing on configurationView and
deletedConfigurationItems contents. If you use TDEConfig to store configuration,
it is important that you call TDEConfig::sync() method after saving.*/
virtual void saveCatalogConfiguration(TDEListView *configurationView);
/**Adds new catalog to a configuration.*/
virtual void addCatalogConfiguration(TDEListView *configurationView,
const TQString &title, const TQString &url);
/**Edits catalog configuration.*/
virtual void editCatalogConfiguration(ConfigurationItem *configurationItem,
const TQString &title, const TQString &url);
/**Removes catalog from configuration. configurationItem should not be removed here.*/
virtual void deleteCatalogConfiguration(const ConfigurationItem *const configurationItem);
/**Returns a mode and a filter for catalog locator dialogs.*/
virtual TQPair<KFile::Mode, TQString> catalogLocatorProps() = 0;
/**Returns a title of catalog defined by an url parameter.*/
virtual TQString catalogTitle(const TQString &url) = 0;
/**Reloads documentation catalogs and indices.*/
virtual void reload();
/**Clears documentation catalogs and indices.*/
virtual void clear();
/**Checks if documentation plugin has given capability.*/
bool hasCapability(Capability cap) const { return m_capabilities & cap; }
/**Sets dirty flag for all indices. Index caching algorythm will update
the cache next time @ref createIndex is called.*/
void setDirtyIndex(bool dirty) { m_indexCreated = dirty; }
/**Caches index for documentation catalog. Reimplement this only if custom
caching algorythm is used (do not forget to reimplement also @ref loadCachedIndex
and @ref createIndex).*/
virtual void cacheIndex(DocumentationCatalogItem *item);
/**Loads index from the cache. Reimplement this only if custom
caching algorythm is used (do not forget to reimplement also @ref cacheIndex
and @ref createIndex).*/
virtual bool loadCachedIndex(IndexBox *index, DocumentationCatalogItem *item);
/**Returns associated project documentation plugin. Default implementation returns zero.
Reimplement this if the documentation plugin can also handle project documentation.*/
virtual ProjectDocumentationPlugin *projectDocumentationPlugin(ProjectDocType /* type */) { return 0; }
public slots:
/**Creates index and fills index listbox. Reimplement this only if custom
caching algorythm is used (do not forget to reimplement also @ref cacheIndex
and @ref loadCachedIndex).*/
virtual void createIndex(IndexBox *index);
protected:
/**A list of loaded documentation catalogs.*/
TQValueList<DocumentationCatalogItem*> catalogs;
/**A map of names of loaded documentation catalogs.*/
TQMap<TQString, DocumentationCatalogItem*> namedCatalogs;
/**A map of indices of loaded documentation catalogs.*/
TQMap<DocumentationCatalogItem*, TQValueList<IndexItemProto*> > indexes;
/**Sets capabilities of documentation plugin.*/
void setCapabilities(int caps) { m_capabilities = caps; }
/**Clears index of given catalog.*/
virtual void clearCatalogIndex(DocumentationCatalogItem *item);
/**Loads index from cache or creates and caches it if does not exist.*/
void loadIndex(IndexBox *index, DocumentationCatalogItem *item);
/**Stores items deleted from configuration. @ref saveCatalogConfiguration
uses this to remove entries from configuration file.*/
TQStringList deletedConfigurationItems;
/**Configuration object used by a plugin.*/
TDEConfig *config;
private:
/**Adds catalog item to catalogs, namedCatalogs and indexes lists and maps.*/
virtual void addCatalog(DocumentationCatalogItem *item);
/**Removes catalog item from catalogs, namedCatalogs and indexes lists and maps.*/
virtual void clearCatalog(DocumentationCatalogItem *item);
int m_capabilities;
bool m_indexCreated;
friend class IndexItemProto;
friend class DocumentationCatalogItem;
};
/**
@short Project documentation plugin
Represents functionality to display project documentation catalog and index in documentation browser.
*/
class ProjectDocumentationPlugin: public TQObject {
Q_OBJECT
public:
ProjectDocumentationPlugin(DocumentationPlugin *docPlugin, DocumentationPlugin::ProjectDocType type);
virtual ~ProjectDocumentationPlugin();
/**Initializes project documentation plugin - creates documentation catalog.*/
virtual void init(TDEListView *contents, IndexBox *index, const TQString &url);
/**Deinitializes project documentation plugin - removes documentation catalog.*/
virtual void deinit();
TQString pluginName() const;
TQString catalogURL() const;
public slots:
/**Performs reinitialization if project documentation has changed (after building api documentation).*/
virtual void reinit();
protected:
DocumentationPlugin *m_docPlugin;
DocumentationCatalogItem *m_catalog;
private:
DocumentationPlugin::ProjectDocType m_type;
class KDirWatch *m_watch;
class TDEListView *m_contents;
class IndexBox *m_index;
TQString m_url;
};
#endif
|