| 1 | /* |
| 2 | * Copyright (C) 2012-2018 Team Kodi |
| 3 | * This file is part of Kodi - https://kodi.tv |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 6 | * See LICENSES/README.md for more information. |
| 7 | */ |
| 8 | |
| 9 | #include "guilib/guiinfo/VisualisationGUIInfo.h" |
| 10 | |
| 11 | #include "GUIUserMessages.h" |
| 12 | #include "ServiceBroker.h" |
| 13 | #include "addons/Addon.h" |
| 14 | #include "addons/AddonManager.h" |
| 15 | #include "guilib/GUIComponent.h" |
| 16 | #include "guilib/GUIVisualisationControl.h" |
| 17 | #include "guilib/GUIWindowManager.h" |
| 18 | #include "guilib/guiinfo/GUIInfo.h" |
| 19 | #include "guilib/guiinfo/GUIInfoLabels.h" |
| 20 | #include "settings/Settings.h" |
| 21 | #include "settings/SettingsComponent.h" |
| 22 | #include "utils/URIUtils.h" |
| 23 | |
| 24 | using namespace KODI::GUILIB::GUIINFO; |
| 25 | |
| 26 | bool CVisualisationGUIInfo::InitCurrentItem(CFileItem *item) |
| 27 | { |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | bool CVisualisationGUIInfo::GetLabel(std::string& value, const CFileItem *item, int contextWindow, const CGUIInfo &info, std::string *fallback) const |
| 32 | { |
| 33 | switch (info.m_info) |
| 34 | { |
| 35 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 36 | // VISUALISATION_* |
| 37 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 38 | case VISUALISATION_PRESET: |
| 39 | { |
| 40 | CGUIMessage msg(GUI_MSG_GET_VISUALISATION, 0, 0); |
| 41 | CServiceBroker::GetGUI()->GetWindowManager().SendMessage(msg); |
| 42 | if (msg.GetPointer()) |
| 43 | { |
| 44 | CGUIVisualisationControl* viz = static_cast<CGUIVisualisationControl*>(msg.GetPointer()); |
| 45 | if (viz) |
| 46 | { |
| 47 | value = viz->GetActivePresetName(); |
| 48 | URIUtils::RemoveExtension(value); |
| 49 | return true; |
| 50 | } |
| 51 | } |
| 52 | break; |
| 53 | } |
| 54 | case VISUALISATION_NAME: |
| 55 | { |
| 56 | ADDON::AddonPtr addon; |
| 57 | value = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_MUSICPLAYER_VISUALISATION); |
| 58 | if (CServiceBroker::GetAddonMgr().GetAddon(value, addon, ADDON::OnlyEnabled::CHOICE_YES) && |
| 59 | addon) |
| 60 | { |
| 61 | value = addon->Name(); |
| 62 | return true; |
| 63 | } |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | bool CVisualisationGUIInfo::GetInt(int& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const |
| 72 | { |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | bool CVisualisationGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const |
| 77 | { |
| 78 | switch (info.m_info) |
| 79 | { |
| 80 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 81 | // VISUALISATION_* |
| 82 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 83 | case VISUALISATION_LOCKED: |
| 84 | { |
| 85 | CGUIMessage msg(GUI_MSG_GET_VISUALISATION, 0, 0); |
| 86 | CServiceBroker::GetGUI()->GetWindowManager().SendMessage(msg); |
| 87 | if (msg.GetPointer()) |
| 88 | { |
| 89 | CGUIVisualisationControl *pVis = static_cast<CGUIVisualisationControl*>(msg.GetPointer()); |
| 90 | value = pVis->IsLocked(); |
| 91 | return true; |
| 92 | } |
| 93 | break; |
| 94 | } |
| 95 | case VISUALISATION_ENABLED: |
| 96 | { |
| 97 | value = !CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_MUSICPLAYER_VISUALISATION).empty(); |
| 98 | return true; |
| 99 | } |
| 100 | case VISUALISATION_HAS_PRESETS: |
| 101 | { |
| 102 | CGUIMessage msg(GUI_MSG_GET_VISUALISATION, 0, 0); |
| 103 | CServiceBroker::GetGUI()->GetWindowManager().SendMessage(msg); |
| 104 | if (msg.GetPointer()) |
| 105 | { |
| 106 | CGUIVisualisationControl* viz = static_cast<CGUIVisualisationControl*>(msg.GetPointer()); |
| 107 | value = (viz && viz->HasPresets()); |
| 108 | return true; |
| 109 | } |
| 110 | break; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return false; |
| 115 | } |