tdesktop/Telegram/SourceFiles/passport/passport_panel_edit_scans.h

153 lines
3.9 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/rp_widget.h"
2019-04-02 09:13:30 +00:00
#include "ui/effects/animations.h"
2019-09-13 12:22:54 +00:00
#include "base/object_ptr.h"
namespace Ui {
2019-09-18 11:19:05 +00:00
class BoxContentDivider;
class VerticalLayout;
class SettingsButton;
class FlatLabel;
template <typename Widget>
class SlideWrap;
} // namespace Ui
namespace Passport {
2018-08-14 15:27:47 +00:00
enum class FileType;
class PanelController;
class ScanButton;
struct ScanInfo;
enum class ReadScanError {
FileTooLarge,
CantReadImage,
BadImageSize,
Unknown,
};
2018-08-14 15:27:47 +00:00
struct ScanListData {
std::vector<ScanInfo> files;
QString errorMissing;
};
class EditScans : public Ui::RpWidget {
public:
EditScans(
QWidget *parent,
not_null<PanelController*> controller,
2018-04-10 07:51:19 +00:00
const QString &header,
const QString &error,
2018-08-14 15:27:47 +00:00
ScanListData &&scans,
2018-09-21 16:28:46 +00:00
std::optional<ScanListData> &&translations);
EditScans(
QWidget *parent,
not_null<PanelController*> controller,
const QString &header,
const QString &error,
2018-08-14 15:27:47 +00:00
std::map<FileType, ScanInfo> &&specialFiles,
2018-09-21 16:28:46 +00:00
std::optional<ScanListData> &&translations);
2018-09-21 16:28:46 +00:00
std::optional<int> validateGetErrorTop();
2018-04-13 10:54:17 +00:00
void scanFieldsChanged(bool changed);
static void ChooseScan(
QPointer<QWidget> parent,
2018-08-14 15:27:47 +00:00
FileType type,
Fn<void(QByteArray&&)> doneCallback,
2018-08-14 15:27:47 +00:00
Fn<void(ReadScanError)> errorCallback);
2018-04-10 07:51:19 +00:00
~EditScans();
private:
struct SpecialScan;
2018-08-14 15:27:47 +00:00
struct List {
List(not_null<PanelController*> controller, ScanListData &&data);
List(
not_null<PanelController*> controller,
2018-09-21 16:28:46 +00:00
std::optional<ScanListData> &&data = std::nullopt);
2018-08-14 15:27:47 +00:00
bool uploadedSomeMore() const;
bool uploadMoreRequired() const;
Ui::SlideWrap<ScanButton> *nonDeletedErrorRow() const;
rpl::producer<QString> uploadButtonText() const;
void toggleError(bool shown);
void hideError();
void errorAnimationCallback();
void updateScan(ScanInfo &&info, int width);
void pushScan(const ScanInfo &info);
not_null<PanelController*> controller;
std::vector<ScanInfo> files;
2018-09-21 16:28:46 +00:00
std::optional<int> initialCount;
2018-08-14 15:27:47 +00:00
QString errorMissing;
2019-09-18 11:19:05 +00:00
QPointer<Ui::SlideWrap<Ui::BoxContentDivider>> divider;
2018-08-14 15:27:47 +00:00
QPointer<Ui::SlideWrap<Ui::FlatLabel>> header;
QPointer<Ui::SlideWrap<Ui::FlatLabel>> uploadMoreError;
QPointer<Ui::VerticalLayout> wrap;
std::vector<base::unique_qptr<Ui::SlideWrap<ScanButton>>> rows;
QPointer<Ui::SettingsButton> upload;
2018-08-14 15:27:47 +00:00
rpl::event_stream<rpl::producer<QString>> uploadTexts;
bool errorShown = false;
2019-04-02 09:13:30 +00:00
Ui::Animations::Simple errorAnimation;
2018-08-14 15:27:47 +00:00
};
List &list(FileType type);
const List &list(FileType type) const;
void setupScans(const QString &header);
2018-08-14 15:27:47 +00:00
void setupList(
not_null<Ui::VerticalLayout*> container,
FileType type,
const QString &header);
void setupSpecialScans(
const QString &header,
std::map<FileType, ScanInfo> &&files);
void init();
2018-08-14 15:27:47 +00:00
void chooseScan(FileType type);
void updateScan(ScanInfo &&info);
2018-08-14 15:27:47 +00:00
void updateSpecialScan(ScanInfo &&info);
void createSpecialScanRow(
SpecialScan &scan,
2018-07-10 09:18:30 +00:00
const ScanInfo &info,
bool requiresBothSides);
2018-04-10 19:00:52 +00:00
base::unique_qptr<Ui::SlideWrap<ScanButton>> createScan(
not_null<Ui::VerticalLayout*> parent,
const ScanInfo &info,
const QString &name);
2018-08-14 15:27:47 +00:00
SpecialScan &findSpecialScan(FileType type);
void updateErrorLabels();
bool somethingChanged() const;
2018-04-13 10:54:17 +00:00
2018-08-14 15:27:47 +00:00
void toggleSpecialScanError(FileType type, bool shown);
void hideSpecialScanError(FileType type);
void specialScanErrorAnimationCallback(FileType type);
void specialScanChanged(FileType type, bool changed);
2018-04-13 10:54:17 +00:00
not_null<PanelController*> _controller;
QString _error;
object_ptr<Ui::VerticalLayout> _content;
QPointer<Ui::SlideWrap<Ui::FlatLabel>> _commonError;
bool _scanFieldsChanged = false;
bool _specialScanChanged = false;
2018-08-14 15:27:47 +00:00
List _scansList;
std::map<FileType, SpecialScan> _specialScans;
List _translationsList;
2018-04-10 19:00:52 +00:00
};
} // namespace Passport