aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlwin Esch <alwin.esch@web.de>2022-09-04 10:29:13 +0200
committerAlwin Esch <alwin.esch@web.de>2022-09-04 10:29:13 +0200
commiteab635c8c1faaf53b5c6d1e54f0ec20fc469a9f3 (patch)
tree9d474427058ad14ac10c0856e3856ec800bf76b5
parentc78ed43814fd6c6af5385f42149585a44fd1b314 (diff)
[addons] allow on multiple selectable instance support one as default
With this change, activating an add-on that allows multiple instances via settings will automatically add one. Also must always one instance present.
-rw-r--r--xbmc/addons/IAddon.h5
-rw-r--r--xbmc/addons/addoninfo/AddonInfo.cpp7
-rw-r--r--xbmc/addons/gui/GUIDialogAddonSettings.cpp5
-rw-r--r--xbmc/pvr/addons/PVRClients.cpp8
4 files changed, 14 insertions, 11 deletions
diff --git a/xbmc/addons/IAddon.h b/xbmc/addons/IAddon.h
index ffca8b6488..43a0f7b8ea 100644
--- a/xbmc/addons/IAddon.h
+++ b/xbmc/addons/IAddon.h
@@ -32,6 +32,11 @@ constexpr const char* ADDON_SETTING_INSTANCE_ENABLED_VALUE = "kodi_addon_instanc
constexpr AddonInstanceId ADDON_SINGLETON_INSTANCE_ID = 0;
/*!
+ * @brief Identifier denoting initial first add-on instance.
+ */
+constexpr AddonInstanceId ADDON_FIRST_INSTANCE_ID = 1;
+
+/*!
* @brief Identifier denoting add-on instance id as unused.
*
* @sa ADDON::IAddonInstanceHandler
diff --git a/xbmc/addons/addoninfo/AddonInfo.cpp b/xbmc/addons/addoninfo/AddonInfo.cpp
index d66fbfb4fa..babfaab16b 100644
--- a/xbmc/addons/addoninfo/AddonInfo.cpp
+++ b/xbmc/addons/addoninfo/AddonInfo.cpp
@@ -283,8 +283,7 @@ std::vector<AddonInstanceId> CAddonInfo::GetKnownInstanceIds() const
const std::string searchPath = StringUtils::Format("special://profile/addon_data/{}/", m_id);
CFileItemList items;
- if (!XFILE::CDirectory::GetDirectory(searchPath, items, ".xml", XFILE::DIR_FLAG_NO_FILE_DIRS))
- return std::vector<AddonInstanceId>();
+ XFILE::CDirectory::GetDirectory(searchPath, items, ".xml", XFILE::DIR_FLAG_NO_FILE_DIRS);
std::vector<AddonInstanceId> ret;
@@ -301,6 +300,10 @@ std::vector<AddonInstanceId> CAddonInfo::GetKnownInstanceIds() const
}
}
+ // If no instances are used, create first as default.
+ if (ret.empty())
+ ret.emplace_back(ADDON_FIRST_INSTANCE_ID);
+
return ret;
}
diff --git a/xbmc/addons/gui/GUIDialogAddonSettings.cpp b/xbmc/addons/gui/GUIDialogAddonSettings.cpp
index cd932c8064..836224488b 100644
--- a/xbmc/addons/gui/GUIDialogAddonSettings.cpp
+++ b/xbmc/addons/gui/GUIDialogAddonSettings.cpp
@@ -162,6 +162,8 @@ bool CGUIDialogAddonSettings::ShowForAddon(const ADDON::AddonPtr& addon,
{
while (true)
{
+ const std::vector<ADDON::AddonInstanceId> ids = addon->GetKnownInstanceIds();
+
CFileItemList itemsGeneral;
CFileItemList itemsInstances;
@@ -175,6 +177,8 @@ bool CGUIDialogAddonSettings::ShowForAddon(const ADDON::AddonPtr& addon,
item->SetProperty("id", ADD_INSTANCE);
itemsGeneral.Add(item);
}
+ // Have always minimal 1 available and not allow this button in this case
+ if (ids.size() > 1)
{
const CFileItemPtr item = std::make_shared<CFileItem>(
g_localizeStrings.Get(10015)); // Remove add-on configuration
@@ -189,7 +193,6 @@ bool CGUIDialogAddonSettings::ShowForAddon(const ADDON::AddonPtr& addon,
itemsGeneral.Add(item);
}
- const std::vector<ADDON::AddonInstanceId> ids = addon->GetKnownInstanceIds();
ADDON::AddonInstanceId highestId = 0;
for (const auto& id : ids)
{
diff --git a/xbmc/pvr/addons/PVRClients.cpp b/xbmc/pvr/addons/PVRClients.cpp
index 9a49414d16..127207c751 100644
--- a/xbmc/pvr/addons/PVRClients.cpp
+++ b/xbmc/pvr/addons/PVRClients.cpp
@@ -137,14 +137,6 @@ void CPVRClients::UpdateAddons(const std::string& changedAddonId /*= ""*/,
}
}
- if (instanceIdsWithStatus.empty() && addon->SupportsInstanceSettings())
- {
- // User has not yet created an instance configuration.
- // Create an instance with default instance settings.
- instanceIdsWithStatus.emplace_back(
- std::pair<ADDON::AddonInstanceId, bool>(1, bEnabled)); //! @todo get rid of magic number
- }
-
for (const auto& instanceInfo : instanceIdsWithStatus)
{
const ADDON::AddonInstanceId instanceId = instanceInfo.first;