Replace QSharedPointer with std::shared_ptr.

This commit is contained in:
John Preston 2017-12-18 13:07:18 +04:00
parent cbbccd0364
commit 14034c255e
46 changed files with 215 additions and 185 deletions

View File

@ -46,7 +46,6 @@ struct SubscriptionHandlerHelper<void> {
template <typename EventType> template <typename EventType>
using SubscriptionHandler = typename SubscriptionHandlerHelper<EventType>::type; using SubscriptionHandler = typename SubscriptionHandlerHelper<EventType>::type;
// Required because QShared/WeakPointer can't point to void.
class BaseObservableData { class BaseObservableData {
}; };
@ -84,14 +83,17 @@ public:
private: private:
struct Node { struct Node {
Node(const QSharedPointer<internal::BaseObservableData> &observable) : observable(observable) { Node(const std::shared_ptr<internal::BaseObservableData> &observable)
: observable(observable) {
} }
Node *next = nullptr; Node *next = nullptr;
Node *prev = nullptr; Node *prev = nullptr;
QWeakPointer<internal::BaseObservableData> observable; std::weak_ptr<internal::BaseObservableData> observable;
}; };
using RemoveAndDestroyMethod = void(*)(Node*); using RemoveAndDestroyMethod = void(*)(Node*);
Subscription(Node *node, RemoveAndDestroyMethod removeAndDestroyMethod) : _node(node), _removeAndDestroyMethod(removeAndDestroyMethod) { Subscription(Node *node, RemoveAndDestroyMethod removeAndDestroyMethod)
: _node(node)
, _removeAndDestroyMethod(removeAndDestroyMethod) {
} }
Node *_node = nullptr; Node *_node = nullptr;
@ -115,13 +117,13 @@ class CommonObservable {
public: public:
Subscription add_subscription(Handler &&handler) { Subscription add_subscription(Handler &&handler) {
if (!_data) { if (!_data) {
_data = MakeShared<ObservableData<EventType, Handler>>(this); _data = std::make_shared<ObservableData<EventType, Handler>>(this);
} }
return _data->append(std::move(handler)); return _data->append(std::move(handler));
} }
private: private:
QSharedPointer<ObservableData<EventType, Handler>> _data; std::shared_ptr<ObservableData<EventType, Handler>> _data;
friend class CommonObservableData<EventType, Handler>; friend class CommonObservableData<EventType, Handler>;
friend class BaseObservable<EventType, Handler, base::type_traits<EventType>::is_fast_copy_type::value>; friend class BaseObservable<EventType, Handler, base::type_traits<EventType>::is_fast_copy_type::value>;
@ -184,7 +186,11 @@ public:
private: private:
struct Node : public Subscription::Node { struct Node : public Subscription::Node {
Node(const QSharedPointer<BaseObservableData> &observer, Handler &&handler) : Subscription::Node(observer), handler(std::move(handler)) { Node(
const std::shared_ptr<BaseObservableData> &observer,
Handler &&handler)
: Subscription::Node(observer)
, handler(std::move(handler)) {
} }
Handler handler; Handler handler;
}; };
@ -210,8 +216,8 @@ private:
} }
static void removeAndDestroyNode(Subscription::Node *node) { static void removeAndDestroyNode(Subscription::Node *node) {
if (auto that = node->observable.toStrongRef()) { if (const auto that = node->observable.lock()) {
static_cast<CommonObservableData*>(that.data())->remove(node); static_cast<CommonObservableData*>(that.get())->remove(node);
} }
delete static_cast<Node*>(node); delete static_cast<Node*>(node);
} }

View File

@ -45,7 +45,7 @@ void AboutBox::prepare() {
addButton(langFactory(lng_close), [this] { closeBox(); }); addButton(langFactory(lng_close), [this] { closeBox(); });
const auto linkHook = [](const ClickHandlerPtr &link, auto button) { const auto linkHook = [](const ClickHandlerPtr &link, auto button) {
if (const auto url = dynamic_cast<UrlClickHandler*>(link.data())) { if (const auto url = dynamic_cast<UrlClickHandler*>(link.get())) {
url->UrlClickHandler::onClick(button); url->UrlClickHandler::onClick(button);
return false; return false;
} }

View File

@ -335,7 +335,7 @@ void GifsListWidget::mouseReleaseEvent(QMouseEvent *e) {
return; return;
} }
if (dynamic_cast<InlineBots::Layout::SendClickHandler*>(activated.data())) { if (dynamic_cast<InlineBots::Layout::SendClickHandler*>(activated.get())) {
int row = _selected / MatrixRowShift, column = _selected % MatrixRowShift; int row = _selected / MatrixRowShift, column = _selected % MatrixRowShift;
selectInlineResult(row, column); selectInlineResult(row, column);
} else { } else {

View File

@ -1005,19 +1005,21 @@ QRect StickersListWidget::megagroupSetButtonRectFinal() const {
return result; return result;
} }
QSharedPointer<Ui::RippleAnimation> StickersListWidget::createButtonRipple(int section) { std::shared_ptr<Ui::RippleAnimation> StickersListWidget::createButtonRipple(int section) {
if (_section == Section::Featured) { if (_section == Section::Featured) {
auto maskSize = QSize(_addWidth - st::stickersTrendingAdd.width, st::stickersTrendingAdd.height); auto maskSize = QSize(_addWidth - st::stickersTrendingAdd.width, st::stickersTrendingAdd.height);
auto mask = Ui::RippleAnimation::roundRectMask(maskSize, st::buttonRadius); auto mask = Ui::RippleAnimation::roundRectMask(maskSize, st::buttonRadius);
return MakeShared<Ui::RippleAnimation>(st::stickersTrendingAdd.ripple, std::move(mask), [this, section] { return std::make_shared<Ui::RippleAnimation>(
rtlupdate(featuredAddRect(section)); st::stickersTrendingAdd.ripple,
}); std::move(mask),
[this, section] { rtlupdate(featuredAddRect(section)); });
} }
auto maskSize = QSize(st::stickerPanRemoveSet.rippleAreaSize, st::stickerPanRemoveSet.rippleAreaSize); auto maskSize = QSize(st::stickerPanRemoveSet.rippleAreaSize, st::stickerPanRemoveSet.rippleAreaSize);
auto mask = Ui::RippleAnimation::ellipseMask(maskSize); auto mask = Ui::RippleAnimation::ellipseMask(maskSize);
return MakeShared<Ui::RippleAnimation>(st::stickerPanRemoveSet.ripple, std::move(mask), [this, section] { return std::make_shared<Ui::RippleAnimation>(
rtlupdate(removeButtonRect(section)); st::stickerPanRemoveSet.ripple,
}); std::move(mask),
[this, section] { rtlupdate(removeButtonRect(section)); });
} }
QPoint StickersListWidget::buttonRippleTopLeft(int section) const { QPoint StickersListWidget::buttonRippleTopLeft(int section) const {

View File

@ -144,7 +144,7 @@ private:
MTPDstickerSet::Flags flags; MTPDstickerSet::Flags flags;
QString title; QString title;
Stickers::Pack pack; Stickers::Pack pack;
QSharedPointer<Ui::RippleAnimation> ripple; std::shared_ptr<Ui::RippleAnimation> ripple;
}; };
using Sets = QList<Set>; using Sets = QList<Set>;
@ -172,7 +172,7 @@ private:
void updateSelected(); void updateSelected();
void setSelected(OverState newSelected); void setSelected(OverState newSelected);
void setPressed(OverState newPressed); void setPressed(OverState newPressed);
QSharedPointer<Ui::RippleAnimation> createButtonRipple(int section); std::shared_ptr<Ui::RippleAnimation> createButtonRipple(int section);
QPoint buttonRippleTopLeft(int section) const; QPoint buttonRippleTopLeft(int section) const;
enum class ValidateIconAnimations { enum class ValidateIconAnimations {

View File

@ -38,9 +38,11 @@ bool ClickHandler::setActive(const ClickHandlerPtr &p, ClickHandlerHost *host) {
// other pressed click handler currently, if there is // other pressed click handler currently, if there is
// this method will be called when it is unpressed // this method will be called when it is unpressed
if (_active && *_active) { if (_active && *_active) {
auto emitClickHandlerActiveChanged = (!_pressed || !*_pressed || *_pressed == *_active); const auto emitClickHandlerActiveChanged = false
auto wasactive = *_active; || !_pressed
(*_active).clear(); || !*_pressed
|| (*_pressed == *_active);
const auto wasactive = base::take(*_active);
if (_activeHost) { if (_activeHost) {
if (emitClickHandlerActiveChanged) { if (emitClickHandlerActiveChanged) {
_activeHost->clickHandlerActiveChanged(wasactive, false); _activeHost->clickHandlerActiveChanged(wasactive, false);

View File

@ -21,7 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#pragma once #pragma once
class ClickHandler; class ClickHandler;
using ClickHandlerPtr = QSharedPointer<ClickHandler>; using ClickHandlerPtr = std::shared_ptr<ClickHandler>;
enum ExpandLinksMode { enum ExpandLinksMode {
ExpandLinksNone, ExpandLinksNone,
@ -103,9 +103,8 @@ public:
// The activated click handler (if any) is returned. // The activated click handler (if any) is returned.
static ClickHandlerPtr unpressed() { static ClickHandlerPtr unpressed() {
if (_pressed && *_pressed) { if (_pressed && *_pressed) {
bool activated = (_active && *_active == *_pressed); const auto activated = (_active && *_active == *_pressed);
ClickHandlerPtr waspressed = *_pressed; const auto waspressed = base::take(*_pressed);
(*_pressed).clear();
if (_pressedHost) { if (_pressedHost) {
_pressedHost->clickHandlerPressedChanged(waspressed, false); _pressedHost->clickHandlerPressedChanged(waspressed, false);
_pressedHost = nullptr; _pressedHost = nullptr;
@ -144,11 +143,15 @@ public:
} }
static void hostDestroyed(ClickHandlerHost *host) { static void hostDestroyed(ClickHandlerHost *host) {
if (_activeHost == host) { if (_activeHost == host) {
if (_active) (*_active).clear(); if (_active) {
*_active = nullptr;
}
_activeHost = nullptr; _activeHost = nullptr;
} }
if (_pressedHost == host) { if (_pressedHost == host) {
if (_pressed) (*_pressed).clear(); if (_pressed) {
*_pressed = nullptr;
}
_pressedHost = nullptr; _pressedHost = nullptr;
} }
} }

View File

@ -97,14 +97,16 @@ private:
QString _originalUrl, _readable; QString _originalUrl, _readable;
}; };
typedef QSharedPointer<TextClickHandler> TextClickHandlerPtr; using TextClickHandlerPtr = std::shared_ptr<TextClickHandler>;
class HiddenUrlClickHandler : public UrlClickHandler { class HiddenUrlClickHandler : public UrlClickHandler {
public: public:
HiddenUrlClickHandler(QString url) : UrlClickHandler(url, false) { HiddenUrlClickHandler(QString url) : UrlClickHandler(url, false) {
} }
QString copyToClipboardContextItemText() const override { QString copyToClipboardContextItemText() const override {
return url().isEmpty() ? QString() : UrlClickHandler::copyToClipboardContextItemText(); return url().isEmpty()
? QString()
: UrlClickHandler::copyToClipboardContextItemText();
} }
static void doOpen(QString url); static void doOpen(QString url);

View File

@ -545,11 +545,6 @@ static int32 QuarterArcLength = (FullArcLength / 4);
static int32 MinArcLength = (FullArcLength / 360); static int32 MinArcLength = (FullArcLength / 360);
static int32 AlmostFullArcLength = (FullArcLength - MinArcLength); static int32 AlmostFullArcLength = (FullArcLength - MinArcLength);
template <typename T, typename... Args>
inline QSharedPointer<T> MakeShared(Args&&... args) {
return QSharedPointer<T>(new T(std::forward<Args>(args)...));
}
// This pointer is used for global non-POD variables that are allocated // This pointer is used for global non-POD variables that are allocated
// on demand by createIfNull(lambda) and are never automatically freed. // on demand by createIfNull(lambda) and are never automatically freed.
template <typename T> template <typename T>

View File

@ -164,7 +164,7 @@ void PeerData::refreshEmptyUserpic() const {
} }
ClickHandlerPtr PeerData::createOpenLink() { ClickHandlerPtr PeerData::createOpenLink() {
return MakeShared<PeerClickHandler>(this); return std::make_shared<PeerClickHandler>(this);
} }
void PeerData::setUserpic( void PeerData::setUserpic(

View File

@ -821,9 +821,9 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
_contextMenuLink = ClickHandler::getActive(); _contextMenuLink = ClickHandler::getActive();
auto item = App::hoveredItem() ? App::hoveredItem() : App::hoveredLinkItem(); auto item = App::hoveredItem() ? App::hoveredItem() : App::hoveredLinkItem();
auto lnkPhoto = dynamic_cast<PhotoClickHandler*>(_contextMenuLink.data()); auto lnkPhoto = dynamic_cast<PhotoClickHandler*>(_contextMenuLink.get());
auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.data()); auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.get());
auto lnkPeer = dynamic_cast<PeerClickHandler*>(_contextMenuLink.data()); auto lnkPeer = dynamic_cast<PeerClickHandler*>(_contextMenuLink.get());
auto lnkIsVideo = lnkDocument ? lnkDocument->document()->isVideoFile() : false; auto lnkIsVideo = lnkDocument ? lnkDocument->document()->isVideoFile() : false;
auto lnkIsVoice = lnkDocument ? lnkDocument->document()->isVoiceMessage() : false; auto lnkIsVoice = lnkDocument ? lnkDocument->document()->isVoiceMessage() : false;
auto lnkIsAudio = lnkDocument ? lnkDocument->document()->isAudioFile() : false; auto lnkIsAudio = lnkDocument ? lnkDocument->document()->isAudioFile() : false;
@ -979,7 +979,7 @@ void InnerWidget::showStickerPackInfo() {
} }
void InnerWidget::cancelContextDownload() { void InnerWidget::cancelContextDownload() {
if (auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.data())) { if (auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.get())) {
lnkDocument->document()->cancel(); lnkDocument->document()->cancel();
} else if (auto item = App::contextItem()) { } else if (auto item = App::contextItem()) {
if (auto media = item->getMedia()) { if (auto media = item->getMedia()) {
@ -992,7 +992,7 @@ void InnerWidget::cancelContextDownload() {
void InnerWidget::showContextInFolder() { void InnerWidget::showContextInFolder() {
QString filepath; QString filepath;
if (auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.data())) { if (auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.get())) {
filepath = lnkDocument->document()->filepath(DocumentData::FilePathResolveChecked); filepath = lnkDocument->document()->filepath(DocumentData::FilePathResolveChecked);
} else if (auto item = App::contextItem()) { } else if (auto item = App::contextItem()) {
if (auto media = item->getMedia()) { if (auto media = item->getMedia()) {
@ -1240,9 +1240,9 @@ void InnerWidget::mouseActionCancel() {
void InnerWidget::mouseActionFinish(const QPoint &screenPos, Qt::MouseButton button) { void InnerWidget::mouseActionFinish(const QPoint &screenPos, Qt::MouseButton button) {
mouseActionUpdate(screenPos); mouseActionUpdate(screenPos);
ClickHandlerPtr activated = ClickHandler::unpressed(); auto activated = ClickHandler::unpressed();
if (_mouseAction == MouseAction::Dragging) { if (_mouseAction == MouseAction::Dragging) {
activated.clear(); activated = nullptr;
} }
if (App::pressedItem()) { if (App::pressedItem()) {
repaintItem(App::pressedItem()); repaintItem(App::pressedItem());

View File

@ -488,7 +488,7 @@ void GenerateItems(not_null<History*> history, LocalIdManager &idManager, const
fromLinkText, fromLinkText,
lt_sticker_set, lt_sticker_set,
textcmdLink(2, lang(lng_admin_log_changed_stickers_set))); textcmdLink(2, lang(lng_admin_log_changed_stickers_set)));
auto setLink = MakeShared<LambdaClickHandler>([set] { auto setLink = std::make_shared<LambdaClickHandler>([set] {
Ui::show(Box<StickerSetBox>(set)); Ui::show(Box<StickerSetBox>(set));
}); });
auto message = HistoryService::PreparedText { text }; auto message = HistoryService::PreparedText { text };

View File

@ -1031,7 +1031,7 @@ void HistoryInner::performDrag() {
} }
auto pressedHandler = ClickHandler::getPressed(); auto pressedHandler = ClickHandler::getPressed();
if (dynamic_cast<VoiceSeekClickHandler*>(pressedHandler.data())) { if (dynamic_cast<VoiceSeekClickHandler*>(pressedHandler.get())) {
return; return;
} }
@ -1127,14 +1127,14 @@ void HistoryInner::mouseActionFinish(const QPoint &screenPos, Qt::MouseButton bu
auto activated = ClickHandler::unpressed(); auto activated = ClickHandler::unpressed();
if (_mouseAction == MouseAction::Dragging) { if (_mouseAction == MouseAction::Dragging) {
activated.clear(); activated = nullptr;
} else if (_mouseActionItem) { } else if (_mouseActionItem) {
// if we are in selecting items mode perhaps we want to // if we are in selecting items mode perhaps we want to
// toggle selection instead of activating the pressed link // toggle selection instead of activating the pressed link
if (_mouseAction == MouseAction::PrepareDrag && !_pressWasInactive && !_selected.empty() && _selected.cbegin()->second == FullSelection && button != Qt::RightButton) { if (_mouseAction == MouseAction::PrepareDrag && !_pressWasInactive && !_selected.empty() && _selected.cbegin()->second == FullSelection && button != Qt::RightButton) {
if (auto media = _mouseActionItem->getMedia()) { if (auto media = _mouseActionItem->getMedia()) {
if (media->toggleSelectionByHandlerClick(activated)) { if (media->toggleSelectionByHandlerClick(activated)) {
activated.clear(); activated = nullptr;
} }
} }
} }
@ -1291,8 +1291,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
_menu = new Ui::PopupMenu(nullptr); _menu = new Ui::PopupMenu(nullptr);
_contextMenuLink = ClickHandler::getActive(); _contextMenuLink = ClickHandler::getActive();
auto lnkPhoto = dynamic_cast<PhotoClickHandler*>(_contextMenuLink.data()); auto lnkPhoto = dynamic_cast<PhotoClickHandler*>(_contextMenuLink.get());
auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.data()); auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.get());
auto lnkIsVideo = lnkDocument ? lnkDocument->document()->isVideoFile() : false; auto lnkIsVideo = lnkDocument ? lnkDocument->document()->isVideoFile() : false;
auto lnkIsVoice = lnkDocument ? lnkDocument->document()->isVoiceMessage() : false; auto lnkIsVoice = lnkDocument ? lnkDocument->document()->isVoiceMessage() : false;
auto lnkIsAudio = lnkDocument ? lnkDocument->document()->isAudioFile() : false; auto lnkIsAudio = lnkDocument ? lnkDocument->document()->isAudioFile() : false;
@ -1594,7 +1594,7 @@ void HistoryInner::toggleFavedSticker(DocumentData *document) {
} }
void HistoryInner::cancelContextDownload() { void HistoryInner::cancelContextDownload() {
if (auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.data())) { if (auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.get())) {
lnkDocument->document()->cancel(); lnkDocument->document()->cancel();
} else if (auto item = App::contextItem()) { } else if (auto item = App::contextItem()) {
if (auto media = item->getMedia()) { if (auto media = item->getMedia()) {
@ -1607,7 +1607,7 @@ void HistoryInner::cancelContextDownload() {
void HistoryInner::showContextInFolder() { void HistoryInner::showContextInFolder() {
QString filepath; QString filepath;
if (auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.data())) { if (auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.get())) {
filepath = lnkDocument->document()->filepath(DocumentData::FilePathResolveChecked); filepath = lnkDocument->document()->filepath(DocumentData::FilePathResolveChecked);
} else if (auto item = App::contextItem()) { } else if (auto item = App::contextItem()) {
if (auto media = item->getMedia()) { if (auto media = item->getMedia()) {
@ -2286,9 +2286,9 @@ void HistoryInner::onUpdateSelected() {
if (point.x() >= dateLeft && point.x() < dateLeft + dateWidth) { if (point.x() >= dateLeft && point.x() < dateLeft + dateWidth) {
if (!_scrollDateLink) { if (!_scrollDateLink) {
_scrollDateLink = MakeShared<DateClickHandler>(item->history()->peer, item->date.date()); _scrollDateLink = std::make_shared<DateClickHandler>(item->history()->peer, item->date.date());
} else { } else {
static_cast<DateClickHandler*>(_scrollDateLink.data())->setDate(item->date.date()); static_cast<DateClickHandler*>(_scrollDateLink.get())->setDate(item->date.date());
} }
dragState = HistoryTextState( dragState = HistoryTextState(
nullptr, nullptr,

View File

@ -142,7 +142,7 @@ ReplyKeyboard::ReplyKeyboard(const HistoryItem *item, StylePtr &&s)
auto &button = newRow[j]; auto &button = newRow[j];
auto str = row.at(j).text; auto str = row.at(j).text;
button.type = row.at(j).type; button.type = row.at(j).type;
button.link = MakeShared<ReplyMarkupClickHandler>(item, i, j); button.link = std::make_shared<ReplyMarkupClickHandler>(item, i, j);
button.text.setText(_st->textStyle(), TextUtilities::SingleLine(str), _textPlainOptions); button.text.setText(_st->textStyle(), TextUtilities::SingleLine(str), _textPlainOptions);
button.characters = str.isEmpty() ? 1 : str.size(); button.characters = str.isEmpty() ? 1 : str.size();
} }
@ -324,7 +324,7 @@ void ReplyKeyboard::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pr
if (pressed) { if (pressed) {
if (!button.ripple) { if (!button.ripple) {
auto mask = Ui::RippleAnimation::roundRectMask(button.rect.size(), _st->buttonRadius()); auto mask = Ui::RippleAnimation::roundRectMask(button.rect.size(), _st->buttonRadius());
button.ripple = MakeShared<Ui::RippleAnimation>(_st->_st->ripple, std::move(mask), [this] { _st->repaint(_item); }); button.ripple = std::make_shared<Ui::RippleAnimation>(_st->_st->ripple, std::move(mask), [this] { _st->repaint(_item); });
} }
button.ripple->add(_savedCoords - button.rect.topLeft()); button.ripple->add(_savedCoords - button.rect.topLeft());
} else { } else {
@ -1424,7 +1424,7 @@ HistoryItem::~HistoryItem() {
} }
ClickHandlerPtr goToMessageClickHandler(PeerData *peer, MsgId msgId) { ClickHandlerPtr goToMessageClickHandler(PeerData *peer, MsgId msgId) {
return MakeShared<LambdaClickHandler>([peer, msgId] { return std::make_shared<LambdaClickHandler>([peer, msgId] {
if (App::main()) { if (App::main()) {
auto current = App::mousedItem(); auto current = App::mousedItem();
if (current && current->history()->peer == peer) { if (current && current->history()->peer == peer) {

View File

@ -372,7 +372,7 @@ private:
void startAnimation(int i, int j, int direction); void startAnimation(int i, int j, int direction);
friend class Style; friend class Style;
using ReplyMarkupClickHandlerPtr = QSharedPointer<ReplyMarkupClickHandler>; using ReplyMarkupClickHandlerPtr = std::shared_ptr<ReplyMarkupClickHandler>;
struct Button { struct Button {
Text text = { 1 }; Text text = { 1 };
QRect rect; QRect rect;
@ -380,7 +380,7 @@ private:
float64 howMuchOver = 0.; float64 howMuchOver = 0.;
HistoryMessageReplyMarkup::Button::Type type; HistoryMessageReplyMarkup::Button::Type type;
ReplyMarkupClickHandlerPtr link; ReplyMarkupClickHandlerPtr link;
mutable QSharedPointer<Ui::RippleAnimation> ripple; mutable std::shared_ptr<Ui::RippleAnimation> ripple;
}; };
using ButtonRow = QVector<Button>; using ButtonRow = QVector<Button>;
using ButtonRows = QVector<ButtonRow>; using ButtonRows = QVector<ButtonRow>;

View File

@ -274,9 +274,9 @@ HistoryPhoto::HistoryPhoto(
, _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) { , _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) {
const auto fullId = parent->fullId(); const auto fullId = parent->fullId();
setLinks( setLinks(
MakeShared<PhotoOpenClickHandler>(_data, fullId), std::make_shared<PhotoOpenClickHandler>(_data, fullId),
MakeShared<PhotoSaveClickHandler>(_data, fullId), std::make_shared<PhotoSaveClickHandler>(_data, fullId),
MakeShared<PhotoCancelClickHandler>(_data, fullId)); std::make_shared<PhotoCancelClickHandler>(_data, fullId));
if (!caption.isEmpty()) { if (!caption.isEmpty()) {
_caption.setText( _caption.setText(
st::messageTextStyle, st::messageTextStyle,
@ -295,9 +295,9 @@ HistoryPhoto::HistoryPhoto(
, _data(photo) { , _data(photo) {
const auto fullId = parent->fullId(); const auto fullId = parent->fullId();
setLinks( setLinks(
MakeShared<PhotoOpenClickHandler>(_data, fullId, chat), std::make_shared<PhotoOpenClickHandler>(_data, fullId, chat),
MakeShared<PhotoSaveClickHandler>(_data, fullId, chat), std::make_shared<PhotoSaveClickHandler>(_data, fullId, chat),
MakeShared<PhotoCancelClickHandler>(_data, fullId, chat)); std::make_shared<PhotoCancelClickHandler>(_data, fullId, chat));
_width = width; _width = width;
init(); init();
@ -322,9 +322,9 @@ HistoryPhoto::HistoryPhoto(
, _caption(other._caption) { , _caption(other._caption) {
const auto fullId = realParent->fullId(); const auto fullId = realParent->fullId();
setLinks( setLinks(
MakeShared<PhotoOpenClickHandler>(_data, fullId), std::make_shared<PhotoOpenClickHandler>(_data, fullId),
MakeShared<PhotoSaveClickHandler>(_data, fullId), std::make_shared<PhotoSaveClickHandler>(_data, fullId),
MakeShared<PhotoCancelClickHandler>(_data, fullId)); std::make_shared<PhotoCancelClickHandler>(_data, fullId));
init(); init();
} }
@ -1497,11 +1497,11 @@ void HistoryDocument::createComponents(bool caption) {
} }
UpdateComponents(mask); UpdateComponents(mask);
if (auto thumbed = Get<HistoryDocumentThumbed>()) { if (auto thumbed = Get<HistoryDocumentThumbed>()) {
thumbed->_linksavel = MakeShared<DocumentSaveClickHandler>(_data); thumbed->_linksavel = std::make_shared<DocumentSaveClickHandler>(_data);
thumbed->_linkcancell = MakeShared<DocumentCancelClickHandler>(_data); thumbed->_linkcancell = std::make_shared<DocumentCancelClickHandler>(_data);
} }
if (auto voice = Get<HistoryDocumentVoice>()) { if (auto voice = Get<HistoryDocumentVoice>()) {
voice->_seekl = MakeShared<VoiceSeekClickHandler>(_data); voice->_seekl = std::make_shared<VoiceSeekClickHandler>(_data);
} }
} }
@ -2216,7 +2216,7 @@ void HistoryGif::initDimensions() {
_caption.setSkipBlock(_parent->skipBlockWidth(), _parent->skipBlockHeight()); _caption.setSkipBlock(_parent->skipBlockWidth(), _parent->skipBlockHeight());
} }
if (!_openInMediaviewLink) { if (!_openInMediaviewLink) {
_openInMediaviewLink = MakeShared<DocumentOpenClickHandler>(_data); _openInMediaviewLink = std::make_shared<DocumentOpenClickHandler>(_data);
} }
bool bubble = _parent->hasBubble(); bool bubble = _parent->hasBubble();
@ -3040,7 +3040,7 @@ void HistorySticker::initDimensions() {
auto sticker = _data->sticker(); auto sticker = _data->sticker();
if (!_packLink && sticker && sticker->set.type() != mtpc_inputStickerSetEmpty) { if (!_packLink && sticker && sticker->set.type() != mtpc_inputStickerSetEmpty) {
_packLink = MakeShared<LambdaClickHandler>([document = _data] { _packLink = std::make_shared<LambdaClickHandler>([document = _data] {
if (auto sticker = document->sticker()) { if (auto sticker = document->sticker()) {
if (sticker->set.type() != mtpc_inputStickerSetEmpty && App::main()) { if (sticker->set.type() != mtpc_inputStickerSetEmpty && App::main()) {
App::main()->stickersBox(sticker->set); App::main()->stickersBox(sticker->set);
@ -3302,7 +3302,7 @@ int HistorySticker::additionalWidth(const HistoryMessageVia *via, const HistoryM
namespace { namespace {
ClickHandlerPtr sendMessageClickHandler(PeerData *peer) { ClickHandlerPtr sendMessageClickHandler(PeerData *peer) {
return MakeShared<LambdaClickHandler>([peer] { return std::make_shared<LambdaClickHandler>([peer] {
App::wnd()->controller()->showPeerHistory( App::wnd()->controller()->showPeerHistory(
peer->id, peer->id,
Window::SectionShow::Way::Forward); Window::SectionShow::Way::Forward);
@ -3310,7 +3310,7 @@ ClickHandlerPtr sendMessageClickHandler(PeerData *peer) {
} }
ClickHandlerPtr addContactClickHandler(HistoryItem *item) { ClickHandlerPtr addContactClickHandler(HistoryItem *item) {
return MakeShared<LambdaClickHandler>([fullId = item->fullId()] { return std::make_shared<LambdaClickHandler>([fullId = item->fullId()] {
if (auto item = App::histItemById(fullId)) { if (auto item = App::histItemById(fullId)) {
if (auto media = item->getMedia()) { if (auto media = item->getMedia()) {
if (media->type() == MediaTypeContact) { if (media->type() == MediaTypeContact) {
@ -3535,7 +3535,7 @@ HistoryCall::FinishReason HistoryCall::GetReason(const MTPDmessageActionPhoneCal
void HistoryCall::initDimensions() { void HistoryCall::initDimensions() {
_maxw = st::msgFileMinWidth; _maxw = st::msgFileMinWidth;
_link = MakeShared<LambdaClickHandler>([peer = _parent->history()->peer] { _link = std::make_shared<LambdaClickHandler>([peer = _parent->history()->peer] {
if (auto user = peer->asUser()) { if (auto user = peer->asUser()) {
Calls::Current().startOutgoingCall(user); Calls::Current().startOutgoingCall(user);
} }
@ -3674,7 +3674,7 @@ void HistoryWebPage::initDimensions() {
auto lineHeight = unitedLineHeight(); auto lineHeight = unitedLineHeight();
if (!_openl && !_data->url.isEmpty()) { if (!_openl && !_data->url.isEmpty()) {
_openl = MakeShared<UrlClickHandler>(_data->url, true); _openl = std::make_shared<UrlClickHandler>(_data->url, true);
} }
// init layout // init layout
@ -4238,7 +4238,7 @@ void HistoryGame::initDimensions() {
auto lineHeight = unitedLineHeight(); auto lineHeight = unitedLineHeight();
if (!_openl && _parent->id > 0) { if (!_openl && _parent->id > 0) {
_openl = MakeShared<ReplyMarkupClickHandler>(_parent, 0, 0); _openl = std::make_shared<ReplyMarkupClickHandler>(_parent, 0, 0);
} }
auto title = TextUtilities::SingleLine(_data->title); auto title = TextUtilities::SingleLine(_data->title);
@ -4320,7 +4320,7 @@ void HistoryGame::initDimensions() {
void HistoryGame::updateMessageId() { void HistoryGame::updateMessageId() {
if (_openl) { if (_openl) {
_openl = MakeShared<ReplyMarkupClickHandler>(_parent, 0, 0); _openl = std::make_shared<ReplyMarkupClickHandler>(_parent, 0, 0);
} }
} }
@ -5027,7 +5027,7 @@ HistoryLocation::HistoryLocation(not_null<HistoryItem*> parent, const LocationCo
, _data(App::location(coords)) , _data(App::location(coords))
, _title(st::msgMinWidth) , _title(st::msgMinWidth)
, _description(st::msgMinWidth) , _description(st::msgMinWidth)
, _link(MakeShared<LocationClickHandler>(coords)) { , _link(std::make_shared<LocationClickHandler>(coords)) {
if (!title.isEmpty()) { if (!title.isEmpty()) {
_title.setText(st::webPageTitleStyle, TextUtilities::Clean(title), _webpageTitleOptions); _title.setText(st::webPageTitleStyle, TextUtilities::Clean(title), _webpageTitleOptions);
} }
@ -5043,7 +5043,7 @@ HistoryLocation::HistoryLocation(not_null<HistoryItem*> parent, const HistoryLoc
, _data(other._data) , _data(other._data)
, _title(other._title) , _title(other._title)
, _description(other._description) , _description(other._description)
, _link(MakeShared<LocationClickHandler>(_data->coords)) { , _link(std::make_shared<LocationClickHandler>(_data->coords)) {
} }
void HistoryLocation::initDimensions() { void HistoryLocation::initDimensions() {

View File

@ -79,21 +79,21 @@ protected:
ClickHandlerPtr open, save; ClickHandlerPtr open, save;
const auto context = realParent->fullId(); const auto context = realParent->fullId();
if (inlinegif) { if (inlinegif) {
open = MakeShared<GifOpenClickHandler>(document, context); open = std::make_shared<GifOpenClickHandler>(document, context);
} else { } else {
open = MakeShared<DocumentOpenClickHandler>(document, context); open = std::make_shared<DocumentOpenClickHandler>(document, context);
} }
if (inlinegif) { if (inlinegif) {
save = MakeShared<GifOpenClickHandler>(document, context); save = std::make_shared<GifOpenClickHandler>(document, context);
} else if (document->isVoiceMessage()) { } else if (document->isVoiceMessage()) {
save = MakeShared<DocumentOpenClickHandler>(document, context); save = std::make_shared<DocumentOpenClickHandler>(document, context);
} else { } else {
save = MakeShared<DocumentSaveClickHandler>(document, context); save = std::make_shared<DocumentSaveClickHandler>(document, context);
} }
setLinks( setLinks(
std::move(open), std::move(open),
std::move(save), std::move(save),
MakeShared<DocumentCancelClickHandler>(document, context)); std::make_shared<DocumentCancelClickHandler>(document, context));
} }
// >= 0 will contain download / upload string, _statusSize = loaded bytes // >= 0 will contain download / upload string, _statusSize = loaded bytes
@ -428,7 +428,7 @@ public:
void checkPlaybackFinished() const; void checkPlaybackFinished() const;
mutable std::unique_ptr<HistoryDocumentVoicePlayback> _playback; mutable std::unique_ptr<HistoryDocumentVoicePlayback> _playback;
QSharedPointer<VoiceSeekClickHandler> _seekl; std::shared_ptr<VoiceSeekClickHandler> _seekl;
mutable int _lastDurationMs = 0; mutable int _lastDurationMs = 0;
bool seeking() const { bool seeking() const {

View File

@ -190,7 +190,7 @@ void FastShareMessage(not_null<HistoryItem*> item) {
MessageIdsList msgIds; MessageIdsList msgIds;
base::flat_set<mtpRequestId> requests; base::flat_set<mtpRequestId> requests;
}; };
const auto data = MakeShared<ShareData>(item->history()->peer, [&] { const auto data = std::make_shared<ShareData>(item->history()->peer, [&] {
if (const auto group = item->getFullGroup()) { if (const auto group = item->getFullGroup()) {
return Auth().data().groupToIds(group); return Auth().data().groupToIds(group);
} }
@ -362,7 +362,7 @@ QString GetErrorTextForForward(
void HistoryMessageVia::create(UserId userId) { void HistoryMessageVia::create(UserId userId) {
_bot = App::user(peerFromUser(userId)); _bot = App::user(peerFromUser(userId));
_maxWidth = st::msgServiceNameFont->width(lng_inline_bot_via(lt_inline_bot, '@' + _bot->username)); _maxWidth = st::msgServiceNameFont->width(lng_inline_bot_via(lt_inline_bot, '@' + _bot->username));
_lnk = MakeShared<LambdaClickHandler>([bot = _bot] { _lnk = std::make_shared<LambdaClickHandler>([bot = _bot] {
App::insertBotCommand('@' + bot->username); App::insertBotCommand('@' + bot->username);
}); });
} }
@ -2401,7 +2401,7 @@ ClickHandlerPtr HistoryMessage::rightActionLink() const {
const auto forwarded = Get<HistoryMessageForwarded>(); const auto forwarded = Get<HistoryMessageForwarded>();
const auto savedFromPeer = forwarded ? forwarded->_savedFromPeer : nullptr; const auto savedFromPeer = forwarded ? forwarded->_savedFromPeer : nullptr;
const auto savedFromMsgId = forwarded ? forwarded->_savedFromMsgId : 0; const auto savedFromMsgId = forwarded ? forwarded->_savedFromMsgId : 0;
_rightActionLink = MakeShared<LambdaClickHandler>([=] { _rightActionLink = std::make_shared<LambdaClickHandler>([=] {
if (auto item = App::histItemById(itemId)) { if (auto item = App::histItemById(itemId)) {
if (savedFromPeer && savedFromMsgId) { if (savedFromPeer && savedFromMsgId) {
App::wnd()->controller()->showPeerHistory( App::wnd()->controller()->showPeerHistory(

View File

@ -359,7 +359,7 @@ HistoryService::PreparedText HistoryService::prepareGameScoreText() {
if (gamescore && gamescore->msg) { if (gamescore && gamescore->msg) {
if (auto media = gamescore->msg->getMedia()) { if (auto media = gamescore->msg->getMedia()) {
if (media->type() == MediaTypeGame) { if (media->type() == MediaTypeGame) {
result.links.push_back(MakeShared<ReplyMarkupClickHandler>(gamescore->msg, 0, 0)); result.links.push_back(std::make_shared<ReplyMarkupClickHandler>(gamescore->msg, 0, 0));
auto titleText = static_cast<HistoryGame*>(media)->game()->title; auto titleText = static_cast<HistoryGame*>(media)->game()->title;
return textcmdLink(result.links.size(), titleText); return textcmdLink(result.links.size(), titleText);
} }

View File

@ -1294,7 +1294,7 @@ void HistoryWidget::onRecordDone(QByteArray result, VoiceWaveform waveform, qint
auto duration = samples / Media::Player::kDefaultFrequency; auto duration = samples / Media::Player::kDefaultFrequency;
auto to = FileLoadTo(_peer->id, _peer->notifySilentPosts(), replyToId()); auto to = FileLoadTo(_peer->id, _peer->notifySilentPosts(), replyToId());
auto caption = QString(); auto caption = QString();
_fileLoader.addTask(MakeShared<FileLoadTask>(result, duration, waveform, to, caption)); _fileLoader.addTask(std::make_shared<FileLoadTask>(result, duration, waveform, to, caption));
} }
void HistoryWidget::onRecordUpdate(quint16 level, qint32 samples) { void HistoryWidget::onRecordUpdate(quint16 level, qint32 samples) {
@ -4215,9 +4215,9 @@ void HistoryWidget::uploadFilesAfterConfirmation(
tasks.reserve(files.size()); tasks.reserve(files.size());
for_const (auto &filepath, files) { for_const (auto &filepath, files) {
if (filepath.isEmpty() && (!image.isNull() || !content.isNull())) { if (filepath.isEmpty() && (!image.isNull() || !content.isNull())) {
tasks.push_back(MakeShared<FileLoadTask>(content, image, type, to, caption)); tasks.push_back(std::make_shared<FileLoadTask>(content, image, type, to, caption));
} else { } else {
tasks.push_back(MakeShared<FileLoadTask>(filepath, std::move(information), type, to, caption)); tasks.push_back(std::make_shared<FileLoadTask>(filepath, std::move(information), type, to, caption));
} }
} }
_fileLoader.addTasks(tasks); _fileLoader.addTasks(tasks);
@ -4228,7 +4228,7 @@ void HistoryWidget::uploadFile(const QByteArray &fileContent, SendMediaType type
auto to = FileLoadTo(_peer->id, _peer->notifySilentPosts(), replyToId()); auto to = FileLoadTo(_peer->id, _peer->notifySilentPosts(), replyToId());
auto caption = QString(); auto caption = QString();
_fileLoader.addTask(MakeShared<FileLoadTask>(fileContent, QImage(), type, to, caption)); _fileLoader.addTask(std::make_shared<FileLoadTask>(fileContent, QImage(), type, to, caption));
} }
void HistoryWidget::sendFileConfirmed(const FileLoadResultPtr &file) { void HistoryWidget::sendFileConfirmed(const FileLoadResultPtr &file) {

View File

@ -1233,8 +1233,8 @@ void ListWidget::showContextMenu(
} }
}); });
auto photoLink = dynamic_cast<PhotoClickHandler*>(link.data()); auto photoLink = dynamic_cast<PhotoClickHandler*>(link.get());
auto fileLink = dynamic_cast<DocumentClickHandler*>(link.data()); auto fileLink = dynamic_cast<DocumentClickHandler*>(link.get());
if (photoLink || fileLink) { if (photoLink || fileLink) {
auto [isVideo, isVoice, isAudio] = [&] { auto [isVideo, isVoice, isAudio] = [&] {
if (fileLink) { if (fileLink) {
@ -1894,7 +1894,7 @@ void ListWidget::performDrag() {
} }
auto pressedHandler = ClickHandler::getPressed(); auto pressedHandler = ClickHandler::getPressed();
if (dynamic_cast<VoiceSeekClickHandler*>(pressedHandler.data())) { if (dynamic_cast<VoiceSeekClickHandler*>(pressedHandler.get())) {
return; return;
} }
@ -1976,9 +1976,9 @@ void ListWidget::mouseActionFinish(const QPoint &screenPos, Qt::MouseButton butt
auto activated = ClickHandler::unpressed(); auto activated = ClickHandler::unpressed();
if (_mouseAction == MouseAction::Dragging if (_mouseAction == MouseAction::Dragging
|| _mouseAction == MouseAction::Selecting) { || _mouseAction == MouseAction::Selecting) {
activated.clear(); activated = nullptr;
} else if (needSelectionToggle) { } else if (needSelectionToggle) {
activated.clear(); activated = nullptr;
} }
_wasSelectedText = false; _wasSelectedText = false;

View File

@ -390,7 +390,7 @@ void Cover::refreshStatusText() {
}(); }();
_status->setRichText(statusText); _status->setRichText(statusText);
if (hasMembersLink) { if (hasMembersLink) {
_status->setLink(1, MakeShared<LambdaClickHandler>([=] { _status->setLink(1, std::make_shared<LambdaClickHandler>([=] {
_controller->showSection(Info::Memento( _controller->showSection(Info::Memento(
_controller->peerId(), _controller->peerId(),
Section::Type::Members)); Section::Type::Members));

View File

@ -101,7 +101,7 @@ Gif::Gif(not_null<Context*> context, Result *result) : FileBase(context, result)
Gif::Gif(not_null<Context*> context, DocumentData *document, bool hasDeleteButton) : FileBase(context, document) { Gif::Gif(not_null<Context*> context, DocumentData *document, bool hasDeleteButton) : FileBase(context, document) {
if (hasDeleteButton) { if (hasDeleteButton) {
_delete = MakeShared<DeleteSavedGifClickHandler>(document); _delete = std::make_shared<DeleteSavedGifClickHandler>(document);
} }
} }
@ -688,8 +688,8 @@ void CancelFileClickHandler::onClickImpl() const {
File::File(not_null<Context*> context, Result *result) : FileBase(context, result) File::File(not_null<Context*> context, Result *result) : FileBase(context, result)
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::msgFileSize - st::inlineThumbSkip) , _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::msgFileSize - st::inlineThumbSkip)
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::msgFileSize - st::inlineThumbSkip) , _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::msgFileSize - st::inlineThumbSkip)
, _open(MakeShared<OpenFileClickHandler>(result)) , _open(std::make_shared<OpenFileClickHandler>(result))
, _cancel(MakeShared<CancelFileClickHandler>(result)) { , _cancel(std::make_shared<CancelFileClickHandler>(result)) {
updateStatusText(); updateStatusText();
regDocumentItem(getShownDocument(), this); regDocumentItem(getShownDocument(), this);
} }
@ -999,7 +999,7 @@ Article::Article(not_null<Context*> context, Result *result, bool withThumb) : I
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) { , _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
LocationCoords location; LocationCoords location;
if (!_link && result->getLocationCoords(&location)) { if (!_link && result->getLocationCoords(&location)) {
_link = MakeShared<LocationClickHandler>(location); _link = std::make_shared<LocationClickHandler>(location);
} }
_thumbLetter = getResultThumbLetter(); _thumbLetter = getResultThumbLetter();
} }

View File

@ -176,14 +176,14 @@ QString ItemBase::getResultUrl() const {
ClickHandlerPtr ItemBase::getResultUrlHandler() const { ClickHandlerPtr ItemBase::getResultUrlHandler() const {
if (!_result->_url.isEmpty()) { if (!_result->_url.isEmpty()) {
return MakeShared<UrlClickHandler>(_result->_url); return std::make_shared<UrlClickHandler>(_result->_url);
} }
return ClickHandlerPtr(); return ClickHandlerPtr();
} }
ClickHandlerPtr ItemBase::getResultContentUrlHandler() const { ClickHandlerPtr ItemBase::getResultContentUrlHandler() const {
if (!_result->_content_url.isEmpty()) { if (!_result->_content_url.isEmpty()) {
return MakeShared<UrlClickHandler>(_result->_content_url); return std::make_shared<UrlClickHandler>(_result->_content_url);
} }
return ClickHandlerPtr(); return ClickHandlerPtr();
} }

View File

@ -224,7 +224,7 @@ void Inner::mouseReleaseEvent(QMouseEvent *e) {
return; return;
} }
if (dynamic_cast<InlineBots::Layout::SendClickHandler*>(activated.data())) { if (dynamic_cast<InlineBots::Layout::SendClickHandler*>(activated.get())) {
int row = _selected / MatrixRowShift, column = _selected % MatrixRowShift; int row = _selected / MatrixRowShift, column = _selected % MatrixRowShift;
selectInlineResult(row, column); selectInlineResult(row, column);
} else { } else {

View File

@ -125,8 +125,8 @@ void PhoneWidget::showSignup() {
auto signupText = lng_phone_notreg(lt_link_start, textcmdStartLink(1), lt_link_end, textcmdStopLink(), lt_signup_start, textcmdStartLink(2), lt_signup_end, textcmdStopLink()); auto signupText = lng_phone_notreg(lt_link_start, textcmdStartLink(1), lt_link_end, textcmdStopLink(), lt_signup_start, textcmdStartLink(2), lt_signup_end, textcmdStopLink());
auto inner = object_ptr<Ui::FlatLabel>(this, signupText, Ui::FlatLabel::InitType::Rich, st::introDescription); auto inner = object_ptr<Ui::FlatLabel>(this, signupText, Ui::FlatLabel::InitType::Rich, st::introDescription);
_signup.create(this, std::move(inner)); _signup.create(this, std::move(inner));
_signup->entity()->setLink(1, MakeShared<UrlClickHandler>(qsl("https://telegram.org"), false)); _signup->entity()->setLink(1, std::make_shared<UrlClickHandler>(qsl("https://telegram.org"), false));
_signup->entity()->setLink(2, MakeShared<LambdaClickHandler>([this] { _signup->entity()->setLink(2, std::make_shared<LambdaClickHandler>([this] {
toSignUp(); toSignUp();
})); }));
_signup->hide(anim::type::instant); _signup->hide(anim::type::instant);

View File

@ -114,8 +114,7 @@ public:
} }
private: private:
std::shared_ptr<QFile> files[LogDataCount];
QSharedPointer<QFile> files[LogDataCount];
QTextStream streams[LogDataCount]; QTextStream streams[LogDataCount];
int32 part = -1; int32 part = -1;
@ -137,7 +136,7 @@ private:
if (postfix.isEmpty()) { // instance checked, need to move to log.txt if (postfix.isEmpty()) { // instance checked, need to move to log.txt
Assert(!files[type]->fileName().isEmpty()); // one of log_startXX.txt should've been opened already Assert(!files[type]->fileName().isEmpty()); // one of log_startXX.txt should've been opened already
QSharedPointer<QFile> to(new QFile(_logsFilePath(type, postfix))); std::shared_ptr<QFile> to = std::make_shared<QFile>(_logsFilePath(type, postfix));
if (to->exists() && !to->remove()) { if (to->exists() && !to->remove()) {
LOG(("Could not delete '%1' file to start new logging!").arg(to->fileName())); LOG(("Could not delete '%1' file to start new logging!").arg(to->fileName()));
return false; return false;
@ -147,8 +146,8 @@ private:
return false; return false;
} }
if (to->open(mode | QIODevice::Append)) { if (to->open(mode | QIODevice::Append)) {
qSwap(files[type], to); std::swap(files[type], to);
streams[type].setDevice(files[type].data()); streams[type].setDevice(files[type].get());
streams[type].setCodec("UTF-8"); streams[type].setCodec("UTF-8");
LOG(("Moved logging from '%1' to '%2'!").arg(to->fileName()).arg(files[type]->fileName())); LOG(("Moved logging from '%1' to '%2'!").arg(to->fileName()).arg(files[type]->fileName()));
to->remove(); to->remove();
@ -206,11 +205,16 @@ private:
} }
} }
if (files[type]->open(mode)) { if (files[type]->open(mode)) {
streams[type].setDevice(files[type].data()); streams[type].setDevice(files[type].get());
streams[type].setCodec("UTF-8"); streams[type].setCodec("UTF-8");
if (type != LogDataMain) { if (type != LogDataMain) {
streams[type] << ((mode & QIODevice::Append) ? qsl("----------------------------------------------------------------\nNEW LOGGING INSTANCE STARTED!!!\n----------------------------------------------------------------\n") : qsl("%1\n").arg(dayIndex)); streams[type] << ((mode & QIODevice::Append)
? qsl("\
----------------------------------------------------------------\n\
NEW LOGGING INSTANCE STARTED!!!\n\
----------------------------------------------------------------\n")
: qsl("%1\n").arg(dayIndex));
streams[type].flush(); streams[type].flush();
} }

View File

@ -101,7 +101,7 @@ MediaView::MediaView() : TWidget(nullptr)
custom.insert(QChar('c'), qMakePair(textcmdStartLink(1), textcmdStopLink())); custom.insert(QChar('c'), qMakePair(textcmdStartLink(1), textcmdStopLink()));
_saveMsgText.setRichText(st::mediaviewSaveMsgStyle, lang(lng_mediaview_saved), _textDlgOptions, custom); _saveMsgText.setRichText(st::mediaviewSaveMsgStyle, lang(lng_mediaview_saved), _textDlgOptions, custom);
_saveMsg = QRect(0, 0, _saveMsgText.maxWidth() + st::mediaviewSaveMsgPadding.left() + st::mediaviewSaveMsgPadding.right(), st::mediaviewSaveMsgStyle.font->height + st::mediaviewSaveMsgPadding.top() + st::mediaviewSaveMsgPadding.bottom()); _saveMsg = QRect(0, 0, _saveMsgText.maxWidth() + st::mediaviewSaveMsgPadding.left() + st::mediaviewSaveMsgPadding.right(), st::mediaviewSaveMsgStyle.font->height + st::mediaviewSaveMsgPadding.top() + st::mediaviewSaveMsgPadding.bottom());
_saveMsgText.setLink(1, MakeShared<LambdaClickHandler>([this] { showSaveMsgFile(); })); _saveMsgText.setLink(1, std::make_shared<LambdaClickHandler>([this] { showSaveMsgFile(); }));
connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onScreenResized(int))); connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onScreenResized(int)));

View File

@ -75,14 +75,18 @@ void MTPstring::write(mtpBuffer &to) const {
} }
uint32 mtpRequest::innerLength() const { // for template MTP requests and MTPBoxed instanciation uint32 mtpRequest::innerLength() const { // for template MTP requests and MTPBoxed instanciation
mtpRequestData *value = data(); const auto value = get();
if (!value || value->size() < 9) return 0; if (!value || value->size() < 9) {
return 0;
}
return value->at(7); return value->at(7);
} }
void mtpRequest::write(mtpBuffer &to) const { void mtpRequest::write(mtpBuffer &to) const {
mtpRequestData *value = data(); const auto value = get();
if (!value || value->size() < 9) return; if (!value || value->size() < 9) {
return;
}
uint32 was = to.size(), s = innerLength() / sizeof(mtpPrime); uint32 was = to.size(), s = innerLength() / sizeof(mtpPrime);
to.resize(was + s); to.resize(was + s);
memcpy(to.data() + was, value->constData() + 8, s * sizeof(mtpPrime)); memcpy(to.data() + was, value->constData() + 8, s * sizeof(mtpPrime));

View File

@ -41,10 +41,11 @@ using mtpBuffer = QVector<mtpPrime>;
using mtpTypeId = uint32; using mtpTypeId = uint32;
class mtpRequestData; class mtpRequestData;
class mtpRequest : public QSharedPointer<mtpRequestData> { class mtpRequest : public std::shared_ptr<mtpRequestData> {
public: public:
mtpRequest() = default; mtpRequest() = default;
explicit mtpRequest(mtpRequestData *ptr) : QSharedPointer<mtpRequestData>(ptr) { explicit mtpRequest(mtpRequestData *ptr)
: std::shared_ptr<mtpRequestData>(ptr) {
} }
uint32 innerLength() const; uint32 innerLength() const;

View File

@ -87,7 +87,7 @@ public:
} }
}; };
using RPCDoneHandlerPtr = QSharedPointer<RPCAbstractDoneHandler>; using RPCDoneHandlerPtr = std::shared_ptr<RPCAbstractDoneHandler>;
class RPCAbstractFailHandler { // abstract fail class RPCAbstractFailHandler { // abstract fail
public: public:
@ -95,7 +95,7 @@ public:
virtual ~RPCAbstractFailHandler() { virtual ~RPCAbstractFailHandler() {
} }
}; };
using RPCFailHandlerPtr = QSharedPointer<RPCAbstractFailHandler>; using RPCFailHandlerPtr = std::shared_ptr<RPCAbstractFailHandler>;
struct RPCResponseHandler { struct RPCResponseHandler {
RPCResponseHandler() { RPCResponseHandler() {

View File

@ -173,9 +173,9 @@ class Sender {
} }
RPCFailHandlerPtr takeOnFail() { RPCFailHandlerPtr takeOnFail() {
if (auto handler = base::get_if<FailPlainHandler>(&_fail)) { if (auto handler = base::get_if<FailPlainHandler>(&_fail)) {
return MakeShared<FailHandler<FailPlainPolicy>>(_sender, std::move(*handler), _failSkipPolicy); return std::make_shared<FailHandler<FailPlainPolicy>>(_sender, std::move(*handler), _failSkipPolicy);
} else if (auto handler = base::get_if<FailRequestIdHandler>(&_fail)) { } else if (auto handler = base::get_if<FailRequestIdHandler>(&_fail)) {
return MakeShared<FailHandler<FailRequestIdPolicy>>(_sender, std::move(*handler), _failSkipPolicy); return std::make_shared<FailHandler<FailRequestIdPolicy>>(_sender, std::move(*handler), _failSkipPolicy);
} }
return RPCFailHandlerPtr(); return RPCFailHandlerPtr();
} }
@ -223,11 +223,11 @@ public:
return *this; return *this;
} }
[[nodiscard]] SpecificRequestBuilder &done(base::lambda_once<void(const typename Request::ResponseType &result)> callback) { [[nodiscard]] SpecificRequestBuilder &done(base::lambda_once<void(const typename Request::ResponseType &result)> callback) {
setDoneHandler(MakeShared<DoneHandler<typename Request::ResponseType, DonePlainPolicy>>(sender(), std::move(callback))); setDoneHandler(std::make_shared<DoneHandler<typename Request::ResponseType, DonePlainPolicy>>(sender(), std::move(callback)));
return *this; return *this;
} }
[[nodiscard]] SpecificRequestBuilder &done(base::lambda_once<void(const typename Request::ResponseType &result, mtpRequestId requestId)> callback) { [[nodiscard]] SpecificRequestBuilder &done(base::lambda_once<void(const typename Request::ResponseType &result, mtpRequestId requestId)> callback) {
setDoneHandler(MakeShared<DoneHandler<typename Request::ResponseType, DoneRequestIdPolicy>>(sender(), std::move(callback))); setDoneHandler(std::make_shared<DoneHandler<typename Request::ResponseType, DoneRequestIdPolicy>>(sender(), std::move(callback)));
return *this; return *this;
} }
[[nodiscard]] SpecificRequestBuilder &fail(base::lambda_once<void(const RPCError &error)> callback) noexcept { [[nodiscard]] SpecificRequestBuilder &fail(base::lambda_once<void(const RPCError &error)> callback) noexcept {

View File

@ -186,14 +186,14 @@ void RadialProgressItem::setDocumentLinks(
not_null<DocumentData*> document not_null<DocumentData*> document
) -> ClickHandlerPtr { ) -> ClickHandlerPtr {
if (document->isVoiceMessage()) { if (document->isVoiceMessage()) {
return MakeShared<DocumentOpenClickHandler>(document); return std::make_shared<DocumentOpenClickHandler>(document);
} }
return MakeShared<DocumentSaveClickHandler>(document); return std::make_shared<DocumentSaveClickHandler>(document);
}; };
setLinks( setLinks(
MakeShared<DocumentOpenClickHandler>(document), std::make_shared<DocumentOpenClickHandler>(document),
createSaveHandler(document), createSaveHandler(document),
MakeShared<DocumentCancelClickHandler>(document)); std::make_shared<DocumentCancelClickHandler>(document));
} }
void RadialProgressItem::clickHandlerActiveChanged(const ClickHandlerPtr &action, bool active) { void RadialProgressItem::clickHandlerActiveChanged(const ClickHandlerPtr &action, bool active) {
@ -283,7 +283,7 @@ Photo::Photo(
not_null<PhotoData*> photo) not_null<PhotoData*> photo)
: ItemBase(parent) : ItemBase(parent)
, _data(photo) , _data(photo)
, _link(MakeShared<PhotoOpenClickHandler>(photo, parent->fullId())) { , _link(std::make_shared<PhotoOpenClickHandler>(photo, parent->fullId())) {
} }
void Photo::initDimensions() { void Photo::initDimensions() {
@ -549,7 +549,7 @@ Voice::Voice(
const style::OverviewFileLayout &st) const style::OverviewFileLayout &st)
: RadialProgressItem(parent) : RadialProgressItem(parent)
, _data(voice) , _data(voice)
, _namel(MakeShared<DocumentOpenClickHandler>(_data)) , _namel(std::make_shared<DocumentOpenClickHandler>(_data))
, _st(st) { , _st(st) {
AddComponents(Info::Bit()); AddComponents(Info::Bit());
@ -794,7 +794,7 @@ Document::Document(
: RadialProgressItem(parent) : RadialProgressItem(parent)
, _data(document) , _data(document)
, _msgl(goToMessageClickHandler(parent)) , _msgl(goToMessageClickHandler(parent))
, _namel(MakeShared<DocumentOpenClickHandler>(_data)) , _namel(std::make_shared<DocumentOpenClickHandler>(_data))
, _st(st) , _st(st)
, _date(langDateTime(date(_data->date))) , _date(langDateTime(date(_data->date)))
, _datew(st::normalFont->width(_date)) , _datew(st::normalFont->width(_date))
@ -1215,22 +1215,22 @@ Link::Link(
if (_page) { if (_page) {
mainUrl = _page->url; mainUrl = _page->url;
if (_page->document) { if (_page->document) {
_photol = MakeShared<DocumentOpenClickHandler>(_page->document); _photol = std::make_shared<DocumentOpenClickHandler>(_page->document);
} else if (_page->photo) { } else if (_page->photo) {
if (_page->type == WebPageProfile || _page->type == WebPageVideo) { if (_page->type == WebPageProfile || _page->type == WebPageVideo) {
_photol = MakeShared<UrlClickHandler>(_page->url); _photol = std::make_shared<UrlClickHandler>(_page->url);
} else if (_page->type == WebPagePhoto || _page->siteName == qstr("Twitter") || _page->siteName == qstr("Facebook")) { } else if (_page->type == WebPagePhoto || _page->siteName == qstr("Twitter") || _page->siteName == qstr("Facebook")) {
_photol = MakeShared<PhotoOpenClickHandler>( _photol = std::make_shared<PhotoOpenClickHandler>(
_page->photo, _page->photo,
parent->fullId()); parent->fullId());
} else { } else {
_photol = MakeShared<UrlClickHandler>(_page->url); _photol = std::make_shared<UrlClickHandler>(_page->url);
} }
} else { } else {
_photol = MakeShared<UrlClickHandler>(_page->url); _photol = std::make_shared<UrlClickHandler>(_page->url);
} }
} else if (!mainUrl.isEmpty()) { } else if (!mainUrl.isEmpty()) {
_photol = MakeShared<UrlClickHandler>(mainUrl); _photol = std::make_shared<UrlClickHandler>(mainUrl);
} }
if (from >= till && _page) { if (from >= till && _page) {
text = _page->description.text; text = _page->description.text;
@ -1456,7 +1456,7 @@ const style::RoundCheckbox &Link::checkboxStyle() const {
Link::LinkEntry::LinkEntry(const QString &url, const QString &text) Link::LinkEntry::LinkEntry(const QString &url, const QString &text)
: text(text) : text(text)
, width(st::normalFont->width(text)) , width(st::normalFont->width(text))
, lnk(MakeShared<UrlClickHandler>(url)) { , lnk(std::make_shared<UrlClickHandler>(url)) {
} }
} // namespace Layout } // namespace Layout

View File

@ -236,7 +236,7 @@ private:
}; };
using Notification = QSharedPointer<NotificationData>; using Notification = std::shared_ptr<NotificationData>;
QString GetServerName() { QString GetServerName() {
if (!LibNotifyLoaded()) { if (!LibNotifyLoaded()) {
@ -440,7 +440,13 @@ void Manager::Private::showNextNotification() {
auto peerId = data.peer->id; auto peerId = data.peer->id;
auto msgId = data.msgId; auto msgId = data.msgId;
auto notification = MakeShared<NotificationData>(_guarded, data.title, data.body, _capabilities, peerId, msgId); auto notification = std::make_shared<NotificationData>(
_guarded,
data.title,
data.body,
_capabilities,
peerId,
msgId);
if (!notification->valid()) { if (!notification->valid()) {
return; return;
} }

View File

@ -75,7 +75,7 @@ void InfoWidget::refreshMobileNumber() {
lang(lng_profile_copy_phone)); lang(lng_profile_copy_phone));
if (auto text = _mobileNumber->entity()->textLabel()) { if (auto text = _mobileNumber->entity()->textLabel()) {
text->setRichText(textcmdLink(1, phoneText.text)); text->setRichText(textcmdLink(1, phoneText.text));
text->setLink(1, MakeShared<LambdaClickHandler>([] { text->setLink(1, std::make_shared<LambdaClickHandler>([] {
Ui::show(Box<ChangePhoneBox>()); Ui::show(Box<ChangePhoneBox>());
})); }));
} }

View File

@ -117,7 +117,7 @@ private:
HashMd5 md5Hash; HashMd5 md5Hash;
QSharedPointer<QFile> docFile; std::shared_ptr<QFile> docFile;
int32 docSentParts; int32 docSentParts;
int32 docSize; int32 docSize;
int32 docPartSize; int32 docPartSize;

View File

@ -318,7 +318,7 @@ bool FileLoadTask::CheckForImage(const QString &filepath, const QByteArray &cont
void FileLoadTask::process() { void FileLoadTask::process() {
const auto stickerMime = qsl("image/webp"); const auto stickerMime = qsl("image/webp");
_result = MakeShared<FileLoadResult>(_id, _to, _caption); _result = std::make_shared<FileLoadResult>(_id, _to, _caption);
QString filename, filemime; QString filename, filemime;
qint64 filesize = 0; qint64 filesize = 0;

View File

@ -114,7 +114,7 @@ public:
} }
}; };
using TaskPtr = QSharedPointer<Task>; using TaskPtr = std::shared_ptr<Task>;
using TasksList = QList<TaskPtr>; using TasksList = QList<TaskPtr>;
class TaskQueueWorker; class TaskQueueWorker;
@ -235,7 +235,7 @@ struct FileLoadResult {
} }
} }
}; };
typedef QSharedPointer<FileLoadResult> FileLoadResultPtr; using FileLoadResultPtr = std::shared_ptr<FileLoadResult>;
class FileLoadTask final : public Task { class FileLoadTask final : public Task {
public: public:

View File

@ -2854,7 +2854,7 @@ TaskId startImageLoad(const StorageKey &location, mtpFileLoader *loader) {
if (j == _imagesMap.cend() || !_localLoader) { if (j == _imagesMap.cend() || !_localLoader) {
return 0; return 0;
} }
return _localLoader->addTask(MakeShared<ImageLoadTask>(j->first, location, loader)); return _localLoader->addTask(std::make_shared<ImageLoadTask>(j->first, location, loader));
} }
int32 hasImages() { int32 hasImages() {
@ -2912,7 +2912,7 @@ TaskId startStickerImageLoad(const StorageKey &location, mtpFileLoader *loader)
if (j == _stickerImagesMap.cend() || !_localLoader) { if (j == _stickerImagesMap.cend() || !_localLoader) {
return 0; return 0;
} }
return _localLoader->addTask(MakeShared<StickerImageLoadTask>(j->first, location, loader)); return _localLoader->addTask(std::make_shared<StickerImageLoadTask>(j->first, location, loader));
} }
bool willStickerImageLoad(const StorageKey &location) { bool willStickerImageLoad(const StorageKey &location) {
@ -2985,7 +2985,7 @@ TaskId startAudioLoad(const StorageKey &location, mtpFileLoader *loader) {
if (j == _audiosMap.cend() || !_localLoader) { if (j == _audiosMap.cend() || !_localLoader) {
return 0; return 0;
} }
return _localLoader->addTask(MakeShared<AudioLoadTask>(j->first, location, loader)); return _localLoader->addTask(std::make_shared<AudioLoadTask>(j->first, location, loader));
} }
bool copyAudio(const StorageKey &oldLocation, const StorageKey &newLocation) { bool copyAudio(const StorageKey &oldLocation, const StorageKey &newLocation) {
@ -3101,7 +3101,7 @@ TaskId startWebFileLoad(const QString &url, webFileLoader *loader) {
if (j == _webFilesMap.cend() || !_localLoader) { if (j == _webFilesMap.cend() || !_localLoader) {
return 0; return 0;
} }
return _localLoader->addTask(MakeShared<WebFileLoadTask>(j->first, url, loader)); return _localLoader->addTask(std::make_shared<WebFileLoadTask>(j->first, url, loader));
} }
int32 hasWebFiles() { int32 hasWebFiles() {
@ -3177,7 +3177,7 @@ void countVoiceWaveform(DocumentData *document) {
if (_localLoader) { if (_localLoader) {
voice->waveform.resize(1 + sizeof(TaskId)); voice->waveform.resize(1 + sizeof(TaskId));
voice->waveform[0] = -1; // counting voice->waveform[0] = -1; // counting
TaskId taskId = _localLoader->addTask(MakeShared<CountWaveformTask>(document)); TaskId taskId = _localLoader->addTask(std::make_shared<CountWaveformTask>(document));
memcpy(voice->waveform.data() + 1, &taskId, sizeof(taskId)); memcpy(voice->waveform.data() + 1, &taskId, sizeof(taskId));
} }
} }

View File

@ -1257,10 +1257,15 @@ WebFileImage *getImage(const WebFileImageLocation &location, int32 size) {
} // namespace internal } // namespace internal
ReadAccessEnabler::ReadAccessEnabler(const PsFileBookmark *bookmark) : _bookmark(bookmark), _failed(_bookmark ? !_bookmark->enable() : false) { ReadAccessEnabler::ReadAccessEnabler(const PsFileBookmark *bookmark)
: _bookmark(bookmark)
, _failed(_bookmark ? !_bookmark->enable() : false) {
} }
ReadAccessEnabler::ReadAccessEnabler(const QSharedPointer<PsFileBookmark> &bookmark) : _bookmark(bookmark.data()), _failed(_bookmark ? !_bookmark->enable() : false) { ReadAccessEnabler::ReadAccessEnabler(
const std::shared_ptr<PsFileBookmark> &bookmark)
: _bookmark(bookmark.get())
, _failed(_bookmark ? !_bookmark->enable() : false) {
} }
ReadAccessEnabler::~ReadAccessEnabler() { ReadAccessEnabler::~ReadAccessEnabler() {
@ -1278,7 +1283,7 @@ FileLocation::FileLocation(const QString &name) : fname(name) {
qint64 s = f.size(); qint64 s = f.size();
if (s > INT_MAX) { if (s > INT_MAX) {
fname = QString(); fname = QString();
_bookmark.clear(); _bookmark = nullptr;
size = 0; size = 0;
} else { } else {
modified = f.lastModified(); modified = f.lastModified();
@ -1286,7 +1291,7 @@ FileLocation::FileLocation(const QString &name) : fname(name) {
} }
} else { } else {
fname = QString(); fname = QString();
_bookmark.clear(); _bookmark = nullptr;
size = 0; size = 0;
} }
} }
@ -1297,7 +1302,7 @@ bool FileLocation::check() const {
ReadAccessEnabler enabler(_bookmark); ReadAccessEnabler enabler(_bookmark);
if (enabler.failed()) { if (enabler.failed()) {
const_cast<FileLocation*>(this)->_bookmark.clear(); const_cast<FileLocation*>(this)->_bookmark = nullptr;
} }
QFileInfo f(name()); QFileInfo f(name());

View File

@ -573,7 +573,7 @@ class PsFileBookmark;
class ReadAccessEnabler { class ReadAccessEnabler {
public: public:
ReadAccessEnabler(const PsFileBookmark *bookmark); ReadAccessEnabler(const PsFileBookmark *bookmark);
ReadAccessEnabler(const QSharedPointer<PsFileBookmark> &bookmark); ReadAccessEnabler(const std::shared_ptr<PsFileBookmark> &bookmark);
bool failed() const { bool failed() const {
return _failed; return _failed;
} }
@ -606,7 +606,7 @@ public:
qint32 size; qint32 size;
private: private:
QSharedPointer<PsFileBookmark> _bookmark; std::shared_ptr<PsFileBookmark> _bookmark;
}; };
inline bool operator==(const FileLocation &a, const FileLocation &b) { inline bool operator==(const FileLocation &a, const FileLocation &b) {

View File

@ -602,45 +602,45 @@ public:
if (_t->_links.size() < lnkIndex) { if (_t->_links.size() < lnkIndex) {
_t->_links.resize(lnkIndex); _t->_links.resize(lnkIndex);
auto &link = links[lnkIndex - maxLnkIndex - 1]; auto &link = links[lnkIndex - maxLnkIndex - 1];
ClickHandlerPtr handler; auto handler = ClickHandlerPtr();
switch (link.type) { switch (link.type) {
case EntityInTextCustomUrl: { case EntityInTextCustomUrl: {
if (!link.data.isEmpty()) { if (!link.data.isEmpty()) {
handler = MakeShared<HiddenUrlClickHandler>(link.data); handler = std::make_shared<HiddenUrlClickHandler>(link.data);
} }
} break; } break;
case EntityInTextEmail: case EntityInTextEmail:
case EntityInTextUrl: handler = MakeShared<UrlClickHandler>(link.data, link.displayStatus == LinkDisplayedFull); break; case EntityInTextUrl: handler = std::make_shared<UrlClickHandler>(link.data, link.displayStatus == LinkDisplayedFull); break;
case EntityInTextBotCommand: handler = MakeShared<BotCommandClickHandler>(link.data); break; case EntityInTextBotCommand: handler = std::make_shared<BotCommandClickHandler>(link.data); break;
case EntityInTextHashtag: case EntityInTextHashtag:
if (options.flags & TextTwitterMentions) { if (options.flags & TextTwitterMentions) {
handler = MakeShared<UrlClickHandler>(qsl("https://twitter.com/hashtag/") + link.data.mid(1) + qsl("?src=hash"), true); handler = std::make_shared<UrlClickHandler>(qsl("https://twitter.com/hashtag/") + link.data.mid(1) + qsl("?src=hash"), true);
} else if (options.flags & TextInstagramMentions) { } else if (options.flags & TextInstagramMentions) {
handler = MakeShared<UrlClickHandler>(qsl("https://instagram.com/explore/tags/") + link.data.mid(1) + '/', true); handler = std::make_shared<UrlClickHandler>(qsl("https://instagram.com/explore/tags/") + link.data.mid(1) + '/', true);
} else { } else {
handler = MakeShared<HashtagClickHandler>(link.data); handler = std::make_shared<HashtagClickHandler>(link.data);
} }
break; break;
case EntityInTextMention: case EntityInTextMention:
if (options.flags & TextTwitterMentions) { if (options.flags & TextTwitterMentions) {
handler = MakeShared<UrlClickHandler>(qsl("https://twitter.com/") + link.data.mid(1), true); handler = std::make_shared<UrlClickHandler>(qsl("https://twitter.com/") + link.data.mid(1), true);
} else if (options.flags & TextInstagramMentions) { } else if (options.flags & TextInstagramMentions) {
handler = MakeShared<UrlClickHandler>(qsl("https://instagram.com/") + link.data.mid(1) + '/', true); handler = std::make_shared<UrlClickHandler>(qsl("https://instagram.com/") + link.data.mid(1) + '/', true);
} else { } else {
handler = MakeShared<MentionClickHandler>(link.data); handler = std::make_shared<MentionClickHandler>(link.data);
} }
break; break;
case EntityInTextMentionName: { case EntityInTextMentionName: {
auto fields = TextUtilities::MentionNameDataToFields(link.data); auto fields = TextUtilities::MentionNameDataToFields(link.data);
if (fields.userId) { if (fields.userId) {
handler = MakeShared<MentionNameClickHandler>(link.text, fields.userId, fields.accessHash); handler = std::make_shared<MentionNameClickHandler>(link.text, fields.userId, fields.accessHash);
} else { } else {
LOG(("Bad mention name: %1").arg(link.data)); LOG(("Bad mention name: %1").arg(link.data));
} }
} break; } break;
} }
if (!handler.isNull()) { if (handler) {
_t->setLink(lnkIndex, handler); _t->setLink(lnkIndex, handler);
} }
} }
@ -1209,7 +1209,7 @@ private:
} }
} }
if (_lookupLink) { if (_lookupLink) {
_lookupResult.link.clear(); _lookupResult.link = nullptr;
} }
_lookupResult.uponSymbol = false; _lookupResult.uponSymbol = false;
return false; return false;
@ -1224,7 +1224,7 @@ private:
// _lookupResult.uponSymbol = ((_lookupX < _x + _w) && (_lineEnd < _t->_text.size()) && (!_endBlock || _endBlock->type() != TextBlockTSkip)) ? true : false; // _lookupResult.uponSymbol = ((_lookupX < _x + _w) && (_lineEnd < _t->_text.size()) && (!_endBlock || _endBlock->type() != TextBlockTSkip)) ? true : false;
} }
if (_lookupLink) { if (_lookupLink) {
_lookupResult.link.clear(); _lookupResult.link = nullptr;
} }
_lookupResult.uponSymbol = false; _lookupResult.uponSymbol = false;
return false; return false;

View File

@ -253,7 +253,7 @@ void SettingsSlider::startRipple(int sectionIndex) {
if (index++ == sectionIndex) { if (index++ == sectionIndex) {
if (!section.ripple) { if (!section.ripple) {
auto mask = prepareRippleMask(sectionIndex, section); auto mask = prepareRippleMask(sectionIndex, section);
section.ripple = MakeShared<RippleAnimation>(_st.ripple, std::move(mask), [this] { update(); }); section.ripple = std::make_shared<RippleAnimation>(_st.ripple, std::move(mask), [this] { update(); });
} }
section.ripple->add(mapFromGlobal(QCursor::pos()) - QPoint(section.left, 0)); section.ripple->add(mapFromGlobal(QCursor::pos()) - QPoint(section.left, 0));
return false; return false;

View File

@ -59,7 +59,7 @@ protected:
int left, width; int left, width;
QString label; QString label;
int labelWidth; int labelWidth;
QSharedPointer<RippleAnimation> ripple; std::shared_ptr<RippleAnimation> ripple;
}; };
int getCurrentActiveLeft(TimeMs ms); int getCurrentActiveLeft(TimeMs ms);

View File

@ -353,9 +353,9 @@ Text::StateResult FlatLabel::dragActionFinish(const QPoint &p, Qt::MouseButton b
_lastMousePos = p; _lastMousePos = p;
auto state = dragActionUpdate(); auto state = dragActionUpdate();
ClickHandlerPtr activated = ClickHandler::unpressed(); auto activated = ClickHandler::unpressed();
if (_dragAction == Dragging) { if (_dragAction == Dragging) {
activated.clear(); activated = nullptr;
} else if (_dragAction == PrepareDrag) { } else if (_dragAction == PrepareDrag) {
_selection = { 0, 0 }; _selection = { 0, 0 };
_savedSelection = { 0, 0 }; _savedSelection = { 0, 0 };

View File

@ -71,10 +71,10 @@ MainMenu::MainMenu(
refreshMenu(); refreshMenu();
_telegram->setRichText(textcmdLink(1, qsl("Telegram Desktop"))); _telegram->setRichText(textcmdLink(1, qsl("Telegram Desktop")));
_telegram->setLink(1, MakeShared<UrlClickHandler>(qsl("https://desktop.telegram.org"))); _telegram->setLink(1, std::make_shared<UrlClickHandler>(qsl("https://desktop.telegram.org")));
_version->setRichText(textcmdLink(1, lng_settings_current_version(lt_version, currentVersionText())) + QChar(' ') + QChar(8211) + QChar(' ') + textcmdLink(2, lang(lng_menu_about))); _version->setRichText(textcmdLink(1, lng_settings_current_version(lt_version, currentVersionText())) + QChar(' ') + QChar(8211) + QChar(' ') + textcmdLink(2, lang(lng_menu_about)));
_version->setLink(1, MakeShared<UrlClickHandler>(qsl("https://desktop.telegram.org/changelog"))); _version->setLink(1, std::make_shared<UrlClickHandler>(qsl("https://desktop.telegram.org/changelog")));
_version->setLink(2, MakeShared<LambdaClickHandler>([] { Ui::show(Box<AboutBox>()); })); _version->setLink(2, std::make_shared<LambdaClickHandler>([] { Ui::show(Box<AboutBox>()); }));
subscribe(Auth().downloaderTaskFinished(), [this] { update(); }); subscribe(Auth().downloaderTaskFinished(), [this] { update(); });
subscribe(Auth().downloaderTaskFinished(), [this] { update(); }); subscribe(Auth().downloaderTaskFinished(), [this] { update(); });