Merge: merge with trunk.

This commit is contained in:
Martin Zibricky 2012-10-14 13:14:37 +02:00
commit 1408e6620d
4 changed files with 63 additions and 24 deletions

View File

@ -177,8 +177,10 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
return FirstTimePage.Progress return FirstTimePage.Progress
elif self.currentId() == FirstTimePage.Themes: elif self.currentId() == FirstTimePage.Themes:
Receiver.send_message(u'cursor_busy') Receiver.send_message(u'cursor_busy')
Receiver.send_message(u'openlp_process_events')
while not self.themeScreenshotThread.isFinished(): while not self.themeScreenshotThread.isFinished():
time.sleep(0.1) time.sleep(0.1)
Receiver.send_message(u'openlp_process_events')
# Build the screenshot icons, as this can not be done in the thread. # Build the screenshot icons, as this can not be done in the thread.
self._buildThemeScreenshots() self._buildThemeScreenshots()
Receiver.send_message(u'cursor_normal') Receiver.send_message(u'cursor_normal')
@ -188,10 +190,11 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
def onCurrentIdChanged(self, pageId): def onCurrentIdChanged(self, pageId):
""" """
Detects Page changes and updates as approprate. Detects Page changes and updates as appropriate.
""" """
# Keep track of the page we are at. Triggering "Cancel" causes pageId # Keep track of the page we are at. Triggering "Cancel" causes pageId
# to be a -1. # to be a -1.
Receiver.send_message(u'openlp_process_events')
if pageId != -1: if pageId != -1:
self.lastId = pageId self.lastId = pageId
if pageId == FirstTimePage.Plugins: if pageId == FirstTimePage.Plugins:
@ -227,10 +230,12 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self.cancelButton.setVisible(False) self.cancelButton.setVisible(False)
elif pageId == FirstTimePage.Progress: elif pageId == FirstTimePage.Progress:
Receiver.send_message(u'cursor_busy') Receiver.send_message(u'cursor_busy')
self.repaint()
Receiver.send_message(u'openlp_process_events')
# Try to give the wizard a chance to redraw itself
time.sleep(0.2)
self._preWizard() self._preWizard()
Receiver.send_message(u'openlp_process_events')
self._performWizard() self._performWizard()
Receiver.send_message(u'openlp_process_events')
self._postWizard() self._postWizard()
Receiver.send_message(u'cursor_normal') Receiver.send_message(u'cursor_normal')
Receiver.send_message(u'openlp_process_events') Receiver.send_message(u'openlp_process_events')
@ -263,8 +268,8 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
""" """
Receiver.send_message(u'cursor_busy') Receiver.send_message(u'cursor_busy')
self._performWizard() self._performWizard()
Receiver.send_message(u'openlp_process_events')
Receiver.send_message(u'cursor_normal') Receiver.send_message(u'cursor_normal')
Receiver.send_message(u'openlp_process_events')
Settings().setValue(u'general/has run wizard', Settings().setValue(u'general/has run wizard',
QtCore.QVariant(True)) QtCore.QVariant(True))
self.close() self.close()
@ -344,6 +349,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
Receiver.send_message(u'openlp_process_events') Receiver.send_message(u'openlp_process_events')
# 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()):
Receiver.send_message(u'openlp_process_events')
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()
@ -352,6 +358,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
# 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():
Receiver.send_message(u'openlp_process_events')
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:
filename = item.data(0, QtCore.Qt.UserRole).toString() filename = item.data(0, QtCore.Qt.UserRole).toString()
@ -360,6 +367,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
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()):
Receiver.send_message(u'openlp_process_events')
item = self.themesListWidget.item(i) item = self.themesListWidget.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()
@ -381,6 +389,10 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self.progressPage.setTitle(translate('OpenLP.FirstTimeWizard', self.progressPage.setTitle(translate('OpenLP.FirstTimeWizard',
'Setting Up')) 'Setting Up'))
self.progressPage.setSubTitle(u'Setup complete.') self.progressPage.setSubTitle(u'Setup complete.')
self.repaint()
Receiver.send_message(u'openlp_process_events')
# Try to give the wizard a chance to repaint itself
time.sleep(0.1)
def _postWizard(self): def _postWizard(self):
""" """

View File

@ -57,8 +57,6 @@ class AlertsManager(QtCore.QObject):
""" """
if message: if message:
self.displayAlert(message[0]) self.displayAlert(message[0])
else:
self.displayAlert(u'')
def displayAlert(self, text=u''): def displayAlert(self, text=u''):
""" """
@ -68,14 +66,15 @@ class AlertsManager(QtCore.QObject):
display text display text
""" """
log.debug(u'display alert called %s' % text) log.debug(u'display alert called %s' % text)
self.alertList.append(text) if text:
if self.timer_id != 0: self.alertList.append(text)
Receiver.send_message(u'mainwindow_status_text', if self.timer_id != 0:
translate('AlertsPlugin.AlertsManager', Receiver.send_message(u'mainwindow_status_text',
'Alert message created and displayed.')) translate('AlertsPlugin.AlertsManager',
return 'Alert message created and displayed.'))
Receiver.send_message(u'mainwindow_status_text', u'') return
self.generateAlert() Receiver.send_message(u'mainwindow_status_text', u'')
self.generateAlert()
def generateAlert(self): def generateAlert(self):
""" """

View File

@ -63,10 +63,14 @@ class OpenLPSongImport(SongImport):
SongImport.__init__(self, manager, **kwargs) SongImport.__init__(self, manager, **kwargs)
self.sourceSession = None self.sourceSession = None
def doImport(self): def doImport(self, progressDialog=None):
""" """
Run the import for an OpenLP version 2 song database. Run the import for an OpenLP version 2 song database.
``progressDialog``
The QProgressDialog used when importing songs from the FRW.
""" """
class OldAuthor(BaseModel): class OldAuthor(BaseModel):
""" """
Author model Author model
@ -101,13 +105,14 @@ class OpenLPSongImport(SongImport):
""" """
pass pass
# Check the file type
if not self.importSource.endswith(u'.sqlite'): if not self.importSource.endswith(u'.sqlite'):
self.logError(self.importSource, self.logError(self.importSource,
translate('SongsPlugin.OpenLPSongImport', translate('SongsPlugin.OpenLPSongImport',
'Not a valid OpenLP 2.0 song database.')) 'Not a valid OpenLP 2.0 song database.'))
return return
self.importSource = u'sqlite:///%s' % self.importSource self.importSource = u'sqlite:///%s' % self.importSource
# Load the db file
engine = create_engine(self.importSource) engine = create_engine(self.importSource)
source_meta = MetaData() source_meta = MetaData()
source_meta.reflect(engine) source_meta.reflect(engine)
@ -224,7 +229,11 @@ class OpenLPSongImport(SongImport):
file_name=media_file.file_name)) file_name=media_file.file_name))
clean_song(self.manager, new_song) clean_song(self.manager, new_song)
self.manager.save_object(new_song) self.manager.save_object(new_song)
if self.importWizard: if progressDialog:
progressDialog.setValue(progressDialog.value() + 1)
progressDialog.setLabelText(
WizardStrings.ImportingType % new_song.title)
else:
self.importWizard.incrementProgressBar( self.importWizard.incrementProgressBar(
WizardStrings.ImportingType % new_song.title) WizardStrings.ImportingType % new_song.title)
if self.stopImportFlag: if self.stopImportFlag:

View File

@ -29,6 +29,7 @@
import logging import logging
import os import os
from tempfile import gettempdir from tempfile import gettempdir
import sqlite3
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -82,7 +83,7 @@ class SongsPlugin(Plugin):
unicode(UiStrings().Tools)) unicode(UiStrings().Tools))
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'servicemanager_new_service'), QtCore.SIGNAL(u'servicemanager_new_service'),
self.clearTemporarySongs) self.clearTemporarySongs)
def addImportMenuItem(self, import_menu): def addImportMenuItem(self, import_menu):
@ -235,31 +236,37 @@ class SongsPlugin(Plugin):
If the first time wizard has run, this function is run to import all the If the first time wizard has run, this function is run to import all the
new songs into the database. new songs into the database.
""" """
Receiver.send_message(u'openlp_process_events')
self.onToolsReindexItemTriggered() self.onToolsReindexItemTriggered()
Receiver.send_message(u'openlp_process_events')
db_dir = unicode(os.path.join( db_dir = unicode(os.path.join(
unicode(gettempdir(), get_filesystem_encoding()), u'openlp')) unicode(gettempdir(), get_filesystem_encoding()), u'openlp'))
if not os.path.exists(db_dir): if not os.path.exists(db_dir):
return return
song_dbs = [] song_dbs = []
song_count = 0
for sfile in os.listdir(db_dir): for sfile in os.listdir(db_dir):
if sfile.startswith(u'songs_') and sfile.endswith(u'.sqlite'): if sfile.startswith(u'songs_') and sfile.endswith(u'.sqlite'):
Receiver.send_message(u'openlp_process_events')
song_dbs.append(os.path.join(db_dir, sfile)) song_dbs.append(os.path.join(db_dir, sfile))
song_count += self._countSongs(os.path.join(db_dir, sfile))
if not song_dbs: if not song_dbs:
return return
Receiver.send_message(u'openlp_process_events')
progress = QtGui.QProgressDialog(self.formParent) progress = QtGui.QProgressDialog(self.formParent)
progress.setWindowModality(QtCore.Qt.WindowModal) progress.setWindowModality(QtCore.Qt.WindowModal)
progress.setWindowTitle(translate('OpenLP.Ui', 'Importing Songs')) progress.setWindowTitle(translate('OpenLP.Ui', 'Importing Songs'))
progress.setLabelText(translate('OpenLP.Ui', 'Starting import...')) progress.setLabelText(translate('OpenLP.Ui', 'Starting import...'))
progress.setCancelButton(None) progress.setCancelButton(None)
progress.setRange(0, len(song_dbs)) progress.setRange(0, song_count)
progress.setMinimumDuration(0) progress.setMinimumDuration(0)
progress.forceShow() progress.forceShow()
for idx, db in enumerate(song_dbs): Receiver.send_message(u'openlp_process_events')
progress.setValue(idx) for db in song_dbs:
Receiver.send_message(u'openlp_process_events')
importer = OpenLPSongImport(self.manager, filename=db) importer = OpenLPSongImport(self.manager, filename=db)
importer.doImport() importer.doImport(progress)
progress.setValue(len(song_dbs)) Receiver.send_message(u'openlp_process_events')
progress.setValue(song_count)
self.mediaItem.onSearchTextButtonClicked() self.mediaItem.onSearchTextButtonClicked()
def finalise(self): def finalise(self):
@ -287,3 +294,15 @@ class SongsPlugin(Plugin):
songs = self.manager.get_all_objects(Song, Song.temporary == True) songs = self.manager.get_all_objects(Song, Song.temporary == True)
for song in songs: for song in songs:
self.manager.delete_object(Song, song.id) self.manager.delete_object(Song, song.id)
def _countSongs(self, db_file):
connection = sqlite3.connect(db_file)
cursor = connection.cursor()
cursor.execute(u'SELECT COUNT(id) AS song_count FROM songs')
song_count = cursor.fetchone()[0]
connection.close()
try:
song_count = int(song_count)
except (TypeError, ValueError):
song_count = 0
return song_count