[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / interfaces / json-rpc / InputOperations.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.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 #include "utils/CharsetConverter.h"
32
33 using namespace JSONRPC;
34
35 //TODO the breakage of the screensaver should be refactored
36 //to one central super duper place for getting rid of
37 //1 million dupes
38 bool CInputOperations::handleScreenSaver()
39 {
40   g_application.ResetScreenSaver();
41   if (g_application.WakeUpScreenSaverAndDPMS())
42     return true;
43
44   return false;
45 }
46
47 JSONRPC_STATUS CInputOperations::SendAction(int actionID, bool wakeScreensaver /* = true */, bool waitResult /* = false */)
48 {
49   if(!wakeScreensaver || !handleScreenSaver())
50   {
51     g_application.ResetSystemIdleTimer();
52     g_audioManager.PlayActionSound(actionID);
53     CApplicationMessenger::Get().SendAction(CAction(actionID), WINDOW_INVALID, waitResult);
54   }
55   return ACK;
56 }
57
58 JSONRPC_STATUS CInputOperations::activateWindow(int windowID)
59 {
60   if(!handleScreenSaver())
61     CApplicationMessenger::Get().ActivateWindow(windowID, std::vector<CStdString>(), false);
62
63   return ACK;
64 }
65
66 JSONRPC_STATUS CInputOperations::SendText(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
67 {
68   CGUIWindow *window = g_windowManager.GetWindow(g_windowManager.GetFocusedWindow());
69   if (!window)
70     return InternalError;
71
72   CGUIMessage msg(GUI_MSG_SET_TEXT, 0, 0);
73   msg.SetLabel(parameterObject["text"].asString());
74   msg.SetParam1(parameterObject["done"].asBoolean() ? 1 : 0);
75   CApplicationMessenger::Get().SendGUIMessage(msg, window->GetID());
76   return ACK;
77 }
78
79 JSONRPC_STATUS CInputOperations::ExecuteAction(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
80 {
81   int action;
82   if (!CButtonTranslator::TranslateActionString(parameterObject["action"].asString().c_str(), action))
83     return InvalidParams;
84
85   return SendAction(action);
86 }
87
88 JSONRPC_STATUS CInputOperations::Left(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
89 {
90   return SendAction(ACTION_MOVE_LEFT);
91 }
92
93 JSONRPC_STATUS CInputOperations::Right(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
94 {
95   return SendAction(ACTION_MOVE_RIGHT);
96 }
97
98 JSONRPC_STATUS CInputOperations::Down(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
99 {
100   return SendAction(ACTION_MOVE_DOWN);
101 }
102
103 JSONRPC_STATUS CInputOperations::Up(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
104 {
105   return SendAction(ACTION_MOVE_UP);
106 }
107
108 JSONRPC_STATUS CInputOperations::Select(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
109 {
110   return SendAction(ACTION_SELECT_ITEM);
111 }
112
113 JSONRPC_STATUS CInputOperations::Back(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
114 {
115   return SendAction(ACTION_NAV_BACK);
116 }
117
118 JSONRPC_STATUS CInputOperations::ContextMenu(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
119 {
120   return SendAction(ACTION_CONTEXT_MENU);
121 }
122
123 JSONRPC_STATUS CInputOperations::Info(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
124 {
125   return SendAction(ACTION_SHOW_INFO);
126 }
127
128 JSONRPC_STATUS CInputOperations::Home(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
129 {
130   return activateWindow(WINDOW_HOME);
131 }
132
133 JSONRPC_STATUS CInputOperations::ShowCodec(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
134 {
135   return SendAction(ACTION_SHOW_CODEC);
136 }
137
138 JSONRPC_STATUS CInputOperations::ShowOSD(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
139 {
140   return SendAction(ACTION_SHOW_OSD);
141 }