forked from openlp/openlp
HEAD
This commit is contained in:
commit
75fda95339
@ -28,7 +28,7 @@
|
|||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import urllib
|
import urllib, urllib2
|
||||||
from tempfile import gettempdir
|
from tempfile import gettempdir
|
||||||
from ConfigParser import SafeConfigParser
|
from ConfigParser import SafeConfigParser
|
||||||
|
|
||||||
@ -60,8 +60,11 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
|||||||
files = self.webAccess.read()
|
files = self.webAccess.read()
|
||||||
self.config.readfp(io.BytesIO(files))
|
self.config.readfp(io.BytesIO(files))
|
||||||
self.updateScreenListCombo()
|
self.updateScreenListCombo()
|
||||||
|
self.downloadCanceled = False
|
||||||
self.downloading = unicode(translate('OpenLP.FirstTimeWizard',
|
self.downloading = unicode(translate('OpenLP.FirstTimeWizard',
|
||||||
'Downloading %s...'))
|
'Downloading %s...'))
|
||||||
|
QtCore.QObject.connect(self.cancelButton,QtCore.SIGNAL('clicked()'),
|
||||||
|
self.onCancelButtonClicked)
|
||||||
QtCore.QObject.connect(self,
|
QtCore.QObject.connect(self,
|
||||||
QtCore.SIGNAL(u'currentIdChanged(int)'), self.onCurrentIdChanged)
|
QtCore.SIGNAL(u'currentIdChanged(int)'), self.onCurrentIdChanged)
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
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')
|
title = self.config.get(u'theme_%s' % theme, u'title')
|
||||||
filename = self.config.get(u'theme_%s' % theme, u'filename')
|
filename = self.config.get(u'theme_%s' % theme, u'filename')
|
||||||
screenshot = self.config.get(u'theme_%s' % theme, u'screenshot')
|
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))
|
os.path.join(gettempdir(), u'openlp', screenshot))
|
||||||
item = QtGui.QListWidgetItem(title, self.themesListWidget)
|
item = QtGui.QListWidgetItem(title, self.themesListWidget)
|
||||||
item.setData(QtCore.Qt.UserRole,
|
item.setData(QtCore.Qt.UserRole,
|
||||||
@ -152,15 +155,16 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
|||||||
"""
|
"""
|
||||||
Detects Page changes and updates as approprate.
|
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()
|
self.themeComboBox.clear()
|
||||||
for iter in xrange(self.themesListWidget.count()):
|
for iter in xrange(self.themesListWidget.count()):
|
||||||
item = self.themesListWidget.item(iter)
|
item = self.themesListWidget.item(iter)
|
||||||
if item.checkState() == QtCore.Qt.Checked:
|
if item.checkState() == QtCore.Qt.Checked:
|
||||||
self.themeComboBox.addItem(item.text())
|
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:
|
if self.has_run_wizard:
|
||||||
# Add any existing themes to list.
|
# Add any existing themes to list.
|
||||||
for theme in self.parent().themeManagerContents.getThemes():
|
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.addItems(self.screens.get_screen_list())
|
||||||
self.displayComboBox.setCurrentIndex(self.displayComboBox.count() - 1)
|
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):
|
def _getFileSize(self, url):
|
||||||
site = urllib.urlopen(url)
|
site = urllib.urlopen(url)
|
||||||
meta = site.info()
|
meta = site.info()
|
||||||
@ -309,42 +340,42 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
|||||||
self._setPluginStatus(self.customCheckBox, u'custom/status')
|
self._setPluginStatus(self.customCheckBox, u'custom/status')
|
||||||
self._setPluginStatus(self.songUsageCheckBox, u'songusage/status')
|
self._setPluginStatus(self.songUsageCheckBox, u'songusage/status')
|
||||||
self._setPluginStatus(self.alertCheckBox, u'alerts/status')
|
self._setPluginStatus(self.alertCheckBox, u'alerts/status')
|
||||||
# Build directories for downloads
|
if self.webAccess:
|
||||||
songs_destination = os.path.join(unicode(gettempdir()), u'openlp')
|
# Build directories for downloads
|
||||||
bibles_destination = AppLocation.get_section_data_path(u'bibles')
|
songs_destination = os.path.join(unicode(gettempdir()), u'openlp')
|
||||||
themes_destination = AppLocation.get_section_data_path(u'themes')
|
bibles_destination = AppLocation.get_section_data_path(u'bibles')
|
||||||
# Download songs
|
themes_destination = AppLocation.get_section_data_path(u'themes')
|
||||||
for i in xrange(self.songsListWidget.count()):
|
# Download songs
|
||||||
item = self.songsListWidget.item(i)
|
for i in xrange(self.songsListWidget.count()):
|
||||||
if item.checkState() == QtCore.Qt.Checked:
|
item = self.songsListWidget.item(i)
|
||||||
filename = item.data(QtCore.Qt.UserRole).toString()
|
if item.checkState() == QtCore.Qt.Checked:
|
||||||
self._incrementProgressBar(self.downloading % filename, 0)
|
filename = item.data(QtCore.Qt.UserRole).toString()
|
||||||
self.previous_size = 0
|
self._incrementProgressBar(self.downloading % filename, 0)
|
||||||
destination = os.path.join(songs_destination, unicode(filename))
|
self.previous_size = 0
|
||||||
urllib.urlretrieve(u'%s%s' % (self.web, filename), destination,
|
destination = os.path.join(songs_destination,
|
||||||
self._downloadProgress)
|
unicode(filename))
|
||||||
# Download Bibles
|
self.urlGetFile(u'%s%s' % (self.web, filename), destination)
|
||||||
bibles_iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget)
|
# Download Bibles
|
||||||
while bibles_iterator.value():
|
bibles_iterator = QtGui.QTreeWidgetItemIterator(
|
||||||
item = bibles_iterator.value()
|
self.biblesTreeWidget)
|
||||||
if item.parent() and item.checkState(0) == QtCore.Qt.Checked:
|
while bibles_iterator.value():
|
||||||
bible = unicode(item.data(0, QtCore.Qt.UserRole).toString())
|
item = bibles_iterator.value()
|
||||||
self._incrementProgressBar(self.downloading % bible, 0)
|
if item.parent() and item.checkState(0) == QtCore.Qt.Checked:
|
||||||
self.previous_size = 0
|
bible = unicode(item.data(0, QtCore.Qt.UserRole).toString())
|
||||||
urllib.urlretrieve(u'%s%s' % (self.web, bible),
|
self._incrementProgressBar(self.downloading % bible, 0)
|
||||||
os.path.join(bibles_destination, bible),
|
self.previous_size = 0
|
||||||
self._downloadProgress)
|
self.urlGetFile(u'%s%s' % (self.web, bible),
|
||||||
bibles_iterator += 1
|
os.path.join(bibles_destination, bible))
|
||||||
# Download themes
|
bibles_iterator += 1
|
||||||
for i in xrange(self.themesListWidget.count()):
|
# Download themes
|
||||||
item = self.themesListWidget.item(i)
|
for i in xrange(self.themesListWidget.count()):
|
||||||
if item.checkState() == QtCore.Qt.Checked:
|
item = self.themesListWidget.item(i)
|
||||||
theme = unicode(item.data(QtCore.Qt.UserRole).toString())
|
if item.checkState() == QtCore.Qt.Checked:
|
||||||
self._incrementProgressBar(self.downloading % theme, 0)
|
theme = unicode(item.data(QtCore.Qt.UserRole).toString())
|
||||||
self.previous_size = 0
|
self._incrementProgressBar(self.downloading % theme, 0)
|
||||||
urllib.urlretrieve(u'%s%s' % (self.web, theme),
|
self.previous_size = 0
|
||||||
os.path.join(themes_destination, theme),
|
self.urlGetFile(u'%s%s' % (self.web, theme),
|
||||||
self._downloadProgress)
|
os.path.join(themes_destination, theme))
|
||||||
# Set Default Display
|
# Set Default Display
|
||||||
if self.displayComboBox.currentIndex() != -1:
|
if self.displayComboBox.currentIndex() != -1:
|
||||||
QtCore.QSettings().setValue(u'General/monitor',
|
QtCore.QSettings().setValue(u'General/monitor',
|
||||||
|
@ -189,9 +189,7 @@ class Ui_FirstTimeWizard(object):
|
|||||||
self.progressBar.setObjectName(u'progressBar')
|
self.progressBar.setObjectName(u'progressBar')
|
||||||
self.progressLayout.addWidget(self.progressBar)
|
self.progressLayout.addWidget(self.progressBar)
|
||||||
FirstTimeWizard.setPage(FirstTimePage.Progress, self.progressPage)
|
FirstTimeWizard.setPage(FirstTimePage.Progress, self.progressPage)
|
||||||
|
|
||||||
self.retranslateUi(FirstTimeWizard)
|
self.retranslateUi(FirstTimeWizard)
|
||||||
QtCore.QMetaObject.connectSlotsByName(FirstTimeWizard)
|
|
||||||
|
|
||||||
def retranslateUi(self, FirstTimeWizard):
|
def retranslateUi(self, FirstTimeWizard):
|
||||||
FirstTimeWizard.setWindowTitle(translate(
|
FirstTimeWizard.setWindowTitle(translate(
|
||||||
|
@ -1044,9 +1044,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
for section_key in keys:
|
for section_key in keys:
|
||||||
section, key = section_key.split(u'/')
|
section, key = section_key.split(u'/')
|
||||||
key_value = settings.value(section_key)
|
key_value = settings.value(section_key)
|
||||||
# Change the service section to servicemanager.
|
|
||||||
if section == u'service':
|
|
||||||
section_key = u'servicemanager/' + key
|
|
||||||
export_settings.setValue(section_key, key_value)
|
export_settings.setValue(section_key, key_value)
|
||||||
export_settings.sync()
|
export_settings.sync()
|
||||||
# Temp CONF file has been written. Blanks in keys are now '%20'.
|
# Temp CONF file has been written. Blanks in keys are now '%20'.
|
||||||
@ -1294,6 +1291,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
"""
|
"""
|
||||||
log.debug(u'Loading QSettings')
|
log.debug(u'Loading QSettings')
|
||||||
settings = QtCore.QSettings()
|
settings = QtCore.QSettings()
|
||||||
|
# Remove obsolete entries.
|
||||||
|
settings.remove(u'custom slide')
|
||||||
|
settings.remove(u'service')
|
||||||
settings.beginGroup(self.generalSettingsSection)
|
settings.beginGroup(self.generalSettingsSection)
|
||||||
self.recentFiles = settings.value(u'recent files').toStringList()
|
self.recentFiles = settings.value(u'recent files').toStringList()
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
|
Loading…
Reference in New Issue
Block a user