diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index cfd4948cb..61e1213db 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -92,7 +92,7 @@ class MediaManagerItem(QtGui.QWidget): """ QtGui.QWidget.__init__(self, parent) self.hide() - self.whitespace = re.compile(r'\W+', re.UNICODE) + self.whitespace = re.compile(r'[\W_]+', re.UNICODE) self.plugin = plugin visible_title = self.plugin.getString(StringContent.VisibleName) self.title = unicode(visible_title[u'title']) diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 65ed76dfe..910c52d2c 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -300,6 +300,12 @@ class Plugin(QtCore.QObject): if self.mediaItem: self.mediadock.remove_dock(self.mediaItem) + def appStartup(self): + """ + Perform tasks on application starup + """ + pass + def usesTheme(self, theme): """ Called to find out if a plugin is currently using a theme. diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index bacbff073..b4a3b3640 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -655,7 +655,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # Give all the plugins a chance to perform some tasks at startup Receiver.send_message(u'openlp_process_events') for plugin in self.pluginManager.plugins: - if plugin.isActive() and hasattr(plugin, u'appStartup'): + if plugin.isActive(): Receiver.send_message(u'openlp_process_events') plugin.appStartup() Receiver.send_message(u'openlp_process_events') diff --git a/openlp/core/ui/pluginform.py b/openlp/core/ui/pluginform.py index c93b08ccb..b4c87488c 100644 --- a/openlp/core/ui/pluginform.py +++ b/openlp/core/ui/pluginform.py @@ -132,6 +132,7 @@ class PluginForm(QtGui.QDialog, Ui_PluginViewDialog): Receiver.send_message(u'cursor_busy') self.activePlugin.toggleStatus(PluginStatus.Active) Receiver.send_message(u'cursor_normal') + self.activePlugin.appStartup() else: self.activePlugin.toggleStatus(PluginStatus.Inactive) status_text = unicode( diff --git a/openlp/core/ui/screen.py b/openlp/core/ui/screen.py index 160080c5a..b970158b2 100644 --- a/openlp/core/ui/screen.py +++ b/openlp/core/ui/screen.py @@ -106,7 +106,7 @@ class ScreenList(object): """ # Do not log at start up. if changed_screen != -1: - log.info(u'screen_count_changed %d' % number) + log.info(u'screen_count_changed %d' % self.desktop.numScreens()) # Remove unplugged screens. for screen in copy.deepcopy(self.screen_list): if screen[u'number'] == self.desktop.numScreens(): diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 349b0a4a3..8ecd89bc7 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -959,6 +959,7 @@ class ServiceManager(QtGui.QWidget): treewidgetitem.setToolTip(0, serviceitem.notes) treewidgetitem.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(item[u'order'])) + treewidgetitem.setSelected(item[u'selected']) # Add the children to their parent treewidgetitem. for count, frame in enumerate(serviceitem.get_frames()): child = QtGui.QTreeWidgetItem(treewidgetitem) @@ -1030,16 +1031,34 @@ class ServiceManager(QtGui.QWidget): # force reset of renderer as theme data has changed self.mainwindow.renderer.themedata = None if self.serviceItems: + for item in self.serviceItems: + item[u'selected'] = False + serviceIterator = QtGui.QTreeWidgetItemIterator( + self.serviceManagerList) + while serviceIterator.value(): + if serviceIterator.value().isSelected(): + selectedItem = serviceIterator.value() + serviceIterator += 1 + if selectedItem is not None: + if selectedItem.parent() is None: + pos = selectedItem.data(0, QtCore.Qt.UserRole).toInt()[0] + else: + pos = selectedItem.parent().data(0, QtCore.Qt.UserRole). \ + toInt()[0] + self.serviceItems[pos - 1][u'selected'] = True tempServiceItems = self.serviceItems self.serviceManagerList.clear() self.serviceItems = [] self.isNew = True for item in tempServiceItems: self.addServiceItem( - item[u'service_item'], False, expand=item[u'expanded']) + item[u'service_item'], False, expand=item[u'expanded'], + repaint=False, selected=item[u'selected']) # Set to False as items may have changed rendering # does not impact the saved song so True may also be valid self.setModified() + # Repaint it once only at the end + self.repaintServiceList(-1, -1) Receiver.send_message(u'cursor_normal') def serviceItemUpdate(self, message): @@ -1069,7 +1088,7 @@ class ServiceManager(QtGui.QWidget): self.setModified() def addServiceItem(self, item, rebuild=False, expand=None, replace=False, - repaint=True): + repaint=True, selected=False): """ Add a Service item to the list @@ -1097,17 +1116,17 @@ class ServiceManager(QtGui.QWidget): for inditem in item: self.serviceItems.append({u'service_item': inditem, u'order': len(self.serviceItems) + 1, - u'expanded': expand}) + u'expanded': expand, u'selected': selected}) else: self.serviceItems.append({u'service_item': item, u'order': len(self.serviceItems) + 1, - u'expanded': expand}) + u'expanded': expand, u'selected': selected}) if repaint: self.repaintServiceList(len(self.serviceItems) - 1, -1) else: self.serviceItems.insert(self.dropPosition, {u'service_item': item, u'order': self.dropPosition, - u'expanded': expand}) + u'expanded': expand, u'selected': selected}) self.repaintServiceList(self.dropPosition, -1) # if rebuilding list make sure live is fixed. if rebuild: diff --git a/openlp/plugins/bibles/forms/bibleupgradeform.py b/openlp/plugins/bibles/forms/bibleupgradeform.py index a29ef25d0..7913aac31 100644 --- a/openlp/plugins/bibles/forms/bibleupgradeform.py +++ b/openlp/plugins/bibles/forms/bibleupgradeform.py @@ -115,6 +115,8 @@ class BibleUpgradeForm(OpenLPWizard): self.stop_import_flag = True if not self.currentPage() == self.progressPage: self.done(QtGui.QDialog.Rejected) + else: + self.postWizard() def onCurrentIdChanged(self, pageId): """ @@ -127,14 +129,6 @@ class BibleUpgradeForm(OpenLPWizard): elif self.page(pageId) == self.selectPage and self.maxBibles == 0: self.next() - def onFinishButton(self): - """ - Some cleanup while finishing - """ - for number, filename in enumerate(self.files): - if number in self.success and self.success[number] == True: - delete_file(os.path.join(self.path, filename[0])) - def onBackupBrowseButtonClicked(self): """ Show the file open dialog for the OSIS file. @@ -180,8 +174,6 @@ class BibleUpgradeForm(OpenLPWizard): """ Set up the signals used in the bible importer. """ - QtCore.QObject.connect(self.finishButton, - QtCore.SIGNAL(u'clicked()'), self.onFinishButton) QtCore.QObject.connect(self.backupBrowseButton, QtCore.SIGNAL(u'clicked()'), self.onBackupBrowseButtonClicked) QtCore.QObject.connect(self.noBackupCheckBox, @@ -536,7 +528,7 @@ class BibleUpgradeForm(OpenLPWizard): """ Perform the actual upgrade. """ - include_webbible = False + self.include_webbible = False proxy_server = None if self.maxBibles == 0: self.progressLabel.setText( @@ -578,19 +570,19 @@ class BibleUpgradeForm(OpenLPWizard): name = unicode(self.versionNameEdit[biblenumber].text()) self.newbibles[number] = BibleDB(self.mediaItem, path=self.path, name=name) + self.newbibles[number].register(self.plugin.upgrade_wizard) metadata = oldbible.get_metadata() webbible = False meta_data = {} for meta in metadata: meta_data[meta[u'key']] = meta[u'value'] - if not meta[u'key'] == u'Version': + if not meta[u'key'] == u'Version' and not meta[u'key'] == \ + u'dbversion': self.newbibles[number].create_meta(meta[u'key'], meta[u'value']) - else: - self.newbibles[number].create_meta(meta[u'key'], name) if meta[u'key'] == u'download source': webbible = True - include_webbible = True + self.include_webbible = True if meta.has_key(u'proxy server'): proxy_server = meta[u'proxy server'] if webbible: @@ -602,12 +594,11 @@ class BibleUpgradeForm(OpenLPWizard): handler = BSExtract(proxy_server) books = handler.get_books_from_http(meta_data[u'download name']) if not books: - log.exception(u'Upgrading books from %s - download '\ + log.error(u'Upgrading books from %s - download '\ u'name: "%s" failed' % ( meta_data[u'download source'], meta_data[u'download name'])) - delete_database(self.path, - clean_filename(self.newbibles[number].get_name())) + delete_database(self.path, clean_filename(name)) del self.newbibles[number] critical_error_message_box( translate('BiblesPlugin.UpgradeWizardForm', @@ -626,16 +617,15 @@ class BibleUpgradeForm(OpenLPWizard): bible = BiblesResourcesDB.get_webbible( meta_data[u'download name'], meta_data[u'download source'].lower()) - if bible[u'language_id']: + if bible and bible[u'language_id']: language_id = bible[u'language_id'] self.newbibles[number].create_meta(u'language_id', language_id) else: language_id = self.newbibles[number].get_language(name) if not language_id: - log.exception(u'Upgrading from "%s" failed' % filename[0]) - delete_database(self.path, - clean_filename(self.newbibles[number].get_name())) + log.warn(u'Upgrading from "%s" failed' % filename[0]) + delete_database(self.path, clean_filename(name)) del self.newbibles[number] self.incrementProgressBar(unicode(translate( 'BiblesPlugin.UpgradeWizardForm', @@ -657,27 +647,42 @@ class BibleUpgradeForm(OpenLPWizard): book_ref_id = self.newbibles[number].\ get_book_ref_id_by_name(book, len(books), language_id) if not book_ref_id: - log.exception(u'Upgrading books from %s - download '\ + log.warn(u'Upgrading books from %s - download '\ u'name: "%s" aborted by user' % ( meta_data[u'download source'], meta_data[u'download name'])) - delete_database(self.path, - clean_filename(self.newbibles[number].get_name())) + delete_database(self.path, clean_filename(name)) del self.newbibles[number] bible_failed = True break book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) - self.newbibles[number].create_book(book, book_ref_id, - book_details[u'testament_id']) + db_book = self.newbibles[number].create_book(book, + book_ref_id, book_details[u'testament_id']) + # Try to import still downloaded verses + oldbook = oldbible.get_book(book) + if oldbook: + verses = oldbible.get_verses(oldbook[u'id']) + if not verses: + log.warn(u'No verses found to import for book ' + u'"%s"', book) + continue + for verse in verses: + if self.stop_import_flag: + bible_failed = True + break + self.newbibles[number].create_verse(db_book.id, + int(verse[u'chapter']), + int(verse[u'verse']), unicode(verse[u'text'])) + Receiver.send_message(u'openlp_process_events') + self.newbibles[number].session.commit() else: language_id = self.newbibles[number].get_object(BibleMeta, u'language_id') if not language_id: language_id = self.newbibles[number].get_language(name) if not language_id: - log.exception(u'Upgrading books from "%s" failed' % name) - delete_database(self.path, - clean_filename(self.newbibles[number].get_name())) + log.warn(u'Upgrading books from "%s" failed' % name) + delete_database(self.path, clean_filename(name)) del self.newbibles[number] self.incrementProgressBar(unicode(translate( 'BiblesPlugin.UpgradeWizardForm', @@ -701,10 +706,9 @@ class BibleUpgradeForm(OpenLPWizard): get_book_ref_id_by_name(book[u'name'], len(books), language_id) if not book_ref_id: - log.exception(u'Upgrading books from %s " '\ + log.warn(u'Upgrading books from %s " '\ 'failed - aborted by user' % name) - delete_database(self.path, - clean_filename(self.newbibles[number].get_name())) + delete_database(self.path, clean_filename(name)) del self.newbibles[number] bible_failed = True break @@ -713,7 +717,7 @@ class BibleUpgradeForm(OpenLPWizard): book_ref_id, book_details[u'testament_id']) verses = oldbible.get_verses(book[u'id']) if not verses: - log.exception(u'No verses found to import for book ' + log.warn(u'No verses found to import for book ' u'"%s"', book[u'name']) self.newbibles[number].delete_book(db_book) continue @@ -727,6 +731,8 @@ class BibleUpgradeForm(OpenLPWizard): Receiver.send_message(u'openlp_process_events') self.newbibles[number].session.commit() if not bible_failed: + self.newbibles[number].create_meta(u'Version', name) + delete_file(os.path.join(self.path, filename[0])) self.incrementProgressBar(unicode(translate( 'BiblesPlugin.UpgradeWizardForm', 'Upgrading Bible %s of %s: "%s"\n' @@ -739,10 +745,13 @@ class BibleUpgradeForm(OpenLPWizard): 'Upgrading Bible %s of %s: "%s"\nFailed')) % (number + 1, self.maxBibles, name), self.progressBar.maximum() - self.progressBar.value()) - delete_database(self.path, - clean_filename(name)) + delete_database(self.path, clean_filename(name)) number += 1 - self.mediaItem.reloadBibles() + + def postWizard(self): + """ + Clean up the UI after the import has finished. + """ successful_import = 0 failed_import = 0 for number, filename in enumerate(self.files): @@ -757,7 +766,7 @@ class BibleUpgradeForm(OpenLPWizard): else: failed_import_text = u'' if successful_import > 0: - if include_webbible: + if self.include_webbible: self.progressLabel.setText(unicode( translate('BiblesPlugin.UpgradeWizardForm', 'Upgrading ' 'Bible(s): %s successful%s\nPlease note, that verses from ' @@ -773,3 +782,4 @@ class BibleUpgradeForm(OpenLPWizard): self.progressLabel.setText( translate('BiblesPlugin.UpgradeWizardForm', 'Upgrade ' 'failed.')) + OpenLPWizard.postWizard(self) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index e44dd0a25..41dc947f9 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -1045,6 +1045,28 @@ class OldBibleDB(QtCore.QObject, Manager): else: return None + def get_book(self, name): + """ + Return a book by name or abbreviation. + + ``name`` + The name or abbreviation of the book. + """ + if not isinstance(name, unicode): + name = unicode(name) + books = self.run_sql(u'SELECT id, testament_id, name, ' + u'abbreviation FROM book WHERE LOWER(name) = ? OR ' + u'LOWER(abbreviation) = ?', (name.lower(), name.lower())) + if books: + return { + u'id': books[0][0], + u'testament_id': books[0][1], + u'name': unicode(books[0][2]), + u'abbreviation': unicode(books[0][3]) + } + else: + return None + def get_books(self): """ Returns the books of the Bible. diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index edb111d93..76a99ea50 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -109,7 +109,7 @@ class BGExtract(object): try: clean_verse_num = int(str(raw_verse_num)) except ValueError: - log.exception(u'Illegal verse number in %s %s %s:%s', + log.warn(u'Illegal verse number in %s %s %s:%s', version, bookname, chapter, unicode(raw_verse_num)) if clean_verse_num: verse_text = raw_verse_num.next @@ -139,16 +139,17 @@ class BGExtract(object): """ log.debug(u'BGExtract.get_books_from_http("%s")', version) url_params = urllib.urlencode( - {u'search': 'Bible-List', u'version': u'%s' % version}) - reference_url = u'http://www.biblegateway.com/passage/?%s' % url_params + {u'action': 'getVersionInfo', u'vid': u'%s' % version}) + reference_url = u'http://www.biblegateway.com/versions/?%s#books' % \ + url_params page = get_web_page(reference_url) if not page: send_error_message(u'download') return None page_source = page.read() page_source = unicode(page_source, 'utf8') - page_source_temp = re.search(u'