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):
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,

View File

@ -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:

View File

@ -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

View File

@ -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()

View File

@ -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.

View File

@ -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)

View File

@ -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)
@ -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

View File

@ -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(".*\[(.*)\].*")

View File

@ -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())

View File

@ -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()

View File

@ -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):

View File

@ -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)

View File

@ -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'':

View File

@ -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)

View File

@ -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()

View File

@ -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))

View File

@ -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(

View File

@ -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)
]