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)
38 stateMachine.setInitialState(disconnectedState);
39 QTimer::singleShot(0, &stateMachine, SLOT(start()));
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::createStates()
122 disconnectedState = new QState(&stateMachine);
123 disconnectedState->assignProperty(ui->networkButton, "text", "Connect");
124 disconnectedState->assignProperty(ui->networkButton, "enabled", true);
126 connectedState = new QState(&stateMachine);
128 connectingState = new QState(connectedState);
129 connectingState->assignProperty(ui->networkButton, "text", "Connecting");
130 connectingState->assignProperty(ui->networkButton, "enabled", false);
132 normalState = new QState(connectedState);
133 normalState->assignProperty(ui->networkButton, "text", "Disconnect");
134 normalState->assignProperty(ui->networkButton, "enabled", true);
136 disconnectingState = new QState(connectedState);
137 disconnectingState->assignProperty(ui->networkButton, "text", "Disconnecting");
138 disconnectingState->assignProperty(ui->networkButton, "enabled", false);
141 void MainWindow::createTransitions()
143 disconnectedState->addTransition(ui->networkButton, SIGNAL(clicked()), connectingState);
145 connectedState->addTransition(&serverSocket, SIGNAL(disconnected()), disconnectedState);
147 connectingState->addTransition(&serverSocket, SIGNAL(connected()), normalState);
148 connectingState->addTransition(&serverSocket, SIGNAL(error(QAbstractSocket::SocketError)), disconnectedState);
150 normalState->addTransition(ui->networkButton, SIGNAL(clicked()), disconnectingState);
153 void MainWindow::createConnections()
155 connect(connectingState, SIGNAL(entered()), this, SLOT(connectToServer()));
156 connect(disconnectingState, SIGNAL(entered()), this, SLOT(disconnectFromServer()));