aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-07-29 00:43:28 +0200
committerdec05eba <dec05eba@protonmail.com>2023-07-29 00:43:28 +0200
commit1139e4a16a76d5de64c87b4075ac570914ef192f (patch)
treecba0936de32ce73e28e1946f5631bbcd0951bc9d
parent1b3312aae47952caa50f8c5f9ca56b16109d1bd7 (diff)
Ctrl+Shift+S: Create a new name for file instead of replacing existing one
-rw-r--r--TODO3
-rw-r--r--src/QuickMedia.cpp30
2 files changed, 31 insertions, 2 deletions
diff --git a/TODO b/TODO
index 20471ee..4232e66 100644
--- a/TODO
+++ b/TODO
@@ -285,4 +285,5 @@ Fix flickering on resize by creating a child window and draw on that. See: https
Add option to get notified on any matrix event type (maybe have a config list with events that we are interested in).
This could be used to get notified when somebody calls us (m.call.invite) with quickmedia doesn't implement, but
we could know when somebody calls us.
- Also mark such room the same way as a mention - it should be put at the top of the room list. \ No newline at end of file
+ Also mark such room the same way as a mention - it should be put at the top of the room list.
+Add command to ignore/hide a room (should also not get notified when you are mentioned in the room). \ No newline at end of file
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 3a42906..86d4f8f 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -7992,6 +7992,33 @@ namespace QuickMedia {
}
}
+ static std::string get_unique_filename(Path directory, Path filename) {
+ Path full_filepath = directory;
+ full_filepath.join(filename);
+ if(get_file_type(full_filepath) == FileType::FILE_NOT_FOUND)
+ return full_filepath.data;
+
+ for(int i = 1; i < 100; ++i) {
+ std::string filename_unique = filename.filename_no_ext() + " (" + std::to_string(i) + ")" + filename.ext();
+ Path full_filepath = directory;
+ full_filepath.join(filename_unique);
+ if(get_file_type(full_filepath) == FileType::FILE_NOT_FOUND)
+ return full_filepath.data;
+ }
+
+ full_filepath = directory;
+ char buffer[10];
+ if(generate_random_characters(buffer, sizeof(buffer), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62)) {
+ std::string new_filename = filename.filename_no_ext() + " ";
+ new_filename.append(buffer, sizeof(buffer));
+ new_filename += filename.ext();
+ full_filepath.join(new_filename);
+ } else {
+ full_filepath.join(filename);
+ }
+ return full_filepath.data;
+ }
+
void Program::download_page(std::string url, std::string download_filename, bool no_dialog) {
window.set_title(("QuickMedia - Select where you want to save " + std::string(url)).c_str());
@@ -8087,7 +8114,8 @@ namespace QuickMedia {
output_filepath = get_config().download.music_directory;
else
output_filepath = get_config().download.file_directory;
- output_filepath += "/" + filename;
+
+ output_filepath = get_unique_filename(output_filepath, filename);
} else {
window.set_visible(true);
output_filepath = file_save_page(filename);