tdesktop/Telegram/SourceFiles/boxes/local_storage_box.h

103 lines
2.3 KiB
C
Raw Normal View History

/*
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 "ui/layers/box_content.h"
#include "storage/cache/storage_cache_database.h"
2019-07-24 14:00:30 +00:00
namespace Main {
class Session;
} // namespace Main
namespace Storage {
namespace Cache {
class Database;
} // namespace Cache
} // namespace Storage
namespace Ui {
class VerticalLayout;
template <typename Widget>
class SlideWrap;
class LabelSimple;
2019-03-01 14:20:04 +00:00
class MediaSlider;
} // namespace Ui
2019-09-18 11:19:05 +00:00
class LocalStorageBox : public Ui::BoxContent {
struct CreateTag {
};
public:
using Database = Storage::Cache::Database;
2019-03-01 14:20:04 +00:00
LocalStorageBox(
QWidget*,
2019-07-24 14:00:30 +00:00
not_null<Main::Session*> session,
2019-03-01 14:20:04 +00:00
CreateTag);
2019-07-24 14:00:30 +00:00
static void Show(not_null<Main::Session*> session);
protected:
void prepare() override;
private:
class Row;
2019-03-01 14:20:04 +00:00
void clearByTag(uint16 tag);
void update(Database::Stats &&stats, Database::Stats &&statsBig);
void updateRow(
not_null<Ui::SlideWrap<Row>*> row,
2019-03-01 14:20:04 +00:00
const Database::TaggedSummary *data);
void setupControls();
void setupLimits(not_null<Ui::VerticalLayout*> container);
2019-03-01 14:20:04 +00:00
void updateMediaLimit();
void updateTotalLimit();
void updateTotalLabel();
void updateMediaLabel();
void limitsChanged();
void save();
2019-03-01 14:20:04 +00:00
Database::TaggedSummary summary() const;
template <
typename Value,
typename Convert,
typename Callback,
typename = std::enable_if_t<
rpl::details::is_callable_plain_v<
Callback,
not_null<Ui::LabelSimple*>,
Value>
&& std::is_same_v<Value, decltype(std::declval<Convert>()(1))>>>
2019-03-01 14:20:04 +00:00
not_null<Ui::MediaSlider*> createLimitsSlider(
not_null<Ui::VerticalLayout*> container,
int valuesCount,
Convert &&convert,
Value currentValue,
Callback &&callback);
2019-07-24 14:00:30 +00:00
const not_null<Main::Session*> _session;
const not_null<Storage::Cache::Database*> _db;
const not_null<Storage::Cache::Database*> _dbBig;
Database::Stats _stats;
2019-03-01 14:20:04 +00:00
Database::Stats _statsBig;
2019-03-01 14:20:04 +00:00
base::flat_map<uint16, not_null<Ui::SlideWrap<Row>*>> _rows;
Ui::MediaSlider *_totalSlider = nullptr;
Ui::LabelSimple *_totalLabel = nullptr;
Ui::MediaSlider *_mediaSlider = nullptr;
Ui::LabelSimple *_mediaLabel = nullptr;
2019-03-01 14:20:04 +00:00
int64 _totalSizeLimit = 0;
int64 _mediaSizeLimit = 0;
size_type _timeLimit = 0;
bool _limitsChanged = false;
};