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-01-12 19:31:29 +00:00
|
|
|
from PyQt4 import Qt, QtCore, QtGui
|
2009-06-12 17:20:40 +00:00
|
|
|
from openlp.core.lib import SongXMLBuilder, SongXMLParser
|
2009-03-09 12:49:55 +00:00
|
|
|
from openlp.plugins.songs.forms import AuthorsForm, TopicsForm, SongBookForm, \
|
|
|
|
EditVerseForm
|
2009-06-12 17:20:40 +00:00
|
|
|
from openlp.plugins.songs.lib.models import Song
|
2009-01-01 10:03:09 +00:00
|
|
|
|
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
|
|
|
"""
|
|
|
|
Class documentation goes here.
|
|
|
|
"""
|
2009-03-07 21:38:59 +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-03-07 21:38:59 +00:00
|
|
|
QtCore.QObject.connect(self.AddAuthorsButton,
|
2009-06-10 17:12:03 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onAddAuthorsButtonClicked)
|
2009-03-07 21:38:59 +00:00
|
|
|
QtCore.QObject.connect(self.AddTopicButton,
|
2009-06-10 17:12:03 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onAddTopicButtonClicked)
|
2009-03-07 21:38:59 +00:00
|
|
|
QtCore.QObject.connect(self.AddSongBookButton,
|
2009-06-10 17:12:03 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onAddSongBookButtonClicked)
|
2009-03-07 21:38:59 +00:00
|
|
|
QtCore.QObject.connect(self.CopyrightInsertItem,
|
2009-06-10 17:12:03 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onCopyrightInsertItemTriggered)
|
2009-03-07 21:38:59 +00:00
|
|
|
QtCore.QObject.connect(self.AddButton,
|
2009-06-10 17:12:03 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onAddVerseButtonClicked)
|
2009-03-07 21:38:59 +00:00
|
|
|
QtCore.QObject.connect(self.EditButton,
|
2009-06-10 17:12:03 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onEditVerseButtonClicked)
|
2009-03-07 21:38:59 +00:00
|
|
|
QtCore.QObject.connect(self.DeleteButton,
|
2009-06-10 17:12:03 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onDeleteVerseButtonClicked)
|
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-01-01 10:03:09 +00:00
|
|
|
self.authors_form = AuthorsForm(self.songmanager)
|
|
|
|
self.topics_form = TopicsForm(self.songmanager)
|
2009-01-17 13:58:16 +00:00
|
|
|
self.song_book_form = SongBookForm(self.songmanager)
|
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-03-09 18:47:37 +00:00
|
|
|
self.loadAuthors()
|
2009-06-04 19:00:41 +00:00
|
|
|
self.loadTopics()
|
2009-06-04 20:06:32 +00:00
|
|
|
self.loadBooks()
|
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:
|
|
|
|
self.AuthorsSelectionComboItem.addItem(author.display_name)
|
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:
|
|
|
|
self.SongTopicCombo.addItem(topic.name)
|
|
|
|
|
2009-06-04 20:06:32 +00:00
|
|
|
def loadBooks(self):
|
|
|
|
books = self.songmanager.get_books()
|
|
|
|
self.SongbookCombo.clear()
|
|
|
|
for book in books:
|
|
|
|
self.SongbookCombo.addItem(book.name)
|
|
|
|
|
2009-06-12 17:20:40 +00:00
|
|
|
def newSong(self):
|
|
|
|
self.song = Song()
|
|
|
|
self.TitleEditItem.setText(u'')
|
|
|
|
self.AlternativeEdit.setText(u'')
|
|
|
|
self.CopyrightEditItem.setText(u'')
|
|
|
|
self.VerseListWidget.clear()
|
|
|
|
self.AuthorsListView.clear()
|
|
|
|
self.TopicsListView.clear()
|
|
|
|
|
2009-02-19 22:25:58 +00:00
|
|
|
def loadSong(self, id):
|
|
|
|
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'@')
|
|
|
|
if len(title) > 1:
|
|
|
|
self.AlternativeEdit.setText(title[1])
|
2009-01-12 19:31:29 +00:00
|
|
|
self.CopyrightEditItem.setText(self.song.copyright)
|
2009-06-12 05:13:54 +00:00
|
|
|
self.VerseListWidget.clear()
|
2009-06-12 17:20:40 +00:00
|
|
|
#lazy xml migration for now
|
|
|
|
if self.song.lyrics.startswith(u'<?xml version='):
|
|
|
|
songXML=SongXMLParser(self.song.lyrics)
|
|
|
|
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()
|
|
|
|
for topics in self.song.topics:
|
|
|
|
author_name = QtGui.QListWidgetItem(unicode(author.display_name))
|
|
|
|
author_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(author.id))
|
|
|
|
self.AuthorsListView.addItem(author_name)
|
2009-01-17 13:58:16 +00:00
|
|
|
self._validate_song()
|
2008-12-01 13:15:31 +00:00
|
|
|
|
2009-02-19 22:25:58 +00:00
|
|
|
def onAddAuthorsButtonClicked(self):
|
2009-01-01 10:03:09 +00:00
|
|
|
"""
|
|
|
|
Slot documentation goes here.
|
|
|
|
"""
|
|
|
|
self.authors_form.load_form()
|
2009-02-19 22:25:58 +00:00
|
|
|
self.authors_form.exec_()
|
2009-03-09 18:47:37 +00:00
|
|
|
self.loadAuthors()
|
2009-01-01 10:03:09 +00:00
|
|
|
|
2009-02-19 22:25:58 +00:00
|
|
|
def onAddTopicButtonClicked(self):
|
2009-01-01 10:03:09 +00:00
|
|
|
"""
|
|
|
|
Slot documentation goes here.
|
|
|
|
"""
|
|
|
|
self.topics_form.load_form()
|
2009-02-19 22:25:58 +00:00
|
|
|
self.topics_form.exec_()
|
2009-06-04 19:00:41 +00:00
|
|
|
self.loadTopics()
|
2009-01-17 13:58:16 +00:00
|
|
|
|
2009-02-28 23:19:45 +00:00
|
|
|
def onAddSongBookButtonClicked(self):
|
2009-01-01 10:03:09 +00:00
|
|
|
"""
|
|
|
|
Slot documentation goes here.
|
|
|
|
"""
|
|
|
|
self.song_book_form.load_form()
|
2009-02-19 22:25:58 +00:00
|
|
|
self.song_book_form.exec_()
|
2009-06-04 20:06:32 +00:00
|
|
|
self.loadBooks()
|
2009-01-17 13:58:16 +00:00
|
|
|
|
2009-03-07 21:38:59 +00:00
|
|
|
def onAddVerseButtonClicked(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())
|
|
|
|
|
|
|
|
def onEditVerseButtonClicked(self):
|
|
|
|
item = self.VerseListWidget.currentItem()
|
|
|
|
self.verse_form.setVerse(item.text())
|
|
|
|
self.verse_form.exec_()
|
|
|
|
item.setText(self.verse_form.getVerse())
|
|
|
|
|
|
|
|
def onDeleteVerseButtonClicked(self):
|
|
|
|
item = self.VerseListWidget.takeItem(self.VerseListWidget.currentRow())
|
|
|
|
item = None
|
|
|
|
|
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-01-12 19:31:29 +00:00
|
|
|
valid = True # Lets be nice and assume the data is correct.
|
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-10 18:04:32 +00:00
|
|
|
if len(self.CopyrightEditItem.displayText()) == 0:
|
2009-01-12 19:31:29 +00:00
|
|
|
valid = False
|
2009-01-17 13:58:16 +00:00
|
|
|
|
2009-01-12 19:31:29 +00:00
|
|
|
def _color_widget(self, slot, invalid):
|
|
|
|
r = Qt.QPalette(slot.palette())
|
|
|
|
if invalid == True:
|
2009-06-10 17:12:03 +00:00
|
|
|
r.setColor(Qt.QPalette.Base, Qt.QColor(u'darkRed'))
|
2009-01-12 19:31:29 +00:00
|
|
|
else:
|
2009-06-10 17:12:03 +00:00
|
|
|
r.setColor(Qt.QPalette.Base, Qt.QColor(u'white'))
|
2009-01-12 19:31:29 +00:00
|
|
|
slot.setPalette(r)
|
2009-01-17 13:58:16 +00:00
|
|
|
slot.setAutoFillBackground(True)
|
|
|
|
|
2009-01-12 19:31:29 +00:00
|
|
|
def on_TitleEditItem_lostFocus(self):
|
2009-02-17 21:01:27 +00:00
|
|
|
#self._validate_song()
|
|
|
|
pass
|
|
|
|
|
2009-02-19 22:25:58 +00:00
|
|
|
def onCopyrightInsertItemTriggered(self):
|
|
|
|
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
|
|
|
|
|
|
|
def onAccept(self):
|
2009-06-10 18:04:32 +00:00
|
|
|
#self.song.topics.append(9) << need opject here
|
|
|
|
self.song.title = unicode(self.TitleEditItem.displayText())
|
|
|
|
self.song.copyright = unicode(self.CopyrightEditItem.displayText())
|
2009-06-12 05:13:54 +00:00
|
|
|
self.song.search_title = self.TitleEditItem.displayText() + u'@'+ self.AlternativeEdit.displayText()
|
2009-06-12 17:20:40 +00:00
|
|
|
self.processLyrics()
|
|
|
|
self.processTitle()
|
2009-06-12 05:13:54 +00:00
|
|
|
|
2009-06-11 05:13:10 +00:00
|
|
|
for i in range(0, self.AuthorsListView.count()):
|
|
|
|
print self.AuthorsListView.item(i)
|
|
|
|
for i in range(0, self.TopicsListView.count()):
|
|
|
|
print self.TopicsListView.item(i)
|
|
|
|
|
2009-06-10 18:04:32 +00:00
|
|
|
self.songmanager.save_song(self.song)
|
|
|
|
self.close()
|
2009-06-12 05:13:54 +00:00
|
|
|
|
2009-06-12 17:20:40 +00:00
|
|
|
def processLyrics(self):
|
|
|
|
sxml=SongXMLBuilder()
|
|
|
|
sxml.new_document()
|
|
|
|
sxml.add_lyrics_to_song()
|
|
|
|
count = 1
|
|
|
|
text = u' '
|
|
|
|
for i in range (0, self.VerseListWidget.count()):
|
|
|
|
sxml.add_verse_to_lyrics(u'Verse', unicode(count), unicode(self.VerseListWidget.item(i).text()))
|
|
|
|
text = text + unicode(self.VerseListWidget.item(i).text()) + u' '
|
|
|
|
count += 1
|
|
|
|
text = text.replace("'", 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'')
|
|
|
|
self.song.search_lyrics = unicode(text)
|
|
|
|
self.song.lyrics = unicode(sxml.extract_xml())
|
|
|
|
|
|
|
|
def processTitle(self):
|
2009-06-12 05:13:54 +00:00
|
|
|
self.song.search_title = self.song.search_title.replace("'", 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)
|