1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/*
* Copyright (C) 2011-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "GUIOperations.h"
#include "GUIInfoManager.h"
#include "ServiceBroker.h"
#include "addons/AddonManager.h"
#include "addons/IAddon.h"
#include "addons/addoninfo/AddonType.h"
#include "application/Application.h"
#include "dialogs/GUIDialogKaiToast.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/StereoscopicsManager.h"
#include "input/Key.h"
#include "input/WindowTranslator.h"
#include "messaging/ApplicationMessenger.h"
#include "rendering/RenderSystem.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
#include "utils/Variant.h"
using namespace JSONRPC;
using namespace ADDON;
JSONRPC_STATUS CGUIOperations::GetProperties(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
{
CVariant properties = CVariant(CVariant::VariantTypeObject);
for (unsigned int index = 0; index < parameterObject["properties"].size(); index++)
{
std::string propertyName = parameterObject["properties"][index].asString();
CVariant property;
JSONRPC_STATUS ret;
if ((ret = GetPropertyValue(propertyName, property)) != OK)
return ret;
properties[propertyName] = property;
}
result = properties;
return OK;
}
JSONRPC_STATUS CGUIOperations::ActivateWindow(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
{
int iWindow = CWindowTranslator::TranslateWindow(parameterObject["window"].asString());
if (iWindow != WINDOW_INVALID)
{
std::vector<std::string> params;
for (CVariant::const_iterator_array param = parameterObject["parameters"].begin_array();
param != parameterObject["parameters"].end_array(); ++param)
{
if (param->isString() && !param->empty())
params.push_back(param->asString());
}
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_GUI_ACTIVATE_WINDOW, iWindow, 0, nullptr, "",
params);
return ACK;
}
return InvalidParams;
}
JSONRPC_STATUS CGUIOperations::ShowNotification(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
{
std::string image = parameterObject["image"].asString();
std::string title = parameterObject["title"].asString();
std::string message = parameterObject["message"].asString();
unsigned int displaytime = (unsigned int)parameterObject["displaytime"].asUnsignedInteger();
if (image.compare("info") == 0)
CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, title, message, displaytime);
else if (image.compare("warning") == 0)
CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Warning, title, message, displaytime);
else if (image.compare("error") == 0)
CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, title, message, displaytime);
else
CGUIDialogKaiToast::QueueNotification(image, title, message, displaytime);
return ACK;
}
JSONRPC_STATUS CGUIOperations::SetFullscreen(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
{
if ((parameterObject["fullscreen"].isString() &&
parameterObject["fullscreen"].asString().compare("toggle") == 0) ||
(parameterObject["fullscreen"].isBoolean() &&
parameterObject["fullscreen"].asBoolean() != g_application.IsFullScreen()))
{
CServiceBroker::GetAppMessenger()->SendMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1,
static_cast<void*>(new CAction(ACTION_SHOW_GUI)));
}
else if (!parameterObject["fullscreen"].isBoolean() && !parameterObject["fullscreen"].isString())
return InvalidParams;
return GetPropertyValue("fullscreen", result);
}
JSONRPC_STATUS CGUIOperations::SetStereoscopicMode(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
{
CAction action = CStereoscopicsManager::ConvertActionCommandToAction("SetStereoMode", parameterObject["mode"].asString());
if (action.GetID() != ACTION_NONE)
{
CServiceBroker::GetAppMessenger()->SendMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1,
static_cast<void*>(new CAction(action)));
return ACK;
}
return InvalidParams;
}
JSONRPC_STATUS CGUIOperations::GetStereoscopicModes(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
{
for (int i = RENDER_STEREO_MODE_OFF; i < RENDER_STEREO_MODE_COUNT; i++)
{
RENDER_STEREO_MODE mode = (RENDER_STEREO_MODE) i;
if (CServiceBroker::GetRenderSystem()->SupportsStereo(mode))
result["stereoscopicmodes"].push_back(GetStereoModeObjectFromGuiMode(mode));
}
return OK;
}
JSONRPC_STATUS CGUIOperations::GetPropertyValue(const std::string &property, CVariant &result)
{
if (property == "currentwindow")
{
result["label"] = CServiceBroker::GetGUI()->GetInfoManager().GetLabel(
CServiceBroker::GetGUI()->GetInfoManager().TranslateString("System.CurrentWindow"),
INFO::DEFAULT_CONTEXT);
result["id"] = CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindowOrDialog();
}
else if (property == "currentcontrol")
result["label"] = CServiceBroker::GetGUI()->GetInfoManager().GetLabel(
CServiceBroker::GetGUI()->GetInfoManager().TranslateString("System.CurrentControl"),
INFO::DEFAULT_CONTEXT);
else if (property == "skin")
{
std::string skinId = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_LOOKANDFEEL_SKIN);
AddonPtr addon;
if (!CServiceBroker::GetAddonMgr().GetAddon(skinId, addon, AddonType::SKIN,
OnlyEnabled::CHOICE_YES))
return InternalError;
result["id"] = skinId;
if (addon.get())
result["name"] = addon->Name();
}
else if (property == "fullscreen")
result = g_application.IsFullScreen();
else if (property == "stereoscopicmode")
{
const CStereoscopicsManager &stereoscopicsManager = CServiceBroker::GetGUI()->GetStereoscopicsManager();
result = GetStereoModeObjectFromGuiMode(stereoscopicsManager.GetStereoMode());
}
else
return InvalidParams;
return OK;
}
CVariant CGUIOperations::GetStereoModeObjectFromGuiMode(const RENDER_STEREO_MODE &mode)
{
const CStereoscopicsManager &stereoscopicsManager = CServiceBroker::GetGUI()->GetStereoscopicsManager();
CVariant modeObj(CVariant::VariantTypeObject);
modeObj["mode"] = stereoscopicsManager.ConvertGuiStereoModeToString(mode);
modeObj["label"] = stereoscopicsManager.GetLabelForStereoMode(mode);
return modeObj;
}
|