Merge pull request #26148 from ksooo/fix-secondstotimestring-warning
[xbmc.git] / xbmc / FileItemList.h
blobeaf345a4d8571d49a102d5b384fb8df43116bcf4
1 /*
2 * Copyright (C) 2005-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 /*!
12 \file FileItemList.h
13 \brief
16 #include "FileItem.h"
18 /*!
19 \brief Represents a list of files
20 \sa CFileItemList, CFileItem
22 class CFileItemList : public CFileItem
24 public:
25 enum class CacheType
27 NEVER = 0,
28 IF_SLOW,
29 ALWAYS
32 CFileItemList();
33 explicit CFileItemList(const std::string& strPath);
34 ~CFileItemList() override;
35 void Archive(CArchive& ar) override;
36 CFileItemPtr operator[](int iItem);
37 const CFileItemPtr operator[](int iItem) const;
38 CFileItemPtr operator[](const std::string& strPath);
39 const CFileItemPtr operator[](const std::string& strPath) const;
40 void Clear();
41 void ClearItems();
42 void Add(CFileItemPtr item);
43 void Add(CFileItem&& item);
44 void AddFront(const CFileItemPtr& pItem, int itemPosition);
45 void Remove(CFileItem* pItem);
46 void Remove(int iItem);
47 CFileItemPtr Get(int iItem) const;
48 const VECFILEITEMS& GetList() const { return m_items; }
49 CFileItemPtr Get(const std::string& strPath) const;
50 int Size() const;
51 bool IsEmpty() const;
52 void Append(const CFileItemList& itemlist);
53 void Assign(const CFileItemList& itemlist, bool append = false);
54 bool Copy(const CFileItemList& item, bool copyItems = true);
55 void Reserve(size_t iCount);
56 void Sort(SortBy sortBy, SortOrder sortOrder, SortAttribute sortAttributes = SortAttributeNone);
57 /* \brief Sorts the items based on the given sorting options
59 In contrast to Sort (see above) this does not change the internal
60 state by storing the sorting method and order used and therefore
61 will always execute the sorting even if the list of items has
62 already been sorted with the same options before.
64 void Sort(SortDescription sortDescription);
65 void Randomize();
66 void FillInDefaultIcons();
67 int GetFolderCount() const;
68 int GetFileCount() const;
69 int GetSelectedCount() const;
70 int GetObjectCount() const;
71 void FilterCueItems();
72 void RemoveExtensions();
73 void SetIgnoreURLOptions(bool ignoreURLOptions);
74 void SetFastLookup(bool fastLookup);
75 bool Contains(const std::string& fileName) const;
76 bool GetFastLookup() const { return m_fastLookup; }
78 /*! \brief stack a CFileItemList
79 By default we stack all items (files and folders) in a CFileItemList
80 \param stackFiles whether to stack all items or just collapse folders (defaults to true)
81 \sa StackFiles,StackFolders
83 void Stack(bool stackFiles = true);
85 SortOrder GetSortOrder() const { return m_sortDescription.sortOrder; }
86 SortBy GetSortMethod() const { return m_sortDescription.sortBy; }
87 void SetSortOrder(SortOrder sortOrder) { m_sortDescription.sortOrder = sortOrder; }
88 void SetSortMethod(SortBy sortBy) { m_sortDescription.sortBy = sortBy; }
90 /*! \brief load a CFileItemList out of the cache
92 The file list may be cached based on which window we're viewing in, as different
93 windows will be listing different portions of the same URL (eg viewing music files
94 versus viewing video files)
96 \param windowID id of the window that's loading this list (defaults to 0)
97 \return true if we loaded from the cache, false otherwise.
98 \sa Save,RemoveDiscCache
100 bool Load(int windowID = 0);
102 /*! \brief save a CFileItemList to the cache
104 The file list may be cached based on which window we're viewing in, as different
105 windows will be listing different portions of the same URL (eg viewing music files
106 versus viewing video files)
108 \param windowID id of the window that's saving this list (defaults to 0)
109 \return true if successful, false otherwise.
110 \sa Load,RemoveDiscCache
112 bool Save(int windowID = 0);
113 void SetCacheToDisc(CacheType cacheToDisc) { m_cacheToDisc = cacheToDisc; }
114 bool CacheToDiscAlways() const { return m_cacheToDisc == CacheType::ALWAYS; }
115 bool CacheToDiscIfSlow() const { return m_cacheToDisc == CacheType::IF_SLOW; }
116 /*! \brief remove a previously cached CFileItemList from the cache
118 The file list may be cached based on which window we're viewing in, as different
119 windows will be listing different portions of the same URL (eg viewing music files
120 versus viewing video files)
122 \param windowID id of the window whose cache we which to remove (defaults to 0)
123 \sa Save,Load
125 void RemoveDiscCache(int windowID = 0) const;
126 void RemoveDiscCache(const std::string& cachefile) const;
127 void RemoveDiscCacheCRC(const std::string& crc) const;
128 bool AlwaysCache() const;
130 void Swap(unsigned int item1, unsigned int item2);
132 /*! \brief Update an item in the item list
133 \param item the new item, which we match based on path to an existing item in the list
134 \return true if the item exists in the list (and was thus updated), false otherwise.
136 bool UpdateItem(const CFileItem* item);
138 void AddSortMethod(SortBy sortBy,
139 int buttonLabel,
140 const LABEL_MASKS& labelMasks,
141 SortAttribute sortAttributes = SortAttributeNone);
142 void AddSortMethod(SortBy sortBy,
143 SortAttribute sortAttributes,
144 int buttonLabel,
145 const LABEL_MASKS& labelMasks);
146 void AddSortMethod(const SortDescription& sortDescription,
147 int buttonLabel,
148 const LABEL_MASKS& labelMasks);
149 bool HasSortDetails() const { return m_sortDetails.size() != 0; }
150 const std::vector<GUIViewSortDetails>& GetSortDetails() const { return m_sortDetails; }
152 /*! \brief Specify whether this list should be sorted with folders separate from files
153 By default we sort with folders listed (and sorted separately) except for those sort modes
154 which should be explicitly sorted with folders interleaved with files (eg SORT_METHOD_FILES).
155 With this set the folder state will be ignored, allowing folders and files to sort interleaved.
156 \param sort whether to ignore the folder state.
158 void SetSortIgnoreFolders(bool sort) { m_sortIgnoreFolders = sort; }
159 bool GetReplaceListing() const { return m_replaceListing; }
160 void SetReplaceListing(bool replace);
161 void SetContent(const std::string& content) { m_content = content; }
162 const std::string& GetContent() const { return m_content; }
164 void ClearSortState();
166 VECFILEITEMS::iterator begin() { return m_items.begin(); }
167 VECFILEITEMS::iterator end() { return m_items.end(); }
168 VECFILEITEMS::iterator erase(VECFILEITEMS::iterator first, VECFILEITEMS::iterator last);
169 VECFILEITEMS::const_iterator begin() const { return m_items.begin(); }
170 VECFILEITEMS::const_iterator end() const { return m_items.end(); }
171 VECFILEITEMS::const_iterator cbegin() const { return m_items.cbegin(); }
172 VECFILEITEMS::const_iterator cend() const { return m_items.cend(); }
173 std::reverse_iterator<VECFILEITEMS::const_iterator> rbegin() const { return m_items.rbegin(); }
174 std::reverse_iterator<VECFILEITEMS::const_iterator> rend() const { return m_items.rend(); }
176 private:
177 void Sort(FILEITEMLISTCOMPARISONFUNC func);
178 void FillSortFields(FILEITEMFILLFUNC func);
179 std::string GetDiscFileCache(int windowID) const;
182 \brief stack files in a CFileItemList
183 \sa Stack
185 void StackFiles();
188 \brief stack folders in a CFileItemList
189 \sa Stack
191 void StackFolders();
193 VECFILEITEMS m_items;
194 MAPFILEITEMS m_map;
195 bool m_ignoreURLOptions = false;
196 bool m_fastLookup = false;
197 SortDescription m_sortDescription;
198 bool m_sortIgnoreFolders = false;
199 CacheType m_cacheToDisc = CacheType::IF_SLOW;
200 bool m_replaceListing = false;
201 std::string m_content;
203 std::vector<GUIViewSortDetails> m_sortDetails;
205 mutable CCriticalSection m_lock;