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 "nepomukcore.h"
20 #include "repository.h"
23 #include <KSharedConfig>
24 #include <KConfigGroup>
25 #include <KStandardDirs>
27 #include <QtCore/QTimer>
29 #include <Soprano/BackendSetting>
32 Nepomuk::Core::Core( QObject
* parent
)
33 : Soprano::Server::ServerCore( parent
)
38 Nepomuk::Core::~Core()
40 kDebug(300002) << "Shutting down Nepomuk storage core.";
42 KSharedConfig::Ptr config
= KSharedConfig::openConfig( "nepomukserverrc" );
43 config
->group( "Basic Settings" ).writeEntry( "Configured repositories", m_repositories
.keys() );
47 void Nepomuk::Core::init()
49 // TODO: export the main model on org.kde.NepomukRepository via Soprano::Server::DBusExportModel
51 m_failedToOpenRepository
= false;
53 KSharedConfig::Ptr config
= KSharedConfig::openConfig( "nepomukserverrc" );
55 const Soprano::Backend
* backend
= Repository::activeSopranoBackend();
57 m_openingRepositories
= config
->group( "Basic Settings" ).readEntry( "Configured repositories", QStringList() << "main" );
58 if ( !m_openingRepositories
.contains( "main" ) ) {
59 m_openingRepositories
<< "main";
62 foreach( const QString
&repoName
, m_openingRepositories
) {
63 createRepository( repoName
);
66 if ( m_openingRepositories
.isEmpty() ) {
67 emit
initializationDone( !m_failedToOpenRepository
);
71 kError() << "No Soprano backend found. Cannot start Nepomuk repository.";
76 bool Nepomuk::Core::initialized() const
78 return m_openingRepositories
.isEmpty() && !m_repositories
.isEmpty();
82 void Nepomuk::Core::createRepository( const QString
& name
)
84 Repository
* repo
= new Repository( name
);
85 m_repositories
.insert( name
, repo
);
86 connect( repo
, SIGNAL( opened( Repository
*, bool ) ),
87 this, SLOT( slotRepositoryOpened( Repository
*, bool ) ) );
88 QTimer::singleShot( 0, repo
, SLOT( open() ) );
90 // make sure ServerCore knows about the repo (important for memory management)
95 void Nepomuk::Core::slotRepositoryOpened( Repository
* repo
, bool success
)
97 m_failedToOpenRepository
= m_failedToOpenRepository
&& !success
;
98 m_openingRepositories
.removeAll( repo
->name() );
99 if ( m_openingRepositories
.isEmpty() ) {
100 emit
initializationDone( !m_failedToOpenRepository
);
105 Soprano::Model
* Nepomuk::Core::model( const QString
& name
)
107 // we need the name of the model for the repository creation
108 // but on the other hand want to use the AsyncModel stuff from
109 // ServerCore. Thus, we have to hack a bit
110 m_currentRepoName
= name
;
111 return ServerCore::model( name
);
115 Soprano::Model
* Nepomuk::Core::createModel( const QList
<Soprano::BackendSetting
>& )
117 // use the name we cached in model()
118 if ( !m_repositories
.contains( m_currentRepoName
) ) {
119 kDebug(300002) << "Creating new repository with name " << m_currentRepoName
;
121 // FIXME: There should be no need for conversion but who knows...
122 Repository
* newRepo
= new Repository( m_currentRepoName
);
123 m_repositories
.insert( m_currentRepoName
, newRepo
);
128 return m_repositories
[m_currentRepoName
];
133 void Nepomuk::Core::optimize( const QString
& name
)
135 if ( m_repositories
.contains( name
) )
136 m_repositories
[name
]->optimize();
139 #include "nepomukcore.moc"