2008-12-01 13:15:31 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
2009-09-08 19:58:05 +00:00
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2012-12-30 19:41:24 +00:00
|
|
|
# Copyright (c) 2008-2013 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
|
2012-06-22 14:14:53 +00:00
|
|
|
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
2012-11-11 21:16:14 +00:00
|
|
|
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
2012-10-21 13:16:22 +00:00
|
|
|
# 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, #
|
2012-11-07 21:37:01 +00:00
|
|
|
# Frode Woldsund, Martin Zibricky #
|
2009-09-08 19:58:05 +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 #
|
|
|
|
###############################################################################
|
2009-08-06 21:30:14 +00:00
|
|
|
|
2009-06-13 06:46:13 +00:00
|
|
|
import logging
|
2009-11-26 18:41:39 +00:00
|
|
|
import re
|
2011-08-24 11:53:22 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
2009-08-04 20:23:33 +00:00
|
|
|
|
2009-09-25 00:43:42 +00:00
|
|
|
from PyQt4 import QtCore, QtGui
|
2009-01-01 10:03:09 +00:00
|
|
|
|
2012-02-16 20:36:35 +00:00
|
|
|
from openlp.core.lib import PluginStatus, Receiver, MediaType, translate, \
|
2012-07-07 14:54:14 +00:00
|
|
|
create_separated_list, check_directory_exists
|
2012-04-01 21:19:56 +00:00
|
|
|
from openlp.core.lib.ui import UiStrings, set_case_insensitive_completer, \
|
2011-04-10 18:54:26 +00:00
|
|
|
critical_error_message_box, find_and_set_in_combo_box
|
2011-08-24 11:53:22 +00:00
|
|
|
from openlp.core.utils import AppLocation
|
2011-08-23 21:48:46 +00:00
|
|
|
from openlp.plugins.songs.forms import EditVerseForm, MediaFilesForm
|
2011-03-14 20:36:30 +00:00
|
|
|
from openlp.plugins.songs.lib import SongXML, VerseType, clean_song
|
2011-08-24 12:22:39 +00:00
|
|
|
from openlp.plugins.songs.lib.db import Book, Song, Author, Topic, MediaFile
|
2011-02-16 17:54:31 +00:00
|
|
|
from openlp.plugins.songs.lib.ui import SongStrings
|
2008-12-24 07:28:25 +00:00
|
|
|
from editsongdialog import Ui_EditSongDialog
|
|
|
|
|
2010-02-27 09:55:44 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2009-02-28 23:19:45 +00:00
|
|
|
class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
2008-12-24 07:28:25 +00:00
|
|
|
"""
|
2009-06-13 06:46:13 +00:00
|
|
|
Class to manage the editing of a song
|
2008-12-24 07:28:25 +00:00
|
|
|
"""
|
2010-02-27 09:55:44 +00:00
|
|
|
log.info(u'%s EditSongForm loaded', __name__)
|
2009-08-04 20:23:33 +00:00
|
|
|
|
2011-05-28 19:38:19 +00:00
|
|
|
def __init__(self, mediaitem, parent, manager):
|
2008-12-24 07:28:25 +00:00
|
|
|
"""
|
|
|
|
Constructor
|
|
|
|
"""
|
2009-02-28 23:19:45 +00:00
|
|
|
QtGui.QDialog.__init__(self, parent)
|
2011-05-28 19:38:19 +00:00
|
|
|
self.mediaitem = mediaitem
|
2010-08-28 19:32:24 +00:00
|
|
|
self.song = None
|
2010-07-21 10:30:29 +00:00
|
|
|
# can this be automated?
|
2010-05-18 19:29:40 +00:00
|
|
|
self.width = 400
|
2008-12-24 07:28:25 +00:00
|
|
|
self.setupUi(self)
|
2009-02-19 22:25:58 +00:00
|
|
|
# Connecting signals and slots
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.authorAddButton,
|
2009-08-04 20:23:33 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onAuthorAddButtonClicked)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.authorRemoveButton,
|
2009-08-04 20:23:33 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onAuthorRemoveButtonClicked)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.authorsListView,
|
2009-09-21 00:12:47 +00:00
|
|
|
QtCore.SIGNAL(u'itemClicked(QListWidgetItem*)'),
|
2012-04-02 00:19:16 +00:00
|
|
|
self.onAuthorsListViewClicked)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.topicAddButton,
|
2009-08-04 20:23:33 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onTopicAddButtonClicked)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.topicRemoveButton,
|
2009-08-04 20:23:33 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onTopicRemoveButtonClicked)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.topicsListView,
|
2009-09-21 00:12:47 +00:00
|
|
|
QtCore.SIGNAL(u'itemClicked(QListWidgetItem*)'),
|
2012-04-02 00:19:16 +00:00
|
|
|
self.onTopicListViewClicked)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.copyrightInsertButton,
|
2009-08-04 20:23:33 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onCopyrightInsertButtonTriggered)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.verseAddButton,
|
2009-08-04 20:23:33 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onVerseAddButtonClicked)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.verseListWidget,
|
2009-11-04 01:16:15 +00:00
|
|
|
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
|
|
|
|
self.onVerseEditButtonClicked)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.verseEditButton,
|
2009-08-04 20:23:33 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onVerseEditButtonClicked)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.verseEditAllButton,
|
2009-09-04 17:19:54 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onVerseEditAllButtonClicked)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.verseDeleteButton,
|
2009-08-04 20:23:33 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onVerseDeleteButtonClicked)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.verseListWidget,
|
2010-05-17 18:39:28 +00:00
|
|
|
QtCore.SIGNAL(u'itemClicked(QTableWidgetItem*)'),
|
2012-04-02 00:19:16 +00:00
|
|
|
self.onVerseListViewClicked)
|
2012-03-05 20:34:23 +00:00
|
|
|
QtCore.QObject.connect(self.verseOrderEdit,
|
|
|
|
QtCore.SIGNAL(u'textChanged(QString)'),
|
|
|
|
self.onVerseOrderTextChanged)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.themeAddButton,
|
2009-09-21 02:42:59 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'),
|
2012-06-04 10:51:50 +00:00
|
|
|
self.mediaitem.plugin.renderer.theme_manager.onAddTheme)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.maintenanceButton,
|
2009-08-06 14:51:38 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onMaintenanceButtonClicked)
|
2011-08-23 13:44:50 +00:00
|
|
|
QtCore.QObject.connect(self.audioAddFromFileButton,
|
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onAudioAddFromFileButtonClicked)
|
2011-08-23 21:48:46 +00:00
|
|
|
QtCore.QObject.connect(self.audioAddFromMediaButton,
|
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onAudioAddFromMediaButtonClicked)
|
2011-08-26 23:04:54 +00:00
|
|
|
QtCore.QObject.connect(self.audioRemoveButton,
|
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onAudioRemoveButtonClicked)
|
|
|
|
QtCore.QObject.connect(self.audioRemoveAllButton,
|
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onAudioRemoveAllButtonClicked)
|
2009-08-25 05:18:09 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
2010-04-16 07:31:01 +00:00
|
|
|
QtCore.SIGNAL(u'theme_update_list'), self.loadThemes)
|
2009-10-30 06:43:28 +00:00
|
|
|
self.previewButton = QtGui.QPushButton()
|
2010-06-06 10:15:12 +00:00
|
|
|
self.previewButton.setObjectName(u'previewButton')
|
2011-04-15 21:43:59 +00:00
|
|
|
self.previewButton.setText(UiStrings().SaveAndPreview)
|
2011-01-04 21:06:50 +00:00
|
|
|
self.buttonBox.addButton(
|
2009-10-30 06:43:28 +00:00
|
|
|
self.previewButton, QtGui.QDialogButtonBox.ActionRole)
|
2011-01-04 21:06:50 +00:00
|
|
|
QtCore.QObject.connect(self.buttonBox,
|
2009-10-25 18:07:23 +00:00
|
|
|
QtCore.SIGNAL(u'clicked(QAbstractButton*)'), self.onPreview)
|
2009-02-19 22:25:58 +00:00
|
|
|
# Create other objects and forms
|
2010-11-03 18:18:44 +00:00
|
|
|
self.manager = manager
|
2011-08-23 21:48:46 +00:00
|
|
|
self.verseForm = EditVerseForm(self)
|
|
|
|
self.mediaForm = MediaFilesForm(self)
|
2008-12-24 07:28:25 +00:00
|
|
|
self.initialise()
|
2011-01-04 21:06:50 +00:00
|
|
|
self.authorsListView.setSortingEnabled(False)
|
|
|
|
self.authorsListView.setAlternatingRowColors(True)
|
|
|
|
self.topicsListView.setSortingEnabled(False)
|
|
|
|
self.topicsListView.setAlternatingRowColors(True)
|
2011-08-23 21:48:46 +00:00
|
|
|
self.audioListWidget.setAlternatingRowColors(True)
|
2009-11-26 18:41:39 +00:00
|
|
|
self.findVerseSplit = re.compile(u'---\[\]---\n', re.UNICODE)
|
2010-12-16 18:20:46 +00:00
|
|
|
self.whitespace = re.compile(r'\W+', re.UNICODE)
|
2009-01-17 13:58:16 +00:00
|
|
|
|
2013-02-11 08:33:46 +00:00
|
|
|
def keyPressEvent(self, event):
|
|
|
|
"""
|
|
|
|
Reimplement the keyPressEvent to react on Return/Enter keys. When some
|
|
|
|
combo boxes have focus we do not want dialog's default action be
|
|
|
|
triggered but instead our own.
|
|
|
|
|
|
|
|
``event``
|
|
|
|
A QtGui.QKeyEvent event.
|
|
|
|
"""
|
|
|
|
if event.key() in (QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return):
|
|
|
|
if self.authorsComboBox.hasFocus() and \
|
|
|
|
self.authorsComboBox.currentText():
|
|
|
|
self.onAuthorAddButtonClicked()
|
|
|
|
return
|
|
|
|
if self.topicsComboBox.hasFocus() and \
|
|
|
|
self.topicsComboBox.currentText():
|
|
|
|
self.onTopicAddButtonClicked()
|
|
|
|
return
|
|
|
|
QtGui.QDialog.keyPressEvent(self, event)
|
|
|
|
|
2008-12-24 07:28:25 +00:00
|
|
|
def initialise(self):
|
2011-01-04 21:06:50 +00:00
|
|
|
self.verseEditButton.setEnabled(False)
|
|
|
|
self.verseDeleteButton.setEnabled(False)
|
|
|
|
self.authorRemoveButton.setEnabled(False)
|
|
|
|
self.topicRemoveButton.setEnabled(False)
|
2009-03-09 18:47:37 +00:00
|
|
|
|
|
|
|
def loadAuthors(self):
|
2010-11-03 18:18:44 +00:00
|
|
|
authors = self.manager.get_all_objects(Author,
|
2010-07-18 23:37:24 +00:00
|
|
|
order_by_ref=Author.display_name)
|
2011-01-04 21:06:50 +00:00
|
|
|
self.authorsComboBox.clear()
|
|
|
|
self.authorsComboBox.addItem(u'')
|
2010-12-11 20:31:47 +00:00
|
|
|
self.authors = []
|
2009-03-09 18:47:37 +00:00
|
|
|
for author in authors:
|
2011-01-04 21:06:50 +00:00
|
|
|
row = self.authorsComboBox.count()
|
|
|
|
self.authorsComboBox.addItem(author.display_name)
|
|
|
|
self.authorsComboBox.setItemData(
|
2009-09-21 00:12:47 +00:00
|
|
|
row, QtCore.QVariant(author.id))
|
2010-12-11 20:31:47 +00:00
|
|
|
self.authors.append(author.display_name)
|
2012-04-01 21:19:56 +00:00
|
|
|
set_case_insensitive_completer(self.authors, self.authorsComboBox)
|
2008-12-24 14:07:27 +00:00
|
|
|
|
2009-06-04 19:00:41 +00:00
|
|
|
def loadTopics(self):
|
2010-12-12 08:35:02 +00:00
|
|
|
self.topics = []
|
2011-02-04 18:17:28 +00:00
|
|
|
self.__loadObjects(Topic, self.topicsComboBox, self.topics)
|
2009-06-04 19:00:41 +00:00
|
|
|
|
2009-06-04 20:06:32 +00:00
|
|
|
def loadBooks(self):
|
2010-12-12 08:35:02 +00:00
|
|
|
self.books = []
|
2011-02-04 18:17:28 +00:00
|
|
|
self.__loadObjects(Book, self.songBookComboBox, self.books)
|
|
|
|
|
2011-02-04 19:58:44 +00:00
|
|
|
def __loadObjects(self, cls, combo, cache):
|
|
|
|
objects = self.manager.get_all_objects(cls, order_by_ref=cls.name)
|
2011-02-04 18:17:28 +00:00
|
|
|
combo.clear()
|
|
|
|
combo.addItem(u'')
|
|
|
|
for object in objects:
|
|
|
|
row = combo.count()
|
|
|
|
combo.addItem(object.name)
|
|
|
|
cache.append(object.name)
|
|
|
|
combo.setItemData(row, QtCore.QVariant(object.id))
|
2012-04-01 21:19:56 +00:00
|
|
|
set_case_insensitive_completer(cache, combo)
|
2009-06-04 20:06:32 +00:00
|
|
|
|
2009-06-14 07:02:58 +00:00
|
|
|
def loadThemes(self, theme_list):
|
2011-01-04 21:06:50 +00:00
|
|
|
self.themeComboBox.clear()
|
|
|
|
self.themeComboBox.addItem(u'')
|
2012-06-09 15:46:01 +00:00
|
|
|
self.themes = theme_list
|
|
|
|
self.themeComboBox.addItems(theme_list)
|
2012-04-01 21:19:56 +00:00
|
|
|
set_case_insensitive_completer(self.themes, self.themeComboBox)
|
2009-06-14 07:02:58 +00:00
|
|
|
|
2011-08-23 21:48:46 +00:00
|
|
|
def loadMediaFiles(self):
|
|
|
|
self.audioAddFromMediaButton.setVisible(False)
|
|
|
|
for plugin in self.parent().pluginManager.plugins:
|
2012-06-09 15:46:01 +00:00
|
|
|
if plugin.name == u'media' and plugin.status == PluginStatus.Active:
|
2011-08-23 21:48:46 +00:00
|
|
|
self.audioAddFromMediaButton.setVisible(True)
|
|
|
|
self.mediaForm.populateFiles(
|
2011-12-07 20:25:12 +00:00
|
|
|
plugin.mediaItem.getList(MediaType.Audio))
|
2011-08-23 21:48:46 +00:00
|
|
|
break
|
|
|
|
|
2009-06-12 17:20:40 +00:00
|
|
|
def newSong(self):
|
2009-06-13 06:46:13 +00:00
|
|
|
log.debug(u'New Song')
|
2011-02-15 01:58:18 +00:00
|
|
|
self.song = None
|
2010-11-28 15:10:51 +00:00
|
|
|
self.initialise()
|
2011-01-04 21:06:50 +00:00
|
|
|
self.songTabWidget.setCurrentIndex(0)
|
2012-04-02 11:38:22 +00:00
|
|
|
self.titleEdit.clear()
|
|
|
|
self.alternativeEdit.clear()
|
|
|
|
self.copyrightEdit.clear()
|
|
|
|
self.verseOrderEdit.clear()
|
|
|
|
self.commentsEdit.clear()
|
|
|
|
self.CCLNumberEdit.clear()
|
2011-01-04 21:06:50 +00:00
|
|
|
self.verseListWidget.clear()
|
|
|
|
self.verseListWidget.setRowCount(0)
|
|
|
|
self.authorsListView.clear()
|
|
|
|
self.topicsListView.clear()
|
2011-08-31 07:49:57 +00:00
|
|
|
self.audioListWidget.clear()
|
2011-01-04 21:06:50 +00:00
|
|
|
self.titleEdit.setFocus(QtCore.Qt.OtherFocusReason)
|
2012-04-02 11:38:22 +00:00
|
|
|
self.songBookNumberEdit.clear()
|
2009-07-18 07:30:26 +00:00
|
|
|
self.loadAuthors()
|
|
|
|
self.loadTopics()
|
|
|
|
self.loadBooks()
|
2011-08-23 21:48:46 +00:00
|
|
|
self.loadMediaFiles()
|
2011-01-04 21:06:50 +00:00
|
|
|
self.themeComboBox.setCurrentIndex(0)
|
2010-07-21 10:30:29 +00:00
|
|
|
# it's a new song to preview is not possible
|
2010-03-11 12:53:20 +00:00
|
|
|
self.previewButton.setVisible(False)
|
2009-06-12 17:20:40 +00:00
|
|
|
|
2010-11-28 15:10:51 +00:00
|
|
|
def loadSong(self, id, preview=False):
|
|
|
|
"""
|
|
|
|
Loads a song.
|
|
|
|
|
|
|
|
``id``
|
|
|
|
The song id (int).
|
|
|
|
|
|
|
|
``preview``
|
|
|
|
Should be ``True`` if the song is also previewed (boolean).
|
|
|
|
"""
|
2009-06-13 06:46:13 +00:00
|
|
|
log.debug(u'Load Song')
|
2010-11-28 15:10:51 +00:00
|
|
|
self.initialise()
|
2011-01-04 21:06:50 +00:00
|
|
|
self.songTabWidget.setCurrentIndex(0)
|
2009-07-18 07:30:26 +00:00
|
|
|
self.loadAuthors()
|
|
|
|
self.loadTopics()
|
|
|
|
self.loadBooks()
|
2011-08-23 21:48:46 +00:00
|
|
|
self.loadMediaFiles()
|
2010-11-03 18:18:44 +00:00
|
|
|
self.song = self.manager.get_object(Song, id)
|
2011-01-04 21:06:50 +00:00
|
|
|
self.titleEdit.setText(self.song.title)
|
2012-04-01 14:22:32 +00:00
|
|
|
self.alternativeEdit.setText(
|
|
|
|
self.song.alternate_title if self.song.alternate_title else u'')
|
2009-06-13 06:46:13 +00:00
|
|
|
if self.song.song_book_id != 0:
|
2010-11-03 18:18:44 +00:00
|
|
|
book_name = self.manager.get_object(Book, self.song.song_book_id)
|
2011-06-29 08:04:14 +00:00
|
|
|
find_and_set_in_combo_box(
|
|
|
|
self.songBookComboBox, unicode(book_name.name))
|
2009-11-03 19:01:53 +00:00
|
|
|
if self.song.theme_name:
|
2011-06-29 08:04:14 +00:00
|
|
|
find_and_set_in_combo_box(
|
|
|
|
self.themeComboBox, unicode(self.song.theme_name))
|
2012-04-01 14:22:32 +00:00
|
|
|
self.copyrightEdit.setText(
|
|
|
|
self.song.copyright if self.song.copyright else u'')
|
|
|
|
self.commentsEdit.setPlainText(
|
|
|
|
self.song.comments if self.song.comments else u'')
|
|
|
|
self.CCLNumberEdit.setText(
|
|
|
|
self.song.ccli_number if self.song.ccli_number else u'')
|
|
|
|
self.songBookNumberEdit.setText(
|
|
|
|
self.song.song_number if self.song.song_number else u'')
|
2010-07-21 10:30:29 +00:00
|
|
|
# lazy xml migration for now
|
2011-01-04 21:06:50 +00:00
|
|
|
self.verseListWidget.clear()
|
|
|
|
self.verseListWidget.setRowCount(0)
|
2010-06-18 19:55:45 +00:00
|
|
|
# This is just because occasionally the lyrics come back as a "buffer"
|
2010-06-13 20:29:47 +00:00
|
|
|
if isinstance(self.song.lyrics, buffer):
|
|
|
|
self.song.lyrics = unicode(self.song.lyrics)
|
2011-02-18 00:48:58 +00:00
|
|
|
verse_tags_translated = False
|
2009-06-12 17:20:40 +00:00
|
|
|
if self.song.lyrics.startswith(u'<?xml version='):
|
2011-01-09 16:52:31 +00:00
|
|
|
songXML = SongXML()
|
2012-06-16 15:51:04 +00:00
|
|
|
verse_list = songXML.get_verses(self.song.lyrics)
|
|
|
|
for count, verse in enumerate(verse_list):
|
2011-01-04 21:06:50 +00:00
|
|
|
self.verseListWidget.setRowCount(
|
|
|
|
self.verseListWidget.rowCount() + 1)
|
2011-02-17 19:46:01 +00:00
|
|
|
# This silently migrates from localized verse type markup.
|
|
|
|
# If we trusted the database, this would be unnecessary.
|
2011-02-18 00:48:58 +00:00
|
|
|
verse_tag = verse[0][u'type']
|
2011-02-17 15:05:58 +00:00
|
|
|
index = None
|
2011-02-18 00:48:58 +00:00
|
|
|
if len(verse_tag) > 1:
|
|
|
|
index = VerseType.from_translated_string(verse_tag)
|
2011-02-17 15:05:58 +00:00
|
|
|
if index is None:
|
2011-11-24 22:34:27 +00:00
|
|
|
index = VerseType.from_string(verse_tag, None)
|
2011-02-18 00:48:58 +00:00
|
|
|
else:
|
|
|
|
verse_tags_translated = True
|
2011-02-17 15:05:58 +00:00
|
|
|
if index is None:
|
2011-02-18 00:48:58 +00:00
|
|
|
index = VerseType.from_tag(verse_tag)
|
2011-02-17 15:05:58 +00:00
|
|
|
verse[0][u'type'] = VerseType.Tags[index]
|
2011-03-14 22:29:02 +00:00
|
|
|
if verse[0][u'label'] == u'':
|
|
|
|
verse[0][u'label'] = u'1'
|
2011-02-18 00:48:58 +00:00
|
|
|
verse_def = u'%s%s' % (verse[0][u'type'], verse[0][u'label'])
|
2010-05-17 18:39:28 +00:00
|
|
|
item = QtGui.QTableWidgetItem(verse[1])
|
2011-02-18 00:48:58 +00:00
|
|
|
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(verse_def))
|
2011-01-04 21:06:50 +00:00
|
|
|
self.verseListWidget.setItem(count, 0, item)
|
2009-06-12 17:20:40 +00:00
|
|
|
else:
|
|
|
|
verses = self.song.lyrics.split(u'\n\n')
|
2009-11-22 20:33:39 +00:00
|
|
|
for count, verse in enumerate(verses):
|
2011-01-04 21:06:50 +00:00
|
|
|
self.verseListWidget.setRowCount(
|
|
|
|
self.verseListWidget.rowCount() + 1)
|
2010-05-17 18:39:28 +00:00
|
|
|
item = QtGui.QTableWidgetItem(verse)
|
2011-02-18 00:48:58 +00:00
|
|
|
verse_def = u'%s%s' % \
|
2011-02-17 15:05:58 +00:00
|
|
|
(VerseType.Tags[VerseType.Verse], unicode(count + 1))
|
2011-02-18 00:48:58 +00:00
|
|
|
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(verse_def))
|
2011-01-04 21:06:50 +00:00
|
|
|
self.verseListWidget.setItem(count, 0, item)
|
2011-02-18 00:48:58 +00:00
|
|
|
if self.song.verse_order:
|
|
|
|
# we translate verse order
|
|
|
|
translated = []
|
|
|
|
for verse_def in self.song.verse_order.split():
|
|
|
|
verse_index = None
|
|
|
|
if verse_tags_translated:
|
2011-11-24 22:34:27 +00:00
|
|
|
verse_index = VerseType.from_translated_tag(verse_def[0],
|
|
|
|
None)
|
2011-02-18 00:48:58 +00:00
|
|
|
if verse_index is None:
|
|
|
|
verse_index = VerseType.from_tag(verse_def[0])
|
|
|
|
verse_tag = VerseType.TranslatedTags[verse_index].upper()
|
|
|
|
translated.append(u'%s%s' % (verse_tag, verse_def[1:]))
|
|
|
|
self.verseOrderEdit.setText(u' '.join(translated))
|
|
|
|
else:
|
|
|
|
self.verseOrderEdit.setText(u'')
|
2010-05-18 19:29:40 +00:00
|
|
|
self.tagRows()
|
2009-06-11 05:13:10 +00:00
|
|
|
# clear the results
|
2011-01-04 21:06:50 +00:00
|
|
|
self.authorsListView.clear()
|
2009-01-12 19:31:29 +00:00
|
|
|
for author in self.song.authors:
|
2009-06-11 21:14:12 +00:00
|
|
|
author_name = QtGui.QListWidgetItem(unicode(author.display_name))
|
2009-06-11 05:13:10 +00:00
|
|
|
author_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(author.id))
|
2011-01-04 21:06:50 +00:00
|
|
|
self.authorsListView.addItem(author_name)
|
2009-06-12 17:20:40 +00:00
|
|
|
# clear the results
|
2011-01-04 21:06:50 +00:00
|
|
|
self.topicsListView.clear()
|
2009-06-14 06:30:09 +00:00
|
|
|
for topic in self.song.topics:
|
|
|
|
topic_name = QtGui.QListWidgetItem(unicode(topic.name))
|
|
|
|
topic_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id))
|
2011-01-04 21:06:50 +00:00
|
|
|
self.topicsListView.addItem(topic_name)
|
2011-08-23 13:44:50 +00:00
|
|
|
self.audioListWidget.clear()
|
2011-08-24 12:22:39 +00:00
|
|
|
for media in self.song.media_files:
|
2011-11-26 21:26:50 +00:00
|
|
|
media_file = QtGui.QListWidgetItem(
|
|
|
|
os.path.split(media.file_name)[1])
|
|
|
|
media_file.setData(QtCore.Qt.UserRole,
|
|
|
|
QtCore.QVariant(media.file_name))
|
2011-08-24 12:22:39 +00:00
|
|
|
self.audioListWidget.addItem(media_file)
|
2011-01-04 21:06:50 +00:00
|
|
|
self.titleEdit.setFocus(QtCore.Qt.OtherFocusReason)
|
2011-03-17 12:32:45 +00:00
|
|
|
# Hide or show the preview button.
|
|
|
|
self.previewButton.setVisible(preview)
|
2008-12-01 13:15:31 +00:00
|
|
|
|
2010-05-18 19:29:40 +00:00
|
|
|
def tagRows(self):
|
|
|
|
"""
|
|
|
|
Tag the Song List rows based on the verse list
|
|
|
|
"""
|
2011-02-18 00:48:58 +00:00
|
|
|
row_label = []
|
2012-05-01 11:00:02 +00:00
|
|
|
for row in range(self.verseListWidget.rowCount()):
|
2011-01-04 21:06:50 +00:00
|
|
|
item = self.verseListWidget.item(row, 0)
|
2011-02-18 00:48:58 +00:00
|
|
|
verse_def = unicode(item.data(QtCore.Qt.UserRole).toString())
|
|
|
|
verse_tag = VerseType.translated_tag(verse_def[0])
|
|
|
|
row_def = u'%s%s' % (verse_tag, verse_def[1:])
|
|
|
|
row_label.append(row_def)
|
|
|
|
self.verseListWidget.setVerticalHeaderLabels(row_label)
|
2011-03-17 12:32:45 +00:00
|
|
|
self.verseListWidget.resizeRowsToContents()
|
|
|
|
self.verseListWidget.repaint()
|
2010-05-18 19:29:40 +00:00
|
|
|
|
2009-08-04 20:23:33 +00:00
|
|
|
def onAuthorAddButtonClicked(self):
|
2011-01-04 21:06:50 +00:00
|
|
|
item = int(self.authorsComboBox.currentIndex())
|
2012-03-22 20:03:11 +00:00
|
|
|
text = unicode(self.authorsComboBox.currentText()).strip(u' \r\n\t')
|
2012-03-22 20:25:11 +00:00
|
|
|
# This if statement is for OS X, which doesn't seem to work well with
|
|
|
|
# the QCompleter autocompletion class. See bug #812628.
|
2012-03-22 20:03:11 +00:00
|
|
|
if text in self.authors:
|
2012-03-22 20:16:49 +00:00
|
|
|
# Index 0 is a blank string, so add 1
|
|
|
|
item = self.authors.index(text) + 1
|
2010-06-13 20:29:47 +00:00
|
|
|
if item == 0 and text:
|
|
|
|
if QtGui.QMessageBox.question(self,
|
2010-06-18 19:55:45 +00:00
|
|
|
translate('SongsPlugin.EditSongForm', 'Add Author'),
|
|
|
|
translate('SongsPlugin.EditSongForm', 'This author does not '
|
2010-07-21 10:30:29 +00:00
|
|
|
'exist, do you want to add them?'),
|
2010-06-13 20:29:47 +00:00
|
|
|
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
|
|
|
|
QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes:
|
2010-07-21 13:13:03 +00:00
|
|
|
if text.find(u' ') == -1:
|
2010-07-21 10:30:29 +00:00
|
|
|
author = Author.populate(first_name=u'', last_name=u'',
|
|
|
|
display_name=text)
|
|
|
|
else:
|
|
|
|
author = Author.populate(first_name=text.rsplit(u' ', 1)[0],
|
|
|
|
last_name=text.rsplit(u' ', 1)[1], display_name=text)
|
2011-01-17 00:52:00 +00:00
|
|
|
self.manager.save_object(author)
|
2011-02-01 00:33:50 +00:00
|
|
|
self.__addAuthorToList(author)
|
2010-06-13 20:29:47 +00:00
|
|
|
self.loadAuthors()
|
2011-01-04 21:06:50 +00:00
|
|
|
self.authorsComboBox.setCurrentIndex(0)
|
2010-06-13 20:29:47 +00:00
|
|
|
else:
|
|
|
|
return
|
|
|
|
elif item > 0:
|
2011-01-04 21:06:50 +00:00
|
|
|
item_id = (self.authorsComboBox.itemData(item)).toInt()[0]
|
2010-11-03 18:18:44 +00:00
|
|
|
author = self.manager.get_object(Author, item_id)
|
2011-01-04 21:06:50 +00:00
|
|
|
if self.authorsListView.findItems(unicode(author.display_name),
|
2010-08-28 19:32:24 +00:00
|
|
|
QtCore.Qt.MatchExactly):
|
2011-02-02 23:12:31 +00:00
|
|
|
critical_error_message_box(
|
2011-01-15 19:24:50 +00:00
|
|
|
message=translate('SongsPlugin.EditSongForm',
|
|
|
|
'This author is already in the list.'))
|
2010-07-19 18:34:03 +00:00
|
|
|
else:
|
2011-02-01 00:33:50 +00:00
|
|
|
self.__addAuthorToList(author)
|
2011-01-04 21:06:50 +00:00
|
|
|
self.authorsComboBox.setCurrentIndex(0)
|
2010-06-13 20:29:47 +00:00
|
|
|
else:
|
2011-04-15 21:43:59 +00:00
|
|
|
QtGui.QMessageBox.warning(self, UiStrings().NISs,
|
2010-06-18 19:55:45 +00:00
|
|
|
translate('SongsPlugin.EditSongForm', 'You have not selected '
|
2010-07-21 10:30:29 +00:00
|
|
|
'a valid author. Either select an author from the list, '
|
|
|
|
'or type in a new author and click the "Add Author to '
|
2010-07-31 02:06:44 +00:00
|
|
|
'Song" button to add the new author.'))
|
2009-06-13 06:46:13 +00:00
|
|
|
|
2011-02-01 00:33:50 +00:00
|
|
|
def __addAuthorToList(self, author):
|
|
|
|
"""
|
|
|
|
Add an author to the author list.
|
|
|
|
"""
|
|
|
|
author_item = QtGui.QListWidgetItem(unicode(author.display_name))
|
|
|
|
author_item.setData(QtCore.Qt.UserRole, QtCore.QVariant(author.id))
|
|
|
|
self.authorsListView.addItem(author_item)
|
|
|
|
|
2012-04-02 00:19:16 +00:00
|
|
|
def onAuthorsListViewClicked(self):
|
2011-01-04 21:06:50 +00:00
|
|
|
if self.authorsListView.count() > 1:
|
|
|
|
self.authorRemoveButton.setEnabled(True)
|
2009-06-13 06:46:13 +00:00
|
|
|
|
2009-08-04 20:23:33 +00:00
|
|
|
def onAuthorRemoveButtonClicked(self):
|
2011-01-04 21:06:50 +00:00
|
|
|
self.authorRemoveButton.setEnabled(False)
|
|
|
|
item = self.authorsListView.currentItem()
|
|
|
|
row = self.authorsListView.row(item)
|
|
|
|
self.authorsListView.takeItem(row)
|
2009-06-14 06:30:09 +00:00
|
|
|
|
2009-08-04 20:23:33 +00:00
|
|
|
def onTopicAddButtonClicked(self):
|
2011-01-04 21:06:50 +00:00
|
|
|
item = int(self.topicsComboBox.currentIndex())
|
|
|
|
text = unicode(self.topicsComboBox.currentText())
|
2010-06-13 20:29:47 +00:00
|
|
|
if item == 0 and text:
|
|
|
|
if QtGui.QMessageBox.question(self,
|
2010-06-18 19:55:45 +00:00
|
|
|
translate('SongsPlugin.EditSongForm', 'Add Topic'),
|
|
|
|
translate('SongsPlugin.EditSongForm', 'This topic does not '
|
2010-07-21 10:30:29 +00:00
|
|
|
'exist, do you want to add it?'),
|
2010-06-13 20:29:47 +00:00
|
|
|
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
|
|
|
|
QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes:
|
|
|
|
topic = Topic.populate(name=text)
|
2011-01-17 00:52:00 +00:00
|
|
|
self.manager.save_object(topic)
|
2010-06-13 20:29:47 +00:00
|
|
|
topic_item = QtGui.QListWidgetItem(unicode(topic.name))
|
2010-06-18 22:13:10 +00:00
|
|
|
topic_item.setData(QtCore.Qt.UserRole,
|
|
|
|
QtCore.QVariant(topic.id))
|
2011-01-04 21:06:50 +00:00
|
|
|
self.topicsListView.addItem(topic_item)
|
2010-06-13 20:29:47 +00:00
|
|
|
self.loadTopics()
|
2011-01-04 21:06:50 +00:00
|
|
|
self.topicsComboBox.setCurrentIndex(0)
|
2010-06-13 20:29:47 +00:00
|
|
|
else:
|
|
|
|
return
|
|
|
|
elif item > 0:
|
2011-01-04 21:06:50 +00:00
|
|
|
item_id = (self.topicsComboBox.itemData(item)).toInt()[0]
|
2010-11-03 18:18:44 +00:00
|
|
|
topic = self.manager.get_object(Topic, item_id)
|
2011-01-04 21:06:50 +00:00
|
|
|
if self.topicsListView.findItems(unicode(topic.name),
|
2010-08-28 19:32:24 +00:00
|
|
|
QtCore.Qt.MatchExactly):
|
2011-02-02 23:12:31 +00:00
|
|
|
critical_error_message_box(
|
2011-01-15 19:24:50 +00:00
|
|
|
message=translate('SongsPlugin.EditSongForm',
|
|
|
|
'This topic is already in the list.'))
|
2010-07-19 18:34:03 +00:00
|
|
|
else:
|
|
|
|
topic_item = QtGui.QListWidgetItem(unicode(topic.name))
|
|
|
|
topic_item.setData(QtCore.Qt.UserRole,
|
|
|
|
QtCore.QVariant(topic.id))
|
2011-01-04 21:06:50 +00:00
|
|
|
self.topicsListView.addItem(topic_item)
|
|
|
|
self.topicsComboBox.setCurrentIndex(0)
|
2010-06-13 20:29:47 +00:00
|
|
|
else:
|
2011-04-15 21:43:59 +00:00
|
|
|
QtGui.QMessageBox.warning(self, UiStrings().NISs,
|
2010-06-18 19:55:45 +00:00
|
|
|
translate('SongsPlugin.EditSongForm', 'You have not selected '
|
2010-07-21 10:30:29 +00:00
|
|
|
'a valid topic. Either select a topic from the list, or '
|
|
|
|
'type in a new topic and click the "Add Topic to Song" '
|
2010-07-31 02:06:44 +00:00
|
|
|
'button to add the new topic.'))
|
2009-06-14 06:30:09 +00:00
|
|
|
|
2012-04-02 00:19:16 +00:00
|
|
|
def onTopicListViewClicked(self):
|
2011-01-04 21:06:50 +00:00
|
|
|
self.topicRemoveButton.setEnabled(True)
|
2009-06-14 06:30:09 +00:00
|
|
|
|
2009-08-04 20:23:33 +00:00
|
|
|
def onTopicRemoveButtonClicked(self):
|
2011-01-04 21:06:50 +00:00
|
|
|
self.topicRemoveButton.setEnabled(False)
|
|
|
|
item = self.topicsListView.currentItem()
|
|
|
|
row = self.topicsListView.row(item)
|
|
|
|
self.topicsListView.takeItem(row)
|
2009-01-17 13:58:16 +00:00
|
|
|
|
2012-04-02 00:19:16 +00:00
|
|
|
def onVerseListViewClicked(self):
|
2011-01-04 21:06:50 +00:00
|
|
|
self.verseEditButton.setEnabled(True)
|
|
|
|
self.verseDeleteButton.setEnabled(True)
|
2009-06-13 06:46:13 +00:00
|
|
|
|
2009-08-04 20:23:33 +00:00
|
|
|
def onVerseAddButtonClicked(self):
|
2011-08-28 20:51:44 +00:00
|
|
|
self.verseForm.setVerse(u'', True)
|
|
|
|
if self.verseForm.exec_():
|
|
|
|
after_text, verse_tag, verse_num = self.verseForm.getVerse()
|
2011-02-18 00:48:58 +00:00
|
|
|
verse_def = u'%s%s' % (verse_tag, verse_num)
|
2011-02-18 08:25:43 +00:00
|
|
|
item = QtGui.QTableWidgetItem(after_text)
|
2011-02-18 00:48:58 +00:00
|
|
|
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(verse_def))
|
|
|
|
item.setText(after_text)
|
2011-01-04 21:06:50 +00:00
|
|
|
self.verseListWidget.setRowCount(
|
|
|
|
self.verseListWidget.rowCount() + 1)
|
|
|
|
self.verseListWidget.setItem(
|
2011-03-17 12:32:45 +00:00
|
|
|
self.verseListWidget.rowCount() - 1, 0, item)
|
2010-05-18 19:29:40 +00:00
|
|
|
self.tagRows()
|
2012-03-31 09:58:34 +00:00
|
|
|
# Check if all verse tags are used.
|
|
|
|
self.onVerseOrderTextChanged(self.verseOrderEdit.text())
|
2009-03-07 21:38:59 +00:00
|
|
|
|
2009-08-04 20:23:33 +00:00
|
|
|
def onVerseEditButtonClicked(self):
|
2011-01-04 21:06:50 +00:00
|
|
|
item = self.verseListWidget.currentItem()
|
2009-11-03 19:01:53 +00:00
|
|
|
if item:
|
2012-06-16 15:51:04 +00:00
|
|
|
temp_text = item.text()
|
2012-06-16 16:12:54 +00:00
|
|
|
verse_id = unicode(item.data(QtCore.Qt.UserRole).toString())
|
|
|
|
self.verseForm.setVerse(temp_text, True, verse_id)
|
2011-08-28 20:51:44 +00:00
|
|
|
if self.verseForm.exec_():
|
|
|
|
after_text, verse_tag, verse_num = self.verseForm.getVerse()
|
2011-02-18 00:48:58 +00:00
|
|
|
verse_def = u'%s%s' % (verse_tag, verse_num)
|
|
|
|
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(verse_def))
|
|
|
|
item.setText(after_text)
|
2011-09-04 09:26:13 +00:00
|
|
|
# number of lines has changed, repaint the list moving the data
|
2012-06-16 15:51:04 +00:00
|
|
|
if len(temp_text.split(u'\n')) != len(after_text.split(u'\n')):
|
|
|
|
temp_list = []
|
|
|
|
temp_ids = []
|
2012-05-01 11:00:02 +00:00
|
|
|
for row in range(self.verseListWidget.rowCount()):
|
2012-06-16 15:51:04 +00:00
|
|
|
item = self.verseListWidget.item(row, 0)
|
|
|
|
temp_list.append(item.text())
|
|
|
|
temp_ids.append(item.data(QtCore.Qt.UserRole))
|
2011-01-04 21:06:50 +00:00
|
|
|
self.verseListWidget.clear()
|
2012-06-16 15:51:04 +00:00
|
|
|
for row, entry in enumerate(temp_list):
|
|
|
|
item = QtGui.QTableWidgetItem(entry, 0)
|
|
|
|
item.setData(QtCore.Qt.UserRole, temp_ids[row])
|
2011-01-04 21:06:50 +00:00
|
|
|
self.verseListWidget.setItem(row, 0, item)
|
2010-05-18 19:29:40 +00:00
|
|
|
self.tagRows()
|
2012-03-31 09:58:34 +00:00
|
|
|
# Check if all verse tags are used.
|
|
|
|
self.onVerseOrderTextChanged(self.verseOrderEdit.text())
|
2009-03-07 21:38:59 +00:00
|
|
|
|
2009-09-04 17:19:54 +00:00
|
|
|
def onVerseEditAllButtonClicked(self):
|
|
|
|
verse_list = u''
|
2011-01-04 21:06:50 +00:00
|
|
|
if self.verseListWidget.rowCount() > 0:
|
2012-05-01 11:00:02 +00:00
|
|
|
for row in range(self.verseListWidget.rowCount()):
|
2011-01-04 21:06:50 +00:00
|
|
|
item = self.verseListWidget.item(row, 0)
|
2010-06-09 21:15:37 +00:00
|
|
|
field = unicode(item.data(QtCore.Qt.UserRole).toString())
|
2011-02-18 00:48:58 +00:00
|
|
|
verse_tag = VerseType.translated_name(field[0])
|
|
|
|
verse_num = field[1:]
|
|
|
|
verse_list += u'---[%s:%s]---\n' % (verse_tag, verse_num)
|
2009-09-04 17:19:54 +00:00
|
|
|
verse_list += item.text()
|
2009-11-26 18:41:39 +00:00
|
|
|
verse_list += u'\n'
|
2011-08-28 20:51:44 +00:00
|
|
|
self.verseForm.setVerse(verse_list)
|
2009-09-04 17:19:54 +00:00
|
|
|
else:
|
2011-08-28 20:51:44 +00:00
|
|
|
self.verseForm.setVerse(u'')
|
|
|
|
if not self.verseForm.exec_():
|
2011-03-17 12:32:45 +00:00
|
|
|
return
|
2011-08-28 20:51:44 +00:00
|
|
|
verse_list = self.verseForm.getVerseAll()
|
2011-03-17 12:32:45 +00:00
|
|
|
verse_list = unicode(verse_list.replace(u'\r\n', u'\n'))
|
|
|
|
self.verseListWidget.clear()
|
|
|
|
self.verseListWidget.setRowCount(0)
|
|
|
|
for row in self.findVerseSplit.split(verse_list):
|
|
|
|
for match in row.split(u'---['):
|
|
|
|
for count, parts in enumerate(match.split(u']---\n')):
|
|
|
|
if count == 0:
|
2012-07-22 20:20:53 +00:00
|
|
|
if len(parts) == 0:
|
|
|
|
continue
|
2011-03-17 12:32:45 +00:00
|
|
|
# handling carefully user inputted versetags
|
|
|
|
separator = parts.find(u':')
|
|
|
|
if separator >= 0:
|
|
|
|
verse_name = parts[0:separator].strip()
|
|
|
|
verse_num = parts[separator+1:].strip()
|
|
|
|
else:
|
|
|
|
verse_name = parts
|
|
|
|
verse_num = u'1'
|
|
|
|
verse_index = VerseType.from_loose_input(verse_name)
|
|
|
|
verse_tag = VerseType.Tags[verse_index]
|
|
|
|
# Later we need to handle v1a as well.
|
|
|
|
#regex = re.compile(r'(\d+\w.)')
|
|
|
|
regex = re.compile(r'\D*(\d+)\D*')
|
|
|
|
match = regex.match(verse_num)
|
|
|
|
if match:
|
|
|
|
verse_num = match.group(1)
|
|
|
|
else:
|
|
|
|
verse_num = u'1'
|
|
|
|
verse_def = u'%s%s' % (verse_tag, verse_num)
|
|
|
|
else:
|
|
|
|
if parts.endswith(u'\n'):
|
|
|
|
parts = parts.rstrip(u'\n')
|
|
|
|
item = QtGui.QTableWidgetItem(parts)
|
|
|
|
item.setData(QtCore.Qt.UserRole,
|
|
|
|
QtCore.QVariant(verse_def))
|
|
|
|
self.verseListWidget.setRowCount(
|
|
|
|
self.verseListWidget.rowCount() + 1)
|
|
|
|
self.verseListWidget.setItem(
|
|
|
|
self.verseListWidget.rowCount() - 1, 0, item)
|
|
|
|
self.tagRows()
|
|
|
|
self.verseEditButton.setEnabled(False)
|
|
|
|
self.verseDeleteButton.setEnabled(False)
|
2012-03-31 09:58:34 +00:00
|
|
|
# Check if all verse tags are used.
|
|
|
|
self.onVerseOrderTextChanged(self.verseOrderEdit.text())
|
2009-09-04 17:19:54 +00:00
|
|
|
|
2009-08-04 20:23:33 +00:00
|
|
|
def onVerseDeleteButtonClicked(self):
|
2011-01-04 21:06:50 +00:00
|
|
|
self.verseListWidget.removeRow(self.verseListWidget.currentRow())
|
2011-03-18 19:15:45 +00:00
|
|
|
if not self.verseListWidget.selectedItems():
|
|
|
|
self.verseEditButton.setEnabled(False)
|
|
|
|
self.verseDeleteButton.setEnabled(False)
|
2009-03-07 21:38:59 +00:00
|
|
|
|
2012-03-05 20:34:23 +00:00
|
|
|
def onVerseOrderTextChanged(self, text):
|
2012-03-11 21:32:43 +00:00
|
|
|
verses = []
|
|
|
|
verse_names = []
|
|
|
|
order = self.__extractVerseOrder(text)
|
2012-05-01 11:00:02 +00:00
|
|
|
for index in range(self.verseListWidget.rowCount()):
|
2012-03-11 21:32:43 +00:00
|
|
|
verse = self.verseListWidget.item(index, 0)
|
|
|
|
verse = unicode(verse.data(QtCore.Qt.UserRole).toString())
|
|
|
|
if verse not in verse_names:
|
|
|
|
verses.append(verse)
|
|
|
|
verse_names.append(u'%s%s' % (
|
|
|
|
VerseType.translated_tag(verse[0]), verse[1:]))
|
|
|
|
verses_not_used = []
|
2012-03-12 22:12:16 +00:00
|
|
|
for verse in verses:
|
2012-03-11 21:32:43 +00:00
|
|
|
if not verse in order:
|
|
|
|
verses_not_used.append(verse)
|
2013-04-18 17:53:01 +00:00
|
|
|
self.warningLabel.setVisible(len(verses_not_used) > 0 and bool(text))
|
2012-03-05 20:34:23 +00:00
|
|
|
|
2012-03-11 21:32:43 +00:00
|
|
|
def __extractVerseOrder(self, verse_order):
|
2012-03-05 20:34:23 +00:00
|
|
|
order = []
|
2012-03-11 21:32:43 +00:00
|
|
|
order_names = unicode(verse_order).split()
|
2012-03-05 20:34:23 +00:00
|
|
|
for item in order_names:
|
|
|
|
if len(item) == 1:
|
|
|
|
verse_index = VerseType.from_translated_tag(item, None)
|
|
|
|
if verse_index is not None:
|
|
|
|
order.append(VerseType.Tags[verse_index] + u'1')
|
|
|
|
else:
|
|
|
|
# it matches no verses anyway
|
|
|
|
order.append(u'')
|
|
|
|
else:
|
|
|
|
verse_index = VerseType.from_translated_tag(item[0], None)
|
|
|
|
if verse_index is None:
|
|
|
|
# it matches no verses anyway
|
|
|
|
order.append(u'')
|
|
|
|
else:
|
|
|
|
verse_tag = VerseType.Tags[verse_index]
|
|
|
|
verse_num = item[1:].lower()
|
|
|
|
order.append(verse_tag + verse_num)
|
2012-03-11 21:32:43 +00:00
|
|
|
return order
|
|
|
|
|
|
|
|
def __validateVerseList(self, verse_order, verse_count):
|
2012-03-05 20:34:23 +00:00
|
|
|
verses = []
|
2012-03-11 21:32:43 +00:00
|
|
|
invalid_verses = []
|
2012-03-05 20:34:23 +00:00
|
|
|
verse_names = []
|
2012-03-11 21:32:43 +00:00
|
|
|
order_names = unicode(verse_order).split()
|
|
|
|
order = self.__extractVerseOrder(verse_order)
|
2012-05-01 11:00:02 +00:00
|
|
|
for index in range(verse_count):
|
2012-03-05 20:34:23 +00:00
|
|
|
verse = self.verseListWidget.item(index, 0)
|
|
|
|
verse = unicode(verse.data(QtCore.Qt.UserRole).toString())
|
|
|
|
if verse not in verse_names:
|
|
|
|
verses.append(verse)
|
|
|
|
verse_names.append(u'%s%s' % (
|
|
|
|
VerseType.translated_tag(verse[0]), verse[1:]))
|
|
|
|
for count, item in enumerate(order):
|
|
|
|
if item not in verses:
|
2012-03-11 21:32:43 +00:00
|
|
|
invalid_verses.append(order_names[count])
|
|
|
|
if invalid_verses:
|
|
|
|
valid = create_separated_list(verse_names)
|
|
|
|
if len(invalid_verses) > 1:
|
|
|
|
critical_error_message_box(message=unicode(translate(
|
|
|
|
'SongsPlugin.EditSongForm', 'The verse order is invalid. '
|
|
|
|
'There are no verses corresponding to %s. Valid entries '
|
|
|
|
'are %s.')) % (u', '.join(invalid_verses), valid))
|
|
|
|
else:
|
|
|
|
critical_error_message_box(message=unicode(translate(
|
|
|
|
'SongsPlugin.EditSongForm', 'The verse order is invalid. '
|
|
|
|
'There is no verse corresponding to %s. Valid entries '
|
|
|
|
'are %s.')) % (invalid_verses[0], valid))
|
|
|
|
return len(invalid_verses) == 0
|
2012-03-05 20:34:23 +00:00
|
|
|
|
2012-03-11 21:32:43 +00:00
|
|
|
def __validateSong(self):
|
2009-01-12 19:31:29 +00:00
|
|
|
"""
|
2011-01-17 00:52:00 +00:00
|
|
|
Check the validity of the song.
|
2009-01-17 13:58:16 +00:00
|
|
|
"""
|
2011-02-25 17:05:01 +00:00
|
|
|
# This checks data in the form *not* self.song. self.song is still
|
2011-01-17 00:52:00 +00:00
|
|
|
# None at this point.
|
2009-06-13 06:46:13 +00:00
|
|
|
log.debug(u'Validate Song')
|
|
|
|
# Lets be nice and assume the data is correct.
|
2011-01-17 00:52:00 +00:00
|
|
|
if not self.titleEdit.text():
|
2011-01-04 21:06:50 +00:00
|
|
|
self.songTabWidget.setCurrentIndex(0)
|
|
|
|
self.titleEdit.setFocus()
|
2011-02-02 23:12:31 +00:00
|
|
|
critical_error_message_box(
|
2011-01-15 19:24:50 +00:00
|
|
|
message=translate('SongsPlugin.EditSongForm',
|
2010-07-21 10:30:29 +00:00
|
|
|
'You need to type in a song title.'))
|
2010-06-20 06:48:32 +00:00
|
|
|
return False
|
2011-01-04 21:06:50 +00:00
|
|
|
if self.verseListWidget.rowCount() == 0:
|
|
|
|
self.songTabWidget.setCurrentIndex(0)
|
|
|
|
self.verseListWidget.setFocus()
|
2011-02-02 23:12:31 +00:00
|
|
|
critical_error_message_box(
|
2011-01-15 19:24:50 +00:00
|
|
|
message=translate('SongsPlugin.EditSongForm',
|
2010-07-21 10:30:29 +00:00
|
|
|
'You need to type in at least one verse.'))
|
2010-06-20 06:48:32 +00:00
|
|
|
return False
|
2011-01-04 21:06:50 +00:00
|
|
|
if self.authorsListView.count() == 0:
|
|
|
|
self.songTabWidget.setCurrentIndex(1)
|
|
|
|
self.authorsListView.setFocus()
|
2011-02-02 23:12:31 +00:00
|
|
|
critical_error_message_box(
|
2011-01-15 19:24:50 +00:00
|
|
|
message=translate('SongsPlugin.EditSongForm',
|
2010-12-18 17:11:21 +00:00
|
|
|
'You need to have an author for this song.'))
|
|
|
|
return False
|
2011-01-17 00:52:00 +00:00
|
|
|
if self.verseOrderEdit.text():
|
2012-03-11 21:32:43 +00:00
|
|
|
result = self.__validateVerseList(self.verseOrderEdit.text(),
|
2012-03-05 20:34:23 +00:00
|
|
|
self.verseListWidget.rowCount())
|
2012-03-11 21:32:43 +00:00
|
|
|
if not result:
|
|
|
|
return False
|
2011-01-17 00:52:00 +00:00
|
|
|
text = unicode(self.songBookComboBox.currentText())
|
|
|
|
if self.songBookComboBox.findText(text, QtCore.Qt.MatchExactly) < 0:
|
|
|
|
if QtGui.QMessageBox.question(self,
|
|
|
|
translate('SongsPlugin.EditSongForm', 'Add Book'),
|
|
|
|
translate('SongsPlugin.EditSongForm', 'This song book does '
|
|
|
|
'not exist, do you want to add it?'),
|
|
|
|
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
|
|
|
|
QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes:
|
|
|
|
book = Book.populate(name=text, publisher=u'')
|
|
|
|
self.manager.save_object(book)
|
|
|
|
else:
|
|
|
|
return False
|
2010-06-20 06:48:32 +00:00
|
|
|
return True
|
2009-06-16 18:21:24 +00:00
|
|
|
|
2009-08-04 20:23:33 +00:00
|
|
|
def onCopyrightInsertButtonTriggered(self):
|
2011-01-04 21:06:50 +00:00
|
|
|
text = self.copyrightEdit.text()
|
|
|
|
pos = self.copyrightEdit.cursorPosition()
|
2011-02-16 17:54:31 +00:00
|
|
|
sign = SongStrings.CopyrightSymbol
|
2011-01-05 10:48:47 +00:00
|
|
|
text = text[:pos] + sign + text[pos:]
|
2011-01-04 21:06:50 +00:00
|
|
|
self.copyrightEdit.setText(text)
|
|
|
|
self.copyrightEdit.setFocus()
|
2011-01-05 10:48:47 +00:00
|
|
|
self.copyrightEdit.setCursorPosition(pos + len(sign))
|
2009-06-10 17:12:03 +00:00
|
|
|
|
2009-08-06 14:51:38 +00:00
|
|
|
def onMaintenanceButtonClicked(self):
|
2010-08-28 19:32:24 +00:00
|
|
|
temp_song_book = None
|
2011-01-04 21:06:50 +00:00
|
|
|
item = int(self.songBookComboBox.currentIndex())
|
|
|
|
text = unicode(self.songBookComboBox.currentText())
|
2010-08-28 19:32:24 +00:00
|
|
|
if item == 0 and text:
|
|
|
|
temp_song_book = text
|
2012-05-26 19:56:12 +00:00
|
|
|
self.mediaitem.songMaintenanceForm.exec_(True)
|
2009-08-06 14:51:38 +00:00
|
|
|
self.loadAuthors()
|
|
|
|
self.loadBooks()
|
|
|
|
self.loadTopics()
|
2010-08-28 19:32:24 +00:00
|
|
|
if temp_song_book:
|
2011-01-04 21:06:50 +00:00
|
|
|
self.songBookComboBox.setEditText(temp_song_book)
|
2009-08-06 14:51:38 +00:00
|
|
|
|
2009-10-25 18:07:23 +00:00
|
|
|
def onPreview(self, button):
|
2010-05-18 19:29:40 +00:00
|
|
|
"""
|
2012-04-02 00:19:16 +00:00
|
|
|
Save and Preview button clicked.
|
2010-05-18 19:29:40 +00:00
|
|
|
The Song is valid so as the plugin to add it to preview to see.
|
2010-11-28 15:10:51 +00:00
|
|
|
|
|
|
|
``button``
|
|
|
|
A button (QPushButton).
|
2010-05-18 19:29:40 +00:00
|
|
|
"""
|
2009-10-25 18:07:23 +00:00
|
|
|
log.debug(u'onPreview')
|
2011-02-18 19:13:37 +00:00
|
|
|
if unicode(button.objectName()) == u'previewButton':
|
|
|
|
self.saveSong(True)
|
2010-04-16 07:31:01 +00:00
|
|
|
Receiver.send_message(u'songs_preview')
|
2009-10-25 18:07:23 +00:00
|
|
|
|
2011-08-23 13:44:50 +00:00
|
|
|
def onAudioAddFromFileButtonClicked(self):
|
|
|
|
"""
|
|
|
|
Loads file(s) from the filesystem.
|
|
|
|
"""
|
|
|
|
filters = u'%s (*)' % UiStrings().AllFiles
|
|
|
|
filenames = QtGui.QFileDialog.getOpenFileNames(self,
|
|
|
|
translate('SongsPlugin.EditSongForm', 'Open File(s)'),
|
|
|
|
QtCore.QString(), filters)
|
|
|
|
for filename in filenames:
|
2011-08-24 11:53:22 +00:00
|
|
|
item = QtGui.QListWidgetItem(os.path.split(unicode(filename))[1])
|
|
|
|
item.setData(QtCore.Qt.UserRole, filename)
|
|
|
|
self.audioListWidget.addItem(item)
|
2011-08-23 13:44:50 +00:00
|
|
|
|
2011-08-23 21:48:46 +00:00
|
|
|
def onAudioAddFromMediaButtonClicked(self):
|
|
|
|
"""
|
|
|
|
Loads file(s) from the media plugin.
|
|
|
|
"""
|
2011-08-24 11:53:22 +00:00
|
|
|
if self.mediaForm.exec_():
|
|
|
|
for filename in self.mediaForm.getSelectedFiles():
|
2011-11-26 21:26:50 +00:00
|
|
|
item = QtGui.QListWidgetItem(
|
|
|
|
os.path.split(unicode(filename))[1])
|
2011-08-24 11:53:22 +00:00
|
|
|
item.setData(QtCore.Qt.UserRole, filename)
|
|
|
|
self.audioListWidget.addItem(item)
|
2011-08-23 21:48:46 +00:00
|
|
|
|
2011-08-26 23:04:54 +00:00
|
|
|
def onAudioRemoveButtonClicked(self):
|
|
|
|
"""
|
|
|
|
Removes a file from the list.
|
|
|
|
"""
|
|
|
|
row = self.audioListWidget.currentRow()
|
|
|
|
if row == -1:
|
|
|
|
return
|
|
|
|
self.audioListWidget.takeItem(row)
|
|
|
|
|
|
|
|
def onAudioRemoveAllButtonClicked(self):
|
|
|
|
"""
|
|
|
|
Removes all files from the list.
|
|
|
|
"""
|
|
|
|
self.audioListWidget.clear()
|
|
|
|
|
2011-08-23 13:44:50 +00:00
|
|
|
def onUpButtonClicked(self):
|
2011-08-26 23:04:54 +00:00
|
|
|
"""
|
|
|
|
Moves a file up when the user clicks the up button on the audio tab.
|
|
|
|
"""
|
|
|
|
row = self.audioListWidget.currentRow()
|
|
|
|
if row <= 0:
|
|
|
|
return
|
|
|
|
item = self.audioListWidget.takeItem(row)
|
|
|
|
self.audioListWidget.insertItem(row - 1, item)
|
|
|
|
self.audioListWidget.setCurrentRow(row - 1)
|
2011-08-23 13:44:50 +00:00
|
|
|
|
|
|
|
def onDownButtonClicked(self):
|
2011-08-26 23:04:54 +00:00
|
|
|
"""
|
|
|
|
Moves a file down when the user clicks the up button on the audio tab.
|
|
|
|
"""
|
|
|
|
row = self.audioListWidget.currentRow()
|
|
|
|
if row == -1 or row > self.audioListWidget.count() - 1:
|
|
|
|
return
|
|
|
|
item = self.audioListWidget.takeItem(row)
|
|
|
|
self.audioListWidget.insertItem(row + 1, item)
|
|
|
|
self.audioListWidget.setCurrentRow(row + 1)
|
2011-08-23 13:44:50 +00:00
|
|
|
|
2010-12-12 08:35:02 +00:00
|
|
|
def clearCaches(self):
|
|
|
|
"""
|
|
|
|
Free up autocompletion memory on dialog exit
|
|
|
|
"""
|
2011-02-01 18:05:59 +00:00
|
|
|
log.debug (u'SongEditForm.clearCaches')
|
2010-12-12 08:35:02 +00:00
|
|
|
self.authors = []
|
|
|
|
self.themes = []
|
|
|
|
self.books = []
|
|
|
|
self.topics = []
|
|
|
|
|
2011-02-01 00:33:50 +00:00
|
|
|
def reject(self):
|
2010-12-12 08:35:02 +00:00
|
|
|
"""
|
|
|
|
Exit Dialog and do not save
|
|
|
|
"""
|
2011-02-01 18:05:59 +00:00
|
|
|
log.debug (u'SongEditForm.reject')
|
2010-04-20 22:00:55 +00:00
|
|
|
Receiver.send_message(u'songs_edit_clear')
|
2010-12-12 08:35:02 +00:00
|
|
|
self.clearCaches()
|
2011-02-01 18:05:59 +00:00
|
|
|
QtGui.QDialog.reject(self)
|
2009-10-29 09:18:26 +00:00
|
|
|
|
2009-08-08 06:19:09 +00:00
|
|
|
def accept(self):
|
2010-12-12 08:35:02 +00:00
|
|
|
"""
|
2011-01-14 21:19:41 +00:00
|
|
|
Exit Dialog and save song if valid
|
2010-12-12 08:35:02 +00:00
|
|
|
"""
|
2011-02-01 18:05:59 +00:00
|
|
|
log.debug(u'SongEditForm.accept')
|
2010-12-12 08:35:02 +00:00
|
|
|
self.clearCaches()
|
2012-03-11 21:32:43 +00:00
|
|
|
if self.__validateSong():
|
2011-01-17 00:52:00 +00:00
|
|
|
self.saveSong()
|
2011-05-26 03:34:42 +00:00
|
|
|
self.song = None
|
2011-02-01 18:05:59 +00:00
|
|
|
QtGui.QDialog.accept(self)
|
2009-10-25 18:07:23 +00:00
|
|
|
|
2010-11-03 18:18:44 +00:00
|
|
|
def saveSong(self, preview=False):
|
2010-09-17 19:02:25 +00:00
|
|
|
"""
|
|
|
|
Get all the data from the widgets on the form, and then save it to the
|
2011-02-25 17:05:01 +00:00
|
|
|
database. The form has been validated and all reference items
|
2011-01-17 00:52:00 +00:00
|
|
|
(Authors, Books and Topics) have been saved before this function is
|
|
|
|
called.
|
2010-11-03 18:18:44 +00:00
|
|
|
|
2010-12-11 20:31:47 +00:00
|
|
|
``preview``
|
2010-11-28 15:10:51 +00:00
|
|
|
Should be ``True`` if the song is also previewed (boolean).
|
2010-09-17 19:02:25 +00:00
|
|
|
"""
|
2011-02-25 17:05:01 +00:00
|
|
|
# The Song() assignment. No database calls should be made while a
|
2011-01-17 00:52:00 +00:00
|
|
|
# Song() is in a partially complete state.
|
|
|
|
if not self.song:
|
|
|
|
self.song = Song()
|
2011-01-04 21:06:50 +00:00
|
|
|
self.song.title = unicode(self.titleEdit.text())
|
|
|
|
self.song.alternate_title = unicode(self.alternativeEdit.text())
|
|
|
|
self.song.copyright = unicode(self.copyrightEdit.text())
|
2011-03-17 12:32:45 +00:00
|
|
|
# Values will be set when cleaning the song.
|
2011-03-14 20:36:30 +00:00
|
|
|
self.song.search_title = u''
|
2011-03-15 17:52:42 +00:00
|
|
|
self.song.search_lyrics = u''
|
2011-03-15 20:12:28 +00:00
|
|
|
self.song.verse_order = u''
|
2011-01-04 21:06:50 +00:00
|
|
|
self.song.comments = unicode(self.commentsEdit.toPlainText())
|
2011-02-17 15:05:58 +00:00
|
|
|
ordertext = unicode(self.verseOrderEdit.text())
|
|
|
|
order = []
|
|
|
|
for item in ordertext.split():
|
2011-03-14 20:36:30 +00:00
|
|
|
verse_tag = VerseType.Tags[VerseType.from_translated_tag(item[0])]
|
2011-02-18 00:48:58 +00:00
|
|
|
verse_num = item[1:].lower()
|
|
|
|
order.append(u'%s%s' % (verse_tag, verse_num))
|
2011-02-17 15:05:58 +00:00
|
|
|
self.song.verse_order = u' '.join(order)
|
2010-06-05 23:05:53 +00:00
|
|
|
self.song.ccli_number = unicode(self.CCLNumberEdit.text())
|
2010-08-28 19:32:24 +00:00
|
|
|
self.song.song_number = unicode(self.songBookNumberEdit.text())
|
2011-01-04 21:06:50 +00:00
|
|
|
book_name = unicode(self.songBookComboBox.currentText())
|
2010-09-25 11:55:01 +00:00
|
|
|
if book_name:
|
2010-11-03 18:18:44 +00:00
|
|
|
self.song.book = self.manager.get_object_filtered(Book,
|
2010-09-25 11:55:01 +00:00
|
|
|
Book.name == book_name)
|
|
|
|
else:
|
|
|
|
self.song.book = None
|
2011-01-04 21:06:50 +00:00
|
|
|
theme_name = unicode(self.themeComboBox.currentText())
|
2010-11-27 20:51:54 +00:00
|
|
|
if theme_name:
|
|
|
|
self.song.theme_name = theme_name
|
|
|
|
else:
|
|
|
|
self.song.theme_name = None
|
2011-03-17 12:32:45 +00:00
|
|
|
self._processLyrics()
|
2011-01-17 00:52:00 +00:00
|
|
|
self.song.authors = []
|
2011-08-24 11:53:22 +00:00
|
|
|
for row in xrange(self.authorsListView.count()):
|
2011-01-17 00:52:00 +00:00
|
|
|
item = self.authorsListView.item(row)
|
|
|
|
authorId = (item.data(QtCore.Qt.UserRole)).toInt()[0]
|
2012-05-26 20:06:19 +00:00
|
|
|
author = self.manager.get_object(Author, authorId)
|
|
|
|
if author is not None:
|
|
|
|
self.song.authors.append(author)
|
2011-01-17 00:52:00 +00:00
|
|
|
self.song.topics = []
|
2011-08-24 11:53:22 +00:00
|
|
|
for row in xrange(self.topicsListView.count()):
|
2011-01-17 00:52:00 +00:00
|
|
|
item = self.topicsListView.item(row)
|
|
|
|
topicId = (item.data(QtCore.Qt.UserRole)).toInt()[0]
|
2012-05-26 20:06:19 +00:00
|
|
|
topic = self.manager.get_object(Topic, topicId)
|
|
|
|
if topic is not None:
|
|
|
|
self.song.topics.append(topic)
|
2011-09-04 09:26:13 +00:00
|
|
|
# Save the song here because we need a valid id for the audio files.
|
2011-08-24 11:53:22 +00:00
|
|
|
clean_song(self.manager, self.song)
|
|
|
|
self.manager.save_object(self.song)
|
2011-08-24 12:22:39 +00:00
|
|
|
audio_files = map(lambda a: a.file_name, self.song.media_files)
|
|
|
|
log.debug(audio_files)
|
2011-08-24 11:53:22 +00:00
|
|
|
save_path = os.path.join(
|
|
|
|
AppLocation.get_section_data_path(self.mediaitem.plugin.name),
|
|
|
|
'audio', str(self.song.id))
|
2012-07-07 14:54:14 +00:00
|
|
|
check_directory_exists(save_path)
|
2011-08-24 11:53:22 +00:00
|
|
|
self.song.media_files = []
|
2011-08-24 12:22:39 +00:00
|
|
|
files = []
|
2011-08-24 11:53:22 +00:00
|
|
|
for row in xrange(self.audioListWidget.count()):
|
|
|
|
item = self.audioListWidget.item(row)
|
|
|
|
filename = unicode(item.data(QtCore.Qt.UserRole).toString())
|
|
|
|
if not filename.startswith(save_path):
|
2011-08-24 12:22:39 +00:00
|
|
|
oldfile, filename = filename, os.path.join(save_path,
|
|
|
|
os.path.split(filename)[1])
|
|
|
|
shutil.copyfile(oldfile, filename)
|
2011-09-04 09:26:13 +00:00
|
|
|
files.append(filename)
|
2011-08-24 12:22:39 +00:00
|
|
|
media_file = MediaFile()
|
|
|
|
media_file.file_name = filename
|
|
|
|
media_file.type = u'audio'
|
2011-08-26 23:04:54 +00:00
|
|
|
media_file.weight = row
|
2011-08-24 12:22:39 +00:00
|
|
|
self.song.media_files.append(media_file)
|
|
|
|
for audio in audio_files:
|
|
|
|
if audio not in files:
|
|
|
|
try:
|
|
|
|
os.remove(audio)
|
|
|
|
except:
|
|
|
|
log.exception('Could not remove file: %s', audio)
|
2011-09-04 12:04:44 +00:00
|
|
|
if not files:
|
|
|
|
try:
|
|
|
|
os.rmdir(save_path)
|
|
|
|
except OSError:
|
|
|
|
log.exception(u'Could not remove directory: %s', save_path)
|
2011-03-15 18:24:13 +00:00
|
|
|
clean_song(self.manager, self.song)
|
2011-01-17 00:52:00 +00:00
|
|
|
self.manager.save_object(self.song)
|
2011-09-01 19:45:36 +00:00
|
|
|
self.mediaitem.autoSelectId = self.song.id
|
2009-06-12 05:13:54 +00:00
|
|
|
|
2011-03-17 12:32:45 +00:00
|
|
|
def _processLyrics(self):
|
2011-01-17 00:52:00 +00:00
|
|
|
"""
|
|
|
|
Process the lyric data entered by the user into the OpenLP XML format.
|
|
|
|
"""
|
|
|
|
# This method must only be run after the self.song = Song() assignment.
|
2011-03-17 12:32:45 +00:00
|
|
|
log.debug(u'_processLyrics')
|
2009-10-30 06:43:28 +00:00
|
|
|
try:
|
2011-01-09 16:52:31 +00:00
|
|
|
sxml = SongXML()
|
2010-06-19 23:16:15 +00:00
|
|
|
multiple = []
|
2012-05-01 11:00:02 +00:00
|
|
|
for i in range(self.verseListWidget.rowCount()):
|
2011-01-04 21:06:50 +00:00
|
|
|
item = self.verseListWidget.item(i, 0)
|
2012-06-16 16:12:54 +00:00
|
|
|
verse_id = unicode(item.data(QtCore.Qt.UserRole).toString())
|
|
|
|
verse_tag = verse_id[0]
|
|
|
|
verse_num = verse_id[1:]
|
2011-02-18 07:53:40 +00:00
|
|
|
sxml.add_verse_to_lyrics(verse_tag, verse_num,
|
2011-02-17 19:46:01 +00:00
|
|
|
unicode(item.text()))
|
2011-03-15 17:52:42 +00:00
|
|
|
if verse_num > u'1' and verse_tag not in multiple:
|
2011-02-18 00:48:58 +00:00
|
|
|
multiple.append(verse_tag)
|
2009-11-04 19:13:49 +00:00
|
|
|
self.song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
|
2010-06-19 23:16:15 +00:00
|
|
|
for verse in multiple:
|
2010-06-20 06:48:32 +00:00
|
|
|
self.song.verse_order = re.sub(u'([' + verse.upper() +
|
2010-06-20 13:03:06 +00:00
|
|
|
verse.lower() + u'])(\W|$)', r'\g<1>1\2',
|
|
|
|
self.song.verse_order)
|
2009-10-30 06:43:28 +00:00
|
|
|
except:
|
2009-11-04 01:16:15 +00:00
|
|
|
log.exception(u'Problem processing song Lyrics \n%s',
|
2011-04-29 06:15:10 +00:00
|
|
|
sxml.dump_xml())
|
2013-03-04 20:49:55 +00:00
|
|
|
raise
|
2011-08-24 11:53:22 +00:00
|
|
|
|