From 881cb4e3c3d7efc907d524d965b2ef74dc96577a Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sun, 3 Oct 2010 23:28:47 +0100 Subject: [PATCH 1/6] Added file extension checking to words of worship import Added the ability for importers to specifiy file fillters, and added the relevent filters for most importers (the ones where I could easily find the file ext, still need easiworship and song beamer, and maybe a few others!) --- openlp/plugins/songs/forms/songimportform.py | 49 ++++++++++++++++---- openlp/plugins/songs/lib/wowimport.py | 4 ++ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index ef655a12a..759922415 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -248,18 +248,24 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard): # Progress page return True - def getFileName(self, title, editbox): + def getFileName(self, title, editbox, + filters = '%s (*)' % translate('SongsPlugin.ImportWizardForm', + 'All Files')): filename = QtGui.QFileDialog.getOpenFileName(self, title, - SettingsManager.get_last_dir(self.plugin.settingsSection, 1)) + SettingsManager.get_last_dir(self.plugin.settingsSection, 1), + filters) if filename: editbox.setText(filename) SettingsManager.set_last_dir( self.plugin.settingsSection, os.path.split(unicode(filename))[0], 1) - def getFiles(self, title, listbox): + def getFiles(self, title, listbox, + filters = '%s (*)' % translate('SongsPlugin.ImportWizardForm', + 'All Files')): filenames = QtGui.QFileDialog.getOpenFileNames(self, title, - SettingsManager.get_last_dir(self.plugin.settingsSection, 1)) + SettingsManager.get_last_dir(self.plugin.settingsSection, 1), + filters) if filenames: listbox.addItems(filenames) SettingsManager.set_last_dir( @@ -281,14 +287,24 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard): self.getFileName( translate('SongsPlugin.ImportWizardForm', 'Select OpenLP 2.0 Database File'), - self.openLP2FilenameEdit + self.openLP2FilenameEdit, + '%s (*.sqlite);;%s (*)' + % (translate('SongsPlugin.ImportWizardForm', + 'OpenLP 2.0 Databases'), + translate('SongsPlugin.ImportWizardForm', + 'All Files')) ) def onOpenLP1BrowseButtonClicked(self): self.getFileName( translate('SongsPlugin.ImportWizardForm', 'Select openlp.org 1.x Database File'), - self.openLP1FilenameEdit + self.openLP1FilenameEdit, + '%s (*.olp);;%s (*)' + % (translate('SongsPlugin.ImportWizardForm', + 'openlp.org v1.x Databases'), + translate('SongsPlugin.ImportWizardForm', + 'All Files')) ) #def onOpenLyricsAddButtonClicked(self): @@ -305,7 +321,12 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard): self.getFiles( translate('SongsPlugin.ImportWizardForm', 'Select Open Song Files'), - self.openSongFileListWidget + self.openSongFileListWidget, + '%s (*.html);;%s (*)' + % (translate('SongsPlugin.ImportWizardForm', + 'OpenSong html Files'), + translate('SongsPlugin.ImportWizardForm', + 'All Files')) ) def onOpenSongRemoveButtonClicked(self): @@ -315,7 +336,12 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard): self.getFiles( translate('SongsPlugin.ImportWizardForm', 'Select Words of Worship Files'), - self.wordsOfWorshipFileListWidget + self.wordsOfWorshipFileListWidget, + '%s (*.wsg *.wow-song);;%s (*)' + % (translate('SongsPlugin.ImportWizardForm', + 'Words Of Worship Song Files'), + translate('SongsPlugin.ImportWizardForm', + 'All Files')) ) def onWordsOfWorshipRemoveButtonClicked(self): @@ -335,7 +361,12 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard): self.getFiles( translate('SongsPlugin.ImportWizardForm', 'Select Songs of Fellowship Files'), - self.songsOfFellowshipFileListWidget + self.songsOfFellowshipFileListWidget, + '%s (*.rtf);;%s (*)' + % (translate('SongsPlugin.ImportWizardForm', + 'Songs Of Felloship Song Files'), + translate('SongsPlugin.ImportWizardForm', + 'All Files')) ) def onSongsOfFellowshipRemoveButtonClicked(self): diff --git a/openlp/plugins/songs/lib/wowimport.py b/openlp/plugins/songs/lib/wowimport.py index 474a9b19d..2b7a3ea54 100644 --- a/openlp/plugins/songs/lib/wowimport.py +++ b/openlp/plugins/songs/lib/wowimport.py @@ -118,6 +118,10 @@ class WowImport(SongImport): for file in self.import_source: # TODO: check that it is a valid words of worship file (could # check header for WoW File Song Word) + os.path.splitext( file ) + self.ext = os.path.splitext(file)[1] + if self.ext != u'.wsg' and self.ext != u'.wow-song': + continue self.author = u'' self.copyright = u'' # Get the song title From e81efb84f6148c717b73e6a9052fc04447b52699 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Tue, 5 Oct 2010 20:41:54 +0100 Subject: [PATCH 2/6] Removed extension checking in wow import as this is handled by the filters in the open dialouge box. Instead, check the the header to ensure that the file is a wow song file regardless of ext. Corrected open song import extension. --- openlp/plugins/songs/forms/songimportform.py | 2 +- openlp/plugins/songs/lib/wowimport.py | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index 759922415..5362adc9a 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -322,7 +322,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard): translate('SongsPlugin.ImportWizardForm', 'Select Open Song Files'), self.openSongFileListWidget, - '%s (*.html);;%s (*)' + '%s (*.xml);;%s (*)' % (translate('SongsPlugin.ImportWizardForm', 'OpenSong html Files'), translate('SongsPlugin.ImportWizardForm', diff --git a/openlp/plugins/songs/lib/wowimport.py b/openlp/plugins/songs/lib/wowimport.py index 2b7a3ea54..879d56704 100644 --- a/openlp/plugins/songs/lib/wowimport.py +++ b/openlp/plugins/songs/lib/wowimport.py @@ -116,20 +116,16 @@ class WowImport(SongImport): self.import_wizard.importProgressBar.setMaximum( len(self.import_source)) for file in self.import_source: - # TODO: check that it is a valid words of worship file (could - # check header for WoW File Song Word) - os.path.splitext( file ) - self.ext = os.path.splitext(file)[1] - if self.ext != u'.wsg' and self.ext != u'.wow-song': - continue self.author = u'' self.copyright = u'' - # Get the song title self.file_name = os.path.split(file)[1] self.import_wizard.incrementProgressBar( "Importing %s" % (self.file_name), 0) + # Get the song title self.title = self.file_name.rpartition(u'.')[0] self.songData = open(file, 'rb') + if self.songData.read(19) != u'WoW File\nSong Words': + continue # Seek to byte which stores number of blocks in the song self.songData.seek(56) self.no_of_blocks = ord(self.songData.read(1)) From 40d06d492b5feea5eaa7778e7eddd8c1c15a42a8 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Tue, 5 Oct 2010 20:47:35 +0100 Subject: [PATCH 3/6] and added some u's before "'"'s --- openlp/plugins/songs/forms/songimportform.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index 5362adc9a..a1cea345f 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -261,7 +261,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard): os.path.split(unicode(filename))[0], 1) def getFiles(self, title, listbox, - filters = '%s (*)' % translate('SongsPlugin.ImportWizardForm', + filters = u'%s (*)' % translate('SongsPlugin.ImportWizardForm', 'All Files')): filenames = QtGui.QFileDialog.getOpenFileNames(self, title, SettingsManager.get_last_dir(self.plugin.settingsSection, 1), @@ -288,7 +288,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard): translate('SongsPlugin.ImportWizardForm', 'Select OpenLP 2.0 Database File'), self.openLP2FilenameEdit, - '%s (*.sqlite);;%s (*)' + u'%s (*.sqlite);;%s (*)' % (translate('SongsPlugin.ImportWizardForm', 'OpenLP 2.0 Databases'), translate('SongsPlugin.ImportWizardForm', @@ -300,7 +300,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard): translate('SongsPlugin.ImportWizardForm', 'Select openlp.org 1.x Database File'), self.openLP1FilenameEdit, - '%s (*.olp);;%s (*)' + u'%s (*.olp);;%s (*)' % (translate('SongsPlugin.ImportWizardForm', 'openlp.org v1.x Databases'), translate('SongsPlugin.ImportWizardForm', @@ -322,7 +322,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard): translate('SongsPlugin.ImportWizardForm', 'Select Open Song Files'), self.openSongFileListWidget, - '%s (*.xml);;%s (*)' + u'%s (*.xml);;%s (*)' % (translate('SongsPlugin.ImportWizardForm', 'OpenSong html Files'), translate('SongsPlugin.ImportWizardForm', @@ -337,7 +337,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard): translate('SongsPlugin.ImportWizardForm', 'Select Words of Worship Files'), self.wordsOfWorshipFileListWidget, - '%s (*.wsg *.wow-song);;%s (*)' + u'%s (*.wsg *.wow-song);;%s (*)' % (translate('SongsPlugin.ImportWizardForm', 'Words Of Worship Song Files'), translate('SongsPlugin.ImportWizardForm', @@ -362,7 +362,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard): translate('SongsPlugin.ImportWizardForm', 'Select Songs of Fellowship Files'), self.songsOfFellowshipFileListWidget, - '%s (*.rtf);;%s (*)' + u'%s (*.rtf);;%s (*)' % (translate('SongsPlugin.ImportWizardForm', 'Songs Of Felloship Song Files'), translate('SongsPlugin.ImportWizardForm', From 274b3b92539e1df1e96551dc06475a0a35831d21 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Tue, 5 Oct 2010 22:32:03 +0100 Subject: [PATCH 4/6] Removed the xml filter for OpenSong --- openlp/plugins/songs/forms/songimportform.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index a1cea345f..3e5b41e46 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -321,12 +321,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard): self.getFiles( translate('SongsPlugin.ImportWizardForm', 'Select Open Song Files'), - self.openSongFileListWidget, - u'%s (*.xml);;%s (*)' - % (translate('SongsPlugin.ImportWizardForm', - 'OpenSong html Files'), - translate('SongsPlugin.ImportWizardForm', - 'All Files')) + self.openSongFileListWidget ) def onOpenSongRemoveButtonClicked(self): From 75d35cf182a9919bdbfd8897293fa8f3b5ecf61f Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 7 Oct 2010 18:52:40 +0100 Subject: [PATCH 5/6] Fix duplicate file saving bug Fix drag and drop service item bug Fixes: https://launchpad.net/bugs/656177 --- openlp/core/lib/mediamanageritem.py | 2 +- openlp/core/lib/plugin.py | 4 ++-- openlp/core/lib/serviceitem.py | 2 +- openlp/core/ui/servicemanager.py | 6 +++++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 457249b35..3752ffc4d 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -96,7 +96,7 @@ class MediaManagerItem(QtGui.QWidget): #TODO: plugin should not be the parent in future self.plugin = parent # plugin visible_title = self.plugin.getString(StringContent.VisibleName) - self.title = visible_title[u'title'] + self.title = unicode(visible_title[u'title']) self.settingsSection = self.plugin.name.lower() if isinstance(icon, QtGui.QIcon): self.icon = icon diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 3fda09676..37ac3d74a 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -303,7 +303,7 @@ class Plugin(QtCore.QObject): The new name the plugin should now use. """ pass - + def getString(self, name): """ encapsulate access of plugins translated text strings @@ -314,4 +314,4 @@ class Plugin(QtCore.QObject): """ Called to define all translatable texts of the plugin """ - pass \ No newline at end of file + pass diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index b4dc263e9..663328d95 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -101,9 +101,9 @@ class ServiceItem(object): self.main = None self.footer = None self.bg_image_bytes = None - self._new_item() self.search_string = u'' self.data_string = u'' + self._new_item() def _new_item(self): """ diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index d751b76be..1fb276a25 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -602,6 +602,7 @@ class ServiceManager(QtGui.QWidget): zip = None file = None try: + write_list = [] zip = zipfile.ZipFile(unicode(filename), 'w') for item in self.serviceItems: service.append({u'serviceitem':item[u'service_item'] @@ -611,7 +612,10 @@ class ServiceManager(QtGui.QWidget): path_from = unicode(os.path.join( frame[u'path'], frame[u'title'])) - zip.write(path_from.encode(u'utf-8')) + # On write a file once + if not path_from in write_list: + write_list.append(path_from) + zip.write(path_from.encode(u'utf-8')) file = open(servicefile, u'wb') cPickle.dump(service, file) file.close() From fd45f2e32dc6bcd4de23492b8d4355bd35a05b5d Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 8 Oct 2010 20:32:07 +0100 Subject: [PATCH 6/6] Add config option for Expanding service items --- openlp/core/ui/advancedtab.py | 10 ++++++ openlp/core/ui/servicemanager.py | 58 ++++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index 0a12c54e5..f31e4c0ff 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -82,6 +82,9 @@ class AdvancedTab(SettingsTab): self.doubleClickLiveCheckBox.setObjectName(u'doubleClickLiveCheckBox') self.uiLayout.addWidget(self.doubleClickLiveCheckBox) self.leftLayout.addWidget(self.uiGroupBox) + self.expandServiceItemCheckBox = QtGui.QCheckBox(self.uiGroupBox) + self.expandServiceItemCheckBox.setObjectName(u'expandServiceItemCheckBox') + self.uiLayout.addWidget(self.expandServiceItemCheckBox) # self.sharedDirGroupBox = QtGui.QGroupBox(self.leftWidget) # self.sharedDirGroupBox.setObjectName(u'sharedDirGroupBox') # self.sharedDirGroupBox.setGeometry(QtCore.QRect(0, 65, 500, 85)) @@ -140,6 +143,8 @@ class AdvancedTab(SettingsTab): 'Remember active media manager tab on startup')) self.doubleClickLiveCheckBox.setText(translate('OpenLP.AdvancedTab', 'Double-click to send items straight to live (requires restart)')) + self.expandServiceItemCheckBox.setText(translate('OpenLP.AdvancedTab', + 'Expand new service items on creation')) # self.sharedDirGroupBox.setTitle( # translate('AdvancedTab', 'Central Data Store')) # self.sharedCheckBox.setText( @@ -167,6 +172,9 @@ class AdvancedTab(SettingsTab): self.doubleClickLiveCheckBox.setChecked( settings.value(u'double click live', QtCore.QVariant(False)).toBool()) + self.expandServiceItemCheckBox.setChecked( + settings.value(u'expand service item', + QtCore.QVariant(False)).toBool()) settings.endGroup() def save(self): @@ -181,6 +189,8 @@ class AdvancedTab(SettingsTab): QtCore.QVariant(self.mediaPluginCheckBox.isChecked())) settings.setValue(u'double click live', QtCore.QVariant(self.doubleClickLiveCheckBox.isChecked())) + settings.setValue(u'expand service item', + QtCore.QVariant(self.expandServiceItemCheckBox.isChecked())) settings.endGroup() def onSharedCheckBoxChanged(self, checked): diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 1fb276a25..b1140eb49 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -107,6 +107,7 @@ class ServiceManager(QtGui.QWidget): self.serviceName = u'' self.suffixes = [] self.droppos = 0 + self.expandTabs = False #is a new service and has not been saved self.isNew = True self.serviceNoteForm = ServiceNoteForm(self.parent) @@ -199,6 +200,19 @@ class ServiceManager(QtGui.QWidget): translate('OpenLP.ServiceManager', 'Delete the selected item from the service.'), self.onDeleteFromService) + self.orderToolbar.addSeparator() + self.orderToolbar.addToolbarButton( + translate('OpenLP.ServiceManager', '&Expand all'), + u':/services/service_top.png', + translate('OpenLP.ServiceManager', + 'Expand all the service items.'), + self.onExpandAll) + self.orderToolbar.addToolbarButton( + translate('OpenLP.ServiceManager', '&Collapse all'), + u':/services/service_bottom.png', + translate('OpenLP.ServiceManager', + 'Collapse all the service items.'), + self.onCollapseAll) self.layout.addWidget(self.orderToolbar) # Connect up our signals and slots QtCore.QObject.connect(self.themeComboBox, @@ -220,7 +234,7 @@ class ServiceManager(QtGui.QWidget): QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'servicemanager_list_request'), self.listRequest) QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'config_updated'), self.regenerateServiceItems) + QtCore.SIGNAL(u'config_updated'), self.configUpdated) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'theme_update_global'), self.themeChange) QtCore.QObject.connect(Receiver.get_receiver(), @@ -265,6 +279,17 @@ class ServiceManager(QtGui.QWidget): self.themeMenu = QtGui.QMenu( translate('OpenLP.ServiceManager', '&Change Item Theme')) self.menu.addMenu(self.themeMenu) + self.configUpdated(True) + + def configUpdated(self, firstTime=False): + """ + Triggered when Config dialog is updated. + """ + self.expandTabs = QtCore.QSettings().value( + u'advanced/expand service item', + QtCore.QVariant(u'False')).toBool() + if not firstTime: + self.regenerateServiceItems() def supportedSuffixes(self, suffix): self.suffixes.append(suffix) @@ -321,7 +346,7 @@ class ServiceManager(QtGui.QWidget): self.serviceItems[item][u'service_item']) if self.serviceItemEditForm.exec_(): self.addServiceItem(self.serviceItemEditForm.getServiceItem(), - replace=True) + replace=True, expand=self.serviceItems[item][u'expand']) def nextItem(self): """ @@ -423,6 +448,14 @@ class ServiceManager(QtGui.QWidget): if setSelected: firstItem.setSelected(True) + def onCollapseAll(self): + """ + Collapse all the service items + """ + for item in self.serviceItems: + item[u'expanded'] = False + self.regenerateServiceItems() + def collapsed(self, item): """ Record if an item is collapsed @@ -431,6 +464,14 @@ class ServiceManager(QtGui.QWidget): pos = item.data(0, QtCore.Qt.UserRole).toInt()[0] self.serviceItems[pos -1 ][u'expanded'] = False + def onExpandAll(self): + """ + Collapse all the service items + """ + for item in self.serviceItems: + item[u'expanded'] = True + self.regenerateServiceItems() + def expanded(self, item): """ Record if an item is collapsed @@ -528,12 +569,12 @@ class ServiceManager(QtGui.QWidget): Used when moving items as the move takes place in supporting array, and when regenerating all the items due to theme changes """ - #Correct order of items in array + # Correct order of items in array count = 1 for item in self.serviceItems: item[u'order'] = count count += 1 - #Repaint the screen + # Repaint the screen self.serviceManagerList.clear() for itemcount, item in enumerate(self.serviceItems): serviceitem = item[u'service_item'] @@ -805,7 +846,7 @@ class ServiceManager(QtGui.QWidget): self.isNew = True for item in tempServiceItems: self.addServiceItem( - item[u'service_item'], False, item[u'expanded']) + item[u'service_item'], False, expand=item[u'expanded']) # Set to False as items may have changed rendering # does not impact the saved song so True may also be valid self.parent.serviceChanged(False, self.serviceName) @@ -834,14 +875,19 @@ class ServiceManager(QtGui.QWidget): self.parent.LiveController.replaceServiceManagerItem(newItem) self.parent.serviceChanged(False, self.serviceName) - def addServiceItem(self, item, rebuild=False, expand=False, replace=False): + def addServiceItem(self, item, rebuild=False, expand=None, replace=False): """ Add a Service item to the list ``item`` Service Item to be added + + ``expand`` + Override the default expand settings. (Tristate) """ log.debug(u'addServiceItem') + if expand == None: + expand = self.expandTabs sitem = self.findServiceItem()[0] item.render() if replace: