Make first time wizard import songs, rather than overwrite them.

This commit is contained in:
Raoul Snyman 2011-03-14 08:48:23 +02:00
parent d1592b46c7
commit a33a13ef05
6 changed files with 80 additions and 29 deletions

View File

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

View File

@ -53,7 +53,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
# check to see if we have web access # check to see if we have web access
self.web = u'http://openlp.org/files/frw/' self.web = u'http://openlp.org/files/frw/'
self.config = SafeConfigParser() self.config = SafeConfigParser()
self.webAccess = get_web_page(u'%s%s' % (self.web, u'download.cfg')) self.webAccess = get_web_page(u'%s%s' % (self.web, u'download.cfg?99'))
if self.webAccess: if self.webAccess:
files = self.webAccess.read() files = self.webAccess.read()
self.config.readfp(io.BytesIO(files)) self.config.readfp(io.BytesIO(files))
@ -111,17 +111,19 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self.biblesTreeWidget.expandAll() self.biblesTreeWidget.expandAll()
themes = self.config.get(u'themes', u'files') themes = self.config.get(u'themes', u'files')
themes = themes.split(u',') 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: for theme in themes:
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(), 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,
QtCore.QVariant(filename)) QtCore.QVariant(filename))
item.setIcon(build_icon( item.setIcon(build_icon(
os.path.join(gettempdir(), screenshot))) os.path.join(gettempdir(), u'openlp', screenshot)))
item.setCheckState(QtCore.Qt.Unchecked) item.setCheckState(QtCore.Qt.Unchecked)
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable) item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
@ -230,7 +232,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
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 # 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') bibles_destination = AppLocation.get_section_data_path(u'bibles')
themes_destination = AppLocation.get_section_data_path(u'themes') themes_destination = AppLocation.get_section_data_path(u'themes')
# Install songs # Install songs
@ -239,18 +241,18 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
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)
destination = os.path.join(songs_destination, u'songs.sqlite') destination = os.path.join(songs_destination, unicode(filename))
if os.path.exists(destination): #if os.path.exists(destination):
if QtGui.QMessageBox.question(self, # if QtGui.QMessageBox.question(self,
translate('OpenLP.FirstTimeWizard', # translate('OpenLP.FirstTimeWizard',
'Overwrite Existing Songs?'), # 'Overwrite Existing Songs?'),
translate('OpenLP.FirstTimeWizard', 'Your songs ' # translate('OpenLP.FirstTimeWizard', 'Your songs '
'database already exists and your current songs will ' # 'database already exists and your current songs will '
'be permanently lost, are you sure you want to ' # 'be permanently lost, are you sure you want to '
'replace it ?'), # 'replace it ?'),
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, # QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
QtGui.QMessageBox.No) != QtGui.QMessageBox.Yes: # QtGui.QMessageBox.No) != QtGui.QMessageBox.Yes:
continue # continue
urllib.urlretrieve(u'%s%s' % (self.web, filename), destination) urllib.urlretrieve(u'%s%s' % (self.web, filename), destination)
# Install Bibles # Install Bibles
bibles_iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget) bibles_iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget)

View File

@ -25,6 +25,8 @@
############################################################################### ###############################################################################
import logging import logging
import os
from tempfile import gettempdir
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -461,16 +463,16 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
actionList = ActionList() 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 This constructor sets up the interface, the various managers, and the
plugins. plugins.
""" """
QtGui.QMainWindow.__init__(self) QtGui.QMainWindow.__init__(self)
self.screens = screens self.screens = screens
self.actionList = ActionList()
self.applicationVersion = applicationVersion self.applicationVersion = applicationVersion
self.clipboard = clipboard self.clipboard = clipboard
#self.firstTime = firstTime
# Set up settings sections for the main application # Set up settings sections for the main application
# (not for use by plugins) # (not for use by plugins)
self.uiSettingsSection = u'user interface' self.uiSettingsSection = u'user interface'
@ -478,6 +480,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.serviceSettingsSection = u'servicemanager' self.serviceSettingsSection = u'servicemanager'
self.songsSettingsSection = u'songs' self.songsSettingsSection = u'songs'
self.serviceNotSaved = False self.serviceNotSaved = False
self.actionList = ActionList()
self.settingsmanager = SettingsManager(screens) self.settingsmanager = SettingsManager(screens)
self.aboutForm = AboutForm(self, applicationVersion) self.aboutForm = AboutForm(self, applicationVersion)
self.settingsForm = SettingsForm(self.screens, self, self) self.settingsForm = SettingsForm(self.screens, self, self)
@ -624,10 +627,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.MediaToolBox.setCurrentIndex(savedPlugin) self.MediaToolBox.setCurrentIndex(savedPlugin)
self.settingsForm.postSetUp() self.settingsForm.postSetUp()
Receiver.send_message(u'cursor_normal') Receiver.send_message(u'cursor_normal')
# Import themes if first time
if firstTime:
self.themeManagerContents.firstTime()
def setAutoLanguage(self, value): def setAutoLanguage(self, value):
self.LanguageGroup.setDisabled(value) self.LanguageGroup.setDisabled(value)
@ -670,6 +669,21 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.setViewMode(False, True, False, False, True) self.setViewMode(False, True, False, False, True)
self.ModeLiveItem.setChecked(True) self.ModeLiveItem.setChecked(True)
def firstTime(self):
# Import themes if first time
#if self.firstTime:
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): def blankCheck(self):
""" """
Check and display message if screen blank on setup. 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() source_songs = self.source_session.query(OldSong).all()
song_total = len(source_songs) song_total = len(source_songs)
self.import_wizard.progressBar.setMaximum(song_total) if self.import_wizard:
self.import_wizard.progressBar.setMaximum(song_total)
song_count = 1 song_count = 1
for song in source_songs: for song in source_songs:
self.import_wizard.incrementProgressBar(unicode(translate( if self.import_wizard:
'SongsPlugin.OpenLPSongImport', 'Importing song %d of %d.')) % self.import_wizard.incrementProgressBar(
(song_count, song_total)) unicode(translate('SongsPlugin.OpenLPSongImport',
'Importing song %d of %d.')) % (song_count, song_total))
new_song = Song() new_song = Song()
new_song.title = song.title new_song.title = song.title
if has_media_files and hasattr(song, 'alternate_title'): if has_media_files and hasattr(song, 'alternate_title'):

View File

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

View File

@ -26,16 +26,20 @@
import logging import logging
import re import re
import os
from tempfile import gettempdir
from PyQt4 import QtCore, QtGui 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.db import Manager
from openlp.core.lib.ui import UiStrings from openlp.core.lib.ui import UiStrings
from openlp.plugins.songs.lib import add_author_unknown, SongMediaItem, \ from openlp.plugins.songs.lib import add_author_unknown, SongMediaItem, \
SongsTab, SongXML SongsTab, SongXML
from openlp.plugins.songs.lib.db import init_schema, Song from openlp.plugins.songs.lib.db import init_schema, Song
from openlp.plugins.songs.lib.importer import SongFormat from openlp.plugins.songs.lib.importer import SongFormat
from openlp.plugins.songs.lib.olpimport import OpenLPSongImport
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -244,6 +248,32 @@ class SongsPlugin(Plugin):
} }
self.setPluginUiTextStrings(tooltips) 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))
progress = QtGui.QProgressDialog(self.formparent)
progress.setWindowModality(QtCore.Qt.WindowModal)
progress.setLabelText(translate('SongsPlugin', 'Importing songs...'))
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))
def finalise(self): def finalise(self):
""" """
Time to tidy up on exit Time to tidy up on exit