add more spacing
[personal-kdebase.git] / runtime / nepomuk / server / nepomukserver.cpp
bloba11e06fcdee256c81757f9bfc98692181983c451
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 "nepomukserver.h"
20 #include "nepomukserveradaptor.h"
21 #include "nepomukserversettings.h"
22 #include "servicemanager.h"
23 #include "servicemanageradaptor.h"
24 #include "legacystoragebridge.h"
26 #include <Soprano/Global>
28 #include <KConfig>
29 #include <KConfigGroup>
30 #include <KDebug>
31 #include <KGlobal>
32 #include <KStandardDirs>
34 #include <QtDBus/QDBusConnection>
37 Nepomuk::Server* Nepomuk::Server::s_self = 0;
39 Nepomuk::Server::Server( QObject* parent )
40 : QObject( parent ),
41 m_enabled( false ),
42 m_legacyStorageBridge( 0 ),
43 m_strigiServiceName( "nepomukstrigiservice" )
45 s_self = this;
47 m_config = KSharedConfig::openConfig( "nepomukserverrc" );
49 QDBusConnection::sessionBus().registerService( "org.kde.NepomukServer" );
51 // register the nepomuk server adaptor
52 (void)new NepomukServerAdaptor( this );
53 QDBusConnection::sessionBus().registerObject( "/nepomukserver", this );
55 // create the service manager.
56 m_serviceManager = new ServiceManager( this );
57 (void)new ServiceManagerAdaptor( m_serviceManager );
59 // initialize according to config
60 init();
64 Nepomuk::Server::~Server()
66 m_serviceManager->stopAllServices();
67 NepomukServerSettings::self()->writeConfig();
68 QDBusConnection::sessionBus().unregisterService( "org.kde.NepomukServer" );
72 void Nepomuk::Server::init()
74 // no need to start strigi explicetely. it is done in enableNepomuk
75 enableNepomuk( NepomukServerSettings::self()->startNepomuk() );
79 void Nepomuk::Server::enableNepomuk( bool enabled )
81 kDebug(300002) << "enableNepomuk" << enabled;
82 if ( enabled != m_enabled ) {
83 if ( enabled ) {
84 // start all autostart services
85 m_serviceManager->startAllServices();
87 // register the service manager interface
88 QDBusConnection::sessionBus().registerObject( "/servicemanager", m_serviceManager );
90 // provide the storage interface for backwards compatibility
91 if ( !m_legacyStorageBridge ) {
92 m_legacyStorageBridge = new LegacyStorageBridge( this );
95 // now nepomuk is enabled
96 m_enabled = true;
98 else {
99 // stop all running services
100 m_serviceManager->stopAllServices();
102 // unregister the service manager interface
103 QDBusConnection::sessionBus().unregisterObject( "/servicemanager" );
105 // we delete since Soprano::Server::ServerCore does not have an unregister method yet
106 delete m_legacyStorageBridge;
107 m_legacyStorageBridge = 0;
109 // nepomuk is disabled
110 m_enabled = false;
116 void Nepomuk::Server::enableStrigi( bool enabled )
118 kDebug(300002) << enabled;
119 if ( isNepomukEnabled() ) {
120 if ( enabled ) {
121 m_serviceManager->startService( m_strigiServiceName );
123 else {
124 m_serviceManager->stopService( m_strigiServiceName );
128 KConfigGroup config( m_config, QString("Service-%1").arg(m_strigiServiceName) );
129 config.writeEntry( "autostart", enabled );
133 bool Nepomuk::Server::isNepomukEnabled() const
135 return m_enabled;
139 bool Nepomuk::Server::isStrigiEnabled() const
141 return m_serviceManager->runningServices().contains( m_strigiServiceName );
145 QString Nepomuk::Server::defaultRepository() const
147 return "main";
151 void Nepomuk::Server::reconfigure()
153 NepomukServerSettings::self()->config()->sync();
154 NepomukServerSettings::self()->readConfig();
155 init();
159 void Nepomuk::Server::quit()
161 QCoreApplication::instance()->quit();
165 KSharedConfig::Ptr Nepomuk::Server::config() const
167 return m_config;
171 Nepomuk::Server* Nepomuk::Server::self()
173 return s_self;
176 #include "nepomukserver.moc"