Skip to content

Commit

Permalink
allow specyfing multiple types of addons to display in addon selector
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Sep 29, 2011
1 parent 7a66387 commit 78af5b9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
58 changes: 43 additions & 15 deletions xbmc/addons/GUIWindowAddonBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,44 +323,72 @@ bool CGUIWindowAddonBrowser::Update(const CStdString &strDirectory)
}

int CGUIWindowAddonBrowser::SelectAddonID(TYPE type, CStdString &addonID, bool showNone /*= false*/)
{
return SelectAddonID(vector<ADDON::TYPE>(type), addonID, showNone);
}

int CGUIWindowAddonBrowser::SelectAddonID(ADDON::TYPE type, CStdStringArray &addonIDs, bool showNone /*= false*/, bool multipleSelection /*= true*/)
{
return SelectAddonID(vector<ADDON::TYPE>(type), addonIDs, showNone, multipleSelection);
}

int CGUIWindowAddonBrowser::SelectAddonID(vector<ADDON::TYPE> types, CStdString &addonID, bool showNone /*= false*/)
{
CStdStringArray addonIDs;
if (!addonID.IsEmpty())
addonIDs.push_back(addonID);
int retval = SelectAddonID(type, addonIDs, showNone, false);
int retval = SelectAddonID(types, addonIDs, showNone, false);
if (addonIDs.size() > 0)
addonID = addonIDs.at(0);
else
addonID = "";
return retval;
}

int CGUIWindowAddonBrowser::SelectAddonID(ADDON::TYPE type, CStdStringArray &addonIDs, bool showNone /*= false*/, bool multipleSelection /*= true*/)
int CGUIWindowAddonBrowser::SelectAddonID(vector<ADDON::TYPE> types, CStdStringArray &addonIDs, bool showNone /*= false*/, bool multipleSelection /*= true*/)
{
CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
if (type == ADDON_UNKNOWN || !dialog)
if (!dialog)
return 0;

CFileItemList items;
CStdString heading;
int iTypes = 0;
for (vector<ADDON::TYPE>::const_iterator it = types.begin(); it != types.end(); ++it)
{
if (*it == ADDON_UNKNOWN)
continue;
ADDON::VECADDONS addons;
if (type == ADDON_AUDIO)
iTypes++;
if (*it == ADDON_AUDIO)
CAddonsDirectory::GetScriptsAndPlugins("audio",addons);
else if (type == ADDON_EXECUTABLE)
else if (*it == ADDON_EXECUTABLE)
CAddonsDirectory::GetScriptsAndPlugins("executable",addons);
else if (type == ADDON_IMAGE)
else if (*it == ADDON_IMAGE)
CAddonsDirectory::GetScriptsAndPlugins("image",addons);
else if (type == ADDON_VIDEO)
else if (*it == ADDON_VIDEO)
CAddonsDirectory::GetScriptsAndPlugins("video",addons);
else
CAddonMgr::Get().GetAddons(type, addons);
CAddonMgr::Get().GetAddons(*it, addons);
for (ADDON::IVECADDONS it2 = addons.begin() ; it2 != addons.end() ; ++it2)
{
CFileItemPtr item(CAddonsDirectory::FileItemFromAddon(*it2, ""));
if (!items.Contains(item->GetPath()))
items.Add(item);
}

CFileItemList items;
for (ADDON::IVECADDONS i = addons.begin(); i != addons.end(); ++i)
items.Add(CAddonsDirectory::FileItemFromAddon(*i, ""));
if (!heading.IsEmpty())
heading += ", ";
heading += TranslateType(*it, true);
}

if (iTypes == 0)
return 0;

dialog->SetHeading(TranslateType(type, true));
dialog->SetHeading(heading);
dialog->Reset();
dialog->SetUseDetails(true);
if (multipleSelection)
if (multipleSelection || iTypes > 1)
{
showNone = false;
dialog->EnableButton(true, 186);
Expand Down Expand Up @@ -390,10 +418,10 @@ int CGUIWindowAddonBrowser::SelectAddonID(ADDON::TYPE type, CStdStringArray &add
dialog->SetItems(&items);
dialog->SetMultiSelection(multipleSelection);
dialog->DoModal();
if (!multipleSelection && dialog->IsButtonPressed())
if (!multipleSelection && iTypes == 1 && dialog->IsButtonPressed())
{ // switch to the addons browser.
vector<CStdString> params;
params.push_back("addons://all/"+TranslateType(type,false)+"/");
params.push_back("addons://all/"+TranslateType(types[0],false)+"/");
params.push_back("return");
g_windowManager.ActivateWindow(WINDOW_ADDON_BROWSER, params);
return 2;
Expand Down
2 changes: 2 additions & 0 deletions xbmc/addons/GUIWindowAddonBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class CGUIWindowAddonBrowser : public CGUIMediaWindow
\return 1 if an addon was selected, 2 if "Get More" was chosen, or 0 if an error occurred or if the selection process was cancelled
*/
static int SelectAddonID(ADDON::TYPE type, CStdString &addonID, bool showNone = false);
static int SelectAddonID(std::vector<ADDON::TYPE> types, CStdString &addonID, bool showNone = false);
/*! \brief Popup a selection dialog with a list of addons of the given type
\param type the type of addon wanted
\param addonIDs [out] array of selected addon IDs
Expand All @@ -50,6 +51,7 @@ class CGUIWindowAddonBrowser : public CGUIMediaWindow
\return 1 if an addon was selected or multiple selection was specified, 2 if "Get More" was chosen, or 0 if an error occurred or if the selection process was cancelled
*/
static int SelectAddonID(ADDON::TYPE type, CStdStringArray &addonIDs, bool showNone = false, bool multipleSelection = true);
static int SelectAddonID(std::vector<ADDON::TYPE> types, CStdStringArray &addonIDs, bool showNone = false, bool multipleSelection = true);

protected:
/* \brief set label2 of an item based on the Addon.Status property
Expand Down

0 comments on commit 78af5b9

Please sign in to comment.