implemented screen inhibit.
[simple-xmbc-rem] / src / mainwindow.cpp
1 // checksum 0xfd0b version 0x20001
2 /*
3   This file was generated by the Mobile Qt Application wizard of Qt Creator.
4   MainWindow is a convenience class containing mobile device specific code
5   such as screen orientation handling.
6   It is recommended not to modify this file, since newer versions of Qt Creator
7   may offer an updated version of it.
8 */
9
10 #include "mainwindow.h"
11 #include "ui_mainwindow.h"
12
13 #include "setupdialog.h"
14 #include "xbmc.h"
15 #include "constants.h"
16
17 #include <QSettings>
18 #include <QCoreApplication>
19
20 #if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK)
21 #include <eikenv.h>
22 #include <eikappui.h>
23 #include <aknenv.h>
24 #include <aknappui.h>
25 #endif // Q_OS_SYMBIAN && ORIENTATIONLOCK
26
27 MainWindow::MainWindow(QWidget *parent)
28     : QMainWindow(parent), m_ui(new Ui::MainWindow)
29 {
30     m_ui->setupUi(this);
31     m_xbmc = new Xbmc(this);
32
33 #ifdef Q_WS_MAEMO_5
34     m_screenSaver = 0;
35 #endif
36
37     setupScreen();
38 }
39
40 MainWindow::~MainWindow()
41 {
42 #ifdef Q_WS_MAEMO_5
43     delete m_screenSaver;
44 #endif
45
46     delete m_xbmc;
47     delete m_ui;
48 }
49
50 void MainWindow::setupScreen()
51 {
52 #ifdef Q_WS_MAEMO_5
53     QSettings settings;
54
55     bool disable_screensaver = settings.value(SETUP_SCREEN_DISABLE_SCREENSAVER, SETUP_SCREEN_DISABLE_SCREENSAVER_DEFAULT).toBool();
56
57     if (disable_screensaver) {
58         if (m_screenSaver == 0) {
59             m_screenSaver = new QSystemScreenSaver(this);
60             bool result = m_screenSaver->setScreenSaverInhibit();
61             qDebug("disabling the screensaver: %s", (result?"ok":"failed"));
62         }
63     } else {
64         if (m_screenSaver) {
65             delete m_screenSaver;
66             m_screenSaver = 0;
67             qDebug("screensaver enabled");
68         }
69     }
70 #endif
71 }
72
73 void MainWindow::setOrientation(ScreenOrientation orientation)
74 {
75 #ifdef Q_OS_SYMBIAN
76     if (orientation != ScreenOrientationAuto) {
77 #if defined(ORIENTATIONLOCK)
78         const CAknAppUiBase::TAppUiOrientation uiOrientation =
79                 (orientation == ScreenOrientationLockPortrait) ? CAknAppUi::EAppUiOrientationPortrait
80                     : CAknAppUi::EAppUiOrientationLandscape;
81         CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
82         TRAPD(error,
83             if (appUi)
84                 appUi->SetOrientationL(uiOrientation);
85         );
86         Q_UNUSED(error)
87 #else // ORIENTATIONLOCK
88         qWarning("'ORIENTATIONLOCK' needs to be defined on Symbian when locking the orientation.");
89 #endif // ORIENTATIONLOCK
90     }
91 #elif defined(Q_WS_MAEMO_5)
92     Qt::WidgetAttribute attribute;
93     switch (orientation) {
94     case ScreenOrientationLockPortrait:
95         attribute = Qt::WA_Maemo5PortraitOrientation;
96         break;
97     case ScreenOrientationLockLandscape:
98         attribute = Qt::WA_Maemo5LandscapeOrientation;
99         break;
100     case ScreenOrientationAuto:
101     default:
102         attribute = Qt::WA_Maemo5AutoOrientation;
103         break;
104     }
105     setAttribute(attribute, true);
106 #else // Q_OS_SYMBIAN
107     Q_UNUSED(orientation);
108 #endif // Q_OS_SYMBIAN
109 }
110
111 void MainWindow::showExpanded()
112 {
113 #ifdef Q_OS_SYMBIAN
114     showFullScreen();
115 #elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
116     showMaximized();
117 #else
118     show();
119 #endif
120 }
121
122 void MainWindow::on_actionSetup_triggered()
123 {
124     SetupDialog dialog;
125     dialog.load();
126     if(dialog.exec() == QDialog::Accepted) {
127         dialog.save();
128     }
129
130     setupScreen();
131 }
132
133 void MainWindow::on_rightBtn_clicked()
134 {
135     m_xbmc->actionRight();
136 }
137
138 void MainWindow::on_leftBtn_clicked()
139 {
140     m_xbmc->actionLeft();
141 }
142
143 void MainWindow::on_upBtn_clicked()
144 {
145     m_xbmc->actionUp();
146 }
147
148 void MainWindow::on_downBtn_clicked()
149 {
150     m_xbmc->actionDown();
151 }
152
153 void MainWindow::on_playBtn_clicked()
154 {
155     m_xbmc->actionPlay();
156 }
157
158 void MainWindow::on_muteBtn_clicked()
159 {
160     m_xbmc->actionMute();
161 }
162
163 void MainWindow::on_volumeUpBtn_clicked()
164 {
165     m_xbmc->actionVolumeUp();
166 }
167
168 void MainWindow::on_volumeDownBtn_clicked()
169 {
170     m_xbmc->actionVolumeDown();
171 }
172
173 void MainWindow::on_nextSubtitleBtn_clicked()
174 {
175     m_xbmc->actionNextSubtitle();
176 }
177
178 void MainWindow::on_nextLanguageBtn_clicked()
179 {
180     m_xbmc->actionNextLanguage();
181 }
182
183 void MainWindow::on_selectButton_clicked()
184 {
185     m_xbmc->actionSelect();
186 }
187
188 void MainWindow::on_stopBtn_clicked()
189 {
190     m_xbmc->actionStop();
191 }
192
193 void MainWindow::on_showGuiBtn_clicked()
194 {
195     m_xbmc->actionShowGui();
196 }
197
198 void MainWindow::on_contextMenuBtn_clicked()
199 {
200     m_xbmc->actionContextMenu();
201 }
202
203 void MainWindow::on_sendEscKeyBtn_clicked()
204 {
205     m_xbmc->actionSendKeyEsc();
206 }