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-03-21 23:58:01 +00:00
|
|
|
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
|
|
|
|
# Thompson, Jon Tibble, Carsten Tinggaard #
|
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-02-14 13:27:32 +00:00
|
|
|
from openlp.plugins.alerts.lib.models import AlertItem
|
2010-05-31 22:06:16 +00:00
|
|
|
from openlp.core.lib import translate
|
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):
|
|
|
|
"""
|
|
|
|
Class documentation goes here.
|
|
|
|
"""
|
|
|
|
def __init__(self, manager, parent):
|
|
|
|
"""
|
|
|
|
Constructor
|
|
|
|
"""
|
|
|
|
self.manager = manager
|
2009-06-01 17:50:37 +00:00
|
|
|
self.parent = parent
|
2010-04-21 17:21:56 +00:00
|
|
|
self.item_id = None
|
2010-02-14 13:27:32 +00:00
|
|
|
QtGui.QDialog.__init__(self, None)
|
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()
|
|
|
|
alerts = self.manager.get_all_alerts()
|
|
|
|
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]
|
|
|
|
self.parent.manager.delete_alert(item_id)
|
|
|
|
row = self.AlertListWidget.row(item)
|
|
|
|
self.AlertListWidget.takeItem(row)
|
|
|
|
self.AlertTextEdit.setText(u'')
|
|
|
|
self.SaveButton.setEnabled(False)
|
|
|
|
self.DeleteButton.setEnabled(False)
|
|
|
|
self.EditButton.setEnabled(False)
|
|
|
|
|
|
|
|
def onNewClick(self):
|
|
|
|
if len(self.AlertTextEdit.text()) == 0:
|
|
|
|
QtGui.QMessageBox.information(self,
|
2010-06-06 11:34:35 +00:00
|
|
|
translate(u'AlertsPlugin.AlertForm', u'Item selected to Add'),
|
|
|
|
translate(u'AlertsPlugin.AlertForm', u'Missing data'))
|
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-02-14 13:27:32 +00:00
|
|
|
self.manager.save_alert(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-04-21 17:21:56 +00:00
|
|
|
if self.item_id:
|
|
|
|
alert = self.manager.get_alert(self.item_id)
|
|
|
|
alert.text = unicode(self.AlertTextEdit.text())
|
|
|
|
self.manager.save_alert(alert)
|
|
|
|
self.item_id = None
|
|
|
|
self.loadList()
|
|
|
|
else:
|
|
|
|
self.onNewClick()
|
2010-02-14 13:27:32 +00:00
|
|
|
|
|
|
|
def onTextChanged(self):
|
2010-04-17 07:31:15 +00:00
|
|
|
#Data has changed by editing it so potential storage required
|
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-04-17 07:31:15 +00:00
|
|
|
self.parent.alertsmanager.displayAlert(text)
|
|
|
|
return True
|
|
|
|
return False
|
2010-06-08 15:38:09 +00:00
|
|
|
|