19 #include "kdevdocumentationplugin.h" 22 #include <tqpainter.h> 25 #include <tqtextstream.h> 27 #include <kstandarddirs.h> 28 #include <kiconloader.h> 29 #include <tdeconfig.h> 31 #include <kdirwatch.h> 32 #include <tdelocale.h> 38 :TDEListViewItem(parent, name), m_type(type)
45 :TDEListViewItem(parent, name), m_type(type)
51 TDEListViewItem *after,
const TQString &name)
52 :TDEListViewItem(parent, after, name), m_type(type)
58 TDEListViewItem * after,
const TQString & name )
59 :TDEListViewItem(parent, after, name), m_type(type)
64 void DocumentationItem::init( )
78 icon =
"text-x-generic";
81 setPixmap(0, SmallIcon(icon));
89 TDEListView *parent, TDEListViewItem *after,
const TQString &name)
91 isLoaded(false), isActivated(false), m_isProjectDocumentationItem(false)
94 m_plugin->addCatalog(
this);
100 isLoaded(false), isActivated(false), m_isProjectDocumentationItem(false)
103 m_plugin->addCatalog(
this);
106 DocumentationCatalogItem::~DocumentationCatalogItem()
108 m_plugin->clearCatalog(
this);
111 void DocumentationCatalogItem::setOpen(
bool o)
117 DocumentationItem::setOpen(o);
120 void DocumentationCatalogItem::load()
136 DocumentationItem::activate();
144 IndexBox *listbox,
const TQString &text,
const TQString &description)
145 : m_listbox(listbox), m_text(text), m_description(description)
147 plugin->
indexes[catalog].append(
this);
148 m_listbox->addIndexItem(
this);
151 IndexItemProto::~IndexItemProto()
153 m_listbox->removeIndexItem(
this);
160 IndexItem::IndexItem(
IndexBox *listbox,
const TQString &text)
161 :TQListBoxText(listbox, text), m_listbox(listbox)
165 IndexItem::List IndexItem::urls()
const 168 TQValueList<IndexItemProto*> itemProtos = m_listbox->items[text()];
169 for (TQValueList<IndexItemProto*>::const_iterator it = itemProtos.begin();
170 it != itemProtos.end(); ++it)
171 urlList.append(tqMakePair((*it)->description(), (*it)->url()));
179 ConfigurationItem::ConfigurationItem(TQListView *parent,
DocumentationPlugin * plugin,
const TQString &title,
const TQString &url,
180 bool indexPossible,
bool fullTextSearchPossible)
181 :TQCheckListItem(parent,
"", TQCheckListItem::CheckBox), m_title(title), m_url(url),
182 m_origTitle(title), m_contents(
true), m_index(
false), m_fullTextSearch(
false),
183 m_indexPossible(indexPossible), m_fullTextSearchPossible(fullTextSearchPossible),
184 m_docPlugin( plugin )
190 void ConfigurationItem::paintCell(TQPainter *p,
const TQColorGroup &cg,
int column,
191 int width,
int align)
193 if ( (column == 0) || (column == 1) || (column == 2) )
198 TQListView *lv = listView();
202 const BackgroundMode bgmode = lv->viewport()->backgroundMode();
203 const TQColorGroup::ColorRole crole = TQPalette::backgroundRoleFromMode( bgmode );
204 p->fillRect(0, 0, width, height(), cg.brush(crole));
206 TQFontMetrics fm(lv->fontMetrics());
207 int boxsize = lv->style().pixelMetric(TQStyle::PM_CheckListButtonSize, lv);
208 int marg = lv->itemMargin();
209 int styleflags = TQStyle::Style_Default;
211 if (((column == 0) && m_contents) || ((column == 1) && m_index) || ((column == 2) && m_fullTextSearch))
212 styleflags |= TQStyle::Style_On;
214 styleflags |= TQStyle::Style_Off;
215 if ((column == 0) || ((column == 1) && m_indexPossible) || ((column == 2) && m_fullTextSearchPossible))
216 styleflags |= TQStyle::Style_Enabled;
221 if (align & AlignVCenter)
222 y = ((height() - boxsize) / 2) + marg;
224 y = (fm.height() + 2 + marg - boxsize) / 2;
226 TQStyleOption opt(
this);
227 lv->style().tqdrawPrimitive(TQStyle::PE_CheckListIndicator, p,
228 TQRect(x, y, boxsize, fm.height() + 2 + marg), cg, styleflags, opt);
232 TQListViewItem::paintCell(p, cg, column, width, align);
235 int ConfigurationItem::width(
const TQFontMetrics &fm,
const TQListView *lv,
int c)
const 237 if ((c == 0) || (c == 1) || (c == 2))
238 return lv->style().pixelMetric(TQStyle::PM_CheckListButtonSize, lv) + 4;
239 return TQListViewItem::width(fm, lv, c);
247 :TQObject(parent, name), config(pluginConfig), m_indexCreated(false)
251 DocumentationPlugin::~DocumentationPlugin()
257 config->setGroup(
"General");
258 if ( !
config->readBoolEntry(
"Autosetup",
false) )
261 config->setGroup(
"General");
262 config->writeEntry(
"Autosetup",
true);
271 for (TQValueList<DocumentationCatalogItem *>::iterator it =
catalogs.begin();
274 if (!(*it)->isProjectDocumentationItem())
289 for (TQMap<TQString, DocumentationCatalogItem*>::iterator it =
namedCatalogs.begin();
292 if (it.data() == item)
299 TQValueList<IndexItemProto *> idx =
indexes[item];
300 for (TQValueList<IndexItemProto *>::iterator it = idx.begin(); it != idx.end(); ++it)
314 for (TQValueList<DocumentationCatalogItem *>::iterator it =
catalogs.begin();
319 m_indexCreated =
true;
324 kdDebug() <<
"Creating index cache for " << item->text(0) << endl;
326 TQString cacheName = locateLocal(
"data", TQString(
"kdevdocumentation/index/cache_") + item->text(0));
327 TQFile cacheFile(cacheName);
328 if (!cacheFile.open(IO_WriteOnly))
331 TQTextStream str(&cacheFile);
332 str.setEncoding(TQTextStream::Unicode);
333 str << CACHE_VERSION << endl;
335 TQValueList<IndexItemProto*> catalogIndexes =
indexes[item];
336 for (TQValueList<IndexItemProto*>::const_iterator it = catalogIndexes.constBegin();
337 it != catalogIndexes.constEnd(); ++it)
339 str << (*it)->text() << endl;
340 str << (*it)->description() << endl;
341 str << (*it)->url().url() << endl;
349 TQString cacheName = locateLocal(
"data", TQString(
"kdevdocumentation/index/cache_") + item->cacheVersion() + item->text(0));
350 TQFile cacheFile(cacheName);
351 if (!cacheFile.open(IO_ReadOnly))
354 kdDebug() <<
"Using cached index for item: " << item->text(0) << endl;
356 TQTextStream str(&cacheFile);
357 str.setEncoding(TQTextStream::Unicode);
358 TQString cache = str.read();
359 TQStringList cacheList = TQStringList::split(
"\n", cache,
true);
360 TQString ver = cacheList.first();
361 if (ver != CACHE_VERSION)
363 kdDebug() <<
"Wrong cache version: " << ver << endl;
366 TQStringList::const_iterator it = cacheList.begin();
368 TQString s[3];
int c = 0;
369 for (; it != cacheList.end(); ++it)
375 ii->addURL(KURL(s[2]));
393 const TQString &title,
const TQString &url)
400 const TQString &title,
const TQString &url)
402 configurationItem->setTitle(title);
403 configurationItem->setURL(url);
414 TQValueList<IndexItemProto *> idx =
indexes[item];
415 for (TQValueList<IndexItemProto *>::iterator it = idx.begin(); it != idx.end(); ++it)
434 TDEListViewItem *curr_item = (TDEListViewItem*)(contents->firstChild());
438 TDEListViewItem *prev_item = NULL;
439 while (curr_item && curr_item->text(0) <= key)
441 prev_item = curr_item;
442 curr_item = (TDEListViewItem*)(curr_item->nextSibling());
449 config->setGroup(
"Locations");
450 TQMap<TQString, TQString> entryMap =
config->entryMap(
"Locations");
452 for (TQMap<TQString, TQString>::const_iterator it = entryMap.begin();
453 it != entryMap.end(); ++it)
455 TQString cat_key = it.key();
469 config->setGroup(
"Locations");
470 TQMap<TQString, TQString> entryMap =
config->entryMap(
"Locations");
482 for (TQMap<TQString, TQString>::const_iterator it = entryMap.begin();
483 it != entryMap.end(); ++it)
485 config->setGroup(
"Locations");
486 TQString cat_key = it.key();
494 kdDebug() <<
"updating 1" << endl;
500 index->setDirty(
true);
505 kdDebug() <<
" updating: clearCatalogIndex" << endl;
511 kdDebug() <<
" index requested " << endl;
513 index->setDirty(
true);
515 m_indexCreated =
true;
522 config->setGroup(
"Locations");
523 TQMap<TQString, TQString> entryMap =
config->entryMap(
"Locations");
525 for (TQMap<TQString, TQString>::const_iterator it = entryMap.begin();
526 it != entryMap.end(); ++it)
532 config->setGroup(
"Locations");
534 config->readPathEntry(it.key()),
536 config->setGroup(
"TOC Settings");
537 item->setContents(
config->readBoolEntry(item->title(),
true));
538 config->setGroup(
"Index Settings");
539 item->setIndex(
config->readBoolEntry(item->title(),
false));
540 config->setGroup(
"Search Settings");
541 item->setFullTextSearch(
config->readBoolEntry(item->title(),
false));
551 config->setGroup(
"Locations");
553 config->setGroup(
"TOC Settings");
555 config->setGroup(
"Index Settings");
557 config->setGroup(
"Search Settings");
561 TQListViewItemIterator it(configurationView);
565 if ( confItem->docPlugin() != this )
571 config->setGroup(
"Locations");
572 if (confItem->isChanged())
573 config->deleteEntry(confItem->origTitle());
574 config->writePathEntry(confItem->title(), confItem->url());
576 config->setGroup(
"TOC Settings");
577 if (confItem->isChanged())
578 config->deleteEntry(confItem->origTitle());
579 config->writeEntry(confItem->title(), confItem->contents());
581 config->setGroup(
"Index Settings");
582 if (confItem->isChanged())
583 config->deleteEntry(confItem->origTitle());
584 config->writeEntry(confItem->title(), confItem->index());
586 config->setGroup(
"Search Settings");
587 if (confItem->isChanged())
588 config->deleteEntry(confItem->origTitle());
589 config->writeEntry(confItem->title(), confItem->fullTextSearch());
598 TQString group =
config->group();
599 config->setGroup(
"Index Settings");
600 config->writeEntry(item->text(0), e);
606 TQString group =
config->group();
607 config->setGroup(
"Index Settings");
608 bool b =
config->readBoolEntry(item->text(0),
false);
615 TQString group =
config->group();
616 config->setGroup(
"TOC Settings");
617 bool b =
config->readBoolEntry(name,
true);
624 TQString group =
config->group();
625 config->setGroup(
"TOC Settings");
626 config->writeEntry(name, e);
634 IndexBox::IndexBox(TQWidget *parent,
const char *name)
635 :TDEListBox(parent, name), m_dirty(
false)
641 items[item->text()].append(item);
646 TQString text = item->text();
647 items[text].remove(item);
648 if (items[text].count() == 0)
651 TQListBoxItem *item = findItem(text, TQt::CaseSensitive | TQt::ExactMatch);
657 void IndexBox::fill()
659 for (TQMap<TQString, TQValueList<IndexItemProto*> >::const_iterator it = items.begin();
660 it != items.end(); ++it)
666 void IndexBox::setDirty(
bool dirty)
671 void IndexBox::refill()
683 :TQObject(0, 0), m_docPlugin(docPlugin), m_catalog(0), m_type(type), m_contents(0), m_index(0)
685 kdDebug() <<
"ProjectDocumentationPlugin::ProjectDocumentationPlugin for type " << type << endl;
687 m_watch =
new KDirWatch(
this);
688 connect(m_watch, TQT_SIGNAL(dirty(
const TQString&)),
this, TQT_SLOT(
reinit()));
689 m_watch->startScan();
692 ProjectDocumentationPlugin::~ProjectDocumentationPlugin()
699 TDEListViewItem *curr_item = (TDEListViewItem*)(contents->firstChild());
703 TDEListViewItem *prev_item = NULL;
704 while (curr_item && curr_item->text(0) <= key)
706 prev_item = curr_item;
707 curr_item = (TDEListViewItem*)(curr_item->nextSibling());
714 m_contents = contents;
720 TQString cat_key = (m_type == DocumentationPlugin::APIDocs ? i18n(
"Project API Documentation")
721 : i18n(
"Project User Manual"));
723 m_catalog = m_docPlugin->createCatalog(contents, afterItem, cat_key, url);
726 m_catalog->setProjectDocumentationItem(
true);
727 m_watch->addFile(url);
734 if (m_contents != 0 && m_index != 0 && m_url != 0)
735 init(m_contents, m_index, m_url);
740 m_watch->removeFile(m_url);
748 TQString ProjectDocumentationPlugin::pluginName()
const 750 return m_docPlugin->pluginName();
753 TQString ProjectDocumentationPlugin::catalogURL()
const 758 #include "kdevdocumentationplugin.moc" Book - a document with nested documents.
virtual void reinit(TDEListView *contents, IndexBox *index, TQStringList restrictions)
Reloads a list of catalogs.
virtual void addCatalogConfiguration(TDEListView *configurationView, const TQString &title, const TQString &url)
Adds new catalog to a configuration.
virtual void setIndexEnabled(DocumentationCatalogItem *item, bool e)
Enables or disables index for documentation catalog.
TQMap< TQString, DocumentationCatalogItem * > namedCatalogs
A map of names of loaded documentation catalogs.
virtual void setCatalogURL(DocumentationCatalogItem *item)=0
Sets the URL to the catalog.
virtual void activate()
should return a short string that identifies the version of the catalog
Documentation index item.
void loadIndex(IndexBox *index, DocumentationCatalogItem *item)
Loads index from cache or creates and caches it if does not exist.
full text search is possible in catalog locations
TDEConfig * config
Configuration object used by a plugin.
Collection - a collection of catalogs, folder with catalogs.
Documentation catalog list item.
virtual void init(TDEListView *contents)
Initialize a list of catalogs.
virtual void clear()
Clears documentation catalogs and indices.
Documentation configuration item.
virtual void deleteCatalogConfiguration(const ConfigurationItem *const configurationItem)
Removes catalog from configuration.
virtual void clearCatalogIndex(DocumentationCatalogItem *item)
Clears index of given catalog.
virtual DocumentationCatalogItem * createCatalog(TDEListView *contents, TDEListViewItem *after, const TQString &title, const TQString &url)=0
Creates documentation catalog with given title and url.
virtual void autoSetup()
Initializes plugin configuration.
virtual void editCatalogConfiguration(ConfigurationItem *configurationItem, const TQString &title, const TQString &url)
Edits catalog configuration.
virtual void setCatalogEnabled(const TQString &name, bool e)
Enables or disables documentation catalog.
TQValueList< DocumentationCatalogItem * > catalogs
A list of loaded documentation catalogs.
virtual bool needRefreshIndex(DocumentationCatalogItem *item)=0
Indicates if an index of given catalog should be rebuilt.
bool hasCapability(Capability cap) const
Checks if documentation plugin has given capability.
TQStringList deletedConfigurationItems
Stores items deleted from configuration.
TDEListViewItem * findCatalogPosition(const TQString &key, const TDEListView *contents) const
Find catalog insert position to maintain a sorted order.
virtual void createTOC(DocumentationCatalogItem *item)=0
Creates a table of contents for given catalog.
TQMap< DocumentationCatalogItem *, TQValueList< IndexItemProto * > > indexes
A map of indices of loaded documentation catalogs.
virtual void loadCatalogConfiguration(TDEListView *configurationView)
Loads catalog configuration and fills configurationView with ConfigurationItem objects.
virtual bool catalogEnabled(const TQString &name) const
Indicates if a catalog with specified name is enabled.
Documentation index view.
virtual void cacheIndex(DocumentationCatalogItem *item)
Caches index for documentation catalog.
virtual void createIndex(IndexBox *index, DocumentationCatalogItem *item)=0
Builds index for given catalog.
virtual void reinit()
Performs reinitialization if project documentation has changed (after building api documentation)...
ProjectDocType
Possible project documentation types.
Documentation Plugin Interface.
virtual void init(TDEListView *contents, IndexBox *index, const TQString &url)
Initializes project documentation plugin - creates documentation catalog.
Type
Type of documentation which is represented by this item.
index can be built for catalogs
virtual void saveCatalogConfiguration(TDEListView *configurationView)
Saves catalog configuration basing on configurationView and deletedConfigurationItems contents...
virtual void autoSetupPlugin()=0
Plugin specific automatic setup code.
TDEListViewItem * findCatalogPosition(const TQString &key, const TDEListView *contents) const
Find catalog insert position to maintain a sorted order.
virtual bool loadCachedIndex(IndexBox *index, DocumentationCatalogItem *item)
Loads index from the cache.
Catalog - a term which defines a document or a group of documents.
DocumentationPlugin(TDEConfig *pluginConfig, TQObject *parent=0, const char *name=0)
Constructor.
virtual bool indexEnabled(DocumentationCatalogItem *item) const
Indicates if an index is enabled for given catalog.
virtual void deinit()
Deinitializes project documentation plugin - removes documentation catalog.