/* 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" #include "ui/layers/layer_widget.h" namespace Ui { class BoxContent; } // namespace Ui namespace Passport { class FormController; class Panel; struct EditDocumentScheme; struct EditContactScheme; enum class ReadScanError; EditDocumentScheme GetDocumentScheme( Scope::Type type, std::optional scansType, bool nativeNames); EditContactScheme GetContactScheme(Scope::Type type); const std::map &LatinToNativeMap(); const std::map &NativeToLatinMap(); QString AdjustKeyName(not_null value, const QString &key); bool SkipFieldCheck(not_null 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 { 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 key; QString text; }; class PanelController : public ViewController { public: PanelController(not_null form); not_null bot() const; QString privacyPolicyUrl() const; void submitForm(); void submitPassword(const QByteArray &password); void recoverPassword(); rpl::producer passwordError() const; QString passwordHint() const; QString unconfirmedEmailPattern() const; void setupPassword(); void cancelPasswordSubmit(); void validateRecoveryEmail(); bool canAddScan(FileType type) const; void uploadScan(FileType type, QByteArray &&content); void deleteScan(FileType type, std::optional fileIndex); void restoreScan(FileType type, std::optional fileIndex); rpl::producer scanUpdated() const; rpl::producer saveErrors() const; void readScanError(ReadScanError error); std::optional> deleteValueLabel() const; 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 callback); rpl::producer<> refillRows() const; void editScope(int index) override; void saveScope(ValueMap &&data, ValueMap &&filesData); bool editScopeChanged( const ValueMap &data, const ValueMap &filesData) const; void cancelEditScope(); void showBox( object_ptr box, Ui::LayerOptions options, anim::type animated) override; void showToast(const QString &text) override; void suggestReset(Fn callback) override; int closeGetDuration() override; void cancelAuth(); void cancelAuthSure(); rpl::lifetime &lifetime(); ~PanelController(); private: void ensurePanelCreated(); void editScope(int index, std::optional documentIndex); void editWithUpload(int index, int documentIndex); bool editRequiresScanUpload( int index, std::optional documentIndex) const; void startScopeEdit(int index, std::optional documentIndex); std::optional findBestDocumentIndex(const Scope &scope) const; void requestScopeFilesType(int index); void cancelValueEdit(); void processValueSaveFinished(not_null value); void processVerificationNeeded(not_null value); bool savingScope() const; bool uploadingScopeScan() const; bool hasValueDocument() const; bool hasValueFields() const; std::vector collectSaveErrors( not_null value) const; QString getDefaultContactValue(Scope::Type type) const; void deleteValueSure(bool withDetails); void resetPassport(Fn callback); void cancelReset(); not_null _form; std::vector _scopes; rpl::event_stream<> _submitFailed; std::vector> _submitErrors; rpl::event_stream _saveErrors; std::unique_ptr _panel; Fn _panelHasUnsavedChanges; QPointer _confirmForgetChangesBox; std::vector _editScopeBoxes; Scope *_editScope = nullptr; const Value *_editValue = nullptr; const Value *_editDocument = nullptr; Ui::BoxPointer _scopeDocumentTypeBox; std::map, Ui::BoxPointer> _verificationBoxes; Ui::BoxPointer _resetBox; rpl::lifetime _lifetime; }; } // namespace Passport