NepomukDaemons
nepomukserver.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 "nepomukserver.h" 00020 #include "nepomukserveradaptor.h" 00021 #include "nepomukserversettings.h" 00022 #include "servicemanager.h" 00023 #include "servicemanageradaptor.h" 00024 #include "legacystoragebridge.h" 00025 00026 #include <Soprano/Global> 00027 00028 #include <KConfig> 00029 #include <KConfigGroup> 00030 #include <KDebug> 00031 #include <KGlobal> 00032 #include <KStandardDirs> 00033 00034 #include <QtDBus/QDBusConnection> 00035 00036 00037 Nepomuk::Server* Nepomuk::Server::s_self = 0; 00038 00039 Nepomuk::Server::Server( QObject* parent ) 00040 : QObject( parent ), 00041 m_enabled( false ), 00042 m_legacyStorageBridge( 0 ), 00043 m_strigiServiceName( "nepomukstrigiservice" ) 00044 { 00045 s_self = this; 00046 00047 m_config = KSharedConfig::openConfig( "nepomukserverrc" ); 00048 00049 QDBusConnection::sessionBus().registerService( "org.kde.NepomukServer" ); 00050 00051 // register the nepomuk server adaptor 00052 (void)new NepomukServerAdaptor( this ); 00053 QDBusConnection::sessionBus().registerObject( "/nepomukserver", this ); 00054 00055 // create the service manager. 00056 m_serviceManager = new ServiceManager( this ); 00057 (void)new ServiceManagerAdaptor( m_serviceManager ); 00058 00059 // initialize according to config 00060 init(); 00061 } 00062 00063 00064 Nepomuk::Server::~Server() 00065 { 00066 m_serviceManager->stopAllServices(); 00067 NepomukServerSettings::self()->writeConfig(); 00068 QDBusConnection::sessionBus().unregisterService( "org.kde.NepomukServer" ); 00069 } 00070 00071 00072 void Nepomuk::Server::init() 00073 { 00074 // no need to start strigi explicetely. it is done in enableNepomuk 00075 enableNepomuk( NepomukServerSettings::self()->startNepomuk() ); 00076 } 00077 00078 00079 void Nepomuk::Server::enableNepomuk( bool enabled ) 00080 { 00081 kDebug(300002) << "enableNepomuk" << enabled; 00082 if ( enabled != m_enabled ) { 00083 if ( enabled ) { 00084 // start all autostart services 00085 m_serviceManager->startAllServices(); 00086 00087 // register the service manager interface 00088 QDBusConnection::sessionBus().registerObject( "/servicemanager", m_serviceManager ); 00089 00090 // provide the storage interface for backwards compatibility 00091 if ( !m_legacyStorageBridge ) { 00092 m_legacyStorageBridge = new LegacyStorageBridge( this ); 00093 } 00094 00095 // now nepomuk is enabled 00096 m_enabled = true; 00097 } 00098 else { 00099 // stop all running services 00100 m_serviceManager->stopAllServices(); 00101 00102 // unregister the service manager interface 00103 QDBusConnection::sessionBus().unregisterObject( "/servicemanager" ); 00104 00105 // we delete since Soprano::Server::ServerCore does not have an unregister method yet 00106 delete m_legacyStorageBridge; 00107 m_legacyStorageBridge = 0; 00108 00109 // nepomuk is disabled 00110 m_enabled = false; 00111 } 00112 } 00113 } 00114 00115 00116 void Nepomuk::Server::enableStrigi( bool enabled ) 00117 { 00118 kDebug(300002) << enabled; 00119 if ( isNepomukEnabled() ) { 00120 if ( enabled ) { 00121 m_serviceManager->startService( m_strigiServiceName ); 00122 } 00123 else { 00124 m_serviceManager->stopService( m_strigiServiceName ); 00125 } 00126 } 00127 00128 KConfigGroup config( m_config, QString("Service-%1").arg(m_strigiServiceName) ); 00129 config.writeEntry( "autostart", enabled ); 00130 } 00131 00132 00133 bool Nepomuk::Server::isNepomukEnabled() const 00134 { 00135 return m_enabled; 00136 } 00137 00138 00139 bool Nepomuk::Server::isStrigiEnabled() const 00140 { 00141 return m_serviceManager->runningServices().contains( m_strigiServiceName ); 00142 } 00143 00144 00145 QString Nepomuk::Server::defaultRepository() const 00146 { 00147 return "main"; 00148 } 00149 00150 00151 void Nepomuk::Server::reconfigure() 00152 { 00153 NepomukServerSettings::self()->config()->sync(); 00154 NepomukServerSettings::self()->readConfig(); 00155 init(); 00156 } 00157 00158 00159 void Nepomuk::Server::quit() 00160 { 00161 QCoreApplication::instance()->quit(); 00162 } 00163 00164 00165 KSharedConfig::Ptr Nepomuk::Server::config() const 00166 { 00167 return m_config; 00168 } 00169 00170 00171 Nepomuk::Server* Nepomuk::Server::self() 00172 { 00173 return s_self; 00174 } 00175 00176 #include "nepomukserver.moc"