| 1 |
/* |
| 2 |
* Copyright (C) 2016-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "GUIDialogSelectGameClient.h" |
| 10 |
|
| 11 |
#include "FileItem.h" |
| 12 |
#include "dialogs/GUIDialogSelect.h" |
| 13 |
#include "filesystem/AddonsDirectory.h" |
| 14 |
#include "games/addons/GameClient.h" |
| 15 |
#include "guilib/GUIComponent.h" |
| 16 |
#include "guilib/GUIWindowManager.h" |
| 17 |
#include "guilib/LocalizeStrings.h" |
| 18 |
#include "guilib/WindowIDs.h" |
| 19 |
#include "utils/StringUtils.h" |
| 20 |
#include "utils/URIUtils.h" |
| 21 |
#include "utils/log.h" |
| 22 |
|
| 23 |
using namespace KODI; |
| 24 |
using namespace GAME; |
| 25 |
|
| 26 |
std::string CGUIDialogSelectGameClient::ShowAndGetGameClient(const std::string& gamePath, |
| 27 |
const GameClientVector& candidates, |
| 28 |
const GameClientVector& installable) |
| 29 |
{ |
| 30 |
std::string gameClient; |
| 31 |
|
| 32 |
LogGameClients(candidates, installable); |
| 33 |
|
| 34 |
std::string extension = URIUtils::GetExtension(gamePath); |
| 35 |
|
| 36 |
// "Select emulator for {0:s}" |
| 37 |
CGUIDialogSelect* dialog = |
| 38 |
GetDialog(StringUtils::Format(g_localizeStrings.Get(35258), extension)); |
| 39 |
if (dialog != nullptr) |
| 40 |
{ |
| 41 |
// Turn the addons into items |
| 42 |
CFileItemList items; |
| 43 |
CFileItemList installableItems; |
| 44 |
for (const auto& candidate : candidates) |
| 45 |
{ |
| 46 |
CFileItemPtr item(XFILE::CAddonsDirectory::FileItemFromAddon(candidate, candidate->ID())); |
| 47 |
item->SetLabel2(g_localizeStrings.Get(35257)); // "Installed" |
| 48 |
items.Add(std::move(item)); |
| 49 |
} |
| 50 |
for (const auto& addon : installable) |
| 51 |
{ |
| 52 |
CFileItemPtr item(XFILE::CAddonsDirectory::FileItemFromAddon(addon, addon->ID())); |
| 53 |
installableItems.Add(std::move(item)); |
| 54 |
} |
| 55 |
items.Sort(SortByLabel, SortOrderAscending); |
| 56 |
installableItems.Sort(SortByLabel, SortOrderAscending); |
| 57 |
|
| 58 |
items.Append(installableItems); |
| 59 |
|
| 60 |
dialog->SetItems(items); |
| 61 |
|
| 62 |
dialog->Open(); |
| 63 |
|
| 64 |
// If the "Get More" button has been pressed, show a list of installable addons |
| 65 |
if (dialog->IsConfirmed()) |
| 66 |
{ |
| 67 |
int selectedIndex = dialog->GetSelectedItem(); |
| 68 |
|
| 69 |
if (0 <= selectedIndex && selectedIndex < items.Size()) |
| 70 |
{ |
| 71 |
gameClient = items[selectedIndex]->GetPath(); |
| 72 |
|
| 73 |
CLog::Log(LOGDEBUG, "Select game client dialog: User selected emulator {}", gameClient); |
| 74 |
} |
| 75 |
else |
| 76 |
{ |
| 77 |
CLog::Log(LOGDEBUG, "Select game client dialog: User selected invalid emulator {}", |
| 78 |
selectedIndex); |
| 79 |
} |
| 80 |
} |
| 81 |
else |
| 82 |
{ |
| 83 |
CLog::Log(LOGDEBUG, "Select game client dialog: User cancelled game client installation"); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
return gameClient; |
| 88 |
} |
| 89 |
|
| 90 |
CGUIDialogSelect* CGUIDialogSelectGameClient::GetDialog(const std::string& title) |
| 91 |
{ |
| 92 |
CGUIDialogSelect* dialog = |
| 93 |
CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>( |
| 94 |
WINDOW_DIALOG_SELECT); |
| 95 |
if (dialog != nullptr) |
| 96 |
{ |
| 97 |
dialog->Reset(); |
| 98 |
dialog->SetHeading(CVariant{title}); |
| 99 |
dialog->SetUseDetails(true); |
| 100 |
} |
| 101 |
|
| 102 |
return dialog; |
| 103 |
} |
| 104 |
|
| 105 |
void CGUIDialogSelectGameClient::LogGameClients(const GameClientVector& candidates, |
| 106 |
const GameClientVector& installable) |
| 107 |
{ |
| 108 |
CLog::Log(LOGDEBUG, "Select game client dialog: Found {} candidates", |
| 109 |
static_cast<unsigned int>(candidates.size())); |
| 110 |
for (const auto& gameClient : candidates) |
| 111 |
CLog::Log(LOGDEBUG, "Adding {} as a candidate", gameClient->ID()); |
| 112 |
|
| 113 |
if (!installable.empty()) |
| 114 |
{ |
| 115 |
CLog::Log(LOGDEBUG, "Select game client dialog: Found {} installable clients", |
| 116 |
static_cast<unsigned int>(installable.size())); |
| 117 |
for (const auto& gameClient : installable) |
| 118 |
CLog::Log(LOGDEBUG, "Adding {} as an installable client", gameClient->ID()); |
| 119 |
} |
| 120 |
} |