1 | /* This file is part of the KDE project |
2 | Copyright (C) 2008 Omat Holding B.V. <info@omat.nl> |
3 | |
4 | This program is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. |
8 | |
9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | */ |
18 | |
19 | #include "global.h" |
20 | |
21 | #include <QString> |
22 | #include <QSettings> |
23 | |
24 | #include <akonadi/private/xdgbasedirs_p.h> |
25 | |
26 | using namespace Akonadi; |
27 | |
28 | namespace Tray |
29 | { |
30 | |
31 | void Global::init() |
32 | { |
33 | const QString serverConfigFile = XdgBaseDirs::akonadiServerConfigFile( XdgBaseDirs::ReadWrite ); |
34 | QSettings settings( serverConfigFile, QSettings::IniFormat ); |
35 | |
36 | m_dbdriver = settings.value( QLatin1String("General/Driver" ), QLatin1String("QMYSQL" ) ).toString(); |
37 | settings.beginGroup( m_dbdriver ); |
38 | |
39 | if( m_dbdriver == QLatin1String("QPSQL" ) ) { |
40 | m_dbname = settings.value( QLatin1String("Name" ), QLatin1String("akonadi" ) ).toString(); |
41 | m_dboptions.append( QLatin1String("--host=" ) + settings.value( QLatin1String("Host" ), QString() ).toString() ); |
42 | // If the server is started by the user, we don't need to know the username/password. |
43 | bool startServer = settings.value( QLatin1String("StartServer" ), QLatin1String("true" ) ).toBool(); |
44 | if( !startServer ) { |
45 | // TODO: postgres will always ask for the user password ! implement .pgpass |
46 | m_dboptions.append( QLatin1String("--username=" ) + settings.value( QLatin1String("User" ), QString() ).toString() ); |
47 | } |
48 | settings.endGroup(); |
49 | m_parsed = true; |
50 | } |
51 | |
52 | else if( m_dbdriver == QLatin1String("QMYSQL" ) ) { |
53 | m_dbname = settings.value( QLatin1String("Name" ), QLatin1String("akonadi" ) ).toString(); |
54 | // If the server is started by the user, we don't need to know the username/password. |
55 | bool startServer = settings.value( QLatin1String("StartServer" ), QString() ).toBool(); |
56 | if( !startServer ) { |
57 | m_dboptions.append( QLatin1String("--host=" ) + settings.value( QLatin1String("Host" ), QString() ).toString() ); |
58 | m_dboptions.append( QLatin1String("--user=" ) + settings.value( QLatin1String("User" ), QString() ).toString() ); |
59 | m_dboptions.append( QLatin1String("--password=" ) + settings.value( QLatin1String("Password" ), QString() ).toString() ); |
60 | } |
61 | else { |
62 | const QString options = settings.value( QLatin1String("Options" ), QString() ).toString(); |
63 | const QStringList list = options.split( QLatin1Char('=') ); |
64 | if( list.count() == 2 ) |
65 | m_dboptions.append( QLatin1String("--socket=" ) + list.at( 1 ) ); |
66 | else { |
67 | m_parsed = false; |
68 | return; |
69 | } |
70 | } |
71 | |
72 | settings.endGroup(); |
73 | m_parsed = true; |
74 | } |
75 | |
76 | else { |
77 | m_parsed = false; |
78 | } |
79 | } |
80 | |
81 | const QString Global::dbdriver() |
82 | { |
83 | if ( !m_parsed ) |
84 | init(); |
85 | |
86 | return m_dbdriver; |
87 | |
88 | } |
89 | |
90 | const QStringList Global::dboptions() |
91 | { |
92 | if ( !m_parsed ) |
93 | init(); |
94 | |
95 | return m_dboptions; |
96 | } |
97 | |
98 | const QString Global::dbname() |
99 | { |
100 | if ( !m_parsed ) |
101 | init(); |
102 | |
103 | return m_dbname; |
104 | } |
105 | |
106 | } |
107 | |