diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 9da185ddf..31db4a6bd 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -173,6 +173,7 @@ class OpenLP(QtGui.QApplication): return False def hookException(self, exctype, value, traceback): + print ''.join(format_exception(exctype, value, traceback)) if not hasattr(self, u'mainWindow'): log.exception(''.join(format_exception(exctype, value, traceback))) return diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 9402f8cda..b16d0e09d 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -328,7 +328,7 @@ class MediaManagerItem(QtGui.QWidget): Add a file to the list widget to make it available for showing """ files = QtGui.QFileDialog.getOpenFileNames(self, self.onNewPrompt, - SettingsManager.get_last_dir(self.settingsSection), self.onNewFileMasks) + Settings.value(u'last directory'), self.onNewFileMasks) log.info(u'New files(s) %s', files) if files: Receiver.send_message(u'cursor_busy') @@ -382,7 +382,7 @@ class MediaManagerItem(QtGui.QWidget): self.listView.clear() self.loadList(full_list) last_dir = os.path.split(unicode(files[0]))[0] - SettingsManager.set_last_dir(self.settingsSection, last_dir) + Settings(self.settingsSection).setValue(u'last directory', last_dir) SettingsManager.set_list(self.settingsSection, self.settingsSection, self.getFileList()) if duplicates_found: diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 5c72d13c5..fd0117e45 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -176,6 +176,7 @@ class Plugin(QtCore.QObject): self.mediaController = plugin_helpers[u'mediacontroller'] # Add the default status to the default settings. default_settings[name + u'/status'] = PluginStatus.Inactive + default_settings[name + u'/last directory'] = u'' # Add settings to the dict of all settings. Settings.extend_default_settings(default_settings) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_add_service_item' % self.name), diff --git a/openlp/core/lib/settings.py b/openlp/core/lib/settings.py index 9951fd143..f753d38f4 100644 --- a/openlp/core/lib/settings.py +++ b/openlp/core/lib/settings.py @@ -103,7 +103,7 @@ class Settings(QtCore.QSettings): u'advanced/default image': u':/graphics/openlp-splash-screen.png', u'advanced/expand service item': False, u'advanced/recent file count': 4, - u'advanced/default service name': UiStrings().DefaultServiceName, + u'advanced/default service name': u'',#UiStrings().DefaultServiceName, u'advanced/default service minute': 0, u'advanced/slide limits': SlideLimits.End, u'advanced/print slide text': False, @@ -111,6 +111,7 @@ class Settings(QtCore.QSettings): u'advanced/print file meta data': False, u'advanced/print notes': False, u'advanced/display size': 0, + u'crashreport/last directory': u'', u'displayTags/html_tags': u'', u'general/ccli number': u'', u'general/has run wizard': False, @@ -143,6 +144,7 @@ class Settings(QtCore.QSettings): u'general/blank warning': False, u'players/background color': u'#000000', u'servicemanager/service theme': u'', + u'servicemanager/last directory': u'', u'shortcuts/viewPreviewPanel': [QtGui.QKeySequence(u'F11')], u'shortcuts/settingsImportItem': [], u'shortcuts/settingsPluginListItem': [QtGui.QKeySequence(u'Alt+F7')], @@ -211,6 +213,8 @@ class Settings(QtCore.QSettings): u'themes/theme level': ThemeLevel.Song, u'themes/global theme': u'', u'themes/last directory': u'', + u'themes/last directory export': u'', + u'themes/last directory import': u'', u'user interface/main window position': QtCore.QPoint(0, 0), u'user interface/preview panel': True, u'user interface/live panel': True, @@ -227,6 +231,11 @@ class Settings(QtCore.QSettings): __obsolete_settings__ = [ (u'bibles/bookname language', u'bibles/book name language', []), (u'general/enable slide loop', u'advanced/slide limits', [(SlideLimits.Wrap, True), (SlideLimits.End, False)]) +# song usage/last directory 1 -> last directory import +# bibles/last directory 1 -> bibles/last directory backup +# themes/last directory -> themes/last directory import +# themes/last directory 1-> themes/last directory export +# songs/last directory 1 -> songs/last directory error log ] @staticmethod @@ -297,7 +306,7 @@ class Settings(QtCore.QSettings): ``default_value`` **Note**, do **not** use this. It is *only* for dynamic keys such as ``something %d``. """ - # FIXME: rework default_value + # FIXME: remove default_value if default_value is None: # if group() is not empty the group has not been specified together with the key. if self.group(): diff --git a/openlp/core/lib/settingsmanager.py b/openlp/core/lib/settingsmanager.py index 820365054..2ce4e504c 100644 --- a/openlp/core/lib/settingsmanager.py +++ b/openlp/core/lib/settingsmanager.py @@ -44,43 +44,6 @@ class SettingsManager(object): Class to provide helper functions for the loading and saving of application settings. """ - @staticmethod - def get_last_dir(section, num=None): - """ - Read the last directory used for plugin. - - ``section`` - The section of code calling the method. This is used in the settings key. - - ``num`` - Defaults to *None*. A further qualifier. - """ - if num: - name = u'last directory %d' % num - else: - name = u'last directory' - return Settings().value(section + u'/' + name, u'') - - @staticmethod - def set_last_dir(section, directory, num=None): - """ - Save the last directory used for plugin. - - ``section`` - The section of code calling the method. This is used in the settings key. - - ``directory`` - The directory being stored in the settings. - - ``num`` - Defaults to *None*. A further qualifier. - """ - if num: - name = u'last directory %d' % num - else: - name = u'last directory' - Settings().setValue(section + u'/' + name, directory) - @staticmethod def set_list(section, name, list_to_save): """ diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index 8e10d92cb..3be6fbeb9 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -506,9 +506,9 @@ class AdvancedTab(SettingsTab): """ old_root_path = unicode(self.dataDirectoryLabel.text()) # Get the new directory location. - new_data_path = unicode(QtGui.QFileDialog.getExistingDirectory(self, + new_data_path = QtGui.QFileDialog.getExistingDirectory(self, translate('OpenLP.AdvancedTab', 'Select Data Directory Location'), old_root_path, - options = QtGui.QFileDialog.ShowDirsOnly)) + options = QtGui.QFileDialog.ShowDirsOnly) # Set the new data path. if new_data_path: new_data_path = os.path.normpath(new_data_path) diff --git a/openlp/core/ui/exceptionform.py b/openlp/core/ui/exceptionform.py index 23ecd258e..213a66388 100644 --- a/openlp/core/ui/exceptionform.py +++ b/openlp/core/ui/exceptionform.py @@ -85,7 +85,7 @@ except AttributeError: WEBKIT_VERSION = u'-' -from openlp.core.lib import translate, SettingsManager, UiStrings +from openlp.core.lib import translate, UiStrings, Settings from openlp.core.utils import get_application_version from exceptiondialog import Ui_ExceptionDialog @@ -146,12 +146,12 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog): '--- Library Versions ---\n%s\n') filename = QtGui.QFileDialog.getSaveFileName(self, translate('OpenLP.ExceptionForm', 'Save Crash Report'), - SettingsManager.get_last_dir(self.settingsSection), + Settings().value(self.settingsSection + u'/last directory'), translate('OpenLP.ExceptionForm', 'Text files (*.txt *.log *.text)')) if filename: filename = unicode(filename).replace(u'/', os.path.sep) - SettingsManager.set_last_dir(self.settingsSection, os.path.dirname(filename)) + Settings().setValue(self.settingsSection + u'/last directory', os.path.dirname(filename)) report_text = report_text % self._createReport() try: report_file = open(filename, u'w') @@ -211,7 +211,7 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog): def onAttachFileButtonClicked(self): files = QtGui.QFileDialog.getOpenFileName( self, translate('ImagePlugin.ExceptionDialog', 'Select Attachment'), - SettingsManager.get_last_dir(u'exceptions'), u'%s (*.*) (*)' % UiStrings().AllFiles) + Settings().value(self.settingsSection + u'/last directory'), u'%s (*.*) (*)' % UiStrings().AllFiles) log.info(u'New files(s) %s', unicode(files)) if files: self.fileAttachment = unicode(files) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 5f0bb86b0..343653e47 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -39,7 +39,7 @@ log = logging.getLogger(__name__) from PyQt4 import QtCore, QtGui -from openlp.core.lib import OpenLPToolbar, ServiceItem, Receiver, build_icon, ItemCapabilities, SettingsManager, \ +from openlp.core.lib import OpenLPToolbar, ServiceItem, Receiver, build_icon, ItemCapabilities, \ translate, str_to_bool, check_directory_exists, Settings, PluginStatus, UiStrings from openlp.core.lib.theme import ThemeLevel from openlp.core.lib.ui import critical_error_message_box, create_widget_action, find_and_set_in_combo_box @@ -369,13 +369,13 @@ class ServiceManager(QtGui.QWidget): if not loadFile: fileName = QtGui.QFileDialog.getOpenFileName(self.mainwindow, translate('OpenLP.ServiceManager', 'Open File'), - SettingsManager.get_last_dir(self.mainwindow.serviceManagerSettingsSection), + Settings().value(self.mainwindow.serviceManagerSettingsSection + u'/last directory'), translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz *.oszl)')) if not fileName: return False else: fileName = loadFile - SettingsManager.set_last_dir(self.mainwindow.serviceManagerSettingsSection, split_filename(fileName)[0]) + Settings().setValue(self.mainwindow.serviceManagerSettingsSection + u'/last directory', split_filename(fileName)[0]) self.loadFile(fileName) def saveModifiedService(self): @@ -421,7 +421,7 @@ class ServiceManager(QtGui.QWidget): basename = os.path.splitext(file_name)[0] service_file_name = '%s.osd' % basename log.debug(u'ServiceManager.saveFile - %s', path_file_name) - SettingsManager.set_last_dir(self.mainwindow.serviceManagerSettingsSection, path) + Settings().setValue(self.mainwindow.serviceManagerSettingsSection + u'/last directory', path) service = [] write_list = [] missing_list = [] @@ -547,7 +547,7 @@ class ServiceManager(QtGui.QWidget): basename = os.path.splitext(file_name)[0] service_file_name = '%s.osd' % basename log.debug(u'ServiceManager.saveFile - %s', path_file_name) - SettingsManager.set_last_dir(self.mainwindow.serviceManagerSettingsSection, path) + Settings().setValue(self.mainwindow.serviceManagerSettingsSection + u'/last directory', path) service = [] Receiver.send_message(u'cursor_busy') # Number of items + 1 to zip it @@ -612,7 +612,7 @@ class ServiceManager(QtGui.QWidget): default_filename = format_time(default_pattern, local_time) else: default_filename = u'' - directory = SettingsManager.get_last_dir(self.mainwindow.serviceManagerSettingsSection) + directory = Settings().value(self.mainwindow.serviceManagerSettingsSection + u'/last directory') path = os.path.join(directory, default_filename) # SaveAs from osz to oszl is not valid as the files will be deleted # on exit which is not sensible or usable in the long term. diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index b6480633c..29d4ddfa0 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -360,12 +360,12 @@ class ThemeManager(QtGui.QWidget): theme = item.data(QtCore.Qt.UserRole) path = QtGui.QFileDialog.getExistingDirectory(self, translate('OpenLP.ThemeManager', 'Save Theme - (%s)') % theme, - SettingsManager.get_last_dir(self.settingsSection, 1)) - path = unicode(path) + Settings().value(self.settingsSection + u'/last directory export')) Receiver.send_message(u'cursor_busy') if path: - SettingsManager.set_last_dir(self.settingsSection, path, 1) + Settings().setValue(self.settingsSection + u'/last directory export', path) theme_path = os.path.join(path, theme + u'.otz') + # FIXME: Do not overwrite build-in. zip = None try: zip = zipfile.ZipFile(theme_path, u'w') @@ -396,14 +396,14 @@ class ThemeManager(QtGui.QWidget): """ files = QtGui.QFileDialog.getOpenFileNames(self, translate('OpenLP.ThemeManager', 'Select Theme Import File'), - SettingsManager.get_last_dir(self.settingsSection), + Settings().value(self.settingsSection + u'/last directory import'), translate('OpenLP.ThemeManager', 'OpenLP Themes (*.theme *.otz)')) log.info(u'New Themes %s', unicode(files)) if not files: return Receiver.send_message(u'cursor_busy') for file in files: - SettingsManager.set_last_dir(self.settingsSection, unicode(file)) + Settings().setValue(self.settingsSection + u'/last directory import', unicode(file)) self.unzipTheme(file, self.path) self.loadThemes() Receiver.send_message(u'cursor_normal') diff --git a/openlp/core/ui/wizard.py b/openlp/core/ui/wizard.py index f4da5a987..fd3d3cb0b 100644 --- a/openlp/core/ui/wizard.py +++ b/openlp/core/ui/wizard.py @@ -254,13 +254,11 @@ class OpenLPWizard(QtGui.QWizard): if filters: filters += u';;' filters += u'%s (*)' % UiStrings().AllFiles - filename = unicode(QtGui.QFileDialog.getOpenFileName(self, title, - os.path.dirname(SettingsManager.get_last_dir( - self.plugin.settingsSection, 1)), filters)) + filename = QtGui.QFileDialog.getOpenFileName(self, title, + os.path.dirname(Settings().value(self.plugin.settingsSection + u'/last directory 1')), filters) if filename: editbox.setText(filename) - SettingsManager.set_last_dir(self.plugin.settingsSection, - filename, 1) + Settings().setValue(self.plugin.settingsSection + u'/last directory 1', filename) def getFolder(self, title, editbox): """ @@ -272,9 +270,9 @@ class OpenLPWizard(QtGui.QWizard): ``editbox`` An editbox (QLineEdit). """ - folder = unicode(QtGui.QFileDialog.getExistingDirectory(self, title, - os.path.dirname(SettingsManager.get_last_dir(self.plugin.settingsSection, 1)), - QtGui.QFileDialog.ShowDirsOnly)) + folder = QtGui.QFileDialog.getExistingDirectory(self, title, + os.path.dirname(Settings().value(self.plugin.settingsSection + u'/last directory 1')), + QtGui.QFileDialog.ShowDirsOnly) if folder: editbox.setText(folder) - SettingsManager.set_last_dir(self.plugin.settingsSection, folder, 1) + Settings().setValue(self.plugin.settingsSection + u'/last directory 1', folder) diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index cf8787767..20bd3e400 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -60,7 +60,8 @@ __default_settings__ = { u'bibles/verse separator': u'', u'bibles/range separator': u'', u'bibles/list separator': u'', - u'bibles/end separator': u'' + u'bibles/end separator': u'', + u'bibles/last directory backup': u'' } diff --git a/openlp/plugins/bibles/forms/bibleupgradeform.py b/openlp/plugins/bibles/forms/bibleupgradeform.py index 8c2b4f5d4..c68835e70 100644 --- a/openlp/plugins/bibles/forms/bibleupgradeform.py +++ b/openlp/plugins/bibles/forms/bibleupgradeform.py @@ -36,7 +36,7 @@ from tempfile import gettempdir from PyQt4 import QtCore, QtGui -from openlp.core.lib import Receiver, SettingsManager, translate, check_directory_exists, Settings, UiStrings +from openlp.core.lib import Receiver, translate, check_directory_exists, Settings, UiStrings from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui.wizard import OpenLPWizard, WizardStrings from openlp.core.utils import AppLocation, delete_file, get_filesystem_encoding @@ -117,10 +117,10 @@ class BibleUpgradeForm(OpenLPWizard): """ filename = QtGui.QFileDialog.getExistingDirectory(self, translate('BiblesPlugin.UpgradeWizardForm', 'Select a Backup Directory'), - os.path.dirname(SettingsManager.get_last_dir(self.plugin.settingsSection, 1))) + os.path.dirname(Settings(self.plugin.settingsSection).value(u'last directory backup'))) if filename: self.backupDirectoryEdit.setText(filename) - SettingsManager.set_last_dir(self.plugin.settingsSection, filename, 1) + Settings(self.plugin.settingsSection).setValue(u'last directory backup', filename) def onNoBackupCheckBoxToggled(self, checked): """ diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index 5f00effd0..cb9a1e2fb 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -250,10 +250,11 @@ class SongImportForm(OpenLPWizard): filters += u';;' filters += u'%s (*)' % UiStrings().AllFiles filenames = QtGui.QFileDialog.getOpenFileNames(self, title, - SettingsManager.get_last_dir(self.plugin.settingsSection, 1), filters) + Settings().value(self.plugin.settingsSection + u'/last directory import'), filters) if filenames: listbox.addItems(filenames) - SettingsManager.set_last_dir(self.plugin.settingsSection, os.path.split(unicode(filenames[0]))[0], 1) + Settings().setValue(self.plugin.settingsSection + u'/last directory import', + os.path.split(unicode(filenames[0]))[0]) def getListOfFiles(self, listbox): """ @@ -360,7 +361,7 @@ class SongImportForm(OpenLPWizard): Save the error report to a file. """ filename = QtGui.QFileDialog.getSaveFileName(self, - SettingsManager.get_last_dir(self.plugin.settingsSection, 1)) + Settings().value(self.plugin.settingsSection + u'last directory error log')) if not filename: return report_file = codecs.open(filename, u'w', u'utf-8') diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index b28581cb9..5e4b9ac6e 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -53,9 +53,12 @@ __default_settings__ = { u'songs/update service on edit': False, u'songs/search as type': False, u'songs/add song from service': True, - u'songs/display songbar': True + u'songs/display songbar': True, + u'songs/last directory import': u'', + u'songs/last directory error log': u'' } + class SongsPlugin(Plugin): """ This is the number 1 plugin, if importance were placed on any diff --git a/openlp/plugins/songusage/forms/songusagedetailform.py b/openlp/plugins/songusage/forms/songusagedetailform.py index 6fb99c531..a62246e6c 100644 --- a/openlp/plugins/songusage/forms/songusagedetailform.py +++ b/openlp/plugins/songusage/forms/songusagedetailform.py @@ -30,11 +30,10 @@ import logging import os -from PyQt4 import QtCore, QtGui +from PyQt4 import QtGui from sqlalchemy.sql import and_ -from openlp.core.lib import Receiver, Settings, SettingsManager, translate, \ - check_directory_exists +from openlp.core.lib import Receiver, Settings, translate, check_directory_exists from openlp.plugins.songusage.lib.db import SongUsageItem from songusagedetaildialog import Ui_SongUsageDetailDialog @@ -62,7 +61,7 @@ class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog): fromDate = Settings().value(self.plugin.settingsSection + u'/from date') self.fromDate.setSelectedDate(fromDate) self.toDate.setSelectedDate(toDate) - self.fileLineEdit.setText(SettingsManager.get_last_dir(self.plugin.settingsSection, 1)) + self.fileLineEdit.setText(Settings().value(self.plugin.settingsSection + u'/last directory')) def defineOutputLocation(self): """ @@ -70,10 +69,9 @@ class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog): """ path = QtGui.QFileDialog.getExistingDirectory(self, translate('SongUsagePlugin.SongUsageDetailForm', 'Output File Location'), - SettingsManager.get_last_dir(self.plugin.settingsSection, 1)) - path = unicode(path) + Settings().value(self.plugin.settingsSection + u'/last directory')) if path: - SettingsManager.set_last_dir(self.plugin.settingsSection, path, 1) + Settings().setValue(self.plugin.settingsSection + u'/last directory', path) self.fileLineEdit.setText(path) def accept(self):