2022-02-24 15:04:24 +00:00
|
|
|
/*
|
|
|
|
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"
|
2022-02-26 11:51:54 +00:00
|
|
|
#include "base/weak_ptr.h"
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
struct DownloadedId;
|
|
|
|
} // namespace Data
|
2022-02-24 15:04:24 +00:00
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
class AbstractController;
|
|
|
|
} // namespace Info
|
|
|
|
|
|
|
|
namespace Info::Downloads {
|
|
|
|
|
2022-02-24 18:19:27 +00:00
|
|
|
class Provider final
|
|
|
|
: public Media::ListProvider
|
2022-02-26 11:51:54 +00:00
|
|
|
, private Media::ListSectionDelegate
|
|
|
|
, public base::has_weak_ptr {
|
2022-02-24 15:04:24 +00:00
|
|
|
public:
|
|
|
|
explicit Provider(not_null<AbstractController*> controller);
|
|
|
|
|
|
|
|
Media::Type type() override;
|
|
|
|
bool hasSelectRestriction() override;
|
|
|
|
rpl::producer<bool> hasSelectRestrictionChanges() override;
|
|
|
|
bool isPossiblyMyItem(not_null<const HistoryItem*> item) override;
|
|
|
|
|
|
|
|
std::optional<int> fullCount() override;
|
|
|
|
|
|
|
|
void restart() override;
|
|
|
|
void checkPreload(
|
|
|
|
QSize viewport,
|
|
|
|
not_null<Media::BaseLayout*> topLayout,
|
|
|
|
not_null<Media::BaseLayout*> bottomLayout,
|
|
|
|
bool preloadTop,
|
|
|
|
bool preloadBottom) override;
|
|
|
|
void refreshViewer() override;
|
|
|
|
rpl::producer<> refreshed() override;
|
|
|
|
|
2022-03-11 11:14:07 +00:00
|
|
|
void setSearchQuery(QString query);
|
|
|
|
|
2022-02-24 15:04:24 +00:00
|
|
|
std::vector<Media::ListSection> fillSections(
|
|
|
|
not_null<Overview::Layout::Delegate*> delegate) override;
|
|
|
|
rpl::producer<not_null<Media::BaseLayout*>> layoutRemoved() override;
|
|
|
|
Media::BaseLayout *lookupLayout(const HistoryItem *item) override;
|
|
|
|
bool isMyItem(not_null<const HistoryItem*> item) override;
|
|
|
|
bool isAfter(
|
|
|
|
not_null<const HistoryItem*> a,
|
|
|
|
not_null<const HistoryItem*> b) override;
|
|
|
|
|
2022-02-27 11:14:39 +00:00
|
|
|
Media::ListItemSelectionData computeSelectionData(
|
|
|
|
not_null<const HistoryItem*> item,
|
|
|
|
TextSelection selection) override;
|
2022-02-24 15:04:24 +00:00
|
|
|
void applyDragSelection(
|
|
|
|
Media::ListSelectedMap &selected,
|
|
|
|
not_null<const HistoryItem*> fromItem,
|
|
|
|
bool skipFrom,
|
|
|
|
not_null<const HistoryItem*> tillItem,
|
|
|
|
bool skipTill) override;
|
|
|
|
|
2022-02-27 11:14:39 +00:00
|
|
|
bool allowSaveFileAs(
|
|
|
|
not_null<const HistoryItem*> item,
|
|
|
|
not_null<DocumentData*> document) override;
|
2022-02-27 13:32:36 +00:00
|
|
|
QString showInFolderPath(
|
|
|
|
not_null<const HistoryItem*> item,
|
|
|
|
not_null<DocumentData*> document) override;
|
2022-02-27 11:14:39 +00:00
|
|
|
|
2022-02-27 17:19:16 +00:00
|
|
|
|
|
|
|
int64 scrollTopStatePosition(not_null<HistoryItem*> item) override;
|
|
|
|
HistoryItem *scrollTopStateItem(
|
|
|
|
Media::ListScrollTopState state) override;
|
2022-02-24 15:04:24 +00:00
|
|
|
void saveState(
|
|
|
|
not_null<Media::Memento*> memento,
|
|
|
|
Media::ListScrollTopState scrollState) override;
|
|
|
|
void restoreState(
|
|
|
|
not_null<Media::Memento*> memento,
|
|
|
|
Fn<void(Media::ListScrollTopState)> restoreScrollState) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Element {
|
|
|
|
not_null<HistoryItem*> item;
|
2022-02-24 17:39:23 +00:00
|
|
|
int64 started = 0; // unixtime * 1000
|
2022-02-27 13:32:36 +00:00
|
|
|
QString path;
|
2022-03-11 11:14:07 +00:00
|
|
|
|
|
|
|
QStringList words;
|
|
|
|
base::flat_set<QChar> letters;
|
|
|
|
bool found = false;
|
2022-02-24 15:04:24 +00:00
|
|
|
};
|
2022-02-24 17:39:23 +00:00
|
|
|
|
2022-02-24 18:19:27 +00:00
|
|
|
bool sectionHasFloatingHeader() override;
|
|
|
|
QString sectionTitle(not_null<const Media::BaseLayout*> item) override;
|
|
|
|
bool sectionItemBelongsHere(
|
|
|
|
not_null<const Media::BaseLayout*> item,
|
|
|
|
not_null<const Media::BaseLayout*> previous) override;
|
|
|
|
|
2022-03-11 11:14:07 +00:00
|
|
|
[[nodiscard]] bool searchMode() const;
|
|
|
|
void fillSearchIndex(Element &element);
|
|
|
|
[[nodiscard]] bool computeIsFound(const Element &element) const;
|
|
|
|
|
2022-02-24 17:39:23 +00:00
|
|
|
void itemRemoved(not_null<const HistoryItem*> item);
|
|
|
|
void markLayoutsStale();
|
|
|
|
void clearStaleLayouts();
|
|
|
|
|
2022-02-26 11:51:54 +00:00
|
|
|
void refreshPostponed(bool added);
|
|
|
|
void addPostponed(not_null<const Data::DownloadedId*> entry);
|
|
|
|
void performRefresh();
|
|
|
|
void performAdd();
|
2022-03-11 11:14:07 +00:00
|
|
|
void addElementNow(Element &&element);
|
2022-02-26 11:51:54 +00:00
|
|
|
void remove(not_null<const HistoryItem*> item);
|
2022-02-24 18:19:27 +00:00
|
|
|
void trackItemSession(not_null<const HistoryItem*> item);
|
|
|
|
|
2022-02-24 17:39:23 +00:00
|
|
|
[[nodiscard]] Media::BaseLayout *getLayout(
|
|
|
|
Element element,
|
|
|
|
not_null<Overview::Layout::Delegate*> delegate);
|
|
|
|
[[nodiscard]] std::unique_ptr<Media::BaseLayout> createLayout(
|
|
|
|
Element element,
|
|
|
|
not_null<Overview::Layout::Delegate*> delegate);
|
|
|
|
|
2022-02-24 15:04:24 +00:00
|
|
|
const not_null<AbstractController*> _controller;
|
|
|
|
|
|
|
|
std::vector<Element> _elements;
|
2022-02-24 17:39:23 +00:00
|
|
|
std::optional<int> _fullCount;
|
|
|
|
base::flat_set<not_null<const HistoryItem*>> _downloading;
|
|
|
|
base::flat_set<not_null<const HistoryItem*>> _downloaded;
|
2022-02-24 15:04:24 +00:00
|
|
|
|
2022-02-27 13:32:36 +00:00
|
|
|
std::vector<Element> _addPostponed;
|
2022-02-26 11:51:54 +00:00
|
|
|
|
2022-02-24 18:19:27 +00:00
|
|
|
std::unordered_map<
|
|
|
|
not_null<const HistoryItem*>,
|
|
|
|
Media::CachedItem> _layouts;
|
2022-02-24 15:04:24 +00:00
|
|
|
rpl::event_stream<not_null<Media::BaseLayout*>> _layoutRemoved;
|
|
|
|
rpl::event_stream<> _refreshed;
|
|
|
|
|
2022-03-11 11:14:07 +00:00
|
|
|
QString _query;
|
|
|
|
QStringList _queryWords;
|
|
|
|
int _foundCount = 0;
|
|
|
|
|
2022-02-24 18:19:27 +00:00
|
|
|
base::flat_map<not_null<Main::Session*>, rpl::lifetime> _trackedSessions;
|
2022-02-26 11:51:54 +00:00
|
|
|
bool _postponedRefreshSort = false;
|
|
|
|
bool _postponedRefresh = false;
|
2022-03-10 14:02:38 +00:00
|
|
|
bool _started = false;
|
2022-02-24 18:19:27 +00:00
|
|
|
|
2022-02-24 15:04:24 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Info::Downloads
|