2009-01-01 10:03:09 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2009-01-02 20:20:33 +00:00
|
|
|
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, Carsten Tinggaard
|
2009-01-02 20:20:33 +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.
|
2009-01-01 10:03:09 +00:00
|
|
|
|
2009-01-02 20:20:33 +00:00
|
|
|
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-01 10:03:09 +00:00
|
|
|
|
|
|
|
from PyQt4 import QtGui, QtCore
|
2009-06-04 19:00:41 +00:00
|
|
|
from openlp.plugins.songs.lib import TextListData
|
2009-01-01 10:03:09 +00:00
|
|
|
|
2009-06-04 19:00:41 +00:00
|
|
|
from openlp.plugins.songs.forms.topicsdialog import Ui_TopicsDialog
|
|
|
|
from openlp.plugins.songs.lib.classes import Topic
|
2009-01-01 10:03:09 +00:00
|
|
|
|
2009-06-04 19:00:41 +00:00
|
|
|
class TopicsForm(QtGui.QDialog, Ui_TopicsDialog):
|
2009-01-01 10:03:09 +00:00
|
|
|
"""
|
|
|
|
Class documentation goes here.
|
|
|
|
"""
|
|
|
|
def __init__(self, songmanager, parent = None):
|
|
|
|
"""
|
|
|
|
Constructor
|
|
|
|
"""
|
2009-06-04 19:00:41 +00:00
|
|
|
QtGui.QDialog.__init__(self, parent)
|
2009-01-01 10:03:09 +00:00
|
|
|
self.setupUi(self)
|
|
|
|
self.songmanager = songmanager
|
2009-06-04 16:14:10 +00:00
|
|
|
self.currentRow = 0
|
2009-06-05 05:00:26 +00:00
|
|
|
self.topic = None
|
2009-06-04 16:14:10 +00:00
|
|
|
|
|
|
|
QtCore.QObject.connect(self.DeleteButton,
|
|
|
|
QtCore.SIGNAL('pressed()'), self.onDeleteButtonClick)
|
|
|
|
QtCore.QObject.connect(self.ClearButton,
|
|
|
|
QtCore.SIGNAL('pressed()'), self.onClearButtonClick)
|
|
|
|
QtCore.QObject.connect(self.AddUpdateButton,
|
|
|
|
QtCore.SIGNAL('pressed()'), self.onAddUpdateButtonClick)
|
2009-06-04 19:00:41 +00:00
|
|
|
QtCore.QObject.connect(self.TopicNameEdit,
|
|
|
|
QtCore.SIGNAL('lostFocus()'), self.onTopicNameEditLostFocus)
|
|
|
|
QtCore.QObject.connect(self.TopicsListView,
|
|
|
|
QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onTopicsListViewItemClicked)
|
2009-02-19 22:25:58 +00:00
|
|
|
|
2009-01-01 10:03:09 +00:00
|
|
|
def load_form(self):
|
2009-06-04 16:14:10 +00:00
|
|
|
"""
|
|
|
|
Refresh the screen and rest fields
|
|
|
|
"""
|
2009-06-04 19:00:41 +00:00
|
|
|
self.TopicsListData.resetStore()
|
2009-06-04 16:14:10 +00:00
|
|
|
self.onClearButtonClick() # tidy up screen
|
2009-06-05 05:00:26 +00:00
|
|
|
topics = self.songmanager.get_topics()
|
|
|
|
for topic in topics:
|
|
|
|
self.TopicsListData.addRow(topic.id,topic.name)
|
|
|
|
#rowCount is number of rows BUT test should be Zero based
|
|
|
|
row_count = self.TopicsListData.rowCount(None) - 1
|
2009-06-04 16:14:10 +00:00
|
|
|
if self.currentRow > row_count:
|
|
|
|
# in case we have delete the last row of the table
|
|
|
|
self.currentRow = row_count
|
2009-06-04 19:00:41 +00:00
|
|
|
row = self.TopicsListData.createIndex(self.currentRow, 0)
|
2009-06-04 16:14:10 +00:00
|
|
|
if row.isValid():
|
2009-06-04 19:00:41 +00:00
|
|
|
self.TopicsListView.selectionModel().setCurrentIndex(row,
|
|
|
|
QtGui.QItemSelectionModel.SelectCurrent)
|
2009-06-04 16:14:10 +00:00
|
|
|
self._validate_form()
|
|
|
|
|
|
|
|
def onDeleteButtonClick(self):
|
|
|
|
"""
|
|
|
|
Delete the Topic is the Topic is not attached to any songs
|
|
|
|
"""
|
2009-06-05 05:00:26 +00:00
|
|
|
self.songmanager.delete_topic(self.topic.id)
|
2009-06-04 16:14:10 +00:00
|
|
|
self.load_form()
|
2009-02-19 22:25:58 +00:00
|
|
|
|
2009-06-04 19:00:41 +00:00
|
|
|
def onTopicNameEditLostFocus(self):
|
2009-06-04 16:14:10 +00:00
|
|
|
self._validate_form()
|
|
|
|
|
|
|
|
def onAddUpdateButtonClick(self):
|
|
|
|
"""
|
|
|
|
Sent New or update details to the database
|
|
|
|
"""
|
2009-06-05 05:00:26 +00:00
|
|
|
if self.topic == None:
|
|
|
|
self.topic = Topic()
|
|
|
|
self.topic.name = unicode(self.TopicNameEdit.displayText())
|
|
|
|
self.songmanager.save_topic(self.topic)
|
2009-06-04 16:14:10 +00:00
|
|
|
self.onClearButtonClick()
|
|
|
|
self.load_form()
|
|
|
|
|
|
|
|
def onClearButtonClick(self):
|
2009-01-01 10:03:09 +00:00
|
|
|
"""
|
2009-06-04 16:14:10 +00:00
|
|
|
Tidy up screen if clear button pressed
|
2009-01-01 10:03:09 +00:00
|
|
|
"""
|
2009-06-04 19:00:41 +00:00
|
|
|
self.TopicNameEdit.setText(u'')
|
2009-06-04 16:14:10 +00:00
|
|
|
self.MessageLabel.setText(u'')
|
|
|
|
self.DeleteButton.setEnabled(False)
|
2009-06-04 19:00:41 +00:00
|
|
|
self.AddUpdateButton.setEnabled(True)
|
2009-06-05 05:00:26 +00:00
|
|
|
self.topic = None
|
2009-06-04 16:14:10 +00:00
|
|
|
self._validate_form()
|
2009-02-19 22:25:58 +00:00
|
|
|
|
2009-06-04 19:00:41 +00:00
|
|
|
def onTopicsListViewItemClicked(self, index):
|
2009-01-01 10:03:09 +00:00
|
|
|
"""
|
2009-06-04 16:14:10 +00:00
|
|
|
An Topic has been selected display it
|
|
|
|
If the Topic is attached to a Song prevent delete
|
2009-01-01 10:03:09 +00:00
|
|
|
"""
|
2009-06-04 16:14:10 +00:00
|
|
|
self.currentRow = index.row()
|
2009-06-04 19:00:41 +00:00
|
|
|
id = int(self.TopicsListData.getId(index))
|
2009-06-05 05:00:26 +00:00
|
|
|
self.topic = self.songmanager.get_topic(id)
|
2009-06-04 16:14:10 +00:00
|
|
|
|
2009-06-05 05:00:26 +00:00
|
|
|
self.TopicNameEdit.setText(self.topic.name)
|
|
|
|
if len(self.topic.songs) > 0:
|
2009-06-04 16:14:10 +00:00
|
|
|
self.MessageLabel.setText("Topic in use 'Delete' is disabled")
|
|
|
|
self.DeleteButton.setEnabled(False)
|
|
|
|
else:
|
|
|
|
self.MessageLabel.setText("Topic is not used")
|
|
|
|
self.DeleteButton.setEnabled(True)
|
|
|
|
self._validate_form()
|
|
|
|
|
|
|
|
def _validate_form(self):
|
2009-06-04 19:00:41 +00:00
|
|
|
if len(self.TopicNameEdit.displayText()) == 0: # We need at lease a display name
|
2009-06-04 16:14:10 +00:00
|
|
|
self.AddUpdateButton.setEnabled(False)
|
|
|
|
else:
|
|
|
|
self.AddUpdateButton.setEnabled(True)
|