passport_panel_edit_scans.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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/rp_widget.h"
  9. #include "ui/effects/animations.h"
  10. #include "base/object_ptr.h"
  11. namespace Ui {
  12. class BoxContentDivider;
  13. class VerticalLayout;
  14. class SettingsButton;
  15. class FlatLabel;
  16. template <typename Widget>
  17. class SlideWrap;
  18. } // namespace Ui
  19. namespace Passport {
  20. enum class FileType;
  21. class PanelController;
  22. class ScanButton;
  23. struct ScanInfo;
  24. enum class ReadScanError {
  25. FileTooLarge,
  26. CantReadImage,
  27. BadImageSize,
  28. Unknown,
  29. };
  30. struct ScanListData {
  31. std::vector<ScanInfo> files;
  32. QString errorMissing;
  33. };
  34. class EditScans : public Ui::RpWidget {
  35. public:
  36. EditScans(
  37. QWidget *parent,
  38. not_null<PanelController*> controller,
  39. const QString &header,
  40. const QString &error,
  41. ScanListData &&scans,
  42. std::optional<ScanListData> &&translations);
  43. EditScans(
  44. QWidget *parent,
  45. not_null<PanelController*> controller,
  46. const QString &header,
  47. const QString &error,
  48. std::map<FileType, ScanInfo> &&specialFiles,
  49. std::optional<ScanListData> &&translations);
  50. std::optional<int> validateGetErrorTop();
  51. void scanFieldsChanged(bool changed);
  52. static void ChooseScan(
  53. QPointer<QWidget> parent,
  54. FileType type,
  55. Fn<void(QByteArray&&)> doneCallback,
  56. Fn<void(ReadScanError)> errorCallback);
  57. ~EditScans();
  58. private:
  59. struct SpecialScan;
  60. struct List {
  61. List(not_null<PanelController*> controller, ScanListData &&data);
  62. List(not_null<PanelController*> controller);
  63. List(
  64. not_null<PanelController*> controller,
  65. std::optional<ScanListData> &&data);
  66. bool uploadedSomeMore() const;
  67. bool uploadMoreRequired() const;
  68. Ui::SlideWrap<ScanButton> *nonDeletedErrorRow() const;
  69. rpl::producer<QString> uploadButtonText() const;
  70. void toggleError(bool shown);
  71. void hideError();
  72. void errorAnimationCallback();
  73. void updateScan(ScanInfo &&info, int width);
  74. void pushScan(const ScanInfo &info);
  75. not_null<PanelController*> controller;
  76. std::vector<ScanInfo> files;
  77. std::optional<int> initialCount;
  78. QString errorMissing;
  79. QPointer<Ui::SlideWrap<Ui::BoxContentDivider>> divider;
  80. QPointer<Ui::SlideWrap<Ui::FlatLabel>> header;
  81. QPointer<Ui::SlideWrap<Ui::FlatLabel>> uploadMoreError;
  82. QPointer<Ui::VerticalLayout> wrap;
  83. std::vector<base::unique_qptr<Ui::SlideWrap<ScanButton>>> rows;
  84. QPointer<Ui::SettingsButton> upload;
  85. rpl::event_stream<rpl::producer<QString>> uploadTexts;
  86. bool errorShown = false;
  87. Ui::Animations::Simple errorAnimation;
  88. };
  89. List &list(FileType type);
  90. const List &list(FileType type) const;
  91. void setupScans(const QString &header);
  92. void setupList(
  93. not_null<Ui::VerticalLayout*> container,
  94. FileType type,
  95. const QString &header);
  96. void setupSpecialScans(
  97. const QString &header,
  98. std::map<FileType, ScanInfo> &&files);
  99. void init();
  100. void chooseScan(FileType type);
  101. void updateScan(ScanInfo &&info);
  102. void updateSpecialScan(ScanInfo &&info);
  103. void createSpecialScanRow(
  104. SpecialScan &scan,
  105. const ScanInfo &info,
  106. bool requiresBothSides);
  107. base::unique_qptr<Ui::SlideWrap<ScanButton>> createScan(
  108. not_null<Ui::VerticalLayout*> parent,
  109. const ScanInfo &info,
  110. const QString &name);
  111. SpecialScan &findSpecialScan(FileType type);
  112. void updateErrorLabels();
  113. bool somethingChanged() const;
  114. void toggleSpecialScanError(FileType type, bool shown);
  115. void hideSpecialScanError(FileType type);
  116. void specialScanErrorAnimationCallback(FileType type);
  117. void specialScanChanged(FileType type, bool changed);
  118. not_null<PanelController*> _controller;
  119. QString _error;
  120. object_ptr<Ui::VerticalLayout> _content;
  121. QPointer<Ui::SlideWrap<Ui::FlatLabel>> _commonError;
  122. bool _scanFieldsChanged = false;
  123. bool _specialScanChanged = false;
  124. List _scansList;
  125. std::map<FileType, SpecialScan> _specialScans;
  126. List _translationsList;
  127. };
  128. } // namespace Passport