diff --git a/openlp/plugins/songs/forms/authorsdialog.py b/openlp/plugins/songs/forms/authorsdialog.py index 0fd81a353..d2e20e123 100644 --- a/openlp/plugins/songs/forms/authorsdialog.py +++ b/openlp/plugins/songs/forms/authorsdialog.py @@ -1,12 +1,22 @@ # -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +""" +OpenLP - Open Source Lyrics Projection +Copyright (c) 2008 Raoul Snyman +Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, -# Form implementation generated from reading ui file 'authorsdialog.ui' -# -# Created: Sat Jan 3 11:48:36 2009 -# by: PyQt4 UI code generator 4.4.3 -# -# WARNING! All changes made in this file will be lost! +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 +""" from PyQt4 import QtCore, QtGui from openlp.plugins.songs.lib import TextListData @@ -18,13 +28,9 @@ class Ui_AuthorsDialog(object): self.DialogLayout.setSpacing(8) self.DialogLayout.setMargin(8) self.DialogLayout.setObjectName("DialogLayout") - self.AuthorListView = QtGui.QListView() self.AuthorListView.setAlternatingRowColors(True) - self.AuthorListData = TextListData() - self.AuthorListView.setModel(self.AuthorListData) self.DialogLayout.addWidget(self.AuthorListView) - self.AuthorDetails = QtGui.QGroupBox(AuthorsDialog) self.AuthorDetails.setMinimumSize(QtCore.QSize(0, 0)) self.AuthorDetails.setObjectName("AuthorDetails") diff --git a/openlp/plugins/songs/forms/authorsform.py b/openlp/plugins/songs/forms/authorsform.py index 495396c39..09d6dc216 100644 --- a/openlp/plugins/songs/forms/authorsform.py +++ b/openlp/plugins/songs/forms/authorsform.py @@ -19,7 +19,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA from PyQt4 import QtGui, QtCore from openlp.core.lib import translate from openlp.plugins.songs.forms.authorsdialog import Ui_AuthorsDialog -from openlp.plugins.songs.lib import TextListData class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): """ diff --git a/openlp/plugins/songs/forms/editsongdialog.py b/openlp/plugins/songs/forms/editsongdialog.py index 5178fa937..3e1ec3717 100644 --- a/openlp/plugins/songs/forms/editsongdialog.py +++ b/openlp/plugins/songs/forms/editsongdialog.py @@ -1,4 +1,22 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +""" +OpenLP - Open Source Lyrics Projection +Copyright (c) 2008 Raoul Snyman +Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, +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 +""" from openlp.core.lib import translate from PyQt4 import QtCore, QtGui diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 202c6ec31..2d1bd3994 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -99,20 +99,26 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): authors = self.songmanager.get_authors() self.AuthorsSelectionComboItem.clear() for author in authors: + row = self.AuthorsSelectionComboItem.count() self.AuthorsSelectionComboItem.addItem(author.display_name) + self.AuthorsSelectionComboItem.setItemData(row, QtCore.QVariant(author.id)) def loadTopics(self): topics = self.songmanager.get_topics() self.SongTopicCombo.clear() for topic in topics: + row = self.SongTopicCombo.count() self.SongTopicCombo.addItem(topic.name) + self.SongTopicCombo.setItemData(row, QtCore.QVariant(topic.id)) def loadBooks(self): books = self.songmanager.get_books() self.SongbookCombo.clear() self.SongbookCombo.addItem(u' ') for book in books: + row = self.SongbookCombo.count() self.SongbookCombo.addItem(book.name) + self.SongbookCombo.setItemData(row, QtCore.QVariant(book.id)) def loadThemes(self, theme_list): self.ThemeSelectionComboItem.clear() @@ -180,8 +186,9 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.title_change = False def onAuthorAddtoSongItemClicked(self): - author_name = unicode(self.AuthorsSelectionComboItem.currentText()) - author = self.songmanager.get_author_by_name(author_name) + item = int(self.AuthorsSelectionComboItem.currentIndex()) + 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)) @@ -201,8 +208,9 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.AuthorsListView.takeItem(row) def onTopicAddtoSongItemClicked(self): - topic_name = unicode(self.SongTopicCombo.currentText()) - topic = self.songmanager.get_topic_by_name(topic_name) + item = int(self.SongTopicCombo.currentIndex()) + 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)) @@ -248,9 +256,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): if item == 0: self.song.song_book_id = 0 else: - book_name = unicode(self.SongbookCombo.itemText(item)) - book = self.songmanager.get_book_by_name(book_name) - self.song.song_book_id = book.id + item = int(self.SongbookCombo.currentIndex()) + self.song.song_book_id = (self.SongbookCombo.itemData(item)).toInt()[0] def onThemeComboChanged(self, item): if item == 0: @@ -293,22 +300,25 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): valid = True if len(self.TitleEditItem.displayText()) == 0: valid = False + self.TitleEditItem.setStyleSheet(u'background-color: red; color: white') + else: + self.TitleEditItem.setStyleSheet(u'') if len(self.CopyrightEditItem.displayText()) == 0: valid = False + self.CopyrightEditItem.setStyleSheet(u'background-color: red; color: white') + else: + self.CopyrightEditItem.setStyleSheet(u'') if self.VerseListWidget.count() == 0: valid = False + self.VerseListWidget.setStyleSheet(u'background-color: red; color: white') + else: + self.VerseListWidget.setStyleSheet(u'') if self.AuthorsListView.count() == 0: valid = False - return valid - - def _color_widget(self, slot, invalid): - r = Qt.QPalette(slot.palette()) - if invalid == True: - r.setColor(Qt.QPalette.Base, Qt.QColor(u'darkRed')) + self.AuthorsListView.setStyleSheet(u'background-color: red; color: white') else: - r.setColor(Qt.QPalette.Base, Qt.QColor(u'white')) - slot.setPalette(r) - slot.setAutoFillBackground(True) + self.AuthorsListView.setStyleSheet(u'') + return valid def on_TitleEditItem_lostFocus(self): self.song.title = self.TitleEditItem.text() diff --git a/openlp/plugins/songs/lib/manager.py b/openlp/plugins/songs/lib/manager.py index 5a75ac506..c21721fd1 100644 --- a/openlp/plugins/songs/lib/manager.py +++ b/openlp/plugins/songs/lib/manager.py @@ -127,12 +127,6 @@ class SongManager(): """ return self.session.query(Author).get(id) - def get_author_by_name(self, name): - """ - Details of the Author - """ - return self.session.query(Author).filter_by(display_name = name).first() - def save_author(self, author): """ Save the Author and refresh the cache @@ -172,12 +166,6 @@ class SongManager(): """ return self.session.query(Topic).get(id) - def get_topic_by_name(self, name): - """ - Details of the Topic - """ - return self.session.query(Topic).filter_by(name = name).first() - def save_topic(self, topic): """ Save the Topic @@ -217,12 +205,6 @@ class SongManager(): """ return self.session.query(Book).get(id) - def get_book_by_name(self, name): - """ - Details of the Books - """ - return self.session.query(Book).filter_by(name = name).first() - def save_book(self, book): """ Save the Book diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 32cbce9b1..7a7692d23 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -23,12 +23,11 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, translate, ServiceItem, SongXMLParser from openlp.plugins.songs.forms import EditSongForm -from openlp.plugins.songs.lib import TextListData -class SongList(QtGui.QListView): +class SongList(QtGui.QListWidget): def __init__(self,parent=None,name=None): - QtGui.QListView.__init__(self,parent) + QtGui.QListWidget.__init__(self,parent) def mouseMoveEvent(self, event): """ @@ -119,14 +118,12 @@ class SongMediaItem(MediaManagerItem): self.SearchLayout.addWidget(self.SearchTextButton, 3, 2, 1, 1) # Add the song widget to the page layout self.PageLayout.addWidget(self.SongWidget) - self.SongListView = SongList() - self.SongListView.setAlternatingRowColors(True) - self.SongListData = TextListData() - self.SongListView.setModel(self.SongListData) - self.SongListView.setDragEnabled(True) - self.SongListView.setObjectName(u'SongListView') - self.PageLayout.addWidget(self.SongListView) - self.SongListView.setDragEnabled(True) + self.SongListWidget = SongList() + self.SongListWidget.setAlternatingRowColors(True) + self.SongListWidget.setDragEnabled(True) + self.SongListWidget.setObjectName(u'SongListWidget') + self.PageLayout.addWidget(self.SongListWidget) + self.SongListWidget.setDragEnabled(True) # Signals and slots QtCore.QObject.connect(self.SearchTextButton, QtCore.SIGNAL(u'pressed()'), self.onSearchTextButtonClick) @@ -134,21 +131,21 @@ class SongMediaItem(MediaManagerItem): QtCore.SIGNAL(u'pressed()'), self.onClearTextButtonClick) QtCore.QObject.connect(self.SearchTextEdit, QtCore.SIGNAL(u'textChanged(const QString&)'), self.onSearchTextEditChanged) - QtCore.QObject.connect(self.SongListView, + QtCore.QObject.connect(self.SongListWidget, QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.onSongPreviewClick) #define and add the context menu - self.SongListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) - self.SongListView.addAction(self.contextMenuAction(self.SongListView, + self.SongListWidget.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) + self.SongListWidget.addAction(self.contextMenuAction(self.SongListWidget, ':/songs/song_new.png', translate(u'SongMediaItem', u'&Edit Song'), self.onSongEditClick)) - self.SongListView.addAction(self.contextMenuSeparator(self.SongListView)) - self.SongListView.addAction(self.contextMenuAction(self.SongListView, + self.SongListWidget.addAction(self.contextMenuSeparator(self.SongListWidget)) + self.SongListWidget.addAction(self.contextMenuAction(self.SongListWidget, ':/system/system_preview.png', translate(u'SongMediaItem', u'&Preview Song'), self.onSongPreviewClick)) - self.SongListView.addAction(self.contextMenuAction(self.SongListView, + self.SongListWidget.addAction(self.contextMenuAction(self.SongListWidget, ':/system/system_live.png', translate(u'SongMediaItem', u'&Show Live'), self.onSongLiveClick)) - self.SongListView.addAction(self.contextMenuAction(self.SongListView, + self.SongListWidget.addAction(self.contextMenuAction(self.SongListWidget, ':/system/system_add.png', translate(u'SongMediaItem', u'&Add to Service'), self.onSongAddClick)) @@ -165,7 +162,7 @@ class SongMediaItem(MediaManagerItem): def displayResults(self, searchresults): log.debug(u'display results') - self.SongListData.resetStore() + self.SongListWidget.clear() #log.debug(u'Records returned from search %s", len(searchresults)) for song in searchresults: author_list = u'' @@ -174,7 +171,9 @@ class SongMediaItem(MediaManagerItem): author_list = author_list + u', ' author_list = author_list + author.display_name song_detail = unicode(u'%s (%s)' % (unicode(song.title), unicode(author_list))) - self.SongListData.addRow(song.id,song_detail) + song_name = QtGui.QListWidgetItem(song_detail) + song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id)) + self.SongListWidget.addItem(song_name) def onClearTextButtonClick(self): """ @@ -209,18 +208,16 @@ class SongMediaItem(MediaManagerItem): self.edit_song_form.exec_() def onSongEditClick(self): - indexes = self.SongListView.selectedIndexes() - for index in indexes: - id = self.SongListData.getId(index) - self.edit_song_form.loadSong(id) - self.edit_song_form.exec_() + item = self.SongListWidget.currentItem() + item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] + self.edit_song_form.loadSong(item_id) + self.edit_song_form.exec_() def onSongDeleteClick(self): - indexes = self.SongListView.selectedIndexes() - for index in indexes: - id = self.SongListData.getId(index) - self.parent.songmanager.delete_song(id) - self.SongListData.deleteRow(index) + item = self.SongListWidget.currentItem() + item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] + self.parent.songmanager.delete_song(id) + self.SongListWidget.removeItem(item) def onSongPreviewClick(self): service_item = ServiceItem(self.parent) @@ -233,29 +230,28 @@ class SongMediaItem(MediaManagerItem): raw_footer = [] author_list = u'' ccl = u'' - indexes = self.SongListView.selectedIndexes() - for index in indexes: - id = self.SongListData.getId(index) - song = self.parent.songmanager.get_song(id) - service_item.theme = song.theme_name - if song.lyrics.startswith(u' 1: - author_list = author_list + u', ' - author_list = author_list + unicode(author.display_name) - if song.ccli_number == None or len(song.ccli_number) == 0: - ccl = self.parent.settings.GeneralTab.CCLNumber - else: - ccl = unicode(song.ccli_number) + item = self.SongListWidget.currentItem() + item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] + song = self.parent.songmanager.get_song(item_id) + service_item.theme = song.theme_name + if song.lyrics.startswith(u' 1: + author_list = author_list + u', ' + author_list = author_list + unicode(author.display_name) + if song.ccli_number == None or len(song.ccli_number) == 0: + ccl = self.parent.settings.GeneralTab.CCLNumber + else: + ccl = unicode(song.ccli_number) raw_footer.append(song.title) raw_footer.append(author_list) raw_footer.append(song.copyright )