KDevelop API Documentation

documentation_part.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Alexander Dymo                                  *
00003  *   cloudtemple@mksat.net                                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #include "documentation_part.h"
00021 
00022 #include <unistd.h>
00023 
00024 #include <qdir.h>
00025 #include <qwhatsthis.h>
00026 #include <qlayout.h>
00027 #include <qpopupmenu.h>
00028 #include <qtabwidget.h>
00029 #include <qapplication.h>
00030 
00031 #include <kapplication.h>
00032 #include <dcopclient.h>
00033 #include <kiconloader.h>
00034 #include <klocale.h>
00035 #include <kaboutdata.h>
00036 #include <ktrader.h>
00037 #include <kdebug.h>
00038 #include <kparts/componentfactory.h>
00039 #include <kservice.h>
00040 #include <kdialogbase.h>
00041 #include <kaction.h>
00042 #include <kactionclasses.h>
00043 #include <kbookmark.h>
00044 #include <kbookmarkmenu.h>
00045 #include <kinputdialog.h>
00046 #include <kstringhandler.h>
00047 #include <kconfig.h>
00048 #include <kwin.h>
00049 
00050 #include "kdevcore.h"
00051 #include "kdevproject.h"
00052 #include "kdevmainwindow.h"
00053 #include "kdevgenericfactory.h"
00054 #include "kdevdocumentationplugin.h"
00055 #include "configwidgetproxy.h"
00056 #include "kdevpartcontroller.h"
00057 #include "domutil.h"
00058 #include "urlutil.h"
00059 
00060 #include "documentation_widget.h"
00061 #include "docglobalconfigwidget.h"
00062 #include "docprojectconfigwidget.h"
00063 #include "contentsview.h"
00064 #include "find_documentation.h"
00065 
00066 #include "KDevDocumentationIface.h"
00067 
00068 #define GLOBALDOC_OPTIONS 1
00069 #define PROJECTDOC_OPTIONS 2
00070 
00071 static const KAboutData data("kdevdocumentation", I18N_NOOP("Documentation"), "1.0");
00072 
00073 typedef KDevGenericFactory<DocumentationPart> DocumentationFactory;
00074 K_EXPORT_COMPONENT_FACTORY( libkdevdocumentation, DocumentationFactory( &data ) );
00075 
00076 DocumentationPart::DocumentationPart(QObject *parent, const char *name, const QStringList& )
00077     :KDevPlugin("Documentation", "khelpcenter", parent, name ? name : "DocumentationPart" ),
00078     m_projectDocumentationPlugin(0), m_userManualPlugin(0), m_hasIndex(false)
00079 {
00080     setInstance(DocumentationFactory::instance());
00081     setXMLFile("kdevpart_documentation.rc");
00082 
00083     m_configProxy = new ConfigWidgetProxy(core());
00084     m_configProxy->createGlobalConfigPage(i18n("Documentation"), GLOBALDOC_OPTIONS, icon() );
00085     m_configProxy->createProjectConfigPage(i18n("Project Documentation"), PROJECTDOC_OPTIONS, icon() );
00086     connect(m_configProxy, SIGNAL(insertConfigWidget(const KDialogBase*, QWidget*, unsigned int )), this, SLOT(insertConfigWidget(const KDialogBase*, QWidget*, unsigned int)));
00087     connect(core(), SIGNAL(contextMenu(QPopupMenu *, const Context *)),
00088         this, SLOT(contextMenu(QPopupMenu *, const Context *)));
00089     connect(core(), SIGNAL(projectOpened()), this, SLOT(projectOpened()));
00090     connect(core(), SIGNAL(projectClosed()), this, SLOT(projectClosed()));
00091 
00092     m_widget = new DocumentationWidget(this);
00093     m_widget->setIcon(SmallIcon( icon() ));
00094     m_widget->setCaption(i18n("Documentation"));
00095 
00096     QWhatsThis::add(m_widget, i18n("<b>Documentation browser</b><p>"
00097         "The documentation browser gives access to various "
00098         "documentation sources (Qt DCF, Doxygen, KDoc, KDevelopTOC and DevHelp "
00099         "documentation) and the KDevelop manuals. It also provides documentation index "
00100         "and full text search capabilities."));
00101 
00102     mainWindow()->embedSelectViewRight(m_widget, i18n("Documentation"),
00103         i18n("Documentation browser"));
00104     
00105     setupActions();
00106     
00107     loadDocumentationPlugins();
00108     
00109     new KDevDocumentationIface(this);
00110 
00111     loadSettings();
00112 }
00113 
00114 DocumentationPart::~DocumentationPart()
00115 {
00116     if ( m_widget )
00117     {
00118         mainWindow()->removeView( m_widget );
00119     }
00120     delete m_widget;
00121 }
00122 
00123 void DocumentationPart::loadDocumentationPlugins()
00124 {
00125     KTrader::OfferList docPluginOffers =
00126         KTrader::self()->query(QString::fromLatin1("KDevelop/DocumentationPlugins"));
00127 
00128     KTrader::OfferList::ConstIterator serviceIt = docPluginOffers.begin();
00129     for ( ; serviceIt != docPluginOffers.end(); ++serviceIt )
00130     {               
00131         KService::Ptr docPluginService;
00132         docPluginService = *serviceIt;
00133         kdDebug() << "DocumentationPart::loadDocumentationPlugins: creating plugin" 
00134             << docPluginService->name() << endl;
00135         
00136         int error;
00137         DocumentationPlugin *docPlugin = KParts::ComponentFactory
00138             ::createInstanceFromService<DocumentationPlugin>(docPluginService, 0,
00139             docPluginService->name().latin1(), QStringList(), &error);
00140         if (!docPlugin)
00141             kdDebug() << "    failed to create doc plugin " << docPluginService->name() << endl;
00142         else
00143         {
00144             kdDebug() << "    success" << endl;
00145             docPlugin->init(m_widget->contents());
00146             connect(this, SIGNAL(indexSelected(IndexBox* )), docPlugin, SLOT(createIndex(IndexBox* )));
00147             m_plugins.append(docPlugin);
00148         }
00149     }
00150 }
00151 
00152 void DocumentationPart::emitIndexSelected(IndexBox *indexBox)
00153 {
00154     if (!m_hasIndex)
00155     {
00156         QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
00157         emit indexSelected(indexBox);
00158         indexBox->fill();
00159         m_hasIndex = true;
00160         QApplication::restoreOverrideCursor();
00161     }
00162 }
00163 
00164 void DocumentationPart::insertConfigWidget(const KDialogBase *dlg, QWidget *page, unsigned int pageNo)
00165 {
00166     switch (pageNo)
00167     {
00168         case GLOBALDOC_OPTIONS:
00169         {
00170             DocGlobalConfigWidget *w1 = new DocGlobalConfigWidget(this, m_widget, page, "doc config widget");
00171             connect(dlg, SIGNAL(okClicked()), w1, SLOT(accept()));
00172             break;
00173         }
00174         case PROJECTDOC_OPTIONS:
00175         {
00176             DocProjectConfigWidget *w1 = new DocProjectConfigWidget(this, page, "doc project config");
00177             connect(dlg, SIGNAL(okClicked()), w1, SLOT(accept()));
00178             break;
00179         }
00180     }
00181 }
00182 
00183 KConfig *DocumentationPart::config()
00184 {
00185     return DocumentationFactory::instance()->config();
00186 }
00187 
00188 bool DocumentationPart::configure(int page)
00189 {
00190     KDialogBase dlg(KDialogBase::Plain, i18n("Documentation Settings"),
00191                     KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, m_widget,
00192                     "docsettings dialog");
00193 
00194     QVBoxLayout *l = new QVBoxLayout(dlg.plainPage(), 0, 0);
00195     DocGlobalConfigWidget *w1 = new DocGlobalConfigWidget(this, m_widget, dlg.plainPage());
00196     l->addWidget(w1);
00197     w1->docTab->setCurrentPage(page);
00198     connect(&dlg, SIGNAL(okClicked()), w1, SLOT(accept()));
00199     return (dlg.exec() == QDialog::Accepted);
00200 }
00201 
00202 void DocumentationPart::setupActions()
00203 {
00204 /*    KActionMenu *menu = new KActionMenu(i18n("&Bookmarks"), actionCollection(), "doc_bookmarks");
00205     KBookmarkMenu *bm = new KBookmarkMenu(new DocBookmarkManager(this),
00206         new DocBookmarkOwner(this), menu->popupMenu(), actionCollection(), true);*/
00207     KAction *action;
00208 
00209     action = new KAction(i18n("&Search in Documentation..."), CTRL+ALT+Key_S,
00210                          this, SLOT(searchInDocumentation()),
00211                          actionCollection(), "help_search_in_doc" );
00212     action->setToolTip(i18n("Full text search in the documentation"));
00213     action->setWhatsThis(i18n("<b>Search in documentation</b><p>"
00214                               "Opens the Search in documentation tab. It allows "
00215                               "a search term to be entered which will be searched for in "
00216                               "the documentation. For this to work, a "
00217                               "full text index must be created first, which can be done in the "
00218                               "configuration dialog of the documentation plugin."));    
00219     action = new KAction(i18n("&Look in Documentation Index..."), CTRL+ALT+Key_I,
00220                          this, SLOT(lookInDocumentationIndex()),
00221                          actionCollection(), "help_look_in_index" );
00222     action->setToolTip(i18n("Look in the documentation index"));
00223     action->setWhatsThis(i18n("<b>Look in documentation index</b><p>"
00224                               "Opens the documentation index tab. It allows "
00225                               "a term to be entered which will be looked for in "
00226                               "the documentation index."));    
00227     action = new KAction(i18n("Man Page..."), 0,
00228                          this, SLOT(manPage()),
00229                          actionCollection(), "help_manpage" );
00230     action->setToolTip(i18n("Show a manpage"));
00231     action->setWhatsThis(i18n("<b>Show a manpage</b><p>Opens a man page using embedded viewer."));
00232     action = new KAction(i18n("Info Page..."), 0,
00233                          this, SLOT(infoPage()),
00234                          actionCollection(), "help_infopage");
00235     action->setToolTip(i18n("Show an infopage"));
00236     action->setWhatsThis(i18n("<b>Show an infopage</b><p>Opens an info page using embedded viewer."));
00237 }
00238 
00239 void DocumentationPart::emitBookmarkLocation(const QString &title, const KURL &url)
00240 {
00241     emit bookmarkLocation(title, url);
00242 }
00243 
00244 void DocumentationPart::searchInDocumentation()
00245 {
00246     if (isAssistantUsed())
00247         callAssistant("KDevDocumentation", "searchInDocumentation()");
00248     else    
00249     {
00250         mainWindow()->raiseView(m_widget);
00251         m_widget->searchInDocumentation();
00252     }
00253 }
00254 
00255 void DocumentationPart::searchInDocumentation(const QString &term)
00256 {
00257     mainWindow()->raiseView(m_widget);
00258     m_widget->searchInDocumentation(term);
00259 }
00260 
00261 void DocumentationPart::contextSearchInDocumentation()
00262 {
00263     if (isAssistantUsed())
00264         callAssistant("KDevDocumentation", "searchInDocumentation(QString)", m_contextStr);
00265     else
00266         searchInDocumentation(m_contextStr);
00267 }
00268 
00269 void DocumentationPart::manPage()
00270 {
00271     if (isAssistantUsed())
00272         callAssistant("KDevDocumentation", "manPage()");
00273     else    
00274     {
00275         bool ok;
00276         QString manpage = KInputDialog::getText(i18n("Show Manual Page"), i18n("Show manpage on:"), "", &ok, 0);
00277         if (ok && !manpage.isEmpty())
00278             manPage(manpage);
00279     }
00280 }
00281 
00282 void DocumentationPart::infoPage()
00283 {
00284     if (isAssistantUsed())
00285         callAssistant("KDevDocumentation", "infoPage()");
00286     else    
00287     {
00288         bool ok;
00289         QString infopage = KInputDialog::getText(i18n("Show Info Page"), i18n("Show infopage on:"), "", &ok, 0);
00290         if (ok && !infopage.isEmpty())
00291             infoPage(infopage);
00292     }
00293 }
00294 
00295 void DocumentationPart::manPage(const QString &term)
00296 {
00297     QString url = QString::fromLatin1("man:/%1").arg(term);
00298     partController()->showDocument(KURL(url));
00299 }
00300 
00301 void DocumentationPart::infoPage(const QString &term)
00302 {
00303     QString url = QString::fromLatin1("info:/%1").arg(term);
00304     partController()->showDocument(KURL(url));
00305 }
00306 
00307 void DocumentationPart::contextManPage()
00308 {
00309     if (isAssistantUsed())
00310         callAssistant("KDevDocumentation", "manPage(QString)", m_contextStr);
00311     else
00312         manPage(m_contextStr);
00313 }
00314 
00315 void DocumentationPart::contextInfoPage()
00316 {
00317     if (isAssistantUsed())
00318         callAssistant("KDevDocumentation", "infoPage(QString)", m_contextStr);
00319     else
00320         infoPage(m_contextStr);
00321 }
00322 
00323 void DocumentationPart::contextFindDocumentation()
00324 {
00325     if (isAssistantUsed())
00326         callAssistant("KDevDocumentation", "findInFinder(QString)", m_contextStr);
00327     else
00328         findInDocumentation(m_contextStr);
00329 }
00330 
00331 void DocumentationPart::findInDocumentation()
00332 {
00333     if (isAssistantUsed())
00334         callAssistant("KDevDocumentation", "findInFinder()");
00335     else
00336     {
00337         mainWindow()->raiseView(m_widget);
00338         m_widget->findInDocumentation();
00339     }
00340 }
00341 
00342 void DocumentationPart::findInDocumentation(const QString &term)
00343 {
00344     mainWindow()->raiseView(m_widget);
00345     m_widget->findInDocumentation(term);
00346 }
00347 
00348 void DocumentationPart::contextMenu(QPopupMenu *popup, const Context *context)
00349 {
00350     if (context->hasType(Context::EditorContext))
00351     {
00352         const EditorContext *econtext = static_cast<const EditorContext*>(context);
00353         QString ident = econtext->currentWord();
00354         if (!ident.isEmpty()) 
00355         {
00356             m_contextStr = ident;
00357             QString squeezed = KStringHandler::csqueeze(m_contextStr, 30);
00358             int id = -1;
00359             if (hasContextFeature(Finder)) {
00360                 id = popup->insertItem(i18n("Find Documentation: %1").arg(squeezed),
00361                                     this, SLOT(contextFindDocumentation()));
00362                 popup->setWhatsThis(id, i18n("<b>Find documentation</b><p>"
00363                                     "Opens the documentation finder tab and searches "
00364                                     "all possible sources of documentation like "
00365                                     "table of contents, index, man and info databases, "
00366                                     "Google, etc."));
00367             }
00368             if (hasContextFeature(IndexLookup)) {
00369                 id = popup->insertItem(i18n("Look in Documentation Index: %1").arg(squeezed),
00370                                 this, SLOT(contextLookInDocumentationIndex()));
00371                 popup->setWhatsThis(id, i18n("<b>Look in documentation index</b><p>"
00372                                 "Opens the documentation index tab. It allows "
00373                                 "a term to be entered which will be looked for in "
00374                                 "the documentation index."));
00375             }
00376             if (hasContextFeature(FullTextSearch)) {
00377                 id = popup->insertItem(i18n("Search in Documentation: %1").arg(squeezed),
00378                                 this, SLOT(contextSearchInDocumentation()));
00379                 popup->setWhatsThis(id, i18n("<b>Search in documentation</b><p>Searches "
00380                                 "for a term under the cursor in "
00381                                 "the documentation. For this to work, "
00382                                 "a full text index must be created first, which can be done in the "
00383                                 "configuration dialog of the documentation plugin."));
00384             }
00385             if (hasContextFeature(GotoMan)) {
00386                 id = popup->insertItem(i18n("Goto Manpage: %1").arg(squeezed),
00387                                 this, SLOT(contextManPage()));
00388                 popup->setWhatsThis(id, i18n("<b>Goto manpage</b><p>Tries to open a man page for the term under the cursor."));
00389             }
00390             if (hasContextFeature(GotoInfo)) {
00391                 id = popup->insertItem( i18n("Goto Infopage: %1").arg(squeezed),
00392                                 this, SLOT(contextInfoPage()) );
00393                 popup->setWhatsThis(id, i18n("<b>Goto infopage</b><p>Tries to open an info page for the term under the cursor."));
00394             }
00395             if (id != -1)
00396                 popup->insertSeparator();
00397         }
00398     }
00399 }
00400 
00401 bool DocumentationPart::hasContextFeature(ContextFeature feature)
00402 {
00403     KConfig *config = DocumentationFactory::instance()->config();
00404     QString group = config->group();
00405     config->setGroup("Context Features");
00406     switch (feature)
00407     {
00408         case Finder:
00409             return config->readBoolEntry("Finder", true);
00410             break;
00411         case IndexLookup:
00412             return config->readBoolEntry("IndexLookup", false);
00413             break;
00414         case FullTextSearch:
00415             return config->readBoolEntry("FullTextSearch", true);
00416             break;
00417         case GotoMan:
00418             return config->readBoolEntry("GotoMan", false);
00419             break;
00420         case GotoInfo:
00421             return config->readBoolEntry("GotoInfo", false);
00422             break;
00423     }
00424     config->setGroup(group);
00425     return false;
00426 }
00427 
00428 void DocumentationPart::setContextFeature(ContextFeature feature, bool b)
00429 {
00430     KConfig *config = DocumentationFactory::instance()->config();
00431     QString group = config->group();
00432     config->setGroup("Context Features");
00433     QString key;
00434     switch (feature)
00435     {
00436         case Finder:
00437             key = "Finder";
00438             break;
00439         case IndexLookup:
00440             key = "IndexLookup";
00441             break;
00442         case FullTextSearch:
00443             key = "FullTextSearch";
00444             break;
00445         case GotoMan:
00446             key = "GotoMan";
00447             break;
00448         case GotoInfo:
00449             key = "GotoInfo";
00450             break;
00451     }
00452     if (!key.isEmpty())
00453         config->writeEntry(key, b);
00454     config->setGroup(group);
00455 }
00456 
00457 void DocumentationPart::lookInDocumentationIndex()
00458 {
00459     if (isAssistantUsed())
00460         callAssistant("KDevDocumentation", "lookupInIndex()");
00461     else    
00462     {
00463         mainWindow()->raiseView(m_widget);
00464         m_widget->lookInDocumentationIndex();
00465     }
00466 }
00467 
00468 void DocumentationPart::lookInDocumentationIndex(const QString &term)
00469 {
00470     mainWindow()->raiseView(m_widget);
00471     m_widget->lookInDocumentationIndex(term);
00472 }
00473 
00474 void DocumentationPart::contextLookInDocumentationIndex()
00475 {
00476     if (isAssistantUsed())
00477         callAssistant("KDevDocumentation", "lookupInIndex(QString)", m_contextStr);
00478     else
00479         lookInDocumentationIndex(m_contextStr);
00480 }
00481 
00482 void DocumentationPart::projectOpened()
00483 {
00484     QString projectDocSystem = DomUtil::readEntry(*(projectDom()), "/kdevdocumentation/projectdoc/docsystem");
00485     QString projectDocURL = DomUtil::readEntry(*(projectDom()), "/kdevdocumentation/projectdoc/docurl");
00486     if (!projectDocURL.isEmpty())
00487         projectDocURL = QDir::cleanDirPath(project()->projectDirectory() + "/" + projectDocURL);
00488     QString userManualURL = DomUtil::readEntry(*(projectDom()), "/kdevdocumentation/projectdoc/usermanualurl");
00489     
00490     for (QValueList<DocumentationPlugin*>::const_iterator it = m_plugins.constBegin();
00491         it != m_plugins.constEnd(); ++it)
00492     {
00493         if ((*it)->hasCapability(DocumentationPlugin::ProjectDocumentation) &&
00494             ((*it)->pluginName() == projectDocSystem))
00495             m_projectDocumentationPlugin = (*it)->projectDocumentationPlugin(DocumentationPlugin::APIDocs);
00496         if ((*it)->hasCapability(DocumentationPlugin::ProjectUserManual))
00497         {
00498             kdDebug() << "creating user manual for type: " << DocumentationPlugin::UserManual << endl;
00499             m_userManualPlugin = (*it)->projectDocumentationPlugin(DocumentationPlugin::UserManual);
00500         }
00501     }
00502     if (m_projectDocumentationPlugin)
00503         m_projectDocumentationPlugin->init(m_widget->contents(), m_widget->index(), projectDocURL);
00504     if (m_userManualPlugin && !userManualURL.isEmpty())
00505         m_userManualPlugin->init(m_widget->contents(), m_widget->index(), userManualURL);
00506 }
00507 
00508 void DocumentationPart::projectClosed()
00509 {   
00510 //    saveProjectDocumentationInfo();
00511         
00512     delete m_projectDocumentationPlugin;
00513     m_projectDocumentationPlugin = 0;
00514     delete m_userManualPlugin;
00515     m_userManualPlugin = 0;
00516 }
00517 
00518 void DocumentationPart::saveProjectDocumentationInfo()
00519 {
00520     if (m_projectDocumentationPlugin)
00521     {
00522         DomUtil::writeEntry(*(projectDom()), "/kdevdocumentation/projectdoc/docsystem", m_projectDocumentationPlugin->pluginName());
00523 
00524         QString relPath = URLUtil::extractPathNameRelative(project()->projectDirectory(),
00525             m_projectDocumentationPlugin->catalogURL());
00526         DomUtil::writeEntry(*(projectDom()), "/kdevdocumentation/projectdoc/docurl", relPath);
00527     }
00528     else
00529     {
00530         DomUtil::writeEntry(*(projectDom()), "/kdevdocumentation/projectdoc/docsystem", "");
00531         DomUtil::writeEntry(*(projectDom()), "/kdevdocumentation/projectdoc/docurl", "");
00532     }
00533     if (m_userManualPlugin)
00534         DomUtil::writeEntry(*(projectDom()), "/kdevdocumentation/projectdoc/usermanualurl", m_userManualPlugin->catalogURL());
00535     else
00536         DomUtil::writeEntry(*(projectDom()), "/kdevdocumentation/projectdoc/usermanualurl", "");
00537 }
00538 
00539 QCString DocumentationPart::startAssistant()
00540 {
00541     static QCString lastAssistant = "";
00542     
00543     if (!lastAssistant.isEmpty() && KApplication::dcopClient()->isApplicationRegistered(lastAssistant))
00544         return lastAssistant;
00545     
00546     const char *function = 0;
00547     QString app = "kdevassistant";
00548     function = "start_service_by_desktop_name(QString,QStringList)";
00549     QStringList URLs;
00550 
00551     QByteArray data, replyData;
00552     QCString replyType;
00553     QDataStream arg(data, IO_WriteOnly);
00554     arg << app << URLs;
00555 
00556     if (!KApplication::dcopClient()->call("klauncher", "klauncher", function,  data, replyType, replyData))
00557     {
00558         kdDebug() << "call failed" << endl;
00559         lastAssistant = "";
00560     } 
00561     else 
00562     {
00563         QDataStream reply(replyData, IO_ReadOnly);
00564 
00565         if ( replyType != "serviceResult" )
00566         {
00567             kdDebug() << "unexpected result: " << replyType.data() << endl;
00568             lastAssistant = "";
00569         }
00570         int result;
00571         QCString dcopName;
00572         QString error;
00573         reply >> result >> dcopName >> error;
00574         if (result != 0)
00575         {
00576             kdDebug() << "Error: " << error << endl;
00577             lastAssistant = "";
00578         }
00579         if (!dcopName.isEmpty())
00580         {
00581             lastAssistant = dcopName;
00582             kdDebug() << dcopName.data() << endl;
00583             
00584             //@fixme: is there another way to wait for the remote object to be loaded
00585             while (!KApplication::dcopClient()->remoteObjects(dcopName).contains("KDevDocumentation"))
00586                 usleep(500);
00587         }
00588     }
00589     return lastAssistant;
00590 }
00591 
00592 bool DocumentationPart::isAssistantUsed() const
00593 {
00594     // hack to solve BR #90334 - don't call kdevassistant via DCOP if we ARE kdevassistant
00595     if ( kapp->instanceName().find("kdevassistant") != -1 )
00596     {
00597         return false;
00598     }
00599     
00600     return m_assistantUsed;
00601 }
00602 
00603 void DocumentationPart::setAssistantUsed(bool b)
00604 {
00605     m_assistantUsed = b;
00606     //use global config to store different settings for kdevassistant and kdevelop
00607     KConfig *config = kapp->config();
00608     config->setGroup("Documentation");
00609     config->writeEntry("UseAssistant", isAssistantUsed());
00610 }
00611 
00612 void DocumentationPart::activateAssistantWindow(const QCString &ref)
00613 {
00614     kdDebug() << "DocumentationPart::activateAssistantWindow" << endl;
00615     QByteArray data, replyData;
00616     QCString replyType;
00617     if (KApplication::dcopClient()->call(ref, "MainWindow", "getWinID()", data, replyType, replyData))
00618     {
00619         kdDebug() << "    call successful " << endl;
00620         QDataStream reply(replyData, IO_ReadOnly);
00621         
00622         int winId;
00623         reply >> winId;
00624         kdDebug() << "Win ID: " << winId << endl;
00625         KWin::forceActiveWindow(winId);
00626 
00627         KApplication::dcopClient()->send(ref, "MainWindow", "show()", QByteArray());
00628     }
00629 }
00630 
00631 void DocumentationPart::callAssistant(const QCString &interface, const QCString &method)
00632 {
00633     QCString ref = startAssistant();
00634     QByteArray data;
00635     if (KApplication::dcopClient()->send(ref, interface, method, data))
00636         activateAssistantWindow(ref);
00637     else
00638         kdDebug() << "problem communicating with: " << ref;
00639 }
00640 
00641 void DocumentationPart::callAssistant(const QCString &interface, const QCString &method, const QString &dataStr)
00642 {
00643     QCString ref = startAssistant();
00644     QByteArray data;
00645     QDataStream arg(data, IO_WriteOnly);
00646     arg << dataStr;
00647     if (KApplication::dcopClient()->send(ref, interface, method, data))
00648         activateAssistantWindow(ref);
00649     else
00650         kdDebug() << "problem communicating with: " << ref;
00651 }
00652 
00653 void DocumentationPart::loadSettings()
00654 {
00655     KConfig *config = kapp->config();
00656     config->setGroup("Documentation");
00657     m_assistantUsed = config->readBoolEntry("UseAssistant", false);
00658     
00659     if (QString(KGlobal::instance()->aboutData()->appName()) == "kdevassistant")
00660     {
00661         int page = config->readNumEntry("LastPage", 0);
00662         switch (page)
00663         {
00664             case 1:
00665                 lookInDocumentationIndex();
00666                 break;
00667             case 2:
00668                 findInDocumentation();
00669                 break;
00670             case 3:
00671                 searchInDocumentation();
00672                 break;
00673         }
00674     }
00675 }
00676 
00677 #include "documentation_part.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:39 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003