#include "mainwindow.h"
#include "ui_mainwindow.h"
-#include "constants.h"
#include "setupdialog.h"
-#include "json.h"
+#include "xbmc.h"
#include <QCoreApplication>
-#include <QSettings>
-#include <QTimer>
-#include <QTextStream>
#if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK)
#include <eikenv.h>
: QMainWindow(parent), m_ui(new Ui::MainWindow)
{
m_ui->setupUi(this);
-
- createStates();
- createTransitions();
- createConnections();
-
- m_stateMachine.setInitialState(m_disconnectedState);
- QTimer::singleShot(0, &m_stateMachine, SLOT(start()));
+ m_xbmc = new Xbmc(this);
}
MainWindow::~MainWindow()
{
+ delete m_xbmc;
delete m_ui;
}
}
}
-void MainWindow::createStates()
+void MainWindow::on_rightBtn_clicked()
{
- m_disconnectedState = new DisconnectedState(m_ui->networkButton, &m_serverSocket, &m_stateMachine);
- m_connectingState = new ConnectingState(m_ui->networkButton, &m_serverSocket, &m_stateMachine);
- m_connectedState = new ConnectedState(m_ui->networkButton, &m_serverSocket, &m_stateMachine);
- m_disconnectingState = new DisconnectingState(m_ui->networkButton, &m_serverSocket, &m_stateMachine);
+ m_xbmc->actionRight();
}
-void MainWindow::createTransitions()
+void MainWindow::on_leftBtn_clicked()
{
- m_disconnectedState->addTransition(m_ui->networkButton, SIGNAL(clicked()), m_connectingState);
-
- m_connectingState->addTransition(m_connectingState, SIGNAL(connected()), m_connectedState);
- m_connectingState->addTransition(m_connectingState, SIGNAL(failed()), m_disconnectedState);
-
- m_connectedState->addTransition(m_ui->networkButton, SIGNAL(clicked()), m_disconnectingState);
- m_connectedState->addTransition(m_connectedState, SIGNAL(disconnected()), m_disconnectedState);
-
- m_disconnectingState->addTransition(m_disconnectingState, SIGNAL(disconnected()), m_disconnectedState);
+ m_xbmc->actionLeft();
}
-void MainWindow::createConnections()
+void MainWindow::on_upBtn_clicked()
{
+ m_xbmc->actionUp();
}
-/////////////////////////////////////////////////////////////////////
-//
-DisconnectedState::DisconnectedState(QAbstractButton *button, QTcpSocket* socket, QState *parent)
- : QState(parent), m_socket(socket)
+void MainWindow::on_downBtn_clicked()
{
- assignProperty(button, "text", "Connect");
- assignProperty(button, "enabled", true);
+ m_xbmc->actionDown();
}
-void DisconnectedState::onEntry(QEvent */*event*/)
+void MainWindow::on_playBtn_clicked()
{
- qDebug("DisconnectedState::onEntry");
+ m_xbmc->actionPlay();
}
-void DisconnectedState::onExit(QEvent */*event*/)
+void MainWindow::on_muteBtn_clicked()
{
- qDebug("DisconnectedState::onExit");
+ m_xbmc->actionMute();
}
-/////////////////////////////////////////////////////////////////////
-//
-ConnectingState::ConnectingState(QAbstractButton *button, QTcpSocket* socket, QState *parent)
- : QState(parent), m_socket(socket)
+void MainWindow::on_parentDirBtn_clicked()
{
- assignProperty(button, "text", "Connecting");
- assignProperty(button, "enabled", false);
+ m_xbmc->actionParentDir();
}
-void ConnectingState::onEntry(QEvent */*event*/)
+void MainWindow::on_volumeUpBtn_clicked()
{
- qDebug("ConnectingState::onEntry");
-
- connect(m_socket, SIGNAL(connected()), this, SIGNAL(connected()));
- connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));
-
- // TODO: we asume the socket is not already connected
- // 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
- QSettings settings;
-
- m_socket->connectToHost(settings.value(SETUP_XBMC_SERVER, SETUP_XBMC_SERVER_DEFAULT).toString(),
- settings.value(SETUP_XBMC_PORT, SETUP_XBMC_PORT_DEFAULT).toInt());
+ m_xbmc->actionVolumeUp();
}
-void ConnectingState::onExit(QEvent */*event*/)
+void MainWindow::on_volumeDownBtn_clicked()
{
- disconnect(m_socket, 0, this, 0);
- qDebug("ConnectingState::onExit");
+ m_xbmc->actionVolumeDown();
}
-void ConnectingState::onSocketError(QAbstractSocket::SocketError)
+void MainWindow::on_nextSubtitleBtn_clicked()
{
- qDebug("ConnectingState::onSocketError: %s", qPrintable(m_socket->errorString()));
- emit failed();
-}
-
-/////////////////////////////////////////////////////////////////////
-//
-ConnectedState::ConnectedState(QAbstractButton *button, QTcpSocket* socket, QState *parent)
- : QState(parent), m_socket(socket)
-{
- assignProperty(button, "text", "Disconnect");
- assignProperty(button, "enabled", true);
-}
-
-void ConnectedState::onEntry(QEvent */*event*/)
-{
- qDebug("ConnectedState::onEntry");
-
- connect(m_socket, SIGNAL(readyRead()), this, SLOT(onSocketData()));
- connect(m_socket, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
- connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));
-
- QTextStream stream(m_socket);
- stream << JsonEngine().playerGetActivePlayers();
-
- qDebug("ConnectedState::onEntry - request sent");
+ m_xbmc->actionNextSubtitle();
}
-void ConnectedState::onExit(QEvent */*event*/)
+void MainWindow::on_nextLanguageBtn_clicked()
{
- disconnect(m_socket, 0, this, 0);
- qDebug("ConnectedState::onExit");
-}
-
-void ConnectedState::onSocketError(QAbstractSocket::SocketError)
-{
- qDebug("ConnectedState::onSocketError: %s", qPrintable(m_socket->errorString()));
-}
-
-void ConnectedState::onSocketData()
-{
- QTextStream stream(m_socket);
- QString msg = stream.readAll();
- qDebug("ConnectedState::onSocketData: %s", qPrintable(msg));
-}
-
-/////////////////////////////////////////////////////////////////////
-//
-DisconnectingState::DisconnectingState(QAbstractButton *button, QTcpSocket* socket, QState *parent)
- : QState(parent), m_socket(socket)
-{
- assignProperty(button, "text", "Disconnecting");
- assignProperty(button, "enabled", false);
-}
-
-void DisconnectingState::onEntry(QEvent */*event*/)
-{
- qDebug("DisconnectingState::onEntry");
-
- connect(m_socket, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
- connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));
-
- if (m_socket->state() != QTcpSocket::UnconnectedState) {
- qDebug("DisconnectingState::disconnectFromHost");
- m_socket->disconnectFromHost();
- }
- else {
- qDebug("DisconnectingState::disconnect");
- QTimer::singleShot(0, this, SIGNAL(disconnected()));
- }
+ m_xbmc->actionNextLanguage();
}
-void DisconnectingState::onExit(QEvent */*event*/)
+void MainWindow::on_selectButton_clicked()
{
- disconnect(m_socket, 0, this, 0);
- qDebug("DisconnectingState::onExit");
+ m_xbmc->actionSelect();
}
-void DisconnectingState::onSocketError(QAbstractSocket::SocketError)
+void MainWindow::on_stopBtn_clicked()
{
- qDebug("DisconnectingState::onSocketError: %s", qPrintable(m_socket->errorString()));
+ m_xbmc->actionStop();
}