Permalink
Browse files

[fix] - make changed settings visible to python addons

  • Loading branch information...
1 parent 3ee0a7b commit 0c2e7a9a4cd7f97d82b1ab70722de57879ca1a9c @Memphiz Memphiz committed Nov 16, 2011
View
@@ -368,9 +368,9 @@ bool CAddon::HasSettings()
return LoadSettings();
}
-bool CAddon::LoadSettings()
+bool CAddon::LoadSettings(bool bForce /* = false*/)
{
- if (m_settingsLoaded)
+ if (m_settingsLoaded && !bForce)
return true;
if (!m_hasSettings)
return false;
@@ -405,6 +405,11 @@ bool CAddon::HasUserSettings()
return m_userSettingsLoaded;
}
+bool CAddon::ReloadSettings()
+{
+ return LoadSettings(true);
+}
+
bool CAddon::LoadUserSettings()
{
m_userSettingsLoaded = false;
@@ -436,6 +441,8 @@ void CAddon::SaveSettings(void)
TiXmlDocument doc;
SettingsToXML(doc);
doc.SaveFile(m_userSettingsPath);
+
+ CAddonMgr::Get().ReloadSettings(ID());//push the settings changes to the running addon instance
}
CStdString CAddon::GetSetting(const CStdString& key)
View
@@ -168,6 +168,7 @@ class CAddon : public IAddon
\return true if min_version <= version <= current_version, false otherwise.
*/
bool MeetsVersion(const AddonVersion &version) const;
+ virtual bool ReloadSettings();
protected:
CAddon(const CAddon&); // protected as all copying is handled by Clone()
@@ -176,10 +177,11 @@ class CAddon : public IAddon
virtual void BuildLibName(const cp_extension_t *ext = NULL);
/*! \brief Load the default settings and override these with any previously configured user settings
+ \param bForce force the load of settings even if they are already loaded (reload)
\return true if settings exist, false otherwise
\sa LoadUserSettings, SaveSettings, HasSettings, HasUserSettings, GetSetting, UpdateSetting
*/
- virtual bool LoadSettings();
+ virtual bool LoadSettings(bool bForce = false);
/*! \brief Load the user settings
\return true if user settings exist, false otherwise
@@ -299,6 +299,49 @@ bool CAddonMgr::GetAllAddons(VECADDONS &addons, bool enabled /*= true*/, bool al
return !addons.empty();
}
+void CAddonMgr::AddToUpdateableAddons(AddonPtr &pAddon)
+{
+ CSingleLock lock(m_critSection);
+ m_updateableAddons.push_back(pAddon);
+}
+
+void CAddonMgr::RemoveFromUpdateableAddons(AddonPtr &pAddon)
+{
+ CSingleLock lock(m_critSection);
+ VECADDONS::iterator it = std::find(m_updateableAddons.begin(), m_updateableAddons.end(), pAddon);
+
+ if(it != m_updateableAddons.end())
+ {
+ m_updateableAddons.erase(it);
+ }
+}
+
+struct AddonIdFinder
+{
+ AddonIdFinder(const CStdString& id)
+ : m_id(id)
+ {}
+
+ bool operator()(const AddonPtr& addon)
+ {
+ return m_id.Equals(addon->ID());
+ }
+ private:
+ CStdString m_id;
+};
+
+bool CAddonMgr::ReloadSettings(const CStdString &id)
+{
+ CSingleLock lock(m_critSection);
+ VECADDONS::iterator it = std::find_if(m_updateableAddons.begin(), m_updateableAddons.end(), AddonIdFinder(id));
+
+ if( it != m_updateableAddons.end())
+ {
+ return (*it)->ReloadSettings();
+ }
+ return false;
+}
+
bool CAddonMgr::GetAllOutdatedAddons(VECADDONS &addons, bool enabled /*= true*/)
{
CSingleLock lock(m_critSection);
@@ -92,6 +92,9 @@ namespace ADDON
bool HasAddons(const TYPE &type, bool enabled = true);
bool GetAddons(const TYPE &type, VECADDONS &addons, bool enabled = true);
bool GetAllAddons(VECADDONS &addons, bool enabled = true, bool allowRepos = false);
+ void AddToUpdateableAddons(AddonPtr &pAddon);
+ void RemoveFromUpdateableAddons(AddonPtr &pAddon);
+ bool ReloadSettings(const CStdString &id);
/*! \brief Get all addons with available updates
\param addons List to fill with all outdated addons
\param enabled Whether to get only enabled or disabled addons
@@ -172,6 +175,7 @@ namespace ADDON
const cp_cfg_element_t *GetExtElement(cp_cfg_element_t *base, const char *path);
cp_context_t *m_cp_context;
DllLibCPluff *m_cpluff;
+ VECADDONS m_updateableAddons;
/*! \brief Fetch a (single) addon from a plugin descriptor.
Assumes that there is a single (non-trivial) extension point per addon.
View
@@ -111,10 +111,11 @@ namespace ADDON
virtual CStdString GetString(uint32_t id) =0;
virtual const ADDONDEPS &GetDeps() const =0;
virtual bool MeetsVersion(const AddonVersion &version) const =0;
+ virtual bool ReloadSettings() =0;
protected:
virtual const AddonPtr Parent() const =0;
- virtual bool LoadSettings() =0;
+ virtual bool LoadSettings(bool bForce = false) =0;
private:
friend class CAddonMgr;
@@ -143,11 +143,13 @@ namespace PYXBMC
}
}
+ CAddonMgr::Get().AddToUpdateableAddons(self->pAddon);
return (PyObject*)self;
}
void Addon_Dealloc(Addon* self)
{
+ CAddonMgr::Get().RemoveFromUpdateableAddons(self->pAddon);
self->ob_type->tp_free((PyObject*)self);
}

0 comments on commit 0c2e7a9

Please sign in to comment.