Fix a potential problem with the First Time Wizard where people would overwrite their song databases by being too eager to click 'next' and 'yes'.

bzr-revno: 1388
This commit is contained in:
Raoul Snyman 2011-03-14 21:02:48 +02:00
commit 78c539e1d8
6 changed files with 72 additions and 31 deletions

View File

@ -184,13 +184,15 @@ class OpenLP(QtGui.QApplication):
# make sure Qt really display the splash screen
self.processEvents()
# start the main app window
self.mainWindow = MainWindow(screens, app_version, self.clipboard(),
not has_run_wizard)
self.mainWindow = MainWindow(screens, app_version, self.clipboard())
self.mainWindow.show()
if show_splash:
# now kill the splashscreen
self.splash.finish(self.mainWindow)
self.mainWindow.repaint()
self.processEvents()
if not has_run_wizard:
self.mainWindow.firstTime()
update_check = QtCore.QSettings().value(
u'general/update check', QtCore.QVariant(True)).toBool()
if update_check:

View File

@ -111,17 +111,19 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self.biblesTreeWidget.expandAll()
themes = self.config.get(u'themes', u'files')
themes = themes.split(u',')
if not os.path.exists(os.path.join(gettempdir(), u'openlp')):
os.makedirs(os.path.join(gettempdir(), u'openlp'))
for theme in themes:
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),
os.path.join(gettempdir(), screenshot))
os.path.join(gettempdir(), u'openlp', screenshot))
item = QtGui.QListWidgetItem(title, self.themesListWidget)
item.setData(QtCore.Qt.UserRole,
QtCore.QVariant(filename))
item.setIcon(build_icon(
os.path.join(gettempdir(), screenshot)))
os.path.join(gettempdir(), u'openlp', screenshot)))
item.setCheckState(QtCore.Qt.Unchecked)
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
@ -230,29 +232,18 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self._setPluginStatus(self.songUsageCheckBox, u'songusage/status')
self._setPluginStatus(self.alertCheckBox, u'alerts/status')
# Build directories for downloads
songs_destination = AppLocation.get_section_data_path(u'songs')
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')
# Install songs
# 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)
destination = os.path.join(songs_destination, u'songs.sqlite')
if os.path.exists(destination):
if QtGui.QMessageBox.question(self,
translate('OpenLP.FirstTimeWizard',
'Overwrite Existing Songs?'),
translate('OpenLP.FirstTimeWizard', 'Your songs '
'database already exists and your current songs will '
'be permanently lost, are you sure you want to '
'replace it ?'),
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
QtGui.QMessageBox.No) != QtGui.QMessageBox.Yes:
continue
destination = os.path.join(songs_destination, unicode(filename))
urllib.urlretrieve(u'%s%s' % (self.web, filename), destination)
# Install Bibles
# Download Bibles
bibles_iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget)
while bibles_iterator.value():
item = bibles_iterator.value()
@ -262,7 +253,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
urllib.urlretrieve(u'%s%s' % (self.web, bible),
os.path.join(bibles_destination, bible))
bibles_iterator += 1
# Install themes
# Download themes
for i in xrange(self.themesListWidget.count()):
item = self.themesListWidget.item(i)
if item.checkState() == QtCore.Qt.Checked:

View File

@ -25,6 +25,8 @@
###############################################################################
import logging
import os
from tempfile import gettempdir
from PyQt4 import QtCore, QtGui
@ -461,14 +463,13 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
actionList = ActionList()
def __init__(self, screens, applicationVersion, clipboard, firstTime):
def __init__(self, screens, applicationVersion, clipboard):
"""
This constructor sets up the interface, the various managers, and the
plugins.
"""
QtGui.QMainWindow.__init__(self)
self.screens = screens
self.actionList = ActionList()
self.applicationVersion = applicationVersion
self.clipboard = clipboard
# Set up settings sections for the main application
@ -478,6 +479,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.serviceSettingsSection = u'servicemanager'
self.songsSettingsSection = u'songs'
self.serviceNotSaved = False
self.actionList = ActionList()
self.settingsmanager = SettingsManager(screens)
self.aboutForm = AboutForm(self, applicationVersion)
self.settingsForm = SettingsForm(self.screens, self, self)
@ -624,10 +626,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.MediaToolBox.setCurrentIndex(savedPlugin)
self.settingsForm.postSetUp()
Receiver.send_message(u'cursor_normal')
# Import themes if first time
if firstTime:
self.themeManagerContents.firstTime()
def setAutoLanguage(self, value):
self.LanguageGroup.setDisabled(value)
@ -670,6 +668,20 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.setViewMode(False, True, False, False, True)
self.ModeLiveItem.setChecked(True)
def firstTime(self):
# Import themes if first time
Receiver.send_message(u'openlp_process_events')
self.themeManagerContents.firstTime()
for plugin in self.pluginManager.plugins:
if hasattr(plugin, u'firstTime'):
Receiver.send_message(u'openlp_process_events')
plugin.firstTime()
Receiver.send_message(u'openlp_process_events')
temp_dir = os.path.join(unicode(gettempdir()), u'openlp')
for filename in os.listdir(temp_dir):
os.remove(os.path.join(temp_dir, filename))
os.removedirs(temp_dir)
def blankCheck(self):
"""
Check and display message if screen blank on setup.

View File

@ -151,12 +151,14 @@ class OpenLPSongImport(SongImport):
source_songs = self.source_session.query(OldSong).all()
song_total = len(source_songs)
if self.import_wizard:
self.import_wizard.progressBar.setMaximum(song_total)
song_count = 1
for song in source_songs:
self.import_wizard.incrementProgressBar(unicode(translate(
'SongsPlugin.OpenLPSongImport', 'Importing song %d of %d.')) %
(song_count, song_total))
if self.import_wizard:
self.import_wizard.incrementProgressBar(
unicode(translate('SongsPlugin.OpenLPSongImport',
'Importing song %d of %d.')) % (song_count, song_total))
new_song = Song()
new_song.title = song.title
if has_media_files and hasattr(song, 'alternate_title'):

View File

@ -62,6 +62,7 @@ class SongImport(QtCore.QObject):
else:
raise KeyError(u'Keyword arguments "filename[s]" not supplied.')
log.debug(self.import_source)
self.import_wizard = None
self.song = None
self.stop_import_flag = False
self.set_defaults()

View File

@ -26,16 +26,20 @@
import logging
import re
import os
from tempfile import gettempdir
from PyQt4 import QtCore, QtGui
from openlp.core.lib import Plugin, StringContent, build_icon, translate
from openlp.core.lib import Plugin, StringContent, build_icon, translate, \
Receiver
from openlp.core.lib.db import Manager
from openlp.core.lib.ui import UiStrings
from openlp.plugins.songs.lib import add_author_unknown, SongMediaItem, \
SongsTab, SongXML
from openlp.plugins.songs.lib.db import init_schema, Song
from openlp.plugins.songs.lib.importer import SongFormat
from openlp.plugins.songs.lib.olpimport import OpenLPSongImport
log = logging.getLogger(__name__)
@ -244,6 +248,35 @@ class SongsPlugin(Plugin):
}
self.setPluginUiTextStrings(tooltips)
def firstTime(self):
"""
If the first time wizard has run, this function is run to import all the
new songs into the database.
"""
db_dir = unicode(os.path.join(gettempdir(), u'openlp'))
song_dbs = []
for sfile in os.listdir(db_dir):
if sfile.startswith(u'songs_') and sfile.endswith(u'.sqlite'):
song_dbs.append(os.path.join(db_dir, sfile))
if len(song_dbs) == 0:
return
progress = QtGui.QProgressDialog(self.formparent)
progress.setWindowModality(QtCore.Qt.WindowModal)
progress.setLabelText(translate('OpenLP.Ui', 'Starting import...'))
progress.setCancelButton(None)
progress.setRange(0, len(song_dbs))
progress.setMinimumDuration(0)
progress.forceShow()
for idx, db in enumerate(song_dbs):
progress.setValue(idx)
Receiver.send_message(u'openlp_process_events')
importer = OpenLPSongImport(self.manager, filename=db)
importer.do_import()
progress.setValue(len(song_dbs))
self.mediaItem.displayResultsSong(
self.manager.get_all_objects(Song, order_by_ref=Song.search_title))
self.onToolsReindexItemTriggered()
def finalise(self):
"""
Time to tidy up on exit