local_storage_box.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "ui/layers/box_content.h"
  9. #include "storage/cache/storage_cache_database.h"
  10. namespace Main {
  11. class Session;
  12. } // namespace Main
  13. namespace Window {
  14. class SessionController;
  15. } // namespace Window
  16. namespace Storage {
  17. namespace Cache {
  18. class Database;
  19. } // namespace Cache
  20. } // namespace Storage
  21. namespace Ui {
  22. class VerticalLayout;
  23. template <typename Widget>
  24. class SlideWrap;
  25. class LabelSimple;
  26. class MediaSlider;
  27. } // namespace Ui
  28. class LocalStorageBox : public Ui::BoxContent {
  29. struct CreateTag {
  30. };
  31. public:
  32. using Database = Storage::Cache::Database;
  33. LocalStorageBox(
  34. QWidget*,
  35. not_null<Main::Session*> session,
  36. CreateTag);
  37. static void Show(not_null<Window::SessionController*> controller);
  38. protected:
  39. void prepare() override;
  40. private:
  41. class Row;
  42. void clearByTag(uint16 tag);
  43. void update(Database::Stats &&stats, Database::Stats &&statsBig);
  44. void updateRow(
  45. not_null<Ui::SlideWrap<Row>*> row,
  46. const Database::TaggedSummary *data);
  47. void setupControls();
  48. void setupLimits(not_null<Ui::VerticalLayout*> container);
  49. void updateMediaLimit();
  50. void updateTotalLimit();
  51. void updateTotalLabel();
  52. void updateMediaLabel();
  53. void limitsChanged();
  54. void save();
  55. Database::TaggedSummary summary() const;
  56. template <
  57. typename Value,
  58. typename Convert,
  59. typename Callback,
  60. typename = std::enable_if_t<
  61. rpl::details::is_callable_plain_v<
  62. Callback,
  63. not_null<Ui::LabelSimple*>,
  64. Value>
  65. && std::is_same_v<Value, decltype(std::declval<Convert>()(1))>>>
  66. not_null<Ui::MediaSlider*> createLimitsSlider(
  67. not_null<Ui::VerticalLayout*> container,
  68. int valuesCount,
  69. Convert &&convert,
  70. Value currentValue,
  71. Callback &&callback);
  72. const not_null<Main::Session*> _session;
  73. const not_null<Storage::Cache::Database*> _db;
  74. const not_null<Storage::Cache::Database*> _dbBig;
  75. Database::Stats _stats;
  76. Database::Stats _statsBig;
  77. base::flat_map<uint16, not_null<Ui::SlideWrap<Row>*>> _rows;
  78. Ui::MediaSlider *_totalSlider = nullptr;
  79. Ui::LabelSimple *_totalLabel = nullptr;
  80. Ui::MediaSlider *_mediaSlider = nullptr;
  81. Ui::LabelSimple *_mediaLabel = nullptr;
  82. int64 _totalSizeLimit = 0;
  83. int64 _mediaSizeLimit = 0;
  84. size_type _timeLimit = 0;
  85. bool _limitsChanged = false;
  86. };