forked from openlp/openlp
Hook it all together
This commit is contained in:
parent
1f41039e07
commit
2cabfc67f3
@ -26,3 +26,5 @@
|
||||
from manager import SongManager
|
||||
from songstab import SongsTab
|
||||
from mediaitem import SongMediaItem
|
||||
from sofimport import SofImport
|
||||
from songimport import SongImport
|
||||
|
@ -133,6 +133,12 @@ class SongManager():
|
||||
"""
|
||||
return self.session.query(Author).get(id)
|
||||
|
||||
def get_author_by_name(self, name):
|
||||
"""
|
||||
Get author by display name
|
||||
"""
|
||||
return self.session.query(Author).filter_by(display_name=name).first()
|
||||
|
||||
def save_author(self, author):
|
||||
"""
|
||||
Save the Author and refresh the cache
|
||||
@ -172,6 +178,12 @@ class SongManager():
|
||||
"""
|
||||
return self.session.query(Topic).get(id)
|
||||
|
||||
def get_topic_by_name(self, name):
|
||||
"""
|
||||
Get topic by name
|
||||
"""
|
||||
return self.session.query(Topic).filter_by(name=name).first()
|
||||
|
||||
def save_topic(self, topic):
|
||||
"""
|
||||
Save the Topic
|
||||
@ -211,6 +223,12 @@ class SongManager():
|
||||
"""
|
||||
return self.session.query(Book).get(id)
|
||||
|
||||
def get_book_by_name(self, name):
|
||||
"""
|
||||
Get book by name
|
||||
"""
|
||||
return self.session.query(Book).filter_by(name=name).first()
|
||||
|
||||
def save_book(self, book):
|
||||
"""
|
||||
Save the Book
|
||||
|
@ -73,6 +73,12 @@ class SofImport(object):
|
||||
self.song = None
|
||||
self.manager = songmanager
|
||||
|
||||
def import_sof(self, filename):
|
||||
self.start_ooo()
|
||||
self.open_ooo_file(filename)
|
||||
self.process_doc()
|
||||
self.close_ooo()
|
||||
|
||||
def start_ooo(self):
|
||||
"""
|
||||
Start OpenOffice.org process
|
||||
@ -270,16 +276,16 @@ class SofImport(object):
|
||||
self.song.set_song_number(song_no)
|
||||
if int(song_no) <= 640:
|
||||
self.song.set_song_book(u'Songs of Fellowship 1',
|
||||
'Kingsway\'s Thankyou Music')
|
||||
u'Kingsway Publications')
|
||||
elif int(song_no) <= 1150:
|
||||
self.song.set_song_book(u'Songs of Fellowship 2',
|
||||
'Kingsway\'s Thankyou Music')
|
||||
u'Kingsway Publications')
|
||||
elif int(song_no) <= 1690:
|
||||
self.song.set_song_book(u'Songs of Fellowship 3',
|
||||
'Kingsway\'s Thankyou Music')
|
||||
u'Kingsway Publications')
|
||||
else:
|
||||
self.song.set_song_book(u'Songs of Fellowship 4',
|
||||
'Kingsway\'s Thankyou Music')
|
||||
u'Kingsway Publications')
|
||||
|
||||
def add_title(self, text):
|
||||
"""
|
||||
@ -506,16 +512,4 @@ class SofImport(object):
|
||||
if song_number == 1117: return 6
|
||||
if song_number == 1119: return 7
|
||||
return None
|
||||
|
||||
#config = None
|
||||
man = None
|
||||
#man = SongManager(config)
|
||||
sof = SofImport(man)
|
||||
sof.start_ooo()
|
||||
#sof.open_ooo_file(u'/home/jonathan/sof.rtf')
|
||||
sof.open_ooo_file(u'/home/jonathan/Documents/VOLS1_2.RTF')
|
||||
#sof.open_ooo_file(u'c:\users\jonathan\Desktop\sof3words.rtf')
|
||||
#sof.open_ooo_file(u'c:\users\jonathan\Desktop\sof4words.rtf')
|
||||
sof.process_doc()
|
||||
sof.close_ooo()
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
import string
|
||||
from openlp.core.lib import SongXMLBuilder
|
||||
from openlp.plugins.songs.lib.models import Song
|
||||
from openlp.plugins.songs.lib.models import Song, Author, Topic, Book
|
||||
|
||||
class SongImport(object):
|
||||
"""
|
||||
@ -43,7 +43,7 @@ class SongImport(object):
|
||||
song_manager is an instance of a SongManager, through which all
|
||||
database access is performed
|
||||
"""
|
||||
self.song_manager = song_manager
|
||||
self.manager = song_manager
|
||||
self.title = u''
|
||||
self.song_number = u''
|
||||
self.copyright = u''
|
||||
@ -153,8 +153,10 @@ class SongImport(object):
|
||||
def remove_punctuation(self, text):
|
||||
"""
|
||||
Remove punctuation from the string for searchable fields
|
||||
"""
|
||||
return text.translate(string.maketrans(u'',u''), string.punctuation)
|
||||
"""
|
||||
for c in string.punctuation:
|
||||
text = text.replace(c, u'')
|
||||
return text
|
||||
|
||||
def finish(self):
|
||||
"""
|
||||
@ -162,10 +164,10 @@ class SongImport(object):
|
||||
"""
|
||||
if len(self.authors) == 0:
|
||||
self.authors.append(u'Author unknown')
|
||||
#self.commit_song()
|
||||
self.print_song()
|
||||
self.commit_song()
|
||||
#self.print_song()
|
||||
|
||||
def commit_song():
|
||||
def commit_song(self):
|
||||
"""
|
||||
Write the song and it's fields to disk
|
||||
"""
|
||||
@ -201,33 +203,30 @@ class SongImport(object):
|
||||
song.theme_name = self.theme_name
|
||||
song.ccli_number = self.ccli_number
|
||||
for authortext in self.authors:
|
||||
author = None
|
||||
# read the author here
|
||||
author = self.manager.get_author_by_name(authortext)
|
||||
if author is None:
|
||||
author = Author()
|
||||
author.display_name = authortext
|
||||
author.last_name = authortext.split(u' ')[-1]
|
||||
author.first_name = u' '.join(authortext.split(u' ')[:-1])
|
||||
# write the author here
|
||||
self.manager.save_author(author)
|
||||
song.authors.append(author)
|
||||
if self.song_book_name:
|
||||
song_book = None
|
||||
# read the book here
|
||||
song_book = self.manager.get_book_by_name(self.song_book_name)
|
||||
if song_book is None:
|
||||
song_book = Book()
|
||||
song_book.name = self.song_book_name
|
||||
song_book.publisher = self.song_book_pub
|
||||
# write the song book here
|
||||
self.manager.save_book(song_book)
|
||||
song.song_book_id = song_book.id
|
||||
for topictext in self.topics:
|
||||
topic = None
|
||||
# read the topic here
|
||||
topic = self.manager.get_topic_by_name(topictext)
|
||||
if topic is None:
|
||||
topic = Topic()
|
||||
topic.name = topictext
|
||||
# write the topic here
|
||||
song.topics.append(topictext)
|
||||
# write the song here
|
||||
topic.name = topictext
|
||||
self.manager.save_topic(topic)
|
||||
song.topics.append(topictext)
|
||||
self.manager.save_song(song)
|
||||
|
||||
def print_song(self):
|
||||
"""
|
||||
@ -245,6 +244,8 @@ class SongImport(object):
|
||||
print u'COPYRIGHT: ' + self.copyright
|
||||
if self.song_book_name:
|
||||
print u'BOOK: ' + self.song_book_name
|
||||
if self.song_book_pub:
|
||||
print u'BOOK PUBLISHER: ' + self.song_book_pub
|
||||
if self.song_number:
|
||||
print u'NUMBER: ' + self.song_number
|
||||
for topictext in self.topics:
|
||||
|
@ -28,7 +28,8 @@ import logging
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
from openlp.core.lib import Plugin, build_icon, PluginStatus
|
||||
from openlp.plugins.songs.lib import SongManager, SongMediaItem, SongsTab
|
||||
from openlp.plugins.songs.lib import SongManager, SongMediaItem, SongsTab, \
|
||||
SofImport
|
||||
from openlp.plugins.songs.forms import OpenLPImportForm, OpenSongExportForm, \
|
||||
OpenSongImportForm, OpenLPExportForm
|
||||
|
||||
@ -102,24 +103,35 @@ class SongsPlugin(Plugin):
|
||||
self.ImportOpenlp1Item.setObjectName(u'ImportOpenlp1Item')
|
||||
self.ImportOpenlp2Item = QtGui.QAction(import_menu)
|
||||
self.ImportOpenlp2Item.setObjectName(u'ImportOpenlp2Item')
|
||||
self.ImportSofItem = QtGui.QAction(import_menu)
|
||||
self.ImportSofItem.setObjectName(u'ImportSofItem')
|
||||
# Add to menus
|
||||
self.ImportSongMenu.addAction(self.ImportOpenlp1Item)
|
||||
self.ImportSongMenu.addAction(self.ImportOpenlp2Item)
|
||||
self.ImportSongMenu.addAction(self.ImportOpenSongItem)
|
||||
self.ImportSongMenu.addAction(self.ImportSofItem)
|
||||
import_menu.addAction(self.ImportSongMenu.menuAction())
|
||||
# Translations...
|
||||
self.ImportSongMenu.setTitle(import_menu.trUtf8('&Song'))
|
||||
self.ImportOpenSongItem.setText(import_menu.trUtf8('OpenSong'))
|
||||
self.ImportOpenlp1Item.setText(import_menu.trUtf8('openlp.org 1.0'))
|
||||
self.ImportOpenlp1Item.setToolTip(
|
||||
import_menu.trUtf8('Export songs in openlp.org 1.0 format'))
|
||||
import_menu.trUtf8('Import songs in openlp.org 1.0 format'))
|
||||
self.ImportOpenlp1Item.setStatusTip(
|
||||
import_menu.trUtf8('Export songs in openlp.org 1.0 format'))
|
||||
import_menu.trUtf8('Import songs in openlp.org 1.0 format'))
|
||||
self.ImportOpenlp2Item.setText(import_menu.trUtf8('OpenLP 2.0'))
|
||||
self.ImportOpenlp2Item.setToolTip(
|
||||
import_menu.trUtf8('Export songs in OpenLP 2.0 format'))
|
||||
import_menu.trUtf8('Import songs in OpenLP 2.0 format'))
|
||||
self.ImportOpenlp2Item.setStatusTip(
|
||||
import_menu.trUtf8('Export songs in OpenLP 2.0 format'))
|
||||
import_menu.trUtf8('Import songs in OpenLP 2.0 format'))
|
||||
self.ImportSofItem.setText(
|
||||
import_menu.trUtf8('Songs of Fellowship'))
|
||||
self.ImportSofItem.setToolTip(
|
||||
import_menu.trUtf8('Import songs from the VOLS1_2.RTF, sof3words' \
|
||||
+ '.rtf and sof4words.rtf supplied with the music books'))
|
||||
self.ImportSofItem.setStatusTip(
|
||||
import_menu.trUtf8('Import songs from the VOLS1_2.RTF, sof3words' \
|
||||
+ '.rtf and sof4words.rtf supplied with the music books'))
|
||||
# Signals and slots
|
||||
QtCore.QObject.connect(self.ImportOpenlp1Item,
|
||||
QtCore.SIGNAL(u'triggered()'), self.onImportOpenlp1ItemClick)
|
||||
@ -127,6 +139,8 @@ class SongsPlugin(Plugin):
|
||||
QtCore.SIGNAL(u'triggered()'), self.onImportOpenlp1ItemClick)
|
||||
QtCore.QObject.connect(self.ImportOpenSongItem,
|
||||
QtCore.SIGNAL(u'triggered()'), self.onImportOpenSongItemClick)
|
||||
QtCore.QObject.connect(self.ImportSofItem,
|
||||
QtCore.SIGNAL(u'triggered()'), self.onImportSofItemClick)
|
||||
self.ImportSongMenu.menuAction().setVisible(False)
|
||||
|
||||
def add_export_menu_item(self, export_menu):
|
||||
@ -169,6 +183,13 @@ class SongsPlugin(Plugin):
|
||||
def onImportOpenSongItemClick(self):
|
||||
self.opensong_import_form.show()
|
||||
|
||||
def onImportSofItemClick(self):
|
||||
filename = QtGui.QFileDialog.getOpenFileName(
|
||||
None, self.trUtf8('Open Songs of Fellowship file'),
|
||||
u'', u'Songs of Fellowship file (*.rtf *.RTF)')
|
||||
sofimport = SofImport(self.songmanager)
|
||||
sofimport.import_sof(unicode(filename))
|
||||
|
||||
def onExportOpenlp1ItemClicked(self):
|
||||
self.openlp_export_form.show()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user