Alerts now have history

This commit is contained in:
Tim Bentley 2010-02-14 13:27:32 +00:00
parent 9c97660b73
commit acc97f3c79
16 changed files with 738 additions and 212 deletions

View File

@ -29,9 +29,8 @@ import logging
from PyQt4 import QtCore, QtGui
from openlp.core.lib import Plugin, Receiver, str_to_bool, build_icon, PluginStatus
from openlp.plugins.alerts.lib import AlertsManager
from openlp.plugins.alerts.lib import AlertsManager, DBManager
from openlp.plugins.alerts.forms import AlertsTab, AlertForm
#from openlp.plugins.alerts.lib.models import alertsItem
class alertsPlugin(Plugin):
global log
@ -43,7 +42,8 @@ class alertsPlugin(Plugin):
self.weight = -3
self.icon = build_icon(u':/media/media_image.png')
self.alertsmanager = AlertsManager(self)
self.alertForm = AlertForm(self)
self.manager = DBManager(self.config)
self.alertForm = AlertForm(self.manager, self)
self.status = PluginStatus.Active
def get_settings_tab(self):
@ -87,6 +87,7 @@ class alertsPlugin(Plugin):
self.config.set_config(u'active', self.alertsActive)
def onAlertsTrigger(self):
self.alertForm.loadList()
self.alertForm.exec_()
def onalertsReport(self):

View File

@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'alertform.ui'
#
# Created: Sat Feb 13 08:19:51 2010
# by: PyQt4 UI code generator 4.6.2
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_AlertDialog(object):
def setupUi(self, AlertForm):
AlertForm.setObjectName("AlertDialog")
AlertForm.resize(430, 320)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/icon/openlp.org-icon-32.bmp"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
AlertForm.setWindowIcon(icon)
self.AlertFormLayout = QtGui.QVBoxLayout(AlertForm)
self.AlertFormLayout.setSpacing(8)
self.AlertFormLayout.setMargin(8)
self.AlertFormLayout.setObjectName("AlertFormLayout")
self.AlertEntryWidget = QtGui.QWidget(AlertForm)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.AlertEntryWidget.sizePolicy().hasHeightForWidth())
self.AlertEntryWidget.setSizePolicy(sizePolicy)
self.AlertEntryWidget.setObjectName("AlertEntryWidget")
self.verticalLayout_2 = QtGui.QVBoxLayout(self.AlertEntryWidget)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.AlertEntryLabel = QtGui.QLabel(self.AlertEntryWidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.AlertEntryLabel.sizePolicy().hasHeightForWidth())
self.AlertEntryLabel.setSizePolicy(sizePolicy)
self.AlertEntryLabel.setObjectName("AlertEntryLabel")
self.verticalLayout.addWidget(self.AlertEntryLabel)
self.AlertEntryEditItem = QtGui.QLineEdit(self.AlertEntryWidget)
self.AlertEntryEditItem.setObjectName("AlertEntryEditItem")
self.verticalLayout.addWidget(self.AlertEntryEditItem)
self.AlertListWidget = QtGui.QListWidget(self.AlertEntryWidget)
self.AlertListWidget.setObjectName("AlertListWidget")
self.verticalLayout.addWidget(self.AlertListWidget)
self.verticalLayout_2.addLayout(self.verticalLayout)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
spacerItem = QtGui.QSpacerItem(181, 38, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.DisplayButton = QtGui.QPushButton(self.AlertEntryWidget)
self.DisplayButton.setObjectName("DisplayButton")
self.horizontalLayout.addWidget(self.DisplayButton)
self.CancelButton = QtGui.QPushButton(self.AlertEntryWidget)
self.CancelButton.setObjectName("CancelButton")
self.horizontalLayout.addWidget(self.CancelButton)
self.verticalLayout_2.addLayout(self.horizontalLayout)
self.AlertFormLayout.addWidget(self.AlertEntryWidget)
self.retranslateUi(AlertForm)
QtCore.QObject.connect(self.CancelButton, QtCore.SIGNAL("clicked()"), AlertForm.close)
QtCore.QMetaObject.connectSlotsByName(AlertForm)
def retranslateUi(self, AlertForm):
AlertForm.setWindowTitle(QtGui.QApplication.translate("AlertForm", "Alert Message", None, QtGui.QApplication.UnicodeUTF8))
self.AlertEntryLabel.setText(QtGui.QApplication.translate("AlertForm", "Alert Text:", None, QtGui.QApplication.UnicodeUTF8))
self.DisplayButton.setText(QtGui.QApplication.translate("AlertForm", "Display", None, QtGui.QApplication.UnicodeUTF8))
self.CancelButton.setText(QtGui.QApplication.translate("AlertForm", "Cancel", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'alerteditdialog.ui'
#
# Created: Sat Feb 13 08:20:09 2010
# by: PyQt4 UI code generator 4.6.2
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_AlertList(object):
def setupUi(self, AlertList):
AlertList.setObjectName("AlertList")
AlertList.resize(400, 300)
self.buttonBox = QtGui.QDialogButtonBox(AlertList)
self.buttonBox.setGeometry(QtCore.QRect(220, 270, 173, 27))
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel)
self.buttonBox.setObjectName("buttonBox")
self.widget = QtGui.QWidget(AlertList)
self.widget.setGeometry(QtCore.QRect(20, 10, 361, 251))
self.widget.setObjectName("widget")
self.verticalLayout_2 = QtGui.QVBoxLayout(self.widget)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.lineEdit = QtGui.QLineEdit(self.widget)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout_2.addWidget(self.lineEdit)
self.SaveButton = QtGui.QPushButton(self.widget)
self.SaveButton.setObjectName("SaveButton")
self.horizontalLayout_2.addWidget(self.SaveButton)
self.verticalLayout_2.addLayout(self.horizontalLayout_2)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.listWidget = QtGui.QListWidget(self.widget)
self.listWidget.setAlternatingRowColors(True)
self.listWidget.setObjectName("listWidget")
self.horizontalLayout.addWidget(self.listWidget)
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.AddButton = QtGui.QPushButton(self.widget)
self.AddButton.setObjectName("AddButton")
self.verticalLayout.addWidget(self.AddButton)
self.EdirButton = QtGui.QPushButton(self.widget)
self.EdirButton.setObjectName("EdirButton")
self.verticalLayout.addWidget(self.EdirButton)
self.DeleteButton = QtGui.QPushButton(self.widget)
self.DeleteButton.setObjectName("DeleteButton")
self.verticalLayout.addWidget(self.DeleteButton)
self.horizontalLayout.addLayout(self.verticalLayout)
self.verticalLayout_2.addLayout(self.horizontalLayout)
self.retranslateUi(AlertList)
QtCore.QMetaObject.connectSlotsByName(AlertList)
def retranslateUi(self, AlertList):
AlertList.setWindowTitle(QtGui.QApplication.translate("AlertList", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.SaveButton.setText(QtGui.QApplication.translate("AlertList", "Save", None, QtGui.QApplication.UnicodeUTF8))
self.AddButton.setText(QtGui.QApplication.translate("AlertList", "Add", None, QtGui.QApplication.UnicodeUTF8))
self.EdirButton.setText(QtGui.QApplication.translate("AlertList", "Edit", None, QtGui.QApplication.UnicodeUTF8))
self.DeleteButton.setText(QtGui.QApplication.translate("AlertList", "Delete", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -23,79 +23,82 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
import logging
from PyQt4 import QtCore, QtGui
from openlp.core.lib import build_icon
from openlp.plugins.alerts.lib import alertmanager
from datetime import date
class AlertForm(QtGui.QDialog):
global log
log = logging.getLogger(u'AlertForm')
from PyQt4 import QtGui, QtCore
from openlp.plugins.alerts.lib.models import AlertItem
def __init__(self, parent):
QtGui.QDialog.__init__(self, None)
from alertdialog import Ui_AlertDialog
class AlertForm(QtGui.QDialog, Ui_AlertDialog):
"""
Class documentation goes here.
"""
def __init__(self, manager, parent):
"""
Constructor
"""
self.manager = manager
self.parent = parent
self.history_required = True
QtGui.QDialog.__init__(self, None)
self.setupUi(self)
log.debug(u'AlertForm Defined')
QtCore.QObject.connect(self.CancelButton,
QtCore.SIGNAL(u'clicked()'),
AlertForm.close)
QtCore.QObject.connect(self.DisplayButton,
QtCore.SIGNAL(u'clicked()'),
self.onDisplayClicked)
QtCore.QObject.connect(self.AlertEntryEditItem,
QtCore.SIGNAL(u'textChanged(const QString&)'),
self.onTextChanged)
QtCore.QObject.connect(self.AlertListWidget,
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
self.onDoubleClick)
QtCore.QObject.connect(self.AlertListWidget,
QtCore.SIGNAL(u'clicked(QModelIndex)'),
self.onSingleClick)
def setupUi(self, AlertForm):
AlertForm.setObjectName(u'AlertForm')
AlertForm.resize(370, 110)
icon = build_icon(u':/icon/openlp-logo-16x16.png')
AlertForm.setWindowIcon(icon)
self.AlertFormLayout = QtGui.QVBoxLayout(AlertForm)
self.AlertFormLayout.setSpacing(8)
self.AlertFormLayout.setMargin(8)
self.AlertFormLayout.setObjectName(u'AlertFormLayout')
self.AlertEntryWidget = QtGui.QWidget(AlertForm)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.AlertEntryWidget.sizePolicy().hasHeightForWidth())
self.AlertEntryWidget.setSizePolicy(sizePolicy)
self.AlertEntryWidget.setObjectName(u'AlertEntryWidget')
self.AlertEntryLabel = QtGui.QLabel(self.AlertEntryWidget)
self.AlertEntryLabel.setGeometry(QtCore.QRect(0, 0, 353, 16))
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.AlertEntryLabel.sizePolicy().hasHeightForWidth())
self.AlertEntryLabel.setSizePolicy(sizePolicy)
self.AlertEntryLabel.setObjectName(u'AlertEntryLabel')
self.AlertEntryEditItem = QtGui.QLineEdit(self.AlertEntryWidget)
self.AlertEntryEditItem.setGeometry(QtCore.QRect(0, 20, 353, 26))
self.AlertEntryEditItem.setObjectName(u'AlertEntryEditItem')
self.AlertFormLayout.addWidget(self.AlertEntryWidget)
self.ButtonBoxWidget = QtGui.QWidget(AlertForm)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.ButtonBoxWidget.sizePolicy().hasHeightForWidth())
self.ButtonBoxWidget.setSizePolicy(sizePolicy)
self.ButtonBoxWidget.setObjectName(u'ButtonBoxWidget')
self.horizontalLayout = QtGui.QHBoxLayout(self.ButtonBoxWidget)
self.horizontalLayout.setSpacing(8)
self.horizontalLayout.setMargin(0)
self.horizontalLayout.setObjectName(u'horizontalLayout')
spacerItem = QtGui.QSpacerItem(267, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.DisplayButton = QtGui.QPushButton(self.ButtonBoxWidget)
self.DisplayButton.setObjectName(u'DisplayButton')
self.horizontalLayout.addWidget(self.DisplayButton)
self.CancelButton = QtGui.QPushButton(self.ButtonBoxWidget)
self.CancelButton.setObjectName(u'CancelButton')
self.horizontalLayout.addWidget(self.CancelButton)
self.AlertFormLayout.addWidget(self.ButtonBoxWidget)
self.retranslateUi(AlertForm)
QtCore.QObject.connect(self.CancelButton, QtCore.SIGNAL(u'clicked()'), AlertForm.close)
QtCore.QObject.connect(self.DisplayButton, QtCore.SIGNAL(u'clicked()'), self.onDisplayClicked)
QtCore.QMetaObject.connectSlotsByName(AlertForm)
def retranslateUi(self, AlertForm):
AlertForm.setWindowTitle(self.trUtf8('Alert Message'))
self.AlertEntryLabel.setText(self.trUtf8('Alert Text:'))
self.DisplayButton.setText(self.trUtf8('Display'))
self.CancelButton.setText(self.trUtf8('Cancel'))
def loadList(self):
self.AlertListWidget.clear()
alerts = self.manager.get_all_alerts()
for alert in alerts:
item_name = QtGui.QListWidgetItem(alert.text)
self.AlertListWidget.addItem(item_name)
def onDisplayClicked(self):
self.parent.alertsmanager.displayAlert(unicode(self.AlertEntryEditItem.text()))
self.triggerAlert(unicode(self.AlertEntryEditItem.text()))
if self.parent.alertsTab.save_history and self.history_required:
alert = AlertItem()
alert.text = unicode(self.AlertEntryEditItem.text())
self.manager.save_alert(alert)
self.history_required = False
self.loadList()
def onTextChanged(self):
#Data has changed by editing it so potential storage
self.history_required = True
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())
self.history_required = False
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())
self.AlertEntryEditItem.setText(bitem.text())
self.history_required = False
def triggerAlert(self, text):
self.parent.alertsmanager.displayAlert(text)

View File

@ -25,7 +25,7 @@
from PyQt4 import QtCore, QtGui
from openlp.core.lib import SettingsTab
from openlp.core.lib import SettingsTab, str_to_bool
class AlertsTab(SettingsTab):
"""
@ -132,6 +132,38 @@ class AlertsTab(SettingsTab):
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.LocationLayout.addItem(self.LocationSpacer)
self.FontLayout.addWidget(self.LocationWidget)
self.HistoryWidget = QtGui.QWidget(self.FontGroupBox)
self.HistoryWidget.setObjectName(u'HistoryWidget')
self.HistoryLayout = QtGui.QHBoxLayout(self.HistoryWidget)
self.HistoryLayout.setSpacing(8)
self.HistoryLayout.setMargin(0)
self.HistoryLayout.setObjectName(u'HistoryLayout')
self.HistoryLabel = QtGui.QLabel(self.HistoryWidget)
self.HistoryLabel.setObjectName(u'HistoryLabel')
self.HistoryLayout.addWidget(self.HistoryLabel)
self.HistoryCheckBox = QtGui.QCheckBox(self.HistoryWidget)
self.HistoryCheckBox.setObjectName(u'HistoryCheckBox')
self.HistoryLayout.addWidget(self.HistoryCheckBox)
self.HistorySpacer = QtGui.QSpacerItem(147, 20,
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.HistoryLayout.addItem(self.HistorySpacer)
self.FontLayout.addWidget(self.HistoryWidget)
self.HistoryEditWidget = QtGui.QWidget(self.FontGroupBox)
self.HistoryEditWidget.setObjectName(u'HistoryEditWidget')
self.HistoryEditLayout = QtGui.QHBoxLayout(self.HistoryEditWidget)
self.HistoryEditLayout.setSpacing(8)
self.HistoryEditLayout.setMargin(0)
self.HistoryEditLayout.setObjectName(u'HistoryEditLayout')
self.HistoryEditLabel = QtGui.QLabel(self.HistoryEditWidget)
self.HistoryEditLabel.setObjectName(u'HistoryEditLabel')
self.HistoryEditLayout.addWidget(self.HistoryEditLabel)
self.HistoryEditPushButton = QtGui.QPushButton(self.HistoryEditWidget)
self.HistoryEditPushButton.setObjectName(u'HistoryEditPushButton')
self.HistoryEditLayout.addWidget(self.HistoryEditPushButton)
self.HistoryEditSpacer = QtGui.QSpacerItem(147, 20,
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.HistoryEditLayout.addItem(self.HistoryEditSpacer)
self.FontLayout.addWidget(self.HistoryEditWidget)
self.SlideLeftLayout.addWidget(self.FontGroupBox)
self.SlideLeftSpacer = QtGui.QSpacerItem(20, 94,
QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
@ -170,6 +202,9 @@ class AlertsTab(SettingsTab):
self.SlideRightLayout.addItem(self.SlideRightSpacer)
self.AlertsLayout.addWidget(self.AlertRightColumn)
# Signals and slots
QtCore.QObject.connect(self.HistoryCheckBox,
QtCore.SIGNAL(u'stateChanged(int)'),
self.onHistoryCheckBoxChanged)
QtCore.QObject.connect(self.BackgroundColorButton,
QtCore.SIGNAL(u'pressed()'), self.onBackgroundColorButtonClicked)
QtCore.QObject.connect(self.FontColorButton,
@ -193,6 +228,8 @@ class AlertsTab(SettingsTab):
self.TimeoutLabel.setText(self.trUtf8('Alert timeout:'))
self.TimeoutSpinBox.setSuffix(self.trUtf8('s'))
self.LocationLabel.setText(self.trUtf8('Location:'))
self.HistoryLabel.setText(self.trUtf8('Keep History:'))
self.HistoryEditLabel.setText(self.trUtf8('Edit History:'))
self.PreviewGroupBox.setTitle(self.trUtf8('Preview'))
self.FontPreview.setText(self.trUtf8('openlp.org'))
self.LocationComboBox.setItemText(0, self.trUtf8('Top'))
@ -211,6 +248,12 @@ class AlertsTab(SettingsTab):
def onLocationComboBoxClicked(self, location):
self.location = location
def onHistoryCheckBoxChanged(self, check_state):
self.save_history = False
# we have a set value convert to True/False
if check_state == QtCore.Qt.Checked:
self.save_history = True
def onFontColorButtonClicked(self):
self.font_color = QtGui.QColorDialog.getColor(
QtGui.QColor(self.font_color), self).name()
@ -235,6 +278,8 @@ class AlertsTab(SettingsTab):
self.font_face = unicode(
self.config.get_config(u'font face', QtGui.QFont().family()))
self.location = int(self.config.get_config(u'location', 0))
self.save_history = str_to_bool(
self.config.get_config(u'save history', u'False'))
self.FontSizeSpinBox.setValue(self.font_size)
self.TimeoutSpinBox.setValue(self.timeout)
self.FontColorButton.setStyleSheet(
@ -242,6 +287,7 @@ class AlertsTab(SettingsTab):
self.BackgroundColorButton.setStyleSheet(
u'background-color: %s' % self.bg_color)
self.LocationComboBox.setCurrentIndex(self.location)
self.HistoryCheckBox.setChecked(self.save_history)
font = QtGui.QFont()
font.setFamily(self.font_face)
self.FontComboBox.setCurrentFont(font)
@ -254,7 +300,9 @@ class AlertsTab(SettingsTab):
self.config.set_config(u'font size', unicode(self.font_size))
self.config.set_config(u'font face', unicode(self.font_face))
self.config.set_config(u'timeout', unicode(self.timeout))
self.config.set_config(u'location', unicode(self.LocationComboBox.currentIndex()))
self.config.set_config(u'location',
unicode(self.LocationComboBox.currentIndex()))
self.config.set_config(u'save history', unicode(self.save_history))
def updateDisplay(self):
font = QtGui.QFont()

View File

@ -23,3 +23,4 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
from alertsmanager import AlertsManager
from manager import DBManager

View File

@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
# Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
class BaseModel(object):
"""
BaseModel provides a base object with a set of generic functions
"""
@classmethod
def populate(cls, **kwargs):
"""
Creates an instance of a class and populates it, returning the instance
"""
me = cls()
keys = kwargs.keys()
for key in keys:
me.__setattr__(key, kwargs[key])
return me
class AlertItem(BaseModel):
"""
Custom Slide model
"""
pass

View File

@ -0,0 +1,108 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
# Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
import logging
from openlp.plugins.alerts.lib.models import init_models, metadata, AlertItem
class DBManager():
"""
The Song Manager provides a central location for all database code. This
class takes care of connecting to the database and running all the queries.
"""
global log
log = logging.getLogger(u'AlertsDBManager')
log.info(u'Alerts DB loaded')
def __init__(self, config):
"""
Creates the connection to the database, and creates the tables if they
don't exist.
"""
self.config = config
log.debug(u'Alerts Initialising')
self.db_url = u''
db_type = self.config.get_config(u'db type', u'sqlite')
if db_type == u'sqlite':
self.db_url = u'sqlite:///%s/alerts.sqlite' % \
self.config.get_data_path()
else:
self.db_url = u'%s://%s:%s@%s/%s' % \
(db_type, self.config.get_config(u'db username'),
self.config.get_config(u'db password'),
self.config.get_config(u'db hostname'),
self.config.get_config(u'db database'))
self.session = init_models(self.db_url)
metadata.create_all(checkfirst=True)
log.debug(u'Alerts Initialised')
def get_all_alerts(self):
"""
Returns the details of a Alert Show
"""
return self.session.query(AlertItem).order_by(AlertItem.text).all()
def save_alert(self, AlertItem):
"""
Saves a Alert show to the database
"""
log.debug(u'Alert added')
try:
self.session.add(AlertItem)
self.session.commit()
log.debug(u'Alert saved')
return True
except:
self.session.rollback()
log.excertion(u'Alert save failed')
return False
def get_alerts(self, id=None):
"""
Returns the details of a Alert
"""
if id is None:
return AlertItem()
else:
return self.session.query(AlertItem).get(id)
def delete_alert(self, id):
"""
Delete a Alert show
"""
if id !=0:
Alerts = self.get_Alert(id)
try:
self.session.delete(AlertItem)
self.session.commit()
return True
except:
self.session.rollback()
log.excertion(u'Alert deleton failed')
return False
else:
return True

View File

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
# Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# 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 sqlalchemy import MetaData
__all__ = ['session', 'metadata', 'engine']
# SQLAlchemy database engine. Updated by model.init_model()
engine = None
# SQLAlchemy session manager. Updated by model.init_model()
session = None
# Global metadata. If you have multiple databases with overlapping table
# names, you'll need a metadata for each database
metadata = MetaData()

View File

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
# Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# 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 sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker, mapper
from openlp.plugins.alerts.lib.meta import metadata
from openlp.plugins.alerts.lib.tables import *
from openlp.plugins.alerts.lib.classes import *
def init_models(url):
engine = create_engine(url)
metadata.bind = engine
session = scoped_session(sessionmaker(autoflush=True, autocommit=False,
bind=engine))
mapper(AlertItem, alerts_table)
return session

View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
# Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# 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 sqlalchemy import Column, Table, types
from openlp.plugins.alerts.lib.meta import metadata
# Definition of the "alerts" table
alerts_table = Table(u'alerts', metadata,
Column(u'id', types.Integer(), primary_key=True),
Column(u'text', types.UnicodeText, nullable=False))

View File

@ -27,8 +27,7 @@ import logging
from PyQt4 import QtCore, QtGui
from openlp.core.lib import str_to_bool, Receiver
from openlp.core.lib import SettingsTab
from openlp.core.lib import str_to_bool, Receiver, SettingsTab
class BiblesTab(SettingsTab):
"""
@ -226,4 +225,4 @@ class BiblesTab(SettingsTab):
# Not Found
id = 0
self.bible_theme = u''
self.BibleThemeComboBox.setCurrentIndex(id)
self.BibleThemeComboBox.setCurrentIndex(id)

View File

@ -27,11 +27,11 @@ from sqlalchemy import Column, Table, types
from openlp.plugins.custom.lib.meta import metadata
# Definition of the "songs" table
# Definition of the "custom slide" table
custom_slide_table = Table(u'custom_slide', metadata,
Column(u'id', types.Integer(), primary_key=True),
Column(u'title', types.Unicode(255), nullable=False),
Column(u'text', types.UnicodeText, nullable=False),
Column(u'credits', types.UnicodeText),
Column(u'theme_name', types.Unicode(128))
)
)

View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AlertForm</class>
<widget class="QWidget" name="AlertForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>430</width>
<height>320</height>
</rect>
</property>
<property name="windowTitle">
<string>Alert Message</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>:/icon/openlp.org-icon-32.bmp</normaloff>:/icon/openlp.org-icon-32.bmp</iconset>
</property>
<layout class="QVBoxLayout" name="AlertFormLayout">
<property name="spacing">
<number>8</number>
</property>
<property name="margin">
<number>8</number>
</property>
<item>
<widget class="QWidget" name="AlertEntryWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="AlertEntryLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Alert Text:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="AlertEntryEditItem"/>
</item>
<item>
<widget class="QListWidget" name="AlertListWidget"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="ButtonBoxWidgetSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>181</width>
<height>38</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="DisplayButton">
<property name="text">
<string>Display</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="CancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../images/openlp-2.qrc"/>
</resources>
<connections>
<connection>
<sender>CancelButton</sender>
<signal>clicked()</signal>
<receiver>AlertForm</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>294</x>
<y>66</y>
</hint>
<hint type="destinationlabel">
<x>257</x>
<y>3</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AlertList</class>
<widget class="QWidget" name="AlertList">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>220</x>
<y>270</y>
<width>173</width>
<height>27</height>
</rect>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel</set>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>361</width>
<height>251</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QPushButton" name="SaveButton">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="listWidget">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="AddButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="EdirButton">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="DeleteButton">
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,133 +0,0 @@
<ui version="4.0" >
<class>AlertForm</class>
<widget class="QWidget" name="AlertForm" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>370</width>
<height>105</height>
</rect>
</property>
<property name="windowTitle" >
<string>Alert Message</string>
</property>
<property name="windowIcon" >
<iconset resource="../images/openlp-2.qrc" >
<normaloff>:/icon/openlp.org-icon-32.bmp</normaloff>:/icon/openlp.org-icon-32.bmp</iconset>
</property>
<layout class="QVBoxLayout" name="AlertFormLayout" >
<property name="spacing" >
<number>8</number>
</property>
<property name="margin" >
<number>8</number>
</property>
<item>
<widget class="QWidget" native="1" name="AlertEntryWidget" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QLabel" name="AlertEntryLabel" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>353</width>
<height>16</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>Alert Text:</string>
</property>
</widget>
<widget class="QLineEdit" name="AlertEntryEditItem" >
<property name="geometry" >
<rect>
<x>0</x>
<y>20</y>
<width>353</width>
<height>21</height>
</rect>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QWidget" native="1" name="ButtonBoxWidget" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" >
<property name="spacing" >
<number>8</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<spacer name="ButtonBoxWidgetSpacer" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>267</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="DisplayButton" >
<property name="text" >
<string>Display</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="CancelButton" >
<property name="text" >
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../images/openlp-2.qrc" />
</resources>
<connections>
<connection>
<sender>CancelButton</sender>
<signal>clicked()</signal>
<receiver>AlertForm</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel" >
<x>294</x>
<y>66</y>
</hint>
<hint type="destinationlabel" >
<x>257</x>
<y>3</y>
</hint>
</hints>
</connection>
</connections>
</ui>