mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +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;
|
||||
const auto showToast = documents.empty();
|
||||
|
||||
const auto saveImages = [=] {
|
||||
const auto saveImages = [=](const QString &folderPath) {
|
||||
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()
|
||||
? File::DefaultDownloadPath(session)
|
||||
: (downloadPath == u"tmp"_q)
|
||||
|
@ -121,18 +123,49 @@ void AddAction(
|
|||
Ui::Toast::Show(Window::Show(controller).toastParent(), config);
|
||||
}
|
||||
};
|
||||
const auto saveDocuments = [=] {
|
||||
const auto saveDocuments = [=](const QString &folderPath) {
|
||||
for (const auto &pair : documents) {
|
||||
DocumentSaveClickHandler::SaveAndTrack(
|
||||
pair.second,
|
||||
pair.first->owner());
|
||||
const auto &document = pair.first->owner();
|
||||
const auto &origin = pair.second;
|
||||
if (!folderPath.isEmpty()) {
|
||||
document->save(origin, folderPath + document->filename());
|
||||
} else {
|
||||
DocumentSaveClickHandler::SaveAndTrack(origin, document);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
menu->addAction(text, [=] {
|
||||
saveImages();
|
||||
saveDocuments();
|
||||
callback();
|
||||
const auto save = [=](const QString &folderPath) {
|
||||
saveImages(folderPath);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -143,7 +176,7 @@ void AddDownloadFilesAction(
|
|||
not_null<Window::SessionController*> window,
|
||||
const std::vector<HistoryView::SelectedItem> &selectedItems,
|
||||
not_null<HistoryView::ListWidget*> list) {
|
||||
if (selectedItems.empty() || Core::App().settings().askDownloadPath()) {
|
||||
if (selectedItems.empty()) {
|
||||
return;
|
||||
}
|
||||
auto docs = Documents();
|
||||
|
@ -169,7 +202,7 @@ void AddDownloadFilesAction(
|
|||
not_null<Window::SessionController*> window,
|
||||
const std::map<HistoryItem*, TextSelection, std::less<>> &items,
|
||||
not_null<HistoryInner*> list) {
|
||||
if (items.empty() || Core::App().settings().askDownloadPath()) {
|
||||
if (items.empty()) {
|
||||
return;
|
||||
}
|
||||
auto docs = Documents();
|
||||
|
|
Loading…
Add table
Reference in a new issue