Ejemplo n.º 1
0
 def __init__(self):
     super(SongUsagePlugin, self).__init__('songusage',
                                           __default_settings__)
     self.manager = Manager('songusage', init_schema, upgrade_mod=upgrade)
     self.weight = -4
     self.icon = UiIcons().song_usage
     self.song_usage_active = False
Ejemplo n.º 2
0
    def test_image_filenames_table(self):
        """
        Test that the ImageFilenames table is correctly upgraded to the latest version
        """
        # GIVEN: An unversioned image database
        temp_db_name = os.path.join(self.tmp_folder, 'image-v0.sqlite')
        shutil.copyfile(
            os.path.join(TEST_RESOURCES_PATH, 'images', 'image-v0.sqlite'),
            temp_db_name)

        with patch.object(AppLocation,
                          'get_data_path',
                          return_value=Path('/', 'test', 'dir')):
            # WHEN: Initalising the database manager
            manager = Manager('images',
                              init_schema,
                              db_file_path=temp_db_name,
                              upgrade_mod=upgrade)

            # THEN: The database should have been upgraded and image_filenames.file_path should return Path objects
            upgraded_results = manager.get_all_objects(ImageFilenames)

            expected_result_data = {
                1: Path('/', 'test', 'image1.jpg'),
                2: Path('/', 'test', 'dir', 'image2.jpg'),
                3: Path('/', 'test', 'dir', 'subdir', 'image3.jpg')
            }

            assert len(upgraded_results) == 3
            for result in upgraded_results:
                assert expected_result_data[result.id] == result.file_path
Ejemplo n.º 3
0
 def __init__(self):
     super(CustomPlugin, self).__init__('custom', __default_settings__,
                                        CustomMediaItem, CustomTab)
     self.weight = -5
     self.db_manager = Manager('custom', init_schema)
     self.icon_path = ':/plugins/plugin_custom.png'
     self.icon = build_icon(self.icon_path)
Ejemplo n.º 4
0
    def __init__(self, parent, **kwargs):
        """
        The constructor loads up the database and creates and initialises the
        tables if the database doesn't exist.

        :param parent:
        :param kwargs:
            ``path``
                The path to the bible database file.

            ``name``
                The name of the database. This is also used as the file name for SQLite databases.
        """
        log.info('BibleDB loaded')
        self.bible_plugin = parent
        self.session = None
        if 'path' not in kwargs:
            raise KeyError('Missing keyword argument "path".')
        if 'name' not in kwargs and 'file' not in kwargs:
            raise KeyError('Missing keyword argument "name" or "file".')
        self.stop_import_flag = False
        if 'name' in kwargs:
            self.name = kwargs['name']
            if not isinstance(self.name, str):
                self.name = str(self.name, 'utf-8')
            self.file = clean_filename(self.name) + '.sqlite'
        if 'file' in kwargs:
            self.file = kwargs['file']
        Manager.__init__(self, 'bibles', init_schema, self.file, upgrade)
        if self.session and 'file' in kwargs:
                self.get_name()
        if 'path' in kwargs:
            self.path = kwargs['path']
        self.wizard = None
        Registry().register_function('openlp_stop_wizard', self.stop_import)
Ejemplo n.º 5
0
 def __init__(self):
     super(SongUsagePlugin, self).__init__('songusage', __default_settings__)
     self.manager = Manager('songusage', init_schema, upgrade_mod=upgrade)
     self.weight = -4
     self.icon = build_icon(':/plugins/plugin_songusage.png')
     self.active_icon = build_icon(':/songusage/song_usage_active.png')
     self.inactive_icon = build_icon(':/songusage/song_usage_inactive.png')
     self.song_usage_active = False
Ejemplo n.º 6
0
 def __init__(self):
     super(SongUsagePlugin, self).__init__('songusage')
     self.manager = Manager('songusage', init_schema, upgrade_mod=upgrade)
     self.weight = -4
     self.icon = UiIcons().song_usage
     self.song_usage_active = False
     State().add_service('song_usage', self.weight, is_plugin=True)
     State().update_pre_conditions('song_usage',
                                   self.check_pre_conditions())
Ejemplo n.º 7
0
 def __init__(self):
     super(CustomPlugin, self).__init__('custom', __default_settings__,
                                        CustomMediaItem, CustomTab)
     self.weight = -5
     self.db_manager = Manager('custom', init_schema)
     self.icon_path = UiIcons().clone
     self.icon = build_icon(self.icon_path)
     register_endpoint(custom_endpoint)
     register_endpoint(api_custom_endpoint)
Ejemplo n.º 8
0
 def __init__(self):
     """
     Class __init__ method
     """
     super(AlertsPlugin, self).__init__('alerts', __default_settings__, settings_tab_class=AlertsTab)
     self.weight = -3
     self.icon_path = ':/plugins/plugin_alerts.png'
     self.icon = build_icon(self.icon_path)
     AlertsManager(self)
     self.manager = Manager('alerts', init_schema)
     self.alert_form = AlertForm(self)
Ejemplo n.º 9
0
 def __init__(self):
     super(CustomPlugin, self).__init__('custom', CustomMediaItem,
                                        CustomTab)
     self.weight = -5
     self.db_manager = Manager('custom', init_schema)
     self.icon_path = UiIcons().clone
     self.icon = build_icon(self.icon_path)
     register_endpoint(custom_endpoint)
     register_endpoint(api_custom_endpoint)
     State().add_service(self.name, self.weight, is_plugin=True)
     State().update_pre_conditions(self.name, self.check_pre_conditions())
Ejemplo n.º 10
0
 def __init__(self):
     """
     Create and set up the Songs plugin.
     """
     super(SongsPlugin, self).__init__('songs', __default_settings__,
                                       SongMediaItem, SongsTab)
     self.manager = Manager('songs', init_schema, upgrade_mod=upgrade)
     self.weight = -10
     self.icon_path = ':/plugins/plugin_songs.png'
     self.icon = build_icon(self.icon_path)
     self.songselect_form = None
Ejemplo n.º 11
0
 def __init__(self):
     """
     Class __init__ method
     """
     super(AlertsPlugin, self).__init__('alerts',
                                        __default_settings__,
                                        settings_tab_class=AlertsTab)
     self.weight = -3
     self.icon_path = UiIcons().alert
     self.icon = self.icon_path
     AlertsManager(self)
     self.manager = Manager('alerts', init_schema)
     self.alert_form = AlertForm(self)
     register_endpoint(alerts_endpoint)
     register_endpoint(api_alerts_endpoint)
Ejemplo n.º 12
0
 def __init__(self):
     """
     Class __init__ method
     """
     super(AlertsPlugin, self).__init__('alerts',
                                        settings_tab_class=AlertsTab)
     self.weight = -3
     self.icon_path = UiIcons().alert
     self.icon = self.icon_path
     AlertsManager(self)
     self.manager = Manager('alerts', init_schema)
     self.alert_form = AlertForm(self)
     register_endpoint(alerts_endpoint)
     register_endpoint(api_alerts_endpoint)
     State().add_service(self.name, self.weight, is_plugin=True)
     State().update_pre_conditions(self.name, self.check_pre_conditions())
Ejemplo n.º 13
0
 def __init__(self):
     super(ImagePlugin, self).__init__('images', __default_settings__,
                                       ImageMediaItem, ImageTab)
     self.manager = Manager('images', init_schema)
     self.weight = -7
     self.icon_path = ':/plugins/plugin_images.png'
     self.icon = build_icon(self.icon_path)
Ejemplo n.º 14
0
 def __init__(self):
     super(AlertsPlugin, self).__init__('alerts', __default_settings__, settings_tab_class=AlertsTab)
     self.weight = -3
     self.icon_path = ':/plugins/plugin_alerts.png'
     self.icon = build_icon(self.icon_path)
     self.alerts_manager = AlertsManager(self)
     self.manager = Manager('alerts', init_schema)
     self.alert_form = AlertForm(self)
Ejemplo n.º 15
0
 def __init__(self):
     Plugin.__init__(self, u'alerts', __default_settings__, settings_tab_class=AlertsTab)
     self.weight = -3
     self.iconPath = u':/plugins/plugin_alerts.png'
     self.icon = build_icon(self.iconPath)
     self.alertsmanager = AlertsManager(self)
     self.manager = Manager(u'alerts', init_schema)
     self.alertForm = AlertForm(self)
Ejemplo n.º 16
0
 def __init__(self):
     super(SongUsagePlugin, self).__init__('songusage', __default_settings__)
     self.manager = Manager('songusage', init_schema, upgrade_mod=upgrade)
     self.weight = -4
     self.icon = build_icon(':/plugins/plugin_songusage.png')
     self.active_icon = build_icon(':/songusage/song_usage_active.png')
     self.inactive_icon = build_icon(':/songusage/song_usage_inactive.png')
     self.song_usage_active = False
Ejemplo n.º 17
0
 def __init__(self):
     super(ImagePlugin, self).__init__('images', __default_settings__,
                                       ImageMediaItem, ImageTab)
     self.manager = Manager('images', init_schema, upgrade_mod=upgrade)
     self.weight = -7
     self.icon_path = UiIcons().picture
     self.icon = build_icon(self.icon_path)
     register_endpoint(images_endpoint)
     register_endpoint(api_images_endpoint)
Ejemplo n.º 18
0
 def __init__(self):
     """
     Create and set up the Songs plugin.
     """
     super(SongsPlugin, self).__init__('songs', SongMediaItem, SongsTab)
     self.manager = Manager('songs', init_schema, upgrade_mod=upgrade)
     self.weight = -10
     self.icon_path = UiIcons().music
     self.icon = build_icon(self.icon_path)
     self.songselect_form = None
     self.settings.extend_default_settings(song_footer)
     register_endpoint(songs_endpoint)
     register_endpoint(api_songs_endpoint)
     State().add_service(self.name, self.weight, is_plugin=True)
     State().update_pre_conditions(self.name, self.check_pre_conditions())
     if not self.settings.value('songs/last import type'):
         self.settings.setValue('songs/last import type',
                                SongFormat.OpenLyrics)
Ejemplo n.º 19
0
 def __init__(self):
     """
     Create and set up the Songs plugin.
     """
     super(SongsPlugin, self).__init__('songs', __default_settings__, SongMediaItem, SongsTab)
     self.manager = Manager('songs', init_schema, upgrade_mod=upgrade)
     self.weight = -10
     self.icon_path = ':/plugins/plugin_songs.png'
     self.icon = build_icon(self.icon_path)
Ejemplo n.º 20
0
 def __init__(self):
     super(ImagePlugin, self).__init__('images', ImageMediaItem, ImageTab)
     self.manager = Manager('images', init_schema, upgrade_mod=upgrade)
     self.weight = -7
     self.icon_path = UiIcons().picture
     self.icon = build_icon(self.icon_path)
     register_endpoint(images_endpoint)
     register_endpoint(api_images_endpoint)
     State().add_service('image', self.weight, is_plugin=True)
     State().update_pre_conditions('image', self.check_pre_conditions())
Ejemplo n.º 21
0
 def _setup(self, parent, **kwargs):
     """
     Run some initial setup. This method is separate from __init__ in order to mock it out in tests.
     """
     self.bible_plugin = parent
     self.session = None
     if 'path' not in kwargs:
         raise KeyError('Missing keyword argument "path".')
     self.path = kwargs['path']
     if 'name' not in kwargs and 'file' not in kwargs:
         raise KeyError('Missing keyword argument "name" or "file".')
     if 'name' in kwargs:
         self.name = kwargs['name']
         if not isinstance(self.name, str):
             self.name = str(self.name, 'utf-8')
         self.file_path = Path(clean_filename(self.name) + '.sqlite')
     if 'file' in kwargs:
         self.file_path = kwargs['file']
     Manager.__init__(self, 'bibles', init_schema, self.file_path, upgrade)
     if self.session and 'file' in kwargs:
         self.get_name()
     self._is_web_bible = None
Ejemplo n.º 22
0
 def _setup(self, parent, **kwargs):
     """
     Run some initial setup. This method is separate from __init__ in order to mock it out in tests.
     """
     self.bible_plugin = parent
     self.session = None
     if 'path' not in kwargs:
         raise KeyError('Missing keyword argument "path".')
     if 'name' not in kwargs and 'file' not in kwargs:
         raise KeyError('Missing keyword argument "name" or "file".')
     if 'name' in kwargs:
         self.name = kwargs['name']
         if not isinstance(self.name, str):
             self.name = str(self.name, 'utf-8')
         self.file = clean_filename(self.name) + '.sqlite'
     if 'file' in kwargs:
         self.file = kwargs['file']
     Manager.__init__(self, 'bibles', init_schema, self.file, upgrade)
     if self.session and 'file' in kwargs:
             self.get_name()
     if 'path' in kwargs:
         self.path = kwargs['path']
Ejemplo n.º 23
0
    def __init__(self, parent, **kwargs):
        """
        The constructor loads up the database and creates and initialises the
        tables if the database doesn't exist.

        :param parent:
        :param kwargs:
            ``path``
                The path to the bible database file.

            ``name``
                The name of the database. This is also used as the file name for SQLite databases.
        """
        log.info('BibleDB loaded')
        QtCore.QObject.__init__(self)
        self.bible_plugin = parent
        self.session = None
        if 'path' not in kwargs:
            raise KeyError('Missing keyword argument "path".')
        if 'name' not in kwargs and 'file' not in kwargs:
            raise KeyError('Missing keyword argument "name" or "file".')
        self.stop_import_flag = False
        if 'name' in kwargs:
            self.name = kwargs['name']
            if not isinstance(self.name, str):
                self.name = str(self.name, 'utf-8')
            self.file = clean_filename(self.name) + '.sqlite'
        if 'file' in kwargs:
            self.file = kwargs['file']
        Manager.__init__(self, 'bibles', init_schema, self.file, upgrade)
        if self.session and 'file' in kwargs:
                self.get_name()
        if 'path' in kwargs:
            self.path = kwargs['path']
        self.wizard = None
        Registry().register_function('openlp_stop_wizard', self.stop_import)
Ejemplo n.º 24
0
    def __init__(self, parent, **kwargs):
        """
        The constructor loads up the database and creates and initialises the
        tables if the database doesn't exist.

        **Required keyword arguments:**

        ``path``
            The path to the bible database file.

        ``name``
            The name of the database. This is also used as the file name for
            SQLite databases.
        """
        log.info(u'BibleDB loaded')
        QtCore.QObject.__init__(self)
        self.bible_plugin = parent
        if u'path' not in kwargs:
            raise KeyError(u'Missing keyword argument "path".')
        if u'name' not in kwargs and u'file' not in kwargs:
            raise KeyError(u'Missing keyword argument "name" or "file".')
        self.stop_import_flag = False
        if u'name' in kwargs:
            self.name = kwargs[u'name']
            if not isinstance(self.name, unicode):
                self.name = unicode(self.name, u'utf-8')
            self.file = clean_filename(self.name) + u'.sqlite'
        if u'file' in kwargs:
            self.file = kwargs[u'file']
        Manager.__init__(self, u'bibles', init_schema, self.file, upgrade)
        if u'file' in kwargs:
            self.get_name()
        if u'path' in kwargs:
            self.path = kwargs[u'path']
        self.wizard = None
        QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import)
Ejemplo n.º 25
0
class SongsPlugin(Plugin):
    """
    This is the number 1 plugin, if importance were placed on any
    plugins. This plugin enables the user to create, edit and display
    songs. Songs are divided into verses, and the verse order can be
    specified. Authors, topics and song books can be assigned to songs
    as well.
    """
    log.info('Song Plugin loaded')

    def __init__(self):
        """
        Create and set up the Songs plugin.
        """
        super(SongsPlugin, self).__init__('songs', __default_settings__, SongMediaItem, SongsTab)
        self.manager = Manager('songs', init_schema, upgrade_mod=upgrade)
        self.weight = -10
        self.icon_path = ':/plugins/plugin_songs.png'
        self.icon = build_icon(self.icon_path)

    def check_pre_conditions(self):
        """
        Check the plugin can run.
        """
        return self.manager.session is not None

    def initialise(self):
        log.info('Songs Initialising')
        super(SongsPlugin, self).initialise()
        self.song_import_item.setVisible(True)
        self.song_export_item.setVisible(True)
        self.tools_reindex_item.setVisible(True)
        self.tools_find_duplicates.setVisible(True)
        action_list = ActionList.get_instance()
        action_list.add_action(self.song_import_item, UiStrings().Import)
        action_list.add_action(self.song_export_item, UiStrings().Export)
        action_list.add_action(self.tools_reindex_item, UiStrings().Tools)
        action_list.add_action(self.tools_find_duplicates, UiStrings().Tools)

    def add_import_menu_item(self, import_menu):
        """
        Give the Songs plugin the opportunity to add items to the
        **Import** menu.

        ``import_menu``
            The actual **Import** menu item, so that your actions can
            use it as their parent.
        """
        # Main song import menu item - will eventually be the only one
        self.song_import_item = create_action(import_menu, 'songImportItem',
            text=translate('SongsPlugin', '&Song'),
            tooltip=translate('SongsPlugin', 'Import songs using the import wizard.'),
            triggers=self.on_song_import_item_clicked)
        import_menu.addAction(self.song_import_item)

    def add_export_menu_Item(self, export_menu):
        """
        Give the Songs plugin the opportunity to add items to the
        **Export** menu.

        ``export_menu``
            The actual **Export** menu item, so that your actions can
            use it as their parent.
        """
        # Main song import menu item - will eventually be the only one
        self.song_export_item = create_action(export_menu, 'songExportItem',
            text=translate('SongsPlugin', '&Song'),
            tooltip=translate('SongsPlugin', 'Exports songs using the export wizard.'),
            triggers=self.on_song_export_item_clicked)
        export_menu.addAction(self.song_export_item)

    def add_tools_menu_item(self, tools_menu):
        """
        Give the Songs plugin the opportunity to add items to the
        **Tools** menu.

        ``tools_menu``
            The actual **Tools** menu item, so that your actions can
            use it as their parent.
        """
        log.info('add tools menu')
        self.tools_reindex_item = create_action(tools_menu, 'toolsReindexItem',
            text=translate('SongsPlugin', '&Re-index Songs'),
            icon=':/plugins/plugin_songs.png',
            statustip=translate('SongsPlugin', 'Re-index the songs database to improve searching and ordering.'),
            visible=False, triggers=self.on_tools_reindex_item_triggered)
        tools_menu.addAction(self.tools_reindex_item)
        self.tools_find_duplicates = create_action(tools_menu, 'toolsFindDuplicates',
            text=translate('SongsPlugin', 'Find &Duplicate Songs'),
            statustip=translate('SongsPlugin',
            'Find and remove duplicate songs in the song database.'),
            visible=False, triggers=self.on_tools_find_duplicates_triggered, can_shortcuts=True)
        tools_menu.addAction(self.tools_find_duplicates)

    def on_tools_reindex_item_triggered(self):
        """
        Rebuild each song.
        """
        maxSongs = self.manager.get_object_count(Song)
        if maxSongs == 0:
            return
        progress_dialog = QtGui.QProgressDialog(translate('SongsPlugin', 'Reindexing songs...'), UiStrings().Cancel,
            0, maxSongs, self.main_window)
        progress_dialog.setWindowTitle(translate('SongsPlugin', 'Reindexing songs'))
        progress_dialog.setWindowModality(QtCore.Qt.WindowModal)
        songs = self.manager.get_all_objects(Song)
        for number, song in enumerate(songs):
            clean_song(self.manager, song)
            progress_dialog.setValue(number + 1)
        self.manager.save_objects(songs)
        self.media_item.on_search_text_button_clicked()

    def on_tools_find_duplicates_triggered(self):
        """
        Search for duplicates in the song database.
        """
        DuplicateSongRemovalForm(self).exec_()

    def on_song_import_item_clicked(self):
        if self.media_item:
            self.media_item.on_import_click()

    def on_song_export_item_clicked(self):
        if self.media_item:
            self.media_item.on_export_click()

    def about(self):
        return translate('SongsPlugin', '<strong>Songs Plugin</strong>'
            '<br />The songs plugin provides the ability to display and manage songs.')

    def uses_theme(self, theme):
        """
        Called to find out if the song plugin is currently using a theme.

        Returns True if the theme is being used, otherwise returns False.
        """
        if self.manager.get_all_objects(Song, Song.theme_name == theme):
            return True
        return False

    def rename_theme(self, oldTheme, newTheme):
        """
        Renames a theme the song plugin is using making the plugin use the new
        name.

        ``oldTheme``
            The name of the theme the plugin should stop using.

        ``newTheme``
            The new name the plugin should now use.
        """
        songsUsingTheme = self.manager.get_all_objects(Song, Song.theme_name == oldTheme)
        for song in songsUsingTheme:
            song.theme_name = newTheme
            self.manager.save_object(song)

    def importSongs(self, format, **kwargs):
        class_ = SongFormat.get(format, 'class')
        importer = class_(self.manager, **kwargs)
        importer.register(self.media_item.import_wizard)
        return importer

    def set_plugin_text_strings(self):
        """
        Called to define all translatable texts of the plugin
        """
        ## Name PluginList ##
        self.text_strings[StringContent.Name] = {
            'singular': translate('SongsPlugin', 'Song', 'name singular'),
            'plural': translate('SongsPlugin', 'Songs', 'name plural')
        }
        ## Name for MediaDockManager, SettingsManager ##
        self.text_strings[StringContent.VisibleName] = {
            'title': translate('SongsPlugin', 'Songs', 'container title')
        }
        # Middle Header Bar
        tooltips = {
            'load': '',
            'import': '',
            'new': translate('SongsPlugin', 'Add a new song.'),
            'edit': translate('SongsPlugin', 'Edit the selected song.'),
            'delete': translate('SongsPlugin', 'Delete the selected song.'),
            'preview': translate('SongsPlugin', 'Preview the selected song.'),
            'live': translate('SongsPlugin', 'Send the selected song live.'),
            'service': translate('SongsPlugin', 'Add the selected song to the service.')
        }
        self.set_plugin_ui_text_strings(tooltips)

    def first_time(self):
        """
        If the first time wizard has run, this function is run to import all the
        new songs into the database.
        """
        self.application.process_events()
        self.on_tools_reindex_item_triggered()
        self.application.process_events()
        db_dir = os.path.join(gettempdir(), 'openlp')
        if not os.path.exists(db_dir):
            return
        song_dbs = []
        song_count = 0
        for sfile in os.listdir(db_dir):
            if sfile.startswith('songs_') and sfile.endswith('.sqlite'):
                self.application.process_events()
                song_dbs.append(os.path.join(db_dir, sfile))
                song_count += self._countSongs(os.path.join(db_dir, sfile))
        if not song_dbs:
            return
        self.application.process_events()
        progress = QtGui.QProgressDialog(self.main_window)
        progress.setWindowModality(QtCore.Qt.WindowModal)
        progress.setWindowTitle(translate('OpenLP.Ui', 'Importing Songs'))
        progress.setLabelText(translate('OpenLP.Ui', 'Starting import...'))
        progress.setCancelButton(None)
        progress.setRange(0, song_count)
        progress.setMinimumDuration(0)
        progress.forceShow()
        self.application.process_events()
        for db in song_dbs:
            importer = OpenLPSongImport(self.manager, filename=db)
            importer.doImport(progress)
            self.application.process_events()
        progress.setValue(song_count)
        self.media_item.on_search_text_button_clicked()

    def finalise(self):
        """
        Time to tidy up on exit
        """
        log.info('Songs Finalising')
        self.new_service_created()
        # Clean up files and connections
        self.manager.finalise()
        self.song_import_item.setVisible(False)
        self.song_export_item.setVisible(False)
        self.tools_reindex_item.setVisible(False)
        self.tools_find_duplicates.setVisible(False)
        action_list = ActionList.get_instance()
        action_list.remove_action(self.song_import_item, UiStrings().Import)
        action_list.remove_action(self.song_export_item, UiStrings().Export)
        action_list.remove_action(self.tools_reindex_item, UiStrings().Tools)
        action_list.remove_action(self.tools_find_duplicates, UiStrings().Tools)
        super(SongsPlugin, self).finalise()

    def new_service_created(self):
        """
        Remove temporary songs from the database
        """
        songs = self.manager.get_all_objects(Song, Song.temporary == True)
        for song in songs:
            self.manager.delete_object(Song, song.id)

    def _countSongs(self, db_file):
        """
        Provide a count of the songs in the database
        """
        connection = sqlite3.connect(db_file)
        cursor = connection.cursor()
        cursor.execute('SELECT COUNT(id) AS song_count FROM songs')
        song_count = cursor.fetchone()[0]
        connection.close()
        try:
            song_count = int(song_count)
        except (TypeError, ValueError):
            song_count = 0
        return song_count
Ejemplo n.º 26
0
class AlertsPlugin(Plugin):
    """
    The Alerts Plugin Class
    """
    log.info('Alerts Plugin loaded')

    def __init__(self):
        """
        Class __init__ method
        """
        super(AlertsPlugin, self).__init__('alerts',
                                           __default_settings__,
                                           settings_tab_class=AlertsTab)
        self.weight = -3
        self.icon_path = UiIcons().alert
        self.icon = self.icon_path
        AlertsManager(self)
        self.manager = Manager('alerts', init_schema)
        self.alert_form = AlertForm(self)
        register_endpoint(alerts_endpoint)
        register_endpoint(api_alerts_endpoint)

    def add_tools_menu_item(self, tools_menu):
        """
        Give the alerts plugin the opportunity to add items to the **Tools** menu.

        :param tools_menu: The actual **Tools** menu item, so that your actions can use it as their parent.
        """
        log.info('add tools menu')
        self.tools_alert_item = create_action(
            tools_menu,
            'toolsAlertItem',
            text=translate('AlertsPlugin', '&Alert'),
            icon=UiIcons().alert,
            statustip=translate('AlertsPlugin', 'Show an alert message.'),
            visible=False,
            can_shortcuts=True,
            triggers=self.on_alerts_trigger)
        self.main_window.tools_menu.addAction(self.tools_alert_item)

    def initialise(self):
        """
        Initialise plugin
        """
        log.info('Alerts Initialising')
        super(AlertsPlugin, self).initialise()
        self.tools_alert_item.setVisible(True)
        action_list = ActionList.get_instance()
        action_list.add_action(self.tools_alert_item, UiStrings().Tools)

    def finalise(self):
        """
        Tidy up on exit
        """
        log.info('Alerts Finalising')
        self.manager.finalise()
        super(AlertsPlugin, self).finalise()
        self.tools_alert_item.setVisible(False)
        action_list = ActionList.get_instance()
        action_list.remove_action(self.tools_alert_item, 'Tools')

    def toggle_alerts_state(self):
        """
        Switch the alerts state
        """
        self.alerts_active = not self.alerts_active
        Settings().setValue(self.settings_section + '/active',
                            self.alerts_active)

    def on_alerts_trigger(self):
        """
        Start of the Alerts dialog triggered from the main menu.
        """
        self.alert_form.load_list()
        self.alert_form.exec()

    @staticmethod
    def about():
        """
        Plugin Alerts about method

        :return: text
        """
        about_text = translate(
            'AlertsPlugin', '<strong>Alerts Plugin</strong>'
            '<br />The alert plugin controls the displaying of alerts on the display screen.'
        )
        return about_text

    def set_plugin_text_strings(self):
        """
        Called to define all translatable texts of the plugin
        """
        # Name PluginList
        self.text_strings[StringContent.Name] = {
            'singular': translate('AlertsPlugin', 'Alert', 'name singular'),
            'plural': translate('AlertsPlugin', 'Alerts', 'name plural')
        }
        # Name for MediaDockManager, SettingsManager
        self.text_strings[StringContent.VisibleName] = {
            'title': translate('AlertsPlugin', 'Alerts', 'container title')
        }

    @staticmethod
    def get_display_javascript():
        """
        Add Javascript to the main display.
        """
        return JAVASCRIPT

    def get_display_css(self):
        """
        Add CSS to the main display.
        """
        align = VerticalType.Names[self.settings_tab.location]
        return CSS.format(vertical_align=align,
                          font_family=self.settings_tab.font_face,
                          font_size=self.settings_tab.font_size,
                          color=self.settings_tab.font_color,
                          background_color=self.settings_tab.background_color)

    @staticmethod
    def get_display_html():
        """
        Add HTML to the main display.
        """
        return HTML

    def refresh_css(self, frame):
        """
        Trigger an update of the CSS in the main display.

        :param frame: The Web frame holding the page.
        """
        align = VerticalType.Names[self.settings_tab.location]
        frame.evaluateJavaScript(
            'update_css("{align}", "{face}", "{size}", "{color}", '
            '"{background}")'.format(
                align=align,
                face=self.settings_tab.font_face,
                size=self.settings_tab.font_size,
                color=self.settings_tab.font_color,
                background=self.settings_tab.background_color))
Ejemplo n.º 27
0
class AlertsPlugin(Plugin):
    log.info('Alerts Plugin loaded')

    def __init__(self):
        super(AlertsPlugin, self).__init__('alerts', __default_settings__, settings_tab_class=AlertsTab)
        self.weight = -3
        self.icon_path = ':/plugins/plugin_alerts.png'
        self.icon = build_icon(self.icon_path)
        self.alerts_manager = AlertsManager(self)
        self.manager = Manager('alerts', init_schema)
        self.alert_form = AlertForm(self)

    def add_tools_menu_item(self, tools_menu):
        """
        Give the alerts plugin the opportunity to add items to the **Tools** menu.

        ``tools_menu``
            The actual **Tools** menu item, so that your actions can use it as their parent.
        """
        log.info('add tools menu')
        self.tools_alert_item = create_action(tools_menu, 'toolsAlertItem',
            text=translate('AlertsPlugin', '&Alert'), icon=':/plugins/plugin_alerts.png',
            statustip=translate('AlertsPlugin', 'Show an alert message.'),
            visible=False, can_shortcuts=True, triggers=self.on_alerts_trigger)
        self.main_window.tools_menu.addAction(self.tools_alert_item)

    def initialise(self):
        log.info('Alerts Initialising')
        super(AlertsPlugin, self).initialise()
        self.tools_alert_item.setVisible(True)
        action_list = ActionList.get_instance()
        action_list.add_action(self.tools_alert_item, UiStrings().Tools)

    def finalise(self):
        """
        Tidy up on exit
        """
        log.info('Alerts Finalising')
        self.manager.finalise()
        super(AlertsPlugin, self).finalise()
        self.tools_alert_item.setVisible(False)
        action_list = ActionList.get_instance()
        action_list.remove_action(self.tools_alert_item, 'Tools')

    def toggle_alerts_state(self):
        self.alerts_active = not self.alerts_active
        Settings().setValue(self.settings_section + '/active', self.alerts_active)

    def on_alerts_trigger(self):
        self.alert_form.load_list()
        self.alert_form.exec_()

    def about(self):
        about_text = translate('AlertsPlugin', '<strong>Alerts Plugin</strong>'
            '<br />The alert plugin controls the displaying of nursery alerts on the display screen.')
        return about_text

    def set_plugin_text_strings(self):
        """
        Called to define all translatable texts of the plugin
        """
        ## Name PluginList ##
        self.text_strings[StringContent.Name] = {
            'singular': translate('AlertsPlugin', 'Alert', 'name singular'),
            'plural': translate('AlertsPlugin', 'Alerts', 'name plural')
        }
        ## Name for MediaDockManager, SettingsManager ##
        self.text_strings[StringContent.VisibleName] = {
            'title': translate('AlertsPlugin', 'Alerts', 'container title')
        }

    def get_display_javascript(self):
        """
        Add Javascript to the main display.
        """
        return JAVASCRIPT

    def get_display_css(self):
        """
        Add CSS to the main display.
        """
        align = VerticalType.Names[self.settings_tab.location]
        return CSS % (align, self.settings_tab.font_face, self.settings_tab.font_size, self.settings_tab.font_color,
            self.settings_tab.background_color)

    def get_display_html(self):
        """
        Add HTML to the main display.
        """
        return HTML

    def refresh_css(self, frame):
        """
        Trigger an update of the CSS in the maindisplay.

        ``frame``
            The Web frame holding the page.
        """
        align = VerticalType.Names[self.settings_tab.location]
        frame.evaluateJavaScript('update_css("%s", "%s", "%s", "%s", "%s")' %
            (align, self.settings_tab.font_face, self.settings_tab.font_size,
            self.settings_tab.font_color, self.settings_tab.background_color))
Ejemplo n.º 28
0
class SongsPlugin(Plugin):
    """
    This plugin enables the user to create, edit and display songs. Songs are divided into verses, and the verse order
    can be specified. Authors, topics and song books can be assigned to songs as well.
    """
    log.info('Song Plugin loaded')

    def __init__(self):
        """
        Create and set up the Songs plugin.
        """
        super(SongsPlugin, self).__init__('songs', __default_settings__,
                                          SongMediaItem, SongsTab)
        self.manager = Manager('songs', init_schema, upgrade_mod=upgrade)
        self.weight = -10
        self.icon_path = ':/plugins/plugin_songs.png'
        self.icon = build_icon(self.icon_path)
        self.songselect_form = None

    def check_pre_conditions(self):
        """
        Check the plugin can run.
        """
        return self.manager.session is not None

    def initialise(self):
        """
        Initialise the plugin
        """
        log.info('Songs Initialising')
        super(SongsPlugin, self).initialise()
        self.songselect_form = SongSelectForm(Registry().get('main_window'),
                                              self, self.manager)
        self.songselect_form.initialise()
        self.song_import_item.setVisible(True)
        self.song_export_item.setVisible(True)
        self.tools_reindex_item.setVisible(True)
        self.tools_find_duplicates.setVisible(True)
        action_list = ActionList.get_instance()
        action_list.add_action(self.song_import_item, UiStrings().Import)
        action_list.add_action(self.song_export_item, UiStrings().Export)
        action_list.add_action(self.tools_reindex_item, UiStrings().Tools)
        action_list.add_action(self.tools_find_duplicates, UiStrings().Tools)

    def add_import_menu_item(self, import_menu):
        """
        Give the Songs plugin the opportunity to add items to the **Import** menu.

        :param import_menu: The actual **Import** menu item, so that your actions can use it as their parent.
        """
        # Main song import menu item - will eventually be the only one
        self.song_import_item = create_action(
            import_menu,
            'songImportItem',
            text=translate('SongsPlugin', '&Song'),
            tooltip=translate('SongsPlugin',
                              'Import songs using the import wizard.'),
            triggers=self.on_song_import_item_clicked)
        import_menu.addAction(self.song_import_item)
        self.import_songselect_item = create_action(
            import_menu,
            'import_songselect_item',
            text=translate('SongsPlugin', 'CCLI SongSelect'),
            statustip=translate(
                'SongsPlugin',
                'Import songs from CCLI\'s SongSelect service.'),
            triggers=self.on_import_songselect_item_triggered)
        import_menu.addAction(self.import_songselect_item)

    def add_export_menu_item(self, export_menu):
        """
        Give the Songs plugin the opportunity to add items to the **Export** menu.

        :param export_menu: The actual **Export** menu item, so that your actions can use it as their parent.
        """
        # Main song import menu item - will eventually be the only one
        self.song_export_item = create_action(
            export_menu,
            'songExportItem',
            text=translate('SongsPlugin', '&Song'),
            tooltip=translate('SongsPlugin',
                              'Exports songs using the export wizard.'),
            triggers=self.on_song_export_item_clicked)
        export_menu.addAction(self.song_export_item)

    def add_tools_menu_item(self, tools_menu):
        """
        Give the Songs plugin the opportunity to add items to the **Tools** menu.

        :param tools_menu: The actual **Tools** menu item, so that your actions can use it as their parent.
        """
        log.info('add tools menu')
        self.tools_reindex_item = create_action(
            tools_menu,
            'toolsReindexItem',
            text=translate('SongsPlugin', '&Re-index Songs'),
            icon=':/plugins/plugin_songs.png',
            statustip=translate(
                'SongsPlugin',
                'Re-index the songs database to improve searching and ordering.'
            ),
            visible=False,
            triggers=self.on_tools_reindex_item_triggered)
        tools_menu.addAction(self.tools_reindex_item)
        self.tools_find_duplicates = create_action(
            tools_menu,
            'toolsFindDuplicates',
            text=translate('SongsPlugin', 'Find &Duplicate Songs'),
            statustip=translate(
                'SongsPlugin',
                'Find and remove duplicate songs in the song database.'),
            visible=False,
            triggers=self.on_tools_find_duplicates_triggered,
            can_shortcuts=True)
        tools_menu.addAction(self.tools_find_duplicates)

    def on_tools_reindex_item_triggered(self):
        """
        Rebuild each song.
        """
        max_songs = self.manager.get_object_count(Song)
        if max_songs == 0:
            return
        progress_dialog = QtGui.QProgressDialog(
            translate('SongsPlugin', 'Reindexing songs...'),
            UiStrings().Cancel, 0, max_songs, self.main_window)
        progress_dialog.setWindowTitle(
            translate('SongsPlugin', 'Reindexing songs'))
        progress_dialog.setWindowModality(QtCore.Qt.WindowModal)
        songs = self.manager.get_all_objects(Song)
        for number, song in enumerate(songs):
            clean_song(self.manager, song)
            progress_dialog.setValue(number + 1)
        self.manager.save_objects(songs)
        self.media_item.on_search_text_button_clicked()

    def on_tools_find_duplicates_triggered(self):
        """
        Search for duplicates in the song database.
        """
        DuplicateSongRemovalForm(self).exec_()

    def on_import_songselect_item_triggered(self):
        """
        Run the SongSelect importer.
        """
        self.songselect_form.exec_()
        self.media_item.on_search_text_button_clicked()

    def on_song_import_item_clicked(self):
        """
        Run the song import wizard.
        """
        if self.media_item:
            self.media_item.on_import_click()

    def on_song_export_item_clicked(self):
        """
        Run the song export wizard.
        """
        if self.media_item:
            self.media_item.on_export_click()

    def about(self):
        """
        Provides information for the plugin manager to display.

        :return: A translatable string with some basic information about the Songs plugin
        """
        return translate(
            'SongsPlugin', '<strong>Songs Plugin</strong>'
            '<br />The songs plugin provides the ability to display and manage songs.'
        )

    def uses_theme(self, theme):
        """
        Called to find out if the song plugin is currently using a theme.

        :param theme: The theme to check for usage
        :return: True if the theme is being used, otherwise returns False
        """
        if self.manager.get_all_objects(Song, Song.theme_name == theme):
            return True
        return False

    def rename_theme(self, old_theme, new_theme):
        """
        Renames a theme the song plugin is using making the plugin use the new name.

        :param old_theme: The name of the theme the plugin should stop using.
        :param new_theme: The new name the plugin should now use.
        """
        songs_using_theme = self.manager.get_all_objects(
            Song, Song.theme_name == old_theme)
        for song in songs_using_theme:
            song.theme_name = new_theme
            self.manager.save_object(song)

    def import_songs(self, import_format, **kwargs):
        """
        Add the correct importer class

        :param import_format: The import_format to be used
        :param kwargs: The arguments
        :return: the correct importer
        """
        class_ = SongFormat.get(import_format, 'class')
        importer = class_(self.manager, **kwargs)
        importer.register(self.media_item.import_wizard)
        return importer

    def set_plugin_text_strings(self):
        """
        Called to define all translatable texts of the plugin
        """
        # Name PluginList
        self.text_strings[StringContent.Name] = {
            'singular': translate('SongsPlugin', 'Song', 'name singular'),
            'plural': translate('SongsPlugin', 'Songs', 'name plural')
        }
        # Name for MediaDockManager, SettingsManager
        self.text_strings[StringContent.VisibleName] = {
            'title': translate('SongsPlugin', 'Songs', 'container title')
        }
        # Middle Header Bar
        tooltips = {
            'load':
            '',
            'import':
            '',
            'new':
            translate('SongsPlugin', 'Add a new song.'),
            'edit':
            translate('SongsPlugin', 'Edit the selected song.'),
            'delete':
            translate('SongsPlugin', 'Delete the selected song.'),
            'preview':
            translate('SongsPlugin', 'Preview the selected song.'),
            'live':
            translate('SongsPlugin', 'Send the selected song live.'),
            'service':
            translate('SongsPlugin', 'Add the selected song to the service.')
        }
        self.set_plugin_ui_text_strings(tooltips)

    def first_time(self):
        """
        If the first time wizard has run, this function is run to import all the new songs into the database.
        """
        self.application.process_events()
        self.on_tools_reindex_item_triggered()
        self.application.process_events()
        db_dir = os.path.join(gettempdir(), 'openlp')
        if not os.path.exists(db_dir):
            return
        song_dbs = []
        song_count = 0
        for sfile in os.listdir(db_dir):
            if sfile.startswith('songs_') and sfile.endswith('.sqlite'):
                self.application.process_events()
                song_dbs.append(os.path.join(db_dir, sfile))
                song_count += self._count_songs(os.path.join(db_dir, sfile))
        if not song_dbs:
            return
        self.application.process_events()
        progress = QtGui.QProgressDialog(self.main_window)
        progress.setWindowModality(QtCore.Qt.WindowModal)
        progress.setWindowTitle(translate('OpenLP.Ui', 'Importing Songs'))
        progress.setLabelText(translate('OpenLP.Ui', 'Starting import...'))
        progress.setCancelButton(None)
        progress.setRange(0, song_count)
        progress.setMinimumDuration(0)
        progress.forceShow()
        self.application.process_events()
        for db in song_dbs:
            importer = OpenLPSongImport(self.manager, filename=db)
            importer.do_import(progress)
            self.application.process_events()
        progress.setValue(song_count)
        self.media_item.on_search_text_button_clicked()

    def finalise(self):
        """
        Time to tidy up on exit
        """
        log.info('Songs Finalising')
        self.new_service_created()
        # Clean up files and connections
        self.manager.finalise()
        self.song_import_item.setVisible(False)
        self.song_export_item.setVisible(False)
        self.tools_reindex_item.setVisible(False)
        self.tools_find_duplicates.setVisible(False)
        action_list = ActionList.get_instance()
        action_list.remove_action(self.song_import_item, UiStrings().Import)
        action_list.remove_action(self.song_export_item, UiStrings().Export)
        action_list.remove_action(self.tools_reindex_item, UiStrings().Tools)
        action_list.remove_action(self.tools_find_duplicates,
                                  UiStrings().Tools)
        super(SongsPlugin, self).finalise()

    def new_service_created(self):
        """
        Remove temporary songs from the database
        """
        songs = self.manager.get_all_objects(Song, Song.temporary is True)
        for song in songs:
            self.manager.delete_object(Song, song.id)

    def _count_songs(self, db_file):
        """
        Provide a count of the songs in the database

        :param db_file: the database name to count
        """
        connection = sqlite3.connect(db_file)
        cursor = connection.cursor()
        cursor.execute('SELECT COUNT(id) AS song_count FROM songs')
        song_count = cursor.fetchone()[0]
        connection.close()
        try:
            song_count = int(song_count)
        except (TypeError, ValueError):
            song_count = 0
        return song_count
Ejemplo n.º 29
0
class SongUsagePlugin(Plugin):
    """
    Song Usage Plugin class
    """
    log.info('SongUsage Plugin loaded')

    def __init__(self):
        super(SongUsagePlugin, self).__init__('songusage', __default_settings__)
        self.manager = Manager('songusage', init_schema, upgrade_mod=upgrade)
        self.weight = -4
        self.icon = build_icon(':/plugins/plugin_songusage.png')
        self.active_icon = build_icon(':/songusage/song_usage_active.png')
        self.inactive_icon = build_icon(':/songusage/song_usage_inactive.png')
        self.song_usage_active = False

    def check_pre_conditions(self):
        """
        Check the plugin can run.
        """
        return self.manager.session is not None

    def add_tools_menu_item(self, tools_menu):
        """
        Give the SongUsage plugin the opportunity to add items to the **Tools** menu.

        :param tools_menu: The actual **Tools** menu item, so that your actions can use it as their parent.
        """
        log.info('add tools menu')
        self.tools_menu = tools_menu
        self.song_usage_menu = QtWidgets.QMenu(tools_menu)
        self.song_usage_menu.setObjectName('song_usage_menu')
        self.song_usage_menu.setTitle(translate('SongUsagePlugin', '&Song Usage Tracking'))
        # SongUsage Delete
        self.song_usage_delete = create_action(
            tools_menu, 'songUsageDelete',
            text=translate('SongUsagePlugin', '&Delete Tracking Data'),
            statustip=translate('SongUsagePlugin', 'Delete song usage data up to a specified date.'),
            triggers=self.on_song_usage_delete)
        # SongUsage Report
        self.song_usage_report = create_action(
            tools_menu, 'songUsageReport',
            text=translate('SongUsagePlugin', '&Extract Tracking Data'),
            statustip=translate('SongUsagePlugin', 'Generate a report on song usage.'),
            triggers=self.on_song_usage_report)
        # SongUsage activation
        self.song_usage_status = create_action(
            tools_menu, 'songUsageStatus',
            text=translate('SongUsagePlugin', 'Toggle Tracking'),
            statustip=translate('SongUsagePlugin', 'Toggle the tracking of song usage.'), checked=False,
            can_shortcuts=True, triggers=self.toggle_song_usage_state)
        # Add Menus together
        self.tools_menu.addAction(self.song_usage_menu.menuAction())
        self.song_usage_menu.addAction(self.song_usage_status)
        self.song_usage_menu.addSeparator()
        self.song_usage_menu.addAction(self.song_usage_report)
        self.song_usage_menu.addAction(self.song_usage_delete)
        self.song_usage_active_button = QtWidgets.QToolButton(self.main_window.status_bar)
        self.song_usage_active_button.setCheckable(True)
        self.song_usage_active_button.setAutoRaise(True)
        self.song_usage_active_button.setStatusTip(translate('SongUsagePlugin', 'Toggle the tracking of song usage.'))
        self.song_usage_active_button.setObjectName('song_usage_active_button')
        self.main_window.status_bar.insertPermanentWidget(1, self.song_usage_active_button)
        self.song_usage_active_button.hide()
        # Signals and slots
        self.song_usage_active_button.toggled.connect(self.toggle_song_usage_state)
        self.song_usage_menu.menuAction().setVisible(False)

    def initialise(self):
        log.info('SongUsage Initialising')
        super(SongUsagePlugin, self).initialise()
        Registry().register_function('slidecontroller_live_started', self.display_song_usage)
        Registry().register_function('print_service_started', self.print_song_usage)
        self.song_usage_active = Settings().value(self.settings_section + '/active')
        # Set the button and checkbox state
        self.set_button_state()
        action_list = ActionList.get_instance()
        action_list.add_action(self.song_usage_status, translate('SongUsagePlugin', 'Song Usage'))
        action_list.add_action(self.song_usage_delete, translate('SongUsagePlugin', 'Song Usage'))
        action_list.add_action(self.song_usage_report, translate('SongUsagePlugin', 'Song Usage'))
        self.song_usage_delete_form = SongUsageDeleteForm(self.manager, self.main_window)
        self.song_usage_detail_form = SongUsageDetailForm(self, self.main_window)
        self.song_usage_menu.menuAction().setVisible(True)
        self.song_usage_active_button.show()

    def finalise(self):
        """
        Tidy up on exit
        """
        log.info('Plugin Finalise')
        self.manager.finalise()
        super(SongUsagePlugin, self).finalise()
        self.song_usage_menu.menuAction().setVisible(False)
        action_list = ActionList.get_instance()
        action_list.remove_action(self.song_usage_status, translate('SongUsagePlugin', 'Song Usage'))
        action_list.remove_action(self.song_usage_delete, translate('SongUsagePlugin', 'Song Usage'))
        action_list.remove_action(self.song_usage_report, translate('SongUsagePlugin', 'Song Usage'))
        self.song_usage_active_button.hide()
        # stop any events being processed
        self.song_usage_active = False

    def toggle_song_usage_state(self):
        """
        Manage the state of the audit collection and amend
        the UI when necessary,
        """
        self.song_usage_active = not self.song_usage_active
        Settings().setValue(self.settings_section + '/active', self.song_usage_active)
        self.set_button_state()

    def set_button_state(self):
        """
        Keep buttons inline.  Turn of signals to stop dead loop but we need the button and check box set correctly.
        """
        self.song_usage_active_button.blockSignals(True)
        self.song_usage_status.blockSignals(True)
        if self.song_usage_active:
            self.song_usage_active_button.setIcon(self.active_icon)
            self.song_usage_status.setChecked(True)
            self.song_usage_active_button.setChecked(True)
            self.song_usage_active_button.setToolTip(translate('SongUsagePlugin', 'Song usage tracking is active.'))
        else:
            self.song_usage_active_button.setIcon(self.inactive_icon)
            self.song_usage_status.setChecked(False)
            self.song_usage_active_button.setChecked(False)
            self.song_usage_active_button.setToolTip(translate('SongUsagePlugin', 'Song usage tracking is inactive.'))
        self.song_usage_active_button.blockSignals(False)
        self.song_usage_status.blockSignals(False)

    def display_song_usage(self, item):
        """
        Song Usage for which has been displayed

        :param item: Item displayed
        """
        self._add_song_usage(translate('SongUsagePlugin', 'display'), item)

    def print_song_usage(self, item):
        """
        Song Usage for which has been printed

        :param item: Item printed
        """
        self._add_song_usage(translate('SongUsagePlugin', 'printed'), item)

    def _add_song_usage(self, source, item):
        audit = item[0].audit
        if self.song_usage_active and audit:
            song_usage_item = SongUsageItem()
            song_usage_item.usagedate = datetime.today()
            song_usage_item.usagetime = datetime.now().time()
            song_usage_item.title = audit[0]
            song_usage_item.copyright = audit[2]
            song_usage_item.ccl_number = audit[3]
            song_usage_item.authors = ' '.join(audit[1])
            song_usage_item.plugin_name = item[0].name
            song_usage_item.source = source
            self.manager.save_object(song_usage_item)

    def on_song_usage_delete(self):
        """
        Request the delete form to be displayed
        """
        self.song_usage_delete_form.exec()

    def on_song_usage_report(self):
        """
        Display the song usage report generator screen

        """
        self.song_usage_detail_form.initialise()
        self.song_usage_detail_form.exec()

    @staticmethod
    def about():
        """
        The plugin about text

        :return: the text to be displayed
        """
        about_text = translate('SongUsagePlugin',
                               '<strong>SongUsage Plugin</strong><br />'
                               'This plugin tracks the usage of songs in services.')
        return about_text

    def set_plugin_text_strings(self):
        """
        Called to define all translatable texts of the plugin
        """
        # Name PluginList
        self.text_strings[StringContent.Name] = {
            'singular': translate('SongUsagePlugin', 'SongUsage', 'name singular'),
            'plural': translate('SongUsagePlugin', 'SongUsage', 'name plural')
        }
        # Name for MediaDockManager, SettingsManager
        self.text_strings[StringContent.VisibleName] = {
            'title': translate('SongUsagePlugin', 'SongUsage', 'container title')
        }
Ejemplo n.º 30
0
 def __init__(self):
     Plugin.__init__(self, u'custom', __default_settings__, CustomMediaItem, CustomTab)
     self.weight = -5
     self.manager = Manager(u'custom', init_schema)
     self.iconPath = u':/plugins/plugin_custom.png'
     self.icon = build_icon(self.iconPath)
Ejemplo n.º 31
0
class CustomPlugin(Plugin):
    """
    This plugin enables the user to create, edit and display
    custom slide shows. Custom shows are divided into slides.
    Each show is able to have it's own theme.
    Custom shows are designed to replace the use of songs where
    the songs plugin has become restrictive. Examples could be
    Welcome slides, Bible Reading information, Orders of service.
    """
    log.info(u'Custom Plugin loaded')

    def __init__(self):
        Plugin.__init__(self, u'custom', __default_settings__, CustomMediaItem, CustomTab)
        self.weight = -5
        self.manager = Manager(u'custom', init_schema)
        self.iconPath = u':/plugins/plugin_custom.png'
        self.icon = build_icon(self.iconPath)

    def about(self):
        about_text = translate('CustomPlugin', '<strong>Custom Slide Plugin </strong><br />The custom slide plugin '
            'provides the ability to set up custom text slides that can be displayed on the screen '
            'the same way songs are. This plugin provides greater freedom over the songs plugin.')
        return about_text

    def usesTheme(self, theme):
        """
        Called to find out if the custom plugin is currently using a theme.

        Returns True if the theme is being used, otherwise returns False.
        """
        if self.manager.get_all_objects(CustomSlide, CustomSlide.theme_name == theme):
            return True
        return False

    def renameTheme(self, oldTheme, newTheme):
        """
        Renames a theme the custom plugin is using making the plugin use the
        new name.

        ``oldTheme``
            The name of the theme the plugin should stop using.

        ``newTheme``
            The new name the plugin should now use.
        """
        customsUsingTheme = self.manager.get_all_objects(CustomSlide, CustomSlide.theme_name == oldTheme)
        for custom in customsUsingTheme:
            custom.theme_name = newTheme
            self.manager.save_object(custom)

    def setPluginTextStrings(self):
        """
        Called to define all translatable texts of the plugin
        """
        ## Name PluginList ##
        self.textStrings[StringContent.Name] = {
            u'singular': translate('CustomPlugin', 'Custom Slide', 'name singular'),
            u'plural': translate('CustomPlugin', 'Custom Slides', 'name plural')
        }
        ## Name for MediaDockManager, SettingsManager ##
        self.textStrings[StringContent.VisibleName] = {
            u'title': translate('CustomPlugin', 'Custom Slides', 'container title')
        }
        # Middle Header Bar
        tooltips = {
            u'load': translate('CustomPlugin', 'Load a new custom slide.'),
            u'import': translate('CustomPlugin', 'Import a custom slide.'),
            u'new': translate('CustomPlugin', 'Add a new custom slide.'),
            u'edit': translate('CustomPlugin', 'Edit the selected custom slide.'),
            u'delete': translate('CustomPlugin', 'Delete the selected custom slide.'),
            u'preview': translate('CustomPlugin', 'Preview the selected custom slide.'),
            u'live': translate('CustomPlugin', 'Send the selected custom slide live.'),
            u'service': translate('CustomPlugin', 'Add the selected custom slide to the service.')
        }
        self.setPluginUiTextStrings(tooltips)

    def finalise(self):
        """
        Time to tidy up on exit
        """
        log.info(u'Custom Finalising')
        self.manager.finalise()
        Plugin.finalise(self)
Ejemplo n.º 32
0
 def __init__(self):
     super(CustomPlugin, self).__init__('custom', __default_settings__, CustomMediaItem, CustomTab)
     self.weight = -5
     self.manager = Manager('custom', init_schema)
     self.icon_path = ':/plugins/plugin_custom.png'
     self.icon = build_icon(self.icon_path)
Ejemplo n.º 33
0
class SongUsagePlugin(Plugin):
    log.info('SongUsage Plugin loaded')

    def __init__(self):
        super(SongUsagePlugin, self).__init__('songusage', __default_settings__)
        self.manager = Manager('songusage', init_schema, upgrade_mod=upgrade)
        self.weight = -4
        self.icon = build_icon(':/plugins/plugin_songusage.png')
        self.active_icon = build_icon(':/songusage/song_usage_active.png')
        self.inactive_icon = build_icon(':/songusage/song_usage_inactive.png')
        self.song_usage_active = False

    def check_pre_conditions(self):
        """
        Check the plugin can run.
        """
        return self.manager.session is not None

    def add_tools_menu_item(self, tools_menu):
        """
        Give the SongUsage plugin the opportunity to add items to the **Tools** menu.

        ``tools_menu``
            The actual **Tools** menu item, so that your actions can use it as their parent.
        """
        log.info('add tools menu')
        self.toolsMenu = tools_menu
        self.song_usage_menu = QtGui.QMenu(tools_menu)
        self.song_usage_menu.setObjectName('song_usage_menu')
        self.song_usage_menu.setTitle(translate('SongUsagePlugin', '&Song Usage Tracking'))
        # SongUsage Delete
        self.song_usage_delete = create_action(tools_menu, 'songUsageDelete',
            text=translate('SongUsagePlugin', '&Delete Tracking Data'),
            statustip=translate('SongUsagePlugin', 'Delete song usage data up to a specified date.'),
            triggers=self.on_song_usage_delete)
        # SongUsage Report
        self.song_usage_report = create_action(tools_menu, 'songUsageReport',
            text=translate('SongUsagePlugin', '&Extract Tracking Data'),
            statustip=translate('SongUsagePlugin', 'Generate a report on song usage.'),
            triggers=self.on_song_usage_report)
        # SongUsage activation
        self.song_usage_status = create_action(tools_menu, 'songUsageStatus',
            text=translate('SongUsagePlugin', 'Toggle Tracking'),
            statustip=translate('SongUsagePlugin', 'Toggle the tracking of song usage.'), checked=False,
            can_shortcuts=True, triggers=self.toggle_song_usage_state)
        # Add Menus together
        self.toolsMenu.addAction(self.song_usage_menu.menuAction())
        self.song_usage_menu.addAction(self.song_usage_status)
        self.song_usage_menu.addSeparator()
        self.song_usage_menu.addAction(self.song_usage_report)
        self.song_usage_menu.addAction(self.song_usage_delete)
        self.song_usage_active_button = QtGui.QToolButton(self.main_window.status_bar)
        self.song_usage_active_button.setCheckable(True)
        self.song_usage_active_button.setAutoRaise(True)
        self.song_usage_active_button.setStatusTip(translate('SongUsagePlugin', 'Toggle the tracking of song usage.'))
        self.song_usage_active_button.setObjectName('song_usage_active_button')
        self.main_window.status_bar.insertPermanentWidget(1, self.song_usage_active_button)
        self.song_usage_active_button.hide()
        # Signals and slots
        QtCore.QObject.connect(self.song_usage_status, QtCore.SIGNAL('visibilityChanged(bool)'),
            self.song_usage_status.setChecked)
        self.song_usage_active_button.toggled.connect(self.toggle_song_usage_state)
        self.song_usage_menu.menuAction().setVisible(False)

    def initialise(self):
        log.info('SongUsage Initialising')
        super(SongUsagePlugin, self).initialise()
        Registry().register_function('slidecontroller_live_started', self.display_song_usage)
        Registry().register_function('print_service_started', self.print_song_usage)
        self.song_usage_active = Settings().value(self.settings_section + '/active')
        # Set the button and checkbox state
        self.set_button_state()
        action_list = ActionList.get_instance()
        action_list.add_action(self.song_usage_status, translate('SongUsagePlugin', 'Song Usage'))
        action_list.add_action(self.song_usage_delete, translate('SongUsagePlugin', 'Song Usage'))
        action_list.add_action(self.song_usage_report, translate('SongUsagePlugin', 'Song Usage'))
        self.song_usage_delete_form = SongUsageDeleteForm(self.manager, self.main_window)
        self.song_usage_detail_form = SongUsageDetailForm(self, self.main_window)
        self.song_usage_menu.menuAction().setVisible(True)
        self.song_usage_active_button.show()

    def finalise(self):
        """
        Tidy up on exit
        """
        log.info('Plugin Finalise')
        self.manager.finalise()
        super(SongUsagePlugin, self).finalise()
        self.song_usage_menu.menuAction().setVisible(False)
        action_list = ActionList.get_instance()
        action_list.remove_action(self.song_usage_status, translate('SongUsagePlugin', 'Song Usage'))
        action_list.remove_action(self.song_usage_delete, translate('SongUsagePlugin', 'Song Usage'))
        action_list.remove_action(self.song_usage_report, translate('SongUsagePlugin', 'Song Usage'))
        self.song_usage_active_button.hide()
        # stop any events being processed
        self.song_usage_active = False

    def toggle_song_usage_state(self):
        """
        Manage the state of the audit collection and amend
        the UI when necessary,
        """
        self.song_usage_active = not self.song_usage_active
        Settings().setValue(self.settings_section + '/active', self.song_usage_active)
        self.set_button_state()

    def set_button_state(self):
        """
        Keep buttons inline.  Turn of signals to stop dead loop but we need the
        button and check box set correctly.
        """
        self.song_usage_active_button.blockSignals(True)
        self.song_usage_status.blockSignals(True)
        if self.song_usage_active:
            self.song_usage_active_button.setIcon(self.active_icon)
            self.song_usage_status.setChecked(True)
            self.song_usage_active_button.setChecked(True)
            self.song_usage_active_button.setToolTip(translate('SongUsagePlugin', 'Song usage tracking is active.'))
        else:
            self.song_usage_active_button.setIcon(self.inactive_icon)
            self.song_usage_status.setChecked(False)
            self.song_usage_active_button.setChecked(False)
            self.song_usage_active_button.setToolTip(translate('SongUsagePlugin', 'Song usage tracking is inactive.'))
        self.song_usage_active_button.blockSignals(False)
        self.song_usage_status.blockSignals(False)

    def display_song_usage(self, item):
        """
        Song Usage for which has been displayed
        """
        self._add_song_usage(translate('SongUsagePlugin', 'display'), item)

    def print_song_usage(self, item):
        """
        Song Usage for which has been printed
        """
        self._add_song_usage(translate('SongUsagePlugin', 'printed'), item)

    def _add_song_usage(self, source, item):
        audit = item[0].audit
        if self.song_usage_active and audit:
            song_usage_item = SongUsageItem()
            song_usage_item.usagedate = datetime.today()
            song_usage_item.usagetime = datetime.now().time()
            song_usage_item.title = audit[0]
            song_usage_item.copyright = audit[2]
            song_usage_item.ccl_number = audit[3]
            song_usage_item.authors = ' '.join(audit[1])
            song_usage_item.plugin_name = item[0].name
            song_usage_item.source = source
            self.manager.save_object(song_usage_item)

    def on_song_usage_delete(self):
        self.song_usage_delete_form.exec_()

    def on_song_usage_report(self):
        self.song_usage_detail_form.initialise()
        self.song_usage_detail_form.exec_()

    def about(self):
        about_text = translate('SongUsagePlugin',
            '<strong>SongUsage Plugin</strong><br />This plugin tracks the usage of songs in services.')
        return about_text

    def set_plugin_text_strings(self):
        """
        Called to define all translatable texts of the plugin
        """
        ## Name PluginList ##
        self.text_strings[StringContent.Name] = {
            'singular': translate('SongUsagePlugin', 'SongUsage', 'name singular'),
            'plural': translate('SongUsagePlugin', 'SongUsage', 'name plural')
        }
        ## Name for MediaDockManager, SettingsManager ##
        self.text_strings[StringContent.VisibleName] = {
            'title': translate('SongUsagePlugin', 'SongUsage', 'container title')
        }
Ejemplo n.º 34
0
class CustomPlugin(Plugin):
    """
    This plugin enables the user to create, edit and display custom slide shows. Custom shows are divided into slides.
    Each show is able to have it's own theme.
    Custom shows are designed to replace the use of songs where the songs plugin has become restrictive.
    Examples could be Welcome slides, Bible Reading information, Orders of service.
    """
    log.info('Custom Plugin loaded')

    def __init__(self):
        super(CustomPlugin, self).__init__('custom', CustomMediaItem,
                                           CustomTab)
        self.weight = -5
        self.db_manager = Manager('custom', init_schema)
        self.icon_path = UiIcons().clone
        self.icon = build_icon(self.icon_path)
        register_endpoint(custom_endpoint)
        register_endpoint(api_custom_endpoint)
        State().add_service(self.name, self.weight, is_plugin=True)
        State().update_pre_conditions(self.name, self.check_pre_conditions())

    @staticmethod
    def about():
        about_text = translate(
            'CustomPlugin',
            '<strong>Custom Slide Plugin </strong><br />The custom slide plugin '
            'provides the ability to set up custom text slides that can be displayed on the screen '
            'the same way songs are. This plugin provides greater freedom over the songs plugin.'
        )
        return about_text

    def uses_theme(self, theme):
        """
        Called to find out if the custom plugin is currently using a theme.

        Returns count of the times the theme is used.
        :param theme: Theme to be queried
        """
        return len(
            self.db_manager.get_all_objects(CustomSlide,
                                            CustomSlide.theme_name == theme))

    def rename_theme(self, old_theme, new_theme):
        """
        Renames a theme the custom plugin is using making the plugin use the new name.

        :param old_theme: The name of the theme the plugin should stop using.
        :param new_theme: The new name the plugin should now use.
        """
        customs_using_theme = self.db_manager.get_all_objects(
            CustomSlide, CustomSlide.theme_name == old_theme)
        for custom in customs_using_theme:
            custom.theme_name = new_theme
            self.db_manager.save_object(custom)

    def set_plugin_text_strings(self):
        """
        Called to define all translatable texts of the plugin
        """
        # Name PluginList
        self.text_strings[StringContent.Name] = {
            'singular': translate('CustomPlugin', 'Custom Slide',
                                  'name singular'),
            'plural': translate('CustomPlugin', 'Custom Slides', 'name plural')
        }
        # Name for MediaDockManager, SettingsManager
        self.text_strings[StringContent.VisibleName] = {
            'title': translate('CustomPlugin', 'Custom Slides',
                               'container title')
        }
        # Middle Header Bar
        tooltips = {
            'load':
            translate('CustomPlugin', 'Load a new custom slide.'),
            'import':
            translate('CustomPlugin', 'Import a custom slide.'),
            'new':
            translate('CustomPlugin', 'Add a new custom slide.'),
            'edit':
            translate('CustomPlugin', 'Edit the selected custom slide.'),
            'delete':
            translate('CustomPlugin', 'Delete the selected custom slide.'),
            'preview':
            translate('CustomPlugin', 'Preview the selected custom slide.'),
            'live':
            translate('CustomPlugin', 'Send the selected custom slide live.'),
            'service':
            translate('CustomPlugin',
                      'Add the selected custom slide to the service.')
        }
        self.set_plugin_ui_text_strings(tooltips)

    def finalise(self):
        """
        Time to tidy up on exit
        """
        log.info('Custom Finalising')
        # call custom manager to delete pco slides
        pco_slides = self.db_manager.get_all_objects(
            CustomSlide, CustomSlide.credits == 'pco')
        for slide in pco_slides:
            self.db_manager.delete_object(CustomSlide, slide.id)
        self.db_manager.finalise()
        Plugin.finalise(self)