changed: prompt for addon installation in case we're trying to execute an addon URL...
authorvdrfan <vdrfan-nospam-@xbmc.org>
Tue, 17 Jan 2012 19:23:46 +0000 (20:23 +0100)
committervdrfan <vdrfan-nospam-@xbmc.org>
Tue, 17 Jan 2012 19:27:27 +0000 (20:27 +0100)
xbmc/addons/AddonManager.cpp
xbmc/addons/AddonManager.h
xbmc/filesystem/PluginDirectory.cpp

index 4a61c7e..dc2d48f 100644 (file)
@@ -20,6 +20,7 @@
  */
 #include "AddonManager.h"
 #include "Addon.h"
+#include "AddonInstaller.h"
 #include "DllLibCPluff.h"
 #include "utils/StringUtils.h"
 #include "utils/JobManager.h"
@@ -31,6 +32,7 @@
 #include "settings/AdvancedSettings.h"
 #include "utils/log.h"
 #include "tinyXML/tinyxml.h"
+#include "dialogs/GUIDialogYesNo.h"
 
 
 #ifdef HAS_VISUALISATION
@@ -390,7 +392,7 @@ bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabled /* =
   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 enabledOnly /*= true*/, bool install  /*= false*/)
 {
   CSingleLock lock(m_critSection);
 
@@ -404,6 +406,25 @@ bool CAddonMgr::GetAddon(const CStdString &str, AddonPtr &addon, const TYPE &typ
       return false;
     return NULL != addon.get();
   }
+  else
+  {
+    if (install)
+    {
+      if (!CGUIDialogYesNo::ShowAndGetInput(g_localizeStrings.Get(24076), g_localizeStrings.Get(24100),
+                                            str.c_str(), g_localizeStrings.Get(24101)))
+        return false;
+
+      if (CAddonInstaller::Get().Install(str.c_str(), true, "", false))
+      {
+        cp_plugin_info_t *cpaddon = m_cpluff->get_plugin_info(m_cp_context, str.c_str(), &status);
+        addon = GetAddonFromDescriptor(cpaddon);
+        m_cpluff->release_info(m_cp_context, cpaddon);
+        if (status == CP_OK && cpaddon)
+          return NULL != addon.get();
+      }
+    }
+  }
+
   if (cpaddon)
     m_cpluff->release_info(m_cp_context, cpaddon);
 
index 8166974..bbbb062 100644 (file)
@@ -86,9 +86,10 @@ namespace ADDON
      \param addon [out] the retrieved addon pointer - only use if the function returns true.
      \param type type of addon to retrieve - defaults to any type.
      \param enabledOnly whether we only want enabled addons - set to false to allow both enabled and disabled addons - defaults to true.
+     \param install whether to install the requested addon in case it's not yet installed - defaults to false.
      \return true if an addon matching the id of the given type is available and is enabled (if enabledOnly is true).
      */
-    bool GetAddon(const CStdString &id, AddonPtr &addon, const TYPE &type = ADDON_UNKNOWN, bool enabledOnly = true);
+    bool GetAddon(const CStdString &id, AddonPtr &addon, const TYPE &type = ADDON_UNKNOWN, bool enabledOnly = true, bool install = false);
     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);
index 70f7f5e..f978b2c 100644 (file)
@@ -77,7 +77,7 @@ bool CPluginDirectory::StartScript(const CStdString& strPath, bool retrievingDir
 {
   CURL url(strPath);
 
-  if (!CAddonMgr::Get().GetAddon(url.GetHostName(), m_addon, ADDON_PLUGIN))
+  if (!CAddonMgr::Get().GetAddon(url.GetHostName(), m_addon, ADDON_PLUGIN, true, true))
   {
     CLog::Log(LOGERROR, "Unable to find plugin %s", url.GetHostName().c_str());
     return false;
@@ -408,7 +408,7 @@ bool CPluginDirectory::RunScriptWithParams(const CStdString& strPath)
     return false;
 
   AddonPtr addon;
-  if (!CAddonMgr::Get().GetAddon(url.GetHostName(), addon, ADDON_PLUGIN))
+  if (!CAddonMgr::Get().GetAddon(url.GetHostName(), addon, ADDON_PLUGIN, true , true))
   {
     CLog::Log(LOGERROR, "Unable to find plugin %s", url.GetHostName().c_str());
     return false;