diff --git a/openlp/core/ui/wizard.py b/openlp/core/ui/wizard.py index 3609302b5..be71a0bbe 100644 --- a/openlp/core/ui/wizard.py +++ b/openlp/core/ui/wizard.py @@ -79,9 +79,10 @@ class OpenLPWizard(QtGui.QWizard): Generic OpenLP wizard to provide generic functionality and a unified look and feel. """ - def __init__(self, parent, plugin, name, image): + def __init__(self, parent, plugin, name, image, addProgressPage=True): QtGui.QWizard.__init__(self, parent) self.plugin = plugin + self.withProgressPage = addProgressPage self.setObjectName(name) self.openIcon = build_icon(u':/general/general_open.png') self.deleteIcon = build_icon(u':/general/general_delete.png') @@ -92,8 +93,9 @@ class OpenLPWizard(QtGui.QWizard): self.customInit() self.customSignals() QtCore.QObject.connect(self, QtCore.SIGNAL(u'currentIdChanged(int)'), self.onCurrentIdChanged) - QtCore.QObject.connect(self.errorCopyToButton, QtCore.SIGNAL(u'clicked()'), self.onErrorCopyToButtonClicked) - QtCore.QObject.connect(self.errorSaveToButton, QtCore.SIGNAL(u'clicked()'), self.onErrorSaveToButtonClicked) + if self.withProgressPage: + QtCore.QObject.connect(self.errorCopyToButton, QtCore.SIGNAL(u'clicked()'), self.onErrorCopyToButtonClicked) + QtCore.QObject.connect(self.errorSaveToButton, QtCore.SIGNAL(u'clicked()'), self.onErrorSaveToButtonClicked) def setupUi(self, image): """ @@ -106,7 +108,8 @@ class OpenLPWizard(QtGui.QWizard): QtGui.QWizard.NoBackButtonOnLastPage) add_welcome_page(self, image) self.addCustomPages() - self.addProgressPage() + if self.withProgressPage: + self.addProgressPage() self.retranslateUi() def registerFields(self): @@ -168,7 +171,7 @@ class OpenLPWizard(QtGui.QWizard): Stop the wizard on cancel button, close button or ESC key. """ log.debug(u'Wizard cancelled by user.') - if self.currentPage() == self.progressPage: + if self.withProgressPage and self.currentPage() == self.progressPage: Receiver.send_message(u'openlp_stop_wizard') self.done(QtGui.QDialog.Rejected) @@ -176,7 +179,7 @@ class OpenLPWizard(QtGui.QWizard): """ Perform necessary functions depending on which wizard page is active. """ - if self.page(pageId) == self.progressPage: + if self.withProgressPage and self.page(pageId) == self.progressPage: self.preWizard() self.performWizard() self.postWizard() diff --git a/openlp/plugins/songs/forms/duplicatesongremovalform.py b/openlp/plugins/songs/forms/duplicatesongremovalform.py new file mode 100644 index 000000000..33cd64b4a --- /dev/null +++ b/openlp/plugins/songs/forms/duplicatesongremovalform.py @@ -0,0 +1,139 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### +""" +The duplicate song removal logic for OpenLP. +""" +import codecs +import logging +import os + +from PyQt4 import QtCore, QtGui + +from openlp.core.lib import Receiver, Settings, SettingsManager, translate +from openlp.core.lib.ui import UiStrings, critical_error_message_box +from openlp.core.ui.wizard import OpenLPWizard, WizardStrings +from openlp.plugins.songs.lib.importer import SongFormat, SongFormatSelect + +log = logging.getLogger(__name__) + +class DuplicateSongRemovalForm(OpenLPWizard): + """ + This is the Duplicate Song Removal Wizard. It provides functionality to + search for and remove duplicate songs in the database. + """ + log.info(u'DuplicateSongRemovalForm loaded') + + def __init__(self, parent, plugin): + """ + Instantiate the wizard, and run any extra setup we need to. + + ``parent`` + The QWidget-derived parent of the wizard. + + ``plugin`` + The songs plugin. + """ + self.clipboard = plugin.formParent.clipboard + OpenLPWizard.__init__(self, parent, plugin, u'duplicateSongRemovalWizard', + u':/wizards/wizard_importsong.bmp', False) + + def customInit(self): + """ + Song wizard specific initialisation. + """ + pass + + def customSignals(self): + """ + Song wizard specific signals. + """ + #QtCore.QObject.connect(self.addButton, + # QtCore.SIGNAL(u'clicked()'), self.onAddButtonClicked) + #QtCore.QObject.connect(self.removeButton, + # QtCore.SIGNAL(u'clicked()'), self.onRemoveButtonClicked) + + def addCustomPages(self): + """ + Add song wizard specific pages. + """ + self.searchingPage = QtGui.QWizardPage() + self.searchingPage.setObjectName('searchingPage') + self.verticalLayout = QtGui.QVBoxLayout(self.searchingPage) + self.verticalLayout.setObjectName('verticalLayout') + self.duplicateSearchProgressBar = QtGui.QProgressBar(self.searchingPage) + self.duplicateSearchProgressBar.setObjectName(u'duplicateSearchProgressBar') + self.verticalLayout.addWidget(self.duplicateSearchProgressBar) + self.foundDuplicatesEdit = QtGui.QPlainTextEdit(self.searchingPage) + self.foundDuplicatesEdit.setUndoRedoEnabled(False) + self.foundDuplicatesEdit.setReadOnly(True) + self.foundDuplicatesEdit.setObjectName('foundDuplicatesEdit') + self.verticalLayout.addWidget(self.foundDuplicatesEdit) + self.addPage(self.searchingPage) + self.reviewPage = QtGui.QWizardPage() + self.reviewPage.setObjectName('reviewPage') + self.addPage(self.reviewPage) + + def retranslateUi(self): + """ + Song wizard localisation. + """ + self.setWindowTitle(translate('Wizard', 'Wizard')) + self.titleLabel.setText(WizardStrings.HeaderStyle % translate('OpenLP.Ui', + 'Welcome to the Duplicate Song Removal Wizard')) + self.informationLabel.setText(translate("Wizard", + 'This wizard will help you to remove duplicate songs from the song database.')) + self.searchingPage.setTitle(translate('Wizard', 'Searching for doubles')) + self.searchingPage.setSubTitle(translate('Wizard', 'The song database is searched for double songs.')) + + def customPageChanged(self, pageId): + """ + Called when changing to a page other than the progress page. + """ + pass + + def onAddButtonClicked(self): + pass + + def onRemoveButtonClicked(self): + pass + + def setDefaults(self): + """ + Set default form values for the song import wizard. + """ + self.restart() + self.foundDuplicatesEdit.clear() + + def performWizard(self): + """ + Perform the actual import. This method pulls in the correct importer + class, and then runs the ``doImport`` method of the importer to do + the actual importing. + """ + pass diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 726cbfbf5..b19eee5e7 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -46,6 +46,8 @@ from openlp.plugins.songs.lib.db import init_schema, Song from openlp.plugins.songs.lib.importer import SongFormat from openlp.plugins.songs.lib.olpimport import OpenLPSongImport from openlp.plugins.songs.lib.duplicatesongfinder import DuplicateSongFinder +from openlp.plugins.songs.forms.duplicatesongremovalform import \ + DuplicateSongRemovalForm log = logging.getLogger(__name__) @@ -184,6 +186,10 @@ class SongsPlugin(Plugin): QtGui.QMessageBox.information(self.formParent, "Double found", str(innerSongCounter) + " " + str(outerSongCounter)) + if not hasattr(self, u'duplicate_removal_wizard'): + self.duplicate_removal_wizard = \ + DuplicateSongRemovalForm(self.formParent, self) + self.duplicate_removal_wizard.exec_() def onSongImportItemClicked(self): if self.mediaItem: