2008-11-28 14:05:41 +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 #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2009-12-31 12:52:01 +00:00
|
|
|
# Copyright (c) 2008-2010 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
|
2010-07-24 22:10:47 +00:00
|
|
|
# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian #
|
|
|
|
# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
|
|
|
|
# Carsten Tinggaard, Frode Woldsund #
|
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 #
|
|
|
|
###############################################################################
|
2008-11-28 14:05:41 +00:00
|
|
|
|
2010-02-14 13:27:32 +00:00
|
|
|
from PyQt4 import QtGui, QtCore
|
2010-02-17 19:13:04 +00:00
|
|
|
|
2010-05-31 22:06:16 +00:00
|
|
|
from openlp.core.lib import translate
|
2010-06-12 01:52:04 +00:00
|
|
|
from openlp.plugins.alerts.lib.db import AlertItem
|
2009-05-01 22:26:43 +00:00
|
|
|
|
2010-02-14 13:27:32 +00:00
|
|
|
from alertdialog import Ui_AlertDialog
|
|
|
|
|
|
|
|
class AlertForm(QtGui.QDialog, Ui_AlertDialog):
|
|
|
|
"""
|
2010-06-10 01:57:59 +00:00
|
|
|
Provide UI for the alert system
|
2010-02-14 13:27:32 +00:00
|
|
|
"""
|
|
|
|
def __init__(self, manager, parent):
|
|
|
|
"""
|
2010-06-10 01:57:59 +00:00
|
|
|
Initialise the alert form
|
2010-02-14 13:27:32 +00:00
|
|
|
"""
|
|
|
|
self.manager = manager
|
2010-04-21 17:21:56 +00:00
|
|
|
self.item_id = None
|
2010-07-31 00:34:37 +00:00
|
|
|
QtGui.QDialog.__init__(self, parent)
|
2009-03-01 09:13:27 +00:00
|
|
|
self.setupUi(self)
|
2010-06-08 15:38:09 +00:00
|
|
|
QtCore.QObject.connect(self.DisplayButton, QtCore.SIGNAL(u'clicked()'),
|
|
|
|
self.onDisplayClicked)
|
2010-04-17 07:31:15 +00:00
|
|
|
QtCore.QObject.connect(self.DisplayCloseButton,
|
2010-06-08 15:38:09 +00:00
|
|
|
QtCore.SIGNAL(u'clicked()'), self.onDisplayCloseClicked)
|
2010-04-17 07:31:15 +00:00
|
|
|
QtCore.QObject.connect(self.AlertTextEdit,
|
2010-06-08 15:38:09 +00:00
|
|
|
QtCore.SIGNAL(u'textChanged(const QString&)'), self.onTextChanged)
|
|
|
|
QtCore.QObject.connect(self.NewButton, QtCore.SIGNAL(u'clicked()'),
|
|
|
|
self.onNewClick)
|
|
|
|
QtCore.QObject.connect(self.DeleteButton, QtCore.SIGNAL(u'clicked()'),
|
|
|
|
self.onDeleteClick)
|
|
|
|
QtCore.QObject.connect(self.SaveButton, QtCore.SIGNAL(u'clicked()'),
|
|
|
|
self.onSaveClick)
|
2010-02-14 13:27:32 +00:00
|
|
|
QtCore.QObject.connect(self.AlertListWidget,
|
2010-06-08 15:38:09 +00:00
|
|
|
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.onDoubleClick)
|
2010-02-14 13:27:32 +00:00
|
|
|
QtCore.QObject.connect(self.AlertListWidget,
|
2010-06-08 15:38:09 +00:00
|
|
|
QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSingleClick)
|
2008-11-28 14:05:41 +00:00
|
|
|
|
2010-02-14 13:27:32 +00:00
|
|
|
def loadList(self):
|
|
|
|
self.AlertListWidget.clear()
|
2010-07-18 23:37:24 +00:00
|
|
|
alerts = self.manager.get_all_objects(AlertItem,
|
|
|
|
order_by_ref=AlertItem.text)
|
2010-02-14 13:27:32 +00:00
|
|
|
for alert in alerts:
|
|
|
|
item_name = QtGui.QListWidgetItem(alert.text)
|
2010-06-08 15:38:09 +00:00
|
|
|
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(alert.id))
|
2010-02-14 13:27:32 +00:00
|
|
|
self.AlertListWidget.addItem(item_name)
|
2010-04-17 07:31:15 +00:00
|
|
|
self.SaveButton.setEnabled(False)
|
|
|
|
self.DeleteButton.setEnabled(False)
|
2008-11-28 14:05:41 +00:00
|
|
|
|
2009-03-22 07:13:34 +00:00
|
|
|
def onDisplayClicked(self):
|
2010-04-17 07:31:15 +00:00
|
|
|
if self.triggerAlert(unicode(self.AlertTextEdit.text())):
|
|
|
|
self.loadList()
|
|
|
|
|
|
|
|
def onDisplayCloseClicked(self):
|
|
|
|
if self.triggerAlert(unicode(self.AlertTextEdit.text())):
|
|
|
|
self.close()
|
|
|
|
|
|
|
|
def onDeleteClick(self):
|
|
|
|
item = self.AlertListWidget.currentItem()
|
|
|
|
if item:
|
|
|
|
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
|
2010-06-12 23:00:14 +00:00
|
|
|
self.manager.delete_object(AlertItem, item_id)
|
2010-04-17 07:31:15 +00:00
|
|
|
row = self.AlertListWidget.row(item)
|
|
|
|
self.AlertListWidget.takeItem(row)
|
|
|
|
self.AlertTextEdit.setText(u'')
|
|
|
|
self.SaveButton.setEnabled(False)
|
|
|
|
self.DeleteButton.setEnabled(False)
|
|
|
|
|
|
|
|
def onNewClick(self):
|
|
|
|
if len(self.AlertTextEdit.text()) == 0:
|
|
|
|
QtGui.QMessageBox.information(self,
|
2010-07-06 15:26:52 +00:00
|
|
|
translate('AlertsPlugin.AlertForm', 'New Alert'),
|
|
|
|
translate('AlertsPlugin.AlertForm', 'You haven\'t specified '
|
|
|
|
'any text for your alert. Please type in some text before '
|
|
|
|
'clicking New.'))
|
2010-04-17 07:31:15 +00:00
|
|
|
else:
|
2010-02-14 13:27:32 +00:00
|
|
|
alert = AlertItem()
|
2010-04-17 07:31:15 +00:00
|
|
|
alert.text = unicode(self.AlertTextEdit.text())
|
2010-06-28 13:38:29 +00:00
|
|
|
self.manager.save_object(alert)
|
2010-04-21 17:21:56 +00:00
|
|
|
self.AlertTextEdit.setText(u'')
|
2010-04-17 07:31:15 +00:00
|
|
|
self.loadList()
|
|
|
|
|
|
|
|
def onSaveClick(self):
|
2010-06-10 01:57:59 +00:00
|
|
|
"""
|
|
|
|
Save an alert
|
|
|
|
"""
|
2010-04-21 17:21:56 +00:00
|
|
|
if self.item_id:
|
2010-06-12 23:00:14 +00:00
|
|
|
alert = self.manager.get_object(AlertItem, self.item_id)
|
2010-04-21 17:21:56 +00:00
|
|
|
alert.text = unicode(self.AlertTextEdit.text())
|
2010-06-28 13:38:29 +00:00
|
|
|
self.manager.save_object(alert)
|
2010-04-21 17:21:56 +00:00
|
|
|
self.item_id = None
|
|
|
|
self.loadList()
|
|
|
|
else:
|
|
|
|
self.onNewClick()
|
2010-02-14 13:27:32 +00:00
|
|
|
|
|
|
|
def onTextChanged(self):
|
2010-06-10 01:57:59 +00:00
|
|
|
"""
|
|
|
|
Enable save button when data has been changed by editing the form
|
|
|
|
"""
|
2010-04-21 17:21:56 +00:00
|
|
|
self.SaveButton.setEnabled(True)
|
2010-02-14 13:27:32 +00:00
|
|
|
|
|
|
|
def onDoubleClick(self):
|
|
|
|
"""
|
|
|
|
List item has been double clicked to display it
|
|
|
|
"""
|
|
|
|
items = self.AlertListWidget.selectedIndexes()
|
|
|
|
for item in items:
|
|
|
|
bitem = self.AlertListWidget.item(item.row())
|
|
|
|
self.triggerAlert(bitem.text())
|
2010-04-21 17:21:56 +00:00
|
|
|
self.AlertTextEdit.setText(bitem.text())
|
|
|
|
self.item_id = (bitem.data(QtCore.Qt.UserRole)).toInt()[0]
|
|
|
|
self.SaveButton.setEnabled(False)
|
|
|
|
self.DeleteButton.setEnabled(True)
|
2010-02-14 13:27:32 +00:00
|
|
|
|
|
|
|
def onSingleClick(self):
|
|
|
|
"""
|
|
|
|
List item has been single clicked to add it to
|
|
|
|
the edit field so it can be changed.
|
|
|
|
"""
|
|
|
|
items = self.AlertListWidget.selectedIndexes()
|
|
|
|
for item in items:
|
|
|
|
bitem = self.AlertListWidget.item(item.row())
|
2010-04-17 07:31:15 +00:00
|
|
|
self.AlertTextEdit.setText(bitem.text())
|
2010-04-21 17:21:56 +00:00
|
|
|
self.item_id = (bitem.data(QtCore.Qt.UserRole)).toInt()[0]
|
|
|
|
self.SaveButton.setEnabled(False)
|
2010-04-17 07:31:15 +00:00
|
|
|
self.DeleteButton.setEnabled(True)
|
2010-02-14 13:27:32 +00:00
|
|
|
|
|
|
|
def triggerAlert(self, text):
|
2010-04-17 07:31:15 +00:00
|
|
|
if text:
|
2010-04-21 17:21:56 +00:00
|
|
|
text = text.replace(u'<>', unicode(self.ParameterEdit.text()))
|
2010-07-31 00:34:37 +00:00
|
|
|
self.parent().alertsmanager.displayAlert(text)
|
2010-04-17 07:31:15 +00:00
|
|
|
return True
|
2010-07-27 09:32:52 +00:00
|
|
|
return False
|