• Skip to content
  • Skip to link menu
KDE 4.2 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 "folderselectionmodel.h"
00022 
00023 #include <KPluginFactory>
00024 #include <KPluginLoader>
00025 #include <KAboutData>
00026 #include <KSharedConfig>
00027 #include <KLed>
00028 #include <KMessageBox>
00029 
00030 #include <QtGui/QTreeView>
00031 
00032 #include <Soprano/PluginManager>
00033 
00034 
00035 K_PLUGIN_FACTORY( NepomukConfigModuleFactory, registerPlugin<Nepomuk::ServerConfigModule>(); )
00036 K_EXPORT_PLUGIN( NepomukConfigModuleFactory("kcm_nepomuk", "nepomuk") )
00037 
00038 
00039 namespace {
00040     QStringList defaultFolders() {
00041         return QStringList() << QDir::homePath();
00042     }
00043 
00044     QStringList defaultExcludeFilters() {
00045         return QStringList() << ".*/" << ".*" << "*~" << "*.part";
00046     }
00047 
00048     void expandRecursively( const QModelIndex& index, QTreeView* view ) {
00049         if ( index.isValid() ) {
00050             view->expand( index );
00051             expandRecursively( index.parent(), view );
00052         }
00053     }
00054 }
00055 
00056 
00057 Nepomuk::ServerConfigModule::ServerConfigModule( QWidget* parent, const QVariantList& args )
00058     : KCModule( NepomukConfigModuleFactory::componentData(), parent, args ),
00059       m_serverInterface( "org.kde.NepomukServer", "/nepomukserver", QDBusConnection::sessionBus() ),
00060       m_strigiInterface( 0 )
00061 {
00062     KAboutData *about = new KAboutData(
00063         "kcm_nepomuk", 0, ki18n("Nepomuk Configuration Module"),
00064         KDE_VERSION_STRING, KLocalizedString(), KAboutData::License_GPL,
00065         ki18n("Copyright 2007 Sebastian Trüg"));
00066     about->addAuthor(ki18n("Sebastian Trüg"), KLocalizedString(), "trueg@kde.org");
00067     setAboutData(about);
00068     setButtons(Apply|Default);
00069     setupUi( this );
00070 
00071     m_folderModel = new FolderSelectionModel( m_viewIndexFolders );
00072     m_viewIndexFolders->setModel( m_folderModel );
00073     m_viewIndexFolders->setHeaderHidden( true );
00074     m_viewIndexFolders->setRootIsDecorated( true );
00075     m_viewIndexFolders->setAnimated( true );
00076     m_viewIndexFolders->setRootIndex( m_folderModel->setRootPath( QDir::rootPath() ) );
00077 
00078     connect( m_checkEnableStrigi, SIGNAL( toggled(bool) ),
00079              this, SLOT( changed() ) );
00080     connect( m_checkEnableNepomuk, SIGNAL( toggled(bool) ),
00081              this, SLOT( changed() ) );
00082     connect( m_folderModel, SIGNAL( dataChanged(const QModelIndex&, const QModelIndex&) ),
00083              this, SLOT( changed() ) );
00084     connect( m_editStrigiExcludeFilters, SIGNAL( changed() ),
00085              this, SLOT( changed() ) );
00086 
00087     connect( QDBusConnection::sessionBus().interface(),
00088              SIGNAL( serviceOwnerChanged( const QString&, const QString&, const QString& ) ),
00089              this,
00090              SLOT( slotUpdateStrigiStatus() ) );
00091 
00092     recreateStrigiInterface();
00093     load();
00094 }
00095 
00096 
00097 Nepomuk::ServerConfigModule::~ServerConfigModule()
00098 {
00099     delete m_strigiInterface;
00100 }
00101 
00102 
00103 void Nepomuk::ServerConfigModule::load()
00104 {
00105     bool sopranoBackendAvailable = !Soprano::PluginManager::instance()->allBackends().isEmpty();
00106 
00107     m_checkEnableNepomuk->setEnabled( sopranoBackendAvailable );
00108 
00109     if ( !sopranoBackendAvailable ) {
00110         KMessageBox::sorry( this,
00111                             i18n( "No Soprano Database backend available. Please check your installation." ),
00112                             i18n( "Nepomuk cannot be started" ) );
00113     }
00114     else if ( m_serverInterface.isValid() ) {
00115         m_checkEnableStrigi->setChecked( m_serverInterface.isStrigiEnabled().value() );
00116         m_checkEnableNepomuk->setChecked( m_serverInterface.isNepomukEnabled().value() );
00117     }
00118     else {
00119         KMessageBox::sorry( this,
00120                             i18n( "The Nepomuk Server is not running. The settings "
00121                                   "will be used the next time the server is started." ),
00122                             i18n( "Nepomuk server not running" ) );
00123 
00124         KConfig config( "nepomukserverrc" );
00125         m_checkEnableNepomuk->setChecked( config.group( "Basic Settings" ).readEntry( "Start Nepomuk", true ) );
00126         m_checkEnableStrigi->setChecked( config.group( "Service-nepomukstrigiservice" ).readEntry( "autostart", true ) );
00127     }
00128 
00129     KConfig strigiConfig( "nepomukstrigirc" );
00130     m_folderModel->setFolders( strigiConfig.group( "General" ).readPathEntry( "folders", defaultFolders() ),
00131                                strigiConfig.group( "General" ).readPathEntry( "exclude folders", QStringList() ) );
00132     m_editStrigiExcludeFilters->setItems( strigiConfig.group( "General" ).readEntry( "exclude filters", defaultExcludeFilters() ) );
00133 
00134     // make sure that the tree is expanded to show all selected items
00135     foreach( const QString& dir, m_folderModel->includeFolders() + m_folderModel->excludeFolders() ) {
00136         expandRecursively( m_folderModel->index( dir ), m_viewIndexFolders );
00137     }
00138 
00139     recreateStrigiInterface();
00140     slotUpdateStrigiStatus();
00141     emit changed(false);
00142 }
00143 
00144 
00145 void Nepomuk::ServerConfigModule::save()
00146 {
00147     // 1. change the settings (in case the server is not running)
00148     KConfig config( "nepomukserverrc" );
00149     config.group( "Basic Settings" ).writeEntry( "Start Nepomuk", m_checkEnableNepomuk->isChecked() );
00150     config.group( "Service-nepomukstrigiservice" ).writeEntry( "autostart", m_checkEnableStrigi->isChecked() );
00151 
00152 
00153     // 2. update Strigi config
00154     KConfig strigiConfig( "nepomukstrigirc" );
00155     strigiConfig.group( "General" ).writePathEntry( "folders", m_folderModel->includeFolders() );
00156     strigiConfig.group( "General" ).writePathEntry( "exclude folders", m_folderModel->excludeFolders() );
00157     strigiConfig.group( "General" ).writeEntry( "exclude filters", m_editStrigiExcludeFilters->items() );
00158 
00159 
00160     // 3. update the current state of the nepomuk server
00161     if ( m_serverInterface.isValid() ) {
00162         m_serverInterface.enableNepomuk( m_checkEnableNepomuk->isChecked() );
00163         m_serverInterface.enableStrigi( m_checkEnableStrigi->isChecked() );
00164     }
00165     else {
00166         KMessageBox::sorry( this,
00167                             i18n( "The Nepomuk Server is not running. The settings have been saved "
00168                                   "and will be used the next time the server is started." ),
00169                             i18n( "Nepomuk server not running" ) );
00170     }
00171 
00172     recreateStrigiInterface();
00173     slotUpdateStrigiStatus();
00174 
00175     emit changed(false);
00176 }
00177 
00178 
00179 void Nepomuk::ServerConfigModule::defaults()
00180 {
00181     m_checkEnableStrigi->setChecked( true );
00182     m_checkEnableNepomuk->setChecked( true );
00183     m_editStrigiExcludeFilters->setItems( defaultExcludeFilters() );
00184     m_folderModel->setFolders( defaultFolders(), QStringList() );
00185 }
00186 
00187 
00188 void Nepomuk::ServerConfigModule::slotUpdateStrigiStatus()
00189 {
00190     if ( m_strigiInterface->isValid() ) {
00191         bool indexing = m_strigiInterface->isIndexing();
00192         bool suspended = m_strigiInterface->isSuspended();
00193         QString folder = m_strigiInterface->currentFolder();
00194 
00195         if ( m_strigiInterface->lastError().isValid() )
00196             m_labelStrigiStatus->setText( i18nc( "@info:status %1 is an error message returned by a dbus interface.",
00197                                                  "Failed to contact Strigi indexer (%1)",
00198                                                  m_strigiInterface->lastError().message() ) );
00199         else if ( suspended )
00200             m_labelStrigiStatus->setText( i18nc( "@info_status", "File indexer is suspended" ) );
00201         else if ( indexing )
00202             m_labelStrigiStatus->setText( i18nc( "@info_status", "Strigi is currently indexing files in folder %1", folder ) );
00203         else
00204             m_labelStrigiStatus->setText( i18nc( "@info_status", "File indexer is idle" ) );
00205     }
00206     else {
00207         m_labelStrigiStatus->setText( i18nc( "@info_status", "Strigi service not running." ) );
00208     }
00209 }
00210 
00211 
00212 void Nepomuk::ServerConfigModule::recreateStrigiInterface()
00213 {
00214     delete m_strigiInterface;
00215     m_strigiInterface = new org::kde::nepomuk::Strigi( "org.kde.nepomuk.services.nepomukstrigiservice", "/nepomukstrigiservice", QDBusConnection::sessionBus() );
00216     connect( m_strigiInterface, SIGNAL( indexingStarted() ),
00217              this, SLOT( slotUpdateStrigiStatus() ) );
00218     connect( m_strigiInterface, SIGNAL( indexingStopped() ),
00219              this, SLOT( slotUpdateStrigiStatus() ) );
00220     connect( m_strigiInterface, SIGNAL( indexingFolder(QString) ),
00221              this, SLOT( slotUpdateStrigiStatus() ) );
00222 }
00223 
00224 #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.7
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