LeechCraft  0.6.70-13729-g7046a9d2a7
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 LC::Util;
36 
37 BackendSelector::BackendSelector (BaseSettingsManager *m, QWidget *parent)
38 : QWidget (parent)
39 , Manager_ (m)
40 {
41  Ui_ = new Ui::BackendSelector;
42  Ui_->setupUi (this);
43 
44  FillUI ();
45 
46  // We should check from last to first
47  if (!QSqlDatabase::isDriverAvailable ("QMYSQL"))
48  {
49  Ui_->MySQLSettings_->setEnabled (false);
50  Ui_->StorageType_->removeItem (2);
51  }
52  if (!QSqlDatabase::isDriverAvailable ("QPSQL"))
53  {
54  Ui_->PostgreSQLSettings_->setEnabled (false);
55  Ui_->StorageType_->removeItem (1);
56  }
57 }
58 
59 void BackendSelector::FillUI ()
60 {
61  int index = Ui_->StorageType_->findText (Manager_->Property ("StorageType", "SQLite").toString ());
62  Ui_->StorageType_->setCurrentIndex (index);
63  Ui_->Settings_->setCurrentIndex (index);
64 
65  Ui_->PostgresHostname_->setText (Manager_->Property ("PostgresHostname", "localhost").toString ());
66  Ui_->PostgresPort_->setValue (Manager_->Property ("PostgresPort", 5432).toInt ());
67  Ui_->PostgresDBName_->setText (Manager_->Property ("PostgresDBName", "").toString ());
68  Ui_->PostgresUsername_->setText (Manager_->Property ("PostgresUsername", "").toString ());
69  Ui_->PostgresPassword_->setText (Manager_->Property ("PostgresPassword", "").toString ());
70 
71  Ui_->MysqlHostname_->setText (Manager_->Property ("MysqlHostname", "localhost").toString ());
72  Ui_->MysqlPort_->setValue (Manager_->Property ("MysqlPort", 5432).toInt ());
73  Ui_->MysqlDBName_->setText (Manager_->Property ("MysqlDBName", "").toString ());
74  Ui_->MysqlUsername_->setText (Manager_->Property ("MysqlUsername", "").toString ());
75  Ui_->MysqlPassword_->setText (Manager_->Property ("MysqlPassword", "").toString ());
76 }
77 
79 {
80  Manager_->setProperty ("StorageType", Ui_->StorageType_->currentText ());
81 
82  Manager_->setProperty ("PostgresHostname", Ui_->PostgresHostname_->text ());
83  Manager_->setProperty ("PostgresPort", Ui_->PostgresPort_->value ());
84  Manager_->setProperty ("PostgresDBName", Ui_->PostgresDBName_->text ());
85  Manager_->setProperty ("PostgresUsername", Ui_->PostgresUsername_->text ());
86  Manager_->setProperty ("PostgresPassword", Ui_->PostgresPassword_->text ());
87 
88  Manager_->setProperty ("MysqlHostname", Ui_->MysqlHostname_->text ());
89  Manager_->setProperty ("MysqlPort", Ui_->MysqlPort_->value ());
90  Manager_->setProperty ("MysqlDBName", Ui_->MysqlDBName_->text ());
91  Manager_->setProperty ("MysqlUsername", Ui_->MysqlUsername_->text ());
92  Manager_->setProperty ("MysqlPassword", Ui_->MysqlPassword_->text ());
93 }
94 
96 {
97  FillUI ();
98 }
99 
void accept()
Updates the settings manager.
void reject()
Restores the settings in UI.
BackendSelector(BaseSettingsManager *manager, QWidget *parent=0)
Constructs the BackendSelector.