| 1 |
/* |
| 2 |
* Copyright (C) 2005-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 "FileItem.h" |
| 12 |
#include "threads/CriticalSection.h" |
| 13 |
#include "utils/EventStream.h" |
| 14 |
|
| 15 |
#include <memory> |
| 16 |
#include <string> |
| 17 |
#include <unordered_map> |
| 18 |
#include <vector> |
| 19 |
|
| 20 |
class CFavouritesService |
| 21 |
{ |
| 22 |
public: |
| 23 |
explicit CFavouritesService(std::string userDataFolder); |
| 24 |
virtual ~CFavouritesService() = default; |
| 25 |
|
| 26 |
/** For profiles*/ |
| 27 |
void ReInit(std::string userDataFolder); |
| 28 |
|
| 29 |
bool IsFavourited(const CFileItem& item, int contextWindow) const; |
| 30 |
std::shared_ptr<CFileItem> GetFavourite(const CFileItem& item, int contextWindow) const; |
| 31 |
std::shared_ptr<CFileItem> ResolveFavourite(const CFileItem& favItem) const; |
| 32 |
|
| 33 |
int Size() const; |
| 34 |
void GetAll(CFileItemList& items) const; |
| 35 |
bool AddOrRemove(const CFileItem& item, int contextWindow); |
| 36 |
bool Save(const CFileItemList& items); |
| 37 |
|
| 38 |
/*! \brief Refresh favourites for directory providers, e.g. the GUI needs to be updated |
| 39 |
*/ |
| 40 |
void RefreshFavourites(); |
| 41 |
|
| 42 |
struct FavouritesUpdated { }; |
| 43 |
|
| 44 |
CEventStream<FavouritesUpdated>& Events() { return m_events; } |
| 45 |
|
| 46 |
private: |
| 47 |
CFavouritesService() = delete; |
| 48 |
CFavouritesService(const CFavouritesService&) = delete; |
| 49 |
CFavouritesService& operator=(const CFavouritesService&) = delete; |
| 50 |
CFavouritesService(CFavouritesService&&) = delete; |
| 51 |
CFavouritesService& operator=(CFavouritesService&&) = delete; |
| 52 |
|
| 53 |
void OnUpdated(); |
| 54 |
bool Persist(); |
| 55 |
|
| 56 |
std::string m_userDataFolder; |
| 57 |
CFileItemList m_favourites; |
| 58 |
mutable std::unordered_map<std::string, std::shared_ptr<CFileItem>> m_targets; |
| 59 |
CEventSource<FavouritesUpdated> m_events; |
| 60 |
mutable CCriticalSection m_criticalSection; |
| 61 |
}; |