summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2017-02-18 12:16:34 +0100
committerArno <arno@disconnect.de>2017-02-18 12:16:34 +0100
commit1803f4a72385856920aeeeaeab1e04b7f0a123dc (patch)
tree4226507a0c2afeeb4e274c2a271f81f4605f680f
downloadBeetPlayer-1803f4a72385856920aeeeaeab1e04b7f0a123dc.tar.gz
BeetPlayer-1803f4a72385856920aeeeaeab1e04b7f0a123dc.tar.bz2
BeetPlayer-1803f4a72385856920aeeeaeab1e04b7f0a123dc.zip
Initial commit
Create database and connect. Does nothing yet...
-rw-r--r--BeetPlayer.pro31
-rw-r--r--beetplayer.cpp38
-rw-r--r--beetplayer.h16
-rw-r--r--configurationdialog.cpp66
-rw-r--r--configurationdialog.h25
-rw-r--r--main.cpp15
6 files changed, 191 insertions, 0 deletions
diff --git a/BeetPlayer.pro b/BeetPlayer.pro
new file mode 100644
index 0000000..ebc16c7
--- /dev/null
+++ b/BeetPlayer.pro
@@ -0,0 +1,31 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2017-02-18T10:18:51
+#
+#-------------------------------------------------
+
+QT += core gui multimedia sql
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = BeetPlayer
+TEMPLATE = app
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as been marked as deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
+
+
+SOURCES += main.cpp\
+ beetplayer.cpp \
+ configurationdialog.cpp
+
+HEADERS += beetplayer.h \
+ configurationdialog.h
diff --git a/beetplayer.cpp b/beetplayer.cpp
new file mode 100644
index 0000000..52c80e4
--- /dev/null
+++ b/beetplayer.cpp
@@ -0,0 +1,38 @@
+#include <QSettings>
+#include <QSqlDatabase>
+#include <QMessageBox>
+#include <QApplication>
+
+#include "beetplayer.h"
+#include "configurationdialog.h"
+
+BeetPlayer::BeetPlayer(QWidget *parent, Qt::WindowFlags f) : QMainWindow(parent, f) {
+ //general setup
+ setMinimumWidth(800);
+ setMinimumHeight(600);
+ openDatabase();
+}
+
+void BeetPlayer::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();
+ if(!QSqlDatabase::contains("beetplayerdb")){
+ QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL", "beetplayerdb");
+ db.setHostName(dbhost);
+ db.setUserName(dbuser);
+ db.setPassword(dbpass);
+ db.setDatabaseName(dbname);
+ if(!db.open()){
+ int res = ConfigurationDialog(this).exec();
+ if(res == QDialog::Accepted){
+ openDatabase();
+ }else{
+ QMessageBox::critical(this, tr("Error"), tr("Could not open database. Giving up!"));
+ qApp->closeAllWindows();
+ }
+ }
+ }
+}
diff --git a/beetplayer.h b/beetplayer.h
new file mode 100644
index 0000000..296f99f
--- /dev/null
+++ b/beetplayer.h
@@ -0,0 +1,16 @@
+#ifndef BEETPLAYER_H
+#define BEETPLAYER_H
+
+#include <QMainWindow>
+
+class BeetPlayer : public QMainWindow {
+ Q_OBJECT
+ public:
+ enum Tabs { Player = 0, Indexer = 1 };
+ explicit BeetPlayer(QWidget *parent = 0, Qt::WindowFlags f = 0);
+
+ private:
+ void openDatabase();
+};
+
+#endif // BEETPLAYER_H
diff --git a/configurationdialog.cpp b/configurationdialog.cpp
new file mode 100644
index 0000000..88e70a4
--- /dev/null
+++ b/configurationdialog.cpp
@@ -0,0 +1,66 @@
+#include <QGridLayout>
+#include <QLineEdit>
+#include <QLabel>
+#include <QPushButton>
+#include <QTabWidget>
+#include <QSettings>
+
+#include "configurationdialog.h"
+
+ConfigurationDialog::ConfigurationDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) {
+ //database setup
+ QGridLayout *dbLayout = new QGridLayout;
+ mDbHost = new QLineEdit;
+ dbLayout->addWidget(new QLabel(tr("Hostname")), 0, 0);
+ dbLayout->addWidget(mDbHost, 0, 1);
+ mDbUser = new QLineEdit;
+ dbLayout->addWidget(new QLabel(tr("Username")), 1, 0);
+ dbLayout->addWidget(mDbUser, 1, 1);
+ mDbPass = new QLineEdit;
+ mDbPass->setEchoMode(QLineEdit::Password);
+ dbLayout->addWidget(new QLabel(tr("Password")), 2, 0);
+ dbLayout->addWidget(mDbPass, 2, 1);
+ mDbName = new QLineEdit;
+ dbLayout->addWidget(new QLabel(tr("DB Name")), 3, 0);
+ dbLayout->addWidget(mDbName, 3, 1);
+ dbLayout->setAlignment(Qt::AlignTop);
+ QWidget *dbWidget = new QWidget;
+ dbWidget->setLayout(dbLayout);
+
+ //buttons
+ QPushButton *acceptB = new QPushButton(tr("Save"));
+ connect(acceptB, SIGNAL(clicked()), this, SLOT(accept()));
+ QPushButton *cancelB = new QPushButton(tr("Cancel"));
+ connect(cancelB, SIGNAL(clicked()), this, SLOT(reject()));
+ QHBoxLayout *bLayout = new QHBoxLayout;
+ bLayout->addStretch();
+ bLayout->addWidget(acceptB);
+ bLayout->addWidget(cancelB);
+ bLayout->addStretch();
+
+ //dialog layout
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ QTabWidget *tab = new QTabWidget;
+ tab->addTab(dbWidget, tr("Database"));
+ mainLayout->addWidget(tab);
+ mainLayout->addLayout(bLayout);
+ readSettings();
+ setLayout(mainLayout);
+ setMinimumWidth(400);
+}
+
+void ConfigurationDialog::accept(){
+ QSettings s;
+ s.setValue("dbhost", mDbHost->text());
+ s.setValue("dbuser", mDbUser->text());
+ s.setValue("dbpass", mDbPass->text());
+ s.setValue("dbname", mDbName->text());
+ QDialog::accept();
+}
+void ConfigurationDialog::readSettings(){
+ QSettings s;
+ mDbHost->setText(s.value("dbhost").toString());
+ mDbUser->setText(s.value("dbuser").toString());
+ mDbPass->setText(s.value("dbpass").toString());
+ mDbName->setText(s.value("dbname").toString());
+}
diff --git a/configurationdialog.h b/configurationdialog.h
new file mode 100644
index 0000000..9a8bad8
--- /dev/null
+++ b/configurationdialog.h
@@ -0,0 +1,25 @@
+#ifndef CONFIGURATIONDIALOG_H
+#define CONFIGURATIONDIALOG_H
+
+#include <QDialog>
+
+class QLineEdit;
+class QPushButton;
+
+class ConfigurationDialog : public QDialog {
+ Q_OBJECT
+ public:
+ explicit ConfigurationDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
+
+ public slots:
+ virtual void accept();
+
+ private:
+ void readSettings();
+ QLineEdit *mDbHost;
+ QLineEdit *mDbUser;
+ QLineEdit *mDbPass;
+ QLineEdit *mDbName;
+};
+
+#endif // CONFIGURATIONDIALOG_H
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..8014d8d
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,15 @@
+#include <QApplication>
+
+#include "beetplayer.h"
+
+int main(int argc, char *argv[]) {
+ QApplication a(argc, argv);
+ QCoreApplication::setOrganizationName("Sissie's, Inc.");
+ QCoreApplication::setOrganizationDomain("tollana.d-tor.org");
+ QCoreApplication::setApplicationName("BeetPlayer");
+ QCoreApplication::setApplicationVersion("0.99 (__build_info__)");
+ BeetPlayer w;
+ w.show();
+
+ return a.exec();
+}