openlp/openlp/plugins/songusage/songusageplugin.py

164 lines
7.6 KiB
Python
Raw Normal View History

2009-10-27 08:38:02 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2009-12-31 12:52:01 +00:00
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
2010-07-24 22:10:47 +00:00
# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian #
# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
# Carsten Tinggaard, Frode Woldsund #
2009-10-27 08:38:02 +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 #
###############################################################################
import logging
2010-06-15 02:08:22 +00:00
from datetime import datetime
2010-07-18 23:37:24 +00:00
2009-10-27 08:38:02 +00:00
from PyQt4 import QtCore, QtGui
from openlp.core.lib import Plugin, Receiver, build_icon, translate
2010-07-18 23:37:24 +00:00
from openlp.core.lib.db import Manager
2010-04-27 16:27:57 +00:00
from openlp.plugins.songusage.forms import SongUsageDetailForm, \
SongUsageDeleteForm
2010-07-18 23:37:24 +00:00
from openlp.plugins.songusage.lib.db import init_schema, SongUsageItem
2009-10-27 08:38:02 +00:00
2010-02-27 15:31:23 +00:00
log = logging.getLogger(__name__)
2009-10-27 08:38:02 +00:00
class SongUsagePlugin(Plugin):
log.info(u'SongUsage Plugin loaded')
def __init__(self, plugin_helpers):
2010-06-23 17:37:01 +00:00
Plugin.__init__(self, u'SongUsage', u'1.9.2', plugin_helpers)
2009-10-27 08:38:02 +00:00
self.weight = -4
self.icon = build_icon(u':/plugins/plugin_songusage.png')
2009-10-27 08:38:02 +00:00
self.songusagemanager = None
self.songusageActive = False
2010-07-05 16:00:48 +00:00
def addToolsMenuItem(self, tools_menu):
2009-10-27 08:38:02 +00:00
"""
Give the SongUsage plugin the opportunity to add items to the
**Tools** menu.
``tools_menu``
The actual **Tools** menu item, so that your actions can
use it as their parent.
"""
log.info(u'add tools menu')
self.toolsMenu = tools_menu
self.SongUsageMenu = QtGui.QMenu(tools_menu)
self.SongUsageMenu.setObjectName(u'SongUsageMenu')
self.SongUsageMenu.setTitle(translate(
2010-07-23 18:03:19 +00:00
'SongUsagePlugin', '&Song Usage Tracking'))
2009-10-30 17:44:16 +00:00
#SongUsage Delete
2009-10-27 08:38:02 +00:00
self.SongUsageDelete = QtGui.QAction(tools_menu)
2010-06-21 21:04:56 +00:00
self.SongUsageDelete.setText(translate('SongUsagePlugin',
2010-07-23 18:03:19 +00:00
'&Delete Tracking Data'))
2010-06-21 21:04:56 +00:00
self.SongUsageDelete.setStatusTip(translate('SongUsagePlugin',
2010-07-23 18:03:19 +00:00
'Delete song usage data up to a specified date.'))
2009-10-27 08:38:02 +00:00
self.SongUsageDelete.setObjectName(u'SongUsageDelete')
#SongUsage Report
self.SongUsageReport = QtGui.QAction(tools_menu)
2009-10-30 17:44:16 +00:00
self.SongUsageReport.setText(
2010-07-23 18:03:19 +00:00
translate('SongUsagePlugin', '&Extract Tracking Data'))
2009-10-27 08:38:02 +00:00
self.SongUsageReport.setStatusTip(
2010-07-23 18:03:19 +00:00
translate('SongUsagePlugin', 'Generate a report on song usage.'))
2009-10-27 08:38:02 +00:00
self.SongUsageReport.setObjectName(u'SongUsageReport')
#SongUsage activation
SongUsageIcon = build_icon(u':/plugins/plugin_songusage.png')
2009-10-27 08:38:02 +00:00
self.SongUsageStatus = QtGui.QAction(tools_menu)
self.SongUsageStatus.setCheckable(True)
self.SongUsageStatus.setChecked(False)
self.SongUsageStatus.setText(translate(
2010-07-23 18:03:19 +00:00
'SongUsagePlugin', 'Toggle Tracking'))
2010-06-21 21:04:56 +00:00
self.SongUsageStatus.setStatusTip(translate('SongUsagePlugin',
2010-07-23 18:03:19 +00:00
'Toggle the tracking of song usage.'))
2009-10-27 08:38:02 +00:00
self.SongUsageStatus.setShortcut(u'F4')
self.SongUsageStatus.setObjectName(u'SongUsageStatus')
#Add Menus together
self.toolsMenu.addAction(self.SongUsageMenu.menuAction())
self.SongUsageMenu.addAction(self.SongUsageStatus)
self.SongUsageMenu.addSeparator()
self.SongUsageMenu.addAction(self.SongUsageDelete)
self.SongUsageMenu.addAction(self.SongUsageReport)
# Signals and slots
QtCore.QObject.connect(self.SongUsageStatus,
QtCore.SIGNAL(u'visibilityChanged(bool)'),
self.SongUsageStatus.setChecked)
QtCore.QObject.connect(self.SongUsageStatus,
QtCore.SIGNAL(u'triggered(bool)'),
self.toggleSongUsageState)
QtCore.QObject.connect(self.SongUsageDelete,
QtCore.SIGNAL(u'triggered()'), self.onSongUsageDelete)
QtCore.QObject.connect(self.SongUsageReport,
QtCore.SIGNAL(u'triggered()'), self.onSongUsageReport)
self.SongUsageMenu.menuAction().setVisible(False)
def initialise(self):
log.info(u'SongUsage Initialising')
Plugin.initialise(self)
QtCore.QObject.connect(Receiver.get_receiver(),
2010-04-29 22:52:23 +00:00
QtCore.SIGNAL(u'songs_live_started'),
2010-04-27 16:27:57 +00:00
self.onReceiveSongUsage)
self.SongUsageActive = QtCore.QSettings().value(
self.settingsSection + u'/active',
2010-04-28 14:17:42 +00:00
QtCore.QVariant(False)).toBool()
2009-10-27 08:38:02 +00:00
self.SongUsageStatus.setChecked(self.SongUsageActive)
if self.songusagemanager is None:
2010-07-18 23:37:24 +00:00
self.songusagemanager = Manager(u'songusage', init_schema)
2009-10-27 08:38:02 +00:00
self.SongUsagedeleteform = SongUsageDeleteForm(self.songusagemanager)
self.SongUsagedetailform = SongUsageDetailForm(self)
self.SongUsageMenu.menuAction().setVisible(True)
def finalise(self):
log.info(u'Plugin Finalise')
self.SongUsageMenu.menuAction().setVisible(False)
#stop any events being processed
self.SongUsageActive = False
def toggleSongUsageState(self):
self.SongUsageActive = not self.SongUsageActive
QtCore.QSettings().setValue(self.settingsSection + u'/active',
2010-04-28 14:17:42 +00:00
QtCore.QVariant(self.SongUsageActive))
2009-10-27 08:38:02 +00:00
2010-04-16 07:31:01 +00:00
def onReceiveSongUsage(self, items):
2009-10-27 08:38:02 +00:00
"""
SongUsage a live song from SlideController
"""
2010-04-16 07:31:01 +00:00
audit = items[0].audit
2010-04-22 21:22:09 +00:00
if self.SongUsageActive and audit:
2010-04-16 07:31:01 +00:00
song_usage_item = SongUsageItem()
song_usage_item.usagedate = datetime.today()
song_usage_item.usagetime = datetime.now().time()
song_usage_item.title = audit[0]
song_usage_item.copyright = audit[2]
song_usage_item.ccl_number = audit[3]
song_usage_item.authors = u''
for author in audit[1]:
song_usage_item.authors += author + u' '
2010-06-28 13:38:29 +00:00
self.songusagemanager.save_object(song_usage_item)
2009-10-27 08:38:02 +00:00
def onSongUsageDelete(self):
self.SongUsagedeleteform.exec_()
def onSongUsageReport(self):
self.SongUsagedetailform.initialise()
self.SongUsagedetailform.exec_()
def about(self):
2010-07-23 18:03:19 +00:00
about_text = translate('SongUsagePlugin', '<strong>SongUsage Plugin'
'</strong><br />This plugin tracks the usage of songs in '
'services.')
2010-07-24 22:10:47 +00:00
return about_text