From 32afa2c28aabe862bfca44dba24083ffd7db6721 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 20 Aug 2016 18:29:52 +0200 Subject: Added configration dialog Database connection options are now configurable. Hopefully it doesn't end up in an infinite loop if the credentials are not corrent... --- shemovcleaner.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'shemovcleaner.cpp') diff --git a/shemovcleaner.cpp b/shemovcleaner.cpp index fb9b9e6..ec9d6e4 100644 --- a/shemovcleaner.cpp +++ b/shemovcleaner.cpp @@ -6,15 +6,21 @@ #include #include #include +#include +#include +#include #include "shemovcleaner.h" #include "torrentwidget.h" +#include "configurationwidget.h" ShemovCleaner::ShemovCleaner(QWidget *parent, Qt::WindowFlags f) : QMainWindow(parent, f) { //general setup qApp->setWindowIcon(QIcon(":/clean_tampon.png")); setMinimumWidth(800); setMinimumHeight(600); + openDatabase(); + mTorrentTab = new TorrentWidget; mTab = new QTabWidget; mTab->addTab(mTorrentTab, tr("Torrents")); @@ -34,6 +40,14 @@ void ShemovCleaner::setSelectionCount(const QString &msg){ mSelected->setText(msg); } +void ShemovCleaner::configure(){ + ConfigurationWidget w(this); + int res = w.exec(); + if(res == QDialog::Accepted){ + openDatabase(); + } +} + void ShemovCleaner::createStatusBar(){ QLabel *l1 = new QLabel(tr("Sel.")); mSelected = new QLabel("000/000"); @@ -46,6 +60,9 @@ void ShemovCleaner::createActions(){ //Application QAction *quitA = new QAction(tr("Quit"), this); connect(quitA, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); + QAction *configA = new QAction(QIcon(":/chastity_belt.png"), tr("Configure..."), this); + connect(configA, SIGNAL(triggered()), this, SLOT(configure())); + //TorrentWidget mTorRefreshA = new QAction(QIcon(":/refresh.png"), tr("Refresh"), this); connect(mTorRefreshA, SIGNAL(triggered()), mTorrentTab, SLOT(gatherData())); @@ -64,6 +81,8 @@ void ShemovCleaner::createActions(){ mTorrentTab->toolBar()->addAction(mTorDeleteA); mTorrentTab->toolBar()->addSeparator(); mTorrentTab->toolBar()->addAction(mTorInfoA); + mTorrentTab->toolBar()->addSeparator(); + mTorrentTab->toolBar()->addAction(configA); QMenu *torFileM = new QMenu(tr("File")); torFileM->addAction(mTorDirA); torFileM->addAction(mTorRefreshA); @@ -74,6 +93,8 @@ void ShemovCleaner::createActions(){ torEditM->addAction(mTorDeleteA); torEditM->addAction(mTorMoveA); torEditM->addSeparator(); + torEditM->addAction(configA); + torEditM->addSeparator(); torEditM->addAction(mTorInfoA); mTorrentTab->menuBar()->addMenu(torEditM); mTorrentTab->addAction(mTorInfoA); @@ -86,6 +107,28 @@ void ShemovCleaner::createActions(){ mTorrentTab->addAction(mTorDirA); } +void ShemovCleaner::openDatabase(){ + QSettings s; + QString dbhost = s.value("dbhost").toString(); + QString dbuser = s.value("dbuser").toString(); + QString dbpass = s.value("dbpass").toString(); + QString dbname = s.value("dbname").toString(); + QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL", "shemovdb"); + db.setHostName(dbhost); + db.setUserName(dbuser); + db.setPassword(dbpass); + db.setDatabaseName(dbname); + if(!db.open()){ + int res = ConfigurationWidget(this).exec(); + if(res == QDialog::Accepted){ + openDatabase(); + }else{ + QMessageBox::critical(this, tr("Error"), tr("Could not open database. Giving up!")); + qApp->closeAllWindows(); + } + } +} + QAction *ShemovCleaner::createSeparator(){ QAction *retval = new QAction(this); retval->setSeparator(true); -- cgit v1.2.3-70-g09d2