2381b53103a609d24a75f58b4e258072a75f84af
[simple-xmbc-rem] / src / xbmc.cpp
1 #include "xbmc.h"
2 #include "constants.h"
3
4 #include <QSettings>
5 #include <QTextStream>
6 #include <QNetworkReply>
7
8 // XBMC constants -- from https://github.com/xbmc/xbmc/blob/master/xbmc/guilib/Key.h
9 #define ACTION_MOVE_LEFT                1
10 #define ACTION_MOVE_RIGHT               2
11 #define ACTION_MOVE_UP                  3
12 #define ACTION_MOVE_DOWN                4
13 #define ACTION_NEXT_SUBTITLE            26 // switch to next subtitle of movie. Can b used in videoFullScreen.xml window id=2005
14 #define ACTION_SUBTITLE_DELAY_MIN       52 // Decrease subtitle/movie Delay. Can b used in videoFullScreen.xml window id=2005
15 #define ACTION_SUBTITLE_DELAY_PLUS      53 // Increase subtitle/movie Delay. Can b used in videoFullScreen.xml window id=2005
16 #define ACTION_AUDIO_DELAY_MIN          54 // Increase avsync delay. Can b used in videoFullScreen.xml window id=2005
17 #define ACTION_AUDIO_DELAY_PLUS         55 // Decrease avsync delay. Can b used in videoFullScreen.xml window id=2005
18 #define ACTION_AUDIO_NEXT_LANGUAGE      56 // Select next language in movie. Can b used in videoFullScreen.xml window id=2005
19 #define ACTION_ENTER                    135
20 #define ACTION_SHOW_GUI                 18 // toggle between GUI and movie or GUI and visualisation.
21 #define ACTION_STEP_FORWARD             20 // seek +1% in the movie. Can b used in videoFullScreen.xml window id=2005
22 #define ACTION_STEP_BACK                21 // seek -1% in the movie. Can b used in videoFullScreen.xml window id=2005
23 #define ACTION_BIG_STEP_FORWARD         22 // seek +10% in the movie. Can b used in videoFullScreen.xml window id=2005
24 #define ACTION_BIG_STEP_BACK            23 // seek -10% in the movie. Can b used in videoFullScreen.xml window id=2005
25
26 #define ACTION_PLAYER_PLAY              79 // Play current song. Unpauses song and sets playspeed to 1x. global action, can be used anywhere
27 #define ACTION_SELECT_ITEM              7
28 #define ACTION_HIGHLIGHT_ITEM           8
29 #define ACTION_PARENT_DIR               9
30
31 Xbmc::Xbmc(QObject *parent) : QObject(parent)
32 {
33     m_manager = new QNetworkAccessManager(this);
34 }
35
36 Xbmc::~Xbmc()
37 {
38     delete m_manager;
39 }
40
41 void Xbmc::do_command_action(int action)
42 {
43     QSettings settings;
44     QString server = settings.value(SETUP_XBMC_SERVER, SETUP_XBMC_SERVER_DEFAULT).toString();
45     QString port = settings.value(SETUP_XBMC_PORT, SETUP_XBMC_PORT_DEFAULT).toString();
46
47     QString url = QString("http://%1:%2/xbmcCmds/xbmcHttp?command=Action(%3)")
48             .arg(server)
49             .arg(port)
50             .arg(action);
51
52     m_manager->get(QNetworkRequest(QUrl(url)));
53 }
54
55 void Xbmc::actionMoveRight()
56 {
57     do_command_action(ACTION_MOVE_RIGHT);
58 }
59
60 void Xbmc::actionMoveLeft()
61 {
62     do_command_action(ACTION_MOVE_LEFT);
63 }
64
65 void Xbmc::actionMoveUp()
66 {
67     do_command_action(ACTION_MOVE_UP);
68 }
69
70 void Xbmc::actionMoveDown()
71 {
72     do_command_action(ACTION_MOVE_DOWN);
73 }
74
75 //void MainWindow::onNetworAccesskManagerReplyFinished(QNetworkReply *reply)
76 //{
77 //    QTextStream stream(reply);
78 //    QString msg = stream.readAll();
79 //    qDebug("MainWindow::onNetworAccesskManagerReplyFinished: %s", qPrintable(msg));
80
81 //    reply->deleteLater();
82 //}