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

NepomukDaemons

nepomukcore.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 "nepomukcore.h"
00020 #include "repository.h"
00021 
00022 #include <KDebug>
00023 #include <KSharedConfig>
00024 #include <KConfigGroup>
00025 #include <KStandardDirs>
00026 
00027 #include <QtCore/QTimer>
00028 
00029 #include <Soprano/BackendSetting>
00030 
00031 
00032 Nepomuk::Core::Core( QObject* parent )
00033     : Soprano::Server::ServerCore( parent )
00034 {
00035 }
00036 
00037 
00038 Nepomuk::Core::~Core()
00039 {
00040     kDebug(300002) << "Shutting down Nepomuk storage core.";
00041 
00042     KSharedConfig::Ptr config = KSharedConfig::openConfig( "nepomukserverrc" );
00043     config->group( "Basic Settings" ).writeEntry( "Configured repositories", m_repositories.keys() );
00044 }
00045 
00046 
00047 void Nepomuk::Core::init()
00048 {
00049     // TODO: export the main model on org.kde.NepomukRepository via Soprano::Server::DBusExportModel
00050 
00051     m_failedToOpenRepository = false;
00052 
00053     KSharedConfig::Ptr config = KSharedConfig::openConfig( "nepomukserverrc" );
00054 
00055     const Soprano::Backend* backend = Repository::activeSopranoBackend();
00056     if ( backend ) {
00057         m_openingRepositories = config->group( "Basic Settings" ).readEntry( "Configured repositories", QStringList() << "main" );
00058         if ( !m_openingRepositories.contains( "main" ) ) {
00059             m_openingRepositories << "main";
00060         }
00061 
00062         foreach( const QString &repoName, m_openingRepositories ) {
00063             createRepository( repoName );
00064         }
00065 
00066         if ( m_openingRepositories.isEmpty() ) {
00067             emit initializationDone( !m_failedToOpenRepository );
00068         }
00069     }
00070     else {
00071         kError() << "No Soprano backend found. Cannot start Nepomuk repository.";
00072     }
00073 }
00074 
00075 
00076 bool Nepomuk::Core::initialized() const
00077 {
00078     return m_openingRepositories.isEmpty() && !m_repositories.isEmpty();
00079 }
00080 
00081 
00082 void Nepomuk::Core::createRepository( const QString& name )
00083 {
00084     Repository* repo = new Repository( name );
00085     m_repositories.insert( name, repo );
00086     connect( repo, SIGNAL( opened( Repository*, bool ) ),
00087              this, SLOT( slotRepositoryOpened( Repository*, bool ) ) );
00088     QTimer::singleShot( 0, repo, SLOT( open() ) );
00089 
00090     // make sure ServerCore knows about the repo (important for memory management)
00091     model( name );
00092 }
00093 
00094 
00095 void Nepomuk::Core::slotRepositoryOpened( Repository* repo, bool success )
00096 {
00097     m_failedToOpenRepository = m_failedToOpenRepository && !success;
00098     m_openingRepositories.removeAll( repo->name() );
00099     if ( m_openingRepositories.isEmpty() ) {
00100         emit initializationDone( !m_failedToOpenRepository );
00101     }
00102 }
00103 
00104 
00105 Soprano::Model* Nepomuk::Core::model( const QString& name )
00106 {
00107     // we need the name of the model for the repository creation
00108     // but on the other hand want to use the AsyncModel stuff from
00109     // ServerCore. Thus, we have to hack a bit
00110     m_currentRepoName = name;
00111     return ServerCore::model( name );
00112 }
00113 
00114 
00115 Soprano::Model* Nepomuk::Core::createModel( const QList<Soprano::BackendSetting>& )
00116 {
00117     // use the name we cached in model()
00118     if ( !m_repositories.contains( m_currentRepoName ) ) {
00119         kDebug(300002) << "Creating new repository with name " << m_currentRepoName;
00120 
00121         // FIXME: There should be no need for conversion but who knows...
00122         Repository* newRepo = new Repository( m_currentRepoName );
00123         m_repositories.insert( m_currentRepoName, newRepo );
00124         newRepo->open();
00125         return newRepo;
00126     }
00127     else {
00128         return m_repositories[m_currentRepoName];
00129     }
00130 }
00131 
00132 
00133 void Nepomuk::Core::optimize( const QString& name )
00134 {
00135     if ( m_repositories.contains( name ) )
00136         m_repositories[name]->optimize();
00137 }
00138 
00139 #include "nepomukcore.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