Replace some std::shared_ptr with std::unique_ptr.

This commit is contained in:
John Preston 2017-12-18 14:38:14 +04:00
parent 14034c255e
commit 37b018257e
16 changed files with 421 additions and 248 deletions

View File

@ -108,16 +108,18 @@ void BotKeyboard::leaveEventHook(QEvent *e) {
}
bool BotKeyboard::moderateKeyActivate(int key) {
if (auto item = App::histItemById(_wasForMsgId)) {
if (auto markup = item->Get<HistoryMessageReplyMarkup>()) {
if (const auto item = App::histItemById(_wasForMsgId)) {
if (const auto markup = item->Get<HistoryMessageReplyMarkup>()) {
if (key >= Qt::Key_1 && key <= Qt::Key_9) {
int index = (key - Qt::Key_1);
if (!markup->rows.isEmpty() && index >= 0 && index < markup->rows.front().size()) {
const auto index = int(key - Qt::Key_1);
if (!markup->rows.empty()
&& index >= 0
&& index < int(markup->rows.front().size())) {
App::activateBotCommand(item, 0, index);
return true;
}
} else if (key == Qt::Key_Q) {
if (auto user = item->history()->peer->asUser()) {
if (const auto user = item->history()->peer->asUser()) {
if (user->botInfo && item->from() == user) {
App::sendBotCommand(user, user, qsl("/translate"));
return true;
@ -163,8 +165,10 @@ bool BotKeyboard::updateMarkup(HistoryItem *to, bool force) {
_impl = nullptr;
if (auto markup = to->Get<HistoryMessageReplyMarkup>()) {
if (!markup->rows.isEmpty()) {
_impl.reset(new ReplyKeyboard(to, std::make_unique<Style>(this, *_st)));
if (!markup->rows.empty()) {
_impl = std::make_unique<ReplyKeyboard>(
to,
std::make_unique<Style>(this, *_st));
}
}

View File

@ -113,6 +113,23 @@ private:
};
StickersListWidget::Set::Set(
uint64 id,
MTPDstickerSet::Flags flags,
const QString &title,
int hoversSize,
const Stickers::Pack &pack)
: id(id)
, flags(flags)
, title(title)
, pack(pack) {
}
StickersListWidget::Set::Set(Set &&other) = default;
StickersListWidget::Set &StickersListWidget::Set::operator=(
Set &&other) = default;
StickersListWidget::Set::~Set() = default;
StickersListWidget::Footer::Footer(not_null<StickersListWidget*> parent) : InnerFooter(parent)
, _pan(parent)
, _a_icons(animation(this, &Footer::step_icons)) {
@ -605,10 +622,12 @@ int StickersListWidget::countDesiredHeight(int newWidth) {
auto minimalLastHeight = (visibleHeight - st::stickerPanPadding);
auto countResult = [this, minimalLastHeight] {
if (_section == Section::Featured) {
return st::stickerPanPadding + shownSets().size() * featuredRowHeight();
return st::stickerPanPadding
+ int(shownSets().size()) * featuredRowHeight();
} else if (!shownSets().empty()) {
auto info = sectionInfo(shownSets().size() - 1);
return info.top + qMax(info.rowsBottom - info.top, minimalLastHeight);
const auto info = sectionInfo(shownSets().size() - 1);
return info.top
+ qMax(info.rowsBottom - info.top, minimalLastHeight);
}
return 0;
};
@ -679,7 +698,7 @@ void StickersListWidget::paintFeaturedStickers(Painter &p, QRect clip) {
auto tilly = st::stickerPanPadding;
auto ms = getms();
for (auto c = 0, l = sets.size(); c != l; ++c) {
for (auto c = 0, l = int(sets.size()); c != l; ++c) {
auto y = tilly;
auto &set = sets[c];
tilly = y + featuredRowHeight();
@ -1005,18 +1024,18 @@ QRect StickersListWidget::megagroupSetButtonRectFinal() const {
return result;
}
std::shared_ptr<Ui::RippleAnimation> StickersListWidget::createButtonRipple(int section) {
std::unique_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 std::make_shared<Ui::RippleAnimation>(
return std::make_unique<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 std::make_shared<Ui::RippleAnimation>(
return std::make_unique<Ui::RippleAnimation>(
st::stickerPanRemoveSet.ripple,
std::move(mask),
[this, section] { rtlupdate(removeButtonRect(section)); });
@ -1085,7 +1104,9 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) {
}
void StickersListWidget::removeRecentSticker(int section, int index) {
if (_section != Section::Stickers || section >= _mySets.size() || _mySets[section].id != Stickers::RecentSetId) {
if ((_section != Section::Stickers)
|| (section >= int(_mySets.size()))
|| (_mySets[section].id != Stickers::RecentSetId)) {
return;
}
@ -1124,7 +1145,9 @@ void StickersListWidget::removeRecentSticker(int section, int index) {
}
void StickersListWidget::removeFavedSticker(int section, int index) {
if (_section != Section::Stickers || section >= _mySets.size() || _mySets[section].id != Stickers::FavedSetId) {
if ((_section != Section::Stickers)
|| (section >= int(_mySets.size()))
|| (_mySets[section].id != Stickers::FavedSetId)) {
return;
}
@ -1231,8 +1254,7 @@ void StickersListWidget::refreshStickers() {
}
void StickersListWidget::refreshSettingsVisibility() {
auto visible = (_section == Section::Stickers)
&& _mySets.isEmpty();
const auto visible = (_section == Section::Stickers) && _mySets.empty();
_settings->setVisible(visible);
}
@ -1253,7 +1275,7 @@ void StickersListWidget::preloadImages() {
for (int j = 0; j != count; ++j) {
if (++k > _columnCount * (_columnCount + 1)) break;
auto sticker = sets.at(i).pack.at(j);
auto sticker = sets[i].pack.at(j);
if (!sticker || !sticker->sticker()) continue;
bool goodThumb = !sticker->thumb->isNull() && ((sticker->thumb->width() >= 128) || (sticker->thumb->height() >= 128));
@ -1274,10 +1296,15 @@ uint64 StickersListWidget::currentSet(int yOffset) const {
if (_section == Section::Featured) {
return Stickers::FeaturedSetId;
}
return _mySets.isEmpty() ? Stickers::RecentSetId : _mySets[sectionInfoByOffset(yOffset).section].id;
return _mySets.empty()
? Stickers::RecentSetId
: _mySets[sectionInfoByOffset(yOffset).section].id;
}
void StickersListWidget::appendSet(Sets &to, uint64 setId, AppendSkip skip) {
void StickersListWidget::appendSet(
std::vector<Set> &to,
uint64 setId,
AppendSkip skip) {
auto &sets = Auth().data().stickerSets();
auto it = sets.constFind(setId);
if (it == sets.cend() || it->stickers.isEmpty()) return;
@ -1425,7 +1452,7 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) {
void StickersListWidget::fillIcons(QList<StickerIcon> &icons) {
icons.clear();
icons.reserve(_mySets.size() + 1);
if (Auth().data().featuredStickerSetsUnreadCount() && !_featuredSets.isEmpty()) {
if (Auth().data().featuredStickerSetsUnreadCount() && !_featuredSets.empty()) {
icons.push_back(StickerIcon(Stickers::FeaturedSetId));
}
@ -1459,7 +1486,8 @@ void StickersListWidget::fillIcons(QList<StickerIcon> &icons) {
icons.push_back(StickerIcon(_mySets[i].id, s, pixw, pixh));
}
if (!Auth().data().featuredStickerSetsUnreadCount() && !_featuredSets.isEmpty()) {
if (!Auth().data().featuredStickerSetsUnreadCount()
&& !_featuredSets.empty()) {
icons.push_back(StickerIcon(Stickers::FeaturedSetId));
}
}

View File

@ -138,15 +138,22 @@ private:
};
struct Set {
Set(uint64 id, MTPDstickerSet::Flags flags, const QString &title, int32 hoversSize, const Stickers::Pack &pack = Stickers::Pack()) : id(id), flags(flags), title(title), pack(pack) {
}
Set(
uint64 id,
MTPDstickerSet::Flags flags,
const QString &title,
int hoversSize,
const Stickers::Pack &pack = Stickers::Pack());
Set(Set &&other);
Set &operator=(Set &&other);
~Set();
uint64 id;
MTPDstickerSet::Flags flags;
QString title;
Stickers::Pack pack;
std::shared_ptr<Ui::RippleAnimation> ripple;
std::unique_ptr<Ui::RippleAnimation> ripple;
};
using Sets = QList<Set>;
template <typename Callback>
bool enumerateSections(Callback callback) const;
@ -172,7 +179,7 @@ private:
void updateSelected();
void setSelected(OverState newSelected);
void setPressed(OverState newPressed);
std::shared_ptr<Ui::RippleAnimation> createButtonRipple(int section);
std::unique_ptr<Ui::RippleAnimation> createButtonRipple(int section);
QPoint buttonRippleTopLeft(int section) const;
enum class ValidateIconAnimations {
@ -182,10 +189,10 @@ private:
};
void validateSelectedIcon(ValidateIconAnimations animations);
Sets &shownSets() {
std::vector<Set> &shownSets() {
return (_section == Section::Featured) ? _featuredSets : _mySets;
}
const Sets &shownSets() const {
const std::vector<Set> &shownSets() const {
return (_section == Section::Featured) ? _featuredSets : _mySets;
}
int featuredRowHeight() const;
@ -210,7 +217,10 @@ private:
Archived,
Installed,
};
void appendSet(Sets &to, uint64 setId, AppendSkip skip = AppendSkip::None);
void appendSet(
std::vector<Set> &to,
uint64 setId,
AppendSkip skip = AppendSkip::None);
void selectEmoji(EmojiPtr emoji);
int stickersLeft() const;
@ -222,10 +232,10 @@ private:
void refreshFooterIcons();
ChannelData *_megagroupSet = nullptr;
Sets _mySets;
Sets _featuredSets;
OrderedSet<uint64> _installedLocallySets;
QList<bool> _custom;
std::vector<Set> _mySets;
std::vector<Set> _featuredSets;
base::flat_set<uint64> _installedLocallySets;
std::vector<bool> _custom;
base::flat_set<not_null<DocumentData*>> _favedStickersMap;
Section _section = Section::Stickers;

View File

@ -97,7 +97,6 @@ private:
QString _originalUrl, _readable;
};
using TextClickHandlerPtr = std::shared_ptr<TextClickHandler>;
class HiddenUrlClickHandler : public UrlClickHandler {
public:

View File

@ -128,33 +128,43 @@ QString ReplyMarkupClickHandler::buttonText() const {
return QString();
}
ReplyKeyboard::ReplyKeyboard(const HistoryItem *item, StylePtr &&s)
: _item(item)
, _a_selected(animation(this, &ReplyKeyboard::step_selected))
, _st(std::move(s)) {
if (auto markup = item->Get<HistoryMessageReplyMarkup>()) {
ReplyKeyboard::Button::Button() = default;
ReplyKeyboard::Button::Button(Button &&other) = default;
ReplyKeyboard::Button &ReplyKeyboard::Button::operator=(
Button &&other) = default;
ReplyKeyboard::Button::~Button() = default;
ReplyKeyboard::ReplyKeyboard(
not_null<const HistoryItem*> item,
std::unique_ptr<Style> &&s)
: _item(item)
, _a_selected(animation(this, &ReplyKeyboard::step_selected))
, _st(std::move(s)) {
if (const auto markup = _item->Get<HistoryMessageReplyMarkup>()) {
_rows.reserve(markup->rows.size());
for (int i = 0, l = markup->rows.size(); i != l; ++i) {
for (auto i = 0, l = int(markup->rows.size()); i != l; ++i) {
auto &row = markup->rows.at(i);
int s = row.size();
ButtonRow newRow(s, Button());
auto newRow = std::vector<Button>();
newRow.reserve(s);
for (int j = 0; j != s; ++j) {
auto &button = newRow[j];
auto button = Button();
auto str = row.at(j).text;
button.type = row.at(j).type;
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();
newRow.push_back(std::move(button));
}
_rows.push_back(newRow);
_rows.push_back(std::move(newRow));
}
}
}
void ReplyKeyboard::updateMessageId() {
auto msgId = _item->fullId();
for_const (auto &row, _rows) {
for_const (auto &button, row) {
const auto msgId = _item->fullId();
for (const auto &row : _rows) {
for (const auto &button : row) {
button.link->setMessageId(msgId);
}
}
@ -165,7 +175,10 @@ void ReplyKeyboard::resize(int width, int height) {
_width = width;
auto markup = _item->Get<HistoryMessageReplyMarkup>();
float64 y = 0, buttonHeight = _rows.isEmpty() ? _st->buttonHeight() : (float64(height + _st->buttonSkip()) / _rows.size());
auto y = 0.;
auto buttonHeight = _rows.empty()
? float64(_st->buttonHeight())
: (float64(height + _st->buttonSkip()) / _rows.size());
for (auto &row : _rows) {
int s = row.size();
@ -228,24 +241,30 @@ bool ReplyKeyboard::isEnoughSpace(int width, const style::BotKeyboardButton &st)
return true;
}
void ReplyKeyboard::setStyle(StylePtr &&st) {
void ReplyKeyboard::setStyle(std::unique_ptr<Style> &&st) {
_st = std::move(st);
}
int ReplyKeyboard::naturalWidth() const {
auto result = 0;
for_const (auto &row, _rows) {
for (const auto &row : _rows) {
auto maxMinButtonWidth = 0;
for_const (auto &button, row) {
accumulate_max(maxMinButtonWidth, _st->minButtonWidth(button.type));
for (const auto &button : row) {
accumulate_max(
maxMinButtonWidth,
_st->minButtonWidth(button.type));
}
auto rowMaxButtonWidth = 0;
for_const (auto &button, row) {
accumulate_max(rowMaxButtonWidth, qMax(button.text.maxWidth(), 1) + maxMinButtonWidth);
for (const auto &button : row) {
accumulate_max(
rowMaxButtonWidth,
qMax(button.text.maxWidth(), 1) + maxMinButtonWidth);
}
auto rowSize = row.size();
accumulate_max(result, rowSize * rowMaxButtonWidth + (rowSize - 1) * _st->buttonSkip());
const auto rowSize = int(row.size());
accumulate_max(
result,
rowSize * rowMaxButtonWidth + (rowSize - 1) * _st->buttonSkip());
}
return result;
}
@ -323,8 +342,13 @@ void ReplyKeyboard::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pr
auto &button = _rows[coords.i][coords.j];
if (pressed) {
if (!button.ripple) {
auto mask = Ui::RippleAnimation::roundRectMask(button.rect.size(), _st->buttonRadius());
button.ripple = std::make_shared<Ui::RippleAnimation>(_st->_st->ripple, std::move(mask), [this] { _st->repaint(_item); });
auto mask = Ui::RippleAnimation::roundRectMask(
button.rect.size(),
_st->buttonRadius());
button.ripple = std::make_unique<Ui::RippleAnimation>(
_st->_st->ripple,
std::move(mask),
[this] { _st->repaint(_item); });
}
button.ripple->add(_savedCoords - button.rect.topLeft());
} else {
@ -339,13 +363,13 @@ void ReplyKeyboard::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pr
}
void ReplyKeyboard::startAnimation(int i, int j, int direction) {
auto notStarted = _animations.isEmpty();
auto notStarted = _animations.empty();
int indexForAnimation = (i * MatrixRowShift + j + 1) * direction;
_animations.remove(-indexForAnimation);
if (!_animations.contains(indexForAnimation)) {
_animations.insert(indexForAnimation, getms());
_animations.emplace(indexForAnimation, getms());
}
if (notStarted && !_a_selected.animating()) {
@ -354,26 +378,30 @@ void ReplyKeyboard::startAnimation(int i, int j, int direction) {
}
void ReplyKeyboard::step_selected(TimeMs ms, bool timer) {
for (Animations::iterator i = _animations.begin(); i != _animations.end();) {
int index = qAbs(i.key()) - 1, row = (index / MatrixRowShift), col = index % MatrixRowShift;
float64 dt = float64(ms - i.value()) / st::botKbDuration;
for (auto i = _animations.begin(); i != _animations.end();) {
const auto index = std::abs(i->first) - 1;
const auto row = (index / MatrixRowShift);
const auto col = index % MatrixRowShift;
const auto dt = float64(ms - i->second) / st::botKbDuration;
if (dt >= 1) {
_rows[row][col].howMuchOver = (i.key() > 0) ? 1 : 0;
_rows[row][col].howMuchOver = (i->first > 0) ? 1 : 0;
i = _animations.erase(i);
} else {
_rows[row][col].howMuchOver = (i.key() > 0) ? dt : (1 - dt);
_rows[row][col].howMuchOver = (i->first > 0) ? dt : (1 - dt);
++i;
}
}
if (timer) _st->repaint(_item);
if (_animations.isEmpty()) {
if (_animations.empty()) {
_a_selected.stop();
}
}
void ReplyKeyboard::clearSelection() {
for (auto i = _animations.cbegin(), e = _animations.cend(); i != e; ++i) {
int index = qAbs(i.key()) - 1, row = (index / MatrixRowShift), col = index % MatrixRowShift;
for (const auto [relativeIndex, time] : _animations) {
const auto index = std::abs(relativeIndex) - 1;
const auto row = (index / MatrixRowShift);
const auto col = index % MatrixRowShift;
_rows[row][col].howMuchOver = 0;
}
_animations.clear();
@ -435,7 +463,7 @@ void HistoryMessageReplyMarkup::createFromButtonRows(const QVector<MTPKeyboardBu
auto &r = row.c_keyboardButtonRow();
auto &b = r.vbuttons.v;
if (!b.isEmpty()) {
ButtonRow buttonRow;
auto buttonRow = std::vector<Button>();
buttonRow.reserve(b.size());
for_const (auto &button, b) {
switch (button.type()) {
@ -476,7 +504,9 @@ void HistoryMessageReplyMarkup::createFromButtonRows(const QVector<MTPKeyboardBu
}
}
}
if (!buttonRow.isEmpty()) rows.push_back(buttonRow);
if (!buttonRow.empty()) {
rows.push_back(std::move(buttonRow));
}
}
} break;
}
@ -515,18 +545,21 @@ void HistoryMessageReplyMarkup::create(const MTPReplyMarkup &markup) {
}
}
void HistoryMessageReplyMarkup::create(const HistoryMessageReplyMarkup &markup) {
void HistoryMessageReplyMarkup::create(
const HistoryMessageReplyMarkup &markup) {
flags = markup.flags;
inlineKeyboard = nullptr;
rows.clear();
for_const (auto &row, markup.rows) {
ButtonRow buttonRow;
for (const auto &row : markup.rows) {
auto buttonRow = std::vector<Button>();
buttonRow.reserve(row.size());
for_const (auto &button, row) {
for (const auto &button : row) {
buttonRow.push_back({ button.type, button.text, button.data, 0 });
}
if (!buttonRow.isEmpty()) rows.push_back(buttonRow);
if (!buttonRow.empty()) {
rows.push_back(std::move(buttonRow));
}
}
}

View File

@ -253,10 +253,8 @@ struct HistoryMessageReplyMarkup : public RuntimeComponent<HistoryMessageReplyMa
QByteArray data;
mutable mtpRequestId requestId;
};
using ButtonRow = QVector<Button>;
using ButtonRows = QVector<ButtonRow>;
ButtonRows rows;
std::vector<std::vector<Button>> rows;
MTPDreplyKeyboardMarkup::Flags flags = 0;
std::unique_ptr<ReplyKeyboard> inlineKeyboard;
@ -345,14 +343,15 @@ public:
friend class ReplyKeyboard;
};
typedef std::unique_ptr<Style> StylePtr;
ReplyKeyboard(const HistoryItem *item, StylePtr &&s);
ReplyKeyboard(
not_null<const HistoryItem*> item,
std::unique_ptr<Style> &&s);
ReplyKeyboard(const ReplyKeyboard &other) = delete;
ReplyKeyboard &operator=(const ReplyKeyboard &other) = delete;
bool isEnoughSpace(int width, const style::BotKeyboardButton &st) const;
void setStyle(StylePtr &&s);
void setStyle(std::unique_ptr<Style> &&s);
void resize(int width, int height);
// what width and height will best fit this keyboard
@ -369,39 +368,39 @@ public:
void updateMessageId();
private:
void startAnimation(int i, int j, int direction);
friend class Style;
using ReplyMarkupClickHandlerPtr = std::shared_ptr<ReplyMarkupClickHandler>;
struct Button {
Button();
Button(Button &&other);
Button &operator=(Button &&other);
~Button();
Text text = { 1 };
QRect rect;
int characters = 0;
float64 howMuchOver = 0.;
HistoryMessageReplyMarkup::Button::Type type;
ReplyMarkupClickHandlerPtr link;
mutable std::shared_ptr<Ui::RippleAnimation> ripple;
std::shared_ptr<ReplyMarkupClickHandler> link;
mutable std::unique_ptr<Ui::RippleAnimation> ripple;
};
using ButtonRow = QVector<Button>;
using ButtonRows = QVector<ButtonRow>;
struct ButtonCoords {
int i, j;
};
void startAnimation(int i, int j, int direction);
ButtonCoords findButtonCoordsByClickHandler(const ClickHandlerPtr &p);
using Animations = QMap<int, TimeMs>;
void step_selected(TimeMs ms, bool timer);
const HistoryItem *_item;
const not_null<const HistoryItem*> _item;
int _width = 0;
ButtonRows _rows;
std::vector<std::vector<Button>> _rows;
Animations _animations;
base::flat_map<int, TimeMs> _animations;
BasicAnimation _a_selected;
StylePtr _st;
std::unique_ptr<Style> _st;
ClickHandlerPtr _savedPressed;
ClickHandlerPtr _savedActive;

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(std::make_shared<FileLoadTask>(result, duration, waveform, to, caption));
_fileLoader.addTask(std::make_unique<FileLoadTask>(result, duration, waveform, to, caption));
}
void HistoryWidget::onRecordUpdate(quint16 level, qint32 samples) {
@ -4211,16 +4211,16 @@ void HistoryWidget::uploadFilesAfterConfirmation(
App::main()->sendMessage(message);
caption = QString();
}
auto tasks = TasksList();
auto tasks = std::vector<std::unique_ptr<Task>>();
tasks.reserve(files.size());
for_const (auto &filepath, files) {
if (filepath.isEmpty() && (!image.isNull() || !content.isNull())) {
tasks.push_back(std::make_shared<FileLoadTask>(content, image, type, to, caption));
tasks.push_back(std::make_unique<FileLoadTask>(content, image, type, to, caption));
} else {
tasks.push_back(std::make_shared<FileLoadTask>(filepath, std::move(information), type, to, caption));
tasks.push_back(std::make_unique<FileLoadTask>(filepath, std::move(information), type, to, caption));
}
}
_fileLoader.addTasks(tasks);
_fileLoader.addTasks(std::move(tasks));
}
void HistoryWidget::uploadFile(const QByteArray &fileContent, SendMediaType type) {
@ -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(std::make_shared<FileLoadTask>(fileContent, QImage(), type, to, caption));
_fileLoader.addTask(std::make_unique<FileLoadTask>(fileContent, QImage(), type, to, caption));
}
void HistoryWidget::sendFileConfirmed(const FileLoadResultPtr &file) {

View File

@ -114,7 +114,7 @@ public:
}
private:
std::shared_ptr<QFile> files[LogDataCount];
std::unique_ptr<QFile> files[LogDataCount];
QTextStream streams[LogDataCount];
int32 part = -1;
@ -136,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
std::shared_ptr<QFile> to = std::make_shared<QFile>(_logsFilePath(type, postfix));
auto to = std::make_unique<QFile>(_logsFilePath(type, postfix));
if (to->exists() && !to->remove()) {
LOG(("Could not delete '%1' file to start new logging!").arg(to->fileName()));
return false;

View File

@ -365,7 +365,7 @@ private:
LinkEntry(const QString &url, const QString &text);
QString text;
int32 width;
TextClickHandlerPtr lnk;
std::shared_ptr<TextClickHandler> lnk;
};
QVector<LinkEntry> _links;

View File

@ -55,7 +55,7 @@ void Uploader::uploadMedia(const FullMsgId &msgId, const SendMediaReady &media)
document->setLocation(FileLocation(media.file));
}
}
queue.insert(msgId, File(media));
queue.emplace(msgId, File(media));
sendNext();
}
@ -73,21 +73,21 @@ void Uploader::upload(const FullMsgId &msgId, const FileLoadResultPtr &file) {
document->setLocation(FileLocation(file->filepath));
}
}
queue.insert(msgId, File(file));
queue.emplace(msgId, File(file));
sendNext();
}
void Uploader::currentFailed() {
Queue::iterator j = queue.find(uploading);
auto j = queue.find(uploadingId);
if (j != queue.end()) {
if (j->type() == SendMediaType::Photo) {
emit photoFailed(j.key());
} else if (j->type() == SendMediaType::File) {
DocumentData *doc = App::document(j->id());
if (doc->status == FileUploading) {
doc->status = FileUploadFailed;
if (j->second.type() == SendMediaType::Photo) {
emit photoFailed(j->first);
} else if (j->second.type() == SendMediaType::File) {
const auto document = App::document(j->second.id());
if (document->status == FileUploading) {
document->status = FileUploadFailed;
}
emit documentFailed(j.key());
emit documentFailed(j->first);
}
queue.erase(j);
}
@ -95,7 +95,7 @@ void Uploader::currentFailed() {
requestsSent.clear();
docRequestsSent.clear();
dcMap.clear();
uploading = FullMsgId();
uploadingId = FullMsgId();
sentSize = 0;
for (int i = 0; i < MTP::kUploadSessionsCount; ++i) {
sentSizes[i] = 0;
@ -111,10 +111,10 @@ void Uploader::killSessions() {
}
void Uploader::sendNext() {
if (sentSize >= kMaxUploadFileParallelSize || _paused.msg) return;
if (sentSize >= kMaxUploadFileParallelSize || _pausedId.msg) return;
bool killing = killSessionsTimer.isActive();
if (queue.isEmpty()) {
if (queue.empty()) {
if (!killing) {
killSessionsTimer.start(MTPAckSendWaiting + MTPKillFileSessionTimeout);
}
@ -124,95 +124,172 @@ void Uploader::sendNext() {
if (killing) {
killSessionsTimer.stop();
}
Queue::iterator i = uploading.msg ? queue.find(uploading) : queue.begin();
if (!uploading.msg) {
uploading = i.key();
auto i = uploadingId.msg ? queue.find(uploadingId) : queue.begin();
if (!uploadingId.msg) {
uploadingId = i->first;
} else if (i == queue.end()) {
i = queue.begin();
uploading = i.key();
uploadingId = i->first;
}
int todc = 0;
for (int dc = 1; dc < MTP::kUploadSessionsCount; ++dc) {
auto &uploadingData = i->second;
auto todc = 0;
for (auto dc = 1; dc != MTP::kUploadSessionsCount; ++dc) {
if (sentSizes[dc] < sentSizes[todc]) {
todc = dc;
}
}
UploadFileParts &parts(i->file ? (i->type() == SendMediaType::Photo ? i->file->fileparts : i->file->thumbparts) : i->media.parts);
uint64 partsOfId(i->file ? (i->type() == SendMediaType::Photo ? i->file->id : i->file->thumbId) : i->media.thumbId);
auto &parts = uploadingData.file
? (uploadingData.type() == SendMediaType::Photo
? uploadingData.file->fileparts
: uploadingData.file->thumbparts)
: uploadingData.media.parts;
const auto partsOfId = uploadingData.file
? (uploadingData.type() == SendMediaType::Photo
? uploadingData.file->id
: uploadingData.file->thumbId)
: uploadingData.media.thumbId;
if (parts.isEmpty()) {
if (i->docSentParts >= i->docPartsCount) {
if (requestsSent.isEmpty() && docRequestsSent.isEmpty()) {
bool silent = i->file && i->file->to.silent;
if (i->type() == SendMediaType::Photo) {
auto photoFilename = i->filename();
if (uploadingData.docSentParts >= uploadingData.docPartsCount) {
if (requestsSent.empty() && docRequestsSent.empty()) {
const auto silent = uploadingData.file
&& uploadingData.file->to.silent;
if (uploadingData.type() == SendMediaType::Photo) {
auto photoFilename = uploadingData.filename();
if (!photoFilename.endsWith(qstr(".jpg"), Qt::CaseInsensitive)) {
// Server has some extensions checking for inputMediaUploadedPhoto,
// so force the extension to be .jpg anyway. It doesn't matter,
// because the filename from inputFile is not used anywhere.
photoFilename += qstr(".jpg");
}
emit photoReady(uploading, silent, MTP_inputFile(MTP_long(i->id()), MTP_int(i->partsCount), MTP_string(photoFilename), MTP_bytes(i->file ? i->file->filemd5 : i->media.jpeg_md5)));
} else if (i->type() == SendMediaType::File || i->type() == SendMediaType::Audio) {
const auto md5 = uploadingData.file
? uploadingData.file->filemd5
: uploadingData.media.jpeg_md5;
const auto file = MTP_inputFile(
MTP_long(uploadingData.id()),
MTP_int(uploadingData.partsCount),
MTP_string(photoFilename),
MTP_bytes(md5));
emit photoReady(uploadingId, silent, file);
} else if (uploadingData.type() == SendMediaType::File
|| uploadingData.type() == SendMediaType::Audio) {
QByteArray docMd5(32, Qt::Uninitialized);
hashMd5Hex(i->md5Hash.result(), docMd5.data());
hashMd5Hex(uploadingData.md5Hash.result(), docMd5.data());
MTPInputFile doc = (i->docSize > UseBigFilesFrom) ? MTP_inputFileBig(MTP_long(i->id()), MTP_int(i->docPartsCount), MTP_string(i->filename())) : MTP_inputFile(MTP_long(i->id()), MTP_int(i->docPartsCount), MTP_string(i->filename()), MTP_bytes(docMd5));
if (i->partsCount) {
emit thumbDocumentReady(uploading, silent, doc, MTP_inputFile(MTP_long(i->thumbId()), MTP_int(i->partsCount), MTP_string(i->file ? i->file->thumbname : (qsl("thumb.") + i->media.thumbExt)), MTP_bytes(i->file ? i->file->thumbmd5 : i->media.jpeg_md5)));
const auto file = (uploadingData.docSize > UseBigFilesFrom)
? MTP_inputFileBig(
MTP_long(uploadingData.id()),
MTP_int(uploadingData.docPartsCount),
MTP_string(uploadingData.filename()))
: MTP_inputFile(
MTP_long(uploadingData.id()),
MTP_int(uploadingData.docPartsCount),
MTP_string(uploadingData.filename()),
MTP_bytes(docMd5));
if (uploadingData.partsCount) {
const auto thumbFilename = uploadingData.file
? uploadingData.file->thumbname
: (qsl("thumb.") + uploadingData.media.thumbExt);
const auto thumbMd5 = uploadingData.file
? uploadingData.file->thumbmd5
: uploadingData.media.jpeg_md5;
const auto thumb = MTP_inputFile(
MTP_long(uploadingData.thumbId()),
MTP_int(uploadingData.partsCount),
MTP_string(thumbFilename),
MTP_bytes(thumbMd5));
emit thumbDocumentReady(
uploadingId,
silent,
file,
thumb);
} else {
emit documentReady(uploading, silent, doc);
emit documentReady(uploadingId, silent, file);
}
}
queue.remove(uploading);
uploading = FullMsgId();
queue.erase(uploadingId);
uploadingId = FullMsgId();
sendNext();
}
return;
}
QByteArray &content(i->file ? i->file->content : i->media.data);
auto &content = uploadingData.file
? uploadingData.file->content
: uploadingData.media.data;
QByteArray toSend;
if (content.isEmpty()) {
if (!i->docFile) {
i->docFile.reset(new QFile(i->file ? i->file->filepath : i->media.file));
if (!i->docFile->open(QIODevice::ReadOnly)) {
if (!uploadingData.docFile) {
const auto filepath = uploadingData.file
? uploadingData.file->filepath
: uploadingData.media.file;
uploadingData.docFile = std::make_unique<QFile>(filepath);
if (!uploadingData.docFile->open(QIODevice::ReadOnly)) {
currentFailed();
return;
}
}
toSend = i->docFile->read(i->docPartSize);
if (i->docSize <= UseBigFilesFrom) {
i->md5Hash.feed(toSend.constData(), toSend.size());
toSend = uploadingData.docFile->read(uploadingData.docPartSize);
if (uploadingData.docSize <= UseBigFilesFrom) {
uploadingData.md5Hash.feed(toSend.constData(), toSend.size());
}
} else {
toSend = content.mid(i->docSentParts * i->docPartSize, i->docPartSize);
if ((i->type() == SendMediaType::File || i->type() == SendMediaType::Audio) && i->docSentParts <= UseBigFilesFrom) {
i->md5Hash.feed(toSend.constData(), toSend.size());
const auto offset = uploadingData.docSentParts
* uploadingData.docPartSize;
toSend = content.mid(offset, uploadingData.docPartSize);
if ((uploadingData.type() == SendMediaType::File
|| uploadingData.type() == SendMediaType::Audio)
&& uploadingData.docSentParts <= UseBigFilesFrom) {
uploadingData.md5Hash.feed(toSend.constData(), toSend.size());
}
}
if (toSend.size() > i->docPartSize || (toSend.size() < i->docPartSize && i->docSentParts + 1 != i->docPartsCount)) {
if ((toSend.size() > uploadingData.docPartSize)
|| ((toSend.size() < uploadingData.docPartSize
&& uploadingData.docSentParts + 1 != uploadingData.docPartsCount))) {
currentFailed();
return;
}
mtpRequestId requestId;
if (i->docSize > UseBigFilesFrom) {
requestId = MTP::send(MTPupload_SaveBigFilePart(MTP_long(i->id()), MTP_int(i->docSentParts), MTP_int(i->docPartsCount), MTP_bytes(toSend)), rpcDone(&Uploader::partLoaded), rpcFail(&Uploader::partFailed), MTP::uploadDcId(todc));
if (uploadingData.docSize > UseBigFilesFrom) {
requestId = MTP::send(
MTPupload_SaveBigFilePart(
MTP_long(uploadingData.id()),
MTP_int(uploadingData.docSentParts),
MTP_int(uploadingData.docPartsCount),
MTP_bytes(toSend)),
rpcDone(&Uploader::partLoaded),
rpcFail(&Uploader::partFailed),
MTP::uploadDcId(todc));
} else {
requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(i->id()), MTP_int(i->docSentParts), MTP_bytes(toSend)), rpcDone(&Uploader::partLoaded), rpcFail(&Uploader::partFailed), MTP::uploadDcId(todc));
requestId = MTP::send(
MTPupload_SaveFilePart(
MTP_long(uploadingData.id()),
MTP_int(uploadingData.docSentParts),
MTP_bytes(toSend)),
rpcDone(&Uploader::partLoaded),
rpcFail(&Uploader::partFailed),
MTP::uploadDcId(todc));
}
docRequestsSent.insert(requestId, i->docSentParts);
dcMap.insert(requestId, todc);
sentSize += i->docPartSize;
sentSizes[todc] += i->docPartSize;
docRequestsSent.emplace(requestId, uploadingData.docSentParts);
dcMap.emplace(requestId, todc);
sentSize += uploadingData.docPartSize;
sentSizes[todc] += uploadingData.docPartSize;
i->docSentParts++;
uploadingData.docSentParts++;
} else {
UploadFileParts::iterator part = parts.begin();
auto part = parts.begin();
mtpRequestId requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(partsOfId), MTP_int(part.key()), MTP_bytes(part.value())), rpcDone(&Uploader::partLoaded), rpcFail(&Uploader::partFailed), MTP::uploadDcId(todc));
requestsSent.insert(requestId, part.value());
dcMap.insert(requestId, todc);
const auto requestId = MTP::send(
MTPupload_SaveFilePart(
MTP_long(partsOfId),
MTP_int(part.key()),
MTP_bytes(part.value())),
rpcDone(&Uploader::partLoaded),
rpcFail(&Uploader::partFailed),
MTP::uploadDcId(todc));
requestsSent.emplace(requestId, part.value());
dcMap.emplace(requestId, todc);
sentSize += part.value().size();
sentSizes[todc] += part.value().size();
@ -222,20 +299,20 @@ void Uploader::sendNext() {
}
void Uploader::cancel(const FullMsgId &msgId) {
uploaded.remove(msgId);
if (uploading == msgId) {
uploaded.erase(msgId);
if (uploadingId == msgId) {
currentFailed();
} else {
queue.remove(msgId);
queue.erase(msgId);
}
}
void Uploader::pause(const FullMsgId &msgId) {
_paused = msgId;
_pausedId = msgId;
}
void Uploader::unpause() {
_paused = FullMsgId();
_pausedId = FullMsgId();
sendNext();
}
@ -245,12 +322,12 @@ void Uploader::confirm(const FullMsgId &msgId) {
void Uploader::clear() {
uploaded.clear();
queue.clear();
for (QMap<mtpRequestId, QByteArray>::const_iterator i = requestsSent.cbegin(), e = requestsSent.cend(); i != e; ++i) {
MTP::cancel(i.key());
for (const auto &[requestId, requestData] : requestsSent) {
MTP::cancel(requestId);
}
requestsSent.clear();
for (QMap<mtpRequestId, int32>::const_iterator i = docRequestsSent.cbegin(), e = docRequestsSent.cend(); i != e; ++i) {
MTP::cancel(i.key());
for (const auto &[requestId, requestIndex] : docRequestsSent) {
MTP::cancel(requestId);
}
docRequestsSent.clear();
dcMap.clear();
@ -263,8 +340,8 @@ void Uploader::clear() {
}
void Uploader::partLoaded(const MTPBool &result, mtpRequestId requestId) {
QMap<mtpRequestId, int32>::iterator j = docRequestsSent.end();
QMap<mtpRequestId, QByteArray>::iterator i = requestsSent.find(requestId);
auto j = docRequestsSent.end();
auto i = requestsSent.find(requestId);
if (i == requestsSent.cend()) {
j = docRequestsSent.find(requestId);
}
@ -273,42 +350,47 @@ void Uploader::partLoaded(const MTPBool &result, mtpRequestId requestId) {
currentFailed();
return;
} else {
QMap<mtpRequestId, int32>::iterator dcIt = dcMap.find(requestId);
auto dcIt = dcMap.find(requestId);
if (dcIt == dcMap.cend()) { // must not happen
currentFailed();
return;
}
int32 dc = dcIt.value();
auto dc = dcIt->second;
dcMap.erase(dcIt);
int32 sentPartSize = 0;
Queue::const_iterator k = queue.constFind(uploading);
auto k = queue.find(uploadingId);
Assert(k != queue.cend());
auto &[fullId, file] = *k;
if (i != requestsSent.cend()) {
sentPartSize = i.value().size();
sentPartSize = i->second.size();
requestsSent.erase(i);
} else {
sentPartSize = k->docPartSize;
sentPartSize = file.docPartSize;
docRequestsSent.erase(j);
}
sentSize -= sentPartSize;
sentSizes[dc] -= sentPartSize;
if (k->type() == SendMediaType::Photo) {
k->fileSentSize += sentPartSize;
PhotoData *photo = App::photo(k->id());
if (photo->uploading() && k->file) {
photo->uploadingData->size = k->file->partssize;
photo->uploadingData->offset = k->fileSentSize;
if (file.type() == SendMediaType::Photo) {
file.fileSentSize += sentPartSize;
const auto photo = App::photo(file.id());
if (photo->uploading() && file.file) {
photo->uploadingData->size = file.file->partssize;
photo->uploadingData->offset = file.fileSentSize;
}
emit photoProgress(k.key());
} else if (k->type() == SendMediaType::File || k->type() == SendMediaType::Audio) {
DocumentData *doc = App::document(k->id());
if (doc->uploading()) {
doc->uploadOffset = (k->docSentParts - docRequestsSent.size()) * k->docPartSize;
if (doc->uploadOffset > doc->size) {
doc->uploadOffset = doc->size;
emit photoProgress(fullId);
} else if (file.type() == SendMediaType::File
|| file.type() == SendMediaType::Audio) {
const auto document = App::document(file.id());
if (document->uploading()) {
const auto doneParts = file.docSentParts
- int(docRequestsSent.size());
document->uploadOffset = doneParts * file.docPartSize;
if (document->uploadOffset > document->size) {
document->uploadOffset = document->size;
}
}
emit documentProgress(k.key());
emit documentProgress(fullId);
}
}
}
@ -319,7 +401,9 @@ void Uploader::partLoaded(const MTPBool &result, mtpRequestId requestId) {
bool Uploader::partFailed(const RPCError &error, mtpRequestId requestId) {
if (MTP::isDefaultHandledError(error)) return false;
if (requestsSent.constFind(requestId) != requestsSent.cend() || docRequestsSent.constFind(requestId) != docRequestsSent.cend()) { // failed to upload current file
// failed to upload current file
if ((requestsSent.find(requestId) != requestsSent.cend())
|| (docRequestsSent.find(requestId) != docRequestsSent.cend())) {
currentFailed();
}
sendNext();

View File

@ -117,28 +117,28 @@ private:
HashMd5 md5Hash;
std::shared_ptr<QFile> docFile;
std::unique_ptr<QFile> docFile;
int32 docSentParts;
int32 docSize;
int32 docPartSize;
int32 docPartsCount;
};
typedef QMap<FullMsgId, File> Queue;
void partLoaded(const MTPBool &result, mtpRequestId requestId);
bool partFailed(const RPCError &err, mtpRequestId requestId);
void currentFailed();
QMap<mtpRequestId, QByteArray> requestsSent;
QMap<mtpRequestId, int32> docRequestsSent;
QMap<mtpRequestId, int32> dcMap;
base::flat_map<mtpRequestId, QByteArray> requestsSent;
base::flat_map<mtpRequestId, int32> docRequestsSent;
base::flat_map<mtpRequestId, int32> dcMap;
uint32 sentSize = 0;
uint32 sentSizes[MTP::kUploadSessionsCount] = { 0 };
FullMsgId uploading, _paused;
Queue queue;
Queue uploaded;
FullMsgId uploadingId;
FullMsgId _pausedId;
std::map<FullMsgId, File> queue;
std::map<FullMsgId, File> uploaded;
QTimer nextTimer, killSessionsTimer;
};

View File

@ -48,21 +48,24 @@ TaskQueue::TaskQueue(QObject *parent, int32 stopTimeoutMs) : QObject(parent), _t
}
}
TaskId TaskQueue::addTask(TaskPtr task) {
TaskId TaskQueue::addTask(std::unique_ptr<Task> &&task) {
const auto result = task->id();
{
QMutexLocker lock(&_tasksToProcessMutex);
_tasksToProcess.push_back(task);
_tasksToProcess.push_back(std::move(task));
}
wakeThread();
return task->id();
return result;
}
void TaskQueue::addTasks(const TasksList &tasks) {
void TaskQueue::addTasks(std::vector<std::unique_ptr<Task>> &&tasks) {
{
QMutexLocker lock(&_tasksToProcessMutex);
_tasksToProcess.append(tasks);
for (auto &task : tasks) {
_tasksToProcess.push_back(std::move(task));
}
}
wakeThread();
@ -85,31 +88,33 @@ void TaskQueue::wakeThread() {
}
void TaskQueue::cancelTask(TaskId id) {
const auto removeFrom = [&](std::deque<std::unique_ptr<Task>> &queue) {
const auto proj = [](const std::unique_ptr<Task> &task) {
return task->id();
};
auto i = ranges::find(queue, id, proj);
if (i != queue.end()) {
queue.erase(i);
}
};
{
QMutexLocker lock(&_tasksToProcessMutex);
for (int32 i = 0, l = _tasksToProcess.size(); i != l; ++i) {
if (_tasksToProcess.at(i)->id() == id) {
_tasksToProcess.removeAt(i);
return;
}
removeFrom(_tasksToProcess);
if (_taskInProcessId == id) {
_taskInProcessId = TaskId();
}
}
QMutexLocker lock(&_tasksToFinishMutex);
for (int32 i = 0, l = _tasksToFinish.size(); i != l; ++i) {
if (_tasksToFinish.at(i)->id() == id) {
_tasksToFinish.removeAt(i);
return;
}
}
removeFrom(_tasksToFinish);
}
void TaskQueue::onTaskProcessed() {
do {
TaskPtr task;
auto task = std::unique_ptr<Task>();
{
QMutexLocker lock(&_tasksToFinishMutex);
if (_tasksToFinish.isEmpty()) break;
task = _tasksToFinish.front();
if (_tasksToFinish.empty()) break;
task = std::move(_tasksToFinish.front());
_tasksToFinish.pop_front();
}
task->finish();
@ -117,7 +122,7 @@ void TaskQueue::onTaskProcessed() {
if (_stopTimer) {
QMutexLocker lock(&_tasksToProcessMutex);
if (_tasksToProcess.isEmpty()) {
if (_tasksToProcess.empty() && !_taskInProcessId) {
_stopTimer->start();
}
}
@ -136,6 +141,7 @@ void TaskQueue::stop() {
}
_tasksToProcess.clear();
_tasksToFinish.clear();
_taskInProcessId = TaskId();
}
TaskQueue::~TaskQueue() {
@ -149,11 +155,13 @@ void TaskQueueWorker::onTaskAdded() {
bool someTasksLeft = false;
do {
TaskPtr task;
auto task = std::unique_ptr<Task>();
{
QMutexLocker lock(&_queue->_tasksToProcessMutex);
if (!_queue->_tasksToProcess.isEmpty()) {
task = _queue->_tasksToProcess.front();
if (!_queue->_tasksToProcess.empty()) {
task = std::move(_queue->_tasksToProcess.front());
_queue->_tasksToProcess.pop_front();
_queue->_taskInProcessId = task->id();
}
}
@ -162,13 +170,13 @@ void TaskQueueWorker::onTaskAdded() {
bool emitTaskProcessed = false;
{
QMutexLocker lockToProcess(&_queue->_tasksToProcessMutex);
if (!_queue->_tasksToProcess.isEmpty() && _queue->_tasksToProcess.front() == task) {
_queue->_tasksToProcess.pop_front();
someTasksLeft = !_queue->_tasksToProcess.isEmpty();
if (_queue->_taskInProcessId == task->id()) {
_queue->_taskInProcessId = TaskId();
someTasksLeft = !_queue->_tasksToProcess.empty();
QMutexLocker lockToFinish(&_queue->_tasksToFinishMutex);
emitTaskProcessed = _queue->_tasksToFinish.isEmpty();
_queue->_tasksToFinish.push_back(task);
emitTaskProcessed = _queue->_tasksToFinish.empty();
_queue->_tasksToFinish.push_back(std::move(task));
}
}
if (emitTaskProcessed) {

View File

@ -114,8 +114,6 @@ public:
}
};
using TaskPtr = std::shared_ptr<Task>;
using TasksList = QList<TaskPtr>;
class TaskQueueWorker;
class TaskQueue : public QObject {
@ -124,8 +122,8 @@ class TaskQueue : public QObject {
public:
TaskQueue(QObject *parent, int32 stopTimeoutMs = 0); // <= 0 - never stop worker
TaskId addTask(TaskPtr task);
void addTasks(const TasksList &tasks);
TaskId addTask(std::unique_ptr<Task> &&task);
void addTasks(std::vector<std::unique_ptr<Task>> &&tasks);
void cancelTask(TaskId id); // this task finish() won't be called
~TaskQueue();
@ -142,7 +140,9 @@ private:
void wakeThread();
TasksList _tasksToProcess, _tasksToFinish;
std::deque<std::unique_ptr<Task>> _tasksToProcess;
std::deque<std::unique_ptr<Task>> _tasksToFinish;
TaskId _taskInProcessId = TaskId();
QMutex _tasksToProcessMutex, _tasksToFinishMutex;
QThread *_thread;
TaskQueueWorker *_worker;

View File

@ -165,9 +165,7 @@ void createLocalKey(const QByteArray &pass, QByteArray *salt, MTP::AuthKeyPtr *r
}
struct FileReadDescriptor {
FileReadDescriptor() : version(0) {
}
int32 version;
int32 version = 0;
QByteArray data;
QBuffer buffer;
QDataStream stream;
@ -2854,7 +2852,8 @@ TaskId startImageLoad(const StorageKey &location, mtpFileLoader *loader) {
if (j == _imagesMap.cend() || !_localLoader) {
return 0;
}
return _localLoader->addTask(std::make_shared<ImageLoadTask>(j->first, location, loader));
return _localLoader->addTask(
std::make_unique<ImageLoadTask>(j->first, location, loader));
}
int32 hasImages() {
@ -2912,7 +2911,8 @@ TaskId startStickerImageLoad(const StorageKey &location, mtpFileLoader *loader)
if (j == _stickerImagesMap.cend() || !_localLoader) {
return 0;
}
return _localLoader->addTask(std::make_shared<StickerImageLoadTask>(j->first, location, loader));
return _localLoader->addTask(
std::make_unique<StickerImageLoadTask>(j->first, location, loader));
}
bool willStickerImageLoad(const StorageKey &location) {
@ -2985,7 +2985,8 @@ TaskId startAudioLoad(const StorageKey &location, mtpFileLoader *loader) {
if (j == _audiosMap.cend() || !_localLoader) {
return 0;
}
return _localLoader->addTask(std::make_shared<AudioLoadTask>(j->first, location, loader));
return _localLoader->addTask(
std::make_unique<AudioLoadTask>(j->first, location, loader));
}
bool copyAudio(const StorageKey &oldLocation, const StorageKey &newLocation) {
@ -3101,7 +3102,8 @@ TaskId startWebFileLoad(const QString &url, webFileLoader *loader) {
if (j == _webFilesMap.cend() || !_localLoader) {
return 0;
}
return _localLoader->addTask(std::make_shared<WebFileLoadTask>(j->first, url, loader));
return _localLoader->addTask(
std::make_unique<WebFileLoadTask>(j->first, url, loader));
}
int32 hasWebFiles() {
@ -3177,7 +3179,8 @@ void countVoiceWaveform(DocumentData *document) {
if (_localLoader) {
voice->waveform.resize(1 + sizeof(TaskId));
voice->waveform[0] = -1; // counting
TaskId taskId = _localLoader->addTask(std::make_shared<CountWaveformTask>(document));
TaskId taskId = _localLoader->addTask(
std::make_unique<CountWaveformTask>(document));
memcpy(voice->waveform.data() + 1, &taskId, sizeof(taskId));
}
}

View File

@ -91,7 +91,8 @@ void DiscreteSlider::setSections(const QStringList &labels) {
}
int DiscreteSlider::getCurrentActiveLeft(TimeMs ms) {
return _a_left.current(ms, _sections.isEmpty() ? 0 : _sections[_selected].left);
const auto left = _sections.empty() ? 0 : _sections[_selected].left;
return _a_left.current(ms, left);
}
template <typename Lambda>
@ -253,9 +254,13 @@ void SettingsSlider::startRipple(int sectionIndex) {
if (index++ == sectionIndex) {
if (!section.ripple) {
auto mask = prepareRippleMask(sectionIndex, section);
section.ripple = std::make_shared<RippleAnimation>(_st.ripple, std::move(mask), [this] { update(); });
section.ripple = std::make_unique<RippleAnimation>(
_st.ripple,
std::move(mask),
[this] { update(); });
}
section.ripple->add(mapFromGlobal(QCursor::pos()) - QPoint(section.left, 0));
const auto point = mapFromGlobal(QCursor::pos());
section.ripple->add(point - QPoint(section.left, 0));
return false;
}
return true;

View File

@ -59,7 +59,7 @@ protected:
int left, width;
QString label;
int labelWidth;
std::shared_ptr<RippleAnimation> ripple;
std::unique_ptr<RippleAnimation> ripple;
};
int getCurrentActiveLeft(TimeMs ms);
@ -91,7 +91,7 @@ private:
int getIndexFromPosition(QPoint pos);
void setSelectedSection(int index);
QList<Section> _sections;
std::vector<Section> _sections;
int _activeIndex = 0;
bool _selectOnPress = true;