2017-04-08 13:27:53 +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.
|
2017-04-08 13:27:53 +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
|
2017-04-08 13:27:53 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ui/widgets/input_fields.h"
|
2018-05-21 21:31:46 +00:00
|
|
|
#include "base/timer.h"
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2019-08-02 10:40:35 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
2019-06-06 10:21:40 +00:00
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
namespace Window {
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2017-04-08 13:27:53 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
|
|
|
QString ConvertTagToMimeTag(const QString &tagId);
|
2018-05-26 14:58:21 +00:00
|
|
|
QString PrepareMentionTag(not_null<UserData*> user);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
EntitiesInText ConvertTextTagsToEntities(const TextWithTags::Tags &tags);
|
2018-01-25 10:10:52 +00:00
|
|
|
TextWithTags::Tags ConvertEntitiesToTextTags(
|
|
|
|
const EntitiesInText &entities);
|
2019-04-08 15:10:06 +00:00
|
|
|
std::unique_ptr<QMimeData> MimeDataFromText(const TextForMimeData &text);
|
|
|
|
void SetClipboardText(
|
|
|
|
const TextForMimeData &text,
|
2018-01-25 10:10:52 +00:00
|
|
|
QClipboard::Mode mode = QClipboard::Clipboard);
|
2019-06-05 18:40:21 +00:00
|
|
|
TextWithTags PrepareEditText(not_null<HistoryItem*> item);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<bool(
|
2018-05-26 14:58:21 +00:00
|
|
|
Ui::InputField::EditLinkSelection selection,
|
|
|
|
QString text,
|
|
|
|
QString link,
|
|
|
|
Ui::InputField::EditLinkAction action)> DefaultEditLinkCallback(
|
2019-08-02 10:40:35 +00:00
|
|
|
not_null<Main::Session*> session,
|
2018-05-26 14:58:21 +00:00
|
|
|
not_null<Ui::InputField*> field);
|
|
|
|
void InitMessageField(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2018-05-26 14:58:21 +00:00
|
|
|
not_null<Ui::InputField*> field);
|
2018-05-21 21:31:46 +00:00
|
|
|
bool HasSendText(not_null<const Ui::InputField*> field);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-05-21 21:31:46 +00:00
|
|
|
struct InlineBotQuery {
|
|
|
|
QString query;
|
|
|
|
QString username;
|
|
|
|
UserData *bot = nullptr;
|
|
|
|
bool lookingUpBot = false;
|
|
|
|
};
|
|
|
|
InlineBotQuery ParseInlineBotQuery(not_null<const Ui::InputField*> field);
|
|
|
|
|
|
|
|
struct AutocompleteQuery {
|
|
|
|
QString query;
|
|
|
|
bool fromStart = false;
|
|
|
|
};
|
|
|
|
AutocompleteQuery ParseMentionHashtagBotCommandQuery(
|
|
|
|
not_null<const Ui::InputField*> field);
|
|
|
|
|
|
|
|
class QtConnectionOwner {
|
2017-04-08 13:27:53 +00:00
|
|
|
public:
|
2018-05-21 21:31:46 +00:00
|
|
|
QtConnectionOwner(QMetaObject::Connection connection = {});
|
|
|
|
QtConnectionOwner(QtConnectionOwner &&other);
|
|
|
|
QtConnectionOwner &operator=(QtConnectionOwner &&other);
|
|
|
|
~QtConnectionOwner();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-05-21 21:31:46 +00:00
|
|
|
private:
|
|
|
|
void disconnect();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-05-21 21:31:46 +00:00
|
|
|
QMetaObject::Connection _data;
|
|
|
|
|
|
|
|
};
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-05-21 21:31:46 +00:00
|
|
|
class MessageLinksParser : private QObject {
|
|
|
|
public:
|
|
|
|
MessageLinksParser(not_null<Ui::InputField*> field);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-05-21 21:31:46 +00:00
|
|
|
const rpl::variable<QStringList> &list() const;
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
protected:
|
2018-05-21 21:31:46 +00:00
|
|
|
bool eventFilter(QObject *object, QEvent *event) override;
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
private:
|
2018-05-21 21:31:46 +00:00
|
|
|
struct LinkRange {
|
|
|
|
int start;
|
|
|
|
int length;
|
2018-05-26 14:58:21 +00:00
|
|
|
QString custom;
|
2018-05-21 21:31:46 +00:00
|
|
|
};
|
|
|
|
friend inline bool operator==(const LinkRange &a, const LinkRange &b) {
|
2018-05-26 14:58:21 +00:00
|
|
|
return (a.start == b.start)
|
|
|
|
&& (a.length == b.length)
|
|
|
|
&& (a.custom == b.custom);
|
2018-05-21 21:31:46 +00:00
|
|
|
}
|
|
|
|
friend inline bool operator!=(const LinkRange &a, const LinkRange &b) {
|
|
|
|
return !(a == b);
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-05-21 21:31:46 +00:00
|
|
|
void parse();
|
|
|
|
void apply(const QString &text, const QVector<LinkRange> &ranges);
|
|
|
|
|
|
|
|
not_null<Ui::InputField*> _field;
|
|
|
|
rpl::variable<QStringList> _list;
|
|
|
|
int _lastLength = 0;
|
|
|
|
base::Timer _timer;
|
|
|
|
QtConnectionOwner _connection;
|
|
|
|
|
2019-07-26 16:06:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void SetupSendWithoutSound(
|
|
|
|
not_null<Ui::RpWidget*> button,
|
|
|
|
Fn<bool()> enabled,
|
|
|
|
Fn<void()> send);
|