2021-08-30 15:04:15 +03:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
#
|
|
|
|
|
|
# The MIT License (MIT)
|
|
|
|
|
|
#
|
2022-01-24 16:39:59 +03:00
|
|
|
|
# Copyright (c) 2018-2022 Dmitriy Yefremov
|
2021-08-30 15:04:15 +03:00
|
|
|
|
#
|
|
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
|
|
#
|
|
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
|
|
#
|
|
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
|
# THE SOFTWARE.
|
|
|
|
|
|
#
|
|
|
|
|
|
# Author: Dmitriy Yefremov
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-27 19:05:37 +03:00
|
|
|
|
import gzip
|
2019-05-04 23:54:58 +03:00
|
|
|
|
import locale
|
2019-04-27 19:05:37 +03:00
|
|
|
|
import os
|
2019-05-04 23:54:58 +03:00
|
|
|
|
import re
|
2019-04-27 19:05:37 +03:00
|
|
|
|
import shutil
|
|
|
|
|
|
import urllib.request
|
2019-04-24 20:27:47 +03:00
|
|
|
|
from enum import Enum
|
2019-06-08 15:45:41 +03:00
|
|
|
|
from urllib.error import HTTPError, URLError
|
2019-04-24 20:27:47 +03:00
|
|
|
|
|
2019-06-03 15:47:04 +03:00
|
|
|
|
from gi.repository import GLib
|
2021-04-28 14:12:59 +03:00
|
|
|
|
|
2022-01-24 19:17:11 +03:00
|
|
|
|
from app.commons import run_idle, run_task, run_with_delay
|
2019-05-04 20:13:57 +03:00
|
|
|
|
from app.connections import download_data, DownloadType
|
2019-04-22 20:25:19 +03:00
|
|
|
|
from app.eparser.ecommons import BouquetService, BqServiceType
|
2021-08-30 15:04:15 +03:00
|
|
|
|
from app.settings import SEP
|
2019-04-22 20:25:19 +03:00
|
|
|
|
from app.tools.epg import EPG, ChannelsParser
|
2021-04-28 14:12:59 +03:00
|
|
|
|
from app.ui.dialogs import get_message, show_dialog, DialogType, get_builder
|
2019-04-30 14:17:45 +03:00
|
|
|
|
from .main_helper import on_popup_menu, update_entry_data
|
2021-10-31 16:09:07 +03:00
|
|
|
|
from .uicommons import Gtk, Gdk, UI_RESOURCES_PATH, Column, EPG_ICON, KeyboardKey, IS_GNOME_SESSION
|
2019-04-18 23:05:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
2019-04-24 20:27:47 +03:00
|
|
|
|
class RefsSource(Enum):
|
2019-04-27 19:05:37 +03:00
|
|
|
|
SERVICES = 0
|
2019-04-24 20:27:47 +03:00
|
|
|
|
XML = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-18 23:05:19 +03:00
|
|
|
|
class EpgDialog:
|
|
|
|
|
|
|
2022-01-24 16:39:59 +03:00
|
|
|
|
def __init__(self, app, bouquet, bouquet_name):
|
2019-04-18 23:05:19 +03:00
|
|
|
|
|
2019-06-08 15:45:41 +03:00
|
|
|
|
handlers = {"on_close_dialog": self.on_close_dialog,
|
|
|
|
|
|
"on_apply": self.on_apply,
|
2019-04-27 19:05:37 +03:00
|
|
|
|
"on_update": self.on_update,
|
2019-04-21 01:18:54 +03:00
|
|
|
|
"on_save_to_xml": self.on_save_to_xml,
|
|
|
|
|
|
"on_auto_configuration": self.on_auto_configuration,
|
|
|
|
|
|
"on_filter_toggled": self.on_filter_toggled,
|
|
|
|
|
|
"on_filter_changed": self.on_filter_changed,
|
|
|
|
|
|
"on_info_bar_close": self.on_info_bar_close,
|
2019-04-22 00:12:04 +03:00
|
|
|
|
"on_popup_menu": on_popup_menu,
|
2019-04-24 21:53:01 +03:00
|
|
|
|
"on_bouquet_popup_menu": self.on_bouquet_popup_menu,
|
|
|
|
|
|
"on_copy_ref": self.on_copy_ref,
|
|
|
|
|
|
"on_assign_ref": self.on_assign_ref,
|
2019-05-07 17:22:18 +03:00
|
|
|
|
"on_reset": self.on_reset,
|
|
|
|
|
|
"on_list_reset": self.on_list_reset,
|
2019-04-22 00:12:04 +03:00
|
|
|
|
"on_drag_begin": self.on_drag_begin,
|
|
|
|
|
|
"on_drag_data_get": self.on_drag_data_get,
|
2019-04-22 20:25:19 +03:00
|
|
|
|
"on_drag_data_received": self.on_drag_data_received,
|
2019-04-25 00:18:49 +03:00
|
|
|
|
"on_resize": self.on_resize,
|
|
|
|
|
|
"on_names_source_changed": self.on_names_source_changed,
|
2019-04-26 22:07:21 +03:00
|
|
|
|
"on_options_save": self.on_options_save,
|
|
|
|
|
|
"on_use_web_source_switch": self.on_use_web_source_switch,
|
2019-04-27 19:05:37 +03:00
|
|
|
|
"on_enable_filtering_switch": self.on_enable_filtering_switch,
|
2019-04-30 14:17:45 +03:00
|
|
|
|
"on_update_on_start_switch": self.on_update_on_start_switch,
|
2019-05-01 13:11:19 +03:00
|
|
|
|
"on_field_icon_press": self.on_field_icon_press,
|
2022-01-24 16:39:59 +03:00
|
|
|
|
"on_key_press": self.on_key_press,
|
|
|
|
|
|
"on_bq_cursor_changed": self.on_bq_cursor_changed}
|
2019-04-18 23:05:19 +03:00
|
|
|
|
|
2022-01-24 16:39:59 +03:00
|
|
|
|
self._app = app
|
2019-05-07 00:04:53 +03:00
|
|
|
|
self._services = {}
|
2022-01-24 16:39:59 +03:00
|
|
|
|
self._ex_services = self._app.current_services
|
|
|
|
|
|
self._ex_fav_model = self._app.fav_view.get_model()
|
|
|
|
|
|
self._settings = self._app.app_settings
|
2019-04-21 01:18:54 +03:00
|
|
|
|
self._bouquet = bouquet
|
2019-06-04 13:31:54 +03:00
|
|
|
|
self._bouquet_name = bouquet_name
|
2019-04-24 21:53:01 +03:00
|
|
|
|
self._current_ref = []
|
2019-04-27 19:05:37 +03:00
|
|
|
|
self._enable_dat_filter = False
|
|
|
|
|
|
self._use_web_source = False
|
2019-05-04 20:13:57 +03:00
|
|
|
|
self._update_epg_data_on_start = False
|
2019-04-27 19:05:37 +03:00
|
|
|
|
self._refs_source = RefsSource.SERVICES
|
2019-06-08 15:45:41 +03:00
|
|
|
|
self._download_xml_is_active = False
|
2019-04-18 23:05:19 +03:00
|
|
|
|
|
2021-09-15 13:12:25 +03:00
|
|
|
|
builder = get_builder(UI_RESOURCES_PATH + "epg.glade", handlers)
|
2019-04-18 23:05:19 +03:00
|
|
|
|
|
|
|
|
|
|
self._dialog = builder.get_object("epg_dialog_window")
|
2022-01-24 16:39:59 +03:00
|
|
|
|
self._dialog.set_transient_for(self._app.app_window)
|
2019-04-22 00:12:04 +03:00
|
|
|
|
self._source_view = builder.get_object("source_view")
|
|
|
|
|
|
self._bouquet_view = builder.get_object("bouquet_view")
|
2019-04-18 23:05:19 +03:00
|
|
|
|
self._bouquet_model = builder.get_object("bouquet_list_store")
|
|
|
|
|
|
self._services_model = builder.get_object("services_list_store")
|
|
|
|
|
|
self._info_bar = builder.get_object("info_bar")
|
|
|
|
|
|
self._message_label = builder.get_object("info_bar_message_label")
|
2019-04-24 21:53:01 +03:00
|
|
|
|
self._assign_ref_popup_item = builder.get_object("bouquet_assign_ref_popup_item")
|
2022-04-03 19:08:08 +03:00
|
|
|
|
self._left_action_box = builder.get_object("left_action_box")
|
2019-06-08 15:45:41 +03:00
|
|
|
|
self._xml_download_progress_bar = builder.get_object("xml_download_progress_bar")
|
2019-04-21 01:18:54 +03:00
|
|
|
|
# Filter
|
|
|
|
|
|
self._filter_bar = builder.get_object("filter_bar")
|
|
|
|
|
|
self._filter_entry = builder.get_object("filter_entry")
|
2022-01-24 19:17:11 +03:00
|
|
|
|
self._filter_auto_switch = builder.get_object("filter_auto_switch")
|
2019-04-21 01:18:54 +03:00
|
|
|
|
self._services_filter_model = builder.get_object("services_filter_model")
|
|
|
|
|
|
self._services_filter_model.set_visible_func(self.services_filter_function)
|
2019-04-30 14:17:45 +03:00
|
|
|
|
# Info
|
|
|
|
|
|
self._source_count_label = builder.get_object("source_count_label")
|
|
|
|
|
|
self._source_info_label = builder.get_object("source_info_label")
|
|
|
|
|
|
self._bouquet_count_label = builder.get_object("bouquet_count_label")
|
|
|
|
|
|
self._bouquet_epg_count_label = builder.get_object("bouquet_epg_count_label")
|
2019-04-25 00:18:49 +03:00
|
|
|
|
# Options
|
2019-04-27 19:05:37 +03:00
|
|
|
|
self._xml_radiobutton = builder.get_object("xml_radiobutton")
|
2019-04-25 00:18:49 +03:00
|
|
|
|
self._xml_chooser_button = builder.get_object("xml_chooser_button")
|
2019-04-27 19:05:37 +03:00
|
|
|
|
self._names_source_box = builder.get_object("names_source_box")
|
2019-04-26 22:07:21 +03:00
|
|
|
|
self._web_source_box = builder.get_object("web_source_box")
|
2019-04-27 19:05:37 +03:00
|
|
|
|
self._use_web_source_switch = builder.get_object("use_web_source_switch")
|
|
|
|
|
|
self._url_to_xml_entry = builder.get_object("url_to_xml_entry")
|
|
|
|
|
|
self._enable_filtering_switch = builder.get_object("enable_filtering_switch")
|
2019-04-30 14:17:45 +03:00
|
|
|
|
self._epg_dat_path_entry = builder.get_object("epg_dat_path_entry")
|
|
|
|
|
|
self._epg_dat_stb_path_entry = builder.get_object("epg_dat_stb_path_entry")
|
2019-05-04 20:13:57 +03:00
|
|
|
|
self._update_on_start_switch = builder.get_object("update_on_start_switch")
|
2019-04-27 19:05:37 +03:00
|
|
|
|
self._epg_dat_source_box = builder.get_object("epg_dat_source_box")
|
2021-10-31 16:09:07 +03:00
|
|
|
|
|
|
|
|
|
|
if IS_GNOME_SESSION:
|
|
|
|
|
|
header_bar = Gtk.HeaderBar(visible=True, show_close_button=True, title="EPG",
|
|
|
|
|
|
subtitle=get_message("List configuration"))
|
|
|
|
|
|
self._dialog.set_titlebar(header_bar)
|
|
|
|
|
|
builder.get_object("left_action_box").reparent(header_bar)
|
|
|
|
|
|
right_box = builder.get_object("right_action_box")
|
|
|
|
|
|
builder.get_object("main_actions_box").remove(right_box)
|
|
|
|
|
|
header_bar.pack_end(right_box)
|
|
|
|
|
|
builder.get_object("toolbar_box").set_visible(False)
|
|
|
|
|
|
|
2022-01-24 16:39:59 +03:00
|
|
|
|
self._app.connect("epg-dat-downloaded", self.on_epg_dat_downloaded)
|
|
|
|
|
|
|
2019-04-22 20:25:19 +03:00
|
|
|
|
# Setting the last size of the dialog window
|
2019-12-13 13:31:07 +03:00
|
|
|
|
window_size = self._settings.get("epg_tool_window_size")
|
2019-04-22 20:25:19 +03:00
|
|
|
|
if window_size:
|
|
|
|
|
|
self._dialog.resize(*window_size)
|
2019-04-18 23:05:19 +03:00
|
|
|
|
|
2019-04-22 00:12:04 +03:00
|
|
|
|
self.init_drag_and_drop()
|
2019-05-01 13:11:19 +03:00
|
|
|
|
self.on_update()
|
2019-04-18 23:05:19 +03:00
|
|
|
|
|
2019-06-03 15:47:04 +03:00
|
|
|
|
def show(self):
|
|
|
|
|
|
self._dialog.show()
|
|
|
|
|
|
|
2019-06-08 15:45:41 +03:00
|
|
|
|
def on_close_dialog(self, window, event):
|
|
|
|
|
|
self._download_xml_is_active = False
|
|
|
|
|
|
|
2019-04-18 23:05:19 +03:00
|
|
|
|
@run_idle
|
2019-06-03 15:47:04 +03:00
|
|
|
|
def on_apply(self, item):
|
|
|
|
|
|
if show_dialog(DialogType.QUESTION, self._dialog) == Gtk.ResponseType.CANCEL:
|
|
|
|
|
|
return
|
2019-05-04 20:13:57 +03:00
|
|
|
|
|
2019-06-03 15:47:04 +03:00
|
|
|
|
self._bouquet.clear()
|
|
|
|
|
|
list(map(self._bouquet.append, [r[Column.FAV_ID] for r in self._bouquet_model]))
|
|
|
|
|
|
for index, row in enumerate(self._ex_fav_model):
|
|
|
|
|
|
fav_id = self._bouquet[index]
|
|
|
|
|
|
row[Column.FAV_ID] = fav_id
|
|
|
|
|
|
if row[Column.FAV_TYPE] == BqServiceType.IPTV.name:
|
|
|
|
|
|
old_fav_id = self._services[fav_id]
|
|
|
|
|
|
srv = self._ex_services.pop(old_fav_id, None)
|
|
|
|
|
|
if srv:
|
|
|
|
|
|
self._ex_services[fav_id] = srv._replace(fav_id=fav_id)
|
|
|
|
|
|
self._dialog.destroy()
|
2019-04-18 23:05:19 +03:00
|
|
|
|
|
2019-06-03 15:47:04 +03:00
|
|
|
|
@run_idle
|
|
|
|
|
|
def on_update(self, item=None):
|
2019-06-08 15:45:41 +03:00
|
|
|
|
self.clear_data()
|
|
|
|
|
|
self.init_options()
|
2022-01-24 16:39:59 +03:00
|
|
|
|
if self._update_epg_data_on_start:
|
|
|
|
|
|
self.download_epg_from_stb()
|
|
|
|
|
|
else:
|
|
|
|
|
|
gen = self.init_data()
|
|
|
|
|
|
GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_LOW)
|
2019-06-08 15:45:41 +03:00
|
|
|
|
|
|
|
|
|
|
def clear_data(self):
|
2019-06-03 15:47:04 +03:00
|
|
|
|
self._services_model.clear()
|
|
|
|
|
|
self._bouquet_model.clear()
|
|
|
|
|
|
self._services.clear()
|
|
|
|
|
|
self._source_info_label.set_text("")
|
|
|
|
|
|
self._bouquet_epg_count_label.set_text("")
|
|
|
|
|
|
self.on_info_bar_close()
|
|
|
|
|
|
|
|
|
|
|
|
def init_data(self):
|
|
|
|
|
|
gen = self.init_bouquet_data()
|
|
|
|
|
|
GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_LOW)
|
2019-04-30 14:17:45 +03:00
|
|
|
|
|
2019-06-08 15:45:41 +03:00
|
|
|
|
refs = None
|
|
|
|
|
|
if self._enable_dat_filter:
|
|
|
|
|
|
try:
|
2019-04-30 14:17:45 +03:00
|
|
|
|
refs = EPG.get_epg_refs(self._epg_dat_path_entry.get_text() + "epg.dat")
|
2022-01-24 16:39:59 +03:00
|
|
|
|
except (OSError, ValueError) as e:
|
2021-10-31 13:34:48 +03:00
|
|
|
|
self.show_info_message(f"Read data error: {e}", Gtk.MessageType.ERROR)
|
2019-04-24 20:27:47 +03:00
|
|
|
|
return
|
2019-06-08 15:45:41 +03:00
|
|
|
|
yield True
|
|
|
|
|
|
|
|
|
|
|
|
if self._refs_source is RefsSource.SERVICES:
|
2022-01-24 16:39:59 +03:00
|
|
|
|
yield from self.init_lamedb_source(refs)
|
2019-06-08 15:45:41 +03:00
|
|
|
|
elif self._refs_source is RefsSource.XML:
|
|
|
|
|
|
xml_gen = self.init_xml_source(refs)
|
|
|
|
|
|
try:
|
|
|
|
|
|
yield from xml_gen
|
|
|
|
|
|
except ValueError as e:
|
|
|
|
|
|
self.show_info_message(str(e), Gtk.MessageType.ERROR)
|
2019-04-18 23:05:19 +03:00
|
|
|
|
else:
|
2019-06-08 15:45:41 +03:00
|
|
|
|
self.show_info_message("Unknown names source!", Gtk.MessageType.ERROR)
|
2019-06-03 15:47:04 +03:00
|
|
|
|
yield True
|
|
|
|
|
|
|
|
|
|
|
|
def init_bouquet_data(self):
|
|
|
|
|
|
for r in self._ex_fav_model:
|
|
|
|
|
|
row = [*r[:]]
|
|
|
|
|
|
fav_id = r[Column.FAV_ID]
|
|
|
|
|
|
self._services[fav_id] = self._ex_services[fav_id].fav_id
|
|
|
|
|
|
yield self._bouquet_model.append(row)
|
|
|
|
|
|
self._bouquet_count_label.set_text(str(len(self._bouquet_model)))
|
|
|
|
|
|
yield True
|
2019-04-18 23:05:19 +03:00
|
|
|
|
|
2019-04-24 20:27:47 +03:00
|
|
|
|
def init_lamedb_source(self, refs):
|
2019-05-07 00:04:53 +03:00
|
|
|
|
srvs = {k[:k.rfind(":")]: v for k, v in self._ex_services.items()}
|
2019-04-27 19:05:37 +03:00
|
|
|
|
s_types = (BqServiceType.MARKER.value, BqServiceType.IPTV.value)
|
|
|
|
|
|
filtered = filter(None, [srvs.get(ref) for ref in refs]) if refs else filter(
|
2019-05-07 00:04:53 +03:00
|
|
|
|
lambda s: s.service_type not in s_types, self._ex_services.values())
|
2022-01-24 16:39:59 +03:00
|
|
|
|
|
|
|
|
|
|
factor = self._app.DEL_FACTOR / 4
|
|
|
|
|
|
for index, srv in enumerate(filtered):
|
|
|
|
|
|
self._services_model.append((srv.service, srv.pos, srv.fav_id))
|
|
|
|
|
|
if index % factor == 0:
|
|
|
|
|
|
yield True
|
|
|
|
|
|
|
2019-06-08 15:45:41 +03:00
|
|
|
|
self.update_source_count_info()
|
2022-01-24 16:39:59 +03:00
|
|
|
|
yield True
|
2019-04-24 20:27:47 +03:00
|
|
|
|
|
|
|
|
|
|
def init_xml_source(self, refs):
|
2019-06-08 15:45:41 +03:00
|
|
|
|
path = self._epg_dat_path_entry.get_text() if self._use_web_source else self._xml_chooser_button.get_filename()
|
|
|
|
|
|
if not path:
|
|
|
|
|
|
self.show_info_message("The path to the xml file is not set!", Gtk.MessageType.ERROR)
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
if self._use_web_source:
|
|
|
|
|
|
# Downloading gzipped xml file that contains services names with references from the web.
|
|
|
|
|
|
self._download_xml_is_active = True
|
|
|
|
|
|
self.update_active_header_elements(False)
|
|
|
|
|
|
url = self._url_to_xml_entry.get_text()
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
with urllib.request.urlopen(url, timeout=2) as fp:
|
|
|
|
|
|
headers = fp.info()
|
|
|
|
|
|
content_type = headers.get("Content-Type", "")
|
|
|
|
|
|
|
|
|
|
|
|
if content_type != "application/gzip":
|
|
|
|
|
|
self._download_xml_is_active = False
|
|
|
|
|
|
raise ValueError("{} {} {}".format(get_message("Download XML file error."),
|
|
|
|
|
|
get_message("Unsupported file type:"),
|
|
|
|
|
|
content_type))
|
|
|
|
|
|
|
|
|
|
|
|
file_name = os.path.basename(url)
|
|
|
|
|
|
data_path = self._epg_dat_path_entry.get_text()
|
|
|
|
|
|
|
|
|
|
|
|
with open(data_path + file_name, "wb") as tfp:
|
|
|
|
|
|
bs = 1024 * 8
|
|
|
|
|
|
size = -1
|
|
|
|
|
|
read = 0
|
|
|
|
|
|
b_num = 0
|
|
|
|
|
|
if "content-length" in headers:
|
|
|
|
|
|
size = int(headers["Content-Length"])
|
|
|
|
|
|
|
|
|
|
|
|
while self._download_xml_is_active:
|
|
|
|
|
|
block = fp.read(bs)
|
|
|
|
|
|
if not block:
|
|
|
|
|
|
break
|
|
|
|
|
|
read += len(block)
|
|
|
|
|
|
tfp.write(block)
|
|
|
|
|
|
b_num += 1
|
|
|
|
|
|
self.update_download_progress(b_num * bs / size)
|
|
|
|
|
|
yield True
|
|
|
|
|
|
|
|
|
|
|
|
path = tfp.name.rstrip(".gz")
|
|
|
|
|
|
except (HTTPError, URLError) as e:
|
2021-10-31 13:34:48 +03:00
|
|
|
|
raise ValueError(f"{get_message('Download XML file error.')} {e}")
|
2019-06-08 15:45:41 +03:00
|
|
|
|
else:
|
|
|
|
|
|
try:
|
|
|
|
|
|
with open(path, "wb") as f_out:
|
|
|
|
|
|
with gzip.open(tfp.name, "rb") as f:
|
|
|
|
|
|
shutil.copyfileobj(f, f_out)
|
|
|
|
|
|
os.remove(tfp.name)
|
|
|
|
|
|
except Exception as e:
|
2021-10-31 13:34:48 +03:00
|
|
|
|
raise ValueError(f"{get_message('Unpacking data error.')} {e}")
|
2019-06-08 15:45:41 +03:00
|
|
|
|
finally:
|
|
|
|
|
|
self._download_xml_is_active = False
|
|
|
|
|
|
self.update_active_header_elements(True)
|
2019-04-30 14:17:45 +03:00
|
|
|
|
|
2019-05-04 20:13:57 +03:00
|
|
|
|
try:
|
2019-06-08 15:45:41 +03:00
|
|
|
|
s_refs, info = ChannelsParser.get_refs_from_xml(path)
|
|
|
|
|
|
yield True
|
2019-05-04 20:13:57 +03:00
|
|
|
|
except Exception as e:
|
2021-10-31 13:34:48 +03:00
|
|
|
|
raise ValueError(f"{get_message('XML parsing error:')} {e}")
|
2019-04-27 19:05:37 +03:00
|
|
|
|
else:
|
2019-05-04 20:13:57 +03:00
|
|
|
|
if refs:
|
2019-06-04 01:22:26 +03:00
|
|
|
|
s_refs = filter(lambda x: x.num in refs, s_refs)
|
2022-01-24 16:39:59 +03:00
|
|
|
|
|
|
|
|
|
|
factor = self._app.DEL_FACTOR / 4
|
|
|
|
|
|
for index, srv in enumerate(s_refs):
|
|
|
|
|
|
self._services_model.append((srv.name, " ", srv.data))
|
|
|
|
|
|
if index % factor == 0:
|
|
|
|
|
|
yield True
|
|
|
|
|
|
|
2019-05-04 20:13:57 +03:00
|
|
|
|
self.update_source_info(info)
|
2019-06-08 15:45:41 +03:00
|
|
|
|
self.update_source_count_info()
|
|
|
|
|
|
yield True
|
2019-04-24 20:27:47 +03:00
|
|
|
|
|
2021-10-31 13:34:48 +03:00
|
|
|
|
def on_key_press(self, view, event):
|
2019-05-01 13:11:19 +03:00
|
|
|
|
""" Handling keystrokes """
|
|
|
|
|
|
key_code = event.hardware_keycode
|
|
|
|
|
|
if not KeyboardKey.value_exist(key_code):
|
|
|
|
|
|
return
|
|
|
|
|
|
key = KeyboardKey(key_code)
|
|
|
|
|
|
ctrl = event.state & Gdk.ModifierType.CONTROL_MASK
|
|
|
|
|
|
|
|
|
|
|
|
if ctrl and key is KeyboardKey.C:
|
|
|
|
|
|
self.on_copy_ref()
|
|
|
|
|
|
elif ctrl and key is KeyboardKey.V:
|
|
|
|
|
|
self.on_assign_ref()
|
|
|
|
|
|
|
2022-01-24 16:39:59 +03:00
|
|
|
|
def on_bq_cursor_changed(self, view):
|
2022-01-24 19:17:11 +03:00
|
|
|
|
if self._filter_bar.get_visible() and self._filter_auto_switch.get_active():
|
2022-01-24 16:39:59 +03:00
|
|
|
|
path, column = view.get_cursor()
|
|
|
|
|
|
model = view.get_model()
|
|
|
|
|
|
if path:
|
|
|
|
|
|
self._filter_entry.set_text(model[path][Column.FAV_SERVICE] or "")
|
|
|
|
|
|
|
2019-04-22 20:25:19 +03:00
|
|
|
|
@run_idle
|
2019-04-21 01:18:54 +03:00
|
|
|
|
def on_save_to_xml(self, item):
|
2019-12-13 13:31:07 +03:00
|
|
|
|
response = show_dialog(DialogType.CHOOSER, self._dialog, settings=self._settings)
|
2019-05-07 00:04:53 +03:00
|
|
|
|
if response in (Gtk.ResponseType.CANCEL, Gtk.ResponseType.DELETE_EVENT):
|
|
|
|
|
|
return
|
|
|
|
|
|
|
2019-04-22 20:25:19 +03:00
|
|
|
|
services = []
|
|
|
|
|
|
iptv_types = (BqServiceType.IPTV.value, BqServiceType.MARKER.value)
|
|
|
|
|
|
for r in self._bouquet_model:
|
|
|
|
|
|
srv_type = r[Column.FAV_TYPE]
|
|
|
|
|
|
if srv_type in iptv_types:
|
|
|
|
|
|
srv = BouquetService(name=r[Column.FAV_SERVICE],
|
|
|
|
|
|
type=BqServiceType(srv_type),
|
|
|
|
|
|
data=r[Column.FAV_ID],
|
|
|
|
|
|
num=r[Column.FAV_NUM])
|
|
|
|
|
|
services.append(srv)
|
|
|
|
|
|
|
2019-06-04 13:31:54 +03:00
|
|
|
|
ChannelsParser.write_refs_to_xml("{}{}.xml".format(response, self._bouquet_name), services)
|
2019-04-22 20:25:19 +03:00
|
|
|
|
self.show_info_message(get_message("Done!"), Gtk.MessageType.INFO)
|
2019-04-21 01:18:54 +03:00
|
|
|
|
|
2019-05-07 00:04:53 +03:00
|
|
|
|
@run_idle
|
2019-04-21 01:18:54 +03:00
|
|
|
|
def on_auto_configuration(self, item):
|
2019-05-04 23:54:58 +03:00
|
|
|
|
""" Simple mapping of services by name. """
|
2019-05-05 11:26:11 +03:00
|
|
|
|
use_cyrillic = locale.getdefaultlocale()[0] in ("ru_RU", "be_BY", "uk_UA", "sr_RS")
|
2019-05-04 23:54:58 +03:00
|
|
|
|
tr = None
|
|
|
|
|
|
if use_cyrillic:
|
2019-05-07 00:04:53 +03:00
|
|
|
|
# may be not entirely correct
|
|
|
|
|
|
symbols = (u"АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯІÏҐЎЈЂЉЊЋЏTB",
|
|
|
|
|
|
u"ABVGDEEJZIJKLMNOPRSTUFHZCSS_Y_EUAIEGUEDLNCJTV")
|
2019-05-04 23:54:58 +03:00
|
|
|
|
tr = {ord(k): ord(v) for k, v in zip(*symbols)}
|
|
|
|
|
|
|
|
|
|
|
|
source = {}
|
|
|
|
|
|
for row in self._services_model:
|
|
|
|
|
|
name = re.sub("\\W+", "", str(row[0])).upper()
|
|
|
|
|
|
name = name.translate(tr) if use_cyrillic else name
|
2021-10-31 13:34:48 +03:00
|
|
|
|
source[name] = row
|
2019-05-04 23:54:58 +03:00
|
|
|
|
|
2019-04-21 01:18:54 +03:00
|
|
|
|
success_count = 0
|
2019-05-07 00:04:53 +03:00
|
|
|
|
not_founded = {}
|
2019-04-21 01:18:54 +03:00
|
|
|
|
|
2019-04-22 00:12:04 +03:00
|
|
|
|
for r in self._bouquet_model:
|
2019-04-30 14:17:45 +03:00
|
|
|
|
if r[Column.FAV_TYPE] != BqServiceType.IPTV.value:
|
|
|
|
|
|
continue
|
2019-05-04 23:54:58 +03:00
|
|
|
|
name = re.sub("\\W+", "", str(r[Column.FAV_SERVICE])).upper()
|
|
|
|
|
|
if use_cyrillic:
|
|
|
|
|
|
name = name.translate(tr)
|
2019-05-07 00:04:53 +03:00
|
|
|
|
ref = source.get(name, None) # Not [pop], because the list may contain duplicates or similar names!
|
2019-04-21 01:18:54 +03:00
|
|
|
|
if ref:
|
2019-04-24 20:27:47 +03:00
|
|
|
|
self.assign_data(r, ref, True)
|
2019-04-21 01:18:54 +03:00
|
|
|
|
success_count += 1
|
2019-05-07 00:04:53 +03:00
|
|
|
|
else:
|
|
|
|
|
|
not_founded[name] = r
|
|
|
|
|
|
# Additional attempt to search in the remaining elements
|
|
|
|
|
|
for n in not_founded:
|
|
|
|
|
|
for k in source:
|
2019-05-07 17:22:18 +03:00
|
|
|
|
if k.startswith(n):
|
2019-05-07 00:04:53 +03:00
|
|
|
|
self.assign_data(not_founded[n], source[k], True)
|
|
|
|
|
|
success_count += 1
|
|
|
|
|
|
break
|
2019-04-21 01:18:54 +03:00
|
|
|
|
|
2019-04-30 14:17:45 +03:00
|
|
|
|
self.update_epg_count()
|
2019-06-08 16:04:47 +03:00
|
|
|
|
self.show_info_message("{} {} {}".format(get_message("Done!"),
|
|
|
|
|
|
get_message("Count of successfully configured services:"),
|
|
|
|
|
|
success_count), Gtk.MessageType.INFO)
|
2019-04-21 01:18:54 +03:00
|
|
|
|
|
2021-10-31 13:34:48 +03:00
|
|
|
|
def assign_data(self, row, data, show_error=False):
|
2019-04-30 14:17:45 +03:00
|
|
|
|
if row[Column.FAV_TYPE] != BqServiceType.IPTV.value:
|
2019-04-24 20:27:47 +03:00
|
|
|
|
if not show_error:
|
|
|
|
|
|
self.show_info_message(get_message("Not allowed in this context!"), Gtk.MessageType.ERROR)
|
|
|
|
|
|
return
|
2019-04-27 19:05:37 +03:00
|
|
|
|
|
2019-04-21 21:48:47 +03:00
|
|
|
|
fav_id = row[Column.FAV_ID]
|
|
|
|
|
|
fav_id_data = fav_id.split(":")
|
2021-10-31 13:34:48 +03:00
|
|
|
|
fav_id_data[3:7] = data[-1].split(":")
|
2019-04-21 21:48:47 +03:00
|
|
|
|
new_fav_id = ":".join(fav_id_data)
|
2019-04-30 14:17:45 +03:00
|
|
|
|
service = self._services.pop(fav_id, None)
|
|
|
|
|
|
if service:
|
2019-05-07 00:04:53 +03:00
|
|
|
|
self._services[new_fav_id] = service
|
2019-04-30 14:17:45 +03:00
|
|
|
|
row[Column.FAV_ID] = new_fav_id
|
|
|
|
|
|
row[Column.FAV_LOCKED] = EPG_ICON
|
2022-01-23 14:24:50 +03:00
|
|
|
|
pos = f"({data[1] if self._refs_source is RefsSource.SERVICES else 'XML'})"
|
2022-01-24 16:39:59 +03:00
|
|
|
|
src = f"{get_message('EPG source')}: {(GLib.markup_escape_text(data[0] or ''))} {pos}"
|
2021-10-31 13:34:48 +03:00
|
|
|
|
row[Column.FAV_TOOLTIP] = f"{get_message('Service reference')}: {':'.join(fav_id_data[:10])}\n{src}"
|
2019-04-21 21:48:47 +03:00
|
|
|
|
|
2022-01-24 16:39:59 +03:00
|
|
|
|
def on_filter_toggled(self, button):
|
2022-01-24 19:17:11 +03:00
|
|
|
|
self._filter_bar.set_visible(button.get_active())
|
2022-01-24 16:39:59 +03:00
|
|
|
|
if not button.get_active():
|
|
|
|
|
|
self._filter_entry.set_text("")
|
2019-04-21 01:18:54 +03:00
|
|
|
|
|
2022-01-24 19:17:11 +03:00
|
|
|
|
@run_with_delay(1)
|
2019-04-21 01:18:54 +03:00
|
|
|
|
def on_filter_changed(self, entry):
|
|
|
|
|
|
self._services_filter_model.refilter()
|
|
|
|
|
|
|
|
|
|
|
|
def services_filter_function(self, model, itr, data):
|
|
|
|
|
|
txt = self._filter_entry.get_text().upper()
|
|
|
|
|
|
return model is None or model == "None" or txt in model.get_value(itr, 0).upper()
|
|
|
|
|
|
|
2019-04-18 23:05:19 +03:00
|
|
|
|
def on_info_bar_close(self, bar=None, resp=None):
|
|
|
|
|
|
self._info_bar.set_visible(False)
|
|
|
|
|
|
|
2019-05-01 13:11:19 +03:00
|
|
|
|
def on_copy_ref(self, item=None):
|
2019-04-24 21:53:01 +03:00
|
|
|
|
model, paths = self._source_view.get_selection().get_selected_rows()
|
|
|
|
|
|
self._current_ref.clear()
|
2019-05-01 13:11:19 +03:00
|
|
|
|
if paths:
|
2021-10-31 13:34:48 +03:00
|
|
|
|
self._current_ref.append(model[paths][:])
|
2019-04-24 21:53:01 +03:00
|
|
|
|
|
2019-05-01 13:11:19 +03:00
|
|
|
|
def on_assign_ref(self, item=None):
|
2019-04-24 21:53:01 +03:00
|
|
|
|
if self._current_ref:
|
|
|
|
|
|
model, paths = self._bouquet_view.get_selection().get_selected_rows()
|
|
|
|
|
|
self.assign_data(model[paths], self._current_ref.pop())
|
2019-05-01 13:11:19 +03:00
|
|
|
|
self.update_epg_count()
|
2019-04-24 21:53:01 +03:00
|
|
|
|
|
2019-05-07 17:22:18 +03:00
|
|
|
|
@run_idle
|
|
|
|
|
|
def on_reset(self, item):
|
|
|
|
|
|
model, paths = self._bouquet_view.get_selection().get_selected_rows()
|
|
|
|
|
|
if paths:
|
|
|
|
|
|
row = self._bouquet_model[paths]
|
|
|
|
|
|
self.reset_row_data(row)
|
2019-05-07 22:08:04 +03:00
|
|
|
|
self.update_epg_count()
|
2019-05-07 17:22:18 +03:00
|
|
|
|
|
|
|
|
|
|
@run_idle
|
|
|
|
|
|
def on_list_reset(self, item):
|
|
|
|
|
|
list(map(self.reset_row_data, self._bouquet_model))
|
2019-05-07 22:08:04 +03:00
|
|
|
|
self.update_epg_count()
|
2019-05-07 17:22:18 +03:00
|
|
|
|
|
|
|
|
|
|
def reset_row_data(self, row):
|
|
|
|
|
|
default_fav_id = self._services.pop(row[Column.FAV_ID], None)
|
|
|
|
|
|
if default_fav_id:
|
|
|
|
|
|
self._services[default_fav_id] = default_fav_id
|
|
|
|
|
|
row[Column.FAV_ID], row[Column.FAV_LOCKED], row[Column.FAV_TOOLTIP] = default_fav_id, None, None
|
2019-04-18 23:05:19 +03:00
|
|
|
|
|
2019-04-25 00:18:49 +03:00
|
|
|
|
@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)
|
|
|
|
|
|
|
2019-04-30 14:17:45 +03:00
|
|
|
|
@run_idle
|
|
|
|
|
|
def update_source_info(self, info):
|
|
|
|
|
|
lines = info.split("\n")
|
|
|
|
|
|
self._source_info_label.set_text(lines[0] if lines else "")
|
|
|
|
|
|
self._source_view.set_tooltip_text(info)
|
|
|
|
|
|
|
2019-06-08 15:45:41 +03:00
|
|
|
|
@run_idle
|
|
|
|
|
|
def update_source_count_info(self):
|
|
|
|
|
|
source_count = len(self._services_model)
|
|
|
|
|
|
self._source_count_label.set_text(str(source_count))
|
|
|
|
|
|
if self._enable_dat_filter and source_count == 0:
|
2019-06-08 16:04:47 +03:00
|
|
|
|
msg = get_message("Current epg.dat file does not contains references for the services of this bouquet!")
|
2019-06-08 15:45:41 +03:00
|
|
|
|
self.show_info_message(msg, Gtk.MessageType.WARNING)
|
|
|
|
|
|
|
2019-04-30 14:17:45 +03:00
|
|
|
|
@run_idle
|
|
|
|
|
|
def update_epg_count(self):
|
|
|
|
|
|
count = len(list((filter(None, [r[Column.FAV_LOCKED] for r in self._bouquet_model]))))
|
|
|
|
|
|
self._bouquet_epg_count_label.set_text(str(count))
|
|
|
|
|
|
|
2019-06-08 15:45:41 +03:00
|
|
|
|
@run_idle
|
|
|
|
|
|
def update_active_header_elements(self, state):
|
2022-04-03 19:08:08 +03:00
|
|
|
|
self._left_action_box.set_sensitive(state)
|
2019-06-08 15:45:41 +03:00
|
|
|
|
self._xml_download_progress_bar.set_visible(not state)
|
|
|
|
|
|
self._source_info_label.set_text("" if state else "Downloading XML:")
|
|
|
|
|
|
|
|
|
|
|
|
@run_idle
|
|
|
|
|
|
def update_download_progress(self, value):
|
|
|
|
|
|
self._xml_download_progress_bar.set_fraction(value)
|
|
|
|
|
|
|
2019-04-25 00:18:49 +03:00
|
|
|
|
def on_bouquet_popup_menu(self, menu, event):
|
|
|
|
|
|
self._assign_ref_popup_item.set_sensitive(self._current_ref)
|
|
|
|
|
|
on_popup_menu(menu, event)
|
|
|
|
|
|
|
2019-04-22 00:12:04 +03:00
|
|
|
|
# ***************** Drag-and-drop *********************#
|
2019-04-24 21:53:01 +03:00
|
|
|
|
|
2019-04-22 00:12:04 +03:00
|
|
|
|
def init_drag_and_drop(self):
|
2021-10-31 13:34:48 +03:00
|
|
|
|
""" Enable drag-and-drop. """
|
2019-04-22 00:12:04 +03:00
|
|
|
|
target = []
|
|
|
|
|
|
self._source_view.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK, target, Gdk.DragAction.COPY)
|
|
|
|
|
|
self._source_view.drag_source_add_text_targets()
|
|
|
|
|
|
self._bouquet_view.enable_model_drag_dest(target, Gdk.DragAction.DEFAULT | Gdk.DragAction.MOVE)
|
|
|
|
|
|
self._bouquet_view.drag_dest_add_text_targets()
|
|
|
|
|
|
|
|
|
|
|
|
def on_drag_begin(self, view, context):
|
|
|
|
|
|
""" Selects a row under the cursor in the view at the dragging beginning. """
|
|
|
|
|
|
selection = view.get_selection()
|
|
|
|
|
|
if selection.count_selected_rows() > 1:
|
|
|
|
|
|
view.do_toggle_cursor_row(view)
|
|
|
|
|
|
|
2021-10-31 13:34:48 +03:00
|
|
|
|
def on_drag_data_get(self, view, drag_context, data, info, time):
|
2019-04-22 00:12:04 +03:00
|
|
|
|
model, paths = view.get_selection().get_selected_rows()
|
|
|
|
|
|
if paths:
|
2021-10-31 13:34:48 +03:00
|
|
|
|
s_data = model[paths][:]
|
|
|
|
|
|
if all(s_data):
|
|
|
|
|
|
data.set_text("::::".join(s_data), -1)
|
|
|
|
|
|
else:
|
|
|
|
|
|
self.show_info_message(get_message("Source error!"), Gtk.MessageType.ERROR)
|
2019-04-22 00:12:04 +03:00
|
|
|
|
|
2021-10-31 13:34:48 +03:00
|
|
|
|
def on_drag_data_received(self, view, drag_context, x, y, data, info, time):
|
2019-04-22 00:12:04 +03:00
|
|
|
|
path, pos = view.get_dest_row_at_pos(x, y)
|
|
|
|
|
|
model = view.get_model()
|
2021-10-31 13:34:48 +03:00
|
|
|
|
data = data.get_text()
|
|
|
|
|
|
if data:
|
|
|
|
|
|
self.assign_data(model[path], data.split("::::"))
|
|
|
|
|
|
self.update_epg_count()
|
2019-04-22 00:12:04 +03:00
|
|
|
|
return False
|
|
|
|
|
|
|
2019-04-25 00:18:49 +03:00
|
|
|
|
# ***************** Options *********************#
|
|
|
|
|
|
|
2019-04-27 19:05:37 +03:00
|
|
|
|
def init_options(self):
|
2021-08-30 15:04:15 +03:00
|
|
|
|
epg_dat_path = "{}epg{}".format(self._settings.profile_data_path, SEP)
|
2019-04-30 14:17:45 +03:00
|
|
|
|
self._epg_dat_path_entry.set_text(epg_dat_path)
|
|
|
|
|
|
default_epg_data_stb_path = "/etc/enigma2"
|
2020-04-02 16:50:58 +03:00
|
|
|
|
epg_options = self._settings.epg_options
|
2019-04-27 19:05:37 +03:00
|
|
|
|
if epg_options:
|
|
|
|
|
|
self._refs_source = RefsSource.XML if epg_options.get("xml_source", False) else RefsSource.SERVICES
|
|
|
|
|
|
self._xml_radiobutton.set_active(self._refs_source is RefsSource.XML)
|
|
|
|
|
|
self._use_web_source = epg_options.get("use_web_source", False)
|
|
|
|
|
|
self._use_web_source_switch.set_active(self._use_web_source)
|
|
|
|
|
|
self._url_to_xml_entry.set_text(epg_options.get("url_to_xml", ""))
|
|
|
|
|
|
self._enable_dat_filter = epg_options.get("enable_filtering", False)
|
|
|
|
|
|
self._enable_filtering_switch.set_active(self._enable_dat_filter)
|
2019-04-30 14:17:45 +03:00
|
|
|
|
epg_dat_path = epg_options.get("epg_dat_path", epg_dat_path)
|
|
|
|
|
|
self._epg_dat_path_entry.set_text(epg_dat_path)
|
|
|
|
|
|
self._epg_dat_stb_path_entry.set_text(epg_options.get("epg_dat_stb_path", default_epg_data_stb_path))
|
2019-05-04 20:13:57 +03:00
|
|
|
|
self._update_epg_data_on_start = epg_options.get("epg_data_update_on_start", False)
|
|
|
|
|
|
self._update_on_start_switch.set_active(self._update_epg_data_on_start)
|
2019-04-27 19:05:37 +03:00
|
|
|
|
local_xml_path = epg_options.get("local_path_to_xml", None)
|
|
|
|
|
|
if local_xml_path:
|
|
|
|
|
|
self._xml_chooser_button.set_filename(local_xml_path)
|
2019-04-30 14:17:45 +03:00
|
|
|
|
os.makedirs(os.path.dirname(self._epg_dat_path_entry.get_text()), exist_ok=True)
|
2019-04-27 19:05:37 +03:00
|
|
|
|
|
2019-04-30 14:17:45 +03:00
|
|
|
|
def on_options_save(self, item=None):
|
2020-04-02 16:50:58 +03:00
|
|
|
|
self._settings.epg_options = {"xml_source": self._xml_radiobutton.get_active(),
|
|
|
|
|
|
"use_web_source": self._use_web_source_switch.get_active(),
|
|
|
|
|
|
"local_path_to_xml": self._xml_chooser_button.get_filename(),
|
|
|
|
|
|
"url_to_xml": self._url_to_xml_entry.get_text(),
|
|
|
|
|
|
"enable_filtering": self._enable_filtering_switch.get_active(),
|
|
|
|
|
|
"epg_dat_path": self._epg_dat_path_entry.get_text(),
|
|
|
|
|
|
"epg_dat_stb_path": self._epg_dat_stb_path_entry.get_text(),
|
|
|
|
|
|
"epg_data_update_on_start": self._update_on_start_switch.get_active()}
|
2019-04-27 19:05:37 +03:00
|
|
|
|
|
2019-04-22 20:25:19 +03:00
|
|
|
|
def on_resize(self, window):
|
2019-12-13 13:31:07 +03:00
|
|
|
|
if self._settings:
|
|
|
|
|
|
self._settings.add("epg_tool_window_size", window.get_size())
|
2019-04-22 20:25:19 +03:00
|
|
|
|
|
2019-04-25 00:18:49 +03:00
|
|
|
|
def on_names_source_changed(self, button):
|
2019-04-27 19:05:37 +03:00
|
|
|
|
self._refs_source = RefsSource.XML if button.get_active() else RefsSource.SERVICES
|
|
|
|
|
|
self._names_source_box.set_sensitive(button.get_active())
|
2019-04-24 21:53:01 +03:00
|
|
|
|
|
2019-04-27 19:05:37 +03:00
|
|
|
|
def on_enable_filtering_switch(self, switch, state):
|
|
|
|
|
|
self._epg_dat_source_box.set_sensitive(state)
|
2019-05-04 20:13:57 +03:00
|
|
|
|
self._update_on_start_switch.set_active(False if not state else self._update_epg_data_on_start)
|
2019-04-26 22:07:21 +03:00
|
|
|
|
|
|
|
|
|
|
def on_update_on_start_switch(self, switch, state):
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def on_use_web_source_switch(self, switch, state):
|
|
|
|
|
|
self._web_source_box.set_sensitive(state)
|
2019-04-27 19:05:37 +03:00
|
|
|
|
self._xml_chooser_button.set_sensitive(not state)
|
2019-04-26 22:07:21 +03:00
|
|
|
|
|
2019-04-30 14:17:45 +03:00
|
|
|
|
def on_field_icon_press(self, entry, icon, event_button):
|
2019-12-13 13:31:07 +03:00
|
|
|
|
update_entry_data(entry, self._dialog, self._settings)
|
2019-04-30 14:17:45 +03:00
|
|
|
|
|
2019-05-04 20:13:57 +03:00
|
|
|
|
# ***************** Downloads *********************#
|
|
|
|
|
|
|
2022-01-24 16:39:59 +03:00
|
|
|
|
def on_epg_dat_downloaded(self, app, value):
|
|
|
|
|
|
gen = self.init_data()
|
|
|
|
|
|
GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_LOW)
|
|
|
|
|
|
|
2021-02-08 14:59:56 +03:00
|
|
|
|
@run_task
|
2019-05-04 20:13:57 +03:00
|
|
|
|
def download_epg_from_stb(self):
|
|
|
|
|
|
""" Download the epg.dat file via ftp from the receiver. """
|
2022-01-24 16:39:59 +03:00
|
|
|
|
try:
|
|
|
|
|
|
download_data(settings=self._settings, download_type=DownloadType.EPG, callback=print)
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
GLib.idle_add(self.show_info_message, f"Download epg.dat file error: {e}", Gtk.MessageType.ERROR)
|
|
|
|
|
|
else:
|
|
|
|
|
|
GLib.idle_add(self._app.emit, "epg-dat-downloaded", None)
|
2019-05-04 20:13:57 +03:00
|
|
|
|
|
2019-04-18 23:05:19 +03:00
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
pass
|