Minor tweak to unised KwKWorshipFilterData
[kworship.git] / kworship / prefsDatabase.cpp
blob780143dd474bb68e0571f9faa0579ac589e0c7ac
1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 /**
21 * @file prefsDatabase.h
22 * @brief Database preferences interface.
23 * @author James Hogan <james@albanarts.com>
26 #include "prefsDatabase.h"
27 #include "KwDatabaseSetup.h"
29 #include <QMessageBox>
30 #include <QSqlError>
33 * Constructors + destructor
36 /// Primary constructor
37 prefsDatabase::prefsDatabase(QWidget *parent)
38 : QWidget(parent)
39 , Ui::prefsDatabase_base()
41 setupUi(this);
43 connect(kcfg_databaseType, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeDatabaseType(QString)));
44 connect(buttonTest, SIGNAL(clicked()), this, SLOT(testConnectionSettings()));
45 connect(kcfg_databaseLocationCustom, SIGNAL(toggled(bool)), frameLocationCustom, SLOT(setEnabled(bool)));
48 /// Destructor.
49 prefsDatabase::~prefsDatabase()
54 * Slots
57 /// Database type has changed.
58 void prefsDatabase::changeDatabaseType(QString newType)
60 bool serverless = (newType == "SQLite");
61 groupConnection->setVisible(!serverless);
62 groupFile->setVisible(serverless);
63 if (serverless)
65 if (newType == "SQLite")
67 kcfg_databaseLocation->setFilter("*.db|SQLite Databases (*.db)");
72 /// Test connection settings.
73 void prefsDatabase::testConnectionSettings()
75 KwDatabaseSetup setup(true);
76 QString type = kcfg_databaseType->currentText();
77 if (type == "MySQL")
79 type = "QMYSQL";
81 else if (type == "PostgreSQL")
83 type = "QPSQL";
85 QString host = kcfg_databaseHost->text();
86 QString name = kcfg_databaseName->text();
87 QString username = kcfg_databaseUsername->text();
88 QString password = kcfg_databasePassword->text();
89 bool worked = setup.initialiseConnection(type, host, name, username, password);
91 if (worked)
93 QMessageBox::information(this, i18n("Success"), i18n("Successfully connected to the database using the provided settings."), QMessageBox::Ok);
95 else
97 QMessageBox::warning(this, i18n("Failure"), i18n("Could not connect to the database using the provided settings. Please check the settings and try again.\n\n%1", setup.database().lastError().text()), QMessageBox::Ok);