[release] version bump to 13.0 beta1
[vuplus_xbmc] / xbmc / interfaces / json-rpc / InputOperations.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "InputOperations.h"
22 #include "Application.h"
23 #include "ApplicationMessenger.h"
24 #include "guilib/GUIAudioManager.h"
25 #include "guilib/GUIWindow.h"
26 #include "guilib/GUIWindowManager.h"
27 #include "input/ButtonTranslator.h"
28 #include "input/XBMC_keyboard.h"
29 #include "input/XBMC_vkeys.h"
30 #include "threads/SingleLock.h"
31
32 using namespace JSONRPC;
33
34 //TODO the breakage of the screensaver should be refactored
35 //to one central super duper place for getting rid of
36 //1 million dupes
37 bool CInputOperations::handleScreenSaver()
38 {
39   g_application.ResetScreenSaver();
40   if (g_application.WakeUpScreenSaverAndDPMS())
41     return true;
42
43   return false;
44 }
45
46 JSONRPC_STATUS CInputOperations::SendAction(int actionID, bool wakeScreensaver /* = true */, bool waitResult /* = false */)
47 {
48   if(!wakeScreensaver || !handleScreenSaver())
49   {
50     g_application.ResetSystemIdleTimer();
51     g_audioManager.PlayActionSound(actionID);
52     CApplicationMessenger::Get().SendAction(CAction(actionID), WINDOW_INVALID, waitResult);
53   }
54   return ACK;
55 }
56
57 JSONRPC_STATUS CInputOperations::activateWindow(int windowID)
58 {
59   if(!handleScreenSaver())
60     CApplicationMessenger::Get().ActivateWindow(windowID, std::vector<CStdString>(), false);
61
62   return ACK;
63 }
64
65 JSONRPC_STATUS CInputOperations::SendText(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
66 {
67   CGUIWindow *window = g_windowManager.GetWindow(g_windowManager.GetFocusedWindow());
68   if (!window)
69     return InternalError;
70
71   CGUIMessage msg(GUI_MSG_SET_TEXT, 0, 0);
72   msg.SetLabel(parameterObject["text"].asString());
73   msg.SetParam1(parameterObject["done"].asBoolean() ? 1 : 0);
74   CApplicationMessenger::Get().SendGUIMessage(msg, window->GetID());
75   return ACK;
76 }
77
78 JSONRPC_STATUS CInputOperations::ExecuteAction(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
79 {
80   int action;
81   if (!CButtonTranslator::TranslateActionString(parameterObject["action"].asString().c_str(), action))
82     return InvalidParams;
83
84   return SendAction(action);
85 }
86
87 JSONRPC_STATUS CInputOperations::Left(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
88 {
89   return SendAction(ACTION_MOVE_LEFT);
90 }
91
92 JSONRPC_STATUS CInputOperations::Right(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
93 {
94   return SendAction(ACTION_MOVE_RIGHT);
95 }
96
97 JSONRPC_STATUS CInputOperations::Down(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
98 {
99   return SendAction(ACTION_MOVE_DOWN);
100 }
101
102 JSONRPC_STATUS CInputOperations::Up(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
103 {
104   return SendAction(ACTION_MOVE_UP);
105 }
106
107 JSONRPC_STATUS CInputOperations::Select(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
108 {
109   return SendAction(ACTION_SELECT_ITEM);
110 }
111
112 JSONRPC_STATUS CInputOperations::Back(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
113 {
114   return SendAction(ACTION_NAV_BACK);
115 }
116
117 JSONRPC_STATUS CInputOperations::ContextMenu(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
118 {
119   return SendAction(ACTION_CONTEXT_MENU);
120 }
121
122 JSONRPC_STATUS CInputOperations::Info(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
123 {
124   return SendAction(ACTION_SHOW_INFO);
125 }
126
127 JSONRPC_STATUS CInputOperations::Home(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
128 {
129   return activateWindow(WINDOW_HOME);
130 }
131
132 JSONRPC_STATUS CInputOperations::ShowCodec(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
133 {
134   return SendAction(ACTION_SHOW_CODEC);
135 }
136
137 JSONRPC_STATUS CInputOperations::ShowOSD(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
138 {
139   return SendAction(ACTION_SHOW_OSD);
140 }