diff --git a/openlp/plugins/alerts/alertsplugin.py b/openlp/plugins/alerts/alertsplugin.py index 1163f70ee..7214618d7 100644 --- a/openlp/plugins/alerts/alertsplugin.py +++ b/openlp/plugins/alerts/alertsplugin.py @@ -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): diff --git a/openlp/plugins/alerts/forms/alertdialog.py b/openlp/plugins/alerts/forms/alertdialog.py new file mode 100644 index 000000000..4756a318f --- /dev/null +++ b/openlp/plugins/alerts/forms/alertdialog.py @@ -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)) diff --git a/openlp/plugins/alerts/forms/alerteditdialog.py b/openlp/plugins/alerts/forms/alerteditdialog.py new file mode 100644 index 000000000..53985d82b --- /dev/null +++ b/openlp/plugins/alerts/forms/alerteditdialog.py @@ -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)) + diff --git a/openlp/plugins/alerts/forms/alertform.py b/openlp/plugins/alerts/forms/alertform.py index 68549eaee..882da7cfa 100644 --- a/openlp/plugins/alerts/forms/alertform.py +++ b/openlp/plugins/alerts/forms/alertform.py @@ -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) diff --git a/openlp/plugins/alerts/forms/alertstab.py b/openlp/plugins/alerts/forms/alertstab.py index a6653d152..7c50ccc19 100644 --- a/openlp/plugins/alerts/forms/alertstab.py +++ b/openlp/plugins/alerts/forms/alertstab.py @@ -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() diff --git a/openlp/plugins/alerts/lib/__init__.py b/openlp/plugins/alerts/lib/__init__.py index f6fb2c0d7..c39574719 100644 --- a/openlp/plugins/alerts/lib/__init__.py +++ b/openlp/plugins/alerts/lib/__init__.py @@ -23,3 +23,4 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### from alertsmanager import AlertsManager +from manager import DBManager diff --git a/openlp/plugins/alerts/lib/classes.py b/openlp/plugins/alerts/lib/classes.py new file mode 100644 index 000000000..eec21300c --- /dev/null +++ b/openlp/plugins/alerts/lib/classes.py @@ -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 diff --git a/openlp/plugins/alerts/lib/manager.py b/openlp/plugins/alerts/lib/manager.py new file mode 100644 index 000000000..79ed928e1 --- /dev/null +++ b/openlp/plugins/alerts/lib/manager.py @@ -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 diff --git a/openlp/plugins/alerts/lib/meta.py b/openlp/plugins/alerts/lib/meta.py new file mode 100644 index 000000000..38b0f7206 --- /dev/null +++ b/openlp/plugins/alerts/lib/meta.py @@ -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() \ No newline at end of file diff --git a/openlp/plugins/alerts/lib/models.py b/openlp/plugins/alerts/lib/models.py new file mode 100644 index 000000000..4f556cd23 --- /dev/null +++ b/openlp/plugins/alerts/lib/models.py @@ -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 diff --git a/openlp/plugins/alerts/lib/tables.py b/openlp/plugins/alerts/lib/tables.py new file mode 100644 index 000000000..0a731fb13 --- /dev/null +++ b/openlp/plugins/alerts/lib/tables.py @@ -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)) diff --git a/openlp/plugins/bibles/lib/biblestab.py b/openlp/plugins/bibles/lib/biblestab.py index 9c7e6b280..ef8e6a090 100644 --- a/openlp/plugins/bibles/lib/biblestab.py +++ b/openlp/plugins/bibles/lib/biblestab.py @@ -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) \ No newline at end of file + self.BibleThemeComboBox.setCurrentIndex(id) diff --git a/openlp/plugins/custom/lib/tables.py b/openlp/plugins/custom/lib/tables.py index 061c6d5c3..13c9de5b9 100644 --- a/openlp/plugins/custom/lib/tables.py +++ b/openlp/plugins/custom/lib/tables.py @@ -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)) -) \ No newline at end of file +) diff --git a/resources/forms/alertdialog.ui b/resources/forms/alertdialog.ui new file mode 100644 index 000000000..c3bfdaf8e --- /dev/null +++ b/resources/forms/alertdialog.ui @@ -0,0 +1,116 @@ + + + AlertForm + + + + 0 + 0 + 430 + 320 + + + + Alert Message + + + + :/icon/openlp.org-icon-32.bmp:/icon/openlp.org-icon-32.bmp + + + + 8 + + + 8 + + + + + + 0 + 0 + + + + + + + + + + 0 + 0 + + + + Alert Text: + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 181 + 38 + + + + + + + + Display + + + + + + + Cancel + + + + + + + + + + + + + + + + CancelButton + clicked() + AlertForm + close() + + + 294 + 66 + + + 257 + 3 + + + + + diff --git a/resources/forms/alerteditdialog.ui b/resources/forms/alerteditdialog.ui new file mode 100644 index 000000000..a4b63ccb7 --- /dev/null +++ b/resources/forms/alerteditdialog.ui @@ -0,0 +1,94 @@ + + + AlertList + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 220 + 270 + 173 + 27 + + + + QDialogButtonBox::Cancel + + + + + + 20 + 10 + 361 + 251 + + + + + + + + + + + + Save + + + + + + + + + + + true + + + + + + + + + Add + + + + + + + Edit + + + + + + + Delete + + + + + + + + + + + + + diff --git a/resources/forms/alertform.ui b/resources/forms/alertform.ui deleted file mode 100644 index 1caf4a356..000000000 --- a/resources/forms/alertform.ui +++ /dev/null @@ -1,133 +0,0 @@ - - AlertForm - - - - 0 - 0 - 370 - 105 - - - - Alert Message - - - - :/icon/openlp.org-icon-32.bmp:/icon/openlp.org-icon-32.bmp - - - - 8 - - - 8 - - - - - - 0 - 0 - - - - - - 0 - 0 - 353 - 16 - - - - - 0 - 0 - - - - Alert Text: - - - - - - 0 - 20 - 353 - 21 - - - - - - - - - - 0 - 0 - - - - - 8 - - - 0 - - - - - Qt::Horizontal - - - - 267 - 20 - - - - - - - - Display - - - - - - - Cancel - - - - - - - - - - - - - - CancelButton - clicked() - AlertForm - close() - - - 294 - 66 - - - 257 - 3 - - - - -