Permalink
Browse files

added: Support for addons to be disabled while still being installed.

git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@30733 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
  • Loading branch information...
1 parent dcf1bfd commit 56aa69b2938a43b7b06f08e2dc179ca4100ad092 jmarshallnz committed Jun 1, 2010
Showing with 118 additions and 12 deletions.
  1. +82 −0 xbmc/AddonDatabase.cpp
  2. +21 −1 xbmc/AddonDatabase.h
  3. +12 −8 xbmc/addons/AddonManager.cpp
  4. +3 −3 xbmc/addons/AddonManager.h
@@ -61,6 +61,10 @@ bool CAddonDatabase::CreateTables()
CLog::Log(LOGINFO, "create addonlinkrepo table");
m_pDS->exec("CREATE TABLE addonlinkrepo (idRepo integer, idAddon integer)\n");
+
+ CLog::Log(LOGINFO, "create disabled table");
+ m_pDS->exec("CREATE TABLE disabled (id integer primary key, addonID text)\n");
+ m_pDS->exec("CREATE INDEX idxDisabled ON disabled(addonID)");
}
catch (...)
{
@@ -103,6 +107,11 @@ bool CAddonDatabase::UpdateOldVersion(int version)
m_pDS->exec("DROP TABLE addon");
m_pDS->exec("ALTER TABLE addonnew RENAME TO addon");
}
+ if (version < 8)
+ {
+ m_pDS->exec("CREATE TABLE disabled (id integer primary key, addonID text)\n");
+ m_pDS->exec("CREATE INDEX idxDisabled ON disabled(addonID)");
+ }
return true;
}
@@ -452,3 +461,76 @@ void CAddonDatabase::SetPropertiesFromAddon(const AddonPtr& addon,
pItem->SetProperty("Addon.Rating", addon->Stars());
pItem->SetProperty("Addon.Path", addon->Path());
}
+
+bool CAddonDatabase::DisableAddon(const CStdString &addonID, bool disable /* = true */)
+{
+ try
+ {
+ if (NULL == m_pDB.get()) return false;
+ if (NULL == m_pDS.get()) return false;
+
+ if (disable)
+ {
+ CStdString sql = FormatSQL("select id from disabled where addonID='%s'", addonID.c_str());
+ m_pDS->query(sql.c_str());
+ if (m_pDS->eof()) // not found
+ {
+ m_pDS->close();
+ sql = FormatSQL("insert into disabled(id, addonID) values(NULL, '%s')", addonID.c_str());
+ m_pDS->exec(sql);
+ return true;
+ }
+ return false; // already disabled or failed query
+ }
+ else
+ {
+ CStdString sql = FormatSQL("delete from disabled where addonID='%s'", addonID.c_str());
+ m_pDS->exec(sql);
+ }
+ return true;
+ }
+ catch (...)
+ {
+ CLog::Log(LOGERROR, "%s failed on addon '%s'", __FUNCTION__, addonID.c_str());
+ }
+ return false;
+}
+
+bool CAddonDatabase::IsAddonDisabled(const CStdString &addonID)
+{
+ try
+ {
+ if (NULL == m_pDB.get()) return false;
+ if (NULL == m_pDS.get()) return false;
+
+ CStdString sql = FormatSQL("select id from disabled where addonID='%s'", addonID.c_str());
+ m_pDS->query(sql.c_str());
+ bool ret = !m_pDS->eof(); // in the disabled table -> disabled
+ m_pDS->close();
+ return ret;
+ }
+ catch (...)
+ {
+ CLog::Log(LOGERROR, "%s failed on addon %s", __FUNCTION__, addonID.c_str());
+ }
+ return false;
+}
+
+bool CAddonDatabase::HasDisabledAddons()
+{
+ try
+ {
+ if (NULL == m_pDB.get()) return false;
+ if (NULL == m_pDS.get()) return false;
+
+ m_pDS->query("select count(id) from disabled");
+ bool ret = !m_pDS->eof() && m_pDS->fv(0).get_asInt() > 0; // have rows -> have disabled addons
+ m_pDS->close();
+ return ret;
+ }
+ catch (...)
+ {
+ CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
+ }
+ return false;
+}
View
@@ -48,10 +48,30 @@ class CAddonDatabase : public CDatabase
bool Search(const CStdString& search, ADDON::VECADDONS& items);
bool SearchTitle(const CStdString& strSearch, ADDON::VECADDONS& items);
static void SetPropertiesFromAddon(const ADDON::AddonPtr& addon, CFileItemPtr& item);
+
+ /*! \brief Disable an addon.
+ Sets a flag that this addon has been disabled. If disabled, it is usually still available on disk.
+ \param addonID id of the addon to disable
+ \param disable whether to enable or disable. Defaults to true (disable)
+ \return true on success, false on failure
+ \sa IsAddonDisabled, HasDisabledAddons */
+ bool DisableAddon(const CStdString &addonID, bool disable = true);
+
+ /*! \brief Check whether an addon has been disabled via DisableAddon.
+ \param addonID id of the addon to check
+ \return true if the addon is disabled, false otherwise
+ \sa DisableAddon, HasDisabledAddons */
+ bool IsAddonDisabled(const CStdString &addonID);
+
+ /*! \brief Check whether we have disabled addons.
+ \return true if we have disabled addons, false otherwise
+ \sa DisableAddon, IsAddonDisabled */
+ bool HasDisabledAddons();
+
protected:
virtual bool CreateTables();
virtual bool UpdateOldVersion(int version);
- virtual int GetMinVersion() const { return 7; }
+ virtual int GetMinVersion() const { return 8; }
const char *GetDefaultDBName() const { return "Addons"; }
};
@@ -265,56 +265,60 @@ void CAddonMgr::DeInit()
m_cpluff = NULL;
}
-bool CAddonMgr::HasAddons(const TYPE &type, bool enabledOnly/*= true*/)
+bool CAddonMgr::HasAddons(const TYPE &type, bool enabled /*= true*/)
{
// TODO: This isn't particularly efficient as we create an addon type for each addon using the Factory, just so
// we can check addon dependencies in the addon constructor.
VECADDONS addons;
- return GetAddons(type, addons, enabledOnly);
+ return GetAddons(type, addons, enabled);
}
-bool CAddonMgr::GetAllAddons(VECADDONS &addons, bool enabledOnly/*= true*/)
+bool CAddonMgr::GetAllAddons(VECADDONS &addons, bool enabled /*= true*/)
{
for (int i = ADDON_UNKNOWN+1; i < ADDON_VIZ_LIBRARY; ++i)
{
if (ADDON_REPOSITORY == (TYPE)i)
continue;
VECADDONS temp;
- if (CAddonMgr::Get().GetAddons((TYPE)i, temp, enabledOnly))
+ if (CAddonMgr::Get().GetAddons((TYPE)i, temp, enabled))
addons.insert(addons.end(), temp.begin(), temp.end());
}
return !addons.empty();
}
-bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabledOnly/*= true*/)
+bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabled /* = true */)
{
CSingleLock lock(m_critSection);
addons.clear();
cp_status_t status;
int num;
+ CAddonDatabase db;
+ if (!db.Open()) return false;
CStdString ext_point(TranslateType(type));
cp_extension_t **exts = m_cpluff->get_extensions_info(m_cp_context, ext_point.c_str(), &status, &num);
for(int i=0; i <num; i++)
{
AddonPtr addon(Factory(exts[i]));
- if (addon)
+ if (addon && db.IsAddonDisabled(addon->ID()) != enabled)
addons.push_back(addon);
}
m_cpluff->release_info(m_cp_context, exts);
return addons.size() > 0;
}
-bool CAddonMgr::GetAddon(const CStdString &str, AddonPtr &addon, const TYPE &type/*=ADDON_UNKNOWN*/, bool enabledOnly/*= true*/)
+bool CAddonMgr::GetAddon(const CStdString &str, AddonPtr &addon, const TYPE &type/*=ADDON_UNKNOWN*/, bool enabled/*= true*/)
{
CSingleLock lock(m_critSection);
+ CAddonDatabase db;
+ if (!db.Open()) return false;
cp_status_t status;
cp_plugin_info_t *cpaddon = m_cpluff->get_plugin_info(m_cp_context, str.c_str(), &status);
if (status == CP_OK && cpaddon)
{
addon = GetAddonFromDescriptor(cpaddon);
m_cpluff->release_info(m_cp_context, cpaddon);
- return NULL != addon.get();
+ return NULL != addon.get() && db.IsAddonDisabled(addon->ID()) != enabled;
}
if (cpaddon)
m_cpluff->release_info(m_cp_context, cpaddon);
@@ -86,10 +86,10 @@ namespace ADDON
/* Addon access */
bool GetDefault(const TYPE &type, AddonPtr &addon);
- bool GetAddon(const CStdString &str, AddonPtr &addon, const TYPE &type = ADDON_UNKNOWN, bool enabledOnly = true);
- bool HasAddons(const TYPE &type, bool enabledOnly = true);
+ bool GetAddon(const CStdString &str, AddonPtr &addon, const TYPE &type = ADDON_UNKNOWN, bool enabled = true);
+ bool HasAddons(const TYPE &type, bool enabled = true);
bool GetAddons(const TYPE &type, VECADDONS &addons, bool enabled = true);
- bool GetAllAddons(VECADDONS &addons, bool enabledOnly = true);
+ bool GetAllAddons(VECADDONS &addons, bool enabled = true);
CStdString GetString(const CStdString &id, const int number);
const char *GetTranslatedString(const cp_cfg_element_t *root, const char *tag);

0 comments on commit 56aa69b

Please sign in to comment.