2008-12-01 13:15:31 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
"""
|
|
|
|
OpenLP - Open Source Lyrics Projection
|
|
|
|
Copyright (c) 2008 Raoul Snyman
|
2009-06-03 16:14:56 +00:00
|
|
|
Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley,
|
2008-12-01 13:15:31 +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-08-04 20:23:33 +00:00
|
|
|
|
2009-01-12 19:31:29 +00:00
|
|
|
from PyQt4 import Qt, QtCore, QtGui
|
2009-01-01 10:03:09 +00:00
|
|
|
|
2009-09-04 17:19:54 +00:00
|
|
|
from openlp.core.lib import SongXMLBuilder, SongXMLParser, Receiver, \
|
|
|
|
translate
|
2009-08-04 20:23:33 +00:00
|
|
|
from openlp.plugins.songs.forms import EditVerseForm
|
|
|
|
from openlp.plugins.songs.lib.models import Song
|
2008-12-24 07:28:25 +00:00
|
|
|
from editsongdialog import Ui_EditSongDialog
|
|
|
|
|
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
|
|
|
"""
|
2009-06-13 06:46:13 +00:00
|
|
|
global log
|
|
|
|
log = logging.getLogger(u'EditSongForm')
|
|
|
|
log.info(u'Song Editor loaded')
|
2009-08-04 20:23:33 +00:00
|
|
|
|
2009-08-26 05:00:19 +00:00
|
|
|
def __init__(self, songmanager, parent=None):
|
2008-12-24 07:28:25 +00:00
|
|
|
"""
|
|
|
|
Constructor
|
|
|
|
"""
|
2009-02-28 23:19:45 +00:00
|
|
|
QtGui.QDialog.__init__(self, parent)
|
2008-12-24 07:28:25 +00:00
|
|
|
self.setupUi(self)
|
2009-02-19 22:25:58 +00:00
|
|
|
# Connecting signals and slots
|
2009-08-04 20:23:33 +00:00
|
|
|
QtCore.QObject.connect(self.AuthorAddButton,
|
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onAuthorAddButtonClicked)
|
|
|
|
QtCore.QObject.connect(self.AuthorRemoveButton,
|
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onAuthorRemoveButtonClicked)
|
2009-06-13 06:46:13 +00:00
|
|
|
QtCore.QObject.connect(self.AuthorsListView,
|
2009-06-16 18:21:24 +00:00
|
|
|
QtCore.SIGNAL(u'itemClicked(QListWidgetItem*)'), self.onAuthorsListViewPressed)
|
2009-08-04 20:23:33 +00:00
|
|
|
QtCore.QObject.connect(self.TopicAddButton,
|
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onTopicAddButtonClicked)
|
|
|
|
QtCore.QObject.connect(self.TopicRemoveButton,
|
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onTopicRemoveButtonClicked)
|
2009-06-14 06:30:09 +00:00
|
|
|
QtCore.QObject.connect(self.TopicsListView,
|
2009-06-16 18:21:24 +00:00
|
|
|
QtCore.SIGNAL(u'itemClicked(QListWidgetItem*)'), self.onTopicListViewPressed)
|
2009-08-04 20:23:33 +00:00
|
|
|
QtCore.QObject.connect(self.CopyrightInsertButton,
|
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onCopyrightInsertButtonTriggered)
|
|
|
|
QtCore.QObject.connect(self.VerseAddButton,
|
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onVerseAddButtonClicked)
|
|
|
|
QtCore.QObject.connect(self.VerseEditButton,
|
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onVerseEditButtonClicked)
|
2009-09-04 17:19:54 +00:00
|
|
|
QtCore.QObject.connect(self.VerseEditAllButton,
|
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onVerseEditAllButtonClicked)
|
2009-08-04 20:23:33 +00:00
|
|
|
QtCore.QObject.connect(self.VerseDeleteButton,
|
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onVerseDeleteButtonClicked)
|
2009-06-13 06:46:13 +00:00
|
|
|
QtCore.QObject.connect(self.VerseListWidget,
|
2009-06-16 18:21:24 +00:00
|
|
|
QtCore.SIGNAL(u'itemClicked(QListWidgetItem*)'), self.onVerseListViewPressed)
|
2009-06-14 06:48:38 +00:00
|
|
|
QtCore.QObject.connect(self.SongbookCombo,
|
|
|
|
QtCore.SIGNAL(u'activated(int)'), self.onSongBookComboChanged)
|
2009-06-14 07:02:58 +00:00
|
|
|
QtCore.QObject.connect(self.ThemeSelectionComboItem,
|
|
|
|
QtCore.SIGNAL(u'activated(int)'), self.onThemeComboChanged)
|
2009-08-06 14:51:38 +00:00
|
|
|
QtCore.QObject.connect(self.MaintenanceButton,
|
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onMaintenanceButtonClicked)
|
2009-08-25 05:18:09 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'update_themes'), self.loadThemes)
|
2009-02-19 22:25:58 +00:00
|
|
|
# Create other objects and forms
|
2008-12-24 07:28:25 +00:00
|
|
|
self.songmanager = songmanager
|
2009-08-06 14:51:38 +00:00
|
|
|
self.parent = parent
|
2009-03-07 21:38:59 +00:00
|
|
|
self.verse_form = EditVerseForm()
|
2008-12-24 07:28:25 +00:00
|
|
|
self.initialise()
|
2009-01-17 13:58:16 +00:00
|
|
|
self.AuthorsListView.setSortingEnabled(False)
|
2009-01-10 08:33:31 +00:00
|
|
|
self.AuthorsListView.setAlternatingRowColors(True)
|
2009-06-12 17:20:40 +00:00
|
|
|
self.TopicsListView.setSortingEnabled(False)
|
|
|
|
self.TopicsListView.setAlternatingRowColors(True)
|
2009-01-17 13:58:16 +00:00
|
|
|
|
2008-12-24 07:28:25 +00:00
|
|
|
def initialise(self):
|
2009-08-04 20:23:33 +00:00
|
|
|
self.VerseEditButton.setEnabled(False)
|
|
|
|
self.VerseDeleteButton.setEnabled(False)
|
|
|
|
self.AuthorRemoveButton.setEnabled(False)
|
|
|
|
self.TopicRemoveButton.setEnabled(False)
|
2009-06-14 07:25:39 +00:00
|
|
|
self.title_change = False
|
2009-03-09 18:47:37 +00:00
|
|
|
|
|
|
|
def loadAuthors(self):
|
|
|
|
authors = self.songmanager.get_authors()
|
2008-12-24 14:07:27 +00:00
|
|
|
self.AuthorsSelectionComboItem.clear()
|
2009-03-09 18:47:37 +00:00
|
|
|
for author in authors:
|
2009-06-14 13:50:56 +00:00
|
|
|
row = self.AuthorsSelectionComboItem.count()
|
2009-03-09 18:47:37 +00:00
|
|
|
self.AuthorsSelectionComboItem.addItem(author.display_name)
|
2009-06-14 13:50:56 +00:00
|
|
|
self.AuthorsSelectionComboItem.setItemData(row, QtCore.QVariant(author.id))
|
2008-12-24 14:07:27 +00:00
|
|
|
|
2009-06-04 19:00:41 +00:00
|
|
|
def loadTopics(self):
|
2009-06-04 20:06:32 +00:00
|
|
|
topics = self.songmanager.get_topics()
|
2009-06-04 19:00:41 +00:00
|
|
|
self.SongTopicCombo.clear()
|
|
|
|
for topic in topics:
|
2009-06-14 13:50:56 +00:00
|
|
|
row = self.SongTopicCombo.count()
|
2009-06-04 19:00:41 +00:00
|
|
|
self.SongTopicCombo.addItem(topic.name)
|
2009-06-14 13:50:56 +00:00
|
|
|
self.SongTopicCombo.setItemData(row, QtCore.QVariant(topic.id))
|
2009-06-04 19:00:41 +00:00
|
|
|
|
2009-06-04 20:06:32 +00:00
|
|
|
def loadBooks(self):
|
|
|
|
books = self.songmanager.get_books()
|
|
|
|
self.SongbookCombo.clear()
|
2009-06-13 06:46:13 +00:00
|
|
|
self.SongbookCombo.addItem(u' ')
|
2009-06-04 20:06:32 +00:00
|
|
|
for book in books:
|
2009-06-14 13:50:56 +00:00
|
|
|
row = self.SongbookCombo.count()
|
2009-06-04 20:06:32 +00:00
|
|
|
self.SongbookCombo.addItem(book.name)
|
2009-06-14 13:50:56 +00:00
|
|
|
self.SongbookCombo.setItemData(row, QtCore.QVariant(book.id))
|
2009-06-04 20:06:32 +00:00
|
|
|
|
2009-06-14 07:02:58 +00:00
|
|
|
def loadThemes(self, theme_list):
|
|
|
|
self.ThemeSelectionComboItem.clear()
|
|
|
|
self.ThemeSelectionComboItem.addItem(u' ')
|
|
|
|
for theme in theme_list:
|
|
|
|
self.ThemeSelectionComboItem.addItem(theme)
|
|
|
|
|
2009-06-12 17:20:40 +00:00
|
|
|
def newSong(self):
|
2009-06-13 06:46:13 +00:00
|
|
|
log.debug(u'New Song')
|
2009-08-08 06:19:09 +00:00
|
|
|
self.SongTabWidget.setCurrentIndex(0)
|
2009-06-12 17:20:40 +00:00
|
|
|
self.song = Song()
|
|
|
|
self.TitleEditItem.setText(u'')
|
|
|
|
self.AlternativeEdit.setText(u'')
|
|
|
|
self.CopyrightEditItem.setText(u'')
|
2009-06-16 18:21:24 +00:00
|
|
|
self.VerseOrderEdit.setText(u'')
|
|
|
|
self.CommentsEdit.setText(u'')
|
|
|
|
self.CCLNumberEdit.setText(u'')
|
2009-06-12 17:20:40 +00:00
|
|
|
self.VerseListWidget.clear()
|
|
|
|
self.AuthorsListView.clear()
|
|
|
|
self.TopicsListView.clear()
|
2009-06-14 07:25:39 +00:00
|
|
|
self.title_change = False
|
2009-07-13 17:02:38 +00:00
|
|
|
self.TitleEditItem.setFocus(QtCore.Qt.OtherFocusReason)
|
2009-07-18 07:30:26 +00:00
|
|
|
self.loadAuthors()
|
|
|
|
self.loadTopics()
|
|
|
|
self.loadBooks()
|
2009-06-12 17:20:40 +00:00
|
|
|
|
2009-02-19 22:25:58 +00:00
|
|
|
def loadSong(self, id):
|
2009-06-13 06:46:13 +00:00
|
|
|
log.debug(u'Load Song')
|
2009-08-08 06:19:09 +00:00
|
|
|
self.SongTabWidget.setCurrentIndex(0)
|
2009-07-18 07:30:26 +00:00
|
|
|
self.loadAuthors()
|
|
|
|
self.loadTopics()
|
|
|
|
self.loadBooks()
|
2009-02-19 22:25:58 +00:00
|
|
|
self.song = self.songmanager.get_song(id)
|
2009-01-17 13:58:16 +00:00
|
|
|
self.TitleEditItem.setText(self.song.title)
|
2009-06-12 05:13:54 +00:00
|
|
|
title = self.song.search_title.split(u'@')
|
2009-06-13 06:46:13 +00:00
|
|
|
if self.song.song_book_id != 0:
|
|
|
|
book_name = self.songmanager.get_book(self.song.song_book_id)
|
2009-07-19 07:58:37 +00:00
|
|
|
id = self.SongbookCombo.findText(unicode(book_name.name), QtCore.Qt.MatchExactly)
|
2009-06-14 06:48:38 +00:00
|
|
|
if id == -1:
|
|
|
|
# Not Found
|
|
|
|
id = 0
|
2009-07-19 06:31:08 +00:00
|
|
|
self.SongbookCombo.setCurrentIndex(id)
|
2009-06-14 07:02:58 +00:00
|
|
|
if self.song.theme_name is not None and len(self.song.theme_name) > 0:
|
2009-07-19 07:58:37 +00:00
|
|
|
id = self.ThemeSelectionComboItem.findText(unicode(self.song.theme_name), QtCore.Qt.MatchExactly)
|
2009-06-14 07:02:58 +00:00
|
|
|
if id == -1:
|
|
|
|
# Not Found
|
|
|
|
id = 0
|
|
|
|
self.song.theme_name = None
|
2009-07-19 07:58:37 +00:00
|
|
|
self.ThemeSelectionComboItem.setCurrentIndex(id)
|
2009-06-12 05:13:54 +00:00
|
|
|
if len(title) > 1:
|
|
|
|
self.AlternativeEdit.setText(title[1])
|
2009-07-13 17:02:38 +00:00
|
|
|
if self.song.copyright is not None:
|
|
|
|
self.CopyrightEditItem.setText(self.song.copyright)
|
|
|
|
else:
|
|
|
|
self.CopyrightEditItem.setText(u'')
|
2009-06-12 05:13:54 +00:00
|
|
|
self.VerseListWidget.clear()
|
2009-06-16 18:21:24 +00:00
|
|
|
if self.song.verse_order is not None:
|
|
|
|
self.VerseOrderEdit.setText(self.song.verse_order)
|
|
|
|
else:
|
|
|
|
self.VerseOrderEdit.setText(u'')
|
|
|
|
if self.song.comments is not None:
|
2009-07-13 17:02:38 +00:00
|
|
|
self.CommentsEdit.setPlainText(self.song.comments)
|
2009-06-16 18:21:24 +00:00
|
|
|
else:
|
2009-07-13 17:02:38 +00:00
|
|
|
self.CommentsEdit.setPlainText(u'')
|
2009-06-16 18:21:24 +00:00
|
|
|
if self.song.ccli_number is not None:
|
|
|
|
self.CCLNumberEdit.setText(self.song.ccli_number)
|
|
|
|
else:
|
|
|
|
self.CCLNumberEdit.setText(u'')
|
2009-06-12 17:20:40 +00:00
|
|
|
#lazy xml migration for now
|
|
|
|
if self.song.lyrics.startswith(u'<?xml version='):
|
2009-08-06 14:51:38 +00:00
|
|
|
songXML = SongXMLParser(self.song.lyrics)
|
2009-06-12 17:20:40 +00:00
|
|
|
verseList = songXML.get_verses()
|
|
|
|
for verse in verseList:
|
|
|
|
self.VerseListWidget.addItem(verse[1])
|
|
|
|
else:
|
|
|
|
verses = self.song.lyrics.split(u'\n\n')
|
|
|
|
for verse in verses:
|
|
|
|
self.VerseListWidget.addItem(verse)
|
2009-06-11 05:13:10 +00:00
|
|
|
# clear the results
|
|
|
|
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))
|
|
|
|
self.AuthorsListView.addItem(author_name)
|
2009-06-12 17:20:40 +00:00
|
|
|
# clear the results
|
|
|
|
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))
|
|
|
|
self.TopicsListView.addItem(topic_name)
|
2009-01-17 13:58:16 +00:00
|
|
|
self._validate_song()
|
2009-06-14 07:25:39 +00:00
|
|
|
self.title_change = False
|
2009-07-13 17:02:38 +00:00
|
|
|
self.TitleEditItem.setFocus(QtCore.Qt.OtherFocusReason)
|
2008-12-01 13:15:31 +00:00
|
|
|
|
2009-08-04 20:23:33 +00:00
|
|
|
def onAuthorAddButtonClicked(self):
|
2009-06-14 13:50:56 +00:00
|
|
|
item = int(self.AuthorsSelectionComboItem.currentIndex())
|
2009-07-18 05:43:50 +00:00
|
|
|
if item > -1:
|
|
|
|
item_id = (self.AuthorsSelectionComboItem.itemData(item)).toInt()[0]
|
|
|
|
author = self.songmanager.get_author(item_id)
|
|
|
|
self.song.authors.append(author)
|
|
|
|
author_item = QtGui.QListWidgetItem(unicode(author.display_name))
|
|
|
|
author_item.setData(QtCore.Qt.UserRole, QtCore.QVariant(author.id))
|
|
|
|
self.AuthorsListView.addItem(author_item)
|
2009-06-13 06:46:13 +00:00
|
|
|
|
|
|
|
def onAuthorsListViewPressed(self):
|
2009-07-18 05:43:50 +00:00
|
|
|
if self.AuthorsListView.count() > 1:
|
2009-08-04 20:23:33 +00:00
|
|
|
self.AuthorRemoveButton.setEnabled(True)
|
2009-06-13 06:46:13 +00:00
|
|
|
|
2009-08-04 20:23:33 +00:00
|
|
|
def onAuthorRemoveButtonClicked(self):
|
2009-08-06 21:30:14 +00:00
|
|
|
self.AuthorRemoveButton.setEnabled(False)
|
2009-06-13 06:46:13 +00:00
|
|
|
item = self.AuthorsListView.currentItem()
|
|
|
|
author_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
|
|
|
|
author = self.songmanager.get_author(author_id)
|
|
|
|
self.song.authors.remove(author)
|
|
|
|
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):
|
2009-06-14 13:50:56 +00:00
|
|
|
item = int(self.SongTopicCombo.currentIndex())
|
2009-07-18 05:43:50 +00:00
|
|
|
if item > -1:
|
|
|
|
item_id = (self.SongTopicCombo.itemData(item)).toInt()[0]
|
|
|
|
topic = self.songmanager.get_topic(item_id)
|
|
|
|
self.song.topics.append(topic)
|
|
|
|
topic_item = QtGui.QListWidgetItem(unicode(topic.name))
|
|
|
|
topic_item.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id))
|
|
|
|
self.TopicsListView.addItem(topic_item)
|
2009-06-14 06:30:09 +00:00
|
|
|
|
|
|
|
def onTopicListViewPressed(self):
|
2009-08-04 20:23:33 +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):
|
|
|
|
self.TopicRemoveButton.setEnabled(False)
|
2009-06-14 06:30:09 +00:00
|
|
|
item = self.TopicsListView.currentItem()
|
|
|
|
topic_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
|
|
|
|
topic = self.songmanager.get_topic(topic_id)
|
|
|
|
self.song.topics.remove(topic)
|
|
|
|
row = self.TopicsListView.row(item)
|
|
|
|
self.TopicsListView.takeItem(row)
|
2009-01-17 13:58:16 +00:00
|
|
|
|
2009-06-14 06:48:38 +00:00
|
|
|
def onSongBookComboChanged(self, item):
|
|
|
|
if item == 0:
|
|
|
|
self.song.song_book_id = 0
|
|
|
|
else:
|
2009-06-14 13:50:56 +00:00
|
|
|
item = int(self.SongbookCombo.currentIndex())
|
|
|
|
self.song.song_book_id = (self.SongbookCombo.itemData(item)).toInt()[0]
|
2009-06-14 06:48:38 +00:00
|
|
|
|
2009-06-14 07:02:58 +00:00
|
|
|
def onThemeComboChanged(self, item):
|
|
|
|
if item == 0:
|
|
|
|
#None means no Theme
|
|
|
|
self.song.song_theme = None
|
|
|
|
else:
|
|
|
|
them_name = unicode(self.ThemeSelectionComboItem.itemText(item))
|
|
|
|
self.song.theme_name = them_name
|
|
|
|
|
2009-06-13 06:46:13 +00:00
|
|
|
def onVerseListViewPressed(self):
|
2009-08-04 20:23:33 +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):
|
2009-06-10 17:12:03 +00:00
|
|
|
self.verse_form.setVerse(u'')
|
2009-03-07 21:38:59 +00:00
|
|
|
self.verse_form.exec_()
|
|
|
|
self.VerseListWidget.addItem(self.verse_form.getVerse())
|
|
|
|
|
2009-08-04 20:23:33 +00:00
|
|
|
def onVerseEditButtonClicked(self):
|
2009-03-07 21:38:59 +00:00
|
|
|
item = self.VerseListWidget.currentItem()
|
2009-06-13 06:46:13 +00:00
|
|
|
if item is not None:
|
2009-09-09 16:34:24 +00:00
|
|
|
tempText = item.text()
|
|
|
|
self.verse_form.setVerse(tempText)
|
2009-06-13 06:46:13 +00:00
|
|
|
self.verse_form.exec_()
|
2009-09-09 16:34:24 +00:00
|
|
|
afterText = self.verse_form.getVerse()
|
|
|
|
item.setText(afterText)
|
|
|
|
#number of lines has change
|
|
|
|
if len(tempText.split(u'\n')) != len(afterText.split(u'\n')):
|
2009-09-09 17:01:02 +00:00
|
|
|
tempList = {}
|
2009-09-09 16:34:24 +00:00
|
|
|
for row in range(0, self.VerseListWidget.count()):
|
2009-09-09 17:02:44 +00:00
|
|
|
tempList[row] = self.VerseListWidget.item(row).text()
|
2009-09-09 16:34:24 +00:00
|
|
|
self.VerseListWidget.clear()
|
|
|
|
for row in range (0, len(tempList)):
|
2009-09-09 17:02:44 +00:00
|
|
|
self.VerseListWidget.addItem(tempList[row])
|
2009-09-09 16:34:24 +00:00
|
|
|
self.VerseListWidget.repaint()
|
2009-08-04 20:23:33 +00:00
|
|
|
self.VerseEditButton.setEnabled(False)
|
|
|
|
self.VerseDeleteButton.setEnabled(False)
|
2009-03-07 21:38:59 +00:00
|
|
|
|
2009-09-04 17:19:54 +00:00
|
|
|
def onVerseEditAllButtonClicked(self):
|
|
|
|
verse_list = u''
|
|
|
|
if self.VerseListWidget.count() > 0:
|
|
|
|
for row in range(0, self.VerseListWidget.count()):
|
|
|
|
item = self.VerseListWidget.item(row)
|
|
|
|
verse_list += item.text()
|
|
|
|
verse_list += u'\n\n'
|
|
|
|
self.verse_form.setVerse(verse_list)
|
|
|
|
else:
|
|
|
|
self.verse_form.setVerse(u'')
|
|
|
|
if self.verse_form.exec_():
|
|
|
|
verse_list = self.verse_form.getVerse()
|
|
|
|
verse_list = verse_list.replace(u'\r\n', u'\n')
|
|
|
|
self.VerseListWidget.clear()
|
|
|
|
for row in verse_list.split(u'\n\n'):
|
|
|
|
self.VerseListWidget.addItem(row)
|
|
|
|
self.VerseListWidget.repaint()
|
|
|
|
|
2009-08-04 20:23:33 +00:00
|
|
|
def onVerseDeleteButtonClicked(self):
|
2009-03-07 21:38:59 +00:00
|
|
|
item = self.VerseListWidget.takeItem(self.VerseListWidget.currentRow())
|
|
|
|
item = None
|
2009-08-04 20:23:33 +00:00
|
|
|
self.VerseEditButton.setEnabled(False)
|
|
|
|
self.VerseDeleteButton.setEnabled(False)
|
2009-03-07 21:38:59 +00:00
|
|
|
|
2009-01-12 19:31:29 +00:00
|
|
|
def _validate_song(self):
|
|
|
|
"""
|
|
|
|
Check the validity of the form. Only display the 'save' if the data can be saved.
|
2009-01-17 13:58:16 +00:00
|
|
|
"""
|
2009-06-13 06:46:13 +00:00
|
|
|
log.debug(u'Validate Song')
|
|
|
|
# Lets be nice and assume the data is correct.
|
|
|
|
valid = True
|
2009-08-15 19:19:34 +00:00
|
|
|
message = u''
|
2009-06-10 18:04:32 +00:00
|
|
|
if len(self.TitleEditItem.displayText()) == 0:
|
2009-01-12 19:31:29 +00:00
|
|
|
valid = False
|
2009-06-14 13:50:56 +00:00
|
|
|
self.TitleEditItem.setStyleSheet(u'background-color: red; color: white')
|
2009-08-15 19:19:34 +00:00
|
|
|
message = translate(u'SongFormDialog', u'You need to enter a song title \n')
|
2009-06-14 13:50:56 +00:00
|
|
|
else:
|
|
|
|
self.TitleEditItem.setStyleSheet(u'')
|
2009-06-13 06:46:13 +00:00
|
|
|
if self.VerseListWidget.count() == 0:
|
|
|
|
valid = False
|
2009-06-14 13:50:56 +00:00
|
|
|
self.VerseListWidget.setStyleSheet(u'background-color: red; color: white')
|
2009-08-15 19:19:34 +00:00
|
|
|
message = message + translate(u'SongFormDialog', u'You need to enter some verse text \n')
|
2009-06-14 13:50:56 +00:00
|
|
|
else:
|
|
|
|
self.VerseListWidget.setStyleSheet(u'')
|
2009-06-13 06:46:13 +00:00
|
|
|
if self.AuthorsListView.count() == 0:
|
|
|
|
valid = False
|
2009-06-14 13:50:56 +00:00
|
|
|
self.AuthorsListView.setStyleSheet(u'background-color: red; color: white')
|
2009-08-15 19:19:34 +00:00
|
|
|
message = message + translate(u'SongFormDialog', u'You need to provide an author')
|
2009-01-12 19:31:29 +00:00
|
|
|
else:
|
2009-06-14 13:50:56 +00:00
|
|
|
self.AuthorsListView.setStyleSheet(u'')
|
2009-08-15 19:19:34 +00:00
|
|
|
return valid, message
|
2009-01-17 13:58:16 +00:00
|
|
|
|
2009-01-12 19:31:29 +00:00
|
|
|
def on_TitleEditItem_lostFocus(self):
|
2009-06-14 07:25:39 +00:00
|
|
|
self.song.title = self.TitleEditItem.text()
|
|
|
|
self.title_change = True
|
2009-02-17 21:01:27 +00:00
|
|
|
|
2009-06-16 18:21:24 +00:00
|
|
|
def on_VerseOrderEdit_lostFocus(self):
|
|
|
|
self.song.verse_order = self.VerseOrderEdit.text()
|
|
|
|
|
|
|
|
def on_CommentsEdit_lostFocus(self):
|
|
|
|
self.song.comments = self.CommentsEdit.text()
|
|
|
|
|
|
|
|
def on_CCLNumberEdit_lostFocus(self):
|
|
|
|
self.song.ccli_number = self.CCLNumberEdit.text()
|
|
|
|
|
2009-08-04 20:23:33 +00:00
|
|
|
def onCopyrightInsertButtonTriggered(self):
|
2009-02-19 22:25:58 +00:00
|
|
|
text = self.CopyrightEditItem.displayText()
|
|
|
|
pos = self.CopyrightEditItem.cursorPosition()
|
|
|
|
text = text[:pos] + u'©' + text[pos:]
|
|
|
|
self.CopyrightEditItem.setText(text)
|
|
|
|
self.CopyrightEditItem.setFocus()
|
|
|
|
self.CopyrightEditItem.setCursorPosition(pos + 1)
|
2009-06-10 17:12:03 +00:00
|
|
|
|
2009-08-06 14:51:38 +00:00
|
|
|
def onMaintenanceButtonClicked(self):
|
|
|
|
self.parent.song_maintenance_form.exec_()
|
|
|
|
self.loadAuthors()
|
|
|
|
self.loadBooks()
|
|
|
|
self.loadTopics()
|
|
|
|
|
2009-08-08 06:19:09 +00:00
|
|
|
def accept(self):
|
|
|
|
log.debug(u'accept')
|
2009-09-02 01:44:09 +00:00
|
|
|
valid, message = self._validate_song()
|
2009-08-15 19:19:34 +00:00
|
|
|
if not valid:
|
|
|
|
QtGui.QMessageBox.critical(self,
|
|
|
|
translate(u'SongFormDialog', u'Error'), message,
|
|
|
|
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
|
2009-06-13 06:46:13 +00:00
|
|
|
return
|
2009-06-10 18:04:32 +00:00
|
|
|
self.song.title = unicode(self.TitleEditItem.displayText())
|
|
|
|
self.song.copyright = unicode(self.CopyrightEditItem.displayText())
|
2009-07-13 17:02:38 +00:00
|
|
|
self.song.search_title = unicode(self.TitleEditItem.displayText()) + u'@'+ unicode(self.AlternativeEdit.displayText())
|
|
|
|
self.song.comments = unicode(self.CommentsEdit.toPlainText())
|
|
|
|
self.song.ccli_number = unicode(self.CCLNumberEdit.displayText())
|
2009-06-12 17:20:40 +00:00
|
|
|
self.processLyrics()
|
|
|
|
self.processTitle()
|
2009-06-10 18:04:32 +00:00
|
|
|
self.songmanager.save_song(self.song)
|
2009-06-14 07:25:39 +00:00
|
|
|
if self.title_change:
|
2009-08-26 05:00:19 +00:00
|
|
|
Receiver().send_message(u'load_song_list')
|
2009-06-10 18:04:32 +00:00
|
|
|
self.close()
|
2009-06-12 05:13:54 +00:00
|
|
|
|
2009-06-12 17:20:40 +00:00
|
|
|
def processLyrics(self):
|
2009-06-13 06:46:13 +00:00
|
|
|
log.debug(u'processLyrics')
|
2009-08-06 21:30:14 +00:00
|
|
|
sxml = SongXMLBuilder()
|
2009-06-12 17:20:40 +00:00
|
|
|
sxml.new_document()
|
|
|
|
sxml.add_lyrics_to_song()
|
|
|
|
count = 1
|
|
|
|
text = u' '
|
2009-06-16 18:21:24 +00:00
|
|
|
verse_order = u''
|
2009-06-12 17:20:40 +00:00
|
|
|
for i in range (0, self.VerseListWidget.count()):
|
2009-08-06 21:30:14 +00:00
|
|
|
sxml.add_verse_to_lyrics(u'Verse', unicode(count),
|
|
|
|
unicode(self.VerseListWidget.item(i).text()))
|
2009-06-12 17:20:40 +00:00
|
|
|
text = text + unicode(self.VerseListWidget.item(i).text()) + u' '
|
2009-08-06 21:30:14 +00:00
|
|
|
verse_order = verse_order + unicode(count) + u' '
|
2009-06-12 17:20:40 +00:00
|
|
|
count += 1
|
2009-06-16 18:21:24 +00:00
|
|
|
if self.song.verse_order is None:
|
|
|
|
self.song.verse_order = verse_order
|
2009-08-06 21:30:14 +00:00
|
|
|
text = text.replace(u'\'', u'')
|
|
|
|
text = text.replace(u',', u'')
|
|
|
|
text = text.replace(u';', u'')
|
|
|
|
text = text.replace(u':', u'')
|
|
|
|
text = text.replace(u'(', u'')
|
|
|
|
text = text.replace(u')', u'')
|
|
|
|
text = text.replace(u'{', u'')
|
|
|
|
text = text.replace(u'}', u'')
|
|
|
|
text = text.replace(u'?', u'')
|
2009-06-12 17:20:40 +00:00
|
|
|
self.song.search_lyrics = unicode(text)
|
|
|
|
self.song.lyrics = unicode(sxml.extract_xml())
|
|
|
|
|
|
|
|
def processTitle(self):
|
2009-06-13 06:46:13 +00:00
|
|
|
log.debug(u'processTitle')
|
2009-08-06 21:30:14 +00:00
|
|
|
self.song.search_title = self.song.search_title.replace(u'\'', u'')
|
|
|
|
self.song.search_title = self.song.search_title.replace(u',', u'')
|
|
|
|
self.song.search_title = self.song.search_title.replace(u';', u'')
|
|
|
|
self.song.search_title = self.song.search_title.replace(u':', u'')
|
|
|
|
self.song.search_title = self.song.search_title.replace(u'(', u'')
|
|
|
|
self.song.search_title = self.song.search_title.replace(u')', u'')
|
|
|
|
self.song.search_title = self.song.search_title.replace(u'{', u'')
|
|
|
|
self.song.search_title = self.song.search_title.replace(u'}', u'')
|
|
|
|
self.song.search_title = self.song.search_title.replace(u'?', u'')
|
|
|
|
self.song.search_title = unicode(self.song.search_title)
|