← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~raoul-snyman/openlp/wizard into lp:openlp

 

Raoul Snyman has proposed merging lp:~raoul-snyman/openlp/wizard into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~raoul-snyman/openlp/wizard/+merge/53199

The first time wizard now doesn't overwrite the user's songs.
-- 
https://code.launchpad.net/~raoul-snyman/openlp/wizard/+merge/53199
Your team OpenLP Core is requested to review the proposed merge of lp:~raoul-snyman/openlp/wizard into lp:openlp.
=== modified file 'openlp.pyw'
--- openlp.pyw	2011-03-12 17:32:34 +0000
+++ openlp.pyw	2011-03-14 06:58:56 +0000
@@ -184,13 +184,15 @@
         # 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:

=== modified file 'openlp/core/ui/firsttimeform.py'
--- openlp/core/ui/firsttimeform.py	2011-03-11 20:51:29 +0000
+++ openlp/core/ui/firsttimeform.py	2011-03-14 06:58:56 +0000
@@ -111,17 +111,19 @@
             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 @@
         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 @@
                 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:

=== modified file 'openlp/core/ui/mainwindow.py'
--- openlp/core/ui/mainwindow.py	2011-03-11 05:15:41 +0000
+++ openlp/core/ui/mainwindow.py	2011-03-14 06:58:56 +0000
@@ -25,6 +25,8 @@
 ###############################################################################
 
 import logging
+import os
+from tempfile import gettempdir
 
 from PyQt4 import QtCore, QtGui
 
@@ -461,14 +463,13 @@
 
     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 @@
         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 @@
                 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 @@
             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.

=== modified file 'openlp/plugins/songs/lib/olpimport.py'
--- openlp/plugins/songs/lib/olpimport.py	2011-03-06 16:28:26 +0000
+++ openlp/plugins/songs/lib/olpimport.py	2011-03-14 06:58:56 +0000
@@ -151,12 +151,14 @@
 
         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'):

=== modified file 'openlp/plugins/songs/lib/songimport.py'
--- openlp/plugins/songs/lib/songimport.py	2011-03-11 08:33:22 +0000
+++ openlp/plugins/songs/lib/songimport.py	2011-03-14 06:58:56 +0000
@@ -62,6 +62,7 @@
         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()

=== modified file 'openlp/plugins/songs/songsplugin.py'
--- openlp/plugins/songs/songsplugin.py	2011-03-10 19:17:05 +0000
+++ openlp/plugins/songs/songsplugin.py	2011-03-14 06:58:56 +0000
@@ -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 @@
         }
         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


Follow ups