diff --git a/openlp/plugins/songs/forms/songexportform.py b/openlp/plugins/songs/forms/songexportform.py index 21adcc93f..94abf54c8 100644 --- a/openlp/plugins/songs/forms/songexportform.py +++ b/openlp/plugins/songs/forms/songexportform.py @@ -24,7 +24,8 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ -The song export function for OpenLP. +The :mod:`songexportform` module provides the wizard for exporting songs to the +OpenLyrics format. """ import logging @@ -40,8 +41,8 @@ log = logging.getLogger(__name__) class SongExportForm(OpenLPWizard): """ - This is the Song Export Wizard, which allows easy exporting of Songs to - OpenLyrics. + This is the Song Export Wizard, which allows easy exporting of Songs to the + OpenLyrics format. """ log.info(u'SongExportForm loaded') @@ -57,7 +58,7 @@ class SongExportForm(OpenLPWizard): """ self.plugin = plugin OpenLPWizard.__init__(self, parent, plugin, u'songExportWizard', - u':/wizards/wizard_importsong.bmp') + u':/wizards/wizard_exportsong.bmp') self.stop_export_flag = False QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_export) @@ -85,9 +86,9 @@ class SongExportForm(OpenLPWizard): """ Song wizard specific signals. """ - QtCore.QObject.connect(self.addSelected, + QtCore.QObject.connect(self.addButton, QtCore.SIGNAL(u'clicked()'), self.onAddSelectedClicked) - QtCore.QObject.connect(self.removeSelected, + QtCore.QObject.connect(self.removeButton, QtCore.SIGNAL(u'clicked()'), self.onRemoveSelectedClicked) QtCore.QObject.connect(self.availableListWidget, QtCore.SIGNAL(u'itemDoubleClicked(QListWidgetItem *)'), @@ -95,6 +96,12 @@ class SongExportForm(OpenLPWizard): QtCore.QObject.connect(self.selectedListWidget, QtCore.SIGNAL(u'itemDoubleClicked(QListWidgetItem *)'), self.onSelectedListItemDoubleClicked) + QtCore.QObject.connect(self.directoryButton, + QtCore.SIGNAL(u'clicked()'), self.onDirectoryButtonClicked) + QtCore.QObject.connect(self.allAvailableButton, + QtCore.SIGNAL(u'clicked()'), self.onAllAvailableButtonClicked) + QtCore.QObject.connect(self.allSelectedButton, + QtCore.SIGNAL(u'clicked()'), self.onAllSelectedButtonClicked) def addCustomPages(self): """ @@ -103,82 +110,83 @@ class SongExportForm(OpenLPWizard): # Source Page self.sourcePage = QtGui.QWizardPage() self.sourcePage.setObjectName(u'sourcePage') - self.sourceLayout = QtGui.QHBoxLayout(self.sourcePage) - self.sourceLayout.setObjectName(u'sourceLayout') - self.availableGroupBox = QtGui.QGroupBox(self.sourcePage) - self.availableGroupBox.setObjectName(u'availableGroupBox') - self.verticalLayout = QtGui.QVBoxLayout(self.availableGroupBox) + self.horizontalLayout = QtGui.QHBoxLayout(self.sourcePage) + self.horizontalLayout.setObjectName(u'horizontalLayout') + self.verticalLayout = QtGui.QVBoxLayout() self.verticalLayout.setObjectName(u'verticalLayout') - self.verticalLayout.setContentsMargins(0, -1, 0, 0) - self.availableListWidget = QtGui.QListWidget(self.availableGroupBox) - self.availableListWidget.setObjectName(u'availableListWidget') - self.availableListWidget.setSelectionMode( - QtGui.QAbstractItemView.ExtendedSelection) - self.availableListWidget.setSizePolicy( - QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) - self.availableListWidget.setSortingEnabled(True) - self.verticalLayout.addWidget(self.availableListWidget) - self.sourceLayout.addWidget(self.availableGroupBox) - self.selectionWidget = QtGui.QWidget(self.sourcePage) - self.selectionWidget.setObjectName(u'selectionWidget') - self.selectionLayout = QtGui.QVBoxLayout(self.selectionWidget) - self.selectionLayout.setSpacing(0) - self.selectionLayout.setMargin(0) - self.selectionLayout.setObjectName(u'selectionLayout') - spacerItem = QtGui.QSpacerItem(20, 0, - QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.MinimumExpanding) - self.selectionLayout.addItem(spacerItem) - self.addSelected = QtGui.QToolButton(self.selectionWidget) - icon = QtGui.QIcon() - icon.addPixmap(QtGui.QPixmap( - u':/exports/export_move_to_list.png'), - QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.addSelected.setIcon(icon) - self.addSelected.setIconSize(QtCore.QSize(20, 20)) - self.addSelected.setObjectName(u'addSelected') - self.selectionLayout.addWidget(self.addSelected) - self.removeSelected = QtGui.QToolButton(self.selectionWidget) - icon = QtGui.QIcon() - icon.addPixmap(QtGui.QPixmap( - u':/exports/export_remove.png'), - QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.removeSelected.setIcon(icon) - self.removeSelected.setIconSize(QtCore.QSize(20, 20)) - self.removeSelected.setObjectName(u'removeSelected') - self.selectionLayout.addWidget(self.removeSelected) - spacerItem = QtGui.QSpacerItem(20, 0, - QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.MinimumExpanding) - self.selectionLayout.addItem(spacerItem) - self.sourceLayout.addWidget(self.selectionWidget) - self.selectedGroupBox = QtGui.QGroupBox(self.sourcePage) - self.selectedGroupBox.setObjectName(u'selectedGroupBox') - self.verticalLayout = QtGui.QVBoxLayout(self.selectedGroupBox) - self.verticalLayout.setObjectName(u'verticalLayout') - self.verticalLayout.setContentsMargins(0, -1, 0, 0) - self.selectedListWidget = QtGui.QListWidget(self.selectedGroupBox) + self.gridLayout = QtGui.QGridLayout() + self.gridLayout.setObjectName(u'gridLayout') + self.selectedListWidget = QtGui.QListWidget(self.sourcePage) self.selectedListWidget.setObjectName(u'selectedListWidget') self.selectedListWidget.setSelectionMode( QtGui.QAbstractItemView.ExtendedSelection) - self.selectedListWidget.setSizePolicy( - QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.selectedListWidget.setSortingEnabled(True) - self.verticalLayout.addWidget(self.selectedListWidget) - self.sourceLayout.addWidget(self.selectedGroupBox) - # - self.horizontalLayout = QtGui.QHBoxLayout() - self.horizontalLayout.setObjectName(u'horizontalLayout') - self.pathLabel = QtGui.QLabel() - self.pathLabel.setObjectName(u'pathLabel') - self.horizontalLayout.addWidget(self.pathLabel) - self.pathEdit = QtGui.QLineEdit() - self.pathEdit.setObjectName(u'pathEdit') - self.horizontalLayout.addWidget(self.pathEdit) - self.browseButton = QtGui.QToolButton() - self.browseButton.setObjectName(u'browseButton') - self.horizontalLayout.addWidget(self.browseButton) - # + self.gridLayout.addWidget(self.selectedListWidget, 1, 2, 1, 1) + self.gridLayout2 = QtGui.QGridLayout() + self.gridLayout2.setObjectName(u'gridLayout2') + self.addButton = QtGui.QToolButton(self.sourcePage) + icon = QtGui.QIcon() + icon.addPixmap(QtGui.QPixmap(u':/exports/export_move_to_list.png'), + QtGui.QIcon.Normal, QtGui.QIcon.Off) + self.addButton.setIcon(icon) + self.addButton.setObjectName(u'addButton') + self.gridLayout2.addWidget(self.addButton, 1, 0, 1, 1) + self.removeButton = QtGui.QToolButton(self.sourcePage) + icon = QtGui.QIcon() + icon.addPixmap(QtGui.QPixmap(u':/exports/export_remove.png'), + QtGui.QIcon.Normal, QtGui.QIcon.Off) + self.removeButton.setIcon(icon) + self.removeButton.setObjectName(u'removeButton') + self.gridLayout2.addWidget(self.removeButton, 2, 0, 1, 1) + spacerItem = QtGui.QSpacerItem(20, 40, + QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) + self.gridLayout2.addItem(spacerItem, 0, 0, 1, 1) + self.gridLayout2.addItem(spacerItem, 3, 0, 1, 1) + self.gridLayout.addLayout(self.gridLayout2, 1, 1, 1, 1) + self.availableLabel = QtGui.QLabel(self.sourcePage) + self.availableLabel.setObjectName(u'availableLabel') + self.gridLayout.addWidget(self.availableLabel, 0, 0, 1, 1) + self.selectedLabel = QtGui.QLabel(self.sourcePage) + self.selectedLabel.setObjectName(u'selectedLabel') + self.gridLayout.addWidget(self.selectedLabel, 0, 2, 1, 1) + self.availableListWidget = QtGui.QListWidget(self.sourcePage) + self.availableListWidget.setObjectName(u'availableListWidget') + self.availableListWidget.setSelectionMode( + QtGui.QAbstractItemView.ExtendedSelection) + self.availableListWidget.setSortingEnabled(True) + self.gridLayout.addWidget(self.availableListWidget, 1, 0, 1, 1) + # Button to select all songs in the "selectedListWidget". + self.allSelectedButton = QtGui.QToolButton(self.sourcePage) +# sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) +# sizePolicy.setHorizontalStretch(0) +# sizePolicy.setVerticalStretch(0) +# sizePolicy.setHeightForWidth(self.allSelectedButton.sizePolicy().hasHeightForWidth()) +# self.allSelectedButton.setSizePolicy(sizePolicy) + self.allSelectedButton.setObjectName(u'allSelectedButton') + self.gridLayout.addWidget(self.allSelectedButton, 3, 2, 1, 1) + # Button to select all songs in the "availableListWidget". + self.allAvailableButton = QtGui.QToolButton(self.sourcePage) + self.allAvailableButton.setObjectName(u'allAvailableButton') + self.gridLayout.addWidget(self.allAvailableButton, 3, 0, 1, 1) + self.verticalLayout.addLayout(self.gridLayout) + self.gridLayout3 = QtGui.QGridLayout() + self.gridLayout3.setObjectName(u'gridLayout3') + self.directoryButton = QtGui.QToolButton(self.sourcePage) + icon = QtGui.QIcon() + icon.addPixmap(QtGui.QPixmap(u':/exports/export_load.png'), + QtGui.QIcon.Normal, QtGui.QIcon.Off) + self.directoryButton.setIcon(icon) + self.directoryButton.setObjectName(u'directoryButton') + self.gridLayout3.addWidget(self.directoryButton, 0, 2, 1, 1) + self.directoryLineEdit = QtGui.QLineEdit(self.sourcePage) + self.directoryLineEdit.setObjectName(u'directoryLineEdit') + self.gridLayout3.addWidget(self.directoryLineEdit, 0, 1, 1, 1) + self.directoryLabel = QtGui.QLabel(self.sourcePage) + self.directoryLabel.setObjectName(u'directoryLabel') + self.gridLayout3.addWidget(self.directoryLabel, 0, 0, 1, 1) + self.verticalLayout.addLayout(self.gridLayout3) + self.horizontalLayout.addLayout(self.verticalLayout) self.addPage(self.sourcePage) - #TODO: Add save dialog and maybe a search box. def retranslateUi(self): """ @@ -193,13 +201,13 @@ class SongExportForm(OpenLPWizard): self.informationLabel.setText( translate('SongsPlugin.ExportWizardForm', 'This wizard will help to ' 'export your songs to the open and free OpenLyrics worship song ' - 'format. You can import these songs in all lyrics projection ' - 'software, which supports OpenLyrics.')) + 'format.')) self.sourcePage.setTitle( translate('SongsPlugin.ExportWizardForm', 'Select Songs')) self.sourcePage.setSubTitle( translate('SongsPlugin.ExportWizardForm', - 'Select the songs, you want to export.')) + 'Add the songs, you want to export to the list on the right hand ' + 'side. You can use the buttons below or double click them.')) self.progressPage.setTitle( translate('SongsPlugin.ExportWizardForm', 'Exporting')) @@ -211,37 +219,38 @@ class SongExportForm(OpenLPWizard): self.progressBar.setFormat( translate('SongsPlugin.ExportWizardForm', '%p%')) - self.availableGroupBox.setTitle( - translate('SongsPlugin.ExportWizardForm', 'Available Songs')) - self.selectedGroupBox.setTitle( - translate('SongsPlugin.ExportWizardForm', 'Selected Songs')) + self.directoryLabel.setText(translate('SongsPlugin.ExportWizardForm', + 'Directory:')) + self.availableLabel.setText( + translate('SongsPlugin.ExportWizardForm', 'Available Songs')) + self.selectedLabel.setText( + translate('SongsPlugin.ExportWizardForm', 'Selected Songs')) + self.allSelectedButton.setText( + translate('SongsPlugin.ExportWizardForm', 'Select all')) + self.allAvailableButton.setText( + translate('SongsPlugin.ExportWizardForm', 'Select all')) def validateCurrentPage(self): """ Validate the current page before moving on to the next page. """ if self.currentPage() == self.welcomePage: - Receiver.send_message(u'cursor_busy') - songs = self.plugin.manager.get_all_objects(Song) - for song in songs: - authors = u', '.join([author.display_name - for author in song.authors]) - song_detail = u'%s (%s)' % (unicode(song.title), authors) - song_name = QtGui.QListWidgetItem(song_detail) - song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song)) - self.availableListWidget.addItem(song_name) - self.availableListWidget.selectAll() - Receiver.send_message(u'cursor_normal') return True elif self.currentPage() == self.sourcePage: - self.selectedListWidget.selectAll() - if not self.selectedListWidget.selectedItems(): + if not self.selectedListWidget.count(): criticalErrorMessageBox( translate('SongsPlugin.ExportWizardForm', 'No Song Selected'), - translate('SongsPlugin.ImportWizardForm', + translate('SongsPlugin.ExportWizardForm', 'You need to add at least one Song to export.')) return False + elif not self.directoryLineEdit.text(): + criticalErrorMessageBox( + translate('SongsPlugin.ExportWizardForm', + 'No Save Location specified'), + translate('SongsPlugin.ExportWizardForm', + 'You need to specified a directory to save the songs in.')) + return False return True elif self.currentPage() == self.progressPage: self.availableListWidget.clear() @@ -261,10 +270,25 @@ class SongExportForm(OpenLPWizard): self.restart() self.finishButton.setVisible(False) self.cancelButton.setVisible(True) + self.availableListWidget.clear() + self.selectedListWidget.clear() + self.directoryLineEdit.clear() + # Load the list of songs. + Receiver.send_message(u'cursor_busy') + songs = self.plugin.manager.get_all_objects(Song) + for song in songs: + authors = u', '.join([author.display_name + for author in song.authors]) + song_detail = u'%s (%s)' % (unicode(song.title), authors) + song_name = QtGui.QListWidgetItem(song_detail) + song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song)) + self.availableListWidget.addItem(song_name) + self.availableListWidget.selectAll() + Receiver.send_message(u'cursor_normal') def preWizard(self): """ - Perform pre export tasks + Perform pre export tasks. """ OpenLPWizard.preWizard(self) self.progressLabel.setText( @@ -273,18 +297,14 @@ class SongExportForm(OpenLPWizard): def performWizard(self): """ - Perform the actual export. This method pulls in the correct exporter - class, and then runs the ``do_export`` method of the exporter to do - the actual exporting. + Perform the actual export. This creates an *openlyricsexport* instance + and calls the *do_export* method. """ - path = unicode(QtGui.QFileDialog.getExistingDirectory(self, translate( - 'SongsPlugin.ExportWizardForm', 'Selecte to Folder'), - SettingsManager.get_last_dir(self.plugin.settingsSection, 1), - options=QtGui.QFileDialog.ShowDirsOnly)) - SettingsManager.set_last_dir(self.plugin.settingsSection, path, 1) + self.selectedListWidget.selectAll() songs = [item.data(QtCore.Qt.UserRole).toPyObject() for item in self.selectedListWidget.selectedItems()] - exporter = OpenLyricsExport(self, songs, path) + exporter = OpenLyricsExport( + self, songs, unicode(self.directoryLineEdit.text())) if exporter.do_export(): self.progressLabel.setText( translate('SongsPlugin.SongExportForm', 'Finished export.')) @@ -340,3 +360,27 @@ class SongExportForm(OpenLPWizard): """ self.selectedListWidget.takeItem(self.selectedListWidget.row(item)) self.availableListWidget.addItem(item) + + def onAllAvailableButtonClicked(self): + """ + Selects all songs in the *availableListWidget*. + """ + self.availableListWidget.selectAll() + + def onDirectoryButtonClicked(self): + """ + Called when click on the *directoryButton*. Opens a dialog and writes + the path to *directoryLineEdit*. + """ + path = unicode(QtGui.QFileDialog.getExistingDirectory(self, + translate('SongsPlugin.ExportWizardForm', 'Selecte to Folder'), + SettingsManager.get_last_dir(self.plugin.settingsSection, 1), + options=QtGui.QFileDialog.ShowDirsOnly)) + SettingsManager.set_last_dir(self.plugin.settingsSection, path, 1) + self.directoryLineEdit.setText(path) + + def onAllSelectedButtonClicked(self): + """ + Selects all songs in the *selectedListWidget*. + """ + self.selectedListWidget.selectAll() diff --git a/openlp/plugins/songs/lib/openlyricsexport.py b/openlp/plugins/songs/lib/openlyricsexport.py index 68dfde93f..ffb1a2d6f 100755 --- a/openlp/plugins/songs/lib/openlyricsexport.py +++ b/openlp/plugins/songs/lib/openlyricsexport.py @@ -25,7 +25,7 @@ ############################################################################### """ The :mod:`openlyricsexport` module provides the functionality for exporting -songs from the database. +songs from the database to the OpenLyrics format. """ import logging import os @@ -50,6 +50,8 @@ class OpenLyricsExport(object): self.manager = parent.plugin.manager self.songs = songs self.save_path = save_path + if not os.path.exists(self.save_path): + os.mkdir(self.save_path) def do_export(self): """ @@ -63,14 +65,10 @@ class OpenLyricsExport(object): if self.parent.stop_export_flag: return False self.parent.incrementProgressBar(unicode(translate( - 'SongsPlugin.OpenLyricsExport', 'Exporting %s...')) % + 'SongsPlugin.OpenLyricsExport', 'Exporting "%s"...')) % song.title) - # Check if path exists. If not, create the directories! - # What do we do with songs with the same title? I do not want to - # overwrite them! - path = os.path.join(self.save_path, song.title + u'.xml') xml = openLyrics.song_to_xml(song) tree = etree.ElementTree(etree.fromstring(xml)) - tree.write(path, encoding=u'utf-8', xml_declaration=True, - pretty_print=True) + tree.write(os.path.join(self.save_path, song.title + u'.xml'), + encoding=u'utf-8', xml_declaration=True, pretty_print=True) return True diff --git a/resources/forms/songexport.ui b/resources/forms/songexport.ui deleted file mode 100644 index 9830db3ef..000000000 --- a/resources/forms/songexport.ui +++ /dev/null @@ -1,241 +0,0 @@ - - SongExportDialog - - - - 0 - 0 - 641 - 607 - - - - Dialog - - - - 8 - - - 8 - - - - - - 8 - - - 0 - - - - - Available Songs - - - - - - - - - Select All - - - - - - - - - - - 0 - 0 - - - - - 30 - 16777215 - - - - - 8 - - - QLayout::SetMinimumSize - - - 0 - - - - - Qt::Vertical - - - QSizePolicy::MinimumExpanding - - - - 20 - 132 - - - - - - - - Select Songs - - - - :/exports/export_move_to_list.png:/exports/export_move_to_list.png - - - - 20 - 20 - - - - - - - - Deselect Songs - - - - :/exports/export_remove.png:/exports/export_remove.png - - - - 20 - 20 - - - - - - - - Qt::Vertical - - - QSizePolicy::MinimumExpanding - - - - 20 - 131 - - - - - - - - - - - Selected Songs - - - - - - - - - Select All - - - - - - - - - - - - - 0 - - - - OpenLyric Format - - - - - Text File - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - SongExportButtonBox - AvailableListWidget - AvailableAllToolButton - SelectToolButton - DeselectToolButton - SelectedListWidget - SelectedAllToolButton - ExportTabWidget - - - - - - - SongExportButtonBox - accepted() - SongExportDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - SongExportButtonBox - rejected() - SongExportDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/resources/forms/songexportform.ui b/resources/forms/songexportform.ui new file mode 100644 index 000000000..ad3ada947 --- /dev/null +++ b/resources/forms/songexportform.ui @@ -0,0 +1,148 @@ + + + WizardPage + + + + 0 + 0 + 576 + 334 + + + + WizardPage + + + + + + + + + + + + + + + ... + + + + :/exports/export_move_to_list.png:/exports/export_move_to_list.png + + + + + + + ... + + + + :/exports/export_remove.png:/exports/export_remove.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Available Songs + + + + + + + Selected Songs + + + + + + + + + + + 0 + 0 + + + + Select all + + + + + + + Select all + + + + + + + + + + + ... + + + + :/exports/export_load.png:/exports/export_load.png + + + + + + + + + + Directory: + + + + + + + + + + + + + + diff --git a/resources/images/export_selectall.png b/resources/images/export_selectall.png deleted file mode 100644 index 0f0d9f152..000000000 Binary files a/resources/images/export_selectall.png and /dev/null differ diff --git a/resources/images/openlp-2.qrc b/resources/images/openlp-2.qrc index 6b9d6dd54..3d953995e 100644 --- a/resources/images/openlp-2.qrc +++ b/resources/images/openlp-2.qrc @@ -78,12 +78,12 @@ import_load.png - export_selectall.png export_remove.png export_load.png export_move_to_list.png + wizard_exportsong.bmp wizard_importsong.bmp wizard_importbible.bmp wizard_createtheme.bmp diff --git a/resources/images/wizard_exportsong.bmp b/resources/images/wizard_exportsong.bmp new file mode 100644 index 000000000..948422dcc Binary files /dev/null and b/resources/images/wizard_exportsong.bmp differ