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
|
/*
* Copyright (C) 2015-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 "AddonSystemSettings.h"
#include "ServiceBroker.h"
#include "addons/AddonInstaller.h"
#include "addons/AddonManager.h"
#include "addons/IAddon.h"
#include "addons/addoninfo/AddonInfo.h"
#include "addons/addoninfo/AddonType.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/LocalizeStrings.h"
#include "messaging/helpers/DialogHelper.h"
#include "messaging/helpers/DialogOKHelper.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
#include "settings/lib/Setting.h"
#include "utils/StringUtils.h"
#include "utils/log.h"
namespace ADDON
{
CAddonSystemSettings::CAddonSystemSettings()
: m_activeSettings{
{AddonType::AUDIOENCODER, CSettings::SETTING_AUDIOCDS_ENCODER},
{AddonType::RESOURCE_LANGUAGE, CSettings::SETTING_LOCALE_LANGUAGE},
{AddonType::RESOURCE_UISOUNDS, CSettings::SETTING_LOOKANDFEEL_SOUNDSKIN},
{AddonType::SCRAPER_ALBUMS, CSettings::SETTING_MUSICLIBRARY_ALBUMSSCRAPER},
{AddonType::SCRAPER_ARTISTS, CSettings::SETTING_MUSICLIBRARY_ARTISTSSCRAPER},
{AddonType::SCRAPER_MOVIES, CSettings::SETTING_SCRAPERS_MOVIESDEFAULT},
{AddonType::SCRAPER_MUSICVIDEOS, CSettings::SETTING_SCRAPERS_MUSICVIDEOSDEFAULT},
{AddonType::SCRAPER_TVSHOWS, CSettings::SETTING_SCRAPERS_TVSHOWSDEFAULT},
{AddonType::SCREENSAVER, CSettings::SETTING_SCREENSAVER_MODE},
{AddonType::SCRIPT_WEATHER, CSettings::SETTING_WEATHER_ADDON},
{AddonType::SKIN, CSettings::SETTING_LOOKANDFEEL_SKIN},
{AddonType::WEB_INTERFACE, CSettings::SETTING_SERVICES_WEBSKIN},
{AddonType::VISUALIZATION, CSettings::SETTING_MUSICPLAYER_VISUALISATION},
}
{}
CAddonSystemSettings& CAddonSystemSettings::GetInstance()
{
static CAddonSystemSettings inst;
return inst;
}
void CAddonSystemSettings::OnSettingAction(const std::shared_ptr<const CSetting>& setting)
{
if (setting->GetId() == CSettings::SETTING_ADDONS_MANAGE_DEPENDENCIES)
{
std::vector<std::string> params{"addons://dependencies/", "return"};
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_ADDON_BROWSER, params);
}
else if (setting->GetId() == CSettings::SETTING_ADDONS_SHOW_RUNNING)
{
std::vector<std::string> params{"addons://running/", "return"};
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_ADDON_BROWSER, params);
}
else if (setting->GetId() == CSettings::SETTING_ADDONS_REMOVE_ORPHANED_DEPENDENCIES)
{
using namespace KODI::MESSAGING::HELPERS;
const auto removedItems = CAddonInstaller::GetInstance().RemoveOrphanedDepsRecursively();
if (removedItems.size() > 0)
{
const auto message =
StringUtils::Format(g_localizeStrings.Get(36641), StringUtils::Join(removedItems, ", "));
ShowOKDialogText(CVariant{36640}, CVariant{message}); // "following orphaned were removed..."
}
else
{
ShowOKDialogText(CVariant{36640}, CVariant{36642}); // "no orphaned found / removed"
}
}
}
void CAddonSystemSettings::OnSettingChanged(const std::shared_ptr<const CSetting>& setting)
{
using namespace KODI::MESSAGING::HELPERS;
if (setting->GetId() == CSettings::SETTING_ADDONS_ALLOW_UNKNOWN_SOURCES &&
CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
CSettings::SETTING_ADDONS_ALLOW_UNKNOWN_SOURCES) &&
ShowYesNoDialogText(19098, 36618) != DialogResponse::CHOICE_YES)
{
CServiceBroker::GetSettingsComponent()->GetSettings()->SetBool(CSettings::SETTING_ADDONS_ALLOW_UNKNOWN_SOURCES, false);
}
}
bool CAddonSystemSettings::GetActive(AddonType type, AddonPtr& addon)
{
auto it = m_activeSettings.find(type);
if (it != m_activeSettings.end())
{
auto settingValue = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(it->second);
return CServiceBroker::GetAddonMgr().GetAddon(settingValue, addon, type,
OnlyEnabled::CHOICE_YES);
}
return false;
}
bool CAddonSystemSettings::SetActive(AddonType type, const std::string& addonID)
{
auto it = m_activeSettings.find(type);
if (it != m_activeSettings.end())
{
CServiceBroker::GetSettingsComponent()->GetSettings()->SetString(it->second, addonID);
return true;
}
return false;
}
bool CAddonSystemSettings::IsActive(const IAddon& addon)
{
AddonPtr active;
return GetActive(addon.Type(), active) && active->ID() == addon.ID();
}
bool CAddonSystemSettings::UnsetActive(const AddonInfoPtr& addon)
{
auto it = m_activeSettings.find(addon->MainType());
if (it == m_activeSettings.end())
return true;
auto setting = std::static_pointer_cast<CSettingString>(CServiceBroker::GetSettingsComponent()->GetSettings()->GetSetting(it->second));
if (setting->GetValue() != addon->ID())
return true;
if (setting->GetDefault() == addon->ID())
return false; // Cant unset defaults
setting->Reset();
return true;
}
int CAddonSystemSettings::GetAddonAutoUpdateMode() const
{
return CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(
CSettings::SETTING_ADDONS_AUTOUPDATES);
}
AddonRepoUpdateMode CAddonSystemSettings::GetAddonRepoUpdateMode() const
{
const int updateMode = CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(
CSettings::SETTING_ADDONS_UPDATEMODE);
return static_cast<AddonRepoUpdateMode>(updateMode);
}
}
|