typo found by Andrey Cherepanov
[kdepim.git] / akonadiconsole / dbaccess.cpp
blob261cb3e2041e77f2d45c138c7cad5739acff54e4
1 /*
2 Copyright (c) 2009 Volker Krause <vkrause@kde.org>
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
20 #include "dbaccess.h"
22 #include <akonadi/private/xdgbasedirs_p.h>
24 #include <QSettings>
25 #include <QSqlDatabase>
26 #include <QSqlError>
28 #include <KGlobal>
29 #include <KLocale>
30 #include <KMessageBox>
32 using namespace Akonadi;
34 class DbAccessPrivate
36 public:
37 DbAccessPrivate()
39 const QString serverConfigFile = XdgBaseDirs::akonadiServerConfigFile( XdgBaseDirs::ReadWrite );
40 QSettings settings( serverConfigFile, QSettings::IniFormat );
42 const QString driver = settings.value( "General/Driver", "QMYSQL" ).toString();
43 database = QSqlDatabase::addDatabase( driver );
44 settings.beginGroup( driver );
45 database.setHostName( settings.value( "Host", QString() ).toString() );
46 database.setDatabaseName( settings.value( "Name", "akonadi" ).toString() );
47 database.setUserName( settings.value( "User", QString() ).toString() );
48 database.setPassword( settings.value( "Password", QString() ).toString() );
49 database.setConnectOptions( settings.value( "Options", QString() ).toString() );
50 if ( !database.open() ) {
51 KMessageBox::error( 0, i18n( "Failed to connect to database: %1", database.lastError().text() ) );
55 QSqlDatabase database;
58 K_GLOBAL_STATIC( DbAccessPrivate, sInstance )
60 QSqlDatabase DbAccess::database()
62 return sInstance->database;