From 4a979b49d9b20a2b0c045faa70a0adfd0ffea5ed Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 17 May 2012 18:19:06 +0200 Subject: [PATCH] continued to implement QString v2 api --- openlp/core/lib/__init__.py | 27 ++++++++++++++----- openlp/core/lib/db.py | 12 ++++----- openlp/core/lib/formattingtags.py | 1 - openlp/core/lib/settingsmanager.py | 5 ++-- openlp/core/lib/ui.py | 1 - openlp/core/ui/firsttimeform.py | 3 +-- openlp/core/ui/mainwindow.py | 36 +++++++++++++++----------- openlp/core/ui/media/__init__.py | 2 +- openlp/core/ui/thememanager.py | 4 +-- openlp/core/utils/__init__.py | 3 +-- openlp/core/utils/languagemanager.py | 2 +- openlp/plugins/alerts/lib/alertstab.py | 8 +++--- openlp/plugins/bibles/lib/__init__.py | 8 +++--- openlp/plugins/bibles/lib/biblestab.py | 19 ++++++-------- openlp/plugins/bibles/lib/manager.py | 4 +-- openlp/plugins/bibles/lib/mediaitem.py | 3 +-- openlp/plugins/images/lib/imagetab.py | 2 +- openlp/plugins/songs/lib/mediaitem.py | 16 ++++++------ 18 files changed, 84 insertions(+), 72 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index d16adda3c..ad696f954 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -64,20 +64,33 @@ class ServiceItemAction(object): class Settings(QtCore.QSettings): + type_list = [] def __init__(self, *args): QtCore.QSettings.__init__(self, *args) - import copy - self.value_ = copy.deepcopy(self.value) - self.value = copy.deepcopy(self.value2) - def value2(self, key, defaultValue): - setting = self.value_(key, defaultValue) + def value(self, key, defaultValue): + setting = super(Settings, self).value(key, defaultValue) + if isinstance(defaultValue, bool): + return setting.toBool() + if isinstance(defaultValue, QtCore.QByteArray): + return setting.toByteArray() if isinstance(defaultValue, int): return setting.toInt()[0] if isinstance(defaultValue, basestring): return setting.toString() - if isinstance(defaultValue, bool): - return setting.toBool() + if isinstance(defaultValue, list): + return setting.toStringList() + if isinstance(defaultValue, QtCore.QPoint): + return setting.toPoint() + print u'No!' + return setting + + def setValue(self, key, value): + super(Settings, self).setValue(key, value) + if type(value) not in Settings.type_list: + Settings.type_list.append(type(value)) + print Settings.type_list + def translate(context, text, comment=None, encoding=QtCore.QCoreApplication.CodecForTr, n=-1, diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index 0af1fe995..7da71afc9 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -184,7 +184,7 @@ class Manager(object): self.db_url = u'' self.is_dirty = False self.session = None - db_type = unicode(settings.value(u'db type', u'sqlite')) + db_type = settings.value(u'db type', u'sqlite') if db_type == u'sqlite': if db_file_name: self.db_url = u'sqlite:///%s/%s' % ( @@ -195,12 +195,12 @@ class Manager(object): AppLocation.get_section_data_path(plugin_name), plugin_name) else: self.db_url = u'%s://%s:%s@%s/%s' % (db_type, - urlquote(unicode(settings.value(u'db username'))), - urlquote(unicode(settings.value(u'db password'))), - urlquote(unicode(settings.value(u'db hostname'))), - urlquote(unicode(settings.value(u'db database')))) + urlquote(settings.value(u'db username', u'')), + urlquote(settings.value(u'db password', u'')), + urlquote(settings.value(u'db hostname', u'')), + urlquote(settings.value(u'db database', u''))) if db_type == u'mysql': - db_encoding = unicode(settings.value(u'db encoding', u'utf8')) + db_encoding = settings.value(u'db encoding', u'utf8') self.db_url += u'?charset=%s' % urlquote(db_encoding) settings.endGroup() if upgrade_mod: diff --git a/openlp/core/lib/formattingtags.py b/openlp/core/lib/formattingtags.py index 2404f3ad7..6661261ba 100644 --- a/openlp/core/lib/formattingtags.py +++ b/openlp/core/lib/formattingtags.py @@ -162,7 +162,6 @@ class FormattingTags(object): u'end html': u'', u'protected': True, u'temporary': False}) FormattingTags.add_html_tags(base_tags) FormattingTags.add_html_tags(temporary_tags) - # Formatting Tags were also known as display tags. user_expands = Settings().value(u'displayTags/html_tags', u'') # cPickle only accepts str not unicode strings diff --git a/openlp/core/lib/settingsmanager.py b/openlp/core/lib/settingsmanager.py index a77df513f..1c1aef4db 100644 --- a/openlp/core/lib/settingsmanager.py +++ b/openlp/core/lib/settingsmanager.py @@ -59,7 +59,7 @@ class SettingsManager(object): name = u'last directory %d' % num else: name = u'last directory' - return unicode(Settings().value(section + u'/' + name, u'')) + return Settings().value(section + u'/' + name, u'') @staticmethod def set_last_dir(section, directory, num=None): @@ -127,7 +127,8 @@ class SettingsManager(object): list = [] if list_count: for counter in range(list_count): - item = unicode(settings.value(u'%s %d' % (name, counter))) + # TODO: Check + item = settings.value(u'%s %d' % (name, counter)) if item: list.append(item) settings.endGroup() diff --git a/openlp/core/lib/ui.py b/openlp/core/lib/ui.py index 3f81af279..2ab67c180 100644 --- a/openlp/core/lib/ui.py +++ b/openlp/core/lib/ui.py @@ -365,7 +365,6 @@ def create_action(parent, name, **kwargs): ``separator`` True in case the action will be considered a separator. - #FIXME: check ``data`` Data which is set as QVariant type. diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index e14db5ae7..33b4ca610 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -206,8 +206,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): index = self.themeComboBox.findText(theme) if index == -1: self.themeComboBox.addItem(theme) - default_theme = unicode(Settings().value( - u'themes/global theme', u'')) + default_theme = Settings().value(u'themes/global theme', u'') # Pre-select the current default theme. index = self.themeComboBox.findText(default_theme) self.themeComboBox.setCurrentIndex(index) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 64167d194..ecba87ab7 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -566,7 +566,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.settingsForm = SettingsForm(self, self) self.formattingTagForm = FormattingTagForm(self) self.shortcutForm = ShortcutListForm(self) - self.recentFiles = QtCore.QStringList() + self.recentFiles = [] # Set up the path with plugins plugin_path = AppLocation.get_directory(AppLocation.PluginsDir) self.pluginManager = PluginManager(plugin_path) @@ -742,7 +742,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): False): self.serviceManagerContents.loadLastFile() view_mode = Settings().value(u'%s/view mode' % \ - self.generalSettingsSection, u'default') + self.generalSettingsSection, u'default') if view_mode == u'default': self.modeDefaultItem.setChecked(True) elif view_mode == u'setup': @@ -1322,20 +1322,20 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): settings.remove(u'custom slide') settings.remove(u'service') settings.beginGroup(self.generalSettingsSection) - self.recentFiles = settings.value(u'recent files').toStringList() + self.recentFiles = settings.value(u'recent files', list()) settings.endGroup() settings.beginGroup(self.uiSettingsSection) - self.move(settings.value(u'main window position', - QtCore.QPoint(0, 0))).toPoint() + self.move(settings.value(u'main window position', QtCore.QPoint(0, 0))) self.restoreGeometry( - settings.value(u'main window geometry').toByteArray()) - self.restoreState(settings.value(u'main window state').toByteArray()) + settings.value(u'main window geometry', QtCore.QByteArray())) + self.restoreState( + settings.value(u'main window state', QtCore.QByteArray())) self.liveController.splitter.restoreState( - settings.value(u'live splitter geometry').toByteArray()) + settings.value(u'live splitter geometry', QtCore.QByteArray())) self.previewController.splitter.restoreState( - settings.value(u'preview splitter geometry').toByteArray()) - self.controlSplitter.restoreState( - settings.value(u'mainwindow splitter geometry').toByteArray()) + settings.value(u'preview splitter geometry', QtCore.QByteArray())) + self.controlSplitter.restoreState(settings.value( + u'mainwindow splitter geometry', QtCore.QByteArray())) settings.endGroup() def saveSettings(self): @@ -1373,7 +1373,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): existingRecentFiles = [recentFile for recentFile in self.recentFiles if os.path.isfile(unicode(recentFile))] recentFilesToDisplay = existingRecentFiles[0:recentFileCount] - self.recentFilesMenu.clear() + self.clearRecentFileMenu() for fileId, filename in enumerate(recentFilesToDisplay): log.debug('Recent file name: %s', filename) action = create_action(self, u'', @@ -1386,10 +1386,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): 'Clear List of recent files'), statustip=translate('OpenLP.MainWindow', 'Clear the list of recent files.'), - enabled=not self.recentFiles.isEmpty(), - triggers=self.recentFiles.clear) + enabled=bool(self.recentFiles), + triggers=self.clearRecentFileMenu) add_actions(self.recentFilesMenu, (None, clearRecentFilesAction)) - clearRecentFilesAction.setEnabled(not self.recentFiles.isEmpty()) + clearRecentFilesAction.setEnabled(bool(self.recentFiles)) def addRecentFile(self, filename): """ @@ -1418,6 +1418,12 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # Don't care what API says takeLast works, removeLast doesn't! self.recentFiles.takeLast() + def clearRecentFileMenu(self): + """ + Clears the recent files. + """ + self.recentFiles = [] + def displayProgressBar(self, size): """ Make Progress bar visible and set size diff --git a/openlp/core/ui/media/__init__.py b/openlp/core/ui/media/__init__.py index 7fb5ccd04..1975c4bb0 100644 --- a/openlp/core/ui/media/__init__.py +++ b/openlp/core/ui/media/__init__.py @@ -80,7 +80,7 @@ def get_media_players(): Here an special media player is chosen for all media actions. """ log.debug(u'get_media_players') - players = Settings().value(u'media/players') + players = Settings().value(u'media/players', u'') if not players: players = u'webkit' reg_ex = QtCore.QRegExp(".*\[(.*)\].*") diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index f4235e2b4..bfbac5fc1 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -764,8 +764,8 @@ class ThemeManager(QtGui.QWidget): Check to see if theme has been selected and the destructive action is allowed. """ - self.global_theme = unicode(Settings().value( - self.settingsSection + u'/global theme', u'')) + self.global_theme = Settings().value( + self.settingsSection + u'/global theme', u'') if check_item_selected(self.themeListWidget, select_text): item = self.themeListWidget.currentItem() theme = unicode(item.text()) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 57d0a33c6..964f82d00 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -285,8 +285,7 @@ def check_latest_version(current_version): # set to prod in the distribution config file. settings = Settings() settings.beginGroup(u'general') - last_test = unicode(settings.value(u'last version test', - datetime.now().date())) + last_test = settings.value(u'last version test', datetime.now().date()) this_test = unicode(datetime.now().date()) settings.setValue(u'last version test', this_test) settings.endGroup() diff --git a/openlp/core/utils/languagemanager.py b/openlp/core/utils/languagemanager.py index 65582885a..21ccffbc1 100644 --- a/openlp/core/utils/languagemanager.py +++ b/openlp/core/utils/languagemanager.py @@ -105,7 +105,7 @@ class LanguageManager(object): Retrieve a saved language to use from settings """ settings = Settings() - language = unicode(settings.value(u'general/language', u'[en]')) + language = settings.value(u'general/language', u'[en]') log.info(u'Language file: \'%s\' Loaded from conf file' % language) reg_ex = QtCore.QRegExp("^\[(.*)\]") if reg_ex.exactMatch(language): diff --git a/openlp/plugins/alerts/lib/alertstab.py b/openlp/plugins/alerts/lib/alertstab.py index cf0c88409..f10826a22 100644 --- a/openlp/plugins/alerts/lib/alertstab.py +++ b/openlp/plugins/alerts/lib/alertstab.py @@ -155,11 +155,11 @@ class AlertsTab(SettingsTab): settings = Settings() settings.beginGroup(self.settingsSection) self.timeout = settings.value(u'timeout', 5) - self.font_color = unicode(settings.value(u'font color', u'#ffffff')) + self.font_color = settings.value(u'font color', u'#ffffff') self.font_size = settings.value(u'font size', 40) - self.bg_color = unicode(settings.value(u'background color', u'#660000')) - self.font_face = unicode(settings.value( - u'font face', QtGui.QFont().family())) + self.bg_color = settings.value(u'background color', u'#660000') + # TODO: isinstance needed? + self.font_face = settings.value(u'font face', QtGui.QFont().family()) self.location = settings.value(u'location', AlertLocation.Bottom) settings.endGroup() self.fontSizeSpinBox.setValue(self.font_size) diff --git a/openlp/plugins/bibles/lib/__init__.py b/openlp/plugins/bibles/lib/__init__.py index b5dc0087a..3543c10a5 100644 --- a/openlp/plugins/bibles/lib/__init__.py +++ b/openlp/plugins/bibles/lib/__init__.py @@ -188,10 +188,10 @@ def update_reference_separators(): settings = Settings() settings.beginGroup(u'bibles') custom_separators = [ - settings.value(u'verse separator'), - settings.value(u'range separator'), - settings.value(u'list separator'), - settings.value(u'end separator')] + settings.value(u'verse separator', u''), + settings.value(u'range separator', u''), + settings.value(u'list separator', u''), + settings.value(u'end separator', u'')] settings.endGroup() for index, role in enumerate([u'v', u'r', u'l', u'e']): if custom_separators[index].strip(u'|') == u'': diff --git a/openlp/plugins/bibles/lib/biblestab.py b/openlp/plugins/bibles/lib/biblestab.py index 148b75cd5..a054d1de0 100644 --- a/openlp/plugins/bibles/lib/biblestab.py +++ b/openlp/plugins/bibles/lib/biblestab.py @@ -420,13 +420,13 @@ class BiblesTab(SettingsTab): self.display_style = settings.value(u'display brackets', 0) self.layout_style = settings.value(u'verse layout style', 0) #TODO: Check - self.bible_theme = unicode(settings.value(u'bible theme', u'')) + self.bible_theme = settings.value(u'bible theme', u'') self.second_bibles = settings.value(u'second bibles', True) self.newChaptersCheckBox.setChecked(self.show_new_chapters) self.displayStyleComboBox.setCurrentIndex(self.display_style) self.layoutStyleComboBox.setCurrentIndex(self.layout_style) self.bibleSecondCheckBox.setChecked(self.second_bibles) - verse_separator = unicode(settings.value(u'verse separator').toString()) + verse_separator = settings.value(u'verse separator', u'') if (verse_separator.strip(u'|') == u'') or \ (verse_separator == get_reference_separator(u'sep_v_default')): self.verseSeparatorLineEdit.setText( @@ -439,7 +439,7 @@ class BiblesTab(SettingsTab): self.verseSeparatorLineEdit.setPalette( self.getGreyTextPalette(False)) self.verseSeparatorCheckBox.setChecked(True) - range_separator = unicode(settings.value(u'range separator').toString()) + range_separator = settings.value(u'range separator', u'') if (range_separator.strip(u'|') == u'') or \ (range_separator == get_reference_separator(u'sep_r_default')): self.rangeSeparatorLineEdit.setText( @@ -452,31 +452,28 @@ class BiblesTab(SettingsTab): self.rangeSeparatorLineEdit.setPalette( self.getGreyTextPalette(False)) self.rangeSeparatorCheckBox.setChecked(True) - list_separator = unicode(settings.value(u'list separator').toString()) + list_separator = settings.value(u'list separator', u'') if (list_separator.strip(u'|') == u'') or \ (list_separator == get_reference_separator(u'sep_l_default')): self.listSeparatorLineEdit.setText( get_reference_separator(u'sep_l_default')) - self.listSeparatorLineEdit.setPalette( - self.getGreyTextPalette(True)) + self.listSeparatorLineEdit.setPalette(self.getGreyTextPalette(True)) self.listSeparatorCheckBox.setChecked(False) else: self.listSeparatorLineEdit.setText(list_separator) self.listSeparatorLineEdit.setPalette( self.getGreyTextPalette(False)) self.listSeparatorCheckBox.setChecked(True) - end_separator = unicode(settings.value(u'end separator').toString()) + end_separator = settings.value(u'end separator', u'') if (end_separator.strip(u'|') == u'') or \ (end_separator == get_reference_separator(u'sep_e_default')): self.endSeparatorLineEdit.setText( get_reference_separator(u'sep_e_default')) - self.endSeparatorLineEdit.setPalette( - self.getGreyTextPalette(True)) + self.endSeparatorLineEdit.setPalette(self.getGreyTextPalette(True)) self.endSeparatorCheckBox.setChecked(False) else: self.endSeparatorLineEdit.setText(end_separator) - self.endSeparatorLineEdit.setPalette( - self.getGreyTextPalette(False)) + self.endSeparatorLineEdit.setPalette(self.getGreyTextPalette(False)) self.endSeparatorCheckBox.setChecked(True) self.language_selection = settings.value(u'book name language', 0) self.languageSelectionComboBox.setCurrentIndex(self.language_selection) diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 03382c572..c2091895a 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -125,8 +125,8 @@ class BibleManager(object): self.web = u'Web' self.db_cache = None self.path = AppLocation.get_section_data_path(self.settingsSection) - self.proxy_name = unicode(Settings().value( - self.settingsSection + u'/proxy name', u'')) + self.proxy_name = Settings().value( + self.settingsSection + u'/proxy name', u'') self.suffix = u'.sqlite' self.import_wizard = None self.reload_bibles() diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 09c59fdf9..2778ee42b 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -386,8 +386,7 @@ class BibleMediaItem(MediaManagerItem): self.advancedVersionComboBox.addItems(bibles) self.advancedSecondComboBox.addItems(bibles) # set the default value - bible = Settings().value( - self.settingsSection + u'/advanced bible', u'') + bible = Settings().value(self.settingsSection + u'/advanced bible', u'') if bible in bibles: find_and_set_in_combo_box(self.advancedVersionComboBox, bible) self.initialiseAdvancedBible(unicode(bible)) diff --git a/openlp/plugins/images/lib/imagetab.py b/openlp/plugins/images/lib/imagetab.py index 1fc6e834b..3e32687bd 100644 --- a/openlp/plugins/images/lib/imagetab.py +++ b/openlp/plugins/images/lib/imagetab.py @@ -84,7 +84,7 @@ class ImageTab(SettingsTab): def load(self): settings = Settings() settings.beginGroup(self.settingsSection) - self.bg_color = unicode(settings.value(u'background color', u'#000000')) + self.bg_color = settings.value(u'background color', u'#000000') self.initial_color = self.bg_color settings.endGroup() self.backgroundColorButton.setStyleSheet( diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 456062b69..b01418cbb 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -133,12 +133,12 @@ class SongMediaItem(MediaManagerItem): def configUpdated(self): # TODO: Check .toBool() - self.searchAsYouType = bool(Settings().value( - self.settingsSection + u'/search as type', False)) - self.updateServiceOnEdit = bool(Settings().value( - self.settingsSection + u'/update service on edit', False)) - self.addSongFromService = bool(Settings().value( - self.settingsSection + u'/add song from service', True)) + self.searchAsYouType = Settings().value( + self.settingsSection + u'/search as type', False) + self.updateServiceOnEdit = Settings().value( + self.settingsSection + u'/update service on edit', False) + self.addSongFromService = Settings().value( + self.settingsSection + u'/add song from service', True) def retranslateUi(self): self.searchTextLabel.setText(u'%s:' % UiStrings().Search) @@ -515,8 +515,8 @@ class SongMediaItem(MediaManagerItem): service_item.raw_footer.append(song.copyright) if Settings().value(u'general/ccli number', u''): service_item.raw_footer.append(unicode( - translate('SongsPlugin.MediaItem', 'CCLI License: ') + - Settings().value(u'general/ccli number', u''))) + translate('SongsPlugin.MediaItem', 'CCLI License: ')) + + Settings().value(u'general/ccli number', u'')) service_item.audit = [ song.title, author_list, song.copyright, unicode(song.ccli_number) ]