def __init__(self, xml_file, xml_location, package_name): super(PackageConfiguration, self).__init__(xml_file, xml_location) self.providers = self.providers_class.known_providers self.manager = SettingsManager() self.providerCache = ProviderCache() self.package_name = package_name self.settings = [] self.provider_list = None self.settings_list = None
def get_sources(self, action_args, overwrite_cache=False): """ Method to handle automatic background or foreground scraping :param action_args: action arguments from request uri :param overwrite_cache: Set to true if you wish to overwrite the current cached return value :return: """ item_information = tools.get_item_information(action_args) if not ProviderCache().get_provider_packages(): yesno = xbmcgui.Dialog().yesno(g.ADDON_NAME, g.get_language_string(30443)) if not yesno: return sources = Sources(item_information).get_sources( overwrite_torrent_cache=overwrite_cache) return sources
def get_sources(self, action_args, overwrite_cache=None): """ Method to handle automatic background or foreground scraping :param action_args: action arguments from request uri :param overwrite_cache: Set to true if you wish to overwrite the current cached return value :return: """ item_information = tools.get_item_information(action_args) if not ProviderCache().get_provider_packages(): yesno = xbmcgui.Dialog().yesno(g.ADDON_NAME, g.get_language_string(30465)) if not yesno: return sources = Sources(item_information).get_sources() if sources is None or len(sources) <= 0 or len(sources[1]) <= 0: g.cancel_playback() g.notification(g.ADDON_NAME, g.get_language_string(30032), time=5000) return sources
class PackageConfiguration(BaseWindow): providers_class = ProviderInstallManager() def __init__(self, xml_file, xml_location, package_name): super(PackageConfiguration, self).__init__(xml_file, xml_location) self.providers = self.providers_class.known_providers self.manager = SettingsManager() self.providerCache = ProviderCache() self.package_name = package_name self.settings = [] self.provider_list = None self.settings_list = None def onInit(self): self.settings_list = self.getControlList(1000) self.provider_list = self.getControlList(2000) self.update_settings() self.fill_providers() self.setProperty("package.name", self.package_name) self.setProperty("hassettings", "true" if self.settings_list.size() > 0 else "false") self.set_default_focus(self.provider_list, 2999, control_list_reset=True) super(PackageConfiguration, self).onInit() def refresh_data(self): self.providers_class.poll_database() self.providers = self.providers_class.known_providers self.update_settings() @staticmethod def _set_setting_item_properties(menu_item, setting): value = g.UNICODE(setting["value"]) if setting["definition"].get("sensitive"): value = "*******" menu_item.setProperty("Label", setting["label"]) menu_item.setProperty("value", value) def _populate_settings(self): def create_menu_item(setting): new_item = xbmcgui.ListItem(label="{}".format(setting["label"])) self._set_setting_item_properties(new_item, value) return new_item if len(self.settings) < self.settings_list.size(): while len(self.settings) < self.settings_list.size(): self.settings_list.removeItem(self.settings_list.size() - 1) for idx, value in enumerate(self.settings): try: menu_item = self.settings_list.getListItem(idx) self._set_setting_item_properties(menu_item, value) except RuntimeError: menu_item = create_menu_item(value) self.settings_list.addItem(menu_item) def fill_providers(self): self.refresh_data() self.provider_list.reset() provider_types = self.providers_class.provider_types for provider_type in provider_types: for i in [ provider for provider in self.providers if provider["package"] == self.package_name and provider["provider_type"] == provider_type ]: item = xbmcgui.ListItem(label=i["provider_name"]) for info in i: item.setProperty(info, i[info]) self.provider_list.addItem(item) def update_settings(self): self.settings = [ i for i in reversed( self.manager.get_all_visible_package_settings( self.package_name)) ] self._populate_settings() def flip_provider_status(self): provider_item = self.provider_list.getSelectedItem() new_status = self.providers_class.flip_provider_status( provider_item.getProperty("package"), provider_item.getLabel()) provider_item.setProperty("status", new_status) self.providers = self.providerCache.get_providers() def flip_mutliple_providers(self, status, provider_type=None): g.show_busy_dialog() providers = [ i for i in self.providers if i["package"] == self.package_name ] if provider_type: providers = [ i for i in providers if i["provider_type"] == provider_type ] for i in providers: self.providers_class.flip_provider_status(i["package"], i["provider_name"], status) self.providers = self.providerCache.get_providers() self.fill_providers() self.set_default_focus(self.provider_list, 3000) g.close_busy_dialog() def handle_action(self, action, control_id=None): if action == 7: if control_id == 1000: position = self.settings_list.getSelectedPosition() self._edit_setting(self.settings[position]) elif control_id == 2000: self.flip_provider_status() elif control_id == 2999: self.close() elif control_id in {3001, 3002, 3003, 3004, 3005, 3006}: options = { 3001: ("enabled", "hosters"), 3002: ("enabled", "torrent"), 3003: ("disabled", "hosters"), 3004: ("disabled", "torrent"), 3005: ("enabled", None), 3006: ("disabled", None), } option = options.get(control_id) self.flip_mutliple_providers(option[0], provider_type=option[1]) def _edit_setting(self, setting): keyboard = xbmc.Keyboard("", setting.get("label")) keyboard.doModal() if keyboard.isConfirmed(): try: self.manager.set_setting( self.package_name, setting["id"], self.manager.settings_template[setting["type"]]["cast"]( keyboard.getText()), ) self.update_settings() except TypeError: xbmcgui.Dialog().ok(g.ADDON_NAME, "The setting value was invalid")
def __init__(self, xml_file, xml_location): super(ProviderPackages, self).__init__(xml_file, xml_location) self.packages = self.providers_class.known_packages self.providers = self.providers_class.known_providers self.package_list = None self.providerCache = ProviderCache()
class ProviderPackages(BaseWindow): providers_class = ProviderInstallManager() def __init__(self, xml_file, xml_location): super(ProviderPackages, self).__init__(xml_file, xml_location) self.packages = self.providers_class.known_packages self.providers = self.providers_class.known_providers self.package_list = None self.providerCache = ProviderCache() def onInit(self): g.close_busy_dialog() self.package_list = self.getControlList(1000) self.fill_packages() self.setFocus(self.package_list) def refresh_data(self): self.providers_class.poll_database() self.packages = self.providers_class.known_packages def fill_packages(self): self.refresh_data() self.package_list.reset() for i in self.packages: item = xbmcgui.ListItem(label=i['pack_name']) for info in i.keys(): item.setProperty(info, i[info]) self.package_list.addItem(item) def onClick(self, control_id): self.handle_action(7, control_id) def _configure_package(self, package): window = PackageConfiguration( *SkinManager().confirm_skin_path('configure_provider_package.xml'), package_name=package) window.doModal() del window def flip_mutliple_providers(self, status, package_name, provider_type=None): g.show_busy_dialog() providers = [i for i in self.providers if i['package'] == package_name] for i in providers: self.providers_class.flip_provider_status(i['package'], i['provider_name'], status) self.providers = self.providerCache.get_providers() g.close_busy_dialog() def handle_action(self, action, control_id=None): if action == 7: if control_id == 2001: self.close() elif control_id == 3001: self._configure_package( self.package_list.getSelectedItem().getLabel()) elif control_id == 3002: g.show_busy_dialog() try: self.providers_class.install_package(None) self.packages = self.providerCache.get_provider_packages() self.fill_packages() self.setFocus(self.package_list) finally: g.close_busy_dialog() elif control_id == 1000: self._configure_package( self.package_list.getSelectedItem().getLabel()) elif control_id == 3003: package = self.package_list.getSelectedItem().getLabel() g.show_busy_dialog() try: confirm = xbmcgui.Dialog().yesno( g.ADDON_NAME, g.get_language_string(30293).format(package)) if not confirm: g.close_busy_dialog() return self.providers_class.uninstall_package( package=self.package_list.getSelectedItem().getLabel()) self.packages = self.providerCache.get_provider_packages() self.fill_packages() self.setFocus(self.package_list) finally: g.close_busy_dialog() g.close_busy_dialog() elif control_id == 3004: self.flip_mutliple_providers( 'enabled', self.package_list.getSelectedItem().getLabel()) elif control_id == 3005: self.flip_mutliple_providers( 'disabled', self.package_list.getSelectedItem().getLabel()) else: super(ProviderPackages, self).handle_action(action, control_id) def doModal(self): BaseWindow.doModal(self) self.clearProperties()
def __init__(self, xml_file, xml_location): BaseWindow.__init__(self, xml_file, xml_location) self.packages = self.providers_class.known_packages self.providers = self.providers_class.known_providers self.package_list = None self.providerCache = ProviderCache()
class ProviderPackages(BaseWindow): providers_class = ProviderInstallManager() def __init__(self, xml_file, xml_location): super(ProviderPackages, self).__init__(xml_file, xml_location) self.packages = self.providers_class.known_packages self.providers = self.providers_class.known_providers self.package_list = None self.providerCache = ProviderCache() def onInit(self): self.package_list = self.getControlList(1000) self.fill_packages() self.set_default_focus(self.package_list, 2999, control_list_reset=True) super(ProviderPackages, self).onInit() def refresh_data(self): self.providers_class.poll_database() self.packages = self.providers_class.known_packages def fill_packages(self): self.refresh_data() self.package_list.reset() for i in self.packages: item = xbmcgui.ListItem(label=i['pack_name']) for info in i: item.setProperty(info, i[info]) self.package_list.addItem(item) @staticmethod def _configure_package(package): try: window = PackageConfiguration( *SkinManager().confirm_skin_path('configure_provider_package.xml'), package_name=package ) window.doModal() finally: del window def flip_mutliple_providers(self, status, package_name): g.show_busy_dialog() providers = [i for i in self.providers if i['package'] == package_name] for i in providers: self.providers_class.flip_provider_status( i['package'], i['provider_name'], status ) self.providers = self.providerCache.get_providers() g.close_busy_dialog() def handle_action(self, action, control_id=None): selected_item = self.package_list.getSelectedItem() package_name = selected_item.getLabel() if selected_item is not None else "" if action == 117: enabled = any( [ p["status"] == "enabled" for p in [i for i in self.providers if i["package"] == package_name] ] ) response = xbmcgui.Dialog().contextmenu( [ g.get_language_string(30475), g.get_language_string(30241) if enabled else g.get_language_string(30240), g.get_language_string(30239), ] ) if response == 0: self._configure_package(package_name) elif response == 1: self.flip_mutliple_providers( 'disabled' if enabled else 'enabled', selected_item.getLabel() ) elif response == 2: g.show_busy_dialog() try: confirm = xbmcgui.Dialog().yesno( g.ADDON_NAME, g.get_language_string(30267).format(package_name) ) if not confirm: g.close_busy_dialog() return self.providers_class.uninstall_package(package=package_name) self.packages = self.providerCache.get_provider_packages() self.fill_packages() self.set_default_focus(self.package_list, 2999) finally: g.close_busy_dialog() if action == 7: if control_id == 1000: self._configure_package(package_name) elif control_id == 2999: self.close() elif control_id == 2002: g.show_busy_dialog() try: self.providers_class.install_package(None) self.packages = self.providerCache.get_provider_packages() self.fill_packages() self.set_default_focus(self.package_list, 2000) finally: g.close_busy_dialog()