diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 2c0d89e8e..bcbc46f91 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -405,11 +405,11 @@ class Ui_MainWindow(object): self.action_Preview_Panel.setStatusTip(translate(u'mainWindow', u'Toggle the visibility of the Preview Panel')) self.action_Preview_Panel.setShortcut(translate(u'mainWindow', u'F11')) - self.ToolsAlertItem.setText(translate(u'mainWindow', u'&Alert')) + self.ToolsAlertItem.setText(translate(u'mainWindow', u'Trigger &Alert')) self.ToolsAlertItem.setStatusTip( translate(u'mainWindow', u'Show an alert message')) self.ToolsAlertItem.setShortcut(translate(u'mainWindow', u'F7')) - self.PluginItem.setText(translate(u'mainWindow', u'&Plugin')) + self.PluginItem.setText(translate(u'mainWindow', u'List &Plugins')) self.PluginItem.setStatusTip( translate(u'mainWindow', u'List the Plugins')) self.PluginItem.setShortcut(translate(u'mainWindow', u'Alt+F7')) @@ -510,16 +510,16 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): QtCore.SIGNAL(u'triggered()'), self.onOptionsSettingsItemClicked) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'update_global_theme'), self.defaultThemeChanged) - QtCore.QObject.connect(self.FileNewItem, + QtCore.QObject.connect(self.FileNewItem, QtCore.SIGNAL(u'triggered()'), self.ServiceManagerContents.onNewService) - QtCore.QObject.connect(self.FileOpenItem, + QtCore.QObject.connect(self.FileOpenItem, QtCore.SIGNAL(u'triggered()'), self.ServiceManagerContents.onLoadService) - QtCore.QObject.connect(self.FileSaveItem, + QtCore.QObject.connect(self.FileSaveItem, QtCore.SIGNAL(u'triggered()'), self.ServiceManagerContents.onQuickSaveService) - QtCore.QObject.connect(self.FileSaveAsItem, + QtCore.QObject.connect(self.FileSaveAsItem, QtCore.SIGNAL(u'triggered()'), self.ServiceManagerContents.onSaveService) #warning cyclic dependency diff --git a/openlp/plugins/audit/auditplugin.py b/openlp/plugins/audit/auditplugin.py index 187b20760..e5e60e95e 100644 --- a/openlp/plugins/audit/auditplugin.py +++ b/openlp/plugins/audit/auditplugin.py @@ -100,7 +100,7 @@ class AuditPlugin(Plugin): self.auditActive = str_to_bool( self.config.get_config(u'audit active', False)) self.ToolsAuditItem.setChecked(self.auditActive) - self.auditmanager = AuditManager() + self.auditmanager = AuditManager(self.config) def toggleAuditState(self): self.auditActive = not self.auditActive @@ -135,7 +135,3 @@ class AuditPlugin(Plugin): self.auditFile.close() self.auditFile = open(self.auditFileNameNew, u'a') - def finalise(self): - log.debug(u'Finalise') - if self.auditFile is not None: - self.auditFile.close() diff --git a/openlp/plugins/audit/lib/__init__.py b/openlp/plugins/audit/lib/__init__.py index b7501b377..784a92abb 100644 --- a/openlp/plugins/audit/lib/__init__.py +++ b/openlp/plugins/audit/lib/__init__.py @@ -21,6 +21,9 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### - -from audittab import AuditTab -from manager import AuditManager +import sys +try: + from audittab import AuditTab + from manager import AuditManager +except: + print sys.exc_info() diff --git a/openlp/plugins/audit/lib/audittab.py b/openlp/plugins/audit/lib/audittab.py index 582a737a5..afdc04c64 100644 --- a/openlp/plugins/audit/lib/audittab.py +++ b/openlp/plugins/audit/lib/audittab.py @@ -39,7 +39,6 @@ class AuditTab(SettingsTab): self.AuditModeGroupBox.setObjectName(u'AuditModeGroupBox') self.verticalLayout = QtGui.QVBoxLayout(self.AuditModeGroupBox) self.verticalLayout.setObjectName("verticalLayout") - self.verticalLayout.addLayout(self.horizontalLayout) self.AuditActive = QtGui.QCheckBox(self) self.AuditActive.setObjectName("AuditActive") self.verticalLayout.addWidget(self.AuditActive) @@ -54,12 +53,9 @@ class AuditTab(SettingsTab): u'A restart is needed for this change to become effective')) def load(self): - self.AuditFileName.setText(self.config.get_config(u'Audit file', u'')) self.AuditActive.setChecked(int(self.config.get_config(u'startup', 0))) def save(self): - self.config.set_config( - u'Audit file', unicode(self.AuditFileName.text())) self.config.set_config( u'startup', unicode(self.AuditActive.checkState())) Receiver().send_message(u'audit_changed') diff --git a/openlp/plugins/audit/lib/classes.py b/openlp/plugins/audit/lib/classes.py new file mode 100644 index 000000000..6883bca14 --- /dev/null +++ b/openlp/plugins/audit/lib/classes.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2009 Raoul Snyman # +# Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, Carsten # +# Tinggaard, Jon Tibble, Jonathan Corwin, Maikel Stuivenberg, Scott Guerrieri # +# --------------------------------------------------------------------------- # +# 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 AuditItem(BaseModel): + """ + Audit model + """ + pass diff --git a/openlp/plugins/audit/lib/manager.py b/openlp/plugins/audit/lib/manager.py index 63be37c5a..07694bb5a 100644 --- a/openlp/plugins/audit/lib/manager.py +++ b/openlp/plugins/audit/lib/manager.py @@ -27,7 +27,7 @@ import sys from sqlalchemy import asc, desc from openlp.plugins.audit.lib.models import init_models, metadata, session, \ - engine, audit_table, Audit + engine, AuditItem, audit_table import logging @@ -38,7 +38,7 @@ class AuditManager(): """ global log - log = logging.getLogger(u'AuditManager') + log=logging.getLogger(u'AuditManager') log.info(u'Audit manager loaded') def __init__(self, config): @@ -51,54 +51,61 @@ class AuditManager(): 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/Audit.sqlite' % \ + self.db_url = u'sqlite:///%s/audit.sqlite' % \ self.config.get_data_path() else: - self.db_url = db_type + 'u://' + \ - self.config.get_config(u'db username') + u':' + \ - self.config.get_config(u'db password') + u'@' + \ - self.config.get_config(u'db hostname') + u'/' + \ - self.config.get_config(u'db database') + 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'AuditInitialised') - def get_audits(self): - """ - Returns a list of all the audits - """ - return self.session.query(audit).order_by(audit.whensung).all() + log.debug(u'Audit Initialised') - def get_audit(self, id): + def get_all_audits(self): """ - Details of the audit + Returns the details of a audit """ - return self.session.query(audit).get(id) + return self.session.query(AuditItem).order_by(AuditItem.title).all() - def save_audit(self, audit): + def insert_audit(self, audititem): """ - Save the audit and refresh the cache + Saves an audit to the database """ + log.debug(u'Audit added') try: - self.session.add(audit) + self.session.add(audititem) self.session.commit() return True except: self.session.rollback() - log.exception(u'Could not save audit to song database') + log.excertion(u'Audit item failed to save') return False - def delete_audit(self, auditid): + def get_audit(self, id=None): """ - Delete the audit + Returns the details of an audit """ - audit = self.get_audit(auditid) - try: - self.session.delete(audit) - self.session.commit() + if id is None: + return AuditItem() + else: + return self.session.query(AuditItem).get(id) + + def delete_audit(self, id): + """ + Delete a audit record + """ + if id !=0: + audititem = self.get_audit(id) + try: + self.session.delete(audititem) + self.session.commit() + return True + except: + self.session.rollback() + log.excertion(u'Audit Item failed to delete') + return False + else: return True - except: - self.session.rollback() - log.exception(u'Could not delete audit from song database') - return False - diff --git a/openlp/plugins/audit/lib/models.py b/openlp/plugins/audit/lib/models.py index 70f228fe9..f51ee8b25 100644 --- a/openlp/plugins/audit/lib/models.py +++ b/openlp/plugins/audit/lib/models.py @@ -27,11 +27,12 @@ from sqlalchemy.orm import scoped_session, sessionmaker, mapper, relation from openlp.plugins.audit.lib.meta import session, metadata, engine from openlp.plugins.audit.lib.tables import * +from openlp.plugins.audit.lib.classes import * def init_models(url): engine = create_engine(url) metadata.bind = engine - session = scoped_session(sessionmaker(autoflush=False, - autocommit=False, bind=engine)) - mapper(Audit, audit_table) + session = scoped_session(sessionmaker(autoflush=True, autocommit=False, + bind=engine)) + mapper(AuditItem, audit_table) return session diff --git a/openlp/plugins/audit/lib/tables.py b/openlp/plugins/audit/lib/tables.py index 550bd9a55..e64aa350e 100644 --- a/openlp/plugins/audit/lib/tables.py +++ b/openlp/plugins/audit/lib/tables.py @@ -22,19 +22,15 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -from datetime import now - -from sqlalchemy import * from sqlalchemy import Column, Table, ForeignKey, types from openlp.plugins.audit.lib.meta import metadata -# Definition of the "audits" table -audit_table = Table(u'audits', metadata, - Column(u'id', types.Integer, primary_key=True), - Column('whensung', types.DateTime, nullable=False, default=datetime.now()), - Column(u'authors', types.Unicode(255)), - Column(u'ccli_number', types.Unicode(64)), +# Definition of the "songs" table +audit_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)) ) - -Index(u'audits_id',audit_table.c.timestamp, audit_table.c.id) diff --git a/openlp/plugins/custom/lib/classes.py b/openlp/plugins/custom/lib/classes.py index 545c5019e..6cd8c158e 100644 --- a/openlp/plugins/custom/lib/classes.py +++ b/openlp/plugins/custom/lib/classes.py @@ -40,6 +40,6 @@ class BaseModel(object): class CustomSlide(BaseModel): """ - Author model + Custom Slide model """ pass diff --git a/openlp/plugins/custom/lib/manager.py b/openlp/plugins/custom/lib/manager.py index 17f75dbc6..4f5406102 100644 --- a/openlp/plugins/custom/lib/manager.py +++ b/openlp/plugins/custom/lib/manager.py @@ -51,8 +51,8 @@ class CustomManager(): 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:///' + self.config.get_data_path() + \ - u'/custom.sqlite' + self.db_url = u'sqlite:///%s/custom.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'), @@ -60,23 +60,19 @@ class CustomManager(): self.config.get_config(u'db hostname'), self.config.get_config(u'db database')) self.session = init_models(self.db_url) - if not custom_slide_table.exists(): - metadata.create_all() + metadata.create_all(checkfirst=True) log.debug(u'Custom Initialised') -# -# def process_dialog(self, dialogobject): -# self.dialogobject = dialogobject -# + def get_all_slides(self): """ - Returns the details of a song + Returns the details of a Custom Slide Show """ return self.session.query(CustomSlide).order_by(CustomSlide.title).all() def save_slide(self, customslide): """ - Saves a song to the database + Saves a Custom slide show to the database """ log.debug(u'Custom Slide added') try: @@ -85,7 +81,8 @@ class CustomManager(): log.debug(u'Custom Slide saved') return True except: - log.debug(u'Custom Slide failed') + self.session.rollback() + log.excertion(u'Custom Slide save failed') return False def get_custom(self, id=None): @@ -98,6 +95,9 @@ class CustomManager(): return self.session.query(CustomSlide).get(id) def delete_custom(self, id): + """ + Delete a Custom slide show + """ if id !=0: customslide = self.get_custom(id) try: @@ -105,6 +105,8 @@ class CustomManager(): self.session.commit() return True except: + self.session.rollback() + log.excertion(u'Custom Slide deleton failed') return False else: return True