KDevelop API Documentation

docglobalconfigwidget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2002 by Bernd Gehrmann                                  *
00003  *   bernd@kdevelop.org                                                    *
00004  *   Copyright (C) 2002 by Sebastian Kratzert                              *
00005  *   skratzert@gmx.de                                                      *
00006  *   Copyright (C) 2003-2004 by Alexander Dymo                             *
00007  *   cloudtemple@mksat.net                                                 *
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  *   This program is distributed in the hope that it will be useful,       *
00015  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017  *   GNU General Public License for more details.                          *
00018  *                                                                         *
00019  *   You should have received a copy of the GNU General Public License     *
00020  *   along with this program; if not, write to the                         *
00021  *   Free Software Foundation, Inc.,                                       *
00022  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00023  ***************************************************************************/
00024 #include "docglobalconfigwidget.h"
00025 
00026 #include <qlayout.h>
00027 #include <qtoolbox.h>
00028 #include <qcheckbox.h>
00029 
00030 #include <kdebug.h>
00031 #include <kconfig.h>
00032 #include <kprocess.h>
00033 #include <kstddirs.h>
00034 #include <kapplication.h>
00035 #include <kurlrequester.h>
00036 
00037 #include "kdevdocumentationplugin.h"
00038 
00039 #include "docconfiglistview.h"
00040 #include "documentation_part.h"
00041 #include "documentation_widget.h"
00042 #include "editcatalogdlg.h"
00043 #include "contentsview.h"
00044 #include "indexview.h"
00045 #include "docutils.h"
00046 
00047 DocGlobalConfigWidget::DocGlobalConfigWidget(DocumentationPart *part, 
00048     DocumentationWidget *widget, QWidget *parent, const char *name, WFlags fl)
00049     :DocGlobalConfigWidgetBase(parent, name, fl), m_part(part), m_widget(widget)
00050 {
00051     //load catalog settings
00052     if (collectionsBox->currentItem())
00053         collectionsBox->removeItem(collectionsBox->currentItem());
00054     for (QValueList<DocumentationPlugin*>::const_iterator it = m_part->m_plugins.constBegin();
00055         it != m_part->m_plugins.constEnd(); ++it)
00056     {
00057         QWidget *contentsContainter = new QWidget(this);
00058         QVBoxLayout *cl = new QVBoxLayout(contentsContainter, 0, 0);
00059         DocConfigListView *view = new DocConfigListView(contentsContainter);
00060         cl->addWidget(view);
00061         int box = collectionsBox->addItem(contentsContainter, (*it)->pluginName());
00062         m_pluginBoxes[box] = *it;
00063         m_pluginViews[box] = view;
00064         (*it)->loadCatalogConfiguration(m_pluginViews[box]);
00065     }
00066     
00067     KConfig *config = m_part->config();
00068     //read full text search settings
00069     config->setGroup("htdig");
00070     QString databaseDir = kapp->dirs()->saveLocation("data",
00071         "kdevdocumentation/search");
00072     databaseDirEdit->setURL(config->readPathEntry("databaseDir", databaseDir));
00073     htdigbinEdit->setURL(config->readPathEntry("htdigbin", kapp->dirs()->findExe("htdig")));
00074     htmergebinEdit->setURL(config->readPathEntry("htmergebin", kapp->dirs()->findExe("htmerge")));
00075     htsearchbinEdit->setURL(config->readPathEntry("htsearchbin", kapp->dirs()->findExe("htsearch")));
00076     if (config->readBoolEntry("IsSetup", false) == false)
00077     {
00078         QFileInfo fi(htsearchbinEdit->url());
00079         if (!fi.exists())
00080         {
00081             //try to guess htsearch location on Debian
00082             QFileInfo fi("/usr/lib/cgi-bin/htsearch");
00083             if (!fi.exists())
00084             {
00085                 //try to guess htsearch location on SuSE
00086                 QFileInfo fi("/srv/www/cgi-bin/htsearch");
00087                 if (fi.exists())
00088                     htsearchbinEdit->setURL("/srv/www/cgi-bin/htsearch");
00089             }
00090             else
00091                 htsearchbinEdit->setURL("/usr/lib/cgi-bin/htsearch");
00092         }
00093     }
00094     
00095     find_box->setChecked(m_part->hasContextFeature(DocumentationPart::Finder));
00096     index_box->setChecked(m_part->hasContextFeature(DocumentationPart::IndexLookup));
00097     search_box->setChecked(m_part->hasContextFeature(DocumentationPart::FullTextSearch));
00098     man_box->setChecked(m_part->hasContextFeature(DocumentationPart::GotoMan));
00099     info_box->setChecked(m_part->hasContextFeature(DocumentationPart::GotoInfo));
00100     
00101     useAssistant_box->setChecked(m_part->isAssistantUsed());
00102     
00103     // Having app-specific settings isn't pretty, but this setting is nonsensical in kdevassistant
00104     if ( kapp->instanceName().find("kdevassistant") != -1 )
00105     {
00106         useAssistant_box->hide();
00107     }
00108 }
00109 
00110 DocGlobalConfigWidget::~DocGlobalConfigWidget()
00111 {
00112 }
00113 
00114 /*$SPECIALIZATION$*/
00115 void DocGlobalConfigWidget::collectionsBoxCurrentChanged(int box)
00116 {
00117 }
00118 
00119 void DocGlobalConfigWidget::removeCollectionButtonClicked()
00120 {
00121     ConfigurationItem *item = dynamic_cast<ConfigurationItem*>(activeView()->currentItem());
00122     if (!item)
00123         return;
00124     activePlugin()->deleteCatalogConfiguration(item);
00125     delete activeView()->currentItem();
00126 }
00127 
00128 void DocGlobalConfigWidget::editCollectionButtonClicked()
00129 {
00130     ConfigurationItem *item = dynamic_cast<ConfigurationItem*>(activeView()->currentItem());
00131     if (!item)
00132         return;
00133     EditCatalogDlg dlg(activePlugin(), this, "edit collection dlg", true);
00134     dlg.setURL(item->url());
00135     dlg.setTitle(item->title());
00136     if (dlg.exec())
00137         activePlugin()->editCatalogConfiguration(item, dlg.title(), dlg.url());
00138 }
00139 
00140 void DocGlobalConfigWidget::addCollectionButtonClicked()
00141 {
00142     EditCatalogDlg dlg(activePlugin(), this, "edit collection dlg", true);
00143     if (dlg.exec())
00144         activePlugin()->addCatalogConfiguration(activeView(), dlg.title(), dlg.url());
00145 }
00146 
00147 DocumentationPlugin *DocGlobalConfigWidget::activePlugin()
00148 {
00149     return m_pluginBoxes[collectionsBox->currentIndex()];
00150 }
00151 
00152 KListView *DocGlobalConfigWidget::activeView()
00153 {
00154     return m_pluginViews[collectionsBox->currentIndex()];
00155 }
00156 
00157 void DocGlobalConfigWidget::accept()
00158 {
00159     //write catalog settings
00160     for (QMap<int, DocumentationPlugin*>::const_iterator it = m_pluginBoxes.constBegin();
00161         it != m_pluginBoxes.constEnd(); ++ it)
00162     {
00163         it.data()->saveCatalogConfiguration(m_pluginViews[it.key()]);
00164         //@todo: take restrictions into account
00165         it.data()->reinit(m_widget->contents(), m_widget->index(), QStringList());
00166     }
00167 
00168     KConfig *config = m_part->config();
00169     //write full text search settings
00170     config->setGroup("htdig");
00171     config->writePathEntry("databaseDir", DocUtils::envURL(databaseDirEdit));
00172     config->writePathEntry("htdigbin", DocUtils::envURL(htdigbinEdit));
00173     config->writePathEntry("htmergebin", DocUtils::envURL(htmergebinEdit));
00174     config->writePathEntry("htsearchbin", DocUtils::envURL(htsearchbinEdit));
00175     
00176     //write full text search locations file    
00177     QString ftsLocationsFile = locateLocal("data", "kdevdocumentation/search/locations.txt");
00178     QFile f(ftsLocationsFile);
00179     QStringList locs;
00180     if (f.open(IO_ReadWrite | IO_Truncate))
00181     {
00182         QTextStream str(&f);
00183         for (QValueList<DocumentationPlugin*>::const_iterator it = m_part->m_plugins.constBegin();
00184             it != m_part->m_plugins.constEnd(); ++ it)
00185         {
00186             QStringList app = (*it)->fullTextSearchLocations();
00187             for (QStringList::const_iterator it2 = app.constBegin();
00188                 it2 != app.constEnd(); ++it2)
00189             {
00190                 if (!locs.contains(*it2))
00191                     locs.append(*it2);
00192             }
00193         }
00194         str << locs.join("\n");
00195 
00196         f.close();
00197     }
00198     
00199     //write editor context menu configuration
00200     m_part->setContextFeature(DocumentationPart::Finder, find_box->isChecked());
00201     m_part->setContextFeature(DocumentationPart::IndexLookup, index_box->isChecked());
00202     m_part->setContextFeature(DocumentationPart::FullTextSearch, search_box->isChecked());
00203     m_part->setContextFeature(DocumentationPart::GotoMan, man_box->isChecked());
00204     m_part->setContextFeature(DocumentationPart::GotoInfo, info_box->isChecked());
00205     
00206     m_part->setAssistantUsed(useAssistant_box->isChecked());
00207     
00208     config->sync();
00209     
00210     //refill the index
00211     kdDebug() << "refill the index" << endl;    
00212     if (m_part->m_hasIndex)
00213     {
00214         kdDebug() << "m_part->m_hasIndex" << endl;
00215         m_part->m_widget->index()->refill();
00216     }
00217 }
00218 
00219 #include "docglobalconfigwidget.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