xbmc
DirectoryProvider.h
1 /*
2  * Copyright (C) 2013-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 #pragma once
10 
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"
19 
20 #include <string>
21 #include <vector>
22 
23 class CFileItem;
24 class TiXmlElement;
25 class CVariant;
26 
27 namespace PVR
28 {
29  enum class PVREvent;
30 }
31 
32 enum class InfoTagType
33 {
34  VIDEO,
35  AUDIO,
36  PICTURE,
37  PROGRAM,
38  PVR,
39 };
40 
42  public IListProvider,
43  public IJobCallback,
45 {
46 public:
47  typedef enum
48  {
49  OK,
50  INVALIDATED,
51  DONE
52  } UpdateState;
53 
54  enum class BrowseMode
55  {
56  NEVER,
57  AUTO, // add browse item if list is longer than given limit
58  ALWAYS
59  };
60 
61  CDirectoryProvider(const TiXmlElement *element, int parentID);
62  explicit CDirectoryProvider(const CDirectoryProvider& other);
63  ~CDirectoryProvider() override;
64 
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<CGUIListItemPtr> &items) override;
73  void Reset() override;
74  bool OnClick(const CGUIListItemPtr &item) override;
75  bool OnPlay(const CGUIListItemPtr& item) override;
76  bool OnInfo(const std::shared_ptr<CFileItem>& item);
77  bool OnContextMenu(const std::shared_ptr<CFileItem>& item);
78  bool OnInfo(const CGUIListItemPtr &item) override;
79  bool OnContextMenu(const CGUIListItemPtr &item) override;
80  bool IsUpdating() const override;
81  void FreeResources(bool immediately) override;
82 
83  // callback from directory job
84  void OnJobComplete(unsigned int jobID, bool success, CJob *job) override;
85 private:
86  UpdateState m_updateState = OK;
87  unsigned int m_jobID = 0;
94  std::string m_currentUrl;
95  std::string m_currentTarget;
96  SortDescription m_currentSort;
97  unsigned int m_currentLimit{0};
98  BrowseMode m_currentBrowse{BrowseMode::AUTO};
99  std::vector<CGUIStaticItemPtr> m_items;
100  std::vector<InfoTagType> m_itemTypes;
101  mutable CCriticalSection m_section;
102 
103  bool UpdateURL();
104  bool UpdateLimit();
105  bool UpdateSort();
106  bool UpdateBrowse();
107  void OnAddonEvent(const ADDON::AddonEvent& event);
108  void OnAddonRepositoryEvent(const ADDON::CRepositoryUpdater::RepositoryUpdated& event);
109  void OnPVRManagerEvent(const PVR::PVREvent& event);
110  void OnFavouritesEvent(const CFavouritesService::FavouritesUpdated& event);
111  std::string GetTarget(const CFileItem& item) const;
112 
113  CCriticalSection m_subscriptionSection;
114  bool m_isSubscribed{false};
115 };
An interface for providing lists to UI containers.
Definition: IListProvider.h:22
Base class for jobs that are executed asynchronously.
Definition: Job.h:109
Definition: ContextMenuManager.h:24
Definition: GUIInfoLabel.h:31
Definition: IAnnouncer.h:70
Definition: RepositoryUpdater.h:72
Definition: DirectoryProvider.h:41
Definition: Variant.h:31
Definition: Application.h:74
Definition: AddonEvents.h:18
Definition: FavouritesService.h:41
Callback interface for asynchronous jobs.
Definition: Job.h:31
Definition: SortUtils.h:176
Represents a file on a share.
Definition: FileItem.h:102