From 75cd78277e7808a2e8d68da16b16c4eecab7871c Mon Sep 17 00:00:00 2001 From: DYefremov Date: Sun, 3 Mar 2019 12:50:40 +0300 Subject: [PATCH] added remove all unused picons --- app/ui/main_app_window.py | 10 +- app/ui/main_helper.py | 27 +- app/ui/main_window.glade | 502 +++++++++++++++++++++----------------- 3 files changed, 299 insertions(+), 240 deletions(-) diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index ae944cdd..823703da 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -25,7 +25,8 @@ from .uicommons import Gtk, Gdk, UI_RESOURCES_PATH, LOCKED_ICON, HIDE_ICON, IPTV from .dialogs import show_dialog, DialogType, get_chooser_dialog, WaitDialog, get_message from .main_helper import insert_marker, move_items, rename, ViewTarget, set_flags, locate_in_services, \ scroll_to, get_base_model, update_picons_data, copy_picon_reference, assign_picon, remove_picon, \ - is_only_one_item_selected, gen_bouquets, BqGenType, get_iptv_url, append_picons, get_selection, get_model_data + is_only_one_item_selected, gen_bouquets, BqGenType, get_iptv_url, append_picons, get_selection, get_model_data, \ + remove_all_unused_picons from .picons_downloader import PiconsDialog from .satellites_dialog import show_satellites_dialog from .settings_dialog import show_settings_dialog @@ -122,6 +123,7 @@ class Application(Gtk.Application): "on_assign_picon": self.on_assign_picon, "on_remove_picon": self.on_remove_picon, "on_reference_picon": self.on_reference_picon, + "on_remove_unused_picons": self.on_remove_unused_picons, "on_filter_toggled": self.on_filter_toggled, "on_search_toggled": self.on_search_toggled, "on_search_down": self.on_search_down, @@ -1821,6 +1823,12 @@ class Application(Gtk.Application): """ Copying picon id to clipboard """ copy_picon_reference(self.get_target_view(view), view, self._services, self._clipboard, self._main_window) + def on_remove_unused_picons(self, item): + if show_dialog(DialogType.QUESTION, self._main_window) == Gtk.ResponseType.CANCEL: + return + + remove_all_unused_picons(self._options.get(self._profile), self._picons, self._services.values()) + def get_target_view(self, view): return ViewTarget.SERVICES if Gtk.Buildable.get_name(view) == "services_tree_view" else ViewTarget.FAV diff --git a/app/ui/main_helper.py b/app/ui/main_helper.py index 4d5dc801..e763e0a1 100644 --- a/app/ui/main_helper.py +++ b/app/ui/main_helper.py @@ -435,15 +435,7 @@ def remove_picon(target, srv_view, fav_view, picons, options): fav_view.get_model().foreach(remove) if target is ViewTarget.SERVICES else get_base_model( srv_view.get_model()).foreach(remove) - pions_path = options.get("picons_dir_path") - backup_path = options.get("data_dir_path") + "backup/picons/" - os.makedirs(os.path.dirname(backup_path), exist_ok=True) - - for p_id in picon_ids: - picons[p_id] = None - src = pions_path + p_id - if os.path.isfile(src): - shutil.move(src, backup_path + p_id) + remove_picons(options, picon_ids, picons) def copy_picon_reference(target, view, services, clipboard, transient): @@ -467,6 +459,23 @@ def copy_picon_reference(target, view, services, clipboard, transient): show_dialog(DialogType.ERROR, transient, "No reference is present!") +def remove_all_unused_picons(options, picons, services): + ids = {s.picon_id for s in services} + pcs = list(filter(lambda x: x not in ids, picons)) + remove_picons(options, pcs, picons) + + +def remove_picons(options, picon_ids, picons): + pions_path = options.get("picons_dir_path") + backup_path = options.get("backup_dir_path") + "picons/" + os.makedirs(os.path.dirname(backup_path), exist_ok=True) + for p_id in picon_ids: + picons[p_id] = None + src = pions_path + p_id + if os.path.isfile(src): + shutil.move(src, backup_path + p_id) + + def is_only_one_item_selected(paths, transient): if len(paths) > 1: show_dialog(DialogType.ERROR, transient, "Please, select only one item!") diff --git a/app/ui/main_window.glade b/app/ui/main_window.glade index c9a2a2d3..69dc3598 100644 --- a/app/ui/main_window.glade +++ b/app/ui/main_window.glade @@ -528,6 +528,11 @@ Author: Dmitriy Yefremov False gtk-remove + + True + False + gtk-remove + True False @@ -800,6 +805,22 @@ Author: Dmitriy Yefremov + + + True + False + + + + + Remove all unused + True + False + remove_all_image + False + + + @@ -823,6 +844,11 @@ Author: Dmitriy Yefremov + + True + False + gtk-remove + False @@ -1023,11 +1049,257 @@ Author: Dmitriy Yefremov False gtk-select-all + + True + False + gtk-select-all + True False gtk-select-all + + True + False + False + + + gtk-goto-last + True + False + True + True + + + + + + + gtk-goto-first + True + False + True + True + + + + + + + True + False + + + + + Create bouquet + True + False + new_image + False + + + True + False + + + For current satellite + True + False + save_as_image_2 + False + + + + + + For current package + True + False + save_as_image + False + + + + + + For current type + True + False + save_as_image_3 + False + + + + + + True + False + + + + + For each satellite + True + False + select_all_image + False + + + + + + For each package + True + False + select_all_image_2 + False + + + + + + For each type + True + False + select_all_image_3 + False + + + + + + + + + + True + False + + + + + gtk-copy + True + False + True + True + + + + + + + gtk-edit + True + False + True + True + + + + + + + gtk-new + False + True + True + + + + + + True + False + + + + + Picon + True + False + insert_image_2 + False + + + True + False + + + Assign + True + False + insert_link_image + False + + + + + + Remove + True + False + clear_image + False + + + + + + True + False + + + + + Copy reference + True + False + copy_image + False + + + + + + True + False + + + + + Remove all unused + True + False + remove_all_image_2 + False + + + + + + + + + + True + False + + + + + gtk-remove + True + False + True + True + + + + + @@ -2943,234 +3215,4 @@ Author: Dmitriy Yefremov - - True - False - gtk-select-all - - - True - False - False - - - gtk-goto-last - True - False - True - True - - - - - - - gtk-goto-first - True - False - True - True - - - - - - - True - False - - - - - Create bouquet - True - False - new_image - False - - - True - False - - - For current satellite - True - False - save_as_image_2 - False - - - - - - For current package - True - False - save_as_image - False - - - - - - For current type - True - False - save_as_image_3 - False - - - - - - True - False - - - - - For each satellite - True - False - select_all_image - False - - - - - - For each package - True - False - slect_all_image_2 - False - - - - - - For each type - True - False - select_all_image_3 - False - - - - - - - - - - True - False - - - - - gtk-copy - True - False - True - True - - - - - - - gtk-edit - True - False - True - True - - - - - - - gtk-new - False - True - True - - - - - - True - False - - - - - Picon - True - False - insert_image_2 - False - - - True - False - - - Assign - True - False - insert_link_image - False - - - - - - Remove - True - False - clear_image - False - - - - - - True - False - - - - - Copy reference - True - False - copy_image - False - - - - - - - - - - True - False - - - - - gtk-remove - True - False - True - True - - - - -