2018-03-31 01:45:40 +00:00
|
|
|
/*
|
|
|
|
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-09-13 12:22:54 +00:00
|
|
|
#include "base/object_ptr.h"
|
2018-03-31 01:45:40 +00:00
|
|
|
|
2019-09-13 06:06:02 +00:00
|
|
|
class BoxContent;
|
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
namespace Ui {
|
|
|
|
class InputField;
|
|
|
|
class ScrollArea;
|
|
|
|
class FadeShadow;
|
|
|
|
class PlainShadow;
|
2018-08-14 11:37:03 +00:00
|
|
|
class FlatLabel;
|
2018-03-31 01:45:40 +00:00
|
|
|
class RoundButton;
|
2018-08-17 13:42:07 +00:00
|
|
|
class VerticalLayout;
|
2018-08-14 11:37:03 +00:00
|
|
|
template <typename Widget>
|
|
|
|
class SlideWrap;
|
2018-03-31 01:45:40 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2018-04-13 16:43:17 +00:00
|
|
|
namespace Info {
|
|
|
|
namespace Profile {
|
|
|
|
class Button;
|
|
|
|
} // namespace Profile
|
|
|
|
} // namespace Info
|
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
namespace Passport {
|
|
|
|
|
|
|
|
class PanelController;
|
|
|
|
struct ValueMap;
|
|
|
|
struct ScanInfo;
|
2018-04-04 19:26:40 +00:00
|
|
|
class EditScans;
|
2018-04-05 17:01:22 +00:00
|
|
|
class PanelDetailsRow;
|
2018-08-14 15:27:47 +00:00
|
|
|
enum class FileType;
|
2018-04-10 11:26:21 +00:00
|
|
|
enum class PanelDetailsType;
|
2018-08-14 15:27:47 +00:00
|
|
|
struct ScanListData;
|
2018-03-31 01:45:40 +00:00
|
|
|
|
2018-04-12 15:45:04 +00:00
|
|
|
struct EditDocumentScheme {
|
|
|
|
enum class ValueClass {
|
|
|
|
Fields,
|
2018-08-17 13:42:07 +00:00
|
|
|
Additional,
|
2018-04-12 15:45:04 +00:00
|
|
|
Scans,
|
|
|
|
};
|
2018-08-20 12:40:41 +00:00
|
|
|
enum class AdditionalVisibility {
|
|
|
|
Hidden,
|
|
|
|
OnlyIfError,
|
|
|
|
Shown,
|
|
|
|
};
|
2018-04-12 15:45:04 +00:00
|
|
|
struct Row {
|
2018-09-21 16:28:46 +00:00
|
|
|
using Validator = Fn<std::optional<QString>(const QString &value)>;
|
2018-08-14 12:51:12 +00:00
|
|
|
using Formatter = Fn<QString(const QString &value)>;
|
2018-04-12 15:45:04 +00:00
|
|
|
ValueClass valueClass = ValueClass::Fields;
|
|
|
|
PanelDetailsType inputType = PanelDetailsType();
|
|
|
|
QString key;
|
|
|
|
QString label;
|
2018-08-14 12:51:12 +00:00
|
|
|
Validator error;
|
|
|
|
Formatter format;
|
2018-04-13 11:15:07 +00:00
|
|
|
int lengthLimit = 0;
|
2018-08-20 12:40:41 +00:00
|
|
|
QString keyForAttachmentTo; // Attach [last|middle]_name to first_*.
|
|
|
|
QString additionalFallbackKey; // *_name_native from *_name.
|
2018-04-12 15:45:04 +00:00
|
|
|
};
|
|
|
|
std::vector<Row> rows;
|
2018-08-14 06:42:06 +00:00
|
|
|
QString fieldsHeader;
|
|
|
|
QString detailsHeader;
|
2018-04-12 15:45:04 +00:00
|
|
|
QString scansHeader;
|
|
|
|
|
2018-08-17 13:42:07 +00:00
|
|
|
QString additionalDependencyKey;
|
2018-08-20 12:40:41 +00:00
|
|
|
Fn<AdditionalVisibility(const QString &dependency)> additionalShown;
|
|
|
|
Fn<QString(const QString &dependency)> additionalHeader;
|
2018-08-17 13:42:07 +00:00
|
|
|
Fn<QString(const QString &dependency)> additionalDescription;
|
|
|
|
|
2018-04-12 15:45:04 +00:00
|
|
|
};
|
|
|
|
|
2018-04-05 17:01:22 +00:00
|
|
|
class PanelEditDocument : public Ui::RpWidget {
|
2018-03-31 01:45:40 +00:00
|
|
|
public:
|
2018-04-12 15:45:04 +00:00
|
|
|
using Scheme = EditDocumentScheme;
|
2018-04-05 17:01:22 +00:00
|
|
|
|
|
|
|
PanelEditDocument(
|
2018-03-31 01:45:40 +00:00
|
|
|
QWidget *parent,
|
|
|
|
not_null<PanelController*> controller,
|
2018-04-05 17:01:22 +00:00
|
|
|
Scheme scheme,
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString &error,
|
2018-03-31 01:45:40 +00:00
|
|
|
const ValueMap &data,
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString &scansError,
|
|
|
|
const ValueMap &scansData,
|
2018-08-14 15:27:47 +00:00
|
|
|
ScanListData &&scans,
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<ScanListData> &&translations,
|
2018-08-14 15:27:47 +00:00
|
|
|
std::map<FileType, ScanInfo> &&specialFiles);
|
2018-08-14 06:42:06 +00:00
|
|
|
PanelEditDocument(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<PanelController*> controller,
|
|
|
|
Scheme scheme,
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString &scansError,
|
|
|
|
const ValueMap &scansData,
|
2018-08-14 15:27:47 +00:00
|
|
|
ScanListData &&scans,
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<ScanListData> &&translations,
|
2018-08-14 15:27:47 +00:00
|
|
|
std::map<FileType, ScanInfo> &&specialFiles);
|
2018-04-05 17:01:22 +00:00
|
|
|
PanelEditDocument(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<PanelController*> controller,
|
|
|
|
Scheme scheme,
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString &error,
|
2018-04-05 17:01:22 +00:00
|
|
|
const ValueMap &data);
|
2018-03-31 01:45:40 +00:00
|
|
|
|
2018-04-09 17:56:07 +00:00
|
|
|
bool hasUnsavedChanges() const;
|
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
protected:
|
|
|
|
void focusInEvent(QFocusEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
2018-04-09 17:56:07 +00:00
|
|
|
struct Result;
|
2018-04-04 19:26:40 +00:00
|
|
|
void setupControls(
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString *error,
|
2018-08-14 06:42:06 +00:00
|
|
|
const ValueMap *data,
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString *scansError,
|
|
|
|
const ValueMap *scansData,
|
2018-08-14 15:27:47 +00:00
|
|
|
ScanListData &&scans,
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<ScanListData> &&translations,
|
2018-08-14 15:27:47 +00:00
|
|
|
std::map<FileType, ScanInfo> &&specialFiles);
|
2018-04-03 18:24:31 +00:00
|
|
|
not_null<Ui::RpWidget*> setupContent(
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString *error,
|
2018-08-14 06:42:06 +00:00
|
|
|
const ValueMap *data,
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString *scansError,
|
|
|
|
const ValueMap *scansData,
|
2018-08-14 15:27:47 +00:00
|
|
|
ScanListData &&scans,
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<ScanListData> &&translations,
|
2018-08-14 15:27:47 +00:00
|
|
|
std::map<FileType, ScanInfo> &&specialFiles);
|
2018-03-31 01:45:40 +00:00
|
|
|
void updateControlsGeometry();
|
2018-08-14 11:37:03 +00:00
|
|
|
void updateCommonError();
|
2018-03-31 01:45:40 +00:00
|
|
|
|
2018-04-09 17:56:07 +00:00
|
|
|
Result collect() const;
|
2018-08-20 12:40:41 +00:00
|
|
|
void fillAdditionalFromFallbacks(Result &result) const;
|
2018-04-13 10:10:09 +00:00
|
|
|
bool validate();
|
2018-03-31 01:45:40 +00:00
|
|
|
void save();
|
|
|
|
|
2018-08-17 13:42:07 +00:00
|
|
|
void createDetailsRow(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
int i,
|
|
|
|
const Scheme::Row &row,
|
|
|
|
const ValueMap &fields,
|
|
|
|
int maxLabelWidth);
|
|
|
|
not_null<PanelDetailsRow*> findRow(const QString &key) const;
|
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
not_null<PanelController*> _controller;
|
2018-04-05 17:01:22 +00:00
|
|
|
Scheme _scheme;
|
2018-03-31 01:45:40 +00:00
|
|
|
|
|
|
|
object_ptr<Ui::ScrollArea> _scroll;
|
|
|
|
object_ptr<Ui::FadeShadow> _topShadow;
|
|
|
|
object_ptr<Ui::PlainShadow> _bottomShadow;
|
|
|
|
|
2018-04-04 19:26:40 +00:00
|
|
|
QPointer<EditScans> _editScans;
|
2018-08-14 11:37:03 +00:00
|
|
|
QPointer<Ui::SlideWrap<Ui::FlatLabel>> _commonError;
|
2018-04-06 18:47:29 +00:00
|
|
|
std::map<int, QPointer<PanelDetailsRow>> _details;
|
2018-08-14 11:37:03 +00:00
|
|
|
bool _fieldsChanged = false;
|
2018-08-20 12:40:41 +00:00
|
|
|
bool _additionalShown = false;
|
2018-03-31 01:45:40 +00:00
|
|
|
|
2018-04-13 16:43:17 +00:00
|
|
|
QPointer<Info::Profile::Button> _delete;
|
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
object_ptr<Ui::RoundButton> _done;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-04-10 07:51:19 +00:00
|
|
|
object_ptr<BoxContent> RequestIdentityType(
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(int index)> submit,
|
2018-04-10 07:51:19 +00:00
|
|
|
std::vector<QString> labels);
|
|
|
|
object_ptr<BoxContent> RequestAddressType(
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(int index)> submit,
|
2018-04-10 07:51:19 +00:00
|
|
|
std::vector<QString> labels);
|
|
|
|
|
2018-04-13 16:43:17 +00:00
|
|
|
object_ptr<BoxContent> ConfirmDeleteDocument(
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(bool withDetails)> submit,
|
2018-04-13 16:43:17 +00:00
|
|
|
const QString &text,
|
|
|
|
const QString &detailsCheckbox = QString());
|
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
} // namespace Passport
|