Update the wizard to show actual downloading of files on the progress page.

bzr-revno: 1398
This commit is contained in:
Raoul Snyman 2011-03-17 23:23:45 +02:00
commit ef223df462

View File

@ -160,6 +160,16 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self._performWizard() self._performWizard()
self._postWizard() self._postWizard()
def _getFileSize(self, url):
site = urllib.urlopen(url)
meta = site.info()
return int(meta.getheaders("Content-Length")[0])
def _downloadProgress(self, count, block_size, total_size):
increment = (count * block_size) - self.previous_size
self._incrementProgressBar(None, increment)
self.previous_size = count * block_size
def _incrementProgressBar(self, status_text, increment=1): def _incrementProgressBar(self, status_text, increment=1):
""" """
Update the wizard progress page. Update the wizard progress page.
@ -184,19 +194,27 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
max_progress = 2 max_progress = 2
# Loop through the songs list and increase for each selected item # Loop through the songs list and increase for each selected item
for i in xrange(self.songsListWidget.count()): for i in xrange(self.songsListWidget.count()):
if self.songsListWidget.item(i).checkState() == QtCore.Qt.Checked: item = self.songsListWidget.item(i)
max_progress += 1 if item.checkState() == QtCore.Qt.Checked:
filename = item.data(QtCore.Qt.UserRole).toString()
size = self._getFileSize(u'%s%s' % (self.web, filename))
max_progress += size
# Loop through the Bibles list and increase for each selected item # Loop through the Bibles list and increase for each selected item
iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget) iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget)
while iterator.value(): while iterator.value():
item = iterator.value() item = iterator.value()
if item.parent() and item.checkState(0) == QtCore.Qt.Checked: if item.parent() and item.checkState(0) == QtCore.Qt.Checked:
max_progress += 1 filename = item.data(0, QtCore.Qt.UserRole).toString()
size = self._getFileSize(u'%s%s' % (self.web, filename))
max_progress += size
iterator += 1 iterator += 1
# Loop through the themes list and increase for each selected item # Loop through the themes list and increase for each selected item
for i in xrange(self.themesListWidget.count()): for i in xrange(self.themesListWidget.count()):
if self.themesListWidget.item(i).checkState() == QtCore.Qt.Checked: item = self.themesListWidget.item(i)
max_progress += 1 if item.checkState() == QtCore.Qt.Checked:
filename = item.data(QtCore.Qt.UserRole).toString()
size = self._getFileSize(u'%s%s' % (self.web, filename))
max_progress += size
self.finishButton.setVisible(False) self.finishButton.setVisible(False)
self.progressBar.setValue(0) self.progressBar.setValue(0)
self.progressBar.setMinimum(0) self.progressBar.setMinimum(0)
@ -241,27 +259,33 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
item = self.songsListWidget.item(i) item = self.songsListWidget.item(i)
if item.checkState() == QtCore.Qt.Checked: if item.checkState() == QtCore.Qt.Checked:
filename = item.data(QtCore.Qt.UserRole).toString() filename = item.data(QtCore.Qt.UserRole).toString()
self._incrementProgressBar(self.downloading % filename) self._incrementProgressBar(self.downloading % filename, 0)
self.previous_size = 0
destination = os.path.join(songs_destination, unicode(filename)) destination = os.path.join(songs_destination, unicode(filename))
urllib.urlretrieve(u'%s%s' % (self.web, filename), destination) urllib.urlretrieve(u'%s%s' % (self.web, filename), destination,
self._downloadProgress)
# Download Bibles # Download Bibles
bibles_iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget) bibles_iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget)
while bibles_iterator.value(): while bibles_iterator.value():
item = bibles_iterator.value() item = bibles_iterator.value()
if item.parent() and item.checkState(0) == QtCore.Qt.Checked: if item.parent() and item.checkState(0) == QtCore.Qt.Checked:
bible = unicode(item.data(0, QtCore.Qt.UserRole).toString()) bible = unicode(item.data(0, QtCore.Qt.UserRole).toString())
self._incrementProgressBar(self.downloading % bible) self._incrementProgressBar(self.downloading % bible, 0)
self.previous_size = 0
urllib.urlretrieve(u'%s%s' % (self.web, bible), urllib.urlretrieve(u'%s%s' % (self.web, bible),
os.path.join(bibles_destination, bible)) os.path.join(bibles_destination, bible),
self._downloadProgress)
bibles_iterator += 1 bibles_iterator += 1
# Download themes # Download themes
for i in xrange(self.themesListWidget.count()): for i in xrange(self.themesListWidget.count()):
item = self.themesListWidget.item(i) item = self.themesListWidget.item(i)
if item.checkState() == QtCore.Qt.Checked: if item.checkState() == QtCore.Qt.Checked:
theme = unicode(item.data(QtCore.Qt.UserRole).toString()) theme = unicode(item.data(QtCore.Qt.UserRole).toString())
self._incrementProgressBar(self.downloading % theme) self._incrementProgressBar(self.downloading % theme, 0)
self.previous_size = 0
urllib.urlretrieve(u'%s%s' % (self.web, theme), urllib.urlretrieve(u'%s%s' % (self.web, theme),
os.path.join(themes_destination, theme)) os.path.join(themes_destination, theme),
self._downloadProgress)
# 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',