Use constants.h to store app's constants. Created a setup dialog.
authorIonutz Borcoman <iborco@gmail.com>
Tue, 1 Feb 2011 09:24:26 +0000 (11:24 +0200)
committerIonutz Borcoman <iborco@gmail.com>
Thu, 10 Mar 2011 08:10:13 +0000 (10:10 +0200)
src/constants.h [new file with mode: 0644]
src/main.cpp
src/mainwindow.cpp
src/mainwindow.h
src/mainwindow.ui
src/setupdialog.cpp [new file with mode: 0644]
src/setupdialog.h [new file with mode: 0644]
src/setupdialog.ui [new file with mode: 0644]
src/xbmcnetmoviesremote.pro

diff --git a/src/constants.h b/src/constants.h
new file mode 100644 (file)
index 0000000..2adece1
--- /dev/null
@@ -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
index ce69cf7..bb6450d 100644 (file)
@@ -1,10 +1,13 @@
 #include "mainwindow.h"
+#include "constants.h"
 
 #include <QtGui/QApplication>
 
 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);
+    app.setOrganizationName(APPLICATION_NAME);
+    app.setApplicationName(ORGANIZATION_NAME);
 
     MainWindow mainWindow;
     mainWindow.setOrientation(MainWindow::ScreenOrientationAuto);
index 460fd88..b7a7495 100644 (file)
@@ -10,6 +10,8 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 
+#include <setupdialog.h>
+
 #include <QtCore/QCoreApplication>
 
 #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();
+    }
+}
index 3482f8d..b33aec6 100644 (file)
@@ -32,6 +32,9 @@ public:
     void setOrientation(ScreenOrientation orientation);
     void showExpanded();
 
+private slots:
+    void on_actionSetup_triggered();
+
 private:
     Ui::MainWindow *ui;
 };
index f3dc9dd..cfd23aa 100644 (file)
@@ -1,7 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <ui version="4.0">
  <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow" >
-  <property name="geometry" >
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <height>320</height>
    </rect>
   </property>
-  <property name="windowTitle" >
-   <string>MainWindow</string>
+  <property name="windowTitle">
+   <string>XBMC Net Movies RC</string>
   </property>
-  <widget class="QMenuBar" name="menuBar" />
-  <widget class="QWidget" name="centralWidget" />
+  <widget class="QWidget" name="centralWidget"/>
+  <widget class="QMenuBar" name="menuBar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>200</width>
+     <height>25</height>
+    </rect>
+   </property>
+   <widget class="QMenu" name="menuSetup">
+    <property name="title">
+     <string>MainMenu</string>
+    </property>
+    <addaction name="actionSetup"/>
+   </widget>
+   <addaction name="menuSetup"/>
+  </widget>
+  <action name="actionSetup">
+   <property name="text">
+    <string>Setup</string>
+   </property>
+  </action>
  </widget>
- <layoutDefault spacing="6" margin="11" />
- <pixmapfunction></pixmapfunction>
+ <layoutdefault spacing="6" margin="11"/>
  <resources/>
  <connections/>
 </ui>
diff --git a/src/setupdialog.cpp b/src/setupdialog.cpp
new file mode 100644 (file)
index 0000000..a8ba697
--- /dev/null
@@ -0,0 +1,32 @@
+#include "setupdialog.h"
+#include "ui_setupdialog.h"
+
+#include "constants.h"
+
+#include <QSettings>
+
+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 (file)
index 0000000..aa76217
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef SETUPDIALOG_H
+#define SETUPDIALOG_H
+
+#include <QDialog>
+
+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 (file)
index 0000000..dfa5ea6
--- /dev/null
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>SetupDialog</class>
+ <widget class="QDialog" name="SetupDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>329</width>
+    <height>111</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <layout class="QVBoxLayout" name="verticalLayout">
+     <item>
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>XBMC</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <layout class="QFormLayout" name="formLayout">
+       <item row="0" column="0">
+        <widget class="QLabel" name="xbmcServerLabel">
+         <property name="text">
+          <string>Server:</string>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="1">
+        <widget class="QLineEdit" name="xbmcServerEdit"/>
+       </item>
+       <item row="1" column="0">
+        <widget class="QLabel" name="xbmcPortLabel">
+         <property name="text">
+          <string>Port:</string>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="1">
+        <widget class="QLineEdit" name="xbmcPortEdit"/>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <spacer name="verticalSpacer">
+       <property name="orientation">
+        <enum>Qt::Vertical</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>20</width>
+         <height>40</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>SetupDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>SetupDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
index 685c440..c95f830 100644 (file)
@@ -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)