openlp/openlp/plugins/songs/forms/songimportform.py

940 lines
42 KiB
Python
Raw Normal View History

2010-04-02 12:23:40 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2010-12-26 11:04:47 +00:00
# Copyright (c) 2008-2011 Raoul Snyman #
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
2010-07-24 22:10:47 +00:00
# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian #
# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
# Carsten Tinggaard, Frode Woldsund #
2010-04-02 12:23:40 +00:00
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
2011-01-13 17:55:29 +00:00
"""
The song import functions for OpenLP.
"""
2010-04-02 12:23:40 +00:00
import logging
2010-08-20 19:40:07 +00:00
import os
2010-04-02 12:23:40 +00:00
from PyQt4 import QtCore, QtGui
from openlp.core.lib import Receiver, SettingsManager, translate
2011-02-09 05:04:12 +00:00
from openlp.core.lib.ui import UiStrings, critical_error_message_box
2011-01-13 17:55:29 +00:00
from openlp.core.ui.wizard import OpenLPWizard
from openlp.plugins.songs.lib.importer import SongFormat
2010-04-02 12:23:40 +00:00
log = logging.getLogger(__name__)
2011-01-13 17:55:29 +00:00
class SongImportForm(OpenLPWizard):
2010-04-02 12:23:40 +00:00
"""
2010-08-08 14:38:51 +00:00
This is the Song Import Wizard, which allows easy importing of Songs
into OpenLP from other formats like OpenLyrics, OpenSong and CCLI.
2010-04-02 12:23:40 +00:00
"""
2010-08-08 14:38:51 +00:00
log.info(u'SongImportForm loaded')
2010-04-02 12:23:40 +00:00
def __init__(self, parent, plugin):
2010-04-02 12:23:40 +00:00
"""
Instantiate the wizard, and run any extra setup we need to.
``parent``
The QWidget-derived parent of the wizard.
2010-08-08 14:38:51 +00:00
``plugin``
The songs plugin.
2010-04-02 12:23:40 +00:00
"""
2011-01-13 17:55:29 +00:00
OpenLPWizard.__init__(self, parent, plugin, u'songImportWizard',
u':/wizards/wizard_importsong.bmp')
def setupUi(self, image):
"""
Set up the song wizard UI.
"""
OpenLPWizard.setupUi(self, image)
self.formatStack.setCurrentIndex(0)
QtCore.QObject.connect(self.formatComboBox,
QtCore.SIGNAL(u'currentIndexChanged(int)'),
self.formatStack.setCurrentIndex)
def customInit(self):
"""
Song wizard specific initialisation.
"""
if not SongFormat.get_availability(SongFormat.OpenLP1):
self.openLP1DisabledWidget.setVisible(True)
self.openLP1ImportWidget.setVisible(False)
if not SongFormat.get_availability(SongFormat.SongsOfFellowship):
self.songsOfFellowshipDisabledWidget.setVisible(True)
self.songsOfFellowshipImportWidget.setVisible(False)
if not SongFormat.get_availability(SongFormat.Generic):
self.genericDisabledWidget.setVisible(True)
self.genericImportWidget.setVisible(False)
2011-01-13 17:55:29 +00:00
def customSignals(self):
"""
Song wizard specific signals.
"""
2010-08-20 19:40:07 +00:00
QtCore.QObject.connect(self.openLP2BrowseButton,
QtCore.SIGNAL(u'clicked()'),
self.onOpenLP2BrowseButtonClicked)
QtCore.QObject.connect(self.openLP1BrowseButton,
QtCore.SIGNAL(u'clicked()'),
self.onOpenLP1BrowseButtonClicked)
2011-01-02 16:42:09 +00:00
QtCore.QObject.connect(self.openLyricsAddButton,
QtCore.SIGNAL(u'clicked()'),
self.onOpenLyricsAddButtonClicked)
QtCore.QObject.connect(self.openLyricsRemoveButton,
QtCore.SIGNAL(u'clicked()'),
self.onOpenLyricsRemoveButtonClicked)
2010-08-20 19:40:07 +00:00
QtCore.QObject.connect(self.openSongAddButton,
QtCore.SIGNAL(u'clicked()'),
self.onOpenSongAddButtonClicked)
QtCore.QObject.connect(self.openSongRemoveButton,
QtCore.SIGNAL(u'clicked()'),
self.onOpenSongRemoveButtonClicked)
QtCore.QObject.connect(self.wordsOfWorshipAddButton,
QtCore.SIGNAL(u'clicked()'),
self.onWordsOfWorshipAddButtonClicked)
QtCore.QObject.connect(self.wordsOfWorshipRemoveButton,
QtCore.SIGNAL(u'clicked()'),
self.onWordsOfWorshipRemoveButtonClicked)
2010-08-26 19:45:09 +00:00
QtCore.QObject.connect(self.ccliAddButton,
QtCore.SIGNAL(u'clicked()'),
self.onCCLIAddButtonClicked)
QtCore.QObject.connect(self.ccliRemoveButton,
QtCore.SIGNAL(u'clicked()'),
self.onCCLIRemoveButtonClicked)
QtCore.QObject.connect(self.songsOfFellowshipAddButton,
2010-08-20 19:40:07 +00:00
QtCore.SIGNAL(u'clicked()'),
self.onSongsOfFellowshipAddButtonClicked)
QtCore.QObject.connect(self.songsOfFellowshipRemoveButton,
QtCore.SIGNAL(u'clicked()'),
self.onSongsOfFellowshipRemoveButtonClicked)
QtCore.QObject.connect(self.genericAddButton,
2010-08-20 19:40:07 +00:00
QtCore.SIGNAL(u'clicked()'),
self.onGenericAddButtonClicked)
QtCore.QObject.connect(self.genericRemoveButton,
QtCore.SIGNAL(u'clicked()'),
self.onGenericRemoveButtonClicked)
2011-01-12 08:59:14 +00:00
QtCore.QObject.connect(self.easiSlidesBrowseButton,
QtCore.SIGNAL(u'clicked()'),
self.onEasiSlidesBrowseButtonClicked)
2010-09-20 18:22:57 +00:00
QtCore.QObject.connect(self.ewBrowseButton,
QtCore.SIGNAL(u'clicked()'),
self.onEWBrowseButtonClicked)
2010-09-23 19:01:52 +00:00
QtCore.QObject.connect(self.songBeamerAddButton,
QtCore.SIGNAL(u'clicked()'),
self.onSongBeamerAddButtonClicked)
QtCore.QObject.connect(self.songBeamerRemoveButton,
QtCore.SIGNAL(u'clicked()'),
self.onSongBeamerRemoveButtonClicked)
2011-02-13 15:13:52 +00:00
QtCore.QObject.connect(self.songShowPlusAddButton,
QtCore.SIGNAL(u'clicked()'),
self.onSongShowPlusAddButtonClicked)
QtCore.QObject.connect(self.songShowPlusRemoveButton,
QtCore.SIGNAL(u'clicked()'),
self.onSongShowPlusRemoveButtonClicked)
2011-02-14 13:01:52 +00:00
QtCore.QObject.connect(self.foilPresenterAddButton,
QtCore.SIGNAL(u'clicked()'),
self.onFoilPresenterAddButtonClicked)
QtCore.QObject.connect(self.foilPresenterRemoveButton,
QtCore.SIGNAL(u'clicked()'),
self.onFoilPresenterRemoveButtonClicked)
2010-04-02 12:23:40 +00:00
2011-01-13 17:55:29 +00:00
def addCustomPages(self):
2010-04-02 12:23:40 +00:00
"""
2011-01-13 17:55:29 +00:00
Add song wizard specific pages.
2010-04-02 12:23:40 +00:00
"""
2011-01-13 17:55:29 +00:00
# Source Page
self.sourcePage = QtGui.QWizardPage()
self.sourcePage.setObjectName(u'SourcePage')
self.sourceLayout = QtGui.QVBoxLayout(self.sourcePage)
self.sourceLayout.setObjectName(u'SourceLayout')
self.formatLayout = QtGui.QFormLayout()
self.formatLayout.setObjectName(u'FormatLayout')
self.formatLabel = QtGui.QLabel(self.sourcePage)
self.formatLabel.setObjectName(u'FormatLabel')
self.formatComboBox = QtGui.QComboBox(self.sourcePage)
self.formatComboBox.setObjectName(u'FormatComboBox')
self.formatLayout.addRow(self.formatLabel, self.formatComboBox)
self.formatSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed,
QtGui.QSizePolicy.Minimum)
self.formatLayout.setItem(1, QtGui.QFormLayout.LabelRole,
self.formatSpacer)
self.sourceLayout.addLayout(self.formatLayout)
2011-02-03 20:12:06 +00:00
self.stackSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed,
QtGui.QSizePolicy.Expanding)
2011-01-13 17:55:29 +00:00
self.formatStack = QtGui.QStackedLayout()
self.formatStack.setObjectName(u'FormatStack')
# OpenLP 2.0
2011-02-02 03:32:25 +00:00
self.addFileSelectItem(u'openLP2', single_select=True)
2011-01-13 17:55:29 +00:00
# openlp.org 1.x
2011-02-02 03:32:25 +00:00
self.addFileSelectItem(u'openLP1', None, True, True)
2011-01-13 17:55:29 +00:00
# OpenLyrics
2011-02-02 03:32:25 +00:00
self.addFileSelectItem(u'openLyrics', u'OpenLyrics', True)
2011-01-13 17:55:29 +00:00
# Open Song
2011-02-02 03:32:25 +00:00
self.addFileSelectItem(u'openSong', u'OpenSong')
2011-01-13 17:55:29 +00:00
# Words of Worship
2011-02-02 03:32:25 +00:00
self.addFileSelectItem(u'wordsOfWorship')
2011-01-13 17:55:29 +00:00
# CCLI File import
2011-02-02 03:32:25 +00:00
self.addFileSelectItem(u'ccli')
2011-01-13 17:55:29 +00:00
# Songs of Fellowship
2011-02-02 03:32:25 +00:00
self.addFileSelectItem(u'songsOfFellowship', None, True)
2011-01-13 17:55:29 +00:00
# Generic Document/Presentation import
2011-02-02 03:32:25 +00:00
self.addFileSelectItem(u'generic', None, True)
# EasySlides
2011-02-02 03:32:25 +00:00
self.addFileSelectItem(u'easiSlides', single_select=True)
2011-01-13 17:55:29 +00:00
# EasyWorship
2011-02-02 03:32:25 +00:00
self.addFileSelectItem(u'ew', single_select=True)
2011-01-13 17:55:29 +00:00
# Words of Worship
2011-02-02 03:32:25 +00:00
self.addFileSelectItem(u'songBeamer')
2011-02-13 15:13:52 +00:00
# Song Show Plus
self.addFileSelectItem(u'songShowPlus')
2011-02-14 13:01:52 +00:00
# Foilpresenter
self.addFileSelectItem(u'foilPresenter')
2011-01-13 17:55:29 +00:00
# Commented out for future use.
2011-02-02 03:32:25 +00:00
# self.addFileSelectItem(u'csv', u'CSV', single_select=True)
2011-01-13 17:55:29 +00:00
self.sourceLayout.addLayout(self.formatStack)
self.addPage(self.sourcePage)
def retranslateUi(self):
2010-12-08 22:55:28 +00:00
"""
2011-01-13 17:55:29 +00:00
Song wizard localisation.
2010-12-08 22:55:28 +00:00
"""
2011-01-13 17:55:29 +00:00
self.setWindowTitle(
translate('SongsPlugin.ImportWizardForm', 'Song Import Wizard'))
self.titleLabel.setText(
u'<span style="font-size:14pt; font-weight:600;">%s</span>' % \
translate('SongsPlugin.ImportWizardForm',
'Welcome to the Song Import Wizard'))
self.informationLabel.setText(
translate('SongsPlugin.ImportWizardForm',
'This wizard will help you to import songs from a variety of '
'formats. Click the next button below to start the process by '
'selecting a format to import from.'))
self.sourcePage.setTitle(
translate('SongsPlugin.ImportWizardForm', 'Select Import Source'))
self.sourcePage.setSubTitle(
translate('SongsPlugin.ImportWizardForm',
'Select the import format, and where to import from.'))
self.formatLabel.setText(
translate('SongsPlugin.ImportWizardForm', 'Format:'))
2011-02-09 05:04:12 +00:00
self.formatComboBox.setItemText(0, UiStrings.OLPV2)
2011-01-13 17:55:29 +00:00
self.formatComboBox.setItemText(1,
translate('SongsPlugin.ImportWizardForm', 'openlp.org 1.x'))
self.formatComboBox.setItemText(2,
translate('SongsPlugin.ImportWizardForm', 'OpenLyrics'))
self.formatComboBox.setItemText(3,
translate('SongsPlugin.ImportWizardForm', 'OpenSong'))
self.formatComboBox.setItemText(4,
translate('SongsPlugin.ImportWizardForm', 'Words of Worship'))
self.formatComboBox.setItemText(5,
translate('SongsPlugin.ImportWizardForm', 'CCLI/SongSelect'))
self.formatComboBox.setItemText(6,
translate('SongsPlugin.ImportWizardForm', 'Songs of Fellowship'))
self.formatComboBox.setItemText(7,
translate('SongsPlugin.ImportWizardForm',
'Generic Document/Presentation'))
self.formatComboBox.setItemText(8,
translate('SongsPlugin.ImportWizardForm', 'EasiSlides'))
2011-01-13 17:55:29 +00:00
self.formatComboBox.setItemText(9,
translate('SongsPlugin.ImportWizardForm', 'EasyWorship'))
self.formatComboBox.setItemText(10,
2011-01-13 17:55:29 +00:00
translate('SongsPlugin.ImportWizardForm', 'SongBeamer'))
2011-02-14 12:20:30 +00:00
self.formatComboBox.setItemText(11,
2011-02-13 15:13:52 +00:00
translate('SongsPlugin.ImportWizardForm', 'SongShow Plus'))
2011-02-14 12:42:35 +00:00
self.formatComboBox.setItemText(12,
2011-02-18 20:40:07 +00:00
translate('SongsPlugin.ImportWizardForm', 'Foilpresenter'))
# self.formatComboBox.setItemText(11,
2011-01-13 17:55:29 +00:00
# translate('SongsPlugin.ImportWizardForm', 'CSV'))
self.openLP2FilenameLabel.setText(
translate('SongsPlugin.ImportWizardForm', 'Filename:'))
self.openLP2BrowseButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Browse...'))
self.openLP1FilenameLabel.setText(
translate('SongsPlugin.ImportWizardForm', 'Filename:'))
self.openLP1BrowseButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Browse...'))
self.openLP1DisabledLabel.setText(
translate('SongsPlugin.ImportWizardForm', 'The openlp.org 1.x '
'importer has been disabled due to a missing Python module. If '
'you want to use this importer, you will need to install the '
'"python-sqlite" module.'))
self.openLyricsAddButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Add Files...'))
self.openLyricsRemoveButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
self.openLyricsDisabledLabel.setText(
translate('SongsPlugin.ImportWizardForm', 'The OpenLyrics '
'importer has not yet been developed, but as you can see, we are '
'still intending to do so. Hopefully it will be in the next '
'release.'))
self.openSongAddButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Add Files...'))
self.openSongRemoveButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
self.wordsOfWorshipAddButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Add Files...'))
self.wordsOfWorshipRemoveButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
self.ccliAddButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Add Files...'))
self.ccliRemoveButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
self.songsOfFellowshipAddButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Add Files...'))
self.songsOfFellowshipRemoveButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
self.songsOfFellowshipDisabledLabel.setText(
translate('SongsPlugin.ImportWizardForm', 'The Songs of '
'Fellowship importer has been disabled because OpenLP cannot '
'find OpenOffice.org on your computer.'))
self.genericAddButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Add Files...'))
self.genericRemoveButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
self.genericDisabledLabel.setText(
translate('SongsPlugin.ImportWizardForm', 'The generic document/'
'presentation importer has been disabled because OpenLP cannot '
'find OpenOffice.org on your computer.'))
self.easiSlidesFilenameLabel.setText(
translate('SongsPlugin.ImportWizardForm', 'Filename:'))
self.easiSlidesBrowseButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Browse...'))
2011-01-13 17:55:29 +00:00
self.ewFilenameLabel.setText(
translate('SongsPlugin.ImportWizardForm', 'Filename:'))
self.ewBrowseButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Browse...'))
self.songBeamerAddButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Add Files...'))
self.songBeamerRemoveButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
2011-02-13 15:13:52 +00:00
self.songShowPlusAddButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Add Files...'))
self.songShowPlusRemoveButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
2011-02-14 12:20:30 +00:00
self.foilPresenterAddButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Add Files...'))
self.foilPresenterRemoveButton.setText(
translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
2011-01-13 17:55:29 +00:00
# self.csvFilenameLabel.setText(
# translate('SongsPlugin.ImportWizardForm', 'Filename:'))
# self.csvBrowseButton.setText(
# translate('SongsPlugin.ImportWizardForm', 'Browse...'))
self.progressPage.setTitle(
translate('SongsPlugin.ImportWizardForm', 'Importing'))
self.progressPage.setSubTitle(
translate('SongsPlugin.ImportWizardForm',
'Please wait while your songs are imported.'))
self.progressLabel.setText(
translate('SongsPlugin.ImportWizardForm', 'Ready.'))
self.progressBar.setFormat(
translate('SongsPlugin.ImportWizardForm', '%p%'))
# Align all QFormLayouts towards each other.
width = max(self.formatLabel.minimumSizeHint().width(),
self.openLP2FilenameLabel.minimumSizeHint().width())
self.formatSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed,
QtGui.QSizePolicy.Fixed)
2010-12-08 22:55:28 +00:00
2010-04-02 12:23:40 +00:00
def validateCurrentPage(self):
"""
Validate the current page before moving on to the next page.
"""
if self.currentPage() == self.welcomePage:
return True
elif self.currentPage() == self.sourcePage:
source_format = self.formatComboBox.currentIndex()
2010-08-20 19:40:07 +00:00
if source_format == SongFormat.OpenLP2:
if self.openLP2FilenameEdit.text().isEmpty():
critical_error_message_box(
2010-08-20 19:40:07 +00:00
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'No OpenLP 2.0 Song Database Selected'),
2010-08-20 19:40:07 +00:00
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'You need to select an OpenLP 2.0 song database '
'file to import from.'))
2010-08-20 19:40:07 +00:00
self.openLP2BrowseButton.setFocus()
return False
elif source_format == SongFormat.OpenLP1:
2010-09-06 22:02:48 +00:00
if self.openLP1FilenameEdit.text().isEmpty():
critical_error_message_box(
2010-08-20 19:40:07 +00:00
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'No openlp.org 1.x Song Database Selected'),
2010-08-20 19:40:07 +00:00
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'You need to select an openlp.org 1.x song '
'database file to import from.'))
2010-08-20 19:40:07 +00:00
self.openLP1BrowseButton.setFocus()
return False
elif source_format == SongFormat.OpenLyrics:
2011-01-02 16:42:09 +00:00
if self.openLyricsFileListWidget.count() == 0:
critical_error_message_box(
2011-01-02 16:42:09 +00:00
translate('SongsPlugin.ImportWizardForm',
'No OpenLyrics Files Selected'),
translate('SongsPlugin.ImportWizardForm',
'You need to add at least one OpenLyrics '
'song file to import from.'))
self.openLyricsAddButton.setFocus()
return False
elif source_format == SongFormat.OpenSong:
2010-08-20 19:40:07 +00:00
if self.openSongFileListWidget.count() == 0:
critical_error_message_box(
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'No OpenSong Files Selected'),
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'You need to add at least one OpenSong '
'song file to import from.'))
2010-08-20 19:40:07 +00:00
self.openSongAddButton.setFocus()
return False
elif source_format == SongFormat.WordsOfWorship:
if self.wordsOfWorshipFileListWidget.count() == 0:
critical_error_message_box(
2010-08-20 19:40:07 +00:00
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'No Words of Worship Files Selected'),
2010-08-20 19:40:07 +00:00
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'You need to add at least one Words of Worship '
'file to import from.'))
2010-08-20 19:40:07 +00:00
self.wordsOfWorshipAddButton.setFocus()
return False
elif source_format == SongFormat.CCLI:
if self.ccliFileListWidget.count() == 0:
critical_error_message_box(
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'No CCLI Files Selected'),
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'You need to add at least one CCLI file '
'to import from.'))
self.ccliAddButton.setFocus()
return False
2010-08-20 19:40:07 +00:00
elif source_format == SongFormat.SongsOfFellowship:
if self.songsOfFellowshipFileListWidget.count() == 0:
critical_error_message_box(
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'No Songs of Fellowship File Selected'),
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'You need to add at least one Songs of Fellowship '
'file to import from.'))
self.songsOfFellowshipAddButton.setFocus()
return False
2010-08-20 19:40:07 +00:00
elif source_format == SongFormat.Generic:
if self.genericFileListWidget.count() == 0:
critical_error_message_box(
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'No Document/Presentation Selected'),
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'You need to add at least one document or '
'presentation file to import from.'))
self.genericAddButton.setFocus()
return False
2011-01-12 08:59:14 +00:00
elif source_format == SongFormat.EasiSlides:
if self.easiSlidesFilenameEdit.text().isEmpty():
critical_error_message_box(
2011-01-12 08:59:14 +00:00
translate('SongsPlugin.ImportWizardForm',
'No Easislides Songs file selected'),
2011-01-12 08:59:14 +00:00
translate('SongsPlugin.ImportWizardForm',
'You need to select an xml song file exported from '
'EasiSlides, to import from.'))
self.easiSlidesBrowseButton.setFocus()
return False
2010-09-20 18:22:57 +00:00
elif source_format == SongFormat.EasyWorship:
if self.ewFilenameEdit.text().isEmpty():
critical_error_message_box(
2010-09-20 18:22:57 +00:00
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'No EasyWorship Song Database Selected'),
2010-09-20 18:22:57 +00:00
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'You need to select an EasyWorship song database '
'file to import from.'))
2010-09-20 18:22:57 +00:00
self.ewBrowseButton.setFocus()
return False
2010-09-23 19:01:52 +00:00
elif source_format == SongFormat.SongBeamer:
if self.songBeamerFileListWidget.count() == 0:
critical_error_message_box(
2010-09-23 19:01:52 +00:00
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'No SongBeamer File Selected'),
2010-09-23 19:01:52 +00:00
translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'You need to add at least one SongBeamer '
'file to import from.'))
2010-09-23 19:01:52 +00:00
self.songBeamerAddButton.setFocus()
return False
2011-02-13 15:13:52 +00:00
elif source_format == SongFormat.SongShowPlus:
if self.songShowPlusFileListWidget.count() == 0:
critical_error_message_box(
translate('SongsPlugin.ImportWizardForm',
'No SongShow Plus Files Selected'),
translate('SongsPlugin.ImportWizardForm',
'You need to add at least one SongShow Plus '
'file to import from.'))
self.wordsOfWorshipAddButton.setFocus()
2011-02-14 13:01:52 +00:00
return False
2011-02-14 12:20:30 +00:00
elif source_format == SongFormat.FoilPresenter:
if self.foilPresenterFileListWidget.count() == 0:
criticalErrorMessageBox(
translate('SongsPlugin.ImportWizardForm',
'No Foilpresenter Files Selected'),
translate('SongsPlugin.ImportWizardForm',
'You need to add at least one Foilpresenter '
'song file to import from.'))
self.foilPresenterAddButton.setFocus()
return False
return True
2011-01-13 17:55:29 +00:00
elif self.currentPage() == self.progressPage:
return True
2010-04-02 12:23:40 +00:00
2010-12-21 13:40:41 +00:00
def getFiles(self, title, listbox, filters=u''):
"""
Opens a QFileDialog and writes the filenames to the given listbox.
``title``
The title of the dialog (unicode).
``listbox``
A listbox (QListWidget).
``filters``
The file extension filters. It should contain the file descriptions
as well as the file extensions. For example::
2011-02-14 20:32:19 +00:00
u'SongBeamer Files (*.sng)'
2010-12-21 13:40:41 +00:00
"""
if filters:
filters += u';;'
2011-02-09 05:04:12 +00:00
filters += u'%s (*)' % UiStrings.AllFiles
2010-08-08 14:38:51 +00:00
filenames = QtGui.QFileDialog.getOpenFileNames(self, title,
2010-12-29 16:35:10 +00:00
SettingsManager.get_last_dir(self.plugin.settingsSection, 1),
filters)
2010-08-08 14:38:51 +00:00
if filenames:
listbox.addItems(filenames)
2010-08-20 19:40:07 +00:00
SettingsManager.set_last_dir(
self.plugin.settingsSection,
os.path.split(unicode(filenames[0]))[0], 1)
2010-08-08 14:38:51 +00:00
def getListOfFiles(self, listbox):
2011-01-13 17:55:29 +00:00
"""
Return a list of file from the listbox
"""
files = []
for row in range(0, listbox.count()):
files.append(unicode(listbox.item(row).text()))
return files
2010-08-08 14:38:51 +00:00
def removeSelectedItems(self, listbox):
2011-01-13 17:55:29 +00:00
"""
Remove selected listbox items
"""
2010-08-08 14:38:51 +00:00
for item in listbox.selectedItems():
item = listbox.takeItem(listbox.row(item))
del item
2010-08-20 19:40:07 +00:00
def onOpenLP2BrowseButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Get OpenLP v2 song database file
"""
2010-08-20 19:40:07 +00:00
self.getFileName(
translate('SongsPlugin.ImportWizardForm',
'Select OpenLP 2.0 Database File'),
2010-12-21 13:40:41 +00:00
self.openLP2FilenameEdit, u'%s (*.sqlite)'
% (translate('SongsPlugin.ImportWizardForm',
2010-12-21 13:40:41 +00:00
'OpenLP 2.0 Databases'))
2010-08-20 19:40:07 +00:00
)
def onOpenLP1BrowseButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Get OpenLP v1 song database file
"""
2010-08-20 19:40:07 +00:00
self.getFileName(
translate('SongsPlugin.ImportWizardForm',
'Select openlp.org 1.x Database File'),
2010-12-21 13:40:41 +00:00
self.openLP1FilenameEdit, u'%s (*.olp)'
% translate('SongsPlugin.ImportWizardForm',
'openlp.org v1.x Databases')
2010-08-20 19:40:07 +00:00
)
2011-01-02 16:42:09 +00:00
def onOpenLyricsAddButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Get OpenLyrics song database files
"""
2011-01-02 16:42:09 +00:00
self.getFiles(
translate('SongsPlugin.ImportWizardForm',
'Select OpenLyrics Files'),
self.openLyricsFileListWidget
)
2010-08-08 14:38:51 +00:00
2011-01-02 16:42:09 +00:00
def onOpenLyricsRemoveButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Remove selected OpenLyrics files from the import list
"""
2011-01-02 16:42:09 +00:00
self.removeSelectedItems(self.openLyricsFileListWidget)
2010-08-20 19:40:07 +00:00
def onOpenSongAddButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Get OpenSong song database files
"""
2010-08-20 19:40:07 +00:00
self.getFiles(
2011-01-13 17:55:29 +00:00
translate('SongsPlugin.ImportWizardForm', 'Select Open Song Files'),
2010-10-05 21:32:03 +00:00
self.openSongFileListWidget
2010-08-20 19:40:07 +00:00
)
def onOpenSongRemoveButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Remove selected OpenSong files from the import list
"""
2010-08-20 19:40:07 +00:00
self.removeSelectedItems(self.openSongFileListWidget)
def onWordsOfWorshipAddButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Get Words of Worship song database files
"""
2010-08-20 19:40:07 +00:00
self.getFiles(
translate('SongsPlugin.ImportWizardForm',
'Select Words of Worship Files'),
2010-12-21 13:40:41 +00:00
self.wordsOfWorshipFileListWidget, u'%s (*.wsg *.wow-song)'
% translate('SongsPlugin.ImportWizardForm',
'Words Of Worship Song Files')
2010-08-20 19:40:07 +00:00
)
def onWordsOfWorshipRemoveButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Remove selected Words of Worship files from the import list
"""
2010-08-20 19:40:07 +00:00
self.removeSelectedItems(self.wordsOfWorshipFileListWidget)
2010-08-26 19:45:09 +00:00
def onCCLIAddButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Get CCLI song database files
"""
2010-08-26 19:45:09 +00:00
self.getFiles(
translate('SongsPlugin.ImportWizardForm',
'Select CCLI Files'),
self.ccliFileListWidget
)
def onCCLIRemoveButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Remove selected CCLI files from the import list
"""
2010-08-26 19:45:09 +00:00
self.removeSelectedItems(self.ccliFileListWidget)
2010-09-06 22:02:48 +00:00
def onSongsOfFellowshipAddButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Get Songs of Fellowship song database files
"""
self.getFiles(
2010-08-20 19:40:07 +00:00
translate('SongsPlugin.ImportWizardForm',
'Select Songs of Fellowship Files'),
2010-12-21 13:40:41 +00:00
self.songsOfFellowshipFileListWidget, u'%s (*.rtf)'
% translate('SongsPlugin.ImportWizardForm',
2011-02-14 20:32:19 +00:00
'Songs Of Fellowship Song Files')
2010-08-20 19:40:07 +00:00
)
def onSongsOfFellowshipRemoveButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Remove selected Songs of Fellowship files from the import list
"""
self.removeSelectedItems(self.songsOfFellowshipFileListWidget)
def onGenericAddButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Get song database files
"""
self.getFiles(
2010-08-20 19:40:07 +00:00
translate('SongsPlugin.ImportWizardForm',
'Select Document/Presentation Files'),
self.genericFileListWidget
2010-08-20 19:40:07 +00:00
)
2010-08-08 14:38:51 +00:00
def onGenericRemoveButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Remove selected files from the import list
"""
self.removeSelectedItems(self.genericFileListWidget)
2011-01-12 08:59:14 +00:00
def onEasiSlidesBrowseButtonClicked(self):
self.getFileName(
translate('SongsPlugin.ImportWizardForm',
'Select EasiSlides songfile'),
self.easiSlidesFilenameEdit
)
2011-01-19 19:37:44 +00:00
2010-09-20 18:22:57 +00:00
def onEWBrowseButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Get EasyWorship song database files
"""
2010-09-20 18:22:57 +00:00
self.getFileName(
translate('SongsPlugin.ImportWizardForm',
'Select EasyWorship Database File'),
self.ewFilenameEdit
)
2010-09-23 19:01:52 +00:00
def onSongBeamerAddButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Get SongBeamer song database files
"""
2010-09-23 19:01:52 +00:00
self.getFiles(
translate('SongsPlugin.ImportWizardForm',
'Select SongBeamer Files'),
2010-12-21 13:40:41 +00:00
self.songBeamerFileListWidget, u'%s (*.sng)' %
2011-02-14 20:32:19 +00:00
translate('SongsPlugin.ImportWizardForm', 'SongBeamer Files')
2010-09-23 19:01:52 +00:00
)
def onSongBeamerRemoveButtonClicked(self):
2011-01-13 17:55:29 +00:00
"""
Remove selected SongBeamer files from the import list
"""
2010-09-23 19:01:52 +00:00
self.removeSelectedItems(self.songBeamerFileListWidget)
2011-02-13 15:13:52 +00:00
def onSongShowPlusAddButtonClicked(self):
"""
Get SongShow Plus song database files
"""
self.getFiles(
translate('SongsPlugin.ImportWizardForm',
'Select SongShow Plus Files'),
self.songShowPlusFileListWidget, u'%s (*.sbsong)'
% translate('SongsPlugin.ImportWizardForm',
'SongShow Plus Song Files')
)
2010-09-23 19:01:52 +00:00
2011-02-14 12:20:30 +00:00
def onFoilPresenterAddButtonClicked(self):
"""
Get FoilPresenter song database files
"""
self.getFiles(
translate('SongsPlugin.ImportWizardForm',
'Select FoilPresenter Files'),
2011-02-18 20:40:07 +00:00
self.foilPresenterFileListWidget, u'%s (*.foil)'
% translate('SongsPlugin.ImportWizardForm',
'Foilpresenter Song Files')
2011-02-14 12:20:30 +00:00
)
def onFoilPresenterRemoveButtonClicked(self):
"""
Remove selected FoilPresenter files from the import list
"""
self.removeSelectedItems(self.foilPresenterFileListWidget)
2010-04-02 20:03:51 +00:00
def registerFields(self):
2011-01-13 17:55:29 +00:00
"""
Register song import wizard fields.
"""
pass
2010-04-02 20:03:51 +00:00
2011-02-13 15:13:52 +00:00
def onSongShowPlusRemoveButtonClicked(self):
"""
Remove selected SongShow Plus files from the import list
"""
self.removeSelectedItems(self.songShowPlusFileListWidget)
2010-09-23 19:01:52 +00:00
2010-04-02 20:03:51 +00:00
def setDefaults(self):
2011-01-13 17:55:29 +00:00
"""
Set default form values for the song import wizard.
"""
self.restart()
self.finishButton.setVisible(False)
self.cancelButton.setVisible(True)
self.formatComboBox.setCurrentIndex(0)
2010-08-20 19:40:07 +00:00
self.openLP2FilenameEdit.setText(u'')
self.openLP1FilenameEdit.setText(u'')
2011-01-02 16:42:09 +00:00
self.openLyricsFileListWidget.clear()
2010-08-20 19:40:07 +00:00
self.openSongFileListWidget.clear()
self.wordsOfWorshipFileListWidget.clear()
self.ccliFileListWidget.clear()
self.songsOfFellowshipFileListWidget.clear()
self.genericFileListWidget.clear()
2011-01-12 08:59:14 +00:00
self.easiSlidesFilenameEdit.setText(u'')
2010-09-20 18:22:57 +00:00
self.ewFilenameEdit.setText(u'')
2010-09-23 19:01:52 +00:00
self.songBeamerFileListWidget.clear()
2011-02-13 15:13:52 +00:00
self.songShowPlusFileListWidget.clear()
2011-02-14 12:20:30 +00:00
self.foilPresenterFileListWidget.clear()
#self.csvFilenameEdit.setText(u'')
2010-04-02 12:23:40 +00:00
2011-01-13 17:55:29 +00:00
def preWizard(self):
"""
Perform pre import tasks
"""
OpenLPWizard.preWizard(self)
self.progressLabel.setText(
translate('SongsPlugin.ImportWizardForm', 'Starting import...'))
Receiver.send_message(u'openlp_process_events')
2010-04-02 12:23:40 +00:00
2011-01-13 17:55:29 +00:00
def performWizard(self):
"""
Perform the actual import. This method pulls in the correct importer
class, and then runs the ``do_import`` method of the importer to do
the actual importing.
"""
source_format = self.formatComboBox.currentIndex()
importer = None
if source_format == SongFormat.OpenLP2:
# Import an OpenLP 2.0 database
importer = self.plugin.importSongs(SongFormat.OpenLP2,
filename=unicode(self.openLP2FilenameEdit.text())
)
2010-09-06 22:02:48 +00:00
elif source_format == SongFormat.OpenLP1:
# Import an openlp.org database
importer = self.plugin.importSongs(SongFormat.OpenLP1,
filename=unicode(self.openLP1FilenameEdit.text())
)
elif source_format == SongFormat.OpenLyrics:
# Import OpenLyrics songs
importer = self.plugin.importSongs(SongFormat.OpenLyrics,
filenames=self.getListOfFiles(self.openLyricsFileListWidget)
)
elif source_format == SongFormat.OpenSong:
# Import OpenSong songs
importer = self.plugin.importSongs(SongFormat.OpenSong,
filenames=self.getListOfFiles(self.openSongFileListWidget)
)
elif source_format == SongFormat.WordsOfWorship:
# Import Words Of Worship songs
importer = self.plugin.importSongs(SongFormat.WordsOfWorship,
filenames=self.getListOfFiles(
self.wordsOfWorshipFileListWidget)
)
elif source_format == SongFormat.CCLI:
# Import Words Of Worship songs
importer = self.plugin.importSongs(SongFormat.CCLI,
filenames=self.getListOfFiles(self.ccliFileListWidget)
)
elif source_format == SongFormat.SongsOfFellowship:
# Import a Songs of Fellowship RTF file
importer = self.plugin.importSongs(SongFormat.SongsOfFellowship,
filenames=self.getListOfFiles(
self.songsOfFellowshipFileListWidget)
)
elif source_format == SongFormat.Generic:
# Import a generic document or presentatoin
importer = self.plugin.importSongs(SongFormat.Generic,
filenames=self.getListOfFiles(self.genericFileListWidget)
)
2011-01-12 08:59:14 +00:00
elif source_format == SongFormat.EasiSlides:
# Import an EasiSlides export file
importer = self.plugin.importSongs(SongFormat.EasiSlides,
filename=unicode(self.easiSlidesFilenameEdit.text())
)
2010-09-20 18:22:57 +00:00
elif source_format == SongFormat.EasyWorship:
2011-01-12 08:59:14 +00:00
# Import an EasyWorship database
2010-09-20 18:22:57 +00:00
importer = self.plugin.importSongs(SongFormat.EasyWorship,
filename=unicode(self.ewFilenameEdit.text())
)
2010-09-23 19:01:52 +00:00
elif source_format == SongFormat.SongBeamer:
# Import SongBeamer songs
importer = self.plugin.importSongs(SongFormat.SongBeamer,
2011-01-13 17:55:29 +00:00
filenames=self.getListOfFiles(self.songBeamerFileListWidget)
2010-09-23 19:01:52 +00:00
)
2011-02-13 15:13:52 +00:00
elif source_format == SongFormat.SongShowPlus:
# Import ShongShow Plus songs
importer = self.plugin.importSongs(SongFormat.SongShowPlus,
filenames=self.getListOfFiles(
self.songShowPlusFileListWidget)
)
2011-02-14 12:20:30 +00:00
elif source_format == SongFormat.FoilPresenter:
# Import Foilpresenter songs
importer = self.plugin.importSongs(SongFormat.FoilPresenter,
filenames=self.getListOfFiles(self.foilPresenterFileListWidget)
)
2010-11-26 14:23:48 +00:00
if importer.do_import():
2011-01-13 17:55:29 +00:00
self.progressLabel.setText(
translate('SongsPlugin.SongImportForm', 'Finished import.'))
else:
2011-01-13 17:55:29 +00:00
self.progressLabel.setText(
translate('SongsPlugin.SongImportForm',
'Your song import failed.'))
2010-04-02 12:23:40 +00:00
2011-02-02 03:32:25 +00:00
def addFileSelectItem(self, prefix, obj_prefix=None, can_disable=False,
single_select=False):
2011-01-13 17:55:29 +00:00
if not obj_prefix:
obj_prefix = prefix
page = QtGui.QWidget()
page.setObjectName(obj_prefix + u'Page')
if can_disable:
importWidget = self.disablableWidget(page, prefix, obj_prefix)
else:
importWidget = page
importLayout = QtGui.QVBoxLayout(importWidget)
importLayout.setMargin(0)
2011-02-02 03:32:25 +00:00
importLayout.setObjectName(obj_prefix + u'ImportLayout')
if single_select:
fileLayout = QtGui.QHBoxLayout()
fileLayout.setObjectName(obj_prefix + u'FileLayout')
filenameLabel = QtGui.QLabel(importWidget)
filenameLabel.setObjectName(obj_prefix + u'FilenameLabel')
fileLayout.addWidget(filenameLabel)
filenameEdit = QtGui.QLineEdit(importWidget)
filenameEdit.setObjectName(obj_prefix + u'FilenameEdit')
fileLayout.addWidget(filenameEdit)
browseButton = QtGui.QToolButton(importWidget)
browseButton.setIcon(self.openIcon)
browseButton.setObjectName(obj_prefix + u'BrowseButton')
fileLayout.addWidget(browseButton)
importLayout.addLayout(fileLayout)
2011-02-03 20:12:06 +00:00
importLayout.addSpacerItem(self.stackSpacer)
2011-01-13 17:55:29 +00:00
else:
2011-02-02 03:32:25 +00:00
fileListWidget = QtGui.QListWidget(importWidget)
fileListWidget.setSelectionMode(
QtGui.QAbstractItemView.ExtendedSelection)
fileListWidget.setObjectName(obj_prefix + u'FileListWidget')
importLayout.addWidget(fileListWidget)
buttonLayout = QtGui.QHBoxLayout()
buttonLayout.setObjectName(obj_prefix + u'ButtonLayout')
addButton = QtGui.QPushButton(importWidget)
addButton.setIcon(self.openIcon)
addButton.setObjectName(obj_prefix + u'AddButton')
buttonLayout.addWidget(addButton)
buttonLayout.addStretch()
removeButton = QtGui.QPushButton(importWidget)
removeButton.setIcon(self.deleteIcon)
removeButton.setObjectName(obj_prefix + u'RemoveButton')
buttonLayout.addWidget(removeButton)
importLayout.addLayout(buttonLayout)
2011-01-13 17:55:29 +00:00
self.formatStack.addWidget(page)
setattr(self, prefix + u'Page', page)
2011-02-02 03:32:25 +00:00
if single_select:
setattr(self, prefix + u'FilenameLabel', filenameLabel)
setattr(self, prefix + u'FileLayout', fileLayout)
setattr(self, prefix + u'FilenameEdit', filenameEdit)
setattr(self, prefix + u'BrowseButton', browseButton)
2011-01-13 17:55:29 +00:00
else:
2011-02-02 03:32:25 +00:00
setattr(self, prefix + u'FileListWidget', fileListWidget)
setattr(self, prefix + u'ButtonLayout', buttonLayout)
setattr(self, prefix + u'AddButton', addButton)
setattr(self, prefix + u'RemoveButton', removeButton)
setattr(self, prefix + u'ImportLayout', importLayout)
2011-01-13 17:55:29 +00:00
self.formatComboBox.addItem(u'')
def disablableWidget(self, page, prefix, obj_prefix):
layout = QtGui.QVBoxLayout(page)
layout.setMargin(0)
layout.setSpacing(0)
layout.setObjectName(obj_prefix + u'Layout')
disabledWidget = QtGui.QWidget(page)
disabledWidget.setVisible(False)
disabledWidget.setObjectName(obj_prefix + u'DisabledWidget')
disabledLayout = QtGui.QVBoxLayout(disabledWidget)
disabledLayout.setMargin(0)
disabledLayout.setObjectName(obj_prefix + u'DisabledLayout')
disabledLabel = QtGui.QLabel(disabledWidget)
disabledLabel.setWordWrap(True)
disabledLabel.setObjectName(obj_prefix + u'DisabledLabel')
disabledLayout.addWidget(disabledLabel)
2011-02-03 20:12:06 +00:00
disabledLayout.addSpacerItem(self.stackSpacer)
2011-01-13 17:55:29 +00:00
layout.addWidget(disabledWidget)
importWidget = QtGui.QWidget(page)
importWidget.setObjectName(obj_prefix + u'ImportWidget')
layout.addWidget(importWidget)
setattr(self, prefix + u'Layout', layout)
setattr(self, prefix + u'DisabledWidget', disabledWidget)
setattr(self, prefix + u'DisabledLayout', disabledLayout)
setattr(self, prefix + u'DisabledLabel', disabledLabel)
setattr(self, prefix + u'ImportWidget', importWidget)
return importWidget