continued to implement QString v2 api

This commit is contained in:
Andreas Preikschat 2012-05-17 18:19:06 +02:00
parent 2d99f59c84
commit 4a979b49d9
18 changed files with 84 additions and 72 deletions

View File

@ -64,20 +64,33 @@ class ServiceItemAction(object):
class Settings(QtCore.QSettings): class Settings(QtCore.QSettings):
type_list = []
def __init__(self, *args): def __init__(self, *args):
QtCore.QSettings.__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): def value(self, key, defaultValue):
setting = self.value_(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): if isinstance(defaultValue, int):
return setting.toInt()[0] return setting.toInt()[0]
if isinstance(defaultValue, basestring): if isinstance(defaultValue, basestring):
return setting.toString() return setting.toString()
if isinstance(defaultValue, bool): if isinstance(defaultValue, list):
return setting.toBool() 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, def translate(context, text, comment=None,
encoding=QtCore.QCoreApplication.CodecForTr, n=-1, encoding=QtCore.QCoreApplication.CodecForTr, n=-1,

View File

@ -184,7 +184,7 @@ class Manager(object):
self.db_url = u'' self.db_url = u''
self.is_dirty = False self.is_dirty = False
self.session = None 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_type == u'sqlite':
if db_file_name: if db_file_name:
self.db_url = u'sqlite:///%s/%s' % ( self.db_url = u'sqlite:///%s/%s' % (
@ -195,12 +195,12 @@ class Manager(object):
AppLocation.get_section_data_path(plugin_name), plugin_name) AppLocation.get_section_data_path(plugin_name), plugin_name)
else: else:
self.db_url = u'%s://%s:%s@%s/%s' % (db_type, self.db_url = u'%s://%s:%s@%s/%s' % (db_type,
urlquote(unicode(settings.value(u'db username'))), urlquote(settings.value(u'db username', u'')),
urlquote(unicode(settings.value(u'db password'))), urlquote(settings.value(u'db password', u'')),
urlquote(unicode(settings.value(u'db hostname'))), urlquote(settings.value(u'db hostname', u'')),
urlquote(unicode(settings.value(u'db database')))) urlquote(settings.value(u'db database', u'')))
if db_type == u'mysql': 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) self.db_url += u'?charset=%s' % urlquote(db_encoding)
settings.endGroup() settings.endGroup()
if upgrade_mod: if upgrade_mod:

View File

@ -162,7 +162,6 @@ class FormattingTags(object):
u'end html': u'', u'protected': True, u'temporary': False}) u'end html': u'', u'protected': True, u'temporary': False})
FormattingTags.add_html_tags(base_tags) FormattingTags.add_html_tags(base_tags)
FormattingTags.add_html_tags(temporary_tags) FormattingTags.add_html_tags(temporary_tags)
# Formatting Tags were also known as display tags. # Formatting Tags were also known as display tags.
user_expands = Settings().value(u'displayTags/html_tags', u'') user_expands = Settings().value(u'displayTags/html_tags', u'')
# cPickle only accepts str not unicode strings # cPickle only accepts str not unicode strings

View File

@ -59,7 +59,7 @@ class SettingsManager(object):
name = u'last directory %d' % num name = u'last directory %d' % num
else: else:
name = u'last directory' name = u'last directory'
return unicode(Settings().value(section + u'/' + name, u'')) return Settings().value(section + u'/' + name, u'')
@staticmethod @staticmethod
def set_last_dir(section, directory, num=None): def set_last_dir(section, directory, num=None):
@ -127,7 +127,8 @@ class SettingsManager(object):
list = [] list = []
if list_count: if list_count:
for counter in range(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: if item:
list.append(item) list.append(item)
settings.endGroup() settings.endGroup()

View File

@ -365,7 +365,6 @@ def create_action(parent, name, **kwargs):
``separator`` ``separator``
True in case the action will be considered a separator. True in case the action will be considered a separator.
#FIXME: check
``data`` ``data``
Data which is set as QVariant type. Data which is set as QVariant type.

View File

@ -206,8 +206,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
index = self.themeComboBox.findText(theme) index = self.themeComboBox.findText(theme)
if index == -1: if index == -1:
self.themeComboBox.addItem(theme) self.themeComboBox.addItem(theme)
default_theme = unicode(Settings().value( default_theme = Settings().value(u'themes/global theme', u'')
u'themes/global theme', u''))
# Pre-select the current default theme. # Pre-select the current default theme.
index = self.themeComboBox.findText(default_theme) index = self.themeComboBox.findText(default_theme)
self.themeComboBox.setCurrentIndex(index) self.themeComboBox.setCurrentIndex(index)

View File

@ -566,7 +566,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.settingsForm = SettingsForm(self, self) self.settingsForm = SettingsForm(self, self)
self.formattingTagForm = FormattingTagForm(self) self.formattingTagForm = FormattingTagForm(self)
self.shortcutForm = ShortcutListForm(self) self.shortcutForm = ShortcutListForm(self)
self.recentFiles = QtCore.QStringList() self.recentFiles = []
# Set up the path with plugins # Set up the path with plugins
plugin_path = AppLocation.get_directory(AppLocation.PluginsDir) plugin_path = AppLocation.get_directory(AppLocation.PluginsDir)
self.pluginManager = PluginManager(plugin_path) self.pluginManager = PluginManager(plugin_path)
@ -742,7 +742,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
False): False):
self.serviceManagerContents.loadLastFile() self.serviceManagerContents.loadLastFile()
view_mode = Settings().value(u'%s/view mode' % \ view_mode = Settings().value(u'%s/view mode' % \
self.generalSettingsSection, u'default') self.generalSettingsSection, u'default')
if view_mode == u'default': if view_mode == u'default':
self.modeDefaultItem.setChecked(True) self.modeDefaultItem.setChecked(True)
elif view_mode == u'setup': elif view_mode == u'setup':
@ -1322,20 +1322,20 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
settings.remove(u'custom slide') settings.remove(u'custom slide')
settings.remove(u'service') settings.remove(u'service')
settings.beginGroup(self.generalSettingsSection) settings.beginGroup(self.generalSettingsSection)
self.recentFiles = settings.value(u'recent files').toStringList() self.recentFiles = settings.value(u'recent files', list())
settings.endGroup() settings.endGroup()
settings.beginGroup(self.uiSettingsSection) settings.beginGroup(self.uiSettingsSection)
self.move(settings.value(u'main window position', self.move(settings.value(u'main window position', QtCore.QPoint(0, 0)))
QtCore.QPoint(0, 0))).toPoint()
self.restoreGeometry( self.restoreGeometry(
settings.value(u'main window geometry').toByteArray()) settings.value(u'main window geometry', QtCore.QByteArray()))
self.restoreState(settings.value(u'main window state').toByteArray()) self.restoreState(
settings.value(u'main window state', QtCore.QByteArray()))
self.liveController.splitter.restoreState( self.liveController.splitter.restoreState(
settings.value(u'live splitter geometry').toByteArray()) settings.value(u'live splitter geometry', QtCore.QByteArray()))
self.previewController.splitter.restoreState( self.previewController.splitter.restoreState(
settings.value(u'preview splitter geometry').toByteArray()) settings.value(u'preview splitter geometry', QtCore.QByteArray()))
self.controlSplitter.restoreState( self.controlSplitter.restoreState(settings.value(
settings.value(u'mainwindow splitter geometry').toByteArray()) u'mainwindow splitter geometry', QtCore.QByteArray()))
settings.endGroup() settings.endGroup()
def saveSettings(self): def saveSettings(self):
@ -1373,7 +1373,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
existingRecentFiles = [recentFile for recentFile in self.recentFiles existingRecentFiles = [recentFile for recentFile in self.recentFiles
if os.path.isfile(unicode(recentFile))] if os.path.isfile(unicode(recentFile))]
recentFilesToDisplay = existingRecentFiles[0:recentFileCount] recentFilesToDisplay = existingRecentFiles[0:recentFileCount]
self.recentFilesMenu.clear() self.clearRecentFileMenu()
for fileId, filename in enumerate(recentFilesToDisplay): for fileId, filename in enumerate(recentFilesToDisplay):
log.debug('Recent file name: %s', filename) log.debug('Recent file name: %s', filename)
action = create_action(self, u'', action = create_action(self, u'',
@ -1386,10 +1386,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
'Clear List of recent files'), 'Clear List of recent files'),
statustip=translate('OpenLP.MainWindow', statustip=translate('OpenLP.MainWindow',
'Clear the list of recent files.'), 'Clear the list of recent files.'),
enabled=not self.recentFiles.isEmpty(), enabled=bool(self.recentFiles),
triggers=self.recentFiles.clear) triggers=self.clearRecentFileMenu)
add_actions(self.recentFilesMenu, (None, clearRecentFilesAction)) add_actions(self.recentFilesMenu, (None, clearRecentFilesAction))
clearRecentFilesAction.setEnabled(not self.recentFiles.isEmpty()) clearRecentFilesAction.setEnabled(bool(self.recentFiles))
def addRecentFile(self, filename): 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! # Don't care what API says takeLast works, removeLast doesn't!
self.recentFiles.takeLast() self.recentFiles.takeLast()
def clearRecentFileMenu(self):
"""
Clears the recent files.
"""
self.recentFiles = []
def displayProgressBar(self, size): def displayProgressBar(self, size):
""" """
Make Progress bar visible and set size Make Progress bar visible and set size

View File

@ -80,7 +80,7 @@ def get_media_players():
Here an special media player is chosen for all media actions. Here an special media player is chosen for all media actions.
""" """
log.debug(u'get_media_players') log.debug(u'get_media_players')
players = Settings().value(u'media/players') players = Settings().value(u'media/players', u'')
if not players: if not players:
players = u'webkit' players = u'webkit'
reg_ex = QtCore.QRegExp(".*\[(.*)\].*") reg_ex = QtCore.QRegExp(".*\[(.*)\].*")

View File

@ -764,8 +764,8 @@ class ThemeManager(QtGui.QWidget):
Check to see if theme has been selected and the destructive action Check to see if theme has been selected and the destructive action
is allowed. is allowed.
""" """
self.global_theme = unicode(Settings().value( self.global_theme = Settings().value(
self.settingsSection + u'/global theme', u'')) self.settingsSection + u'/global theme', u'')
if check_item_selected(self.themeListWidget, select_text): if check_item_selected(self.themeListWidget, select_text):
item = self.themeListWidget.currentItem() item = self.themeListWidget.currentItem()
theme = unicode(item.text()) theme = unicode(item.text())

View File

@ -285,8 +285,7 @@ def check_latest_version(current_version):
# set to prod in the distribution config file. # set to prod in the distribution config file.
settings = Settings() settings = Settings()
settings.beginGroup(u'general') settings.beginGroup(u'general')
last_test = unicode(settings.value(u'last version test', last_test = settings.value(u'last version test', datetime.now().date())
datetime.now().date()))
this_test = unicode(datetime.now().date()) this_test = unicode(datetime.now().date())
settings.setValue(u'last version test', this_test) settings.setValue(u'last version test', this_test)
settings.endGroup() settings.endGroup()

View File

@ -105,7 +105,7 @@ class LanguageManager(object):
Retrieve a saved language to use from settings Retrieve a saved language to use from settings
""" """
settings = 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) log.info(u'Language file: \'%s\' Loaded from conf file' % language)
reg_ex = QtCore.QRegExp("^\[(.*)\]") reg_ex = QtCore.QRegExp("^\[(.*)\]")
if reg_ex.exactMatch(language): if reg_ex.exactMatch(language):

View File

@ -155,11 +155,11 @@ class AlertsTab(SettingsTab):
settings = Settings() settings = Settings()
settings.beginGroup(self.settingsSection) settings.beginGroup(self.settingsSection)
self.timeout = settings.value(u'timeout', 5) 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.font_size = settings.value(u'font size', 40)
self.bg_color = unicode(settings.value(u'background color', u'#660000')) self.bg_color = settings.value(u'background color', u'#660000')
self.font_face = unicode(settings.value( # TODO: isinstance needed?
u'font face', QtGui.QFont().family())) self.font_face = settings.value(u'font face', QtGui.QFont().family())
self.location = settings.value(u'location', AlertLocation.Bottom) self.location = settings.value(u'location', AlertLocation.Bottom)
settings.endGroup() settings.endGroup()
self.fontSizeSpinBox.setValue(self.font_size) self.fontSizeSpinBox.setValue(self.font_size)

View File

@ -188,10 +188,10 @@ def update_reference_separators():
settings = Settings() settings = Settings()
settings.beginGroup(u'bibles') settings.beginGroup(u'bibles')
custom_separators = [ custom_separators = [
settings.value(u'verse separator'), settings.value(u'verse separator', u''),
settings.value(u'range separator'), settings.value(u'range separator', u''),
settings.value(u'list separator'), settings.value(u'list separator', u''),
settings.value(u'end separator')] settings.value(u'end separator', u'')]
settings.endGroup() settings.endGroup()
for index, role in enumerate([u'v', u'r', u'l', u'e']): for index, role in enumerate([u'v', u'r', u'l', u'e']):
if custom_separators[index].strip(u'|') == u'': if custom_separators[index].strip(u'|') == u'':

View File

@ -420,13 +420,13 @@ class BiblesTab(SettingsTab):
self.display_style = settings.value(u'display brackets', 0) self.display_style = settings.value(u'display brackets', 0)
self.layout_style = settings.value(u'verse layout style', 0) self.layout_style = settings.value(u'verse layout style', 0)
#TODO: Check #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.second_bibles = settings.value(u'second bibles', True)
self.newChaptersCheckBox.setChecked(self.show_new_chapters) self.newChaptersCheckBox.setChecked(self.show_new_chapters)
self.displayStyleComboBox.setCurrentIndex(self.display_style) self.displayStyleComboBox.setCurrentIndex(self.display_style)
self.layoutStyleComboBox.setCurrentIndex(self.layout_style) self.layoutStyleComboBox.setCurrentIndex(self.layout_style)
self.bibleSecondCheckBox.setChecked(self.second_bibles) 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 \ if (verse_separator.strip(u'|') == u'') or \
(verse_separator == get_reference_separator(u'sep_v_default')): (verse_separator == get_reference_separator(u'sep_v_default')):
self.verseSeparatorLineEdit.setText( self.verseSeparatorLineEdit.setText(
@ -439,7 +439,7 @@ class BiblesTab(SettingsTab):
self.verseSeparatorLineEdit.setPalette( self.verseSeparatorLineEdit.setPalette(
self.getGreyTextPalette(False)) self.getGreyTextPalette(False))
self.verseSeparatorCheckBox.setChecked(True) 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 \ if (range_separator.strip(u'|') == u'') or \
(range_separator == get_reference_separator(u'sep_r_default')): (range_separator == get_reference_separator(u'sep_r_default')):
self.rangeSeparatorLineEdit.setText( self.rangeSeparatorLineEdit.setText(
@ -452,31 +452,28 @@ class BiblesTab(SettingsTab):
self.rangeSeparatorLineEdit.setPalette( self.rangeSeparatorLineEdit.setPalette(
self.getGreyTextPalette(False)) self.getGreyTextPalette(False))
self.rangeSeparatorCheckBox.setChecked(True) 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 \ if (list_separator.strip(u'|') == u'') or \
(list_separator == get_reference_separator(u'sep_l_default')): (list_separator == get_reference_separator(u'sep_l_default')):
self.listSeparatorLineEdit.setText( self.listSeparatorLineEdit.setText(
get_reference_separator(u'sep_l_default')) get_reference_separator(u'sep_l_default'))
self.listSeparatorLineEdit.setPalette( self.listSeparatorLineEdit.setPalette(self.getGreyTextPalette(True))
self.getGreyTextPalette(True))
self.listSeparatorCheckBox.setChecked(False) self.listSeparatorCheckBox.setChecked(False)
else: else:
self.listSeparatorLineEdit.setText(list_separator) self.listSeparatorLineEdit.setText(list_separator)
self.listSeparatorLineEdit.setPalette( self.listSeparatorLineEdit.setPalette(
self.getGreyTextPalette(False)) self.getGreyTextPalette(False))
self.listSeparatorCheckBox.setChecked(True) 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 \ if (end_separator.strip(u'|') == u'') or \
(end_separator == get_reference_separator(u'sep_e_default')): (end_separator == get_reference_separator(u'sep_e_default')):
self.endSeparatorLineEdit.setText( self.endSeparatorLineEdit.setText(
get_reference_separator(u'sep_e_default')) get_reference_separator(u'sep_e_default'))
self.endSeparatorLineEdit.setPalette( self.endSeparatorLineEdit.setPalette(self.getGreyTextPalette(True))
self.getGreyTextPalette(True))
self.endSeparatorCheckBox.setChecked(False) self.endSeparatorCheckBox.setChecked(False)
else: else:
self.endSeparatorLineEdit.setText(end_separator) self.endSeparatorLineEdit.setText(end_separator)
self.endSeparatorLineEdit.setPalette( self.endSeparatorLineEdit.setPalette(self.getGreyTextPalette(False))
self.getGreyTextPalette(False))
self.endSeparatorCheckBox.setChecked(True) self.endSeparatorCheckBox.setChecked(True)
self.language_selection = settings.value(u'book name language', 0) self.language_selection = settings.value(u'book name language', 0)
self.languageSelectionComboBox.setCurrentIndex(self.language_selection) self.languageSelectionComboBox.setCurrentIndex(self.language_selection)

View File

@ -125,8 +125,8 @@ class BibleManager(object):
self.web = u'Web' self.web = u'Web'
self.db_cache = None self.db_cache = None
self.path = AppLocation.get_section_data_path(self.settingsSection) self.path = AppLocation.get_section_data_path(self.settingsSection)
self.proxy_name = unicode(Settings().value( self.proxy_name = Settings().value(
self.settingsSection + u'/proxy name', u'')) self.settingsSection + u'/proxy name', u'')
self.suffix = u'.sqlite' self.suffix = u'.sqlite'
self.import_wizard = None self.import_wizard = None
self.reload_bibles() self.reload_bibles()

View File

@ -386,8 +386,7 @@ class BibleMediaItem(MediaManagerItem):
self.advancedVersionComboBox.addItems(bibles) self.advancedVersionComboBox.addItems(bibles)
self.advancedSecondComboBox.addItems(bibles) self.advancedSecondComboBox.addItems(bibles)
# set the default value # set the default value
bible = Settings().value( bible = Settings().value(self.settingsSection + u'/advanced bible', u'')
self.settingsSection + u'/advanced bible', u'')
if bible in bibles: if bible in bibles:
find_and_set_in_combo_box(self.advancedVersionComboBox, bible) find_and_set_in_combo_box(self.advancedVersionComboBox, bible)
self.initialiseAdvancedBible(unicode(bible)) self.initialiseAdvancedBible(unicode(bible))

View File

@ -84,7 +84,7 @@ class ImageTab(SettingsTab):
def load(self): def load(self):
settings = Settings() settings = Settings()
settings.beginGroup(self.settingsSection) 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 self.initial_color = self.bg_color
settings.endGroup() settings.endGroup()
self.backgroundColorButton.setStyleSheet( self.backgroundColorButton.setStyleSheet(

View File

@ -133,12 +133,12 @@ class SongMediaItem(MediaManagerItem):
def configUpdated(self): def configUpdated(self):
# TODO: Check .toBool() # TODO: Check .toBool()
self.searchAsYouType = bool(Settings().value( self.searchAsYouType = Settings().value(
self.settingsSection + u'/search as type', False)) self.settingsSection + u'/search as type', False)
self.updateServiceOnEdit = bool(Settings().value( self.updateServiceOnEdit = Settings().value(
self.settingsSection + u'/update service on edit', False)) self.settingsSection + u'/update service on edit', False)
self.addSongFromService = bool(Settings().value( self.addSongFromService = Settings().value(
self.settingsSection + u'/add song from service', True)) self.settingsSection + u'/add song from service', True)
def retranslateUi(self): def retranslateUi(self):
self.searchTextLabel.setText(u'%s:' % UiStrings().Search) self.searchTextLabel.setText(u'%s:' % UiStrings().Search)
@ -515,8 +515,8 @@ class SongMediaItem(MediaManagerItem):
service_item.raw_footer.append(song.copyright) service_item.raw_footer.append(song.copyright)
if Settings().value(u'general/ccli number', u''): if Settings().value(u'general/ccli number', u''):
service_item.raw_footer.append(unicode( service_item.raw_footer.append(unicode(
translate('SongsPlugin.MediaItem', 'CCLI License: ') + translate('SongsPlugin.MediaItem', 'CCLI License: ')) +
Settings().value(u'general/ccli number', u''))) Settings().value(u'general/ccli number', u''))
service_item.audit = [ service_item.audit = [
song.title, author_list, song.copyright, unicode(song.ccli_number) song.title, author_list, song.copyright, unicode(song.ccli_number)
] ]