1 /* This file is part of the KDE Project
2 Copyright (c) 2007 Sebastian Trueg <trueg@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "nepomukserverkcm.h"
20 #include "nepomukserverinterface.h"
21 #include "folderselectionmodel.h"
23 #include <KPluginFactory>
24 #include <KPluginLoader>
26 #include <KSharedConfig>
28 #include <KMessageBox>
30 #include <QtGui/QTreeView>
32 #include <Soprano/PluginManager>
35 K_PLUGIN_FACTORY( NepomukConfigModuleFactory
, registerPlugin
<Nepomuk::ServerConfigModule
>(); )
36 K_EXPORT_PLUGIN( NepomukConfigModuleFactory("kcm_nepomuk", "nepomuk") )
40 QStringList
defaultFolders() {
41 return QStringList() << QDir::homePath();
44 QStringList
defaultExcludeFilters() {
45 return QStringList() << ".*/" << ".*" << "*~" << "*.part";
48 void expandRecursively( const QModelIndex
& index
, QTreeView
* view
) {
49 if ( index
.isValid() ) {
50 view
->expand( index
);
51 expandRecursively( index
.parent(), view
);
57 Nepomuk::ServerConfigModule::ServerConfigModule( QWidget
* parent
, const QVariantList
& args
)
58 : KCModule( NepomukConfigModuleFactory::componentData(), parent
, args
),
59 m_serverInterface( "org.kde.NepomukServer", "/nepomukserver", QDBusConnection::sessionBus() ),
60 m_strigiInterface( 0 )
62 KAboutData
*about
= new KAboutData(
63 "kcm_nepomuk", 0, ki18n("Nepomuk Configuration Module"),
64 KDE_VERSION_STRING
, KLocalizedString(), KAboutData::License_GPL
,
65 ki18n("Copyright 2007 Sebastian Trüg"));
66 about
->addAuthor(ki18n("Sebastian Trüg"), KLocalizedString(), "trueg@kde.org");
68 setButtons(Apply
|Default
);
71 m_folderModel
= new FolderSelectionModel( m_viewIndexFolders
);
72 m_viewIndexFolders
->setModel( m_folderModel
);
73 m_viewIndexFolders
->setHeaderHidden( true );
74 m_viewIndexFolders
->setRootIsDecorated( true );
75 m_viewIndexFolders
->setAnimated( true );
76 m_viewIndexFolders
->setRootIndex( m_folderModel
->setRootPath( QDir::rootPath() ) );
78 connect( m_checkEnableStrigi
, SIGNAL( toggled(bool) ),
79 this, SLOT( changed() ) );
80 connect( m_checkEnableNepomuk
, SIGNAL( toggled(bool) ),
81 this, SLOT( changed() ) );
82 connect( m_folderModel
, SIGNAL( dataChanged(const QModelIndex
&, const QModelIndex
&) ),
83 this, SLOT( changed() ) );
84 connect( m_editStrigiExcludeFilters
, SIGNAL( changed() ),
85 this, SLOT( changed() ) );
87 connect( QDBusConnection::sessionBus().interface(),
88 SIGNAL( serviceOwnerChanged( const QString
&, const QString
&, const QString
& ) ),
90 SLOT( slotUpdateStrigiStatus() ) );
92 recreateStrigiInterface();
97 Nepomuk::ServerConfigModule::~ServerConfigModule()
99 delete m_strigiInterface
;
103 void Nepomuk::ServerConfigModule::load()
105 bool sopranoBackendAvailable
= !Soprano::PluginManager::instance()->allBackends().isEmpty();
107 m_checkEnableNepomuk
->setEnabled( sopranoBackendAvailable
);
109 if ( !sopranoBackendAvailable
) {
110 KMessageBox::sorry( this,
111 i18n( "No Soprano Database backend available. Please check your installation." ),
112 i18n( "Nepomuk cannot be started" ) );
114 else if ( m_serverInterface
.isValid() ) {
115 m_checkEnableStrigi
->setChecked( m_serverInterface
.isStrigiEnabled().value() );
116 m_checkEnableNepomuk
->setChecked( m_serverInterface
.isNepomukEnabled().value() );
119 KMessageBox::sorry( this,
120 i18n( "The Nepomuk Server is not running. The settings "
121 "will be used the next time the server is started." ),
122 i18n( "Nepomuk server not running" ) );
124 KConfig
config( "nepomukserverrc" );
125 m_checkEnableNepomuk
->setChecked( config
.group( "Basic Settings" ).readEntry( "Start Nepomuk", true ) );
126 m_checkEnableStrigi
->setChecked( config
.group( "Service-nepomukstrigiservice" ).readEntry( "autostart", true ) );
129 KConfig
strigiConfig( "nepomukstrigirc" );
130 m_folderModel
->setFolders( strigiConfig
.group( "General" ).readPathEntry( "folders", defaultFolders() ),
131 strigiConfig
.group( "General" ).readPathEntry( "exclude folders", QStringList() ) );
132 m_editStrigiExcludeFilters
->setItems( strigiConfig
.group( "General" ).readEntry( "exclude filters", defaultExcludeFilters() ) );
134 // make sure that the tree is expanded to show all selected items
135 foreach( const QString
& dir
, m_folderModel
->includeFolders() + m_folderModel
->excludeFolders() ) {
136 expandRecursively( m_folderModel
->index( dir
), m_viewIndexFolders
);
139 recreateStrigiInterface();
140 slotUpdateStrigiStatus();
145 void Nepomuk::ServerConfigModule::save()
147 // 1. change the settings (in case the server is not running)
148 KConfig
config( "nepomukserverrc" );
149 config
.group( "Basic Settings" ).writeEntry( "Start Nepomuk", m_checkEnableNepomuk
->isChecked() );
150 config
.group( "Service-nepomukstrigiservice" ).writeEntry( "autostart", m_checkEnableStrigi
->isChecked() );
153 // 2. update Strigi config
154 KConfig
strigiConfig( "nepomukstrigirc" );
155 strigiConfig
.group( "General" ).writePathEntry( "folders", m_folderModel
->includeFolders() );
156 strigiConfig
.group( "General" ).writePathEntry( "exclude folders", m_folderModel
->excludeFolders() );
157 strigiConfig
.group( "General" ).writeEntry( "exclude filters", m_editStrigiExcludeFilters
->items() );
160 // 3. update the current state of the nepomuk server
161 if ( m_serverInterface
.isValid() ) {
162 m_serverInterface
.enableNepomuk( m_checkEnableNepomuk
->isChecked() );
163 m_serverInterface
.enableStrigi( m_checkEnableStrigi
->isChecked() );
166 KMessageBox::sorry( this,
167 i18n( "The Nepomuk Server is not running. The settings have been saved "
168 "and will be used the next time the server is started." ),
169 i18n( "Nepomuk server not running" ) );
172 recreateStrigiInterface();
173 slotUpdateStrigiStatus();
179 void Nepomuk::ServerConfigModule::defaults()
181 m_checkEnableStrigi
->setChecked( true );
182 m_checkEnableNepomuk
->setChecked( true );
183 m_editStrigiExcludeFilters
->setItems( defaultExcludeFilters() );
184 m_folderModel
->setFolders( defaultFolders(), QStringList() );
188 void Nepomuk::ServerConfigModule::slotUpdateStrigiStatus()
190 if ( m_strigiInterface
->isValid() ) {
191 bool indexing
= m_strigiInterface
->isIndexing();
192 bool suspended
= m_strigiInterface
->isSuspended();
193 QString folder
= m_strigiInterface
->currentFolder();
195 if ( m_strigiInterface
->lastError().isValid() )
196 m_labelStrigiStatus
->setText( i18nc( "@info:status %1 is an error message returned by a dbus interface.",
197 "Failed to contact Strigi indexer (%1)",
198 m_strigiInterface
->lastError().message() ) );
199 else if ( suspended
)
200 m_labelStrigiStatus
->setText( i18nc( "@info_status", "File indexer is suspended" ) );
202 m_labelStrigiStatus
->setText( i18nc( "@info_status", "Strigi is currently indexing files in folder %1", folder
) );
204 m_labelStrigiStatus
->setText( i18nc( "@info_status", "File indexer is idle" ) );
207 m_labelStrigiStatus
->setText( i18nc( "@info_status", "Strigi service not running." ) );
212 void Nepomuk::ServerConfigModule::recreateStrigiInterface()
214 delete m_strigiInterface
;
215 m_strigiInterface
= new org::kde::nepomuk::Strigi( "org.kde.nepomuk.services.nepomukstrigiservice", "/nepomukstrigiservice", QDBusConnection::sessionBus() );
216 connect( m_strigiInterface
, SIGNAL( indexingStarted() ),
217 this, SLOT( slotUpdateStrigiStatus() ) );
218 connect( m_strigiInterface
, SIGNAL( indexingStopped() ),
219 this, SLOT( slotUpdateStrigiStatus() ) );
220 connect( m_strigiInterface
, SIGNAL( indexingFolder(QString
) ),
221 this, SLOT( slotUpdateStrigiStatus() ) );
224 #include "nepomukserverkcm.moc"