2016-07-28 17:01:08 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-07-28 17:01:08 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
2018-04-09 17:56:07 +00:00
|
|
|
#include "base/timer.h"
|
2017-03-21 11:42:04 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
namespace Ui {
|
2016-11-15 11:56:49 +00:00
|
|
|
class InputField;
|
2016-11-16 10:44:06 +00:00
|
|
|
class FlatLabel;
|
2016-11-11 13:46:04 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2017-03-21 11:42:04 +00:00
|
|
|
class SentCodeField : public Ui::InputField {
|
|
|
|
public:
|
2017-05-30 15:21:05 +00:00
|
|
|
SentCodeField(QWidget *parent, const style::InputField &st, base::lambda<QString()> placeholderFactory = base::lambda<QString()>(), const QString &val = QString()) : Ui::InputField(parent, st, std::move(placeholderFactory), val) {
|
2017-03-21 11:42:04 +00:00
|
|
|
connect(this, &Ui::InputField::changed, [this] { fix(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAutoSubmit(int length, base::lambda<void()> submitCallback) {
|
|
|
|
_autoSubmitLength = length;
|
|
|
|
_submitCallback = std::move(submitCallback);
|
|
|
|
}
|
|
|
|
void setChangedCallback(base::lambda<void()> changedCallback) {
|
|
|
|
_changedCallback = std::move(changedCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void fix();
|
|
|
|
|
|
|
|
// Flag for not calling onTextChanged() recursively.
|
|
|
|
bool _fixing = false;
|
|
|
|
|
|
|
|
int _autoSubmitLength = 0;
|
|
|
|
base::lambda<void()> _submitCallback;
|
|
|
|
base::lambda<void()> _changedCallback;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class SentCodeCall {
|
|
|
|
public:
|
2018-04-09 17:56:07 +00:00
|
|
|
SentCodeCall(
|
|
|
|
base::lambda_once<void()> callCallback,
|
|
|
|
base::lambda<void()> updateCallback);
|
2017-03-21 11:42:04 +00:00
|
|
|
|
|
|
|
enum class State {
|
|
|
|
Waiting,
|
|
|
|
Calling,
|
|
|
|
Called,
|
|
|
|
Disabled,
|
|
|
|
};
|
|
|
|
struct Status {
|
|
|
|
Status() {
|
|
|
|
}
|
|
|
|
Status(State state, int timeout) : state(state), timeout(timeout) {
|
|
|
|
}
|
|
|
|
|
|
|
|
State state = State::Disabled;
|
|
|
|
int timeout = 0;
|
|
|
|
};
|
|
|
|
void setStatus(const Status &status);
|
|
|
|
|
|
|
|
void callDone() {
|
|
|
|
if (_status.state == State::Calling) {
|
|
|
|
_status.state = State::Called;
|
|
|
|
if (_update) {
|
|
|
|
_update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString getText() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Status _status;
|
2018-04-09 17:56:07 +00:00
|
|
|
base::Timer _timer;
|
2017-03-21 11:42:04 +00:00
|
|
|
base::lambda_once<void()> _call;
|
|
|
|
base::lambda<void()> _update;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
class ConfirmPhoneBox : public BoxContent, public RPCSender {
|
2016-07-28 17:01:08 +00:00
|
|
|
public:
|
|
|
|
static void start(const QString &phone, const QString &hash);
|
|
|
|
|
|
|
|
~ConfirmPhoneBox();
|
|
|
|
|
|
|
|
protected:
|
2016-12-13 17:07:56 +00:00
|
|
|
void prepare() override;
|
|
|
|
void setInnerFocus() override;
|
|
|
|
|
2016-07-28 17:01:08 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
2016-12-13 17:07:56 +00:00
|
|
|
ConfirmPhoneBox(QWidget*, const QString &phone, const QString &hash);
|
|
|
|
friend class object_ptr<ConfirmPhoneBox>;
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void sendCode();
|
2017-03-21 11:42:04 +00:00
|
|
|
void sendCall();
|
2016-12-13 17:07:56 +00:00
|
|
|
void checkPhoneAndHash();
|
|
|
|
|
2016-07-28 17:01:08 +00:00
|
|
|
void sendCodeDone(const MTPauth_SentCode &result);
|
|
|
|
bool sendCodeFail(const RPCError &error);
|
|
|
|
|
|
|
|
void callDone(const MTPauth_SentCode &result);
|
|
|
|
|
|
|
|
void confirmDone(const MTPBool &result);
|
|
|
|
bool confirmFail(const RPCError &error);
|
|
|
|
|
|
|
|
QString getPhone() const {
|
|
|
|
return _phone;
|
|
|
|
}
|
|
|
|
void launch();
|
|
|
|
|
|
|
|
void showError(const QString &error);
|
|
|
|
|
|
|
|
mtpRequestId _sendCodeRequestId = 0;
|
|
|
|
|
2016-07-29 10:05:00 +00:00
|
|
|
// _hash from the link for account.sendConfirmPhoneCode call.
|
|
|
|
// _phoneHash from auth.sentCode for account.confirmPhone call.
|
|
|
|
QString _phone, _hash;
|
|
|
|
QString _phoneHash;
|
2016-07-28 17:01:08 +00:00
|
|
|
|
|
|
|
// If we receive the code length, we autosubmit _code field when enough symbols is typed.
|
|
|
|
int _sentCodeLength = 0;
|
|
|
|
|
|
|
|
mtpRequestId _checkCodeRequestId = 0;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::FlatLabel> _about = { nullptr };
|
2017-03-21 11:42:04 +00:00
|
|
|
object_ptr<SentCodeField> _code = { nullptr };
|
2016-07-28 17:01:08 +00:00
|
|
|
|
|
|
|
QString _error;
|
2017-03-21 11:42:04 +00:00
|
|
|
SentCodeCall _call;
|
2016-07-28 17:01:08 +00:00
|
|
|
|
|
|
|
};
|