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"
31 #include "utils/CharsetConverter.h"
33 using namespace JSONRPC;
35 //TODO the breakage of the screensaver should be refactored
36 //to one central super duper place for getting rid of
38 bool CInputOperations::handleScreenSaver()
40 g_application.ResetScreenSaver();
41 if (g_application.WakeUpScreenSaverAndDPMS())
47 JSONRPC_STATUS CInputOperations::SendAction(int actionID, bool wakeScreensaver /* = true */, bool waitResult /* = false */)
49 if(!wakeScreensaver || !handleScreenSaver())
51 g_application.ResetSystemIdleTimer();
52 g_audioManager.PlayActionSound(actionID);
53 CApplicationMessenger::Get().SendAction(CAction(actionID), WINDOW_INVALID, waitResult);
58 JSONRPC_STATUS CInputOperations::activateWindow(int windowID)
60 if(!handleScreenSaver())
61 CApplicationMessenger::Get().ActivateWindow(windowID, std::vector<CStdString>(), false);
66 JSONRPC_STATUS CInputOperations::SendText(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
68 CGUIWindow *window = g_windowManager.GetWindow(g_windowManager.GetFocusedWindow());
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());
79 JSONRPC_STATUS CInputOperations::ExecuteAction(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
82 if (!CButtonTranslator::TranslateActionString(parameterObject["action"].asString().c_str(), action))
85 return SendAction(action);
88 JSONRPC_STATUS CInputOperations::Left(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
90 return SendAction(ACTION_MOVE_LEFT);
93 JSONRPC_STATUS CInputOperations::Right(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
95 return SendAction(ACTION_MOVE_RIGHT);
98 JSONRPC_STATUS CInputOperations::Down(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
100 return SendAction(ACTION_MOVE_DOWN);
103 JSONRPC_STATUS CInputOperations::Up(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
105 return SendAction(ACTION_MOVE_UP);
108 JSONRPC_STATUS CInputOperations::Select(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
110 return SendAction(ACTION_SELECT_ITEM);
113 JSONRPC_STATUS CInputOperations::Back(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
115 return SendAction(ACTION_NAV_BACK);
118 JSONRPC_STATUS CInputOperations::ContextMenu(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
120 return SendAction(ACTION_CONTEXT_MENU);
123 JSONRPC_STATUS CInputOperations::Info(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
125 return SendAction(ACTION_SHOW_INFO);
128 JSONRPC_STATUS CInputOperations::Home(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
130 return activateWindow(WINDOW_HOME);
133 JSONRPC_STATUS CInputOperations::ShowCodec(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
135 return SendAction(ACTION_SHOW_CODEC);
138 JSONRPC_STATUS CInputOperations::ShowOSD(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
140 return SendAction(ACTION_SHOW_OSD);