mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
added Chat Folders for Downloads
This commit is contained in:
parent
57aebdd300
commit
31a901cae1
4 changed files with 70 additions and 18 deletions
|
@ -4094,6 +4094,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_translate_undo" = "Undo";
|
"lng_translate_undo" = "Undo";
|
||||||
|
|
||||||
"lng_downloads_section" = "Downloads";
|
"lng_downloads_section" = "Downloads";
|
||||||
|
"lng_downloads_settings_save_to_chat_folders" = "Save files to chat folders";
|
||||||
|
"lng_downloads_settings_save_to_chat_folders_about" = "When enabled, files will be saved to separate folders named after their source chat.";
|
||||||
"lng_downloads_view_in_chat" = "View in chat";
|
"lng_downloads_view_in_chat" = "View in chat";
|
||||||
"lng_downloads_view_in_section" = "View in downloads";
|
"lng_downloads_view_in_section" = "View in downloads";
|
||||||
"lng_downloads_delete_sure_one" = "Do you want to delete this file?";
|
"lng_downloads_delete_sure_one" = "Do you want to delete this file?";
|
||||||
|
|
|
@ -954,6 +954,9 @@ public:
|
||||||
|
|
||||||
void resetOnLastLogout();
|
void resetOnLastLogout();
|
||||||
|
|
||||||
|
[[nodiscard]] bool saveToFoldersByChat() const { return _saveToFoldersByChat; }
|
||||||
|
void setSaveToFoldersByChat(bool value) { _saveToFoldersByChat = value; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void resolveRecentEmoji() const;
|
void resolveRecentEmoji() const;
|
||||||
|
|
||||||
|
@ -1094,7 +1097,7 @@ private:
|
||||||
|
|
||||||
QByteArray _photoEditorBrush;
|
QByteArray _photoEditorBrush;
|
||||||
|
|
||||||
|
bool _saveToFoldersByChat = false; // Default to disabled
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
|
@ -210,11 +210,10 @@ QString FileNameForSave(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DocumentFileNameForSave(
|
QString DocumentFileNameForSave(not_null<const DocumentData *> data,
|
||||||
not_null<const DocumentData*> data,
|
bool forceSavingAs,
|
||||||
bool forceSavingAs,
|
const QString &already,
|
||||||
const QString &already,
|
const QDir &dir) {
|
||||||
const QDir &dir) {
|
|
||||||
auto alreadySavingFilename = data->loadingFilePath();
|
auto alreadySavingFilename = data->loadingFilePath();
|
||||||
if (!alreadySavingFilename.isEmpty()) {
|
if (!alreadySavingFilename.isEmpty()) {
|
||||||
return alreadySavingFilename;
|
return alreadySavingFilename;
|
||||||
|
@ -253,20 +252,53 @@ QString DocumentFileNameForSave(
|
||||||
} else {
|
} else {
|
||||||
filter = mimeType.filterString() + u";;"_q + FileDialog::AllFilesFilter();
|
filter = mimeType.filterString() + u";;"_q + FileDialog::AllFilesFilter();
|
||||||
}
|
}
|
||||||
caption = data->isAudioFile()
|
caption = data->isAudioFile() ? tr::lng_save_audio_file(tr::now) : tr::lng_save_file(tr::now);
|
||||||
? tr::lng_save_audio_file(tr::now)
|
|
||||||
: tr::lng_save_file(tr::now);
|
|
||||||
prefix = u"doc"_q;
|
prefix = u"doc"_q;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FileNameForSave(
|
// Try to get chat information
|
||||||
&data->session(),
|
QString chatFolder;
|
||||||
caption,
|
|
||||||
filter,
|
// Get window controller
|
||||||
prefix,
|
if (const auto controller = data->session().windows().empty() ? nullptr : data->session().windows().front().get()) {
|
||||||
name,
|
|
||||||
forceSavingAs,
|
// Get the active chat history
|
||||||
dir);
|
if (const auto history = controller->activeChatCurrent().history()) {
|
||||||
|
if (const auto peer = history->peer) {
|
||||||
|
chatFolder = peer->name();
|
||||||
|
// Sanitize folder name
|
||||||
|
chatFolder.replace(QRegularExpression("[\\\\/:*?\"<>|]"), "_");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get base download path
|
||||||
|
auto path = [&]
|
||||||
|
{
|
||||||
|
const auto path = Core::App().settings().downloadPath();
|
||||||
|
if (path.isEmpty()) {
|
||||||
|
return File::DefaultDownloadPath(&data->session());
|
||||||
|
} else if (path == FileDialog::Tmp()) {
|
||||||
|
return data->session().local().tempDirectory();
|
||||||
|
} else {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
|
// Create chat subfolder if we have a chat name and setting is enabled
|
||||||
|
if (!chatFolder.isEmpty() && !path.isEmpty() && !forceSavingAs && Core::App().settings().saveToFoldersByChat()) {
|
||||||
|
// Create full path with chat subfolder
|
||||||
|
QDir baseDir(path);
|
||||||
|
if (!baseDir.exists(chatFolder)) {
|
||||||
|
baseDir.mkdir(chatFolder);
|
||||||
|
}
|
||||||
|
QDir chatDir(path + "/" + chatFolder);
|
||||||
|
|
||||||
|
// Use the chat directory instead of the base directory
|
||||||
|
return FileNameForSave(&data->session(), caption, filter, prefix, name, forceSavingAs, chatDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return FileNameForSave(&data->session(), caption, filter, prefix, name, forceSavingAs, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
Data::FileOrigin StickerData::setOrigin() const {
|
Data::FileOrigin StickerData::setOrigin() const {
|
||||||
|
|
|
@ -1096,6 +1096,21 @@ void SetupDataStorage(
|
||||||
const auto showpath = container->lifetime(
|
const auto showpath = container->lifetime(
|
||||||
).make_state<rpl::event_stream<bool>>();
|
).make_state<rpl::event_stream<bool>>();
|
||||||
|
|
||||||
|
container->add(object_ptr<Ui::Checkbox>(
|
||||||
|
container,
|
||||||
|
tr::lng_downloads_settings_save_to_chat_folders(),
|
||||||
|
Core::App().settings().saveToFoldersByChat(),
|
||||||
|
st::settingsCheckbox),
|
||||||
|
st::settingsCheckboxPadding)->checkedChanges() |
|
||||||
|
rpl::start_with_next(
|
||||||
|
[=](bool checked) {
|
||||||
|
Core::App().settings().setSaveToFoldersByChat(checked);
|
||||||
|
Core::App().saveSettingsDelayed();
|
||||||
|
},
|
||||||
|
container->lifetime());
|
||||||
|
|
||||||
|
Ui::AddDividerText(container, tr::lng_downloads_settings_save_to_chat_folders_about());
|
||||||
|
|
||||||
const auto path = container->add(
|
const auto path = container->add(
|
||||||
object_ptr<Ui::SlideWrap<Button>>(
|
object_ptr<Ui::SlideWrap<Button>>(
|
||||||
container,
|
container,
|
||||||
|
|
Loading…
Add table
Reference in a new issue