From adbc9ad32251a53cdb822e8868450baabe34574c Mon Sep 17 00:00:00 2001 From: DYefremov Date: Tue, 24 Jan 2023 23:02:28 +0300 Subject: [PATCH] option 'replace existing' for import dialog (#127) --- app/ui/imports.glade | 62 +++++++++++++++++++++++++++++++++++--------- app/ui/imports.py | 14 +++++++--- app/ui/main.py | 19 +++++++++++++- 3 files changed, 78 insertions(+), 17 deletions(-) diff --git a/app/ui/imports.glade b/app/ui/imports.glade index 2f18be04..4996806f 100644 --- a/app/ui/imports.glade +++ b/app/ui/imports.glade @@ -3,7 +3,7 @@ The MIT License (MIT) -Copyright (c) 2018-2022 Dmitriy Yefremov +Copyright (c) 2018-2023 Dmitriy Yefremov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -27,11 +27,12 @@ Author: Dmitriy Yefremov --> - + + - + @@ -217,7 +218,6 @@ Author: Dmitriy Yefremov True True Bouquets and services - center import_image True @@ -229,20 +229,58 @@ Author: Dmitriy Yefremov - - Details + True - True - False - True - details_image - True + False + 5 + + + True + False + Replace existing + + + False + True + 0 + + + + + True + True + center + + + False + True + 1 + + + + + True + True + False + True + Details + 5 + details_image + True + + + False + True + end + 2 + + False True end - 1 + 2 diff --git a/app/ui/imports.py b/app/ui/imports.py index 7b26a75b..963f7fec 100644 --- a/app/ui/imports.py +++ b/app/ui/imports.py @@ -144,6 +144,7 @@ class ImportDialog: self._dialog_window.set_transient_for(app.app_window) self._info_bar = builder.get_object("info_bar") self._message_label = builder.get_object("message_label") + self._replace_existing_switch = builder.get_object("replace_existing_switch") # Bouquets page. self._bq_model = builder.get_object("bq_list_store") self._bq_view = builder.get_object("bq_view") @@ -168,9 +169,9 @@ class ImportDialog: button = builder.get_object("import_button") actions_box.remove(button) header_bar.pack_start(button) - button = builder.get_object("details_button") - actions_box.remove(button) - header_bar.pack_end(button) + extra_box = builder.get_object("extra_header_box") + actions_box.remove(extra_box) + header_bar.pack_end(extra_box) self._dialog_window.set_titlebar(header_bar) window_size = self._settings.get("import_dialog_window_size") @@ -266,9 +267,10 @@ class ImportDialog: if show_dialog(DialogType.QUESTION, self._dialog_window) != Gtk.ResponseType.OK: return - replace_existing = False + replace_existing = self._replace_existing_switch.get_active() services = [] current_services = self._app.current_services + to_replace = {} for row in self._sat_model: if row[-1]: @@ -277,10 +279,14 @@ class ImportDialog: for s in filter(lambda srv: srv.fav_id not in skip, self._sat_services.get(sat[0], ())): if replace_existing and s.fav_id in self._ids: current_services[s.fav_id] = s + to_replace[s.fav_id] = s elif s.fav_id not in self._ids: services.append(s) self._append((), services) + if to_replace: + self._app.emit("services_update", to_replace) + self._dialog_window.destroy() @run_idle diff --git a/app/ui/main.py b/app/ui/main.py index 689e4ebe..559f0ebd 100644 --- a/app/ui/main.py +++ b/app/ui/main.py @@ -308,6 +308,8 @@ class Application(Gtk.Application): GObject.TYPE_PYOBJECT, (GObject.TYPE_PYOBJECT,)) GObject.signal_new("epg-dat-downloaded", self, GObject.SIGNAL_RUN_LAST, GObject.TYPE_PYOBJECT, (GObject.TYPE_PYOBJECT,)) + GObject.signal_new("services-update", self, GObject.SIGNAL_RUN_LAST, + GObject.TYPE_PYOBJECT, (GObject.TYPE_PYOBJECT,)) GObject.signal_new("iptv-service-edited", self, GObject.SIGNAL_RUN_LAST, GObject.TYPE_PYOBJECT, (GObject.TYPE_PYOBJECT,)) GObject.signal_new("iptv-service-added", self, GObject.SIGNAL_RUN_LAST, @@ -488,6 +490,7 @@ class Application(Gtk.Application): self._logs_box = builder.get_object("logs_box") self._logs_box.pack_start(LogsClient(self), True, True, 0) self._bottom_paned = builder.get_object("bottom_paned") + self.connect("services-update", self.on_services_update) # Send/Receive. self.connect("data-receive", self.on_download) self.connect("data-send", self.on_upload) @@ -1268,6 +1271,20 @@ class Application(Gtk.Application): self._bouquets_buffer.clear() self.update_bouquets_type() + def on_services_update(self, app, services): + """ Updates services in the main model. """ + for r in self._fav_model: + fav_id = r[Column.FAV_ID] + if fav_id in services: + service = services[fav_id] + r[Column.FAV_SERVICE] = service.service + + for r in self._services_model: + fav_id = r[Column.SRV_FAV_ID] + if fav_id in services: + service = services[fav_id] + r[Column.SRV_SERVICE] = service.service + # ***************** Deletion ********************* # def on_delete(self, view): @@ -4270,7 +4287,7 @@ class Application(Gtk.Application): row = model[path][:] srv = self._services.get(row[Column.ALT_FAV_ID], None) if srv and srv.transponder or row[Column.ALT_TYPE] == BqServiceType.IPTV.name: - self._control_tool.on_service_changed(srv.picon_id.rstrip(".png").replace("_", ":")) + self._control_tool.on_services_update(srv.picon_id.rstrip(".png").replace("_", ":")) # ***************** Profile label ********************* #