forked from openlp/openlp
[merge] merge with trunk r1742
This commit is contained in:
commit
a3ff14d337
@ -485,7 +485,8 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
"""
|
||||
pass
|
||||
|
||||
def generateSlideData(self, serviceItem, item=None, xmlVersion=False):
|
||||
def generateSlideData(self, serviceItem, item=None, xmlVersion=False,
|
||||
remote=False):
|
||||
raise NotImplementedError(u'MediaManagerItem.generateSlideData needs '
|
||||
u'to be defined by the plugin')
|
||||
|
||||
@ -539,12 +540,12 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
else:
|
||||
self.goLive()
|
||||
|
||||
def goLive(self, item_id=None):
|
||||
def goLive(self, item_id=None, remote=False):
|
||||
log.debug(u'%s Live requested', self.plugin.name)
|
||||
item = None
|
||||
if item_id:
|
||||
item = self.createItemFromId(item_id)
|
||||
serviceItem = self.buildServiceItem(item)
|
||||
serviceItem = self.buildServiceItem(item, remote=remote)
|
||||
if serviceItem:
|
||||
if not item_id:
|
||||
serviceItem.from_plugin = True
|
||||
@ -574,8 +575,8 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
for item in items:
|
||||
self.addToService(item)
|
||||
|
||||
def addToService(self, item=None, replace=None):
|
||||
serviceItem = self.buildServiceItem(item, True)
|
||||
def addToService(self, item=None, replace=None, remote=False):
|
||||
serviceItem = self.buildServiceItem(item, True, remote=remote)
|
||||
if serviceItem:
|
||||
serviceItem.from_plugin = False
|
||||
self.plugin.serviceManager.addServiceItem(serviceItem,
|
||||
@ -608,13 +609,13 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
unicode(translate('OpenLP.MediaManagerItem',
|
||||
'You must select a %s service item.')) % self.title)
|
||||
|
||||
def buildServiceItem(self, item=None, xmlVersion=False):
|
||||
def buildServiceItem(self, item=None, xmlVersion=False, remote=False):
|
||||
"""
|
||||
Common method for generating a service item
|
||||
"""
|
||||
serviceItem = ServiceItem(self.plugin)
|
||||
serviceItem.add_icon(self.plugin.icon_path)
|
||||
if self.generateSlideData(serviceItem, item, xmlVersion):
|
||||
if self.generateSlideData(serviceItem, item, xmlVersion, remote):
|
||||
return serviceItem
|
||||
else:
|
||||
return None
|
||||
|
@ -28,7 +28,7 @@
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
import urllib
|
||||
import urllib, urllib2
|
||||
from tempfile import gettempdir
|
||||
from ConfigParser import SafeConfigParser
|
||||
|
||||
@ -60,8 +60,11 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
||||
files = self.webAccess.read()
|
||||
self.config.readfp(io.BytesIO(files))
|
||||
self.updateScreenListCombo()
|
||||
self.downloadCanceled = False
|
||||
self.downloading = unicode(translate('OpenLP.FirstTimeWizard',
|
||||
'Downloading %s...'))
|
||||
QtCore.QObject.connect(self.cancelButton,QtCore.SIGNAL('clicked()'),
|
||||
self.onCancelButtonClicked)
|
||||
QtCore.QObject.connect(self,
|
||||
QtCore.SIGNAL(u'currentIdChanged(int)'), self.onCurrentIdChanged)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
@ -120,7 +123,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
||||
title = self.config.get(u'theme_%s' % theme, u'title')
|
||||
filename = self.config.get(u'theme_%s' % theme, u'filename')
|
||||
screenshot = self.config.get(u'theme_%s' % theme, u'screenshot')
|
||||
urllib.urlretrieve(u'%s/%s' % (self.web, screenshot),
|
||||
urllib.urlretrieve(u'%s%s' % (self.web, screenshot),
|
||||
os.path.join(gettempdir(), u'openlp', screenshot))
|
||||
item = QtGui.QListWidgetItem(title, self.themesListWidget)
|
||||
item.setData(QtCore.Qt.UserRole,
|
||||
@ -152,15 +155,16 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
||||
"""
|
||||
Detects Page changes and updates as approprate.
|
||||
"""
|
||||
if pageId == FirstTimePage.Defaults:
|
||||
if pageId == FirstTimePage.Plugins:
|
||||
# Check if this is a re-run of the wizard.
|
||||
self.has_run_wizard = QtCore.QSettings().value(
|
||||
u'general/has run wizard', QtCore.QVariant(False)).toBool()
|
||||
elif pageId == FirstTimePage.Defaults:
|
||||
self.themeComboBox.clear()
|
||||
for iter in xrange(self.themesListWidget.count()):
|
||||
item = self.themesListWidget.item(iter)
|
||||
if item.checkState() == QtCore.Qt.Checked:
|
||||
self.themeComboBox.addItem(item.text())
|
||||
# Check if this is a re-run of the wizard.
|
||||
self.has_run_wizard = QtCore.QSettings().value(
|
||||
u'general/has run wizard', QtCore.QVariant(False)).toBool()
|
||||
if self.has_run_wizard:
|
||||
# Add any existing themes to list.
|
||||
for theme in self.parent().themeManagerContents.getThemes():
|
||||
@ -192,6 +196,33 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
||||
self.displayComboBox.addItems(self.screens.get_screen_list())
|
||||
self.displayComboBox.setCurrentIndex(self.displayComboBox.count() - 1)
|
||||
|
||||
def onCancelButtonClicked(self):
|
||||
self.downloadCanceled = True
|
||||
Receiver.send_message(u'cursor_normal')
|
||||
|
||||
def urlGetFile(self, url, fpath):
|
||||
""""
|
||||
Download a file given a URL. The file is retrieved in chunks, giving
|
||||
the ability to cancel the download at any point.
|
||||
"""
|
||||
block_count = 0
|
||||
block_size = 4096
|
||||
urlfile = urllib2.urlopen(url)
|
||||
filesize = urlfile.headers["Content-Length"]
|
||||
filename = open(fpath, "wb")
|
||||
# Download until finished or canceled.
|
||||
while not self.downloadCanceled:
|
||||
data = urlfile.read(block_size)
|
||||
if not data:
|
||||
break
|
||||
filename.write(data)
|
||||
block_count += 1
|
||||
self._downloadProgress(block_count, block_size, filesize)
|
||||
filename.close()
|
||||
# Delete file if canceled, it may be a partial file.
|
||||
if self.downloadCanceled:
|
||||
os.remove(fpath)
|
||||
|
||||
def _getFileSize(self, url):
|
||||
site = urllib.urlopen(url)
|
||||
meta = site.info()
|
||||
@ -201,7 +232,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
||||
increment = (count * block_size) - self.previous_size
|
||||
self._incrementProgressBar(None, increment)
|
||||
self.previous_size = count * block_size
|
||||
|
||||
|
||||
def _incrementProgressBar(self, status_text, increment=1):
|
||||
"""
|
||||
Update the wizard progress page.
|
||||
@ -309,42 +340,42 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
||||
self._setPluginStatus(self.customCheckBox, u'custom/status')
|
||||
self._setPluginStatus(self.songUsageCheckBox, u'songusage/status')
|
||||
self._setPluginStatus(self.alertCheckBox, u'alerts/status')
|
||||
# Build directories for downloads
|
||||
songs_destination = os.path.join(unicode(gettempdir()), u'openlp')
|
||||
bibles_destination = AppLocation.get_section_data_path(u'bibles')
|
||||
themes_destination = AppLocation.get_section_data_path(u'themes')
|
||||
# Download songs
|
||||
for i in xrange(self.songsListWidget.count()):
|
||||
item = self.songsListWidget.item(i)
|
||||
if item.checkState() == QtCore.Qt.Checked:
|
||||
filename = item.data(QtCore.Qt.UserRole).toString()
|
||||
self._incrementProgressBar(self.downloading % filename, 0)
|
||||
self.previous_size = 0
|
||||
destination = os.path.join(songs_destination, unicode(filename))
|
||||
urllib.urlretrieve(u'%s%s' % (self.web, filename), destination,
|
||||
self._downloadProgress)
|
||||
# Download Bibles
|
||||
bibles_iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget)
|
||||
while bibles_iterator.value():
|
||||
item = bibles_iterator.value()
|
||||
if item.parent() and item.checkState(0) == QtCore.Qt.Checked:
|
||||
bible = unicode(item.data(0, QtCore.Qt.UserRole).toString())
|
||||
self._incrementProgressBar(self.downloading % bible, 0)
|
||||
self.previous_size = 0
|
||||
urllib.urlretrieve(u'%s%s' % (self.web, bible),
|
||||
os.path.join(bibles_destination, bible),
|
||||
self._downloadProgress)
|
||||
bibles_iterator += 1
|
||||
# Download themes
|
||||
for i in xrange(self.themesListWidget.count()):
|
||||
item = self.themesListWidget.item(i)
|
||||
if item.checkState() == QtCore.Qt.Checked:
|
||||
theme = unicode(item.data(QtCore.Qt.UserRole).toString())
|
||||
self._incrementProgressBar(self.downloading % theme, 0)
|
||||
self.previous_size = 0
|
||||
urllib.urlretrieve(u'%s%s' % (self.web, theme),
|
||||
os.path.join(themes_destination, theme),
|
||||
self._downloadProgress)
|
||||
if self.webAccess:
|
||||
# Build directories for downloads
|
||||
songs_destination = os.path.join(unicode(gettempdir()), u'openlp')
|
||||
bibles_destination = AppLocation.get_section_data_path(u'bibles')
|
||||
themes_destination = AppLocation.get_section_data_path(u'themes')
|
||||
# Download songs
|
||||
for i in xrange(self.songsListWidget.count()):
|
||||
item = self.songsListWidget.item(i)
|
||||
if item.checkState() == QtCore.Qt.Checked:
|
||||
filename = item.data(QtCore.Qt.UserRole).toString()
|
||||
self._incrementProgressBar(self.downloading % filename, 0)
|
||||
self.previous_size = 0
|
||||
destination = os.path.join(songs_destination,
|
||||
unicode(filename))
|
||||
self.urlGetFile(u'%s%s' % (self.web, filename), destination)
|
||||
# Download Bibles
|
||||
bibles_iterator = QtGui.QTreeWidgetItemIterator(
|
||||
self.biblesTreeWidget)
|
||||
while bibles_iterator.value():
|
||||
item = bibles_iterator.value()
|
||||
if item.parent() and item.checkState(0) == QtCore.Qt.Checked:
|
||||
bible = unicode(item.data(0, QtCore.Qt.UserRole).toString())
|
||||
self._incrementProgressBar(self.downloading % bible, 0)
|
||||
self.previous_size = 0
|
||||
self.urlGetFile(u'%s%s' % (self.web, bible),
|
||||
os.path.join(bibles_destination, bible))
|
||||
bibles_iterator += 1
|
||||
# Download themes
|
||||
for i in xrange(self.themesListWidget.count()):
|
||||
item = self.themesListWidget.item(i)
|
||||
if item.checkState() == QtCore.Qt.Checked:
|
||||
theme = unicode(item.data(QtCore.Qt.UserRole).toString())
|
||||
self._incrementProgressBar(self.downloading % theme, 0)
|
||||
self.previous_size = 0
|
||||
self.urlGetFile(u'%s%s' % (self.web, theme),
|
||||
os.path.join(themes_destination, theme))
|
||||
# Set Default Display
|
||||
if self.displayComboBox.currentIndex() != -1:
|
||||
QtCore.QSettings().setValue(u'General/monitor',
|
||||
|
@ -189,9 +189,7 @@ class Ui_FirstTimeWizard(object):
|
||||
self.progressBar.setObjectName(u'progressBar')
|
||||
self.progressLayout.addWidget(self.progressBar)
|
||||
FirstTimeWizard.setPage(FirstTimePage.Progress, self.progressPage)
|
||||
|
||||
self.retranslateUi(FirstTimeWizard)
|
||||
QtCore.QMetaObject.connectSlotsByName(FirstTimeWizard)
|
||||
|
||||
def retranslateUi(self, FirstTimeWizard):
|
||||
FirstTimeWizard.setWindowTitle(translate(
|
||||
|
@ -784,6 +784,8 @@ class SlideController(QtGui.QWidget):
|
||||
self.onBlankDisplay(True)
|
||||
else:
|
||||
Receiver.send_message(u'maindisplay_show')
|
||||
else:
|
||||
Receiver.send_message(u'maindisplay_hide', HideMode.Screen)
|
||||
|
||||
def onSlideBlank(self):
|
||||
"""
|
||||
|
@ -788,7 +788,8 @@ class BibleMediaItem(MediaManagerItem):
|
||||
items.append(bible_verse)
|
||||
return items
|
||||
|
||||
def generateSlideData(self, service_item, item=None, xmlVersion=False):
|
||||
def generateSlideData(self, service_item, item=None, xmlVersion=False,
|
||||
remote=False):
|
||||
"""
|
||||
Generates and formats the slides for the service item as well as the
|
||||
service item's title.
|
||||
|
@ -222,7 +222,8 @@ class CustomMediaItem(MediaManagerItem):
|
||||
def onFocus(self):
|
||||
self.searchTextEdit.setFocus()
|
||||
|
||||
def generateSlideData(self, service_item, item=None, xmlVersion=False):
|
||||
def generateSlideData(self, service_item, item=None, xmlVersion=False,
|
||||
remote=False):
|
||||
raw_footer = []
|
||||
slide = None
|
||||
theme = None
|
||||
|
@ -139,7 +139,8 @@ class ImageMediaItem(MediaManagerItem):
|
||||
if not initialLoad:
|
||||
self.plugin.formparent.finishedProgressBar()
|
||||
|
||||
def generateSlideData(self, service_item, item=None, xmlVersion=False):
|
||||
def generateSlideData(self, service_item, item=None, xmlVersion=False,
|
||||
remote=False):
|
||||
background = QtGui.QColor(QtCore.QSettings().value(self.settingsSection
|
||||
+ u'/background color', QtCore.QVariant(u'#000000')))
|
||||
if item:
|
||||
@ -166,11 +167,12 @@ class ImageMediaItem(MediaManagerItem):
|
||||
items.remove(item)
|
||||
# We cannot continue, as all images do not exist.
|
||||
if not items:
|
||||
critical_error_message_box(
|
||||
translate('ImagePlugin.MediaItem', 'Missing Image(s)'),
|
||||
unicode(translate('ImagePlugin.MediaItem',
|
||||
'The following image(s) no longer exist: %s')) %
|
||||
u'\n'.join(missing_items_filenames))
|
||||
if not remote:
|
||||
critical_error_message_box(
|
||||
translate('ImagePlugin.MediaItem', 'Missing Image(s)'),
|
||||
unicode(translate('ImagePlugin.MediaItem',
|
||||
'The following image(s) no longer exist: %s')) %
|
||||
u'\n'.join(missing_items_filenames))
|
||||
return False
|
||||
# We have missing as well as existing images. We ask what to do.
|
||||
elif missing_items and QtGui.QMessageBox.question(self,
|
||||
|
@ -129,18 +129,20 @@ class MediaMediaItem(MediaManagerItem):
|
||||
'There was a problem replacing your background, '
|
||||
'the media file "%s" no longer exists.')) % filename)
|
||||
|
||||
def generateSlideData(self, service_item, item=None, xmlVersion=False):
|
||||
def generateSlideData(self, service_item, item=None, xmlVersion=False,
|
||||
remote=False):
|
||||
if item is None:
|
||||
item = self.listView.currentItem()
|
||||
if item is None:
|
||||
return False
|
||||
filename = unicode(item.data(QtCore.Qt.UserRole).toString())
|
||||
if not os.path.exists(filename):
|
||||
# File is no longer present
|
||||
critical_error_message_box(
|
||||
translate('MediaPlugin.MediaItem', 'Missing Media File'),
|
||||
unicode(translate('MediaPlugin.MediaItem',
|
||||
'The file %s no longer exists.')) % filename)
|
||||
if not remote:
|
||||
# File is no longer present
|
||||
critical_error_message_box(
|
||||
translate('MediaPlugin.MediaItem', 'Missing Media File'),
|
||||
unicode(translate('MediaPlugin.MediaItem',
|
||||
'The file %s no longer exists.')) % filename)
|
||||
return False
|
||||
self.mediaObject.stop()
|
||||
self.mediaObject.clearQueue()
|
||||
|
@ -233,7 +233,8 @@ class PresentationMediaItem(MediaManagerItem):
|
||||
SettingsManager.set_list(self.settingsSection,
|
||||
u'presentations', self.getFileList())
|
||||
|
||||
def generateSlideData(self, service_item, item=None, xmlVersion=False):
|
||||
def generateSlideData(self, service_item, item=None, xmlVersion=False,
|
||||
remote=False):
|
||||
"""
|
||||
Load the relevant information for displaying the presentation
|
||||
in the slidecontroller. In the case of powerpoints, an image
|
||||
@ -275,12 +276,13 @@ class PresentationMediaItem(MediaManagerItem):
|
||||
return True
|
||||
else:
|
||||
# File is no longer present
|
||||
critical_error_message_box(
|
||||
translate('PresentationPlugin.MediaItem',
|
||||
'Missing Presentation'),
|
||||
unicode(translate('PresentationPlugin.MediaItem',
|
||||
'The Presentation %s is incomplete,'
|
||||
' please reload.')) % filename)
|
||||
if not remote:
|
||||
critical_error_message_box(
|
||||
translate('PresentationPlugin.MediaItem',
|
||||
'Missing Presentation'),
|
||||
unicode(translate('PresentationPlugin.MediaItem',
|
||||
'The Presentation %s is incomplete,'
|
||||
' please reload.')) % filename)
|
||||
return False
|
||||
else:
|
||||
# File is no longer present
|
||||
|
@ -528,7 +528,7 @@ class HttpConnection(object):
|
||||
id = json.loads(self.url_params[u'data'][0])[u'request'][u'id']
|
||||
plugin = self.parent.plugin.pluginManager.get_plugin_by_name(type)
|
||||
if plugin.status == PluginStatus.Active and plugin.mediaItem:
|
||||
plugin.mediaItem.goLive(id)
|
||||
plugin.mediaItem.goLive(id, remote=True)
|
||||
|
||||
def add_to_service(self, type):
|
||||
"""
|
||||
@ -538,7 +538,7 @@ class HttpConnection(object):
|
||||
plugin = self.parent.plugin.pluginManager.get_plugin_by_name(type)
|
||||
if plugin.status == PluginStatus.Active and plugin.mediaItem:
|
||||
item_id = plugin.mediaItem.createItemFromId(id)
|
||||
plugin.mediaItem.addToService(item_id)
|
||||
plugin.mediaItem.addToService(item_id, remote=True)
|
||||
|
||||
def send_response(self, response):
|
||||
http = u'HTTP/1.1 %s\r\n' % response.code
|
||||
|
@ -411,7 +411,8 @@ class SongMediaItem(MediaManagerItem):
|
||||
self.plugin.manager.save_object(new_song)
|
||||
self.onSongListLoad()
|
||||
|
||||
def generateSlideData(self, service_item, item=None, xmlVersion=False):
|
||||
def generateSlideData(self, service_item, item=None, xmlVersion=False,
|
||||
remote=False):
|
||||
log.debug(u'generateSlideData (%s:%s)' % (service_item, item))
|
||||
item_id = self._getIdOfItemToGenerate(item, self.remoteSong)
|
||||
service_item.add_capability(ItemCapabilities.CanEdit)
|
||||
|
Loading…
Reference in New Issue
Block a user