implemented screen inhibit.
[simple-xmbc-rem] / src / mainwindow.cpp
index b7a7495..5ef8368 100644 (file)
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 
-#include <setupdialog.h>
+#include "setupdialog.h"
+#include "xbmc.h"
+#include "constants.h"
 
-#include <QtCore/QCoreApplication>
+#include <QSettings>
+#include <QCoreApplication>
 
 #if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK)
 #include <eikenv.h>
 #endif // Q_OS_SYMBIAN && ORIENTATIONLOCK
 
 MainWindow::MainWindow(QWidget *parent)
-    : QMainWindow(parent), ui(new Ui::MainWindow)
+    : QMainWindow(parent), m_ui(new Ui::MainWindow)
 {
-    ui->setupUi(this);
+    m_ui->setupUi(this);
+    m_xbmc = new Xbmc(this);
+
+#ifdef Q_WS_MAEMO_5
+    m_screenSaver = 0;
+#endif
+
+    setupScreen();
 }
 
 MainWindow::~MainWindow()
 {
-    delete ui;
+#ifdef Q_WS_MAEMO_5
+    delete m_screenSaver;
+#endif
+
+    delete m_xbmc;
+    delete m_ui;
+}
+
+void MainWindow::setupScreen()
+{
+#ifdef Q_WS_MAEMO_5
+    QSettings settings;
+
+    bool disable_screensaver = settings.value(SETUP_SCREEN_DISABLE_SCREENSAVER, SETUP_SCREEN_DISABLE_SCREENSAVER_DEFAULT).toBool();
+
+    if (disable_screensaver) {
+        if (m_screenSaver == 0) {
+            m_screenSaver = new QSystemScreenSaver(this);
+            bool result = m_screenSaver->setScreenSaverInhibit();
+            qDebug("disabling the screensaver: %s", (result?"ok":"failed"));
+        }
+    } else {
+        if (m_screenSaver) {
+            delete m_screenSaver;
+            m_screenSaver = 0;
+            qDebug("screensaver enabled");
+        }
+    }
+#endif
 }
 
 void MainWindow::setOrientation(ScreenOrientation orientation)
@@ -88,4 +126,81 @@ void MainWindow::on_actionSetup_triggered()
     if(dialog.exec() == QDialog::Accepted) {
         dialog.save();
     }
+
+    setupScreen();
+}
+
+void MainWindow::on_rightBtn_clicked()
+{
+    m_xbmc->actionRight();
+}
+
+void MainWindow::on_leftBtn_clicked()
+{
+    m_xbmc->actionLeft();
+}
+
+void MainWindow::on_upBtn_clicked()
+{
+    m_xbmc->actionUp();
+}
+
+void MainWindow::on_downBtn_clicked()
+{
+    m_xbmc->actionDown();
+}
+
+void MainWindow::on_playBtn_clicked()
+{
+    m_xbmc->actionPlay();
+}
+
+void MainWindow::on_muteBtn_clicked()
+{
+    m_xbmc->actionMute();
+}
+
+void MainWindow::on_volumeUpBtn_clicked()
+{
+    m_xbmc->actionVolumeUp();
+}
+
+void MainWindow::on_volumeDownBtn_clicked()
+{
+    m_xbmc->actionVolumeDown();
+}
+
+void MainWindow::on_nextSubtitleBtn_clicked()
+{
+    m_xbmc->actionNextSubtitle();
+}
+
+void MainWindow::on_nextLanguageBtn_clicked()
+{
+    m_xbmc->actionNextLanguage();
+}
+
+void MainWindow::on_selectButton_clicked()
+{
+    m_xbmc->actionSelect();
+}
+
+void MainWindow::on_stopBtn_clicked()
+{
+    m_xbmc->actionStop();
+}
+
+void MainWindow::on_showGuiBtn_clicked()
+{
+    m_xbmc->actionShowGui();
+}
+
+void MainWindow::on_contextMenuBtn_clicked()
+{
+    m_xbmc->actionContextMenu();
+}
+
+void MainWindow::on_sendEscKeyBtn_clicked()
+{
+    m_xbmc->actionSendKeyEsc();
 }