[Windows] Remove redundant DirectSound error codes
[xbmc.git] / xbmc / playlists / SmartPlaylistFileItemListModifier.cpp
blob20beb18c627b780480ebdb8fc7373bf1db7c6a0a
1 /*
2 * Copyright (C) 2013-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "SmartPlaylistFileItemListModifier.h"
11 #include "FileItem.h"
12 #include "FileItemList.h"
13 #include "URL.h"
14 #include "playlists/SmartPlayList.h"
15 #include "utils/StringUtils.h"
17 #include <string>
19 #define URL_OPTION_XSP "xsp"
20 #define PROPERTY_SORT_ORDER "sort.order"
21 #define PROPERTY_SORT_ASCENDING "sort.ascending"
23 namespace KODI::PLAYLIST
26 bool CSmartPlaylistFileItemListModifier::CanModify(const CFileItemList &items) const
28 return !GetUrlOption(items.GetPath(), URL_OPTION_XSP).empty();
31 bool CSmartPlaylistFileItemListModifier::Modify(CFileItemList &items) const
33 if (items.HasProperty(PROPERTY_SORT_ORDER))
34 return false;
36 std::string xspOption = GetUrlOption(items.GetPath(), URL_OPTION_XSP);
37 if (xspOption.empty())
38 return false;
40 // check for smartplaylist-specific sorting information
41 CSmartPlaylist xsp;
42 if (!xsp.LoadFromJson(xspOption))
43 return false;
45 items.SetProperty(PROPERTY_SORT_ORDER, (int)xsp.GetOrder());
46 items.SetProperty(PROPERTY_SORT_ASCENDING, xsp.GetOrderDirection() == SortOrderAscending);
48 return true;
51 std::string CSmartPlaylistFileItemListModifier::GetUrlOption(const std::string &path, const std::string &option)
53 if (path.empty() || option.empty())
54 return StringUtils::Empty;
56 CURL url(path);
57 return url.GetOption(option);
60 } // namespace KODI::PLAYLIST