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 TiXmlElement;
24 class CVariant;
25 
26 namespace PVR
27 {
28  enum class PVREvent;
29 }
30 
31 enum class InfoTagType
32 {
33  VIDEO,
34  AUDIO,
35  PICTURE,
36  PROGRAM,
37  PVR,
38 };
39 
41  public IListProvider,
42  public IJobCallback,
44 {
45 public:
46  typedef enum
47  {
48  OK,
49  INVALIDATED,
50  DONE
51  } UpdateState;
52 
53  CDirectoryProvider(const TiXmlElement *element, int parentID);
54  explicit CDirectoryProvider(const CDirectoryProvider& other);
55  ~CDirectoryProvider() override;
56 
57  // Implementation of IListProvider
58  std::unique_ptr<IListProvider> Clone() override;
59  bool Update(bool forceRefresh) override;
60  void Announce(ANNOUNCEMENT::AnnouncementFlag flag,
61  const std::string& sender,
62  const std::string& message,
63  const CVariant& data) override;
64  void Fetch(std::vector<CGUIListItemPtr> &items) override;
65  void Reset() override;
66  bool OnClick(const CGUIListItemPtr &item) override;
67  bool OnPlay(const CGUIListItemPtr& item) override;
68  bool OnInfo(const CGUIListItemPtr &item) override;
69  bool OnContextMenu(const CGUIListItemPtr &item) override;
70  bool IsUpdating() const override;
71  void FreeResources(bool immediately) override;
72 
73  // callback from directory job
74  void OnJobComplete(unsigned int jobID, bool success, CJob *job) override;
75 private:
76  UpdateState m_updateState;
77  unsigned int m_jobID;
83  std::string m_currentUrl;
84  std::string m_currentTarget;
85  SortDescription m_currentSort;
86  unsigned int m_currentLimit;
87  std::vector<CGUIStaticItemPtr> m_items;
88  std::vector<InfoTagType> m_itemTypes;
89  mutable CCriticalSection m_section;
90 
91  bool UpdateURL();
92  bool UpdateLimit();
93  bool UpdateSort();
94  void OnAddonEvent(const ADDON::AddonEvent& event);
95  void OnAddonRepositoryEvent(const ADDON::CRepositoryUpdater::RepositoryUpdated& event);
96  void OnPVRManagerEvent(const PVR::PVREvent& event);
97  void OnFavouritesEvent(const CFavouritesService::FavouritesUpdated& event);
98  std::string GetTarget(const CFileItem& item) const;
99 
100  CCriticalSection m_subscriptionSection;
101  bool m_isSubscribed{false};
102 };
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:40
Definition: Variant.h:29
Definition: Application.h:74
Definition: AddonEvents.h:18
Definition: FavouritesService.h:36
Callback interface for asynchronous jobs.
Definition: Job.h:31
Definition: SortUtils.h:176
Represents a file on a share.
Definition: FileItem.h:102