2018-11-04 00:36:07 +03:00
|
|
|
from enum import Enum
|
|
|
|
|
|
|
|
|
|
from app.commons import run_task, run_idle
|
2018-11-08 13:07:24 +03:00
|
|
|
from app.connections import test_telnet, test_ftp, TestException, test_http
|
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
|
|
|
|
|
|
|
|
|
2018-11-04 00:36:07 +03:00
|
|
|
class Property(Enum):
|
|
|
|
|
FTP = "ftp"
|
|
|
|
|
HTTP = "http"
|
|
|
|
|
TELNET = "telnet"
|
|
|
|
|
|
|
|
|
|
|
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,
|
2018-11-04 00:36:07 +03:00
|
|
|
"apply_settings": self.apply_settings,
|
|
|
|
|
"on_connection_test": self.on_connection_test,
|
|
|
|
|
"on_info_bar_close": self.on_info_bar_close}
|
2018-01-10 22:13:25 +03:00
|
|
|
|
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-09-14 14:23:25 +03:00
|
|
|
builder.add_from_file(UI_RESOURCES_PATH + "settings_dialog.glade")
|
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-11-04 00:36:07 +03:00
|
|
|
self._http_login_field = builder.get_object("http_login_field")
|
|
|
|
|
self._http_password_field = builder.get_object("http_password_field")
|
|
|
|
|
self._http_port_field = builder.get_object("http_port_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")
|
2018-11-19 13:37:10 +03:00
|
|
|
self._support_http_api_check_button = builder.get_object("support_http_api_check_button")
|
2018-11-04 00:36:07 +03:00
|
|
|
self._settings_stack = builder.get_object("settings_stack")
|
|
|
|
|
self._info_bar = builder.get_object("info_bar")
|
|
|
|
|
self._message_label = builder.get_object("info_bar_message_label")
|
|
|
|
|
self._test_spinner = builder.get_object("test_spinner")
|
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)
|
2018-11-19 13:37:10 +03:00
|
|
|
self._support_http_api_check_button.set_sensitive(profile is not Profile.NEUTRINO_MP)
|
2018-11-04 00:36:07 +03:00
|
|
|
self._settings_stack.get_child_by_name(Property.HTTP.value).set_visible(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()
|
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
|
2018-11-04 00:36:07 +03:00
|
|
|
self._settings_stack.get_child_by_name(Property.HTTP.value).set_visible(profile is not Profile.NEUTRINO_MP)
|
2018-05-28 18:45:31 +03:00
|
|
|
self.set_profile(profile)
|
|
|
|
|
self._support_ver5_check_button.set_sensitive(profile is Profile.ENIGMA_2)
|
2018-11-19 13:37:10 +03:00
|
|
|
self._support_http_api_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-11-04 00:36:07 +03:00
|
|
|
self._http_login_field.set_text(options.get("http_user", ""))
|
|
|
|
|
self._http_password_field.set_text(options.get("http_password", ""))
|
|
|
|
|
self._http_port_field.set_text(options.get("http_port", "80"))
|
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))
|
2018-11-19 13:37:10 +03:00
|
|
|
self._support_http_api_check_button.set_active(options.get("http_api_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-11-04 00:36:07 +03:00
|
|
|
options["http_user"] = self._http_login_field.get_text()
|
|
|
|
|
options["http_password"] = self._http_password_field.get_text()
|
|
|
|
|
options["http_port"] = self._http_port_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()
|
2018-11-19 13:37:10 +03:00
|
|
|
options["http_api_support"] = self._support_http_api_check_button.get_active()
|
|
|
|
|
|
2018-11-06 23:43:49 +03:00
|
|
|
write_config(self._options)
|
2017-12-30 21:51:57 +03:00
|
|
|
|
2018-11-04 00:36:07 +03:00
|
|
|
@run_task
|
|
|
|
|
def on_connection_test(self, item):
|
|
|
|
|
if self._test_spinner.get_state() is Gtk.StateType.ACTIVE:
|
|
|
|
|
return
|
|
|
|
|
self.show_spinner(True)
|
|
|
|
|
current_property = Property(self._settings_stack.get_visible_child_name())
|
|
|
|
|
if current_property is Property.HTTP:
|
|
|
|
|
self.test_http()
|
|
|
|
|
elif current_property is Property.TELNET:
|
|
|
|
|
self.test_telnet()
|
|
|
|
|
elif current_property is Property.FTP:
|
|
|
|
|
self.test_ftp()
|
|
|
|
|
|
|
|
|
|
def test_http(self):
|
|
|
|
|
user, password = self._http_login_field.get_text(), self._http_password_field.get_text()
|
2018-11-08 13:07:24 +03:00
|
|
|
host, port = self._host_field.get_text(), self._http_port_field.get_text()
|
2018-11-04 00:36:07 +03:00
|
|
|
try:
|
2018-11-08 13:07:24 +03:00
|
|
|
self.show_info_message(test_http(host, port, user, password), Gtk.MessageType.INFO)
|
|
|
|
|
except TestException as e:
|
2018-11-04 00:36:07 +03:00
|
|
|
self.show_info_message(str(e), Gtk.MessageType.ERROR)
|
|
|
|
|
finally:
|
|
|
|
|
self.show_spinner(False)
|
|
|
|
|
|
|
|
|
|
def test_telnet(self):
|
|
|
|
|
timeout = int(self._telnet_timeout_spin_button.get_value())
|
|
|
|
|
host, port = self._host_field.get_text(), self._telnet_port_field.get_text()
|
|
|
|
|
user, password = self._telnet_login_field.get_text(), self._telnet_password_field.get_text()
|
|
|
|
|
try:
|
2018-11-08 13:07:24 +03:00
|
|
|
self.show_info_message(test_telnet(host, port, user, password, timeout), Gtk.MessageType.INFO)
|
2018-11-04 00:36:07 +03:00
|
|
|
self.show_spinner(False)
|
2018-11-08 13:07:24 +03:00
|
|
|
except TestException as e:
|
2018-11-04 00:36:07 +03:00
|
|
|
self.show_info_message(str(e), Gtk.MessageType.ERROR)
|
|
|
|
|
self.show_spinner(False)
|
|
|
|
|
|
|
|
|
|
def test_ftp(self):
|
|
|
|
|
host, port = self._host_field.get_text(), self._port_field.get_text()
|
|
|
|
|
user, password = self._login_field.get_text(), self._password_field.get_text()
|
|
|
|
|
try:
|
2018-11-08 13:07:24 +03:00
|
|
|
self.show_info_message("OK. {}".format(test_ftp(host, port, user, password)), Gtk.MessageType.INFO)
|
|
|
|
|
except TestException as e:
|
2018-11-04 00:36:07 +03:00
|
|
|
self.show_info_message(str(e), Gtk.MessageType.ERROR)
|
|
|
|
|
finally:
|
|
|
|
|
self.show_spinner(False)
|
|
|
|
|
|
|
|
|
|
@run_idle
|
|
|
|
|
def show_info_message(self, text, message_type):
|
|
|
|
|
self._info_bar.set_visible(True)
|
|
|
|
|
self._info_bar.set_message_type(message_type)
|
|
|
|
|
self._message_label.set_text(text)
|
|
|
|
|
|
|
|
|
|
@run_idle
|
|
|
|
|
def show_spinner(self, show):
|
|
|
|
|
self._test_spinner.start() if show else self._test_spinner.stop()
|
|
|
|
|
self._test_spinner.set_state(Gtk.StateType.ACTIVE if show else Gtk.StateType.NORMAL)
|
|
|
|
|
|
|
|
|
|
def on_info_bar_close(self, bar=None, resp=None):
|
|
|
|
|
self._info_bar.set_visible(False)
|
|
|
|
|
|
2017-10-14 13:23:34 +03:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
pass
|