LeechCraft  0.6.70-10870-g558588d6ec
Modular cross-platform feature rich live environment.
backendselector.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #include "backendselector.h"
31 #include <QSqlDatabase>
32 #include "ui_backendselector.h"
33 #include "../xmlsettingsdialog/basesettingsmanager.h"
34 
35 using namespace LeechCraft::Util;
36 
37 BackendSelector::BackendSelector (BaseSettingsManager *m,
38  QWidget *parent)
39 : QWidget (parent)
40 , Manager_ (m)
41 {
42  Ui_ = new Ui::BackendSelector;
43  Ui_->setupUi (this);
44 
45  FillUI ();
46 
47  // We should check from last to first
48  if (!QSqlDatabase::isDriverAvailable ("QMYSQL"))
49  {
50  Ui_->MySQLSettings_->setEnabled (false);
51  Ui_->StorageType_->removeItem (2);
52  }
53  if (!QSqlDatabase::isDriverAvailable ("QPSQL"))
54  {
55  Ui_->PostgreSQLSettings_->setEnabled (false);
56  Ui_->StorageType_->removeItem (1);
57  }
58 }
59 
60 void BackendSelector::FillUI ()
61 {
62  int index = Ui_->StorageType_->
63  findText (Manager_->
64  Property ("StorageType", "SQLite").toString ());
65  Ui_->StorageType_->setCurrentIndex (index);
66  Ui_->Settings_->setCurrentIndex (index);
67 
68  Ui_->SQLiteVacuum_->setCheckState (Manager_->
69  Property ("SQLiteVacuum", false).toBool () ?
70  Qt::Checked :
71  Qt::Unchecked);
72  Ui_->SQLiteJournalMode_->setCurrentIndex (Ui_->SQLiteJournalMode_->
73  findText (Manager_->
74  Property ("SQLiteJournalMode", "TRUNCATE").toString ()));
75  Ui_->SQLiteTempStore_->setCurrentIndex (Ui_->SQLiteTempStore_->
76  findText (Manager_->
77  Property ("SQLiteTempStore", "MEMORY").toString ()));
78  Ui_->SQLiteSynchronous_->setCurrentIndex (Ui_->SQLiteSynchronous_->
79  findText (Manager_->
80  Property ("SQLiteSynchronous", "OFF").toString ()));
81 
82  Ui_->PostgresHostname_->setText (Manager_->
83  Property ("PostgresHostname", "localhost").toString ());
84  Ui_->PostgresPort_->setValue (Manager_->
85  Property ("PostgresPort", 5432).toInt ());
86  Ui_->PostgresDBName_->setText (Manager_->
87  Property ("PostgresDBName", "").toString ());
88  Ui_->PostgresUsername_->setText (Manager_->
89  Property ("PostgresUsername", "").toString ());
90  Ui_->PostgresPassword_->setText (Manager_->
91  Property ("PostgresPassword", "").toString ());
92 
93  Ui_->MysqlHostname_->setText (Manager_->
94  Property ("MysqlHostname", "localhost").toString ());
95  Ui_->MysqlPort_->setValue (Manager_->
96  Property ("MysqlPort", 5432).toInt ());
97  Ui_->MysqlDBName_->setText (Manager_->
98  Property ("MysqlDBName", "").toString ());
99  Ui_->MysqlUsername_->setText (Manager_->
100  Property ("MysqlUsername", "").toString ());
101  Ui_->MysqlPassword_->setText (Manager_->
102  Property ("MysqlPassword", "").toString ());
103 }
104 
106 {
107  Manager_->setProperty ("StorageType",
108  Ui_->StorageType_->currentText ());
109 
110  Manager_->setProperty ("SQLiteVacuum",
111  Ui_->SQLiteVacuum_->checkState () == Qt::Checked);
112  Manager_->setProperty ("SQLiteJournalMode",
113  Ui_->SQLiteJournalMode_->currentText ());
114  Manager_->setProperty ("SQLiteTempStore",
115  Ui_->SQLiteTempStore_->currentText ());
116  Manager_->setProperty ("SQLiteSynchronous",
117  Ui_->SQLiteSynchronous_->currentText ());
118 
119  Manager_->setProperty ("PostgresHostname",
120  Ui_->PostgresHostname_->text ());
121  Manager_->setProperty ("PostgresPort",
122  Ui_->PostgresPort_->value ());
123  Manager_->setProperty ("PostgresDBName",
124  Ui_->PostgresDBName_->text ());
125  Manager_->setProperty ("PostgresUsername",
126  Ui_->PostgresUsername_->text ());
127  Manager_->setProperty ("PostgresPassword",
128  Ui_->PostgresPassword_->text ());
129 
130  Manager_->setProperty ("MysqlHostname",
131  Ui_->MysqlHostname_->text ());
132  Manager_->setProperty ("MysqlPort",
133  Ui_->MysqlPort_->value ());
134  Manager_->setProperty ("MysqlDBName",
135  Ui_->MysqlDBName_->text ());
136  Manager_->setProperty ("MysqlUsername",
137  Ui_->MysqlUsername_->text ());
138  Manager_->setProperty ("MysqlPassword",
139  Ui_->MysqlPassword_->text ());
140 }
141 
143 {
144  FillUI ();
145 }
146 
BackendSelector(BaseSettingsManager *manager, QWidget *parent=0)
Constructs the BackendSelector.
void accept()
Updates the settings manager.
void reject()
Restores the settings in UI.
char * toString(const char *name, const T &t)
Definition: common.h:56