tdesktop/Telegram/SourceFiles/passport/passport_panel_controller.h

192 lines
5.1 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 "passport/passport_form_view_controller.h"
#include "passport/passport_form_controller.h"
2019-09-18 11:19:05 +00:00
#include "ui/layers/layer_widget.h"
namespace Ui {
class BoxContent;
} // namespace Ui
namespace Passport {
class FormController;
class Panel;
struct EditDocumentCountry;
2018-04-12 15:45:04 +00:00
struct EditDocumentScheme;
struct EditContactScheme;
enum class ReadScanError;
using preferredLangCallback =
Fn<rpl::producer<EditDocumentCountry>(const QString &)>;
2018-04-12 15:45:04 +00:00
EditDocumentScheme GetDocumentScheme(
Scope::Type type,
2018-09-21 16:28:46 +00:00
std::optional<Value::Type> scansType,
bool nativeNames,
preferredLangCallback &&preferredLanguage);
2018-04-12 15:45:04 +00:00
EditContactScheme GetContactScheme(Scope::Type type);
const std::map<QString, QString> &LatinToNativeMap();
const std::map<QString, QString> &NativeToLatinMap();
QString AdjustKeyName(not_null<const Value*> value, const QString &key);
2018-08-14 05:43:40 +00:00
bool SkipFieldCheck(not_null<const Value*> value, const QString &key);
struct ScanInfo {
explicit ScanInfo(FileType type);
ScanInfo(
FileType type,
const FileKey &key,
const QString &status,
const QImage &thumb,
bool deleted,
const QString &error);
FileType type;
FileKey key;
QString status;
QImage thumb;
bool deleted = false;
QString error;
};
struct ScopeError {
2018-08-14 05:43:40 +00:00
enum class General {
WholeValue,
ScanMissing,
TranslationMissing,
};
// FileKey - file_hash error (bad scan / selfie / translation)
// General - general value error (or scan / translation missing)
// QString - data_hash with such key error (bad value)
std::variant<FileKey, General, QString> key;
QString text;
};
class PanelController : public ViewController {
public:
PanelController(not_null<FormController*> form);
not_null<UserData*> bot() const;
2018-04-03 18:24:31 +00:00
QString privacyPolicyUrl() const;
2018-04-12 15:45:04 +00:00
void submitForm();
void submitPassword(const QByteArray &password);
void recoverPassword();
rpl::producer<QString> passwordError() const;
QString passwordHint() const;
2018-04-16 17:02:40 +00:00
QString unconfirmedEmailPattern() const;
void setupPassword();
void cancelPasswordSubmit();
2018-11-07 09:39:31 +00:00
void validateRecoveryEmail();
2018-08-14 15:27:47 +00:00
bool canAddScan(FileType type) const;
void uploadScan(FileType type, QByteArray &&content);
2018-09-21 16:28:46 +00:00
void deleteScan(FileType type, std::optional<int> fileIndex);
void restoreScan(FileType type, std::optional<int> fileIndex);
rpl::producer<ScanInfo> scanUpdated() const;
rpl::producer<ScopeError> saveErrors() const;
void readScanError(ReadScanError error);
2018-09-21 16:28:46 +00:00
std::optional<rpl::producer<QString>> deleteValueLabel() const;
2018-04-13 16:43:17 +00:00
void deleteValue();
QString defaultEmail() const;
QString defaultPhoneNumber() const;
void showAskPassword() override;
void showNoPassword() override;
void showCriticalError(const QString &error) override;
void showUpdateAppBox() override;
void fillRows(
Fn<void(
QString title,
QString description,
2018-04-13 17:42:28 +00:00
bool ready,
bool error)> callback);
rpl::producer<> refillRows() const;
2018-04-03 18:24:31 +00:00
void editScope(int index) override;
void saveScope(ValueMap &&data, ValueMap &&filesData);
bool editScopeChanged(
const ValueMap &data,
const ValueMap &filesData) const;
void cancelEditScope();
2018-04-16 17:02:40 +00:00
void showBox(
2019-09-18 11:19:05 +00:00
object_ptr<Ui::BoxContent> box,
Ui::LayerOptions options,
2018-04-16 17:02:40 +00:00
anim::type animated) override;
2018-04-13 10:54:17 +00:00
void showToast(const QString &text) override;
void suggestReset(Fn<void()> callback) override;
2018-04-06 16:23:09 +00:00
int closeGetDuration() override;
void cancelAuth();
2018-06-02 14:29:21 +00:00
void cancelAuthSure();
rpl::lifetime &lifetime();
~PanelController();
private:
void ensurePanelCreated();
2018-09-21 16:28:46 +00:00
void editScope(int index, std::optional<int> documentIndex);
2018-04-12 15:45:04 +00:00
void editWithUpload(int index, int documentIndex);
bool editRequiresScanUpload(
int index,
2018-09-21 16:28:46 +00:00
std::optional<int> documentIndex) const;
void startScopeEdit(int index, std::optional<int> documentIndex);
std::optional<int> findBestDocumentIndex(const Scope &scope) const;
2018-04-10 07:51:19 +00:00
void requestScopeFilesType(int index);
void cancelValueEdit();
void processValueSaveFinished(not_null<const Value*> value);
void processVerificationNeeded(not_null<const Value*> value);
2018-04-13 16:43:17 +00:00
bool savingScope() const;
bool uploadingScopeScan() const;
2018-04-13 16:43:17 +00:00
bool hasValueDocument() const;
bool hasValueFields() const;
std::vector<ScopeError> collectSaveErrors(
not_null<const Value*> value) const;
QString getDefaultContactValue(Scope::Type type) const;
2018-04-13 16:43:17 +00:00
void deleteValueSure(bool withDetails);
void resetPassport(Fn<void()> callback);
void cancelReset();
not_null<FormController*> _form;
2018-04-03 18:24:31 +00:00
std::vector<Scope> _scopes;
2018-04-13 17:42:28 +00:00
rpl::event_stream<> _submitFailed;
std::vector<not_null<const Value*>> _submitErrors;
rpl::event_stream<ScopeError> _saveErrors;
std::unique_ptr<Panel> _panel;
Fn<bool()> _panelHasUnsavedChanges;
2019-09-18 11:19:05 +00:00
QPointer<Ui::BoxContent> _confirmForgetChangesBox;
std::vector<Ui::BoxPointer> _editScopeBoxes;
2018-04-03 18:24:31 +00:00
Scope *_editScope = nullptr;
2018-04-13 16:43:17 +00:00
const Value *_editValue = nullptr;
const Value *_editDocument = nullptr;
2019-09-18 11:19:05 +00:00
Ui::BoxPointer _scopeDocumentTypeBox;
std::map<not_null<const Value*>, Ui::BoxPointer> _verificationBoxes;
2019-09-18 11:19:05 +00:00
Ui::BoxPointer _resetBox;
rpl::lifetime _lifetime;
};
} // namespace Passport