2 * Copyright (C) 2005-2013 Team XBMC
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)
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.
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/>.
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"
32 using namespace JSONRPC;
34 //TODO the breakage of the screensaver should be refactored
35 //to one central super duper place for getting rid of
37 bool CInputOperations::handleScreenSaver()
39 g_application.ResetScreenSaver();
40 if (g_application.WakeUpScreenSaverAndDPMS())
46 JSONRPC_STATUS CInputOperations::SendAction(int actionID, bool wakeScreensaver /* = true */, bool waitResult /* = false */)
48 if(!wakeScreensaver || !handleScreenSaver())
50 g_application.ResetSystemIdleTimer();
51 g_audioManager.PlayActionSound(actionID);
52 CApplicationMessenger::Get().SendAction(CAction(actionID), WINDOW_INVALID, waitResult);
57 JSONRPC_STATUS CInputOperations::activateWindow(int windowID)
59 if(!handleScreenSaver())
60 CApplicationMessenger::Get().ActivateWindow(windowID, std::vector<CStdString>(), false);
65 JSONRPC_STATUS CInputOperations::SendText(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
67 CGUIWindow *window = g_windowManager.GetWindow(g_windowManager.GetFocusedWindow());
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());
78 JSONRPC_STATUS CInputOperations::ExecuteAction(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
81 if (!CButtonTranslator::TranslateActionString(parameterObject["action"].asString().c_str(), action))
84 return SendAction(action);
87 JSONRPC_STATUS CInputOperations::Left(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
89 return SendAction(ACTION_MOVE_LEFT);
92 JSONRPC_STATUS CInputOperations::Right(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
94 return SendAction(ACTION_MOVE_RIGHT);
97 JSONRPC_STATUS CInputOperations::Down(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
99 return SendAction(ACTION_MOVE_DOWN);
102 JSONRPC_STATUS CInputOperations::Up(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
104 return SendAction(ACTION_MOVE_UP);
107 JSONRPC_STATUS CInputOperations::Select(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
109 return SendAction(ACTION_SELECT_ITEM);
112 JSONRPC_STATUS CInputOperations::Back(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
114 return SendAction(ACTION_NAV_BACK);
117 JSONRPC_STATUS CInputOperations::ContextMenu(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
119 return SendAction(ACTION_CONTEXT_MENU);
122 JSONRPC_STATUS CInputOperations::Info(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
124 return SendAction(ACTION_SHOW_INFO);
127 JSONRPC_STATUS CInputOperations::Home(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
129 return activateWindow(WINDOW_HOME);
132 JSONRPC_STATUS CInputOperations::ShowCodec(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
134 return SendAction(ACTION_SHOW_CODEC);
137 JSONRPC_STATUS CInputOperations::ShowOSD(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
139 return SendAction(ACTION_SHOW_OSD);