2009-02-21 19:23:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
2009-09-08 19:58:05 +00:00
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2009-12-31 12:52:01 +00:00
|
|
|
# Copyright (c) 2008-2010 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
|
2010-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-09-08 19:58:05 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
2009-02-21 19:23:54 +00:00
|
|
|
|
|
|
|
import os
|
2009-05-09 07:01:33 +00:00
|
|
|
import logging
|
2009-06-08 20:36:33 +00:00
|
|
|
import cPickle
|
2009-06-20 11:23:34 +00:00
|
|
|
import zipfile
|
2009-02-21 19:23:54 +00:00
|
|
|
|
2010-02-27 15:31:23 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2009-05-09 07:01:33 +00:00
|
|
|
from PyQt4 import QtCore, QtGui
|
2010-03-03 17:48:37 +00:00
|
|
|
|
2010-06-12 20:22:58 +00:00
|
|
|
from openlp.core.lib import OpenLPToolbar, ServiceItem, context_menu_action, \
|
2010-07-08 08:14:10 +00:00
|
|
|
Receiver, build_icon, ItemCapabilities, SettingsManager, translate, \
|
|
|
|
ThemeLevel
|
2010-03-28 15:56:49 +00:00
|
|
|
from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm
|
2010-04-27 16:27:57 +00:00
|
|
|
from openlp.core.utils import AppLocation
|
2009-02-21 19:23:54 +00:00
|
|
|
|
2009-06-29 17:37:46 +00:00
|
|
|
class ServiceManagerList(QtGui.QTreeWidget):
|
2010-06-10 01:57:59 +00:00
|
|
|
"""
|
|
|
|
Set up key bindings and mouse behaviour for the service list
|
|
|
|
"""
|
2009-11-07 00:00:36 +00:00
|
|
|
def __init__(self, parent=None, name=None):
|
2010-04-28 14:17:42 +00:00
|
|
|
QtGui.QTreeWidget.__init__(self, parent)
|
2009-06-29 17:37:46 +00:00
|
|
|
self.parent = parent
|
2009-10-29 09:18:26 +00:00
|
|
|
|
2009-06-29 17:37:46 +00:00
|
|
|
def keyPressEvent(self, event):
|
2010-06-09 17:09:32 +00:00
|
|
|
if isinstance(event, QtGui.QKeyEvent):
|
2009-06-29 17:37:46 +00:00
|
|
|
#here accept the event and do something
|
|
|
|
if event.key() == QtCore.Qt.Key_Enter:
|
|
|
|
self.parent.makeLive()
|
|
|
|
event.accept()
|
2009-07-21 18:10:14 +00:00
|
|
|
elif event.key() == QtCore.Qt.Key_Home:
|
|
|
|
self.parent.onServiceTop()
|
|
|
|
event.accept()
|
|
|
|
elif event.key() == QtCore.Qt.Key_End:
|
|
|
|
self.parent.onServiceEnd()
|
|
|
|
event.accept()
|
|
|
|
elif event.key() == QtCore.Qt.Key_PageUp:
|
|
|
|
self.parent.onServiceUp()
|
|
|
|
event.accept()
|
|
|
|
elif event.key() == QtCore.Qt.Key_PageDown:
|
|
|
|
self.parent.onServiceDown()
|
|
|
|
event.accept()
|
|
|
|
elif event.key() == QtCore.Qt.Key_Up:
|
2009-07-21 20:04:27 +00:00
|
|
|
self.parent.onMoveSelectionUp()
|
2009-07-21 18:10:14 +00:00
|
|
|
event.accept()
|
|
|
|
elif event.key() == QtCore.Qt.Key_Down:
|
2009-07-21 20:04:27 +00:00
|
|
|
self.parent.onMoveSelectionDown()
|
2009-07-21 18:10:14 +00:00
|
|
|
event.accept()
|
2009-06-29 17:37:46 +00:00
|
|
|
event.ignore()
|
|
|
|
else:
|
|
|
|
event.ignore()
|
|
|
|
|
2009-10-11 09:31:27 +00:00
|
|
|
def mouseMoveEvent(self, event):
|
|
|
|
"""
|
|
|
|
Drag and drop event does not care what data is selected
|
|
|
|
as the recipient will use events to request the data move
|
|
|
|
just tell it what plugin to call
|
|
|
|
"""
|
|
|
|
if event.buttons() != QtCore.Qt.LeftButton:
|
2010-03-02 19:44:55 +00:00
|
|
|
event.ignore()
|
2009-10-11 09:31:27 +00:00
|
|
|
return
|
|
|
|
drag = QtGui.QDrag(self)
|
|
|
|
mimeData = QtCore.QMimeData()
|
|
|
|
drag.setMimeData(mimeData)
|
|
|
|
mimeData.setText(u'ServiceManager')
|
2010-04-30 21:00:17 +00:00
|
|
|
drag.start(QtCore.Qt.CopyAction)
|
2009-10-11 09:31:27 +00:00
|
|
|
|
2009-05-09 07:01:33 +00:00
|
|
|
class ServiceManager(QtGui.QWidget):
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
2009-09-19 21:45:50 +00:00
|
|
|
Manages the services. This involves taking text strings from plugins and
|
|
|
|
adding them to the service. This service can then be zipped up with all
|
|
|
|
the resources used into one OSZ file for use on any OpenLP v2 installation.
|
2009-03-04 21:56:27 +00:00
|
|
|
Also handles the UI tasks of moving things up and down etc.
|
|
|
|
"""
|
2009-03-23 19:17:07 +00:00
|
|
|
def __init__(self, parent):
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
|
|
|
Sets up the service manager, toolbars, list view, et al.
|
|
|
|
"""
|
2009-05-09 07:01:33 +00:00
|
|
|
QtGui.QWidget.__init__(self)
|
2009-05-22 18:30:25 +00:00
|
|
|
self.parent = parent
|
|
|
|
self.serviceItems = []
|
2009-07-07 16:35:01 +00:00
|
|
|
self.serviceName = u''
|
2010-05-06 16:49:12 +00:00
|
|
|
self.suffixes = []
|
2010-03-14 07:56:39 +00:00
|
|
|
self.droppos = 0
|
2009-10-30 20:14:55 +00:00
|
|
|
#is a new service and has not been saved
|
2009-09-18 13:32:40 +00:00
|
|
|
self.isNew = True
|
2010-07-21 00:36:15 +00:00
|
|
|
self.serviceNoteForm = ServiceNoteForm(self.parent)
|
|
|
|
self.serviceItemEditForm = ServiceItemEditForm(self.parent)
|
2009-10-30 20:14:55 +00:00
|
|
|
#start with the layout
|
2010-07-28 13:15:39 +00:00
|
|
|
self.layout = QtGui.QVBoxLayout(self)
|
|
|
|
self.layout.setSpacing(0)
|
|
|
|
self.layout.setMargin(0)
|
2009-06-08 19:03:16 +00:00
|
|
|
# Create the top toolbar
|
2010-07-28 13:15:39 +00:00
|
|
|
self.toolbar = OpenLPToolbar(self)
|
|
|
|
self.toolbar.addToolbarButton(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'New Service'),
|
2010-06-07 21:36:22 +00:00
|
|
|
u':/general/general_new.png',
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Create a new service'),
|
2010-06-07 21:36:22 +00:00
|
|
|
self.onNewService)
|
2010-07-28 13:15:39 +00:00
|
|
|
self.toolbar.addToolbarButton(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Open Service'),
|
2010-06-07 21:36:22 +00:00
|
|
|
u':/general/general_open.png',
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Load an existing service'),
|
2010-06-07 21:36:22 +00:00
|
|
|
self.onLoadService)
|
2010-07-28 13:15:39 +00:00
|
|
|
self.toolbar.addToolbarButton(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Save Service'),
|
2010-06-07 21:36:22 +00:00
|
|
|
u':/general/general_save.png',
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Save this service'),
|
2010-07-14 22:16:59 +00:00
|
|
|
self.onQuickSaveService)
|
2010-07-28 13:15:39 +00:00
|
|
|
self.toolbar.addSeparator()
|
|
|
|
self.themeLabel = QtGui.QLabel(translate('OpenLP.ServiceManager',
|
2010-07-26 15:19:11 +00:00
|
|
|
'Theme:'), self)
|
2010-07-28 13:15:39 +00:00
|
|
|
self.themeLabel.setMargin(3)
|
|
|
|
self.toolbar.addToolbarWidget(u'ThemeLabel', self.themeLabel)
|
|
|
|
self.themeComboBox = QtGui.QComboBox(self.toolbar)
|
|
|
|
self.themeComboBox.setToolTip(translate('OpenLP.ServiceManager',
|
2010-06-19 04:05:39 +00:00
|
|
|
'Select a theme for the service'))
|
2010-07-28 13:15:39 +00:00
|
|
|
self.themeComboBox.setSizeAdjustPolicy(
|
2009-09-10 17:03:17 +00:00
|
|
|
QtGui.QComboBox.AdjustToContents)
|
2010-07-28 13:15:39 +00:00
|
|
|
self.toolbar.addToolbarWidget(u'ThemeWidget', self.themeComboBox)
|
|
|
|
self.layout.addWidget(self.toolbar)
|
2009-06-08 19:03:16 +00:00
|
|
|
# Create the service manager list
|
2010-07-28 13:15:39 +00:00
|
|
|
self.serviceManagerList = ServiceManagerList(self)
|
|
|
|
self.serviceManagerList.setEditTriggers(
|
2009-09-10 20:18:15 +00:00
|
|
|
QtGui.QAbstractItemView.CurrentChanged |
|
|
|
|
QtGui.QAbstractItemView.DoubleClicked |
|
2009-09-10 17:03:17 +00:00
|
|
|
QtGui.QAbstractItemView.EditKeyPressed)
|
2010-07-28 13:15:39 +00:00
|
|
|
self.serviceManagerList.setDragDropMode(
|
2009-09-10 17:03:17 +00:00
|
|
|
QtGui.QAbstractItemView.DragDrop)
|
2010-07-28 13:15:39 +00:00
|
|
|
self.serviceManagerList.setAlternatingRowColors(True)
|
|
|
|
self.serviceManagerList.setHeaderHidden(True)
|
|
|
|
self.serviceManagerList.setExpandsOnDoubleClick(False)
|
|
|
|
self.serviceManagerList.setContextMenuPolicy(
|
2010-05-27 14:41:47 +00:00
|
|
|
QtCore.Qt.CustomContextMenu)
|
2010-07-28 13:15:39 +00:00
|
|
|
QtCore.QObject.connect(self.serviceManagerList,
|
2010-05-27 14:41:47 +00:00
|
|
|
QtCore.SIGNAL('customContextMenuRequested(QPoint)'),
|
|
|
|
self.contextMenu)
|
2010-07-28 13:15:39 +00:00
|
|
|
self.serviceManagerList.setObjectName(u'serviceManagerList')
|
2009-06-08 19:03:16 +00:00
|
|
|
# enable drop
|
2010-07-28 13:15:39 +00:00
|
|
|
self.serviceManagerList.__class__.dragEnterEvent = self.dragEnterEvent
|
|
|
|
self.serviceManagerList.__class__.dragMoveEvent = self.dragEnterEvent
|
|
|
|
self.serviceManagerList.__class__.dropEvent = self.dropEvent
|
|
|
|
self.layout.addWidget(self.serviceManagerList)
|
2009-06-08 19:03:16 +00:00
|
|
|
# Add the bottom toolbar
|
2010-07-30 16:19:32 +00:00
|
|
|
self.orderToolbar = OpenLPToolbar(self)
|
|
|
|
self.orderToolbar.addToolbarButton(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Move to &top'),
|
2010-06-07 21:36:22 +00:00
|
|
|
u':/services/service_top.png',
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager',
|
|
|
|
'Move item to the top of the service.'),
|
|
|
|
self.onServiceTop)
|
2010-07-30 16:19:32 +00:00
|
|
|
self.orderToolbar.addToolbarButton(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Move &up'),
|
2010-06-07 21:36:22 +00:00
|
|
|
u':/services/service_up.png',
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager',
|
|
|
|
'Move item up one position in the service.'),
|
|
|
|
self.onServiceUp)
|
2010-07-30 16:19:32 +00:00
|
|
|
self.orderToolbar.addToolbarButton(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Move &down'),
|
2010-06-07 21:36:22 +00:00
|
|
|
u':/services/service_down.png',
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager',
|
|
|
|
'Move item down one position in the service.'),
|
2010-06-07 21:36:22 +00:00
|
|
|
self.onServiceDown)
|
2010-07-30 16:19:32 +00:00
|
|
|
self.orderToolbar.addToolbarButton(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Move to &bottom'),
|
2010-06-07 21:36:22 +00:00
|
|
|
u':/services/service_bottom.png',
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager',
|
|
|
|
'Move item to the end of the service.'),
|
2010-06-07 21:36:22 +00:00
|
|
|
self.onServiceEnd)
|
2010-07-30 16:19:32 +00:00
|
|
|
self.orderToolbar.addSeparator()
|
|
|
|
self.orderToolbar.addToolbarButton(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', '&Delete From Service'),
|
2010-05-27 14:41:47 +00:00
|
|
|
u':/general/general_delete.png',
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager',
|
|
|
|
'Delete the selected item from the service.'),
|
2010-06-07 21:36:22 +00:00
|
|
|
self.onDeleteFromService)
|
2010-07-30 16:19:32 +00:00
|
|
|
self.layout.addWidget(self.orderToolbar)
|
2009-06-08 19:03:16 +00:00
|
|
|
# Connect up our signals and slots
|
2010-07-28 13:15:39 +00:00
|
|
|
QtCore.QObject.connect(self.themeComboBox,
|
2009-06-08 19:03:16 +00:00
|
|
|
QtCore.SIGNAL(u'activated(int)'), self.onThemeComboBoxSelected)
|
2010-07-28 13:15:39 +00:00
|
|
|
QtCore.QObject.connect(self.serviceManagerList,
|
2010-03-05 09:24:42 +00:00
|
|
|
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.makeLive)
|
2010-07-28 13:15:39 +00:00
|
|
|
QtCore.QObject.connect(self.serviceManagerList,
|
2009-06-20 07:08:17 +00:00
|
|
|
QtCore.SIGNAL(u'itemCollapsed(QTreeWidgetItem*)'), self.collapsed)
|
2010-07-28 13:15:39 +00:00
|
|
|
QtCore.QObject.connect(self.serviceManagerList,
|
2009-06-20 07:08:17 +00:00
|
|
|
QtCore.SIGNAL(u'itemExpanded(QTreeWidgetItem*)'), self.expanded)
|
2009-08-25 05:18:09 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
2010-04-16 07:31:01 +00:00
|
|
|
QtCore.SIGNAL(u'theme_update_list'), self.updateThemeList)
|
2010-02-03 18:29:02 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'servicemanager_next_item'), self.nextItem)
|
2010-04-26 21:29:40 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'servicemanager_previous_item'), self.previousItem)
|
2010-04-28 22:08:37 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'servicemanager_set_item'), self.onSetItem)
|
2010-04-26 21:29:40 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'servicemanager_list_request'), self.listRequest)
|
2010-03-13 15:11:31 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'config_updated'), self.regenerateServiceItems)
|
2010-06-26 07:19:30 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'theme_update_global'), self.themeChange)
|
2009-06-08 19:03:16 +00:00
|
|
|
# Last little bits of setting up
|
2010-04-27 16:27:57 +00:00
|
|
|
self.service_theme = unicode(QtCore.QSettings().value(
|
2010-04-30 22:38:15 +00:00
|
|
|
self.parent.serviceSettingsSection + u'/service theme',
|
2010-04-28 14:17:42 +00:00
|
|
|
QtCore.QVariant(u'')).toString())
|
2010-04-27 16:27:57 +00:00
|
|
|
self.servicePath = AppLocation.get_section_data_path(u'servicemanager')
|
2010-05-01 13:05:17 +00:00
|
|
|
#build the drag and drop context menu
|
|
|
|
self.dndMenu = QtGui.QMenu()
|
2010-06-06 09:52:11 +00:00
|
|
|
self.newAction = self.dndMenu.addAction(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', '&Add New Item'))
|
2010-05-01 13:05:17 +00:00
|
|
|
self.newAction.setIcon(build_icon(u':/general/general_edit.png'))
|
2010-06-06 09:52:11 +00:00
|
|
|
self.addToAction = self.dndMenu.addAction(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', '&Add to Selected Item'))
|
2010-05-01 13:05:17 +00:00
|
|
|
self.addToAction.setIcon(build_icon(u':/general/general_edit.png'))
|
2010-03-05 09:24:42 +00:00
|
|
|
#build the context menu
|
|
|
|
self.menu = QtGui.QMenu()
|
2010-06-06 09:52:11 +00:00
|
|
|
self.editAction = self.menu.addAction(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', '&Edit Item'))
|
2010-03-23 19:04:15 +00:00
|
|
|
self.editAction.setIcon(build_icon(u':/general/general_edit.png'))
|
2010-06-06 09:52:11 +00:00
|
|
|
self.maintainAction = self.menu.addAction(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', '&Reorder Item'))
|
2010-05-01 13:05:17 +00:00
|
|
|
self.maintainAction.setIcon(build_icon(u':/general/general_edit.png'))
|
2010-06-06 09:52:11 +00:00
|
|
|
self.notesAction = self.menu.addAction(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', '&Notes'))
|
2010-03-08 19:50:35 +00:00
|
|
|
self.notesAction.setIcon(build_icon(u':/services/service_notes.png'))
|
2010-04-27 16:27:57 +00:00
|
|
|
self.deleteAction = self.menu.addAction(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', '&Delete From Service'))
|
2010-03-23 19:04:15 +00:00
|
|
|
self.deleteAction.setIcon(build_icon(u':/general/general_delete.png'))
|
2010-03-05 09:24:42 +00:00
|
|
|
self.sep1 = self.menu.addAction(u'')
|
|
|
|
self.sep1.setSeparator(True)
|
2010-06-06 09:52:11 +00:00
|
|
|
self.previewAction = self.menu.addAction(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', '&Preview Verse'))
|
2010-03-23 19:04:15 +00:00
|
|
|
self.previewAction.setIcon(build_icon(u':/general/general_preview.png'))
|
2010-06-06 09:52:11 +00:00
|
|
|
self.liveAction = self.menu.addAction(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', '&Live Verse'))
|
2010-03-23 19:04:15 +00:00
|
|
|
self.liveAction.setIcon(build_icon(u':/general/general_live.png'))
|
2010-03-05 09:24:42 +00:00
|
|
|
self.sep2 = self.menu.addAction(u'')
|
|
|
|
self.sep2.setSeparator(True)
|
2010-06-06 09:52:11 +00:00
|
|
|
self.themeMenu = QtGui.QMenu(
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', '&Change Item Theme'))
|
2010-03-05 09:24:42 +00:00
|
|
|
self.menu.addMenu(self.themeMenu)
|
|
|
|
|
2010-05-05 18:07:57 +00:00
|
|
|
def supportedSuffixes(self, suffix):
|
2010-05-06 16:49:12 +00:00
|
|
|
self.suffixes.append(suffix)
|
2010-05-05 19:14:48 +00:00
|
|
|
|
2010-03-05 09:24:42 +00:00
|
|
|
def contextMenu(self, point):
|
2010-07-28 13:15:39 +00:00
|
|
|
item = self.serviceManagerList.itemAt(point)
|
2010-03-12 19:39:15 +00:00
|
|
|
if item is None:
|
|
|
|
return
|
2010-03-05 09:24:42 +00:00
|
|
|
if item.parent() is None:
|
|
|
|
pos = item.data(0, QtCore.Qt.UserRole).toInt()[0]
|
|
|
|
else:
|
|
|
|
pos = item.parent().data(0, QtCore.Qt.UserRole).toInt()[0]
|
|
|
|
serviceItem = self.serviceItems[pos - 1]
|
|
|
|
self.editAction.setVisible(False)
|
2010-03-16 20:30:33 +00:00
|
|
|
self.maintainAction.setVisible(False)
|
2010-03-05 09:24:42 +00:00
|
|
|
self.notesAction.setVisible(False)
|
2010-04-03 07:10:31 +00:00
|
|
|
if serviceItem[u'service_item'].is_capable(ItemCapabilities.AllowsEdit):
|
2010-03-05 09:24:42 +00:00
|
|
|
self.editAction.setVisible(True)
|
2010-04-06 19:16:14 +00:00
|
|
|
if serviceItem[u'service_item']\
|
|
|
|
.is_capable(ItemCapabilities.AllowsMaintain):
|
2010-03-16 20:30:33 +00:00
|
|
|
self.maintainAction.setVisible(True)
|
2010-03-05 09:24:42 +00:00
|
|
|
if item.parent() is None:
|
|
|
|
self.notesAction.setVisible(True)
|
|
|
|
self.themeMenu.menuAction().setVisible(False)
|
|
|
|
if serviceItem[u'service_item'].is_text():
|
|
|
|
self.themeMenu.menuAction().setVisible(True)
|
2010-07-28 13:15:39 +00:00
|
|
|
action = self.menu.exec_(self.serviceManagerList.mapToGlobal(point))
|
2010-03-05 09:24:42 +00:00
|
|
|
if action == self.editAction:
|
|
|
|
self.remoteEdit()
|
2010-03-17 21:25:35 +00:00
|
|
|
if action == self.maintainAction:
|
|
|
|
self.onServiceItemEditForm()
|
2010-03-08 19:50:35 +00:00
|
|
|
if action == self.deleteAction:
|
|
|
|
self.onDeleteFromService()
|
2010-03-05 09:24:42 +00:00
|
|
|
if action == self.notesAction:
|
|
|
|
self.onServiceItemNoteForm()
|
|
|
|
if action == self.previewAction:
|
|
|
|
self.makePreview()
|
|
|
|
if action == self.liveAction:
|
|
|
|
self.makeLive()
|
2009-05-18 19:04:25 +00:00
|
|
|
|
2010-03-03 17:48:37 +00:00
|
|
|
def onServiceItemNoteForm(self):
|
2010-05-27 14:41:47 +00:00
|
|
|
item = self.findServiceItem()[0]
|
2010-03-17 21:08:18 +00:00
|
|
|
self.serviceNoteForm.textEdit.setPlainText(
|
2010-03-04 22:03:43 +00:00
|
|
|
self.serviceItems[item][u'service_item'].notes)
|
2010-03-17 21:08:18 +00:00
|
|
|
if self.serviceNoteForm.exec_():
|
2010-03-04 22:03:43 +00:00
|
|
|
self.serviceItems[item][u'service_item'].notes = \
|
2010-03-17 21:08:18 +00:00
|
|
|
self.serviceNoteForm.textEdit.toPlainText()
|
2010-03-06 08:00:36 +00:00
|
|
|
self.repaintServiceList(item, 0)
|
2010-03-03 17:48:37 +00:00
|
|
|
|
2010-03-17 21:25:35 +00:00
|
|
|
def onServiceItemEditForm(self):
|
2010-05-27 14:41:47 +00:00
|
|
|
item = self.findServiceItem()[0]
|
2010-03-18 21:50:20 +00:00
|
|
|
self.serviceItemEditForm.setServiceItem(
|
|
|
|
self.serviceItems[item][u'service_item'])
|
2010-03-17 21:25:35 +00:00
|
|
|
if self.serviceItemEditForm.exec_():
|
2010-08-23 17:48:52 +00:00
|
|
|
self.addServiceItem(self.serviceItemEditForm.getServiceItem(),
|
|
|
|
replace=True)
|
2010-03-17 21:25:35 +00:00
|
|
|
|
2010-02-03 18:29:02 +00:00
|
|
|
def nextItem(self):
|
|
|
|
"""
|
|
|
|
Called by the SlideController to select the
|
|
|
|
next service item
|
|
|
|
"""
|
2010-07-28 13:15:39 +00:00
|
|
|
if len(self.serviceManagerList.selectedItems()) == 0:
|
2010-02-04 19:25:32 +00:00
|
|
|
return
|
2010-07-28 13:15:39 +00:00
|
|
|
selected = self.serviceManagerList.selectedItems()[0]
|
2010-02-03 18:29:02 +00:00
|
|
|
lookFor = 0
|
2010-07-28 13:15:39 +00:00
|
|
|
serviceIterator = QtGui.QTreeWidgetItemIterator(self.serviceManagerList)
|
2010-02-03 18:29:02 +00:00
|
|
|
while serviceIterator.value():
|
|
|
|
if lookFor == 1 and serviceIterator.value().parent() is None:
|
2010-07-28 13:15:39 +00:00
|
|
|
self.serviceManagerList.setCurrentItem(serviceIterator.value())
|
2010-02-03 18:29:02 +00:00
|
|
|
self.makeLive()
|
|
|
|
return
|
|
|
|
if serviceIterator.value() == selected:
|
|
|
|
lookFor = 1
|
|
|
|
serviceIterator += 1
|
|
|
|
|
2010-04-26 21:29:40 +00:00
|
|
|
def previousItem(self):
|
|
|
|
"""
|
|
|
|
Called by the SlideController to select the
|
|
|
|
previous service item
|
|
|
|
"""
|
2010-07-28 13:15:39 +00:00
|
|
|
if len(self.serviceManagerList.selectedItems()) == 0:
|
2010-04-26 21:29:40 +00:00
|
|
|
return
|
2010-07-28 13:15:39 +00:00
|
|
|
selected = self.serviceManagerList.selectedItems()[0]
|
2010-04-26 21:29:40 +00:00
|
|
|
prevItem = None
|
2010-07-28 13:15:39 +00:00
|
|
|
serviceIterator = QtGui.QTreeWidgetItemIterator(self.serviceManagerList)
|
2010-04-26 21:29:40 +00:00
|
|
|
while serviceIterator.value():
|
|
|
|
if serviceIterator.value() == selected:
|
|
|
|
if prevItem:
|
2010-07-28 13:15:39 +00:00
|
|
|
self.serviceManagerList.setCurrentItem(prevItem)
|
2010-04-26 21:29:40 +00:00
|
|
|
self.makeLive()
|
|
|
|
return
|
|
|
|
if serviceIterator.value().parent() is None:
|
|
|
|
prevItem = serviceIterator.value()
|
|
|
|
serviceIterator += 1
|
|
|
|
|
2010-04-28 22:08:37 +00:00
|
|
|
def onSetItem(self, message):
|
|
|
|
"""
|
|
|
|
Called by a signal to select a specific item
|
|
|
|
"""
|
|
|
|
self.setItem(int(message[0]))
|
2010-05-04 20:01:45 +00:00
|
|
|
|
2010-04-28 22:08:37 +00:00
|
|
|
def setItem(self, index):
|
|
|
|
"""
|
|
|
|
Makes a specific item in the service live
|
|
|
|
"""
|
2010-07-28 13:15:39 +00:00
|
|
|
if index >= 0 and index < self.serviceManagerList.topLevelItemCount:
|
|
|
|
item = self.serviceManagerList.topLevelItem(index)
|
|
|
|
self.serviceManagerList.setCurrentItem(item)
|
2010-04-28 22:08:37 +00:00
|
|
|
self.makeLive()
|
|
|
|
|
2009-07-21 20:04:27 +00:00
|
|
|
def onMoveSelectionUp(self):
|
|
|
|
"""
|
|
|
|
Moves the selection up the window
|
|
|
|
Called by the up arrow
|
|
|
|
"""
|
2010-07-28 13:15:39 +00:00
|
|
|
serviceIterator = QtGui.QTreeWidgetItemIterator(self.serviceManagerList)
|
2009-07-21 20:04:27 +00:00
|
|
|
tempItem = None
|
|
|
|
setLastItem = False
|
2009-11-03 01:37:08 +00:00
|
|
|
while serviceIterator:
|
|
|
|
if serviceIterator.isSelected() and tempItem is None:
|
2009-07-21 20:04:27 +00:00
|
|
|
setLastItem = True
|
2009-11-03 01:37:08 +00:00
|
|
|
serviceIterator.setSelected(False)
|
|
|
|
if serviceIterator.isSelected():
|
2009-07-21 20:04:27 +00:00
|
|
|
#We are on the first record
|
2009-11-03 18:14:25 +00:00
|
|
|
if tempItem:
|
2009-07-21 20:04:27 +00:00
|
|
|
tempItem.setSelected(True)
|
2009-11-03 01:37:08 +00:00
|
|
|
serviceIterator.setSelected(False)
|
2009-07-21 20:04:27 +00:00
|
|
|
else:
|
2009-11-03 01:37:08 +00:00
|
|
|
tempItem = serviceIterator
|
|
|
|
lastItem = serviceIterator
|
|
|
|
++serviceIterator
|
2009-07-21 20:04:27 +00:00
|
|
|
#Top Item was selected so set the last one
|
|
|
|
if setLastItem:
|
|
|
|
lastItem.setSelected(True)
|
|
|
|
|
|
|
|
def onMoveSelectionDown(self):
|
|
|
|
"""
|
|
|
|
Moves the selection down the window
|
|
|
|
Called by the down arrow
|
|
|
|
"""
|
2010-07-28 13:15:39 +00:00
|
|
|
serviceIterator = QtGui.QTreeWidgetItemIterator(self.serviceManagerList)
|
2009-11-03 01:37:08 +00:00
|
|
|
firstItem = serviceIterator
|
2009-07-21 20:04:27 +00:00
|
|
|
setSelected = False
|
2009-11-03 01:37:08 +00:00
|
|
|
while serviceIterator:
|
2009-07-21 20:04:27 +00:00
|
|
|
if setSelected:
|
|
|
|
setSelected = False
|
2009-11-03 01:37:08 +00:00
|
|
|
serviceIterator.setSelected(True)
|
|
|
|
elif serviceIterator.isSelected():
|
|
|
|
serviceIterator.setSelected(False)
|
2009-07-21 20:04:27 +00:00
|
|
|
setSelected = True
|
2009-11-03 01:37:08 +00:00
|
|
|
++serviceIterator
|
2009-07-21 20:04:27 +00:00
|
|
|
if setSelected:
|
|
|
|
firstItem.setSelected(True)
|
|
|
|
|
2009-06-20 07:08:17 +00:00
|
|
|
def collapsed(self, item):
|
2009-07-11 05:18:34 +00:00
|
|
|
"""
|
|
|
|
Record if an item is collapsed
|
|
|
|
Used when repainting the list to get the correct state
|
|
|
|
"""
|
2009-06-20 07:08:17 +00:00
|
|
|
pos = item.data(0, QtCore.Qt.UserRole).toInt()[0]
|
|
|
|
self.serviceItems[pos -1 ][u'expanded'] = False
|
|
|
|
|
|
|
|
def expanded(self, item):
|
2009-07-11 05:18:34 +00:00
|
|
|
"""
|
|
|
|
Record if an item is collapsed
|
|
|
|
Used when repainting the list to get the correct state
|
|
|
|
"""
|
2009-06-20 07:08:17 +00:00
|
|
|
pos = item.data(0, QtCore.Qt.UserRole).toInt()[0]
|
|
|
|
self.serviceItems[pos -1 ][u'expanded'] = True
|
|
|
|
|
2009-05-04 08:15:48 +00:00
|
|
|
def onServiceTop(self):
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
|
|
|
Move the current ServiceItem to the top of the list
|
|
|
|
"""
|
2009-06-19 18:41:38 +00:00
|
|
|
item, count = self.findServiceItem()
|
|
|
|
if item < len(self.serviceItems) and item is not -1:
|
|
|
|
temp = self.serviceItems[item]
|
|
|
|
self.serviceItems.remove(self.serviceItems[item])
|
|
|
|
self.serviceItems.insert(0, temp)
|
2009-07-21 18:10:14 +00:00
|
|
|
self.repaintServiceList(0, count)
|
2009-09-19 21:45:50 +00:00
|
|
|
self.parent.serviceChanged(False, self.serviceName)
|
2009-05-04 08:15:48 +00:00
|
|
|
|
|
|
|
def onServiceUp(self):
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
|
|
|
Move the current ServiceItem up in the list
|
2010-03-18 21:50:20 +00:00
|
|
|
Note move up means move to top of area ie 0.
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
2009-06-19 18:41:38 +00:00
|
|
|
item, count = self.findServiceItem()
|
|
|
|
if item > 0:
|
|
|
|
temp = self.serviceItems[item]
|
|
|
|
self.serviceItems.remove(self.serviceItems[item])
|
|
|
|
self.serviceItems.insert(item - 1, temp)
|
2009-09-21 17:56:36 +00:00
|
|
|
self.repaintServiceList(item - 1, count)
|
2009-09-19 21:45:50 +00:00
|
|
|
self.parent.serviceChanged(False, self.serviceName)
|
2009-05-04 08:15:48 +00:00
|
|
|
|
|
|
|
def onServiceDown(self):
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
|
|
|
Move the current ServiceItem down in the list
|
2009-06-19 18:41:38 +00:00
|
|
|
Note move down means move to bottom of area i.e len().
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
2009-06-19 18:41:38 +00:00
|
|
|
item, count = self.findServiceItem()
|
|
|
|
if item < len(self.serviceItems) and item is not -1:
|
|
|
|
temp = self.serviceItems[item]
|
|
|
|
self.serviceItems.remove(self.serviceItems[item])
|
|
|
|
self.serviceItems.insert(item + 1, temp)
|
2009-09-21 17:56:36 +00:00
|
|
|
self.repaintServiceList(item + 1, count)
|
2009-09-19 21:45:50 +00:00
|
|
|
self.parent.serviceChanged(False, self.serviceName)
|
2009-05-04 08:15:48 +00:00
|
|
|
|
|
|
|
def onServiceEnd(self):
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
|
|
|
Move the current ServiceItem to the bottom of the list
|
|
|
|
"""
|
2009-06-19 18:41:38 +00:00
|
|
|
item, count = self.findServiceItem()
|
|
|
|
if item < len(self.serviceItems) and item is not -1:
|
|
|
|
temp = self.serviceItems[item]
|
|
|
|
self.serviceItems.remove(self.serviceItems[item])
|
|
|
|
self.serviceItems.insert(len(self.serviceItems), temp)
|
2009-07-21 18:10:14 +00:00
|
|
|
self.repaintServiceList(len(self.serviceItems) - 1, count)
|
2009-09-19 21:45:50 +00:00
|
|
|
self.parent.serviceChanged(False, self.serviceName)
|
2009-05-04 08:15:48 +00:00
|
|
|
|
|
|
|
def onNewService(self):
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
|
|
|
Clear the list to create a new service
|
|
|
|
"""
|
2010-04-28 14:17:42 +00:00
|
|
|
if self.parent.serviceNotSaved and QtCore.QSettings().value(
|
2010-04-30 22:38:15 +00:00
|
|
|
self.parent.generalSettingsSection + u'/save prompt',
|
2010-04-28 14:17:42 +00:00
|
|
|
QtCore.QVariant(False)).toBool():
|
2010-01-24 13:58:39 +00:00
|
|
|
ret = QtGui.QMessageBox.question(self,
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Save Changes to Service?'),
|
|
|
|
translate('OpenLP.ServiceManager',
|
2010-06-19 04:05:39 +00:00
|
|
|
'Your service is unsaved, do you want to save '
|
|
|
|
'those changes before creating a new one?'),
|
2009-10-30 20:14:55 +00:00
|
|
|
QtGui.QMessageBox.StandardButtons(
|
2010-07-31 02:06:44 +00:00
|
|
|
QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Save),
|
2009-10-30 20:14:55 +00:00
|
|
|
QtGui.QMessageBox.Save)
|
|
|
|
if ret == QtGui.QMessageBox.Save:
|
|
|
|
self.onSaveService()
|
2010-07-28 13:15:39 +00:00
|
|
|
self.serviceManagerList.clear()
|
2009-06-08 20:36:33 +00:00
|
|
|
self.serviceItems = []
|
2009-07-07 16:35:01 +00:00
|
|
|
self.serviceName = u''
|
2009-09-18 13:32:40 +00:00
|
|
|
self.isNew = True
|
2009-09-19 21:45:50 +00:00
|
|
|
self.parent.serviceChanged(True, self.serviceName)
|
2009-05-04 08:15:48 +00:00
|
|
|
|
|
|
|
def onDeleteFromService(self):
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
|
|
|
Remove the current ServiceItem from the list
|
|
|
|
"""
|
2010-05-27 14:41:47 +00:00
|
|
|
item = self.findServiceItem()[0]
|
2009-06-19 18:41:38 +00:00
|
|
|
if item is not -1:
|
|
|
|
self.serviceItems.remove(self.serviceItems[item])
|
2009-07-21 18:10:14 +00:00
|
|
|
self.repaintServiceList(0, 0)
|
2009-09-19 21:45:50 +00:00
|
|
|
self.parent.serviceChanged(False, self.serviceName)
|
2009-06-19 18:41:38 +00:00
|
|
|
|
2009-09-19 21:45:50 +00:00
|
|
|
def repaintServiceList(self, serviceItem, serviceItemCount):
|
2009-07-11 05:18:34 +00:00
|
|
|
"""
|
|
|
|
Clear the existing service list and prepaint all the items
|
|
|
|
Used when moving items as the move takes place in supporting array,
|
|
|
|
and when regenerating all the items due to theme changes
|
|
|
|
"""
|
2009-08-02 16:13:59 +00:00
|
|
|
#Correct order of items in array
|
2009-06-19 18:41:38 +00:00
|
|
|
count = 1
|
|
|
|
for item in self.serviceItems:
|
|
|
|
item[u'order'] = count
|
|
|
|
count += 1
|
|
|
|
#Repaint the screen
|
2010-07-28 13:15:39 +00:00
|
|
|
self.serviceManagerList.clear()
|
2009-07-21 18:10:14 +00:00
|
|
|
for itemcount, item in enumerate(self.serviceItems):
|
2009-11-14 08:40:14 +00:00
|
|
|
serviceitem = item[u'service_item']
|
2010-07-28 13:15:39 +00:00
|
|
|
treewidgetitem = QtGui.QTreeWidgetItem(self.serviceManagerList)
|
2010-05-07 18:29:17 +00:00
|
|
|
if serviceitem.is_valid:
|
2010-05-04 20:01:45 +00:00
|
|
|
if serviceitem.notes:
|
|
|
|
icon = QtGui.QImage(serviceitem.icon)
|
|
|
|
icon = icon.scaled(80, 80, QtCore.Qt.KeepAspectRatio,
|
2010-06-01 17:13:54 +00:00
|
|
|
QtCore.Qt.SmoothTransformation)
|
2010-05-04 20:01:45 +00:00
|
|
|
overlay = QtGui.QImage(':/services/service_item_notes.png')
|
|
|
|
overlay = overlay.scaled(80, 80, QtCore.Qt.KeepAspectRatio,
|
2010-06-01 17:13:54 +00:00
|
|
|
QtCore.Qt.SmoothTransformation)
|
2010-05-04 20:01:45 +00:00
|
|
|
painter = QtGui.QPainter(icon)
|
|
|
|
painter.drawImage(0, 0, overlay)
|
|
|
|
painter.end()
|
|
|
|
treewidgetitem.setIcon(0, build_icon(icon))
|
|
|
|
else:
|
|
|
|
treewidgetitem.setIcon(0, serviceitem.iconic_representation)
|
2010-03-06 08:00:36 +00:00
|
|
|
else:
|
2010-06-01 17:13:54 +00:00
|
|
|
treewidgetitem.setIcon(0,
|
|
|
|
build_icon(u':/general/general_delete.png'))
|
2010-03-07 20:45:27 +00:00
|
|
|
treewidgetitem.setText(0, serviceitem.title)
|
2010-03-06 08:00:36 +00:00
|
|
|
treewidgetitem.setToolTip(0, serviceitem.notes)
|
2009-09-02 01:44:09 +00:00
|
|
|
treewidgetitem.setData(0, QtCore.Qt.UserRole,
|
|
|
|
QtCore.QVariant(item[u'order']))
|
2009-11-14 09:41:11 +00:00
|
|
|
for count, frame in enumerate(serviceitem.get_frames()):
|
2009-06-19 18:41:38 +00:00
|
|
|
treewidgetitem1 = QtGui.QTreeWidgetItem(treewidgetitem)
|
|
|
|
text = frame[u'title']
|
2010-03-06 08:00:36 +00:00
|
|
|
treewidgetitem1.setText(0, text[:40])
|
2009-09-02 01:44:09 +00:00
|
|
|
treewidgetitem1.setData(0, QtCore.Qt.UserRole,
|
|
|
|
QtCore.QVariant(count))
|
2009-07-21 18:10:14 +00:00
|
|
|
if serviceItem == itemcount and serviceItemCount == count:
|
2010-03-08 19:50:35 +00:00
|
|
|
#preserve expanding status as setCurrentItem sets it to True
|
|
|
|
temp = item[u'expanded']
|
2010-07-28 13:15:39 +00:00
|
|
|
self.serviceManagerList.setCurrentItem(treewidgetitem1)
|
2010-03-08 19:50:35 +00:00
|
|
|
item[u'expanded'] = temp
|
|
|
|
treewidgetitem.setExpanded(item[u'expanded'])
|
2009-05-04 08:15:48 +00:00
|
|
|
|
2009-09-18 09:03:04 +00:00
|
|
|
def onSaveService(self, quick=False):
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
2009-09-19 21:45:50 +00:00
|
|
|
Save the current service in a zip (OSZ) file
|
2009-07-11 05:18:34 +00:00
|
|
|
This file contains
|
2009-09-19 21:45:50 +00:00
|
|
|
* An osd which is a pickle of the service items
|
2009-09-02 01:44:09 +00:00
|
|
|
* All image, presentation and video files needed to run the service.
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
2010-08-31 17:51:48 +00:00
|
|
|
log.debug(u'onSaveService %s' % quick)
|
2009-09-18 13:32:40 +00:00
|
|
|
if not quick or self.isNew:
|
2009-09-18 09:03:04 +00:00
|
|
|
filename = QtGui.QFileDialog.getSaveFileName(self,
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Save Service'),
|
2010-04-30 22:38:15 +00:00
|
|
|
SettingsManager.get_last_dir(self.parent.serviceSettingsSection),
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz)'))
|
2009-09-18 09:03:04 +00:00
|
|
|
else:
|
2010-07-15 00:06:20 +00:00
|
|
|
filename = os.path.join(SettingsManager.get_last_dir(
|
|
|
|
self.parent.serviceSettingsSection), self.serviceName)
|
2009-11-07 00:00:36 +00:00
|
|
|
if filename:
|
2010-07-15 00:06:20 +00:00
|
|
|
filename = QtCore.QDir.toNativeSeparators(filename)
|
2009-09-18 13:45:07 +00:00
|
|
|
splittedFile = filename.split(u'.')
|
2009-09-19 21:45:50 +00:00
|
|
|
if splittedFile[-1] != u'osz':
|
|
|
|
filename = filename + u'.osz'
|
2009-09-18 13:45:07 +00:00
|
|
|
filename = unicode(filename)
|
2009-09-18 13:32:40 +00:00
|
|
|
self.isNew = False
|
2010-07-15 00:06:20 +00:00
|
|
|
SettingsManager.set_last_dir(self.parent.serviceSettingsSection,
|
2010-04-30 01:59:15 +00:00
|
|
|
os.path.split(filename)[0])
|
2009-06-08 20:36:33 +00:00
|
|
|
service = []
|
2009-09-19 21:45:50 +00:00
|
|
|
servicefile = filename + u'.osd'
|
2009-11-07 00:00:36 +00:00
|
|
|
zip = None
|
|
|
|
file = None
|
|
|
|
try:
|
|
|
|
zip = zipfile.ZipFile(unicode(filename), 'w')
|
|
|
|
for item in self.serviceItems:
|
2010-04-23 19:55:31 +00:00
|
|
|
service.append({u'serviceitem':item[u'service_item']
|
|
|
|
.get_service_repr()})
|
2009-12-08 17:04:27 +00:00
|
|
|
if item[u'service_item'].uses_file():
|
2010-01-29 16:38:28 +00:00
|
|
|
for frame in item[u'service_item'].get_frames():
|
2009-11-07 00:00:36 +00:00
|
|
|
path_from = unicode(os.path.join(
|
2010-03-18 21:50:20 +00:00
|
|
|
frame[u'path'],
|
2010-01-29 16:38:28 +00:00
|
|
|
frame[u'title']))
|
2010-06-09 19:10:57 +00:00
|
|
|
zip.write(path_from.encode(u'utf-8'))
|
2009-11-07 00:00:36 +00:00
|
|
|
file = open(servicefile, u'wb')
|
|
|
|
cPickle.dump(service, file)
|
|
|
|
file.close()
|
2010-06-09 19:10:57 +00:00
|
|
|
zip.write(servicefile.encode(u'utf-8'))
|
2010-05-27 14:41:47 +00:00
|
|
|
except IOError:
|
2009-11-07 00:00:36 +00:00
|
|
|
log.exception(u'Failed to save service to disk')
|
|
|
|
finally:
|
|
|
|
if file:
|
|
|
|
file.close()
|
|
|
|
if zip:
|
|
|
|
zip.close()
|
2009-06-20 11:23:34 +00:00
|
|
|
try:
|
|
|
|
os.remove(servicefile)
|
2010-05-27 16:00:51 +00:00
|
|
|
except (IOError, OSError):
|
2009-06-20 11:23:34 +00:00
|
|
|
pass #if not present do not worry
|
2010-03-14 17:05:50 +00:00
|
|
|
name = filename.split(os.path.sep)
|
|
|
|
self.serviceName = name[-1]
|
2010-04-23 18:30:53 +00:00
|
|
|
self.parent.addRecentFile(filename)
|
2010-03-14 17:05:50 +00:00
|
|
|
self.parent.serviceChanged(True, self.serviceName)
|
2009-10-01 16:56:42 +00:00
|
|
|
|
2009-09-18 09:03:04 +00:00
|
|
|
def onQuickSaveService(self):
|
|
|
|
self.onSaveService(True)
|
2009-06-20 11:23:34 +00:00
|
|
|
|
2009-11-12 23:33:59 +00:00
|
|
|
def onLoadService(self, lastService=False):
|
2009-10-18 14:53:04 +00:00
|
|
|
if lastService:
|
2010-06-30 11:59:09 +00:00
|
|
|
filename = self.parent.recentFiles[0]
|
2009-10-18 14:53:04 +00:00
|
|
|
else:
|
2009-10-23 13:17:43 +00:00
|
|
|
filename = QtGui.QFileDialog.getOpenFileName(
|
2010-07-22 06:02:31 +00:00
|
|
|
self, translate('OpenLP.ServiceManager', 'Open Service'),
|
2010-04-30 01:31:41 +00:00
|
|
|
SettingsManager.get_last_dir(
|
2010-04-30 22:38:15 +00:00
|
|
|
self.parent.serviceSettingsSection), u'Services (*.osz)')
|
2010-06-30 11:59:09 +00:00
|
|
|
filename = QtCore.QDir.toNativeSeparators(filename)
|
2010-04-23 18:30:53 +00:00
|
|
|
self.loadService(filename)
|
|
|
|
|
|
|
|
def loadService(self, filename=None):
|
|
|
|
"""
|
|
|
|
Load an existing service from disk and rebuild the serviceitems. All
|
|
|
|
files retrieved from the zip file are placed in a temporary directory
|
|
|
|
and will only be used for this service.
|
|
|
|
"""
|
2010-04-23 19:55:31 +00:00
|
|
|
if self.parent.serviceNotSaved:
|
|
|
|
ret = QtGui.QMessageBox.question(self,
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Save Changes to Service?'),
|
|
|
|
translate('OpenLP.ServiceManager',
|
2010-06-19 04:05:39 +00:00
|
|
|
'Your current service is unsaved, do you want to '
|
|
|
|
'save the changes before opening a new one?'),
|
2010-04-23 19:55:31 +00:00
|
|
|
QtGui.QMessageBox.StandardButtons(
|
2010-07-31 02:06:44 +00:00
|
|
|
QtGui.QMessageBox.Discard | QtGui.QMessageBox.Save),
|
2010-04-23 19:55:31 +00:00
|
|
|
QtGui.QMessageBox.Save)
|
|
|
|
if ret == QtGui.QMessageBox.Save:
|
|
|
|
self.onSaveService()
|
2010-04-23 18:30:53 +00:00
|
|
|
if filename is None:
|
|
|
|
action = self.sender()
|
|
|
|
if isinstance(action, QtGui.QAction):
|
|
|
|
filename = action.data().toString()
|
|
|
|
else:
|
|
|
|
return
|
2009-06-20 11:23:34 +00:00
|
|
|
filename = unicode(filename)
|
2009-07-07 16:35:01 +00:00
|
|
|
name = filename.split(os.path.sep)
|
2009-11-07 00:00:36 +00:00
|
|
|
if filename:
|
2010-06-20 12:12:49 +00:00
|
|
|
SettingsManager.set_last_dir(self.parent.serviceSettingsSection,
|
2010-06-30 11:59:09 +00:00
|
|
|
os.path.split(filename)[0])
|
2009-11-07 00:00:36 +00:00
|
|
|
zip = None
|
2010-05-27 14:41:47 +00:00
|
|
|
file_to = None
|
2009-06-20 19:11:17 +00:00
|
|
|
try:
|
2009-08-31 18:27:36 +00:00
|
|
|
zip = zipfile.ZipFile(unicode(filename))
|
|
|
|
for file in zip.namelist():
|
2010-06-09 19:10:57 +00:00
|
|
|
try:
|
|
|
|
ucsfile = file.decode(u'utf-8')
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
QtGui.QMessageBox.critical(
|
2010-07-22 06:02:31 +00:00
|
|
|
self, translate('OpenLP.ServiceManager', 'Error'),
|
|
|
|
translate('OpenLP.ServiceManager',
|
2010-06-19 04:05:39 +00:00
|
|
|
'File is not a valid service.\n'
|
|
|
|
'The content encoding is not UTF-8.'))
|
2010-06-19 18:29:18 +00:00
|
|
|
log.exception(u'Filename "%s" is not valid UTF-8' %
|
2010-06-09 19:10:57 +00:00
|
|
|
file.decode(u'utf-8', u'replace'))
|
|
|
|
continue
|
|
|
|
osfile = unicode(QtCore.QDir.toNativeSeparators(ucsfile))
|
2009-11-12 23:33:59 +00:00
|
|
|
names = osfile.split(os.path.sep)
|
2010-05-27 14:41:47 +00:00
|
|
|
file_path = os.path.join(self.servicePath,
|
2009-09-10 17:03:17 +00:00
|
|
|
names[len(names) - 1])
|
2010-05-27 14:41:47 +00:00
|
|
|
file_to = open(file_path, u'wb')
|
|
|
|
file_to.write(zip.read(file))
|
|
|
|
file_to.flush()
|
|
|
|
file_to.close()
|
|
|
|
if file_path.endswith(u'osd'):
|
|
|
|
p_file = file_path
|
2010-06-09 19:10:57 +00:00
|
|
|
if 'p_file' in locals():
|
|
|
|
file_to = open(p_file, u'r')
|
|
|
|
items = cPickle.load(file_to)
|
|
|
|
file_to.close()
|
|
|
|
self.onNewService()
|
|
|
|
for item in items:
|
|
|
|
serviceitem = ServiceItem()
|
2010-06-20 11:43:16 +00:00
|
|
|
serviceitem.render_manager = self.parent.RenderManager
|
2010-06-09 19:10:57 +00:00
|
|
|
serviceitem.set_from_service(item, self.servicePath)
|
|
|
|
self.validateItem(serviceitem)
|
|
|
|
self.addServiceItem(serviceitem)
|
|
|
|
try:
|
|
|
|
if os.path.isfile(p_file):
|
|
|
|
os.remove(p_file)
|
|
|
|
except (IOError, OSError):
|
|
|
|
log.exception(u'Failed to remove osd file')
|
|
|
|
else:
|
|
|
|
QtGui.QMessageBox.critical(
|
2010-07-22 06:02:31 +00:00
|
|
|
self, translate('OpenLP.ServiceManager', 'Error'),
|
|
|
|
translate('OpenLP.ServiceManager',
|
2010-06-19 04:05:39 +00:00
|
|
|
'File is not a valid service.'))
|
2010-06-09 19:10:57 +00:00
|
|
|
log.exception(u'File contains no service data')
|
2010-06-10 07:59:46 +00:00
|
|
|
except (IOError, NameError):
|
2009-09-17 23:10:25 +00:00
|
|
|
log.exception(u'Problem loading a service file')
|
2009-11-07 00:00:36 +00:00
|
|
|
finally:
|
2010-05-27 14:41:47 +00:00
|
|
|
if file_to:
|
|
|
|
file_to.close()
|
2009-11-07 00:00:36 +00:00
|
|
|
if zip:
|
|
|
|
zip.close()
|
2009-09-18 13:45:07 +00:00
|
|
|
self.isNew = False
|
2009-07-07 16:35:01 +00:00
|
|
|
self.serviceName = name[len(name) - 1]
|
2010-04-23 18:30:53 +00:00
|
|
|
self.parent.addRecentFile(filename)
|
2009-09-19 21:45:50 +00:00
|
|
|
self.parent.serviceChanged(True, self.serviceName)
|
|
|
|
|
2010-01-29 16:38:28 +00:00
|
|
|
def validateItem(self, serviceItem):
|
2010-05-04 20:01:45 +00:00
|
|
|
"""
|
|
|
|
Validates the service item and if the suffix matches an accepted
|
|
|
|
one it allows the item to be displayed
|
|
|
|
"""
|
|
|
|
if serviceItem.is_command():
|
|
|
|
type = serviceItem._raw_frames[0][u'title'].split(u'.')[1]
|
2010-05-05 18:07:57 +00:00
|
|
|
if type not in self.suffixes:
|
2010-05-07 18:29:17 +00:00
|
|
|
serviceItem.is_valid = False
|
2010-01-29 16:38:28 +00:00
|
|
|
|
2009-09-19 21:45:50 +00:00
|
|
|
def cleanUp(self):
|
|
|
|
"""
|
|
|
|
Empties the servicePath of temporary files
|
|
|
|
"""
|
|
|
|
for file in os.listdir(self.servicePath):
|
|
|
|
file_path = os.path.join(self.servicePath, file)
|
|
|
|
try:
|
|
|
|
if os.path.isfile(file_path):
|
|
|
|
os.remove(file_path)
|
2010-05-27 16:00:51 +00:00
|
|
|
except OSError:
|
2009-09-19 21:45:50 +00:00
|
|
|
log.exception(u'Failed to clean up servicePath')
|
2009-05-04 08:15:48 +00:00
|
|
|
|
2009-04-25 06:11:15 +00:00
|
|
|
def onThemeComboBoxSelected(self, currentIndex):
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
|
|
|
Set the theme for the current service
|
|
|
|
"""
|
2010-08-31 17:51:48 +00:00
|
|
|
log.debug(u'onThemeComboBoxSelected')
|
2010-07-28 13:15:39 +00:00
|
|
|
self.service_theme = unicode(self.themeComboBox.currentText())
|
2009-06-01 17:50:37 +00:00
|
|
|
self.parent.RenderManager.set_service_theme(self.service_theme)
|
2010-04-30 01:31:41 +00:00
|
|
|
QtCore.QSettings().setValue(
|
2010-04-30 22:38:15 +00:00
|
|
|
self.parent.serviceSettingsSection + u'/service theme',
|
2010-04-27 16:27:57 +00:00
|
|
|
QtCore.QVariant(self.service_theme))
|
2009-06-26 16:39:16 +00:00
|
|
|
self.regenerateServiceItems()
|
|
|
|
|
2010-06-26 07:19:30 +00:00
|
|
|
def themeChange(self):
|
|
|
|
"""
|
|
|
|
The theme may have changed in the settings dialog so make
|
|
|
|
sure the theme combo box is in the correct state.
|
|
|
|
"""
|
2010-08-31 17:51:48 +00:00
|
|
|
log.debug(u'themeChange')
|
2010-06-26 07:19:30 +00:00
|
|
|
if self.parent.RenderManager.theme_level == ThemeLevel.Global:
|
2010-07-28 13:15:39 +00:00
|
|
|
self.toolbar.actions[u'ThemeLabel'].setVisible(False)
|
|
|
|
self.toolbar.actions[u'ThemeWidget'].setVisible(False)
|
2010-06-26 07:19:30 +00:00
|
|
|
else:
|
2010-07-28 13:15:39 +00:00
|
|
|
self.toolbar.actions[u'ThemeLabel'].setVisible(True)
|
|
|
|
self.toolbar.actions[u'ThemeWidget'].setVisible(True)
|
2010-06-26 07:19:30 +00:00
|
|
|
|
2009-06-26 16:39:16 +00:00
|
|
|
def regenerateServiceItems(self):
|
2010-05-23 07:03:28 +00:00
|
|
|
"""
|
|
|
|
Rebuild the service list as things have changed and a
|
|
|
|
repaint is the easiest way to do this.
|
|
|
|
"""
|
2010-08-31 17:51:48 +00:00
|
|
|
log.debug(u'regenerateServiceItems')
|
2010-08-26 05:01:29 +00:00
|
|
|
# force reset of renderer as theme data has changed
|
2010-02-23 19:37:07 +00:00
|
|
|
self.parent.RenderManager.themedata = None
|
2010-03-09 19:43:11 +00:00
|
|
|
if self.serviceItems:
|
2009-06-10 15:54:46 +00:00
|
|
|
tempServiceItems = self.serviceItems
|
2010-07-28 13:15:39 +00:00
|
|
|
self.serviceManagerList.clear()
|
2010-03-05 12:06:19 +00:00
|
|
|
self.serviceItems = []
|
|
|
|
self.isNew = True
|
2009-06-10 15:54:46 +00:00
|
|
|
for item in tempServiceItems:
|
2010-04-27 16:27:57 +00:00
|
|
|
self.addServiceItem(
|
|
|
|
item[u'service_item'], False, item[u'expanded'])
|
2010-08-26 05:01:29 +00:00
|
|
|
# Set to False as items may have changed rendering
|
|
|
|
# does not impact the saved song so True may also be valid
|
2010-03-05 12:06:19 +00:00
|
|
|
self.parent.serviceChanged(False, self.serviceName)
|
2009-04-23 18:22:54 +00:00
|
|
|
|
2010-04-20 22:00:55 +00:00
|
|
|
def addServiceItem(self, item, rebuild=False, expand=True, replace=False):
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
2009-08-06 17:43:53 +00:00
|
|
|
Add a Service item to the list
|
|
|
|
|
|
|
|
``item``
|
|
|
|
Service Item to be added
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
2010-08-31 17:51:48 +00:00
|
|
|
log.debug(u'addServiceItem')
|
2010-05-27 14:41:47 +00:00
|
|
|
sitem = self.findServiceItem()[0]
|
2009-05-09 07:01:33 +00:00
|
|
|
item.render()
|
2010-04-20 22:00:55 +00:00
|
|
|
if replace:
|
2009-11-14 08:40:14 +00:00
|
|
|
item.merge(self.serviceItems[sitem][u'service_item'])
|
|
|
|
self.serviceItems[sitem][u'service_item'] = item
|
2009-10-11 07:30:16 +00:00
|
|
|
self.repaintServiceList(sitem + 1, 0)
|
2009-10-31 08:45:24 +00:00
|
|
|
self.parent.LiveController.replaceServiceManagerItem(item)
|
2009-10-29 09:18:26 +00:00
|
|
|
else:
|
2010-03-27 20:27:33 +00:00
|
|
|
#nothing selected for dnd
|
2010-03-14 07:56:39 +00:00
|
|
|
if self.droppos == 0:
|
2010-03-27 20:27:33 +00:00
|
|
|
if isinstance(item, list):
|
|
|
|
for inditem in item:
|
|
|
|
self.serviceItems.append({u'service_item': inditem,
|
|
|
|
u'order': len(self.serviceItems) + 1,
|
|
|
|
u'expanded':expand})
|
|
|
|
else:
|
|
|
|
self.serviceItems.append({u'service_item': item,
|
|
|
|
u'order': len(self.serviceItems) + 1,
|
|
|
|
u'expanded':expand})
|
2009-10-29 09:18:26 +00:00
|
|
|
self.repaintServiceList(len(self.serviceItems) + 1, 0)
|
|
|
|
else:
|
2010-03-14 07:56:39 +00:00
|
|
|
self.serviceItems.insert(self.droppos, {u'service_item': item,
|
|
|
|
u'order': self.droppos,
|
2010-03-07 19:22:54 +00:00
|
|
|
u'expanded':expand})
|
2010-03-14 07:56:39 +00:00
|
|
|
self.repaintServiceList(self.droppos, 0)
|
2010-02-22 06:14:44 +00:00
|
|
|
#if rebuilding list make sure live is fixed.
|
|
|
|
if rebuild:
|
|
|
|
self.parent.LiveController.replaceServiceManagerItem(item)
|
2010-03-14 07:56:39 +00:00
|
|
|
self.droppos = 0
|
2009-09-19 21:45:50 +00:00
|
|
|
self.parent.serviceChanged(False, self.serviceName)
|
2009-05-09 07:01:33 +00:00
|
|
|
|
2009-05-13 19:47:25 +00:00
|
|
|
def makePreview(self):
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
|
|
|
Send the current item to the Preview slide controller
|
|
|
|
"""
|
2009-05-14 18:00:36 +00:00
|
|
|
item, count = self.findServiceItem()
|
2010-05-07 18:29:17 +00:00
|
|
|
if self.serviceItems[item][u'service_item'].is_valid:
|
2010-05-06 16:49:12 +00:00
|
|
|
self.parent.PreviewController.addServiceManagerItem(
|
|
|
|
self.serviceItems[item][u'service_item'], count)
|
|
|
|
else:
|
|
|
|
QtGui.QMessageBox.critical(self,
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Missing Display Handler'),
|
2010-07-26 15:19:11 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Your item cannot be '
|
2010-07-31 02:06:44 +00:00
|
|
|
'displayed as there is no handler to display it'))
|
2009-05-13 19:47:25 +00:00
|
|
|
|
2010-03-16 20:22:28 +00:00
|
|
|
def getServiceItem(self):
|
|
|
|
"""
|
|
|
|
Send the current item to the Preview slide controller
|
|
|
|
"""
|
2010-05-27 14:41:47 +00:00
|
|
|
item = self.findServiceItem()[0]
|
2010-03-16 20:22:28 +00:00
|
|
|
if item == -1:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return self.serviceItems[item][u'service_item']
|
2010-02-26 12:18:01 +00:00
|
|
|
|
2009-05-12 21:06:35 +00:00
|
|
|
def makeLive(self):
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
|
|
|
Send the current item to the Live slide controller
|
|
|
|
"""
|
2009-05-14 18:00:36 +00:00
|
|
|
item, count = self.findServiceItem()
|
2010-05-07 18:29:17 +00:00
|
|
|
if self.serviceItems[item][u'service_item'].is_valid:
|
2010-05-04 20:01:45 +00:00
|
|
|
self.parent.LiveController.addServiceManagerItem(
|
|
|
|
self.serviceItems[item][u'service_item'], count)
|
|
|
|
if QtCore.QSettings().value(
|
|
|
|
self.parent.generalSettingsSection + u'/auto preview',
|
|
|
|
QtCore.QVariant(False)).toBool():
|
|
|
|
item += 1
|
|
|
|
if self.serviceItems and item < len(self.serviceItems) and \
|
|
|
|
self.serviceItems[item][u'service_item'].is_capable(
|
|
|
|
ItemCapabilities.AllowsPreview):
|
2010-05-24 22:37:20 +00:00
|
|
|
self.parent.PreviewController.addServiceManagerItem(
|
|
|
|
self.serviceItems[item][u'service_item'], 0)
|
2010-08-21 07:25:54 +00:00
|
|
|
self.parent.LiveController.PreviewListWidget.setFocus()
|
2010-05-04 20:01:45 +00:00
|
|
|
else:
|
|
|
|
QtGui.QMessageBox.critical(self,
|
2010-07-22 06:02:31 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Missing Display Handler'),
|
2010-07-26 15:19:11 +00:00
|
|
|
translate('OpenLP.ServiceManager', 'Your item cannot be '
|
2010-07-31 02:06:44 +00:00
|
|
|
'displayed as there is no handler to display it'))
|
2009-05-14 18:00:36 +00:00
|
|
|
|
2009-10-29 09:18:26 +00:00
|
|
|
def remoteEdit(self):
|
|
|
|
"""
|
|
|
|
Posts a remote edit message to a plugin to allow item to be edited.
|
|
|
|
"""
|
2010-05-27 14:41:47 +00:00
|
|
|
item = self.findServiceItem()[0]
|
2010-04-06 19:16:14 +00:00
|
|
|
if self.serviceItems[item][u'service_item']\
|
|
|
|
.is_capable(ItemCapabilities.AllowsEdit):
|
2009-11-15 07:24:30 +00:00
|
|
|
Receiver.send_message(u'%s_edit' %
|
2010-04-21 21:56:48 +00:00
|
|
|
self.serviceItems[item][u'service_item'].name.lower(), u'L:%s' %
|
2009-11-14 08:40:14 +00:00
|
|
|
self.serviceItems[item][u'service_item'].editId )
|
2009-10-29 09:18:26 +00:00
|
|
|
|
2009-05-14 18:00:36 +00:00
|
|
|
def findServiceItem(self):
|
2009-06-08 19:03:16 +00:00
|
|
|
"""
|
|
|
|
Finds a ServiceItem in the list
|
|
|
|
"""
|
2010-07-28 13:15:39 +00:00
|
|
|
items = self.serviceManagerList.selectedItems()
|
2009-05-14 18:00:36 +00:00
|
|
|
pos = 0
|
|
|
|
count = 0
|
|
|
|
for item in items:
|
2009-09-21 17:56:36 +00:00
|
|
|
parentitem = item.parent()
|
2009-06-19 18:41:38 +00:00
|
|
|
if parentitem is None:
|
2009-05-14 18:00:36 +00:00
|
|
|
pos = item.data(0, QtCore.Qt.UserRole).toInt()[0]
|
|
|
|
else:
|
|
|
|
pos = parentitem.data(0, QtCore.Qt.UserRole).toInt()[0]
|
|
|
|
count = item.data(0, QtCore.Qt.UserRole).toInt()[0]
|
2010-01-29 13:06:47 +00:00
|
|
|
#adjust for zero based arrays
|
2009-06-08 19:06:42 +00:00
|
|
|
pos = pos - 1
|
2009-05-14 18:00:36 +00:00
|
|
|
return pos, count
|
2009-05-12 21:06:35 +00:00
|
|
|
|
2009-05-09 07:01:33 +00:00
|
|
|
def dragEnterEvent(self, event):
|
|
|
|
"""
|
|
|
|
Accept Drag events
|
2009-08-06 17:43:53 +00:00
|
|
|
|
|
|
|
``event``
|
|
|
|
Handle of the event pint passed
|
2009-05-09 07:01:33 +00:00
|
|
|
"""
|
|
|
|
event.accept()
|
|
|
|
|
|
|
|
def dropEvent(self, event):
|
|
|
|
"""
|
2009-08-06 17:43:53 +00:00
|
|
|
Receive drop event and trigger an internal event to get the
|
|
|
|
plugins to build and push the correct service item
|
|
|
|
The drag event payload carries the plugin name
|
|
|
|
|
|
|
|
``event``
|
|
|
|
Handle of the event pint passed
|
2009-05-09 07:01:33 +00:00
|
|
|
"""
|
2009-05-22 18:30:25 +00:00
|
|
|
link = event.mimeData()
|
2009-05-09 07:01:33 +00:00
|
|
|
if link.hasText():
|
|
|
|
plugin = event.mimeData().text()
|
2010-07-28 13:15:39 +00:00
|
|
|
item = self.serviceManagerList.itemAt(event.pos())
|
2010-05-01 13:05:17 +00:00
|
|
|
#ServiceManager started the drag and drop
|
2009-10-11 09:31:27 +00:00
|
|
|
if plugin == u'ServiceManager':
|
2010-04-30 21:00:17 +00:00
|
|
|
startpos, startCount = self.findServiceItem()
|
2010-02-27 00:11:26 +00:00
|
|
|
if item is None:
|
2009-10-11 09:31:27 +00:00
|
|
|
endpos = len(self.serviceItems)
|
|
|
|
else:
|
2010-03-14 17:05:50 +00:00
|
|
|
endpos = self._getParentItemData(item) - 1
|
2009-10-11 09:31:27 +00:00
|
|
|
serviceItem = self.serviceItems[startpos]
|
|
|
|
self.serviceItems.remove(serviceItem)
|
2010-06-17 23:17:16 +00:00
|
|
|
self.serviceItems.insert(endpos, serviceItem)
|
2009-10-11 09:31:27 +00:00
|
|
|
self.repaintServiceList(endpos, startCount)
|
|
|
|
else:
|
2010-05-01 13:05:17 +00:00
|
|
|
#we are not over anything so drop
|
|
|
|
replace = False
|
2010-06-09 17:09:32 +00:00
|
|
|
if item is None:
|
2010-03-14 07:56:39 +00:00
|
|
|
self.droppos = len(self.serviceItems)
|
|
|
|
else:
|
2010-05-01 13:05:17 +00:00
|
|
|
#we are over somthing so lets investigate
|
|
|
|
pos = self._getParentItemData(item) - 1
|
|
|
|
serviceItem = self.serviceItems[pos]
|
2010-05-24 22:37:20 +00:00
|
|
|
if (plugin == serviceItem[u'service_item'].name and
|
|
|
|
serviceItem[u'service_item'].is_capable(
|
|
|
|
ItemCapabilities.AllowsAdditions)):
|
|
|
|
action = self.dndMenu.exec_(QtGui.QCursor.pos())
|
|
|
|
#New action required
|
|
|
|
if action == self.newAction:
|
|
|
|
self.droppos = self._getParentItemData(item)
|
|
|
|
#Append to existing action
|
|
|
|
if action == self.addToAction:
|
|
|
|
self.droppos = self._getParentItemData(item)
|
|
|
|
item.setSelected(True)
|
|
|
|
replace = True
|
2010-05-01 13:05:17 +00:00
|
|
|
else:
|
|
|
|
self.droppos = self._getParentItemData(item)
|
|
|
|
Receiver.send_message(u'%s_add_service_item' % plugin, replace)
|
2009-03-04 21:55:24 +00:00
|
|
|
|
2009-04-23 18:22:54 +00:00
|
|
|
def updateThemeList(self, theme_list):
|
2009-05-09 07:01:33 +00:00
|
|
|
"""
|
|
|
|
Called from ThemeManager when the Themes have changed
|
2009-08-06 17:43:53 +00:00
|
|
|
|
|
|
|
``theme_list``
|
|
|
|
A list of current themes to be displayed
|
2009-05-09 07:01:33 +00:00
|
|
|
"""
|
2010-07-28 13:15:39 +00:00
|
|
|
self.themeComboBox.clear()
|
2010-03-03 17:48:37 +00:00
|
|
|
self.themeMenu.clear()
|
2010-07-28 13:15:39 +00:00
|
|
|
self.themeComboBox.addItem(u'')
|
2009-04-23 18:22:54 +00:00
|
|
|
for theme in theme_list:
|
2010-07-28 13:15:39 +00:00
|
|
|
self.themeComboBox.addItem(theme)
|
|
|
|
action = context_menu_action(self.serviceManagerList, None, theme,
|
|
|
|
self.onThemeChangeAction)
|
2010-03-03 17:48:37 +00:00
|
|
|
self.themeMenu.addAction(action)
|
2010-07-28 13:15:39 +00:00
|
|
|
index = self.themeComboBox.findText(self.service_theme,
|
2009-09-10 17:03:17 +00:00
|
|
|
QtCore.Qt.MatchExactly)
|
2009-05-22 18:30:25 +00:00
|
|
|
# Not Found
|
2010-07-28 13:15:39 +00:00
|
|
|
if index == -1:
|
|
|
|
index = 0
|
2009-05-18 19:04:25 +00:00
|
|
|
self.service_theme = u''
|
2010-07-28 13:15:39 +00:00
|
|
|
self.themeComboBox.setCurrentIndex(index)
|
2009-06-19 18:41:38 +00:00
|
|
|
self.parent.RenderManager.set_service_theme(self.service_theme)
|
2009-06-26 16:39:16 +00:00
|
|
|
self.regenerateServiceItems()
|
2009-10-25 16:26:03 +00:00
|
|
|
|
|
|
|
def onThemeChangeAction(self):
|
|
|
|
theme = unicode(self.sender().text())
|
2010-05-27 14:41:47 +00:00
|
|
|
item = self.findServiceItem()[0]
|
2009-11-14 08:40:14 +00:00
|
|
|
self.serviceItems[item][u'service_item'].theme = theme
|
2010-01-24 13:58:39 +00:00
|
|
|
self.regenerateServiceItems()
|
2010-03-14 17:05:50 +00:00
|
|
|
|
|
|
|
def _getParentItemData(self, item):
|
|
|
|
parentitem = item.parent()
|
|
|
|
if parentitem is None:
|
|
|
|
return item.data(0, QtCore.Qt.UserRole).toInt()[0]
|
|
|
|
else:
|
|
|
|
return parentitem.data(0, QtCore.Qt.UserRole).toInt()[0]
|
2010-05-04 20:01:45 +00:00
|
|
|
|
2010-04-26 21:29:40 +00:00
|
|
|
def listRequest(self, message=None):
|
|
|
|
data = []
|
2010-05-27 14:41:47 +00:00
|
|
|
curindex = self.findServiceItem()[0]
|
2010-04-28 22:08:37 +00:00
|
|
|
if curindex >= 0 and curindex < len(self.serviceItems):
|
|
|
|
curitem = self.serviceItems[curindex]
|
|
|
|
else:
|
|
|
|
curitem = None
|
2010-04-26 21:29:40 +00:00
|
|
|
for item in self.serviceItems:
|
|
|
|
service_item = item[u'service_item']
|
2010-04-28 22:08:37 +00:00
|
|
|
data_item = {}
|
|
|
|
data_item[u'title'] = unicode(service_item.title)
|
|
|
|
data_item[u'plugin'] = unicode(service_item.name)
|
|
|
|
data_item[u'notes'] = unicode(service_item.notes)
|
|
|
|
data_item[u'selected'] = (item == curitem)
|
|
|
|
data.append(data_item)
|
2010-07-26 15:19:11 +00:00
|
|
|
Receiver.send_message(u'servicemanager_list_response', data)
|