1 // checksum 0xfd0b version 0x20001
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.
10 #include "mainwindow.h"
11 #include "ui_mainwindow.h"
13 #include "constants.h"
14 #include "setupdialog.h"
17 #include <QtCore/QCoreApplication>
18 #include <QtCore/QSettings>
19 #include <QtCore/QTimer>
20 #include <QtCore/QTextStream>
22 #if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK)
27 #endif // Q_OS_SYMBIAN && ORIENTATIONLOCK
29 MainWindow::MainWindow(QWidget *parent)
30 : QMainWindow(parent), ui(new Ui::MainWindow)
34 connect(&serverSocket, SIGNAL(connected()), this, SLOT(serverConnected()));
35 connect(&serverSocket, SIGNAL(disconnected()), this, SLOT(serverDisconnected()));
36 connect(&serverSocket, SIGNAL(readyRead()), this, SLOT(serverDataAvailable()));
37 connect(&serverSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(serverError()));
42 MainWindow::~MainWindow()
47 void MainWindow::setOrientation(ScreenOrientation orientation)
50 if (orientation != ScreenOrientationAuto) {
51 #if defined(ORIENTATIONLOCK)
52 const CAknAppUiBase::TAppUiOrientation uiOrientation =
53 (orientation == ScreenOrientationLockPortrait) ? CAknAppUi::EAppUiOrientationPortrait
54 : CAknAppUi::EAppUiOrientationLandscape;
55 CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
58 appUi->SetOrientationL(uiOrientation);
61 #else // ORIENTATIONLOCK
62 qWarning("'ORIENTATIONLOCK' needs to be defined on Symbian when locking the orientation.");
63 #endif // ORIENTATIONLOCK
65 #elif defined(Q_WS_MAEMO_5)
66 Qt::WidgetAttribute attribute;
67 switch (orientation) {
68 case ScreenOrientationLockPortrait:
69 attribute = Qt::WA_Maemo5PortraitOrientation;
71 case ScreenOrientationLockLandscape:
72 attribute = Qt::WA_Maemo5LandscapeOrientation;
74 case ScreenOrientationAuto:
76 attribute = Qt::WA_Maemo5AutoOrientation;
79 setAttribute(attribute, true);
81 Q_UNUSED(orientation);
82 #endif // Q_OS_SYMBIAN
85 void MainWindow::showExpanded()
89 #elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
96 void MainWindow::on_actionSetup_triggered()
100 if(dialog.exec() == QDialog::Accepted) {
105 void MainWindow::connectToServer()
107 // TODO: we asume the socket is not already connected
108 // TODO: we should add code to do nothing if the connection is ok, or close and open a new one if the server or port changed
111 serverSocket.connectToHost(settings.value(SETUP_XBMC_SERVER, SETUP_XBMC_SERVER_DEFAULT).toString(),
112 settings.value(SETUP_XBMC_PORT, SETUP_XBMC_PORT_DEFAULT).toInt());
115 void MainWindow::disconnectFromServer()
117 serverSocket.disconnectFromHost();
120 void MainWindow::serverConnected()
122 ui->testButton->setEnabled(true);
123 ui->actionConnect->setChecked(true);
126 void MainWindow::serverDisconnected()
128 ui->testButton->setEnabled(false);
129 ui->actionConnect->setChecked(false);
132 void MainWindow::serverDataAvailable()
134 QTextStream stream(&serverSocket);
135 ui->textEdit->setText(stream.readAll());
138 void MainWindow::serverError()
140 ui->textEdit->setText(serverSocket.errorString());
141 ui->actionConnect->setChecked(serverSocket.state() == QTcpSocket::ConnectedState);
142 // clean the error window after 2 secs
143 QTimer::singleShot(2000, this, SLOT(cleanError()));
146 void MainWindow::cleanError()
148 ui->textEdit->clear();
151 void MainWindow::on_testButton_clicked()
153 QTextStream stream(&serverSocket);
154 stream << JsonEngine().playerGetActivePlayers();
157 void MainWindow::on_actionConnect_triggered(bool checked)
159 qDebug("menu state: %d", checked);
163 disconnectFromServer();