mirror of
https://github.com/Huluti/Curtail.git
synced 2024-09-11 06:05:33 +03:00
Add a recursive setting - fix #219
This commit is contained in:
parent
b05e9044a4
commit
fb987241e8
@ -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
|
||||
|
@ -6,6 +6,11 @@
|
||||
<summary>Save into a new file</summary>
|
||||
<description>Save the compressed image into a new file.</description>
|
||||
</key>
|
||||
<key type="b" name="recursive">
|
||||
<default>true</default>
|
||||
<summary>Enable recursive compression in folders</summary>
|
||||
<description>This setting enable compression in a recursive way in folders.</description>
|
||||
</key>
|
||||
<key type="b" name="metadata">
|
||||
<default>true</default>
|
||||
<summary>Keep metadata</summary>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<menu id="window-menu">
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">Bulk Compress Directory (Recursive)</attribute>
|
||||
<attribute name="label" translatable="yes">Bulk Compress Directory</attribute>
|
||||
<attribute name="action">win.convert-dir</attribute>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -26,6 +26,18 @@
|
||||
<property name="title" translatable="yes">New File Suffix</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwActionRow">
|
||||
<property name="title" translatable="yes">Recursive Compression</property>
|
||||
<property name="subtitle" translatable="yes">Enable or disable recursive compression through subdirectories</property>
|
||||
<property name="activatable-widget">toggle_recursive</property>
|
||||
<child>
|
||||
<object class="GtkSwitch" id="toggle_recursive">
|
||||
<property name="valign">center</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwActionRow">
|
||||
<property name="title" translatable="yes">Keep Metadata</property>
|
||||
@ -76,8 +88,8 @@
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwPreferencesPage">
|
||||
<property name="name">compression</property>
|
||||
<property name="title" translatable="yes">Compression</property>
|
||||
<property name="name">formats</property>
|
||||
<property name="title" translatable="yes">Formats</property>
|
||||
<property name="icon-name">image-x-generic-symbolic</property>
|
||||
<child>
|
||||
<object class="AdwPreferencesGroup">
|
||||
|
@ -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,
|
||||
|
15
src/tools.py
15
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():
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user