forked from openlp/openlp
remove set_list and get_list from SettingsManager
This commit is contained in:
parent
254f6915ed
commit
a98045e386
@ -383,8 +383,7 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
self.loadList(full_list)
|
||||
last_dir = os.path.split(unicode(files[0]))[0]
|
||||
Settings().setValue(self.settingsSection + u'/last directory', last_dir)
|
||||
SettingsManager.set_list(self.settingsSection,
|
||||
self.settingsSection, self.getFileList())
|
||||
Settings().setValue(u'%s/%s files' % (self.settingsSection, self.settingsSection), self.getFileList())
|
||||
if duplicates_found:
|
||||
critical_error_message_box(UiStrings().Duplicate,
|
||||
translate('OpenLP.MediaManagerItem', 'Duplicate files were found on import and were ignored.'))
|
||||
|
@ -177,6 +177,8 @@ class Plugin(QtCore.QObject):
|
||||
# Add the default status to the default settings.
|
||||
default_settings[name + u'/status'] = PluginStatus.Inactive
|
||||
default_settings[name + u'/last directory'] = u''
|
||||
if media_item_class is not None:
|
||||
default_settings[u'%s/%s files' % (name, name)] = []
|
||||
# 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),
|
||||
|
@ -44,56 +44,6 @@ class SettingsManager(object):
|
||||
Class to provide helper functions for the loading and saving of application settings.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def set_list(section, name, list_to_save):
|
||||
"""
|
||||
Save a list to application settings.
|
||||
|
||||
``section``
|
||||
The section of the settings to store this list.
|
||||
|
||||
``name``
|
||||
The name of the list to save.
|
||||
|
||||
``list_to_save``
|
||||
The list of values to save.
|
||||
"""
|
||||
settings = Settings()
|
||||
settings.beginGroup(section)
|
||||
old_count = settings.value(u'%s count' % name, 0)
|
||||
new_count = len(list_to_save)
|
||||
settings.setValue(u'%s count' % name, new_count)
|
||||
for counter in range(new_count):
|
||||
settings.setValue(u'%s %d' % (name, counter), list_to_save[counter - 1])
|
||||
if old_count > new_count:
|
||||
# Tidy up any old list items
|
||||
for counter in range(new_count, old_count):
|
||||
settings.remove(u'%s %d' % (name, counter))
|
||||
settings.endGroup()
|
||||
|
||||
@staticmethod
|
||||
def load_list(section, name):
|
||||
"""
|
||||
Load a list from the config file.
|
||||
|
||||
``section``
|
||||
The section of the settings to load the list from.
|
||||
|
||||
``name``
|
||||
The name of the list.
|
||||
"""
|
||||
settings = Settings()
|
||||
settings.beginGroup(section)
|
||||
list_count = settings.value(u'%s count' % name, 0)
|
||||
loaded_list = []
|
||||
if list_count:
|
||||
for counter in range(list_count):
|
||||
item = settings.value(u'%s %d' % (name, counter), u'')
|
||||
if item:
|
||||
loaded_list.append(item)
|
||||
settings.endGroup()
|
||||
return loaded_list
|
||||
|
||||
@staticmethod
|
||||
def get_files(section=None, extension=None):
|
||||
"""
|
||||
|
@ -37,7 +37,8 @@ from openlp.plugins.images.lib import ImageMediaItem, ImageTab
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
__default_settings__ = {
|
||||
u'images/background color': u'#000000'
|
||||
u'images/background color': u'#000000',
|
||||
u'images/image files': []
|
||||
}
|
||||
|
||||
|
||||
|
@ -78,7 +78,7 @@ class ImageMediaItem(MediaManagerItem):
|
||||
self.listView.setIconSize(QtCore.QSize(88, 50))
|
||||
self.servicePath = os.path.join(AppLocation.get_section_data_path(self.settingsSection), u'thumbnails')
|
||||
check_directory_exists(self.servicePath)
|
||||
self.loadList(SettingsManager.load_list(self.settingsSection, u'images'), True)
|
||||
self.loadList(Settings().value(self.settingsSection + u'/image files'), True)
|
||||
|
||||
def addListViewToToolBar(self):
|
||||
MediaManagerItem.addListViewToToolBar(self)
|
||||
@ -107,7 +107,7 @@ class ImageMediaItem(MediaManagerItem):
|
||||
delete_file(os.path.join(self.servicePath, text.text()))
|
||||
self.listView.takeItem(row)
|
||||
self.plugin.formParent.incrementProgressBar()
|
||||
SettingsManager.set_list(self.settingsSection, u'images', self.getFileList())
|
||||
Settings().setValue(self.settingsSection + u'/image files', self.getFileList())
|
||||
self.plugin.formParent.finishedProgressBar()
|
||||
Receiver.send_message(u'cursor_normal')
|
||||
self.listView.blockSignals(False)
|
||||
@ -222,7 +222,7 @@ class ImageMediaItem(MediaManagerItem):
|
||||
'the image file "%s" no longer exists.') % filename)
|
||||
|
||||
def search(self, string, showError):
|
||||
files = SettingsManager.load_list(self.settingsSection, u'images')
|
||||
files = Settings().value(self.settingsSection + u'/image files')
|
||||
results = []
|
||||
string = string.lower()
|
||||
for file in files:
|
||||
|
@ -201,7 +201,7 @@ class MediaMediaItem(MediaManagerItem):
|
||||
def initialise(self):
|
||||
self.listView.clear()
|
||||
self.listView.setIconSize(QtCore.QSize(88, 50))
|
||||
self.loadList(SettingsManager.load_list(self.settingsSection, u'media'))
|
||||
self.loadList(Settings().value(self.settingsSection + u'/media files'))
|
||||
self.populateDisplayTypes()
|
||||
|
||||
def rebuild_players(self):
|
||||
@ -253,8 +253,7 @@ class MediaMediaItem(MediaManagerItem):
|
||||
row_list.sort(reverse=True)
|
||||
for row in row_list:
|
||||
self.listView.takeItem(row)
|
||||
SettingsManager.set_list(self.settingsSection,
|
||||
u'media', self.getFileList())
|
||||
Settings().setValue(self.settingsSection + u'/media files', self.getFileList())
|
||||
|
||||
def loadList(self, media):
|
||||
# Sort the media by its filename considering language specific
|
||||
@ -284,7 +283,7 @@ class MediaMediaItem(MediaManagerItem):
|
||||
self.listView.addItem(item_name)
|
||||
|
||||
def getList(self, type=MediaType.Audio):
|
||||
media = SettingsManager.load_list(self.settingsSection, u'media')
|
||||
media = Settings().value(self.settingsSection + u'/media files')
|
||||
media.sort(cmp=locale_compare, key=lambda filename: os.path.split(unicode(filename))[1])
|
||||
ext = []
|
||||
if type == MediaType.Audio:
|
||||
@ -296,7 +295,7 @@ class MediaMediaItem(MediaManagerItem):
|
||||
return media
|
||||
|
||||
def search(self, string, showError):
|
||||
files = SettingsManager.load_list(self.settingsSection, u'media')
|
||||
files = Settings().value(self.settingsSection + u'/media files')
|
||||
results = []
|
||||
string = string.lower()
|
||||
for file in files:
|
||||
|
@ -38,7 +38,8 @@ log = logging.getLogger(__name__)
|
||||
|
||||
# Some settings starting with "media" are in core, because they are needed for core functionality.
|
||||
__default_settings__ = {
|
||||
u'media/media auto start': QtCore.Qt.Unchecked
|
||||
u'media/media auto start': QtCore.Qt.Unchecked,
|
||||
u'media/media files': []
|
||||
}
|
||||
|
||||
|
||||
|
@ -120,7 +120,7 @@ class PresentationMediaItem(MediaManagerItem):
|
||||
Populate the media manager tab
|
||||
"""
|
||||
self.listView.setIconSize(QtCore.QSize(88, 50))
|
||||
files = SettingsManager.load_list(self.settingsSection, u'presentations')
|
||||
files = Settings().value(self.settingsSection + u'/presentation files')
|
||||
self.loadList(files, True)
|
||||
self.populateDisplayTypes()
|
||||
|
||||
@ -232,7 +232,7 @@ class PresentationMediaItem(MediaManagerItem):
|
||||
Receiver.send_message(u'cursor_normal')
|
||||
for row in row_list:
|
||||
self.listView.takeItem(row)
|
||||
SettingsManager.set_list(self.settingsSection, u'presentations', self.getFileList())
|
||||
Settings().setValue(self.settingsSection + u'/presentation files', self.getFileList())
|
||||
|
||||
def generateSlideData(self, service_item, item=None, xmlVersion=False,
|
||||
remote=False, context=ServiceItemContext.Service):
|
||||
@ -311,8 +311,7 @@ class PresentationMediaItem(MediaManagerItem):
|
||||
return None
|
||||
|
||||
def search(self, string, showError):
|
||||
files = SettingsManager.load_list(
|
||||
self.settingsSection, u'presentations')
|
||||
files = Settings().value(self.settingsSection + u'/presentation files')
|
||||
results = []
|
||||
string = string.lower()
|
||||
for file in files:
|
||||
|
@ -46,7 +46,8 @@ __default_settings__ = {
|
||||
u'presentations/override app': QtCore.Qt.Unchecked,
|
||||
u'presentations/Impress': QtCore.Qt.Checked,
|
||||
u'presentations/Powerpoint': QtCore.Qt.Checked,
|
||||
u'presentations/Powerpoint Viewer': QtCore.Qt.Checked
|
||||
u'presentations/Powerpoint Viewer': QtCore.Qt.Checked,
|
||||
u'presentations/presentation files': []
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user