mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Allowed to save not loaded photos from bulk download menu item.
This commit is contained in:
parent
ed345e0823
commit
1b5b9f46d2
1 changed files with 69 additions and 36 deletions
|
@ -35,7 +35,7 @@ namespace Menu {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using Documents = std::vector<std::pair<not_null<DocumentData*>, FullMsgId>>;
|
using Documents = std::vector<std::pair<not_null<DocumentData*>, FullMsgId>>;
|
||||||
using Photos = std::vector<std::shared_ptr<Data::PhotoMedia>>;
|
using Photos = std::vector<std::pair<not_null<PhotoData*>, FullMsgId>>;
|
||||||
|
|
||||||
[[nodiscard]] bool Added(
|
[[nodiscard]] bool Added(
|
||||||
HistoryItem *item,
|
HistoryItem *item,
|
||||||
|
@ -44,12 +44,8 @@ using Photos = std::vector<std::shared_ptr<Data::PhotoMedia>>;
|
||||||
if (item && !item->forbidsForward()) {
|
if (item && !item->forbidsForward()) {
|
||||||
if (const auto media = item->media()) {
|
if (const auto media = item->media()) {
|
||||||
if (const auto photo = media->photo()) {
|
if (const auto photo = media->photo()) {
|
||||||
if (const auto view = photo->activeMediaView()) {
|
photos.emplace_back(photo, item->fullId());
|
||||||
if (view->loaded()) {
|
return true;
|
||||||
photos.push_back(view);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (const auto document = media->document()) {
|
} else if (const auto document = media->document()) {
|
||||||
documents.emplace_back(document, item->fullId());
|
documents.emplace_back(document, item->fullId());
|
||||||
return true;
|
return true;
|
||||||
|
@ -71,7 +67,7 @@ void AddAction(
|
||||||
const auto icon = documents.empty()
|
const auto icon = documents.empty()
|
||||||
? &st::menuIconSaveImage
|
? &st::menuIconSaveImage
|
||||||
: &st::menuIconDownload;
|
: &st::menuIconDownload;
|
||||||
const auto showToast = documents.empty();
|
const auto shouldShowToast = documents.empty();
|
||||||
|
|
||||||
const auto weak = base::make_weak(controller);
|
const auto weak = base::make_weak(controller);
|
||||||
const auto saveImages = [=](const QString &folderPath) {
|
const auto saveImages = [=](const QString &folderPath) {
|
||||||
|
@ -91,38 +87,75 @@ void AddAction(
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDir().mkpath(path);
|
QDir().mkpath(path);
|
||||||
const auto fullPath = [&](int i) {
|
|
||||||
return filedialogDefaultName(
|
const auto showToast = !shouldShowToast
|
||||||
u"photo_"_q + QString::number(i),
|
? Fn<void(const QString &)>(nullptr)
|
||||||
u".jpg"_q,
|
: [=](const QString &lastPath) {
|
||||||
path);
|
const auto filter = [lastPath](const auto ...) {
|
||||||
};
|
File::ShowInFolder(lastPath);
|
||||||
auto lastPath = QString();
|
return false;
|
||||||
for (auto i = 0; i < photos.size(); i++) {
|
};
|
||||||
lastPath = fullPath(i + 1);
|
controller->showToast({
|
||||||
photos[i]->saveToFile(lastPath);
|
.text = (photos.size() > 1
|
||||||
|
? tr::lng_mediaview_saved_images_to
|
||||||
|
: tr::lng_mediaview_saved_to)(
|
||||||
|
tr::now,
|
||||||
|
lt_downloads,
|
||||||
|
Ui::Text::Link(
|
||||||
|
tr::lng_mediaview_downloads(tr::now),
|
||||||
|
"internal:show_saved_message"),
|
||||||
|
Ui::Text::WithEntities),
|
||||||
|
.st = &st::defaultToast,
|
||||||
|
.filter = filter,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
auto views = std::vector<std::shared_ptr<Data::PhotoMedia>>();
|
||||||
|
for (const auto &[photo, fullId] : photos) {
|
||||||
|
if (const auto view = photo->createMediaView()) {
|
||||||
|
view->wanted(Data::PhotoSize::Large, fullId);
|
||||||
|
views.push_back(view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showToast) {
|
const auto finalCheck = [=] {
|
||||||
const auto filter = [lastPath](const auto ...) {
|
for (const auto &[photo, _] : photos) {
|
||||||
File::ShowInFolder(lastPath);
|
if (photo->loading()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto saveToFiles = [=] {
|
||||||
|
const auto fullPath = [&](int i) {
|
||||||
|
return filedialogDefaultName(
|
||||||
|
u"photo_"_q + QString::number(i),
|
||||||
|
u".jpg"_q,
|
||||||
|
path);
|
||||||
};
|
};
|
||||||
controller->showToast({
|
auto lastPath = QString();
|
||||||
.text = (photos.size() > 1
|
for (auto i = 0; i < views.size(); i++) {
|
||||||
? tr::lng_mediaview_saved_images_to
|
lastPath = fullPath(i + 1);
|
||||||
: tr::lng_mediaview_saved_to)(
|
views[i]->saveToFile(lastPath);
|
||||||
tr::now,
|
}
|
||||||
lt_downloads,
|
if (showToast) {
|
||||||
Ui::Text::Link(
|
showToast(lastPath);
|
||||||
tr::lng_mediaview_downloads(tr::now),
|
}
|
||||||
"internal:show_saved_message"),
|
};
|
||||||
Ui::Text::WithEntities),
|
|
||||||
.st = &st::defaultToast,
|
if (finalCheck()) {
|
||||||
.filter = filter,
|
saveToFiles();
|
||||||
});
|
} else {
|
||||||
|
auto lifetime = std::make_shared<rpl::lifetime>();
|
||||||
|
session->downloaderTaskFinished(
|
||||||
|
) | rpl::start_with_next([=]() mutable {
|
||||||
|
if (finalCheck()) {
|
||||||
|
saveToFiles();
|
||||||
|
base::take(lifetime)->destroy();
|
||||||
|
}
|
||||||
|
}, *lifetime);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const auto saveDocuments = [=](const QString &folderPath) {
|
const auto saveDocuments = [=](const QString &folderPath) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue