diff --git a/app/settings.py b/app/settings.py index 28c1c78b..431e12c0 100644 --- a/app/settings.py +++ b/app/settings.py @@ -196,6 +196,14 @@ class Settings: def language(self, value): self._settings["language"] = value + @property + def load_last_config(self): + return self._settings.get("load_last_config", False) + + @load_last_config.setter + def load_last_config(self, value): + self._settings["load_last_config"] = value + @property def host(self): return self._cp_settings.get("host", self.get_default("host")) diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index f58c9cc4..a15beba8 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -290,9 +290,15 @@ class Application(Gtk.Application): def do_startup(self): Gtk.Application.do_startup(self) - self.init_profiles() self.init_drag_and_drop() self.init_colors() + if self._settings.load_last_config: + config = self._settings.get("last_config") or {} + self.init_profiles(config.get("last_profile", None)) + last_bouquet = config.get("last_bouquet", None) + self.open_data(callback=lambda: self.open_bouquet(last_bouquet)) + else: + self.init_profiles() gen = self.init_http_api() GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_LOW) @@ -303,7 +309,11 @@ class Application(Gtk.Application): def do_shutdown(self): """ Performs shutdown tasks """ - self._settings.save() # storing current config + if self._settings.load_last_config: + self._settings.add("last_config", {"last_profile": self._settings.current_profile, + "last_bouquet": self._current_bq_name}) + self._settings.save() # storing current settings + if self._player: self._player.release() Gtk.Application.do_shutdown(self) @@ -318,9 +328,11 @@ class Application(Gtk.Application): self.activate() return 0 - def init_profiles(self): + def init_profiles(self, profile=None): self.update_profiles() - self._profile_combo_box.set_active_id(self._settings.default_profile) + self._profile_combo_box.set_active_id(profile if profile else self._settings.default_profile) + if profile: + self.set_profile(profile) def init_drag_and_drop(self): """ Enable drag-and-drop """ @@ -855,12 +867,12 @@ class Application(Gtk.Application): return self.open_data(response) - def open_data(self, data_path=None): + def open_data(self, data_path=None, callback=None): """ Opening data and fill views. """ - gen = self.update_data(data_path) + gen = self.update_data(data_path, callback) GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_DEFAULT_IDLE) - def update_data(self, data_path): + def update_data(self, data_path, callback=None): self._wait_dialog.show() yield True @@ -892,6 +904,8 @@ class Application(Gtk.Application): yield from self.append_data(bouquets, services) finally: self._wait_dialog.hide() + if callback: + callback() yield True def append_data(self, bouquets, services): @@ -956,6 +970,17 @@ class Application(Gtk.Application): if extra_services: self._extra_bouquets[bq_id] = extra_services + @run_idle + def open_bouquet(self, name): + """ Find and open bouquet by name """ + for r in self._bouquets_model: + for i in r.iterchildren(): + if i[Column.BQ_NAME] == name: + self._bouquets_view.expand_row(self._bouquets_model.get_path(r.iter), Column.BQ_NAME) + self._bouquets_view.set_cursor(i.path) + self._bouquets_view.row_activated(i.path, self._bouquets_view.get_column(Column.BQ_NAME)) + break + def append_services(self, services): for srv in services: # adding channels to dict with fav_id as keys @@ -1202,14 +1227,17 @@ class Application(Gtk.Application): active = self._profile_combo_box.get_active_text() if active in self._settings.profiles: - self._settings.current_profile = active - self._s_type = self._settings.setting_type - self._profile_combo_box.set_tooltip_text(self._profile_combo_box.get_tooltip_text() + self._settings.host) - self.update_profile_label() + self.set_profile(active) gen = self.init_http_api() GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_LOW) self.open_data() + def set_profile(self, active): + self._settings.current_profile = active + self._s_type = self._settings.setting_type + self._profile_combo_box.set_tooltip_text(self._profile_combo_box.get_tooltip_text() + self._settings.host) + self.update_profile_label() + def update_profiles(self): self._profile_combo_box.remove_all() for p in self._settings.profiles: diff --git a/app/ui/settings_dialog.glade b/app/ui/settings_dialog.glade index 61c21fc2..166696c9 100644 --- a/app/ui/settings_dialog.glade +++ b/app/ui/settings_dialog.glade @@ -1291,7 +1291,7 @@ Author: Dmitriy Yefremov False vertical - + True False 5 @@ -1356,6 +1356,64 @@ Author: Dmitriy Yefremov 0 + + + True + False + 5 + 5 + 5 + 5 + 0 + in + + + True + False + 5 + 5 + 5 + 5 + + + True + False + start + 5 + 5 + Load the last open configuration at program startup + + + True + True + 0 + + + + + True + True + center + + + False + True + end + 1 + + + + + + + + + + False + True + 1 + + True diff --git a/app/ui/settings_dialog.py b/app/ui/settings_dialog.py index 3d5d1fc7..03e25a56 100644 --- a/app/ui/settings_dialog.py +++ b/app/ui/settings_dialog.py @@ -95,6 +95,7 @@ class SettingsDialog: self._set_color_switch = builder.get_object("set_color_switch") self._new_color_button = builder.get_object("new_color_button") self._extra_color_button = builder.get_object("extra_color_button") + self._load_on_startup_switch = builder.get_object("load_on_startup_switch") # HTTP API self._support_http_api_switch = builder.get_object("support_http_api_switch") self._enable_y_dl_switch = builder.get_object("enable_y_dl_switch") @@ -198,6 +199,7 @@ class SettingsDialog: self._before_save_switch.set_active(self._settings.backup_before_save) self._before_downloading_switch.set_active(self._settings.backup_before_downloading) self.set_fav_click_mode(self._settings.fav_click_mode) + self._load_on_startup_switch.set_active(self._settings.load_last_config) if self._s_type is SettingsType.ENIGMA_2: self._support_ver5_switch.set_active(self._settings.v5_support) @@ -244,6 +246,7 @@ class SettingsDialog: self._ext_settings.backup_before_downloading = self._before_downloading_switch.get_active() self._ext_settings.fav_click_mode = self.get_fav_click_mode() self._ext_settings.language = self._lang_combo_box.get_active_id() + self._ext_settings.load_last_config = self._load_on_startup_switch.get_active() if self._s_type is SettingsType.ENIGMA_2: self._ext_settings.use_colors = self._set_color_switch.get_active()