2017-12-30 21:51:57 +03:00
|
|
|
from app.properties import write_config, Profile, get_default_settings
|
2018-04-16 18:50:48 +03:00
|
|
|
from .uicommons import Gtk, UI_RESOURCES_PATH, TEXT_DOMAIN
|
2018-01-11 17:59:59 +03:00
|
|
|
from .main_helper import update_entry_data
|
2017-10-14 13:23:34 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def show_settings_dialog(transient, options):
|
2017-12-30 21:51:57 +03:00
|
|
|
return SettingsDialog(transient, options).show()
|
2017-11-03 23:39:15 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class SettingsDialog:
|
2018-05-28 18:45:31 +03:00
|
|
|
|
2017-11-03 23:39:15 +03:00
|
|
|
def __init__(self, transient, options):
|
2017-12-30 21:51:57 +03:00
|
|
|
handlers = {"on_data_dir_field_icon_press": self.on_data_dir_field_icon_press,
|
2018-01-11 17:59:59 +03:00
|
|
|
"on_picons_dir_field_icon_press": self.on_picons_dir_field_icon_press,
|
2017-12-30 21:51:57 +03:00
|
|
|
"on_profile_changed": self.on_profile_changed,
|
2018-01-10 22:13:25 +03:00
|
|
|
"on_reset": self.on_reset,
|
|
|
|
|
"apply_settings": self.apply_settings}
|
|
|
|
|
|
2017-11-03 23:39:15 +03:00
|
|
|
builder = Gtk.Builder()
|
2018-03-02 17:06:53 +03:00
|
|
|
builder.set_translation_domain(TEXT_DOMAIN)
|
2018-01-10 22:13:25 +03:00
|
|
|
builder.add_objects_from_file(UI_RESOURCES_PATH + "dialogs.glade",
|
|
|
|
|
("settings_dialog", "telnet_timeout_adjustment"))
|
2017-11-03 23:39:15 +03:00
|
|
|
builder.connect_signals(handlers)
|
2017-12-30 21:51:57 +03:00
|
|
|
|
2017-11-03 23:39:15 +03:00
|
|
|
self._dialog = builder.get_object("settings_dialog")
|
|
|
|
|
self._dialog.set_transient_for(transient)
|
|
|
|
|
self._host_field = builder.get_object("host_field")
|
|
|
|
|
self._port_field = builder.get_object("port_field")
|
|
|
|
|
self._login_field = builder.get_object("login_field")
|
|
|
|
|
self._password_field = builder.get_object("password_field")
|
2018-01-10 22:13:25 +03:00
|
|
|
self._telnet_login_field = builder.get_object("telnet_login_field")
|
|
|
|
|
self._telnet_password_field = builder.get_object("telnet_password_field")
|
|
|
|
|
self._telnet_port_field = builder.get_object("telnet_port_field")
|
|
|
|
|
self._telnet_timeout_spin_button = builder.get_object("telnet_timeout_spin_button")
|
2017-11-03 23:39:15 +03:00
|
|
|
self._services_field = builder.get_object("services_field")
|
|
|
|
|
self._user_bouquet_field = builder.get_object("user_bouquet_field")
|
|
|
|
|
self._satellites_xml_field = builder.get_object("satellites_xml_field")
|
|
|
|
|
self._data_dir_field = builder.get_object("data_dir_field")
|
2018-01-10 18:09:44 +03:00
|
|
|
self._picons_field = builder.get_object("picons_field")
|
2018-01-10 12:15:41 +03:00
|
|
|
self._picons_dir_field = builder.get_object("picons_dir_field")
|
2017-12-30 21:51:57 +03:00
|
|
|
self._enigma_radio_button = builder.get_object("enigma_radio_button")
|
|
|
|
|
self._neutrino_radio_button = builder.get_object("neutrino_radio_button")
|
2018-05-28 18:45:31 +03:00
|
|
|
self._support_ver5_check_button = builder.get_object("support_ver5_check_button")
|
2017-12-30 21:51:57 +03:00
|
|
|
|
|
|
|
|
self._options = options
|
|
|
|
|
self._active_profile = options.get("profile")
|
|
|
|
|
self.set_settings()
|
2018-05-28 18:45:31 +03:00
|
|
|
profile = Profile(self._active_profile)
|
|
|
|
|
self._neutrino_radio_button.set_active(profile is Profile.NEUTRINO_MP)
|
|
|
|
|
self._support_ver5_check_button.set_sensitive(profile is not Profile.NEUTRINO_MP)
|
2017-12-30 21:51:57 +03:00
|
|
|
|
|
|
|
|
def show(self):
|
|
|
|
|
response = self._dialog.run()
|
|
|
|
|
if response == Gtk.ResponseType.OK:
|
|
|
|
|
self.apply_settings()
|
|
|
|
|
write_config(self._options)
|
2017-11-03 23:39:15 +03:00
|
|
|
self._dialog.destroy()
|
|
|
|
|
|
2017-12-30 21:51:57 +03:00
|
|
|
return response
|
|
|
|
|
|
2017-11-03 23:39:15 +03:00
|
|
|
def on_data_dir_field_icon_press(self, entry, icon, event_button):
|
2018-01-11 17:59:59 +03:00
|
|
|
update_entry_data(entry, self._dialog, self._options.get(self._options.get("profile")))
|
|
|
|
|
|
|
|
|
|
def on_picons_dir_field_icon_press(self, entry, icon, event_button):
|
|
|
|
|
update_entry_data(entry, self._dialog, self._options.get(self._options.get("profile")))
|
2017-10-27 20:48:35 +03:00
|
|
|
|
2017-12-30 21:51:57 +03:00
|
|
|
def on_profile_changed(self, item):
|
2018-05-28 18:45:31 +03:00
|
|
|
profile = Profile.ENIGMA_2 if self._enigma_radio_button.get_active() else Profile.NEUTRINO_MP
|
|
|
|
|
self.set_profile(profile)
|
|
|
|
|
self._support_ver5_check_button.set_sensitive(profile is Profile.ENIGMA_2)
|
2017-12-30 21:51:57 +03:00
|
|
|
|
|
|
|
|
def set_profile(self, profile):
|
|
|
|
|
self._active_profile = profile.value
|
|
|
|
|
self.set_settings()
|
|
|
|
|
|
|
|
|
|
def on_reset(self, item):
|
|
|
|
|
def_settings = get_default_settings()
|
|
|
|
|
for key in def_settings:
|
|
|
|
|
current = self._options.get(key)
|
|
|
|
|
if type(current) is str:
|
|
|
|
|
continue
|
|
|
|
|
default = def_settings.get(key)
|
|
|
|
|
for k in default:
|
|
|
|
|
current[k] = default.get(k)
|
|
|
|
|
self.set_settings()
|
|
|
|
|
|
|
|
|
|
def set_settings(self):
|
|
|
|
|
options = self._options.get(self._active_profile)
|
2018-01-10 18:09:44 +03:00
|
|
|
self._host_field.set_text(options.get("host", ""))
|
|
|
|
|
self._port_field.set_text(options.get("port", ""))
|
|
|
|
|
self._login_field.set_text(options.get("user", ""))
|
|
|
|
|
self._password_field.set_text(options.get("password", ""))
|
2018-01-10 22:13:25 +03:00
|
|
|
self._telnet_login_field.set_text(options.get("telnet_user", ""))
|
|
|
|
|
self._telnet_password_field.set_text(options.get("telnet_password", ""))
|
|
|
|
|
self._telnet_port_field.set_text(options.get("telnet_port", ""))
|
|
|
|
|
self._telnet_timeout_spin_button.set_value(options.get("telnet_timeout", 5))
|
2018-01-10 18:09:44 +03:00
|
|
|
self._services_field.set_text(options.get("services_path", ""))
|
|
|
|
|
self._user_bouquet_field.set_text(options.get("user_bouquet_path", ""))
|
|
|
|
|
self._satellites_xml_field.set_text(options.get("satellites_xml_path", ""))
|
|
|
|
|
self._picons_field.set_text(options.get("picons_path", ""))
|
|
|
|
|
self._data_dir_field.set_text(options.get("data_dir_path", ""))
|
|
|
|
|
self._picons_dir_field.set_text(options.get("picons_dir_path", ""))
|
2018-05-28 18:45:31 +03:00
|
|
|
if Profile(self._active_profile) is Profile.ENIGMA_2:
|
|
|
|
|
self._support_ver5_check_button.set_active(options.get("v5_support", False))
|
2017-12-30 21:51:57 +03:00
|
|
|
|
2018-01-10 22:13:25 +03:00
|
|
|
def apply_settings(self, item=None):
|
2018-05-28 18:45:31 +03:00
|
|
|
profile = Profile.ENIGMA_2 if self._enigma_radio_button.get_active() else Profile.NEUTRINO_MP
|
|
|
|
|
self._active_profile = profile.value
|
|
|
|
|
self._options["profile"] = self._active_profile
|
2017-12-30 21:51:57 +03:00
|
|
|
options = self._options.get(self._active_profile)
|
|
|
|
|
options["host"] = self._host_field.get_text()
|
|
|
|
|
options["port"] = self._port_field.get_text()
|
|
|
|
|
options["user"] = self._login_field.get_text()
|
|
|
|
|
options["password"] = self._password_field.get_text()
|
2018-01-10 22:13:25 +03:00
|
|
|
options["telnet_user"] = self._telnet_login_field.get_text()
|
|
|
|
|
options["telnet_password"] = self._telnet_password_field.get_text()
|
|
|
|
|
options["telnet_port"] = self._telnet_port_field.get_text()
|
2018-01-18 00:57:58 +03:00
|
|
|
options["telnet_timeout"] = int(self._telnet_timeout_spin_button.get_value())
|
2017-12-30 21:51:57 +03:00
|
|
|
options["services_path"] = self._services_field.get_text()
|
|
|
|
|
options["user_bouquet_path"] = self._user_bouquet_field.get_text()
|
|
|
|
|
options["satellites_xml_path"] = self._satellites_xml_field.get_text()
|
2018-01-10 18:09:44 +03:00
|
|
|
options["picons_path"] = self._picons_field.get_text()
|
2017-12-30 21:51:57 +03:00
|
|
|
options["data_dir_path"] = self._data_dir_field.get_text()
|
2018-01-10 18:09:44 +03:00
|
|
|
options["picons_dir_path"] = self._picons_dir_field.get_text()
|
2018-05-28 18:45:31 +03:00
|
|
|
if profile is Profile.ENIGMA_2:
|
|
|
|
|
options["v5_support"] = self._support_ver5_check_button.get_active()
|
2017-12-30 21:51:57 +03:00
|
|
|
|
2017-10-14 13:23:34 +03:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
pass
|