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

View file

@ -45,7 +45,7 @@ void AboutBox::prepare() {
addButton(langFactory(lng_close), [this] { closeBox(); });
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);
return false;
}

View file

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

View file

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

View file

@ -144,7 +144,7 @@ private:
MTPDstickerSet::Flags flags;
QString title;
Stickers::Pack pack;
QSharedPointer<Ui::RippleAnimation> ripple;
std::shared_ptr<Ui::RippleAnimation> ripple;
};
using Sets = QList<Set>;
@ -172,7 +172,7 @@ private:
void updateSelected();
void setSelected(OverState newSelected);
void setPressed(OverState newPressed);
QSharedPointer<Ui::RippleAnimation> createButtonRipple(int section);
std::shared_ptr<Ui::RippleAnimation> createButtonRipple(int section);
QPoint buttonRippleTopLeft(int section) const;
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
// this method will be called when it is unpressed
if (_active && *_active) {
auto emitClickHandlerActiveChanged = (!_pressed || !*_pressed || *_pressed == *_active);
auto wasactive = *_active;
(*_active).clear();
const auto emitClickHandlerActiveChanged = false
|| !_pressed
|| !*_pressed
|| (*_pressed == *_active);
const auto wasactive = base::take(*_active);
if (_activeHost) {
if (emitClickHandlerActiveChanged) {
_activeHost->clickHandlerActiveChanged(wasactive, false);

View file

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

View file

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

View file

@ -545,11 +545,6 @@ static int32 QuarterArcLength = (FullArcLength / 4);
static int32 MinArcLength = (FullArcLength / 360);
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
// on demand by createIfNull(lambda) and are never automatically freed.
template <typename T>

View file

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

View file

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

View file

@ -488,7 +488,7 @@ void GenerateItems(not_null<History*> history, LocalIdManager &idManager, const
fromLinkText,
lt_sticker_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));
});
auto message = HistoryService::PreparedText { text };

View file

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

View file

@ -142,7 +142,7 @@ ReplyKeyboard::ReplyKeyboard(const HistoryItem *item, StylePtr &&s)
auto &button = newRow[j];
auto str = row.at(j).text;
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.characters = str.isEmpty() ? 1 : str.size();
}
@ -324,7 +324,7 @@ void ReplyKeyboard::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pr
if (pressed) {
if (!button.ripple) {
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());
} else {
@ -1424,7 +1424,7 @@ HistoryItem::~HistoryItem() {
}
ClickHandlerPtr goToMessageClickHandler(PeerData *peer, MsgId msgId) {
return MakeShared<LambdaClickHandler>([peer, msgId] {
return std::make_shared<LambdaClickHandler>([peer, msgId] {
if (App::main()) {
auto current = App::mousedItem();
if (current && current->history()->peer == peer) {

View file

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

View file

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

View file

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

View file

@ -190,7 +190,7 @@ void FastShareMessage(not_null<HistoryItem*> item) {
MessageIdsList msgIds;
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()) {
return Auth().data().groupToIds(group);
}
@ -362,7 +362,7 @@ QString GetErrorTextForForward(
void HistoryMessageVia::create(UserId userId) {
_bot = App::user(peerFromUser(userId));
_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);
});
}
@ -2401,7 +2401,7 @@ ClickHandlerPtr HistoryMessage::rightActionLink() const {
const auto forwarded = Get<HistoryMessageForwarded>();
const auto savedFromPeer = forwarded ? forwarded->_savedFromPeer : nullptr;
const auto savedFromMsgId = forwarded ? forwarded->_savedFromMsgId : 0;
_rightActionLink = MakeShared<LambdaClickHandler>([=] {
_rightActionLink = std::make_shared<LambdaClickHandler>([=] {
if (auto item = App::histItemById(itemId)) {
if (savedFromPeer && savedFromMsgId) {
App::wnd()->controller()->showPeerHistory(

View file

@ -359,7 +359,7 @@ HistoryService::PreparedText HistoryService::prepareGameScoreText() {
if (gamescore && gamescore->msg) {
if (auto media = gamescore->msg->getMedia()) {
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;
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 to = FileLoadTo(_peer->id, _peer->notifySilentPosts(), replyToId());
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) {
@ -4215,9 +4215,9 @@ void HistoryWidget::uploadFilesAfterConfirmation(
tasks.reserve(files.size());
for_const (auto &filepath, files) {
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 {
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);
@ -4228,7 +4228,7 @@ void HistoryWidget::uploadFile(const QByteArray &fileContent, SendMediaType type
auto to = FileLoadTo(_peer->id, _peer->notifySilentPosts(), replyToId());
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) {

View file

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

View file

@ -390,7 +390,7 @@ void Cover::refreshStatusText() {
}();
_status->setRichText(statusText);
if (hasMembersLink) {
_status->setLink(1, MakeShared<LambdaClickHandler>([=] {
_status->setLink(1, std::make_shared<LambdaClickHandler>([=] {
_controller->showSection(Info::Memento(
_controller->peerId(),
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) {
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)
, _title(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))
, _cancel(MakeShared<CancelFileClickHandler>(result)) {
, _open(std::make_shared<OpenFileClickHandler>(result))
, _cancel(std::make_shared<CancelFileClickHandler>(result)) {
updateStatusText();
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) {
LocationCoords location;
if (!_link && result->getLocationCoords(&location)) {
_link = MakeShared<LocationClickHandler>(location);
_link = std::make_shared<LocationClickHandler>(location);
}
_thumbLetter = getResultThumbLetter();
}

View file

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

View file

@ -224,7 +224,7 @@ void Inner::mouseReleaseEvent(QMouseEvent *e) {
return;
}
if (dynamic_cast<InlineBots::Layout::SendClickHandler*>(activated.data())) {
if (dynamic_cast<InlineBots::Layout::SendClickHandler*>(activated.get())) {
int row = _selected / MatrixRowShift, column = _selected % MatrixRowShift;
selectInlineResult(row, column);
} 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 inner = object_ptr<Ui::FlatLabel>(this, signupText, Ui::FlatLabel::InitType::Rich, st::introDescription);
_signup.create(this, std::move(inner));
_signup->entity()->setLink(1, MakeShared<UrlClickHandler>(qsl("https://telegram.org"), false));
_signup->entity()->setLink(2, MakeShared<LambdaClickHandler>([this] {
_signup->entity()->setLink(1, std::make_shared<UrlClickHandler>(qsl("https://telegram.org"), false));
_signup->entity()->setLink(2, std::make_shared<LambdaClickHandler>([this] {
toSignUp();
}));
_signup->hide(anim::type::instant);

View file

@ -114,8 +114,7 @@ public:
}
private:
QSharedPointer<QFile> files[LogDataCount];
std::shared_ptr<QFile> files[LogDataCount];
QTextStream streams[LogDataCount];
int32 part = -1;
@ -137,7 +136,7 @@ private:
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
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()) {
LOG(("Could not delete '%1' file to start new logging!").arg(to->fileName()));
return false;
@ -147,8 +146,8 @@ private:
return false;
}
if (to->open(mode | QIODevice::Append)) {
qSwap(files[type], to);
streams[type].setDevice(files[type].data());
std::swap(files[type], to);
streams[type].setDevice(files[type].get());
streams[type].setCodec("UTF-8");
LOG(("Moved logging from '%1' to '%2'!").arg(to->fileName()).arg(files[type]->fileName()));
to->remove();
@ -206,11 +205,16 @@ private:
}
}
if (files[type]->open(mode)) {
streams[type].setDevice(files[type].data());
streams[type].setDevice(files[type].get());
streams[type].setCodec("UTF-8");
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();
}

View file

@ -101,7 +101,7 @@ MediaView::MediaView() : TWidget(nullptr)
custom.insert(QChar('c'), qMakePair(textcmdStartLink(1), textcmdStopLink()));
_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());
_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)));

View file

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

View file

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

View file

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

View file

@ -173,9 +173,9 @@ class Sender {
}
RPCFailHandlerPtr takeOnFail() {
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)) {
return MakeShared<FailHandler<FailRequestIdPolicy>>(_sender, std::move(*handler), _failSkipPolicy);
return std::make_shared<FailHandler<FailRequestIdPolicy>>(_sender, std::move(*handler), _failSkipPolicy);
}
return RPCFailHandlerPtr();
}
@ -223,11 +223,11 @@ public:
return *this;
}
[[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;
}
[[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;
}
[[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
) -> ClickHandlerPtr {
if (document->isVoiceMessage()) {
return MakeShared<DocumentOpenClickHandler>(document);
return std::make_shared<DocumentOpenClickHandler>(document);
}
return MakeShared<DocumentSaveClickHandler>(document);
return std::make_shared<DocumentSaveClickHandler>(document);
};
setLinks(
MakeShared<DocumentOpenClickHandler>(document),
std::make_shared<DocumentOpenClickHandler>(document),
createSaveHandler(document),
MakeShared<DocumentCancelClickHandler>(document));
std::make_shared<DocumentCancelClickHandler>(document));
}
void RadialProgressItem::clickHandlerActiveChanged(const ClickHandlerPtr &action, bool active) {
@ -283,7 +283,7 @@ Photo::Photo(
not_null<PhotoData*> photo)
: ItemBase(parent)
, _data(photo)
, _link(MakeShared<PhotoOpenClickHandler>(photo, parent->fullId())) {
, _link(std::make_shared<PhotoOpenClickHandler>(photo, parent->fullId())) {
}
void Photo::initDimensions() {
@ -549,7 +549,7 @@ Voice::Voice(
const style::OverviewFileLayout &st)
: RadialProgressItem(parent)
, _data(voice)
, _namel(MakeShared<DocumentOpenClickHandler>(_data))
, _namel(std::make_shared<DocumentOpenClickHandler>(_data))
, _st(st) {
AddComponents(Info::Bit());
@ -794,7 +794,7 @@ Document::Document(
: RadialProgressItem(parent)
, _data(document)
, _msgl(goToMessageClickHandler(parent))
, _namel(MakeShared<DocumentOpenClickHandler>(_data))
, _namel(std::make_shared<DocumentOpenClickHandler>(_data))
, _st(st)
, _date(langDateTime(date(_data->date)))
, _datew(st::normalFont->width(_date))
@ -1215,22 +1215,22 @@ Link::Link(
if (_page) {
mainUrl = _page->url;
if (_page->document) {
_photol = MakeShared<DocumentOpenClickHandler>(_page->document);
_photol = std::make_shared<DocumentOpenClickHandler>(_page->document);
} else if (_page->photo) {
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")) {
_photol = MakeShared<PhotoOpenClickHandler>(
_photol = std::make_shared<PhotoOpenClickHandler>(
_page->photo,
parent->fullId());
} else {
_photol = MakeShared<UrlClickHandler>(_page->url);
_photol = std::make_shared<UrlClickHandler>(_page->url);
}
} else {
_photol = MakeShared<UrlClickHandler>(_page->url);
_photol = std::make_shared<UrlClickHandler>(_page->url);
}
} else if (!mainUrl.isEmpty()) {
_photol = MakeShared<UrlClickHandler>(mainUrl);
_photol = std::make_shared<UrlClickHandler>(mainUrl);
}
if (from >= till && _page) {
text = _page->description.text;
@ -1456,7 +1456,7 @@ const style::RoundCheckbox &Link::checkboxStyle() const {
Link::LinkEntry::LinkEntry(const QString &url, const QString &text)
: text(text)
, width(st::normalFont->width(text))
, lnk(MakeShared<UrlClickHandler>(url)) {
, lnk(std::make_shared<UrlClickHandler>(url)) {
}
} // namespace Layout

View file

@ -236,7 +236,7 @@ private:
};
using Notification = QSharedPointer<NotificationData>;
using Notification = std::shared_ptr<NotificationData>;
QString GetServerName() {
if (!LibNotifyLoaded()) {
@ -440,7 +440,13 @@ void Manager::Private::showNextNotification() {
auto peerId = data.peer->id;
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()) {
return;
}

View file

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

View file

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

View file

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

View file

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

View file

@ -2854,7 +2854,7 @@ TaskId startImageLoad(const StorageKey &location, mtpFileLoader *loader) {
if (j == _imagesMap.cend() || !_localLoader) {
return 0;
}
return _localLoader->addTask(MakeShared<ImageLoadTask>(j->first, location, loader));
return _localLoader->addTask(std::make_shared<ImageLoadTask>(j->first, location, loader));
}
int32 hasImages() {
@ -2912,7 +2912,7 @@ TaskId startStickerImageLoad(const StorageKey &location, mtpFileLoader *loader)
if (j == _stickerImagesMap.cend() || !_localLoader) {
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) {
@ -2985,7 +2985,7 @@ TaskId startAudioLoad(const StorageKey &location, mtpFileLoader *loader) {
if (j == _audiosMap.cend() || !_localLoader) {
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) {
@ -3101,7 +3101,7 @@ TaskId startWebFileLoad(const QString &url, webFileLoader *loader) {
if (j == _webFilesMap.cend() || !_localLoader) {
return 0;
}
return _localLoader->addTask(MakeShared<WebFileLoadTask>(j->first, url, loader));
return _localLoader->addTask(std::make_shared<WebFileLoadTask>(j->first, url, loader));
}
int32 hasWebFiles() {
@ -3177,7 +3177,7 @@ void countVoiceWaveform(DocumentData *document) {
if (_localLoader) {
voice->waveform.resize(1 + sizeof(TaskId));
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));
}
}

View file

@ -1257,10 +1257,15 @@ WebFileImage *getImage(const WebFileImageLocation &location, int32 size) {
} // 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() {
@ -1278,7 +1283,7 @@ FileLocation::FileLocation(const QString &name) : fname(name) {
qint64 s = f.size();
if (s > INT_MAX) {
fname = QString();
_bookmark.clear();
_bookmark = nullptr;
size = 0;
} else {
modified = f.lastModified();
@ -1286,7 +1291,7 @@ FileLocation::FileLocation(const QString &name) : fname(name) {
}
} else {
fname = QString();
_bookmark.clear();
_bookmark = nullptr;
size = 0;
}
}
@ -1297,7 +1302,7 @@ bool FileLocation::check() const {
ReadAccessEnabler enabler(_bookmark);
if (enabler.failed()) {
const_cast<FileLocation*>(this)->_bookmark.clear();
const_cast<FileLocation*>(this)->_bookmark = nullptr;
}
QFileInfo f(name());

View file

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

View file

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

View file

@ -253,7 +253,7 @@ void SettingsSlider::startRipple(int sectionIndex) {
if (index++ == sectionIndex) {
if (!section.ripple) {
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));
return false;

View file

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

View file

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

View file

@ -71,10 +71,10 @@ MainMenu::MainMenu(
refreshMenu();
_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->setLink(1, MakeShared<UrlClickHandler>(qsl("https://desktop.telegram.org/changelog")));
_version->setLink(2, MakeShared<LambdaClickHandler>([] { Ui::show(Box<AboutBox>()); }));
_version->setLink(1, std::make_shared<UrlClickHandler>(qsl("https://desktop.telegram.org/changelog")));
_version->setLink(2, std::make_shared<LambdaClickHandler>([] { Ui::show(Box<AboutBox>()); }));
subscribe(Auth().downloaderTaskFinished(), [this] { update(); });
subscribe(Auth().downloaderTaskFinished(), [this] { update(); });