| 1 |
/* |
| 2 |
* Copyright (C) 2012-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 "GUIViewStateWindowGames.h" |
| 10 |
|
| 11 |
#include "FileItem.h" |
| 12 |
#include "games/GameUtils.h" |
| 13 |
#include "guilib/LocalizeStrings.h" |
| 14 |
#include "guilib/WindowIDs.h" |
| 15 |
#include "settings/MediaSourceSettings.h" |
| 16 |
#include "utils/StringUtils.h" |
| 17 |
#include "view/ViewState.h" |
| 18 |
#include "view/ViewStateSettings.h" |
| 19 |
#include "windowing/GraphicContext.h" // include before ViewState.h |
| 20 |
|
| 21 |
#include <assert.h> |
| 22 |
#include <set> |
| 23 |
|
| 24 |
using namespace KODI; |
| 25 |
using namespace GAME; |
| 26 |
|
| 27 |
CGUIViewStateWindowGames::CGUIViewStateWindowGames(const CFileItemList& items) |
| 28 |
: CGUIViewState(items) |
| 29 |
{ |
| 30 |
if (items.IsVirtualDirectoryRoot()) |
| 31 |
{ |
| 32 |
AddSortMethod(SortByLabel, 551, LABEL_MASKS()); |
| 33 |
AddSortMethod(SortByDriveType, 564, LABEL_MASKS()); |
| 34 |
SetSortMethod(SortByLabel); |
| 35 |
SetSortOrder(SortOrderAscending); |
| 36 |
SetViewAsControl(DEFAULT_VIEW_LIST); |
| 37 |
} |
| 38 |
else |
| 39 |
{ |
| 40 |
AddSortMethod(SortByFile, 561, |
| 41 |
LABEL_MASKS("%F", "%I", "%L", "")); // Filename, Size | Label, empty |
| 42 |
AddSortMethod(SortBySize, 553, |
| 43 |
LABEL_MASKS("%L", "%I", "%L", "%I")); // Filename, Size | Label, Size |
| 44 |
|
| 45 |
const CViewState* viewState = CViewStateSettings::GetInstance().Get("games"); |
| 46 |
if (viewState) |
| 47 |
{ |
| 48 |
SetSortMethod(viewState->m_sortDescription); |
| 49 |
SetViewAsControl(viewState->m_viewMode); |
| 50 |
SetSortOrder(viewState->m_sortDescription.sortOrder); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
LoadViewState(items.GetPath(), WINDOW_GAMES); |
| 55 |
} |
| 56 |
|
| 57 |
std::string CGUIViewStateWindowGames::GetLockType() |
| 58 |
{ |
| 59 |
return "games"; |
| 60 |
} |
| 61 |
|
| 62 |
std::string CGUIViewStateWindowGames::GetExtensions() |
| 63 |
{ |
| 64 |
std::set<std::string> exts = CGameUtils::GetGameExtensions(); |
| 65 |
|
| 66 |
// Ensure .zip appears |
| 67 |
exts.insert(".zip"); |
| 68 |
|
| 69 |
return StringUtils::Join(exts, "|"); |
| 70 |
} |
| 71 |
|
| 72 |
VECSOURCES& CGUIViewStateWindowGames::GetSources() |
| 73 |
{ |
| 74 |
VECSOURCES* pGameSources = CMediaSourceSettings::GetInstance().GetSources("games"); |
| 75 |
|
| 76 |
// Guard against source type not existing |
| 77 |
if (pGameSources == nullptr) |
| 78 |
{ |
| 79 |
static VECSOURCES empty; |
| 80 |
return empty; |
| 81 |
} |
| 82 |
|
| 83 |
return *pGameSources; |
| 84 |
} |
| 85 |
|
| 86 |
void CGUIViewStateWindowGames::SaveViewState() |
| 87 |
{ |
| 88 |
SaveViewToDb(m_items.GetPath(), WINDOW_GAMES, CViewStateSettings::GetInstance().Get("games")); |
| 89 |
} |