mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to download multiple files to custom location.
This commit is contained in:
parent
8bcb30e84d
commit
47bb04b019
1 changed files with 44 additions and 11 deletions
|
@ -76,9 +76,11 @@ void AddAction(
|
||||||
: &st::menuIconDownload;
|
: &st::menuIconDownload;
|
||||||
const auto showToast = documents.empty();
|
const auto showToast = documents.empty();
|
||||||
|
|
||||||
const auto saveImages = [=] {
|
const auto saveImages = [=](const QString &folderPath) {
|
||||||
const auto session = &controller->session();
|
const auto session = &controller->session();
|
||||||
const auto downloadPath = Core::App().settings().downloadPath();
|
const auto downloadPath = folderPath.isEmpty()
|
||||||
|
? Core::App().settings().downloadPath()
|
||||||
|
: folderPath;
|
||||||
const auto path = downloadPath.isEmpty()
|
const auto path = downloadPath.isEmpty()
|
||||||
? File::DefaultDownloadPath(session)
|
? File::DefaultDownloadPath(session)
|
||||||
: (downloadPath == u"tmp"_q)
|
: (downloadPath == u"tmp"_q)
|
||||||
|
@ -121,18 +123,49 @@ void AddAction(
|
||||||
Ui::Toast::Show(Window::Show(controller).toastParent(), config);
|
Ui::Toast::Show(Window::Show(controller).toastParent(), config);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const auto saveDocuments = [=] {
|
const auto saveDocuments = [=](const QString &folderPath) {
|
||||||
for (const auto &pair : documents) {
|
for (const auto &pair : documents) {
|
||||||
DocumentSaveClickHandler::SaveAndTrack(
|
const auto &document = pair.first->owner();
|
||||||
pair.second,
|
const auto &origin = pair.second;
|
||||||
pair.first->owner());
|
if (!folderPath.isEmpty()) {
|
||||||
|
document->save(origin, folderPath + document->filename());
|
||||||
|
} else {
|
||||||
|
DocumentSaveClickHandler::SaveAndTrack(origin, document);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
menu->addAction(text, [=] {
|
menu->addAction(text, [=] {
|
||||||
saveImages();
|
const auto save = [=](const QString &folderPath) {
|
||||||
saveDocuments();
|
saveImages(folderPath);
|
||||||
callback();
|
saveDocuments(folderPath);
|
||||||
|
callback();
|
||||||
|
};
|
||||||
|
if (Core::App().settings().askDownloadPath()) {
|
||||||
|
const auto initialPath = [] {
|
||||||
|
const auto path = Core::App().settings().downloadPath();
|
||||||
|
if (!path.isEmpty() && path != u"tmp"_q) {
|
||||||
|
return path.left(path.size()
|
||||||
|
- (path.endsWith('/') ? 1 : 0));
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}();
|
||||||
|
const auto handleFolder = [=](const QString &result) {
|
||||||
|
if (!result.isEmpty()) {
|
||||||
|
const auto folderPath = result.endsWith('/')
|
||||||
|
? result
|
||||||
|
: (result + '/');
|
||||||
|
save(folderPath);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
FileDialog::GetFolder(
|
||||||
|
nullptr,
|
||||||
|
tr::lng_download_path_choose(tr::now),
|
||||||
|
initialPath,
|
||||||
|
handleFolder);
|
||||||
|
} else {
|
||||||
|
save(QString());
|
||||||
|
}
|
||||||
}, icon);
|
}, icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +176,7 @@ void AddDownloadFilesAction(
|
||||||
not_null<Window::SessionController*> window,
|
not_null<Window::SessionController*> window,
|
||||||
const std::vector<HistoryView::SelectedItem> &selectedItems,
|
const std::vector<HistoryView::SelectedItem> &selectedItems,
|
||||||
not_null<HistoryView::ListWidget*> list) {
|
not_null<HistoryView::ListWidget*> list) {
|
||||||
if (selectedItems.empty() || Core::App().settings().askDownloadPath()) {
|
if (selectedItems.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto docs = Documents();
|
auto docs = Documents();
|
||||||
|
@ -169,7 +202,7 @@ void AddDownloadFilesAction(
|
||||||
not_null<Window::SessionController*> window,
|
not_null<Window::SessionController*> window,
|
||||||
const std::map<HistoryItem*, TextSelection, std::less<>> &items,
|
const std::map<HistoryItem*, TextSelection, std::less<>> &items,
|
||||||
not_null<HistoryInner*> list) {
|
not_null<HistoryInner*> list) {
|
||||||
if (items.empty() || Core::App().settings().askDownloadPath()) {
|
if (items.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto docs = Documents();
|
auto docs = Documents();
|
||||||
|
|
Loading…
Add table
Reference in a new issue