diff --git a/CHANGELOG.md b/CHANGELOG.md index a8ad61d..5df1c4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. ## UNRELEASED ### Added +- Add a "Recursive Compression" setting. - Add Bulgarian translation. Thank's to @twlvnn. - Add Hindi translation. Thank's to @Scrambled777. @@ -12,6 +13,7 @@ All notable changes to this project will be documented in this file. ### Fixed - Fix opening files with "Open With...". Thank's to @ARAKHN1D. +- Fix DnD with nested folders (recursive). ## 1.9.1 - 2024-04-12 ### Fixed diff --git a/data/com.github.huluti.Curtail.gschema.xml b/data/com.github.huluti.Curtail.gschema.xml index 7912891..b204e32 100644 --- a/data/com.github.huluti.Curtail.gschema.xml +++ b/data/com.github.huluti.Curtail.gschema.xml @@ -6,6 +6,11 @@ Save into a new file Save the compressed image into a new file. + + true + Enable recursive compression in folders + This setting enable compression in a recursive way in folders. + true Keep metadata diff --git a/data/ui/menu.ui b/data/ui/menu.ui index 1ff216f..0fc545b 100644 --- a/data/ui/menu.ui +++ b/data/ui/menu.ui @@ -3,7 +3,7 @@
- Bulk Compress Directory (Recursive) + Bulk Compress Directory win.convert-dir diff --git a/data/ui/preferences.ui b/data/ui/preferences.ui index a972cec..8b4ed79 100644 --- a/data/ui/preferences.ui +++ b/data/ui/preferences.ui @@ -26,6 +26,18 @@ New File Suffix + + + Recursive Compression + Enable or disable recursive compression through subdirectories + toggle_recursive + + + center + + + + Keep Metadata @@ -76,8 +88,8 @@ - compression - Compression + formats + Formats image-x-generic-symbolic diff --git a/src/preferences.py b/src/preferences.py index 315cffc..a520465 100644 --- a/src/preferences.py +++ b/src/preferences.py @@ -26,6 +26,7 @@ SETTINGS_SCHEMA = 'com.github.huluti.Curtail' class CurtailPrefsWindow(Adw.PreferencesWindow): __gtype_name__ = 'CurtailPrefsWindow' + toggle_recursive = Gtk.Template.Child() toggle_metadata = Gtk.Template.Child() toggle_file_attributes = Gtk.Template.Child() toggle_new_file = Gtk.Template.Child() @@ -53,6 +54,11 @@ class CurtailPrefsWindow(Adw.PreferencesWindow): def build_ui(self): # Compression settings + # Recursive + self.toggle_recursive.set_active(self._settings.get_boolean('recursive')) + self.toggle_recursive.connect('notify::active', self.on_bool_changed, + 'recursive') + # Keep metadata self.toggle_metadata.set_active(self._settings.get_boolean('metadata')) self.toggle_metadata.connect('notify::active', self.on_bool_changed, diff --git a/src/tools.py b/src/tools.py index dd87ff4..af47f9d 100644 --- a/src/tools.py +++ b/src/tools.py @@ -109,15 +109,26 @@ def create_image_from_file(filename, max_width, max_height): return image + def get_image_files_from_folder(folder_path): + images = [] + for file in os.listdir(folder_path): + path = os.path.join(folder_path, file) + if os.path.isfile(path): + if get_file_type(path) is not None: + image_file = Gio.File.new_for_path(path) + images.append(image_file) + return images + + +def get_image_files_from_folder_recursive(folder_path): images = [] for root, dirs, files in os.walk(folder_path): for file in files: path = os.path.join(root, file) - if get_file_type(path) != None: + if get_file_type(path) is not None: image_file = Gio.File.new_for_path(path) images.append(image_file) - return images def debug_infos(): diff --git a/src/window.py b/src/window.py index 0f0f37d..7ef979d 100644 --- a/src/window.py +++ b/src/window.py @@ -197,8 +197,7 @@ class CurtailWindow(Adw.ApplicationWindow): filenames = list() for file in files: filenames.append(file.get_uri()) - final_filenames = self.handle_filenames(filenames) - self.compress_filenames(final_filenames) + self.compress_filenames(filenames) dialog.open_multiple(self, None, handle_response) @@ -210,13 +209,8 @@ class CurtailWindow(Adw.ApplicationWindow): if response == "compress": filenames = list() for folder in folders: - images = get_image_files_from_folder(folder.get_path()) - - for image in images: - filenames.append(image.get_uri()) - - final_filenames = self.handle_filenames(filenames) - self.compress_filenames(final_filenames) + filenames.append(folder.get_path()) + self.compress_filenames(filenames) try: folders = dialog.select_multiple_folders_finish(result) @@ -261,9 +255,7 @@ class CurtailWindow(Adw.ApplicationWindow): filenames = [] for file in files: filenames.append(file.get_uri()) - - final_filenames = self.handle_filenames(filenames) - self.compress_filenames(final_filenames) + self.compress_filenames(filenames) def handle_filenames(self, filenames): final_filenames = [] @@ -273,9 +265,13 @@ class CurtailWindow(Adw.ApplicationWindow): path = Path(filename) if path.is_dir(): - for new_filename in path.rglob("*"): - new_filename = self.clean_filename(new_filename) - final_filenames.append(new_filename) + if self._settings.get_boolean('recursive'): + images = get_image_files_from_folder_recursive(path) + else: + images = get_image_files_from_folder(path) + for image in images: + image = self.clean_filename(image) + final_filenames.append(image) else: final_filenames.append(filename) @@ -307,6 +303,8 @@ class CurtailWindow(Adw.ApplicationWindow): return new_filename def compress_filenames(self, filenames): + filenames = self.handle_filenames(filenames) + result_items = [] for filename in filenames: error_message = False