Ejemplo n.º 1
0
 def is_data_path_missing():
     """
     Check if the data folder path exists.
     """
     data_folder_path = AppLocation.get_data_path()
     if not data_folder_path.exists():
         log.critical('Database was not found in: %s', data_folder_path)
         status = QtWidgets.QMessageBox.critical(
             None, translate('OpenLP', 'Data Directory Error'),
             translate(
                 'OpenLP',
                 'OpenLP data folder was not found in:\n\n{path}\n\nThe location of the data folder '
                 'was previously changed from the OpenLP\'s default location. If the data was '
                 'stored on removable device, that device needs to be made available.\n\nYou may '
                 'reset the data location back to the default location, or you can try to make the '
                 'current location available.\n\nDo you want to reset to the default data location? '
                 'If not, OpenLP will be closed so you can try to fix the the problem.'
             ).format(path=data_folder_path),
             QtWidgets.QMessageBox.StandardButtons(
                 QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No),
             QtWidgets.QMessageBox.No)
         if status == QtWidgets.QMessageBox.No:
             # If answer was "No", return "True", it will shutdown OpenLP in def main
             log.info('User requested termination')
             return True
         # If answer was "Yes", remove the custom data path thus resetting the default location.
         Settings().remove('advanced/data path')
         log.info(
             'Database location has been reset to the default settings.')
         return False
Ejemplo n.º 2
0
    def on_data_directory_path_edit_path_changed(self, new_path):
        """
        Handle the `editPathChanged` signal of the data_directory_path_edit

        :param pathlib.Path new_path: The new path
        :rtype: None
        """
        # Make sure they want to change the data.
        answer = QtWidgets.QMessageBox.question(
            self,
            translate('OpenLP.AdvancedTab', 'Confirm Data Directory Change'),
            translate(
                'OpenLP.AdvancedTab', 'Are you sure you want to change the '
                'location of the OpenLP data directory to:\n\n{path}'
                '\n\nThe data directory will be changed when OpenLP is '
                'closed.').format(path=new_path),
            defaultButton=QtWidgets.QMessageBox.No)
        if answer != QtWidgets.QMessageBox.Yes:
            self.data_directory_path_edit.path = AppLocation.get_data_path()
            return
        # Check if data already exists here.
        self.check_data_overwrite(new_path)
        # Save the new location.
        self.main_window.new_data_path = new_path
        self.data_directory_cancel_button.show()
Ejemplo n.º 3
0
def upgrade_2(session, metadata):
    """
    Version 2 upgrade - Move file path from old db to JSON encoded path to new db. Added during 2.5 dev
    """
    log.debug('Starting upgrade_2 for file_path to JSON')
    old_table = Table('image_filenames', metadata, autoload=True)
    if 'file_path' not in [col.name for col in old_table.c.values()]:
        op = get_upgrade_op(session)
        op.add_column('image_filenames', Column('file_path', PathType()))
        conn = op.get_bind()
        results = conn.execute('SELECT * FROM image_filenames')
        data_path = AppLocation.get_data_path()
        for row in results.fetchall():
            file_path_json = json.dumps(Path(row.filename),
                                        cls=OpenLPJsonEncoder,
                                        base_path=data_path)
            sql = 'UPDATE image_filenames SET file_path = \'{file_path_json}\' WHERE id = {id}'.format(
                file_path_json=file_path_json, id=row.id)
            conn.execute(sql)
        # Drop old columns
        if metadata.bind.url.get_dialect().name == 'sqlite':
            drop_columns(op, 'image_filenames', [
                'filename',
            ])
        else:
            op.drop_constraint('image_filenames', 'foreignkey')
            op.drop_column('image_filenames', 'filenames')
Ejemplo n.º 4
0
 def update_preview_text(self):
     """
     Creates the html text and updates the html of *self.document*.
     """
     html_data = self._add_element('html')
     self._add_element('head', parent=html_data)
     self._add_element('title', self.title_line_edit.text(), html_data.head)
     css_path = AppLocation.get_data_path() / 'serviceprint' / 'service_print.css'
     custom_css = get_text_file_string(css_path)
     if not custom_css:
         custom_css = DEFAULT_CSS
     self._add_element('style', custom_css, html_data.head, attribute=('type', 'text/css'))
     self._add_element('body', parent=html_data)
     self._add_element('h1', html.escape(self.title_line_edit.text()), html_data.body, class_id='serviceTitle')
     for index, item in enumerate(self.service_manager.service_items):
         self._add_preview_item(html_data.body, item['service_item'], index)
     if not self.show_chords_check_box.isChecked():
         # Remove chord row and spacing span elements when not printing chords
         for chord_row in html_data.find_class('chordrow'):
             chord_row.drop_tree()
         for spacing_span in html_data.find_class('chordspacing'):
             spacing_span.drop_tree()
     # Add the custom service notes:
     if self.footer_text_edit.toPlainText():
         div = self._add_element('div', parent=html_data.body, class_id='customNotes')
         self._add_element(
             'span', translate('OpenLP.ServiceManager', 'Service Notes: '), div, class_id='customNotesTitle')
         self._add_element('span', html.escape(self.footer_text_edit.toPlainText()), div, class_id='customNotesText')
     self.document.setHtml(lxml.html.tostring(html_data).decode())
     self.preview_widget.updatePreview()
Ejemplo n.º 5
0
    def process_bind_param(self, value, dialect):
        """
        Convert the Path object to a JSON representation

        :param pathlib.Path value: The value to convert
        :param dialect: Not used
        :return str: The Path object as a JSON string
        """
        data_path = AppLocation.get_data_path()
        return json.dumps(value, cls=OpenLPJSONEncoder, base_path=data_path)
Ejemplo n.º 6
0
 def on_data_directory_cancel_button_clicked(self):
     """
     Cancel the data directory location change
     """
     self.data_directory_path_edit.path = AppLocation.get_data_path()
     self.data_directory_copy_check_box.setChecked(False)
     self.main_window.new_data_path = None
     self.main_window.set_copy_data(False)
     self.data_directory_copy_check_box.hide()
     self.data_directory_cancel_button.hide()
     self.new_data_directory_has_files_label.hide()
Ejemplo n.º 7
0
    def process_result_value(self, value, dialect):
        """
        Convert the JSON representation back

        :param types.UnicodeText value: The value to convert
        :param dialect: Not used
        :return: The JSON object converted Python object (in this case it should be a Path object)
        :rtype: pathlib.Path
        """
        data_path = AppLocation.get_data_path()
        return json.loads(value, cls=OpenLPJSONDecoder, base_path=data_path)
Ejemplo n.º 8
0
    def process_bind_param(self, value, dialect):
        """
        Convert the Path object to a JSON representation

        :param openlp.core.common.path.Path value: The value to convert
        :param dialect: Not used
        :return: The Path object as a JSON string
        :rtype: str
        """
        data_path = AppLocation.get_data_path()
        return json.dumps(value, cls=OpenLPJsonEncoder, base_path=data_path)
Ejemplo n.º 9
0
    def backup_on_upgrade(self, has_run_wizard, can_show_splash):
        """
        Check if OpenLP has been upgraded, and ask if a backup of data should be made

        :param has_run_wizard: OpenLP has been run before
        :param can_show_splash: Should OpenLP show the splash screen
        """
        data_version = Settings().value('core/application version')
        openlp_version = get_version()['version']
        # New installation, no need to create backup
        if not has_run_wizard:
            Settings().setValue('core/application version', openlp_version)
        # If data_version is different from the current version ask if we should backup the data folder
        elif data_version != openlp_version:
            if can_show_splash and self.splash.isVisible():
                self.splash.hide()
            if QtWidgets.QMessageBox.question(
                    None,
                    translate('OpenLP', 'Backup'),
                    translate(
                        'OpenLP',
                        'OpenLP has been upgraded, do you want to create\n'
                        'a backup of the old data folder?'),
                    defaultButton=QtWidgets.QMessageBox.Yes
            ) == QtWidgets.QMessageBox.Yes:
                # Create copy of data folder
                data_folder_path = AppLocation.get_data_path()
                timestamp = time.strftime("%Y%m%d-%H%M%S")
                data_folder_backup_path = data_folder_path.with_name(
                    data_folder_path.name + '-' + timestamp)
                try:
                    copytree(data_folder_path, data_folder_backup_path)
                except OSError:
                    QtWidgets.QMessageBox.warning(
                        None, translate('OpenLP', 'Backup'),
                        translate('OpenLP',
                                  'Backup of the data folder failed!'))
                    return
                message = translate(
                    'OpenLP',
                    'A backup of the data folder has been created at:\n\n'
                    '{text}').format(text=data_folder_backup_path)
                QtWidgets.QMessageBox.information(
                    None, translate('OpenLP', 'Backup'), message)

            # Update the version in the settings
            Settings().setValue('core/application version', openlp_version)
            if can_show_splash:
                self.splash.show()
Ejemplo n.º 10
0
def test_get_data_path_with_custom_location(MockSettings):
    """
    Test the AppLocation.get_data_path() method when a custom location is set in the settings
    """
    # GIVEN: A mocked out Settings class which returns a custom data location
    MockSettings.return_value.contains.return_value = True
    MockSettings.return_value.value.return_value = Path('custom', 'dir')

    # WHEN: we call AppLocation.get_data_path()
    data_path = AppLocation.get_data_path()

    # THEN: the mocked Settings methods were called and the value returned was our set up value
    MockSettings.return_value.contains.assert_called_with('advanced/data path')
    MockSettings.return_value.value.assert_called_with('advanced/data path')
    assert data_path == Path('custom', 'dir'), 'Result should be "custom/dir"'
Ejemplo n.º 11
0
def test_get_data_path(mocked_os, mocked_create_paths, mocked_get_directory, MockSettings):
    """
    Test the AppLocation.get_data_path() method
    """
    # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory()
    MockSettings.return_value.contains.return_value = False
    mocked_get_directory.return_value = Path('tests', 'dir')
    mocked_create_paths.return_value = True
    mocked_os.path.normpath.return_value = Path('tests', 'dir')

    # WHEN: we call AppLocation.get_data_path()
    data_path = AppLocation.get_data_path()

    # THEN: check that all the correct methods were called, and the result is correct
    MockSettings.return_value.contains.assert_called_with('advanced/data path')
    mocked_get_directory.assert_called_with(AppLocation.DataDir)
    mocked_create_paths.assert_called_with(Path('tests', 'dir'))
    assert data_path == Path('tests', 'dir'), 'Result should be "tests/dir"'
Ejemplo n.º 12
0
def main(args=None):
    """
    The main function which parses command line options and then runs

    :param args: Some args
    """
    args = parse_options(args)
    qt_args = []
    if args and args.loglevel.lower() in ['d', 'debug']:
        log.setLevel(logging.DEBUG)
    elif args and args.loglevel.lower() in ['w', 'warning']:
        log.setLevel(logging.WARNING)
    else:
        log.setLevel(logging.INFO)
    # Throw the rest of the arguments at Qt, just in case.
    qt_args.extend(args.rargs)
    # Bug #1018855: Set the WM_CLASS property in X11
    if not is_win() and not is_macosx():
        qt_args.append('OpenLP')
    # Initialise the resources
    qInitResources()
    # Now create and actually run the application.
    application = OpenLP(qt_args)
    application.setOrganizationName('OpenLP')
    application.setOrganizationDomain('openlp.org')
    application.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
    application.setAttribute(QtCore.Qt.AA_DontCreateNativeWidgetSiblings, True)
    if args.portable:
        application.setApplicationName('OpenLPPortable')
        Settings.setDefaultFormat(Settings.IniFormat)
        # Get location OpenLPPortable.ini
        portable_path = (AppLocation.get_directory(AppLocation.AppDir) / '..' /
                         '..').resolve()
        data_path = portable_path / 'Data'
        set_up_logging(portable_path / 'Other')
        log.info('Running portable')
        portable_settings_path = data_path / 'OpenLP.ini'
        # Make this our settings file
        log.info('INI file: {name}'.format(name=portable_settings_path))
        Settings.set_filename(str(portable_settings_path))
        portable_settings = Settings()
        # Set our data path
        log.info('Data path: {name}'.format(name=data_path))
        # Point to our data path
        portable_settings.setValue('advanced/data path', data_path)
        portable_settings.setValue('advanced/is portable', True)
        portable_settings.sync()
    else:
        application.setApplicationName('OpenLP')
        set_up_logging(AppLocation.get_directory(AppLocation.CacheDir))
    Registry.create()
    Registry().register('application', application)
    Registry().set_flag('no_web_server', args.no_web_server)
    application.setApplicationVersion(get_version()['version'])
    # Check if an instance of OpenLP is already running. Quit if there is a running instance and the user only wants one
    server = Server()
    if server.is_another_instance_running():
        application.is_already_running()
        server.post_to_server(qt_args)
        sys.exit()
    else:
        server.start_server()
        application.server = server
    # If the custom data path is missing and the user wants to restore the data path, quit OpenLP.
    if application.is_data_path_missing():
        server.close_server()
        sys.exit()
    # Upgrade settings.
    settings = Settings()
    if settings.can_upgrade():
        now = datetime.now()
        # Only back up if OpenLP has previously run.
        if settings.value('core/has run wizard'):
            back_up_path = AppLocation.get_data_path() / (
                now.strftime('%Y-%m-%d %H-%M') + '.conf')
            log.info(
                'Settings about to be upgraded. Existing settings are being backed up to {back_up_path}'
                .format(back_up_path=back_up_path))
            QtWidgets.QMessageBox.information(
                None, translate('OpenLP', 'Settings Upgrade'),
                translate(
                    'OpenLP',
                    'Your settings are about to be upgraded. A backup will be created at '
                    '{back_up_path}').format(back_up_path=back_up_path))
            settings.export(back_up_path)
        settings.upgrade_settings()
    # First time checks in settings
    if not Settings().value('core/has run wizard'):
        if not FirstTimeLanguageForm().exec():
            # if cancel then stop processing
            server.close_server()
            sys.exit()
    # i18n Set Language
    language = LanguageManager.get_language()
    translators = LanguageManager.get_translators(language)
    for translator in translators:
        if not translator.isEmpty():
            application.installTranslator(translator)
    if not translators:
        log.debug('Could not find translators.')
    if args and not args.no_error_form:
        sys.excepthook = application.hook_exception
    sys.exit(application.run(qt_args))
Ejemplo n.º 13
0
 def load(self):
     """
     Load settings from disk.
     """
     settings = Settings()
     settings.beginGroup(self.settings_section)
     # The max recent files value does not have an interface and so never
     # gets actually stored in the settings therefore the default value of
     # 20 will always be used.
     self.recent_spin_box.setMaximum(settings.value('max recent files'))
     self.recent_spin_box.setValue(settings.value('recent file count'))
     self.media_plugin_check_box.setChecked(
         settings.value('save current plugin'))
     self.double_click_live_check_box.setChecked(
         settings.value('double click live'))
     self.single_click_preview_check_box.setChecked(
         settings.value('single click preview'))
     self.single_click_service_preview_check_box.setChecked(
         settings.value('single click service preview'))
     self.expand_service_item_check_box.setChecked(
         settings.value('expand service item'))
     slide_max_height_value = settings.value('slide max height')
     for i in range(0, self.slide_max_height_combo_box.count()):
         if self.slide_max_height_combo_box.itemData(
                 i) == slide_max_height_value:
             self.slide_max_height_combo_box.setCurrentIndex(i)
     autoscroll_value = settings.value('autoscrolling')
     for i in range(0, len(self.autoscroll_map)):
         if self.autoscroll_map[
                 i] == autoscroll_value and i < self.autoscroll_combo_box.count(
                 ):
             self.autoscroll_combo_box.setCurrentIndex(i)
     self.enable_auto_close_check_box.setChecked(
         settings.value('enable exit confirmation'))
     self.experimental_check_box.setChecked(settings.value('experimental'))
     if HAS_DARK_STYLE:
         self.use_dark_style_checkbox.setChecked(
             settings.value('use_dark_style'))
     self.hide_mouse_check_box.setChecked(settings.value('hide mouse'))
     self.service_name_day.setCurrentIndex(
         settings.value('default service day'))
     self.service_name_time.setTime(
         QtCore.QTime(settings.value('default service hour'),
                      settings.value('default service minute')))
     self.should_update_service_name_example = True
     self.service_name_edit.setText(settings.value('default service name'))
     default_service_enabled = settings.value('default service enabled')
     self.service_name_check_box.setChecked(default_service_enabled)
     self.service_name_check_box_toggled(default_service_enabled)
     self.ignore_aspect_ratio_check_box.setChecked(
         settings.value('ignore aspect ratio'))
     self.x11_bypass_check_box.setChecked(settings.value('x11 bypass wm'))
     self.slide_limits = settings.value('slide limits')
     self.is_search_as_you_type_enabled = settings.value('search as type')
     self.search_as_type_check_box.setChecked(
         self.is_search_as_you_type_enabled)
     # Prevent the dialog displayed by the alternate_rows_check_box to display.
     self.alternate_rows_check_box.blockSignals(True)
     self.alternate_rows_check_box.setChecked(
         settings.value('alternate rows'))
     self.alternate_rows_check_box.blockSignals(False)
     if self.slide_limits == SlideLimits.End:
         self.end_slide_radio_button.setChecked(True)
     elif self.slide_limits == SlideLimits.Wrap:
         self.wrap_slide_radio_button.setChecked(True)
     else:
         self.next_item_radio_button.setChecked(True)
     settings.endGroup()
     self.data_directory_copy_check_box.hide()
     self.new_data_directory_has_files_label.hide()
     self.data_directory_cancel_button.hide()
     # Since data location can be changed, make sure the path is present.
     self.data_directory_path_edit.path = AppLocation.get_data_path()
     # Don't allow data directory move if running portable.
     if settings.value('advanced/is portable'):
         self.data_directory_group_box.hide()
Ejemplo n.º 14
0
def controller_text(request):
    """
    Perform an action on the slide controller.

    :param request: the http request - not used
    """
    log.debug("controller_text ")
    live_controller = Registry().get('live_controller')
    current_item = live_controller.service_item
    data = []
    if current_item:
        for index, frame in enumerate(current_item.get_frames()):
            item = {}
            # Handle text (songs, custom, bibles)
            if current_item.is_text():
                if frame['verseTag']:
                    item['tag'] = str(frame['verseTag'])
                else:
                    item['tag'] = str(index + 1)
                item['chords_text'] = str(frame['chords_text'])
                item['text'] = str(frame['text'])
                item['html'] = str(frame['html'])
            # Handle images, unless a custom thumbnail is given or if thumbnails is disabled
            elif current_item.is_image() and not frame.get(
                    'image', '') and Settings().value('api/thumbnails'):
                item['tag'] = str(index + 1)
                thumbnail_path = os.path.join('images', 'thumbnails',
                                              frame['title'])
                full_thumbnail_path = AppLocation.get_data_path(
                ) / thumbnail_path
                # Create thumbnail if it doesn't exists
                if not full_thumbnail_path.exists():
                    create_thumb(Path(current_item.get_frame_path(index)),
                                 full_thumbnail_path, False)
                Registry().get('image_manager').add_image(
                    str(full_thumbnail_path), frame['title'], None, 88, 88)
                item['img'] = urllib.request.pathname2url(os.path.sep +
                                                          str(thumbnail_path))
                item['text'] = str(frame['title'])
                item['html'] = str(frame['title'])
            else:
                # Handle presentation etc.
                item['tag'] = str(index + 1)
                if current_item.is_capable(ItemCapabilities.HasDisplayTitle):
                    item['title'] = str(frame['display_title'])
                if current_item.is_capable(ItemCapabilities.HasNotes):
                    item['slide_notes'] = str(frame['notes'])
                if current_item.is_capable(
                        ItemCapabilities.HasThumbnails) and Settings().value(
                            'api/thumbnails'):
                    # If the file is under our app directory tree send the portion after the match
                    data_path = str(AppLocation.get_data_path())
                    if frame['image'][0:len(data_path)] == data_path:
                        item['img'] = urllib.request.pathname2url(
                            frame['image'][len(data_path):])
                    Registry().get('image_manager').add_image(
                        frame['image'], frame['title'], None, 88, 88)
                item['text'] = str(frame['title'])
                item['html'] = str(frame['title'])
            item['selected'] = (live_controller.selected_row == index)
            item['title'] = current_item.title
            data.append(item)
    json_data = {'results': {'slides': data}}
    if current_item:
        json_data['results'][
            'item'] = live_controller.service_item.unique_identifier
    return json_data