Improve sword modules interface
[kworship.git] / kworship / prefsSongDB.cpp
blob11fe8235fe0174cc162293360940f7e0606c4ac9
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 prefsSongDB.h
22 * @brief SongDB preferences interface.
23 * @author James Hogan <james@albanarts.com>
26 #include "prefsSongDB.h"
27 #include "KwDatabaseSetup.h"
29 #include <QMessageBox>
32 * Constructors + destructor
35 /// Primary constructor
36 prefsSongDB::prefsSongDB(QWidget *parent)
37 : QWidget(parent)
38 , Ui::prefsSongDB_base()
40 setupUi(this);
42 connect(kcfg_songdbType, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeDatabaseType(QString)));
43 connect(buttonTest, SIGNAL(clicked()), this, SLOT(testConnectionSettings()));
44 connect(kcfg_songdbLocationCustom, SIGNAL(toggled(bool)), frameLocationCustom, SLOT(setEnabled(bool)));
47 /// Destructor.
48 prefsSongDB::~prefsSongDB()
53 * Slots
56 /// Database type has changed.
57 void prefsSongDB::changeDatabaseType(QString newType)
59 bool serverless = (newType == "SQLite");
60 groupConnection->setVisible(!serverless);
61 groupFile->setVisible(serverless);
62 if (serverless)
64 if (newType == "SQLite")
66 kcfg_songdbLocation->setFilter("*.db|SQLite Databases (*.db)");
71 /// Test connection settings.
72 void prefsSongDB::testConnectionSettings()
74 KwDatabaseSetup setup(true);
75 QString type = kcfg_songdbType->currentText();
76 if (type == "MySQL")
78 type = "QMYSQL";
80 else if (type == "PostgreSQL")
82 type = "QPSQL";
84 QString host = kcfg_songdbHost->text();
85 QString name = kcfg_songdbName->text();
86 QString username = kcfg_songdbUsername->text();
87 QString password = kcfg_songdbPassword->text();
88 bool worked = setup.initialiseConnection(type, host, name, username, password);
90 if (worked)
92 QMessageBox::information(this, i18n("Success"), i18n("Successfully connected to the database using the provided settings."), QMessageBox::Ok);
94 else
96 QMessageBox::warning(this, i18n("Failure"), i18n("Could not connect to the database using the provided settings. Please check the settings and try again."), QMessageBox::Ok);