forked from openlp/openlp
started work on converting old image settings
This commit is contained in:
parent
c1ba98ee0f
commit
25373944b2
@ -301,23 +301,10 @@ class Plugin(QtCore.QObject):
|
|||||||
# This is needed to load the list of images/media/presentation from the config saved
|
# This is needed to load the list of images/media/presentation from the config saved
|
||||||
# before the settings rewrite.
|
# before the settings rewrite.
|
||||||
if self.mediaItemClass is not None:
|
if self.mediaItemClass is not None:
|
||||||
# We need QSettings instead of Settings here to bypass our central settings dict.
|
loaded_list = Settings().get_files_from_config(self)
|
||||||
# Do NOT do this anywhere else!
|
# Now save the list to the config using our Settings class.
|
||||||
settings = QtCore.QSettings()
|
Settings().setValue(u'%s/%s files' % (self.settingsSection, self.name), loaded_list)
|
||||||
settings.beginGroup(self.settingsSection)
|
# FIXME: make sure we do not do this for the images plugin.
|
||||||
if settings.contains(u'%s count' % self.name):
|
|
||||||
list_count = int(settings.value(u'%s count' % self.name, 0))
|
|
||||||
loaded_list = []
|
|
||||||
if list_count:
|
|
||||||
for counter in range(list_count):
|
|
||||||
item = settings.value(u'%s %d' % (self.name, counter), u'')
|
|
||||||
if item:
|
|
||||||
loaded_list.append(item)
|
|
||||||
settings.remove(u'%s %d' % (self.name, counter))
|
|
||||||
settings.remove(u'%s count' % self.name)
|
|
||||||
# Now save the list to the config using our Settings class.
|
|
||||||
Settings().setValue(u'%s/%s files' % (self.settingsSection, self.name), loaded_list)
|
|
||||||
settings.endGroup()
|
|
||||||
|
|
||||||
def usesTheme(self, theme):
|
def usesTheme(self, theme):
|
||||||
"""
|
"""
|
||||||
|
@ -364,3 +364,32 @@ class Settings(QtCore.QSettings):
|
|||||||
if isinstance(default_value, int):
|
if isinstance(default_value, int):
|
||||||
return int(setting)
|
return int(setting)
|
||||||
return setting
|
return setting
|
||||||
|
|
||||||
|
def get_files_from_config(self, plugin):
|
||||||
|
"""
|
||||||
|
This removes the settings needed for old way we saved files (e. g. the image paths for the image plugin). A list
|
||||||
|
of file paths are returned.
|
||||||
|
|
||||||
|
**Note**: Only a list of paths is returned; this does not convert anything!
|
||||||
|
|
||||||
|
``plugin``
|
||||||
|
The Plugin object.The caller has to convert/save the list himself; o
|
||||||
|
"""
|
||||||
|
files_list = []
|
||||||
|
# We need QSettings instead of Settings here to bypass our central settings dict.
|
||||||
|
# Do NOT do this anywhere else!
|
||||||
|
settings = QtCore.QSettings()
|
||||||
|
settings.beginGroup(plugin.settingsSection)
|
||||||
|
if settings.contains(u'%s count' % plugin.name):
|
||||||
|
# Get the count.
|
||||||
|
list_count = int(settings.value(u'%s count' % plugin.name, 0))
|
||||||
|
if list_count:
|
||||||
|
for counter in range(list_count):
|
||||||
|
# The keys were named e. g.: "image 0"
|
||||||
|
item = settings.value(u'%s %d' % (plugin.name, counter), u'')
|
||||||
|
if item:
|
||||||
|
files_list.append(item)
|
||||||
|
settings.remove(u'%s %d' % (plugin.name, counter))
|
||||||
|
settings.remove(u'%s count' % plugin.name)
|
||||||
|
settings.endGroup()
|
||||||
|
return files_list
|
||||||
|
@ -835,19 +835,11 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
return
|
return
|
||||||
setting_sections = []
|
setting_sections = []
|
||||||
# Add main sections.
|
# Add main sections.
|
||||||
setting_sections.extend([self.generalSettingsSection])
|
setting_sections.extend([self.generalSettingsSection, self.advancedSettingsSection, self.uiSettingsSection,
|
||||||
setting_sections.extend([self.advancedSettingsSection])
|
self.shortcutsSettingsSection, self.serviceManagerSettingsSection, self.themesSettingsSection,
|
||||||
setting_sections.extend([self.uiSettingsSection])
|
self.playersSettingsSection, self.displayTagsSection, self.headerSection, u'crashreport'])
|
||||||
setting_sections.extend([self.shortcutsSettingsSection])
|
|
||||||
setting_sections.extend([self.serviceManagerSettingsSection])
|
|
||||||
setting_sections.extend([self.themesSettingsSection])
|
|
||||||
setting_sections.extend([self.playersSettingsSection])
|
|
||||||
setting_sections.extend([self.displayTagsSection])
|
|
||||||
setting_sections.extend([self.headerSection])
|
|
||||||
setting_sections.extend([u'crashreport'])
|
|
||||||
# Add plugin sections.
|
# Add plugin sections.
|
||||||
for plugin in self.plugin_manager.plugins:
|
setting_sections.extend([plugin.name for plugin in self.plugin_manager.plugins])
|
||||||
setting_sections.extend([plugin.name])
|
|
||||||
# Copy the settings file to the tmp dir, because we do not want to change the original one.
|
# Copy the settings file to the tmp dir, because we do not want to change the original one.
|
||||||
temp_directory = os.path.join(unicode(gettempdir()), u'openlp')
|
temp_directory = os.path.join(unicode(gettempdir()), u'openlp')
|
||||||
check_directory_exists(temp_directory)
|
check_directory_exists(temp_directory)
|
||||||
@ -857,9 +849,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
import_settings = Settings(temp_config, Settings.IniFormat)
|
import_settings = Settings(temp_config, Settings.IniFormat)
|
||||||
# Remove/rename old settings to prepare the import.
|
# Remove/rename old settings to prepare the import.
|
||||||
import_settings.remove_obsolete_settings()
|
import_settings.remove_obsolete_settings()
|
||||||
# Lets do a basic sanity check. If it contains this string we can
|
# FIXME: Convert image files
|
||||||
# assume it was created by OpenLP and so we'll load what we can
|
|
||||||
# from it, and just silently ignore anything we don't recognise
|
# Lets do a basic sanity check. If it contains this string we can assume it was created by OpenLP and so we'll
|
||||||
|
# load what we can from it, and just silently ignore anything we don't recognise.
|
||||||
if import_settings.value(u'SettingsImport/type') != u'OpenLP_settings_export':
|
if import_settings.value(u'SettingsImport/type') != u'OpenLP_settings_export':
|
||||||
QtGui.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'Import settings'),
|
QtGui.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'Import settings'),
|
||||||
translate('OpenLP.MainWindow', 'The file you have selected does not appear to be a valid OpenLP '
|
translate('OpenLP.MainWindow', 'The file you have selected does not appear to be a valid OpenLP '
|
||||||
@ -894,9 +887,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
settings.setValue(u'file_date_imported', now.strftime("%Y-%m-%d %H:%M"))
|
settings.setValue(u'file_date_imported', now.strftime("%Y-%m-%d %H:%M"))
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
settings.sync()
|
settings.sync()
|
||||||
# We must do an immediate restart or current configuration will
|
# We must do an immediate restart or current configuration will overwrite what was just imported when
|
||||||
# overwrite what was just imported when application terminates
|
# application terminates normally. We need to exit without saving configuration.
|
||||||
# normally. We need to exit without saving configuration.
|
|
||||||
QtGui.QMessageBox.information(self, translate('OpenLP.MainWindow', 'Import settings'),
|
QtGui.QMessageBox.information(self, translate('OpenLP.MainWindow', 'Import settings'),
|
||||||
translate('OpenLP.MainWindow', 'OpenLP will now close. Imported settings will '
|
translate('OpenLP.MainWindow', 'OpenLP will now close. Imported settings will '
|
||||||
'be applied the next time you start OpenLP.'),
|
'be applied the next time you start OpenLP.'),
|
||||||
|
@ -41,7 +41,6 @@ log = logging.getLogger(__name__)
|
|||||||
__default_settings__ = {
|
__default_settings__ = {
|
||||||
u'images/db type': u'sqlite',
|
u'images/db type': u'sqlite',
|
||||||
u'images/background color': u'#000000',
|
u'images/background color': u'#000000',
|
||||||
u'images/images files': []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,16 +91,12 @@ class ImageMediaItem(MediaManagerItem):
|
|||||||
self.servicePath = os.path.join(AppLocation.get_section_data_path(self.settingsSection), u'thumbnails')
|
self.servicePath = os.path.join(AppLocation.get_section_data_path(self.settingsSection), u'thumbnails')
|
||||||
check_directory_exists(self.servicePath)
|
check_directory_exists(self.servicePath)
|
||||||
# Import old images list
|
# Import old images list
|
||||||
images_old = Settings().value(self.settingsSection + u'/images files')
|
files_from_config = Settings().get_files_from_config(self.plugin)
|
||||||
if len(images_old) > 0:
|
for old_file in files_from_config:
|
||||||
for imageFile in images_old:
|
imagefilename = ImageFilenames()
|
||||||
imagefilename = ImageFilenames()
|
imagefilename.group_id = 0
|
||||||
imagefilename.group_id = 0
|
imagefilename.filename = old_file
|
||||||
imagefilename.filename = imageFile
|
success = self.manager.save_object(imagefilename)
|
||||||
success = self.manager.save_object(imagefilename)
|
|
||||||
Settings().setValue(self.settingsSection + u'/images files', [])
|
|
||||||
Settings().remove(self.settingsSection + u'/images files')
|
|
||||||
Settings().remove(self.settingsSection + u'/images count')
|
|
||||||
# Load images from the database
|
# Load images from the database
|
||||||
self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename),
|
self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename),
|
||||||
initial_load=True)
|
initial_load=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user