Esempio n. 1
0
    def create_from_service_item(self, item):
        """
        Create a custom slide from a text service item

        :param item:  the service item to be converted to a Custom item
        """
        custom = CustomSlide()
        custom.title = item.title
        if item.theme:
            custom.theme_name = item.theme
        else:
            custom.theme_name = ''
        footer = ' '.join(item.raw_footer)
        if footer:
            if footer.startswith(item.title):
                custom.credits = footer[len(item.title) + 1:]
            else:
                custom.credits = footer
        else:
            custom.credits = ''
        custom_xml = CustomXMLBuilder()
        for (idx, slide) in enumerate(item._raw_frames):
            custom_xml.add_verse_to_lyrics('custom', str(idx + 1), slide['raw_slide'])
        custom.text = str(custom_xml.extract_xml(), 'utf-8')
        self.plugin.db_manager.save_object(custom)
        self.on_search_text_button_clicked()
Esempio n. 2
0
 def create_from_service_item(self, item):
     """
     Create a custom slide from a text service item
     """
     custom = CustomSlide()
     custom.title = item.title
     if item.theme:
         custom.theme_name = item.theme
     else:
         custom.theme_name = u''
     footer = u' '.join(item.raw_footer)
     if footer:
         if footer.startswith(item.title):
             custom.credits = footer[len(item.title) + 1:]
         else:
             custom.credits = footer
     else:
         custom.credits = u''
     custom_xml = CustomXMLBuilder()
     for (idx, slide) in enumerate(item._raw_frames):
         custom_xml.add_verse_to_lyrics(u'custom', unicode(idx + 1), slide['raw_slide'])
     custom.text = unicode(custom_xml.extract_xml(), u'utf-8')
     self.plugin.manager.save_object(custom)
     self.onSearchTextButtonClicked()
     if item.name.lower() == u'custom':
         Receiver.send_message(u'service_item_update', u'%s:%s:%s' % (custom.id, item.unique_identifier, False))
Esempio n. 3
0
    def load_custom(self, id, preview=False):
        """
        Called when editing or creating a new custom.

        :param id: The custom's id. If zero, then a new custom is created.
        :param preview: States whether the custom is edited while being previewed in the preview panel.
        """
        self.slide_list_view.clear()
        if id == 0:
            self.custom_slide = CustomSlide()
            self.title_edit.setText('')
            self.credit_edit.setText('')
            self.theme_combo_box.setCurrentIndex(0)
        else:
            self.custom_slide = self.manager.get_object(CustomSlide, id)
            self.title_edit.setText(self.custom_slide.title)
            self.credit_edit.setText(self.custom_slide.credits)
            custom_xml = CustomXMLParser(self.custom_slide.text)
            slide_list = custom_xml.get_verses()
            self.slide_list_view.addItems([slide[1] for slide in slide_list])
            theme = self.custom_slide.theme_name
            find_and_set_in_combo_box(self.theme_combo_box, theme)
        self.title_edit.setFocus()
        # If not preview hide the preview button.
        self.preview_button.setVisible(preview)
Esempio n. 4
0
 def on_clone_click(self):
     """
     Clone the selected Custom item
     """
     item = self.list_view.currentItem()
     item_id = item.data(QtCore.Qt.UserRole)
     old_custom_slide = self.plugin.db_manager.get_object(
         CustomSlide, item_id)
     new_custom_slide = CustomSlide()
     new_custom_slide.title = '{title} <{text}>'.format(
         title=old_custom_slide.title,
         text=translate('CustomPlugin.MediaItem', 'copy',
                        'For item cloning'))
     new_custom_slide.text = old_custom_slide.text
     new_custom_slide.credits = old_custom_slide.credits
     new_custom_slide.theme_name = old_custom_slide.theme_name
     self.plugin.db_manager.save_object(new_custom_slide)
     self.on_search_text_button_clicked()
Esempio n. 5
0
 def add_slide(self, item_title, html_details, theme_name):
     custom_slide = CustomSlide()
     custom_slide.title = item_title
     sxml = CustomXMLBuilder()
     slide_content = ''
     if html_details is None:
         slide_content = item_title
     else:
         # we need non-html here, but the input is html
         slide_content = self._process_details(html_details)
     sxml.add_verse_to_lyrics('custom', str(1), slide_content)
     custom_slide.text = str(sxml.extract_xml(), 'utf-8')
     custom_slide.credits = 'pco'
     custom_slide.theme_name = theme_name
     custom = Registry().get('custom')
     custom_db_manager = custom.plugin.db_manager
     custom_db_manager.save_object(custom_slide)
     return custom_slide.id