From a33a13ef05cf3758c8869f8a3c4ae262b2cbaf5c Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 14 Mar 2011 08:48:23 +0200 Subject: [PATCH 1/5] Make first time wizard import songs, rather than overwrite them. --- openlp.pyw | 6 +++-- openlp/core/ui/firsttimeform.py | 34 ++++++++++++++------------ openlp/core/ui/mainwindow.py | 26 +++++++++++++++----- openlp/plugins/songs/lib/olpimport.py | 10 +++++--- openlp/plugins/songs/lib/songimport.py | 1 + openlp/plugins/songs/songsplugin.py | 32 +++++++++++++++++++++++- 6 files changed, 80 insertions(+), 29 deletions(-) diff --git a/openlp.pyw b/openlp.pyw index 416b2bb13..04f65a5dd 100755 --- a/openlp.pyw +++ b/openlp.pyw @@ -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: diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index b049e2ea7..c02da2179 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -53,7 +53,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): # check to see if we have web access self.web = u'http://openlp.org/files/frw/' 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: files = self.webAccess.read() self.config.readfp(io.BytesIO(files)) @@ -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,7 +232,7 @@ 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 @@ -239,18 +241,18 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): 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)) + #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 urllib.urlretrieve(u'%s%s' % (self.web, filename), destination) # Install Bibles bibles_iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index cb324a872..4279673ba 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -25,6 +25,8 @@ ############################################################################### import logging +import os +from tempfile import gettempdir from PyQt4 import QtCore, QtGui @@ -461,16 +463,16 @@ 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 + #self.firstTime = firstTime # Set up settings sections for the main application # (not for use by plugins) self.uiSettingsSection = u'user interface' @@ -478,6 +480,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 +627,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 +669,21 @@ 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 + #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): """ Check and display message if screen blank on setup. diff --git a/openlp/plugins/songs/lib/olpimport.py b/openlp/plugins/songs/lib/olpimport.py index 11170f9a0..9bd098e47 100644 --- a/openlp/plugins/songs/lib/olpimport.py +++ b/openlp/plugins/songs/lib/olpimport.py @@ -151,12 +151,14 @@ class OpenLPSongImport(SongImport): source_songs = self.source_session.query(OldSong).all() 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 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'): diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index 3bc1a082f..4097af636 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -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() diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 1e072afdf..cb49f9149 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -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,32 @@ 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)) + 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): """ Time to tidy up on exit From b3aa2bfdd19f17b739ae38af8ec7665c8e243d4a Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 14 Mar 2011 08:49:54 +0200 Subject: [PATCH 2/5] Removed some unnecessary comments. --- openlp/core/ui/firsttimeform.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index c02da2179..907a58819 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -235,26 +235,15 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): 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, unicode(filename)) - #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 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() @@ -264,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: From 3bb7f556c904233d367840e9f360acdd438fa617 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 14 Mar 2011 08:54:18 +0200 Subject: [PATCH 3/5] Post-development cleanup. --- openlp/core/ui/firsttimeform.py | 2 +- openlp/core/ui/mainwindow.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index 907a58819..382be85b8 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -53,7 +53,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): # check to see if we have web access self.web = u'http://openlp.org/files/frw/' self.config = SafeConfigParser() - self.webAccess = get_web_page(u'%s%s' % (self.web, u'download.cfg?99')) + self.webAccess = get_web_page(u'%s%s' % (self.web, u'download.cfg')) if self.webAccess: files = self.webAccess.read() self.config.readfp(io.BytesIO(files)) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 4279673ba..06b809a20 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -472,7 +472,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.screens = screens self.applicationVersion = applicationVersion self.clipboard = clipboard - #self.firstTime = firstTime # Set up settings sections for the main application # (not for use by plugins) self.uiSettingsSection = u'user interface' @@ -671,7 +670,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): 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: From 82239abb92d93880f97ce12fa6cc792e1f6e3087 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 14 Mar 2011 20:34:48 +0200 Subject: [PATCH 4/5] Used a temporary string due to string freeze, and included the song reindex as per Andreas' request. --- openlp/plugins/songs/songsplugin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index cb49f9149..c569284d8 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -260,7 +260,7 @@ class SongsPlugin(Plugin): 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.setLabelText(translate('OpenLP.Ui', 'Starting import...')) progress.setCancelButton(None) progress.setRange(0, len(song_dbs)) progress.setMinimumDuration(0) @@ -273,6 +273,7 @@ class SongsPlugin(Plugin): 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): """ From e0ea2c57a3915b2ea747f9633d95894d1293faac Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 14 Mar 2011 20:40:27 +0200 Subject: [PATCH 5/5] Fixed up a bug where the song import progress dialog would show up and not disappear if a user did not select any song databases to import. --- openlp/plugins/songs/songsplugin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index c569284d8..bd953ffac 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -258,6 +258,8 @@ class SongsPlugin(Plugin): 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...'))