• Skip to content
  • Skip to link menu
KDE 4.1 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     // FIXME: export the main model on org.kde.NepomukRepository via Soprano::Server::DBusExportModel
00050 
00051     KSharedConfig::Ptr config = KSharedConfig::openConfig( "nepomukserverrc" );
00052 
00053     const Soprano::Backend* backend = Repository::activeSopranoBackend();
00054     if ( backend ) {
00055         m_openingRepositories = config->group( "Basic Settings" ).readEntry( "Configured repositories", QStringList() << "main" );
00056         if ( !m_openingRepositories.contains( "main" ) ) {
00057             m_openingRepositories << "main";
00058         }
00059 
00060         foreach( const QString &repoName, m_openingRepositories ) {
00061             createRepository( repoName );
00062         }
00063 
00064         if ( m_openingRepositories.isEmpty() ) {
00065             emit initializationDone( true );
00066         }
00067     }
00068     else {
00069         kError() << "No Soprano backend found. Cannot start Nepomuk repository.";
00070     }
00071 }
00072 
00073 
00074 bool Nepomuk::Core::initialized() const
00075 {
00076     return m_openingRepositories.isEmpty() && !m_repositories.isEmpty();
00077 }
00078 
00079 
00080 void Nepomuk::Core::createRepository( const QString& name )
00081 {
00082     Repository* repo = new Repository( name );
00083     m_repositories.insert( name, repo );
00084     connect( repo, SIGNAL( opened( Repository*, bool ) ),
00085              this, SLOT( slotRepositoryOpened( Repository*, bool ) ) );
00086     QTimer::singleShot( 0, repo, SLOT( open() ) );
00087 
00088     // make sure ServerCore knows about the repo (important for memory management)
00089     model( name );
00090 }
00091 
00092 
00093 void Nepomuk::Core::slotRepositoryOpened( Repository* repo, bool /*success*/ )
00094 {
00095     // FIXME: do something with success
00096     m_openingRepositories.removeAll( repo->name() );
00097     if ( m_openingRepositories.isEmpty() ) {
00098         emit initializationDone( true );
00099     }
00100 }
00101 
00102 
00103 Soprano::Model* Nepomuk::Core::model( const QString& name )
00104 {
00105     // we need the name of the model for the repository creation
00106     // but on the other hand want to use the AsyncModel stuff from
00107     // ServerCore. Thus, we have to hack a bit
00108     m_currentRepoName = name;
00109     return ServerCore::model( name );
00110 }
00111 
00112 
00113 Soprano::Model* Nepomuk::Core::createModel( const QList<Soprano::BackendSetting>& )
00114 {
00115     // use the name we cached in model()
00116     if ( !m_repositories.contains( m_currentRepoName ) ) {
00117         kDebug(300002) << "Creating new repository with name " << m_currentRepoName;
00118 
00119         // FIXME: There should be no need for conversion but who knows...
00120         Repository* newRepo = new Repository( m_currentRepoName );
00121         m_repositories.insert( m_currentRepoName, newRepo );
00122         newRepo->open();
00123         return newRepo;
00124     }
00125     else {
00126         return m_repositories[m_currentRepoName];
00127     }
00128 }
00129 
00130 #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.4
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