• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

NepomukDaemons

nepomukserverkcm.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE Project
00002    Copyright (c) 2007 Sebastian Trueg <trueg@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "nepomukserverkcm.h"
00020 #include "nepomukserverinterface.h"
00021 #include "../common/strigiconfigfile.h"
00022 
00023 #include <KPluginFactory>
00024 #include <KPluginLoader>
00025 #include <KAboutData>
00026 #include <KSharedConfig>
00027 #include <KLed>
00028 #include <KMessageBox>
00029 #include <KUrlRequester>
00030 
00031 #include <strigi/qtdbus/strigiclient.h>
00032 
00033 
00034 K_PLUGIN_FACTORY( NepomukConfigModuleFactory, registerPlugin<Nepomuk::ServerConfigModule>(); )
00035 K_EXPORT_PLUGIN( NepomukConfigModuleFactory("kcm_nepomuk", "nepomuk") )
00036 
00037 
00038 Nepomuk::ServerConfigModule::ServerConfigModule( QWidget* parent, const QVariantList& args )
00039     : KCModule( NepomukConfigModuleFactory::componentData(), parent, args ),
00040       m_serverInterface( "org.kde.NepomukServer", "/nepomukserver", QDBusConnection::sessionBus() )
00041 {
00042     KAboutData *about = new KAboutData(
00043         "kcm_nepomuk", 0, ki18n("Nepomuk Configuration Module"),
00044         KDE_VERSION_STRING, KLocalizedString(), KAboutData::License_GPL,
00045         ki18n("Copyright 2007 Sebastian Trüg"));
00046     about->addAuthor(ki18n("Sebastian Trüg"), KLocalizedString(), "trueg@kde.org");
00047     setAboutData(about);
00048     setButtons(Apply|Default);
00049     setupUi( this );
00050 
00051     KUrlRequester* urlReq = new KUrlRequester( m_editStrigiFolders );
00052     urlReq->setMode( KFile::Directory|KFile::LocalOnly|KFile::ExistingOnly );
00053     KEditListBox::CustomEditor ce( urlReq, urlReq->lineEdit() );
00054     m_editStrigiFolders->setCustomEditor( ce );
00055 
00056     connect( m_checkEnableStrigi, SIGNAL( toggled(bool) ),
00057              this, SLOT( changed() ) );
00058     connect( m_checkEnableNepomuk, SIGNAL( toggled(bool) ),
00059              this, SLOT( changed() ) );
00060     connect( m_editStrigiFolders, SIGNAL( changed() ),
00061              this, SLOT( changed() ) );
00062     connect( m_editStrigiExcludeFilters, SIGNAL( changed() ),
00063              this, SLOT( changed() ) );
00064 
00065     load();
00066 }
00067 
00068 
00069 Nepomuk::ServerConfigModule::~ServerConfigModule()
00070 {
00071 }
00072 
00073 
00074 void Nepomuk::ServerConfigModule::load()
00075 {
00076     if ( m_serverInterface.isValid() ) {
00077         m_checkEnableStrigi->setChecked( m_serverInterface.isStrigiEnabled().value() );
00078         m_checkEnableNepomuk->setChecked( m_serverInterface.isNepomukEnabled().value() );
00079     }
00080     else {
00081         KMessageBox::sorry( this,
00082                             i18n( "The Nepomuk Server is not running. The settings "
00083                                   "will be used the next time the server is started." ),
00084                             i18n( "Nepomuk server not running" ) );
00085 
00086         KConfig config( "nepomukserverrc" );
00087         m_checkEnableNepomuk->setChecked( config.group( "Basic Settings" ).readEntry( "Start Nepomuk", true ) );
00088         m_checkEnableStrigi->setChecked( config.group( "Service-nepomukstrigiservice" ).readEntry( "autostart", false ) );
00089     }
00090 
00091     if ( isStrigiRunning() ) {
00092         StrigiClient strigiClient;
00093         m_editStrigiFolders->setItems( strigiClient.getIndexedDirectories() );
00094         QList<QPair<bool, QString> > filters = strigiClient.getFilters();
00095         m_editStrigiExcludeFilters->clear();
00096         for( QList<QPair<bool, QString> >::const_iterator it = filters.constBegin();
00097              it != filters.constEnd(); ++it ) {
00098             if ( !it->first ) {
00099                 m_editStrigiExcludeFilters->insertItem( it->second );
00100             }
00101             // else: we simply drop include filters for now
00102         }
00103     }
00104     else {
00105         StrigiConfigFile strigiConfig( StrigiConfigFile::defaultStrigiConfigFilePath() );
00106         strigiConfig.load();
00107         m_editStrigiFolders->setItems( strigiConfig.defaultRepository().indexedDirectories() );
00108         m_editStrigiExcludeFilters->setItems( strigiConfig.excludeFilters() );
00109     }
00110 
00111     updateStrigiStatus();
00112 }
00113 
00114 
00115 void Nepomuk::ServerConfigModule::save()
00116 {
00117     // 1. change the settings (in case the server is not running)
00118     KConfig config( "nepomukserverrc" );
00119     config.group( "Basic Settings" ).writeEntry( "Start Nepomuk", m_checkEnableNepomuk->isChecked() );
00120     config.group( "Service-nepomukstrigiservice" ).writeEntry( "autostart", m_checkEnableStrigi->isChecked() );
00121 
00122 
00123     // 2. update Strigi config
00124     StrigiConfigFile strigiConfig( StrigiConfigFile::defaultStrigiConfigFilePath() );
00125     strigiConfig.load();
00126     if ( m_checkEnableNepomuk->isChecked() ) {
00127         strigiConfig.defaultRepository().setType( "sopranobackend" );
00128     }
00129     else {
00130         strigiConfig.defaultRepository().setType( "clucene" );
00131     }
00132     strigiConfig.defaultRepository().setIndexedDirectories( m_editStrigiFolders->items() );
00133     strigiConfig.setExcludeFilters( m_editStrigiExcludeFilters->items() );
00134     strigiConfig.save();
00135 
00136 
00137     // 3. update the current state of the nepomuk server
00138     if ( m_serverInterface.isValid() ) {
00139         m_serverInterface.enableNepomuk( m_checkEnableNepomuk->isChecked() );
00140         m_serverInterface.enableStrigi( m_checkEnableStrigi->isChecked() );
00141     }
00142     else {
00143         KMessageBox::sorry( this,
00144                             i18n( "The Nepomuk Server is not running. The settings have been saved "
00145                                   "and will be used the next time the server is started." ),
00146                             i18n( "Nepomuk server not running" ) );
00147     }
00148 
00149 
00150     // 4. update values in the running Strigi instance
00151     // TODO: there should be a dbus method to re-read the config
00152     // -----------------------------
00153     if ( m_checkEnableStrigi->isChecked() ) {
00154         // give strigi some time to start
00155         QTimer::singleShot( 2000, this, SLOT( updateStrigiSettingsInRunningInstance() ) );
00156     }
00157 
00158     // give strigi some time to start
00159     QTimer::singleShot( 2000, this, SLOT( updateStrigiStatus() ) );
00160 }
00161 
00162 
00163 void Nepomuk::ServerConfigModule::defaults()
00164 {
00165     m_checkEnableStrigi->setChecked( false );
00166     m_checkEnableNepomuk->setChecked( true );
00167     // create Strigi default config
00168     StrigiConfigFile defaultConfig;
00169     m_editStrigiFolders->setItems( defaultConfig.defaultRepository().indexedDirectories() );
00170     m_editStrigiExcludeFilters->setItems( defaultConfig.excludeFilters() );
00171 }
00172 
00173 
00174 void Nepomuk::ServerConfigModule::updateStrigiStatus()
00175 {
00176     if ( isStrigiRunning() ) {
00177         m_strigiStatus->on();
00178         m_strigiStatusLabel->setText( i18n( "Strigi is running" ) );
00179     }
00180     else {
00181         m_strigiStatus->off();
00182         m_strigiStatusLabel->setText( i18n( "Strigi not running" ) );
00183     }
00184 }
00185 
00186 
00187 void Nepomuk::ServerConfigModule::updateStrigiSettingsInRunningInstance()
00188 {
00189     if ( isStrigiRunning() ) {
00190         StrigiClient strigiClient;
00191         strigiClient.setIndexedDirectories( m_editStrigiFolders->items() );
00192 
00193         // FIXME: there should be a rereadConfig method in strigi
00194         StrigiConfigFile strigiConfig( StrigiConfigFile::defaultStrigiConfigFilePath() );
00195         strigiConfig.load();
00196 
00197         QList<QPair<bool, QString> > filters;
00198         foreach( const QString &filter, strigiConfig.excludeFilters() ) {
00199             filters.append( qMakePair( false, filter ) );
00200         }
00201         strigiClient.setFilters( filters );
00202     }
00203 }
00204 
00205 
00206 bool Nepomuk::ServerConfigModule::isStrigiRunning()
00207 {
00208     return QDBusConnection::sessionBus().interface()->isServiceRegistered( "vandenoever.strigi" ).value();
00209 }
00210 
00211 #include "nepomukserverkcm.moc"

NepomukDaemons

Skip menu "NepomukDaemons"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KCMShell
  • KNotify
  • KStyles
  • Nepomuk Daemons
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal