From cb29cf01553675e32719c83157e849cdfe9451f6 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Fri, 6 Mar 2020 11:55:34 +0300 Subject: [PATCH] added new paths settings --- app/settings.py | 68 ++++++++++--- app/ui/settings_dialog.glade | 187 ++++++++++++++++++++++++++++++++++- app/ui/settings_dialog.py | 58 ++++++----- 3 files changed, 270 insertions(+), 43 deletions(-) diff --git a/app/settings.py b/app/settings.py index 74f991ad..4f0510a2 100644 --- a/app/settings.py +++ b/app/settings.py @@ -26,6 +26,8 @@ class Defaults(Enum): NEW_COLOR = "rgb(255,230,204)" EXTRA_COLOR = "rgb(179,230,204)" FAV_CLICK_MODE = 0 + PROFILE_FOLDER_DEFAULT = False + RECORDS_PATH = DATA_PATH + "records/" def get_default_settings(profile_name="default"): @@ -43,14 +45,20 @@ def get_default_settings(profile_name="default"): "use_colors": Defaults.USE_COLORS.value, "new_color": Defaults.NEW_COLOR.value, "extra_color": Defaults.EXTRA_COLOR.value, - "fav_click_mode": Defaults.FAV_CLICK_MODE.value + "fav_click_mode": Defaults.FAV_CLICK_MODE.value, + "profile_folder_is_default": Defaults.PROFILE_FOLDER_DEFAULT.value, + "records_path": Defaults.RECORDS_PATH.value } -def set_local_paths(settings, profile_name): - settings["data_local_path"] = "{}{}/".format(settings["data_local_path"], profile_name) - settings["picons_local_path"] = "{}{}/".format(settings["picons_local_path"], profile_name) - settings["backup_local_path"] = "{}{}/".format(settings["backup_local_path"], profile_name) +def set_local_paths(settings, profile_name, data_path=DATA_PATH, use_profile_folder=False): + settings["data_local_path"] = "{}{}/".format(data_path, profile_name) + if use_profile_folder: + settings["picons_local_path"] = "{}{}/{}/".format(data_path, profile_name, "picons") + settings["backup_local_path"] = "{}{}/{}/".format(data_path, profile_name, "backup") + else: + settings["picons_local_path"] = "{}{}/{}/".format(data_path, "picons", profile_name) + settings["backup_local_path"] = "{}{}/{}/".format(data_path, "backup", profile_name) class SettingsType(IntEnum): @@ -126,7 +134,10 @@ class Settings: def reset(self, force_write=False): for k, v in self.setting_type.get_default_settings().items(): self._cp_settings[k] = v - set_local_paths(self._cp_settings, self._current_profile) + + def_path = self.default_data_path + def_path += "enigma2/" if self.setting_type is SettingsType.ENIGMA_2 else "neutrino/" + set_local_paths(self._cp_settings, self._current_profile, def_path, self.profile_folder_is_default) if force_write: self.save() @@ -335,14 +346,6 @@ class Settings: def satellites_xml_path(self, value): self._cp_settings["satellites_xml_path"] = value - @property - def data_local_path(self): - return self._cp_settings.get("data_local_path", self.get_default("data_local_path")) - - @data_local_path.setter - def data_local_path(self, value): - self._cp_settings["data_local_path"] = value - @property def picons_path(self): return self._cp_settings.get("picons_path", self.get_default("picons_path")) @@ -351,6 +354,32 @@ class Settings: def picons_path(self, value): self._cp_settings["picons_path"] = value + # ***** Local paths ***** # + + @property + def profile_folder_is_default(self): + return self._settings.get("profile_folder_is_default", Defaults.PROFILE_FOLDER_DEFAULT.value) + + @profile_folder_is_default.setter + def profile_folder_is_default(self, value): + self._settings["profile_folder_is_default"] = value + + @property + def default_data_path(self): + return self._settings.get("default_data_path", DATA_PATH) + + @default_data_path.setter + def default_data_path(self, value): + self._settings["default_data_path"] = value + + @property + def data_local_path(self): + return self._cp_settings.get("data_local_path", self.get_default("data_local_path")) + + @data_local_path.setter + def data_local_path(self, value): + self._cp_settings["data_local_path"] = value + @property def picons_local_path(self): return self._cp_settings.get("picons_local_path", self.get_default("picons_local_path")) @@ -367,6 +396,14 @@ class Settings: def backup_local_path(self, value): self._cp_settings["backup_local_path"] = value + @property + def records_path(self): + return self._settings.get("records_path", Defaults.RECORDS_PATH.value) + + @records_path.setter + def records_path(self, value): + self._settings["records_path"] = value + # ***** Program settings ***** @property @@ -451,8 +488,7 @@ class Settings: def get_settings(): - os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True) # create dir if not exist - os.makedirs(os.path.dirname(DATA_PATH), exist_ok=True) + os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True) if not os.path.isfile(CONFIG_FILE) or os.stat(CONFIG_FILE).st_size == 0: write_settings(get_default_settings()) diff --git a/app/ui/settings_dialog.glade b/app/ui/settings_dialog.glade index 88cfe4a5..bcb4e402 100644 --- a/app/ui/settings_dialog.glade +++ b/app/ui/settings_dialog.glade @@ -1286,6 +1286,185 @@ Author: Dmitriy Yefremov Network + + + True + False + vertical + 2 + + + True + False + 5 + 5 + 5 + 5 + 0.019999999552965164 + in + + + True + False + Sets the profile folder as default to store picons, backups, etc. + 5 + 5 + 3 + 3 + + + True + False + Make profile folder as default for the additional data. + + + False + True + 0 + + + + + True + True + + + + False + True + end + 1 + + + + + + + + + + False + True + 0 + + + + + True + False + 5 + 5 + 5 + 2 + True + + + True + False + Default data path: + 0 + 0.019999999552965164 + + + 0 + 0 + + + + + True + True + gtk-edit + folder-open + False + Select + Select + + + + + 0 + 1 + + + + + False + True + 1 + + + + + True + False + 5 + 5 + 5 + 0.019999999552965164 + in + + + True + False + 5 + 5 + 5 + 5 + 2 + True + + + True + False + Streams record path: + 0.019999999552965164 + + + 0 + 0 + + + + + True + True + gtk-edit + folder-open + False + Select + Select + + + + 0 + 1 + + + + + + + True + False + Record: + + + + + False + True + 2 + + + + + paths + Paths + gtk-open + 1 + + True @@ -1458,7 +1637,7 @@ Author: Dmitriy Yefremov True True - + False @@ -1639,7 +1818,7 @@ Author: Dmitriy Yefremov program Program - 1 + 2 @@ -1797,7 +1976,7 @@ Author: Dmitriy Yefremov True True end - + 1 @@ -1969,7 +2148,7 @@ Author: Dmitriy Yefremov extra Extra - 2 + 3 diff --git a/app/ui/settings_dialog.py b/app/ui/settings_dialog.py index 05880556..85014083 100644 --- a/app/ui/settings_dialog.py +++ b/app/ui/settings_dialog.py @@ -1,6 +1,5 @@ import os from enum import Enum -from pathlib import Path from app.commons import run_task, run_idle from app.connections import test_telnet, test_ftp, TestException, test_http, HttpApiException @@ -31,10 +30,12 @@ class SettingsDialog: "on_apply_profile_settings": self.on_apply_profile_settings, "on_connection_test": self.on_connection_test, "on_info_bar_close": self.on_info_bar_close, - "on_set_color_switch_state": self.on_set_color_switch_state, - "on_http_mode_switch_state": self.on_http_mode_switch_state, - "on_yt_dl_switch_state": self.on_yt_dl_switch_state, - "on_send_to_switch_state": self.on_send_to_switch_state, + "on_set_color_switch": self.on_set_color_switch, + "on_http_mode_switch": self.on_http_mode_switch, + "on_yt_dl_switch": self.on_yt_dl_switch, + "on_send_to_switch": self.on_send_to_switch, + "on_default_path_mode_switch": self.on_default_path_mode_switch, + "on_default_data_path_changed": self.on_default_data_path_changed, "on_profile_add": self.on_profile_add, "on_profile_edit": self.on_profile_edit, "on_profile_remove": self.on_profile_remove, @@ -80,6 +81,9 @@ class SettingsDialog: self._picons_field = builder.get_object("picons_field") self._picons_dir_field = builder.get_object("picons_dir_field") self._backup_dir_field = builder.get_object("backup_dir_field") + self._default_data_dir_field = builder.get_object("default_data_dir_field") + self._record_data_dir_field = builder.get_object("record_data_dir_field") + self._default_data_paths_switch = builder.get_object("default_data_paths_switch") # Info bar self._info_bar = builder.get_object("info_bar") self._message_label = builder.get_object("info_bar_message_label") @@ -207,10 +211,13 @@ class SettingsDialog: self._data_dir_field.set_text(self._settings.data_local_path) self._picons_dir_field.set_text(self._settings.picons_local_path) self._backup_dir_field.set_text(self._settings.backup_local_path) + self._default_data_dir_field.set_text(self._settings.default_data_path) + self._record_data_dir_field.set_text(self._settings.records_path) 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) + self._default_data_paths_switch.set_active(self._settings.profile_folder_is_default) if self._s_type is SettingsType.ENIGMA_2: self._support_ver5_switch.set_active(self._settings.v5_support) @@ -263,6 +270,9 @@ class SettingsDialog: 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() + self._ext_settings.profile_folder_is_default = self._default_data_paths_switch.get_active() + self._ext_settings.default_data_path = self._default_data_dir_field.get_text() + self._ext_settings.records_path = self._record_data_dir_field.get_text() if self._s_type is SettingsType.ENIGMA_2: self._ext_settings.use_colors = self._set_color_switch.get_active() @@ -338,22 +348,28 @@ class SettingsDialog: def on_info_bar_close(self, bar=None, resp=None): self._info_bar.set_visible(False) - def on_set_color_switch_state(self, switch, state): + def on_set_color_switch(self, switch, state): self._colors_grid.set_sensitive(state) - def on_http_mode_switch_state(self, switch, state): + def on_http_mode_switch(self, switch, state): self._click_mode_zap_button.set_sensitive(state) if any((self._click_mode_play_button.get_active(), self._click_mode_zap_button.get_active(), self._click_mode_zap_and_play_button.get_active())): self._click_mode_disabled_button.set_active(True) - def on_yt_dl_switch_state(self, switch, state): + def on_yt_dl_switch(self, switch, state): self.show_info_message("Not implemented yet!", Gtk.MessageType.WARNING) - def on_send_to_switch_state(self, switch, state): + def on_send_to_switch(self, switch, state): self.show_info_message("Not implemented yet!", Gtk.MessageType.WARNING) + def on_default_path_mode_switch(self, switch, state): + self._settings.profile_folder_is_default = state + + def on_default_data_path_changed(self, entry): + self._settings.default_data_path = entry.get_text() + def on_profile_add(self, item): model = self._profile_view.get_model() count = 0 @@ -366,10 +382,6 @@ class SettingsDialog: model.append((name, None)) scroll_to(len(model) - 1, self._profile_view) self.on_profile_selected(self._profile_view) - p = name + "/" - self._settings.data_local_path += p - self._settings.picons_local_path += p - self._settings.backup_local_path += p self.on_reset() def on_profile_edit(self, item=None): @@ -392,29 +404,29 @@ class SettingsDialog: def on_profile_edited(self, render, path, new_value): row = self._profile_view.get_model()[path] - p_name = row[0] - if p_name == new_value: + old_name = row[0] + if old_name == new_value: return if new_value in self._profiles: show_dialog(DialogType.ERROR, self._dialog, "A profile with that name exists!") return - p_name = self._profiles.pop(p_name, None) - if p_name: + p_settings = self._profiles.pop(old_name, None) + if p_settings: row[0] = new_value - self._profiles[new_value] = p_name - self.update_local_paths(new_value) + self._profiles[new_value] = p_settings + self.update_local_paths(new_value, old_name) self.on_profile_selected(self._profile_view) - def update_local_paths(self, p_name, force_rename=False): + def update_local_paths(self, p_name, old_name, force_rename=False): data_path = self._settings.data_local_path picons_path = self._settings.picons_local_path backup_path = self._settings.backup_local_path - self._settings.data_local_path = "{}/{}/".format(Path(data_path).parent, p_name) - self._settings.picons_local_path = "{}/{}/".format(Path(picons_path).parent, p_name) - self._settings.backup_local_path = "{}/{}/".format(Path(backup_path).parent, p_name) + self._settings.data_local_path = p_name.join(data_path.rsplit(old_name, 1)) + self._settings.picons_local_path = p_name.join(picons_path.rsplit(old_name, 1)) + self._settings.backup_local_path = p_name.join(backup_path.rsplit(old_name, 1)) if force_rename: try: