Merge pull request #26350 from jjd-uk/estuary_media_align
[xbmc.git] / xbmc / guilib / listproviders / DirectoryProvider.h
blobc72634ead0f6e4da2240ed50a9e86564c0ddca6e
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 #pragma once
11 #include "IListProvider.h"
12 #include "addons/AddonEvents.h"
13 #include "addons/RepositoryUpdater.h"
14 #include "favourites/FavouritesService.h"
15 #include "guilib/GUIStaticItem.h"
16 #include "interfaces/IAnnouncer.h"
17 #include "threads/CriticalSection.h"
18 #include "utils/Job.h"
20 #include <string>
21 #include <vector>
23 class CFileItem;
24 class TiXmlElement;
25 class CVariant;
27 namespace PVR
29 enum class PVREvent;
32 enum class InfoTagType
34 VIDEO,
35 AUDIO,
36 PICTURE,
37 PROGRAM,
38 PVR,
41 class CDirectoryProvider :
42 public IListProvider,
43 public IJobCallback,
44 public ANNOUNCEMENT::IAnnouncer
46 public:
47 typedef enum
49 OK,
50 INVALIDATED,
51 DONE
52 } UpdateState;
54 enum class BrowseMode
56 NEVER,
57 AUTO, // add browse item if list is longer than given limit
58 ALWAYS
61 CDirectoryProvider(const TiXmlElement *element, int parentID);
62 explicit CDirectoryProvider(const CDirectoryProvider& other);
63 ~CDirectoryProvider() override;
65 // Implementation of IListProvider
66 std::unique_ptr<IListProvider> Clone() override;
67 bool Update(bool forceRefresh) override;
68 void Announce(ANNOUNCEMENT::AnnouncementFlag flag,
69 const std::string& sender,
70 const std::string& message,
71 const CVariant& data) override;
72 void Fetch(std::vector<std::shared_ptr<CGUIListItem>>& items) override;
73 void Reset() override;
74 bool OnClick(const std::shared_ptr<CGUIListItem>& item) override;
75 bool OnPlay(const std::shared_ptr<CGUIListItem>& item) override;
76 bool OnInfo(const std::shared_ptr<CGUIListItem>& item) override;
77 bool OnContextMenu(const std::shared_ptr<CGUIListItem>& item) override;
78 bool IsUpdating() const override;
79 void FreeResources(bool immediately) override;
81 // callback from directory job
82 void OnJobComplete(unsigned int jobID, bool success, CJob *job) override;
83 private:
84 UpdateState m_updateState = OK;
85 unsigned int m_jobID = 0;
86 KODI::GUILIB::GUIINFO::CGUIInfoLabel m_url;
87 KODI::GUILIB::GUIINFO::CGUIInfoLabel m_target;
88 KODI::GUILIB::GUIINFO::CGUIInfoLabel m_sortMethod;
89 KODI::GUILIB::GUIINFO::CGUIInfoLabel m_sortOrder;
90 KODI::GUILIB::GUIINFO::CGUIInfoLabel m_limit;
91 KODI::GUILIB::GUIINFO::CGUIInfoLabel m_browse;
92 std::string m_currentUrl;
93 std::string m_currentTarget; ///< \brief node.target property on the list as a whole
94 SortDescription m_currentSort;
95 unsigned int m_currentLimit{0};
96 BrowseMode m_currentBrowse{BrowseMode::AUTO};
97 std::vector<CGUIStaticItemPtr> m_items;
98 std::vector<InfoTagType> m_itemTypes;
99 mutable CCriticalSection m_section;
101 bool UpdateURL();
102 bool UpdateLimit();
103 bool UpdateSort();
104 bool UpdateBrowse();
105 void OnAddonEvent(const ADDON::AddonEvent& event);
106 void OnAddonRepositoryEvent(const ADDON::CRepositoryUpdater::RepositoryUpdated& event);
107 void OnPVRManagerEvent(const PVR::PVREvent& event);
108 void OnFavouritesEvent(const CFavouritesService::FavouritesUpdated& event);
109 std::string GetTarget(const CFileItem& item) const;
111 CCriticalSection m_subscriptionSection;
112 bool m_isSubscribed{false};