diff --git a/app/ui/dialogs.glade b/app/ui/dialogs.glade index c38770d8..7cbeb76d 100644 --- a/app/ui/dialogs.glade +++ b/app/ui/dialogs.glade @@ -668,6 +668,7 @@ dmitry.v.yefremov@gmail.com True True True + True @@ -683,6 +684,7 @@ dmitry.v.yefremov@gmail.com True True True + True @@ -772,7 +774,7 @@ dmitry.v.yefremov@gmail.com - + True False Type: @@ -786,7 +788,6 @@ dmitry.v.yefremov@gmail.com True False - 5 stream_type_liststore 0 0 @@ -817,8 +818,7 @@ dmitry.v.yefremov@gmail.com True True - 15 - 15 + False 3 @@ -844,7 +844,7 @@ dmitry.v.yefremov@gmail.com Url: 7 7 - 0 + 0.0099999997764825821 @@ -873,160 +873,183 @@ dmitry.v.yefremov@gmail.com - + True False - - - False - True - 2 - 4 - - - - - True - False - DVB/TS data: - 0.0099999997764825821 - - - - False - True - 5 - - - - - True - False - 2 - 2 - True + vertical + 2 - + True False - Service type - 0 - 0 + False + True + 1 + 0 - + True False - SID + DVB/TS data: + 0.0099999997764825821 + - 1 - 0 + False + True + 1 - + True False - Tr. ID + 2 + 2 + True + + + True + False + Service type + + + 0 + 0 + + + + + True + False + SID + + + 1 + 0 + + + + + True + False + Tr. ID + + + 2 + 0 + + + + + True + False + Net. ID + + + 3 + 0 + + + + + True + False + Namespace + + + 4 + 0 + + + + + True + True + 10 + 10 + gtk-edit + + + + 0 + 1 + + + + + True + True + 10 + 10 + gtk-edit + + + + 1 + 1 + + + + + True + True + 10 + 10 + gtk-edit + + + + 2 + 1 + + + + + True + True + 10 + 10 + gtk-edit + + + + 3 + 1 + + + + + True + True + 10 + 10 + gtk-edit + + + + 4 + 1 + + - 2 - 0 - - - - - True - False - Net. ID - - - 3 - 0 - - - - - True - False - Namespace - - - 4 - 0 - - - - - True - True - 10 - 10 - - - 0 - 1 - - - - - True - True - 10 - 10 - - - 1 - 1 - - - - - True - True - 10 - 10 - - - 2 - 1 - - - - - True - True - 10 - 10 - - - 3 - 1 - - - - - True - True - 10 - 10 - - - 4 - 1 + False + True + 2 False True - 6 + 3 @@ -1052,8 +1075,6 @@ dmitry.v.yefremov@gmail.com iptv_dialog_cancel_button - iptv_dialog_add_button - iptv_dialog_save_button diff --git a/app/ui/dialogs.py b/app/ui/dialogs.py index e1349532..3eee74f5 100644 --- a/app/ui/dialogs.py +++ b/app/ui/dialogs.py @@ -18,7 +18,6 @@ class DialogType(Enum): QUESTION = "question_dialog" ABOUT = "about_dialog" WAIT = "wait_dialog" - IPTV = "iptv_dialog" class WaitDialog: diff --git a/app/ui/iptv.py b/app/ui/iptv.py index c70a22cf..b19c9f79 100644 --- a/app/ui/iptv.py +++ b/app/ui/iptv.py @@ -1,14 +1,21 @@ -from .main_helper import get_base_model -from . import Gtk +import re +from app.eparser.iptv import NEUTRINO_FAV_ID_FORMAT from app.properties import Profile -from .dialogs import get_dialog_from_xml, DialogType, Action +from . import Gtk, Gdk, TEXT_DOMAIN, UI_RESOURCES_PATH +from .dialogs import Action, show_dialog, DialogType +from .main_helper import get_base_model class IptvDialog: def __init__(self, transient, view=None, services=None, bouquets=None, profile=Profile.ENIGMA_2, action=Action.ADD): - builder, dialog = get_dialog_from_xml(DialogType.IPTV, transient) - self._dialog = dialog + handlers = {"on_entry_changed": self.on_entry_changed, "on_save": self.on_save} + builder = Gtk.Builder() + builder.set_translation_domain(TEXT_DOMAIN) + builder.add_objects_from_file(UI_RESOURCES_PATH + "dialogs.glade", ("iptv_dialog", "stream_type_liststore")) + builder.connect_signals(handlers) + + self._dialog = builder.get_object("iptv_dialog") self._dialog.set_transient_for(transient) self._name_entry = builder.get_object("name_entry") self._description_entry = builder.get_object("description_entry") @@ -25,39 +32,61 @@ class IptvDialog: self._stream_type_combobox = builder.get_object("stream_type_combobox") self._action = action self._profile = profile + self._model, self._paths = view.get_selection().get_selected_rows() + self._current_srv = get_base_model(self._model)[self._paths][:] + + self._pattern = re.compile("(?:^[\s]*$|\D)") + # style + self._style_provider = Gtk.CssProvider() + self._style_provider.load_from_path(UI_RESOURCES_PATH + "style.css") + for el in (self._srv_type_entry, self._sid_entry, self._tr_id_entry, self._net_id_entry, self._namespace_entry): + el.get_style_context().add_provider_for_screen(Gdk.Screen.get_default(), self._style_provider, + Gtk.STYLE_PROVIDER_PRIORITY_USER) + if profile is Profile.NEUTRINO_MP: + builder.get_object("iptv_data_box").set_visible(False) + builder.get_object("iptv_type_label").set_visible(False) + self._stream_type_combobox.set_visible(False) if self._action is Action.ADD: self._save_button.set_visible(False) self._add_button.set_visible(True) elif self._action is Action.EDIT: - model, paths = view.get_selection().get_selected_rows() - self.init_data(get_base_model(model)[paths][:]) + self.init_data(self._current_srv) def show(self): - response = self._dialog.run() - if response == Gtk.ResponseType.OK: - self.save() - self._dialog.hide() + self._dialog.run() + self._dialog.destroy() - def save(self): - print(self._action) + def on_save(self, item): + if show_dialog(DialogType.QUESTION, self._dialog) == Gtk.ResponseType.CANCEL: + return + + self.save_enigma2_data()if self._profile is Profile.ENIGMA_2 else self.save_neutrino_data() + self._dialog.destroy() def init_data(self, srv): name, fav_id = srv[2], srv[7] self._name_entry.set_text(name) - if self._profile is Profile.ENIGMA_2: - data, sep, desc = fav_id.partition("#DESCRIPTION:") - self._description_entry.set_text(desc.strip()) - data = data.split(":") - if len(data) < 12: - return - self._srv_type_entry.set_text(data[2]) - self._sid_entry.set_text(data[3]) - self._tr_id_entry.set_text(data[4]) - self._net_id_entry.set_text(data[5]) - self._namespace_entry.set_text(data[6]) - self._url_entry.set_text(data[10].replace("%3a", ":")) - self._update_reference_entry() + self.init_enigma2_data(fav_id) if self._profile is Profile.ENIGMA_2 else self.init_neutrino_data(fav_id) + + def init_enigma2_data(self, fav_id): + data, sep, desc = fav_id.partition("#DESCRIPTION:") + self._description_entry.set_text(desc.strip()) + data = data.split(":") + if len(data) < 12: + return + self._srv_type_entry.set_text(data[2]) + self._sid_entry.set_text(data[3]) + self._tr_id_entry.set_text(data[4]) + self._net_id_entry.set_text(data[5]) + self._namespace_entry.set_text(data[6]) + self._url_entry.set_text(data[10].replace("%3a", ":")) + self._update_reference_entry() + + def init_neutrino_data(self, fav_id): + data = fav_id.split("::") + self._url_entry.set_text(data[0]) + self._description_entry.set_text(data[1]) def _update_reference_entry(self): if self._profile is Profile.ENIGMA_2: @@ -71,6 +100,25 @@ class IptvDialog: def get_type(self): return 1 + def on_entry_changed(self, entry): + if self._pattern.search(entry.get_text()): + entry.set_name("digit-entry") + else: + entry.set_name("GtkEntry") + self._update_reference_entry() + + def save_enigma2_data(self): + pass + + def save_neutrino_data(self): + name = self._name_entry.get_text() + if self._action is Action.EDIT: + id_data = self._current_srv[7].split("::") + id_data[0] = self._url_entry.get_text() + id_data[1] = self._description_entry.get_text() + fav_id = NEUTRINO_FAV_ID_FORMAT.format(*id_data) + self._model.set_value(self._model.get_iter(self._paths), 2, name) + if __name__ == "__main__": pass diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index 8538bf2c..e315e313 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -864,7 +864,8 @@ class MainAppWindow: self.update_bouquet_channels(self.__fav_model, None, bq_selected) def on_iptv(self, item): - IptvDialog(self.__main_window).show() + pass + # IptvDialog(self.__main_window).show() def on_insert_marker(self, view): """ Inserts marker into bouquet services list. """