/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include "info/media/info_media_common.h" #include "base/weak_ptr.h" namespace Data { struct DownloadedId; } // namespace Data namespace Info { class AbstractController; } // namespace Info namespace Info::Downloads { class Provider final : public Media::ListProvider , private Media::ListSectionDelegate , public base::has_weak_ptr { public: explicit Provider(not_null controller); Media::Type type() override; bool hasSelectRestriction() override; rpl::producer hasSelectRestrictionChanges() override; bool isPossiblyMyItem(not_null item) override; std::optional fullCount() override; void restart() override; void checkPreload( QSize viewport, not_null topLayout, not_null bottomLayout, bool preloadTop, bool preloadBottom) override; void refreshViewer() override; rpl::producer<> refreshed() override; void setSearchQuery(QString query) override; std::vector fillSections( not_null delegate) override; rpl::producer> layoutRemoved() override; Media::BaseLayout *lookupLayout(const HistoryItem *item) override; bool isMyItem(not_null item) override; bool isAfter( not_null a, not_null b) override; Media::ListItemSelectionData computeSelectionData( not_null item, TextSelection selection) override; void applyDragSelection( Media::ListSelectedMap &selected, not_null fromItem, bool skipFrom, not_null tillItem, bool skipTill) override; bool allowSaveFileAs( not_null item, not_null document) override; QString showInFolderPath( not_null item, not_null document) override; int64 scrollTopStatePosition(not_null item) override; HistoryItem *scrollTopStateItem( Media::ListScrollTopState state) override; void saveState( not_null memento, Media::ListScrollTopState scrollState) override; void restoreState( not_null memento, Fn restoreScrollState) override; private: struct Element { not_null item; int64 started = 0; // unixtime * 1000 QString path; QStringList words; base::flat_set letters; bool found = false; }; bool sectionHasFloatingHeader() override; QString sectionTitle(not_null item) override; bool sectionItemBelongsHere( not_null item, not_null previous) override; [[nodiscard]] bool searchMode() const; void fillSearchIndex(Element &element); [[nodiscard]] bool computeIsFound(const Element &element) const; void itemRemoved(not_null item); void markLayoutsStale(); void clearStaleLayouts(); void refreshPostponed(bool added); void addPostponed(not_null entry); void performRefresh(); void performAdd(); void addElementNow(Element &&element); void remove(not_null item); void trackItemSession(not_null item); [[nodiscard]] Media::BaseLayout *getLayout( Element element, not_null delegate); [[nodiscard]] std::unique_ptr createLayout( Element element, not_null delegate); const not_null _controller; std::vector _elements; std::optional _fullCount; base::flat_set> _downloading; base::flat_set> _downloaded; std::vector _addPostponed; std::unordered_map< not_null, Media::CachedItem> _layouts; rpl::event_stream> _layoutRemoved; rpl::event_stream<> _refreshed; QString _query; QStringList _queryWords; int _foundCount = 0; base::flat_map, rpl::lifetime> _trackedSessions; bool _postponedRefreshSort = false; bool _postponedRefresh = false; bool _started = false; rpl::lifetime _lifetime; }; } // namespace Info::Downloads