From e7b90033075551226c868bc56c1e7171199cd4d9 Mon Sep 17 00:00:00 2001 From: Ionutz Borcoman Date: Tue, 1 Feb 2011 11:24:26 +0200 Subject: [PATCH] Use constants.h to store app's constants. Created a setup dialog. --- src/constants.h | 14 ++++++ src/main.cpp | 3 ++ src/mainwindow.cpp | 11 +++++ src/mainwindow.h | 3 ++ src/mainwindow.ui | 37 ++++++++++---- src/setupdialog.cpp | 32 +++++++++++++ src/setupdialog.h | 24 ++++++++++ src/setupdialog.ui | 112 +++++++++++++++++++++++++++++++++++++++++++ src/xbmcnetmoviesremote.pro | 10 ++-- 9 files changed, 235 insertions(+), 11 deletions(-) create mode 100644 src/constants.h create mode 100644 src/setupdialog.cpp create mode 100644 src/setupdialog.h create mode 100644 src/setupdialog.ui diff --git a/src/constants.h b/src/constants.h new file mode 100644 index 0000000..2adece1 --- /dev/null +++ b/src/constants.h @@ -0,0 +1,14 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +// QCoreApplication info +#define APPLICATION_NAME "xbmcnetmoviesremote" +#define ORGANIZATION_NAME "Ionutz Borcoman" + +// QSettings keys +#define SETUP_XBMC_SERVER "xbmc/server" +#define SETUP_XBMC_SERVER_DEFAULT "localhost" +#define SETUP_XBMC_PORT "xbmc/port" +#define SETUP_XBMC_PORT_DEFAULT "9090" + +#endif // SETTINGS_H diff --git a/src/main.cpp b/src/main.cpp index ce69cf7..bb6450d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,13 @@ #include "mainwindow.h" +#include "constants.h" #include int main(int argc, char *argv[]) { QApplication app(argc, argv); + app.setOrganizationName(APPLICATION_NAME); + app.setApplicationName(ORGANIZATION_NAME); MainWindow mainWindow; mainWindow.setOrientation(MainWindow::ScreenOrientationAuto); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 460fd88..b7a7495 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -10,6 +10,8 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include + #include #if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK) @@ -78,3 +80,12 @@ void MainWindow::showExpanded() show(); #endif } + +void MainWindow::on_actionSetup_triggered() +{ + SetupDialog dialog; + dialog.load(); + if(dialog.exec() == QDialog::Accepted) { + dialog.save(); + } +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 3482f8d..b33aec6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -32,6 +32,9 @@ public: void setOrientation(ScreenOrientation orientation); void showExpanded(); +private slots: + void on_actionSetup_triggered(); + private: Ui::MainWindow *ui; }; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index f3dc9dd..cfd23aa 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1,7 +1,8 @@ + MainWindow - - + + 0 0 @@ -9,14 +10,34 @@ 320 - - MainWindow + + XBMC Net Movies RC - - + + + + + 0 + 0 + 200 + 25 + + + + + MainMenu + + + + + + + + Setup + + - - + diff --git a/src/setupdialog.cpp b/src/setupdialog.cpp new file mode 100644 index 0000000..a8ba697 --- /dev/null +++ b/src/setupdialog.cpp @@ -0,0 +1,32 @@ +#include "setupdialog.h" +#include "ui_setupdialog.h" + +#include "constants.h" + +#include + +SetupDialog::SetupDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SetupDialog) +{ + ui->setupUi(this); +} + +SetupDialog::~SetupDialog() +{ + delete ui; +} + +void SetupDialog::save() +{ + QSettings settings; + settings.setValue(SETUP_XBMC_SERVER, ui->xbmcServerEdit->text()); + settings.setValue(SETUP_XBMC_PORT, ui->xbmcPortEdit->text()); +} + +void SetupDialog::load() +{ + QSettings settings; + ui->xbmcServerEdit->setText(settings.value(SETUP_XBMC_SERVER, SETUP_XBMC_SERVER_DEFAULT).toString()); + ui->xbmcPortEdit->setText(settings.value(SETUP_XBMC_PORT, SETUP_XBMC_PORT_DEFAULT).toString()); +} diff --git a/src/setupdialog.h b/src/setupdialog.h new file mode 100644 index 0000000..aa76217 --- /dev/null +++ b/src/setupdialog.h @@ -0,0 +1,24 @@ +#ifndef SETUPDIALOG_H +#define SETUPDIALOG_H + +#include + +namespace Ui { + class SetupDialog; +} + +class SetupDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SetupDialog(QWidget *parent = 0); + ~SetupDialog(); + void save(); + void load(); + +private: + Ui::SetupDialog *ui; +}; + +#endif // SETUPDIALOG_H diff --git a/src/setupdialog.ui b/src/setupdialog.ui new file mode 100644 index 0000000..dfa5ea6 --- /dev/null +++ b/src/setupdialog.ui @@ -0,0 +1,112 @@ + + + SetupDialog + + + + 0 + 0 + 329 + 111 + + + + Dialog + + + + + + + + XBMC + + + + + + + + + Server: + + + + + + + + + + Port: + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Vertical + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + SetupDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SetupDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/xbmcnetmoviesremote.pro b/src/xbmcnetmoviesremote.pro index 685c440..c95f830 100644 --- a/src/xbmcnetmoviesremote.pro +++ b/src/xbmcnetmoviesremote.pro @@ -18,9 +18,13 @@ symbian:TARGET.UID3 = 0xED8FBFF1 # CONFIG += mobility # MOBILITY += -SOURCES += main.cpp mainwindow.cpp -HEADERS += mainwindow.h -FORMS += mainwindow.ui +SOURCES += main.cpp mainwindow.cpp \ + setupdialog.cpp +HEADERS += mainwindow.h \ + setupdialog.h \ + constants.h +FORMS += mainwindow.ui \ + setupdialog.ui # Please do not modify the following two lines. Required for deployment. include(deployment.pri) -- 1.7.9.5