2011-03-20 20:50:19 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-01-01 16:33:41 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
2011-03-20 20:50:19 +00:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2015-12-31 22:46:06 +00:00
|
|
|
# Copyright (c) 2008-2016 OpenLP Developers #
|
2011-03-20 20:50:19 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
|
2015-04-07 22:01:52 +00:00
|
|
|
from openlp.plugins.bibles.lib import get_reference_separator
|
|
|
|
|
2013-10-13 21:07:28 +00:00
|
|
|
|
2011-03-20 20:50:19 +00:00
|
|
|
class VerseReferenceList(object):
|
|
|
|
"""
|
2013-04-18 17:45:14 +00:00
|
|
|
The VerseReferenceList class encapsulates a list of verse references, but maintains the order in which they were
|
|
|
|
added.
|
2011-03-20 20:50:19 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.verse_list = []
|
|
|
|
self.version_list = []
|
|
|
|
self.current_index = -1
|
|
|
|
|
|
|
|
def add(self, book, chapter, verse, version, copyright, permission):
|
|
|
|
self.add_version(version, copyright, permission)
|
2013-08-31 18:17:38 +00:00
|
|
|
if not self.verse_list or self.verse_list[self.current_index]['book'] != book:
|
2014-03-09 10:26:28 +00:00
|
|
|
self.verse_list.append({'version': version, 'book': book, 'chapter': chapter, 'start': verse, 'end': verse})
|
2011-03-20 20:50:19 +00:00
|
|
|
self.current_index += 1
|
2013-08-31 18:17:38 +00:00
|
|
|
elif self.verse_list[self.current_index]['chapter'] != chapter:
|
2014-03-09 10:26:28 +00:00
|
|
|
self.verse_list.append({'version': version, 'book': book, 'chapter': chapter, 'start': verse, 'end': verse})
|
2011-03-20 20:50:19 +00:00
|
|
|
self.current_index += 1
|
2013-08-31 18:17:38 +00:00
|
|
|
elif (self.verse_list[self.current_index]['end'] + 1) == verse:
|
|
|
|
self.verse_list[self.current_index]['end'] = verse
|
2011-03-20 20:50:19 +00:00
|
|
|
else:
|
2014-03-09 10:26:28 +00:00
|
|
|
self.verse_list.append({'version': version, 'book': book, 'chapter': chapter, 'start': verse, 'end': verse})
|
2011-03-20 20:50:19 +00:00
|
|
|
self.current_index += 1
|
|
|
|
|
|
|
|
def add_version(self, version, copyright, permission):
|
|
|
|
for bible_version in self.version_list:
|
2013-08-31 18:17:38 +00:00
|
|
|
if bible_version['version'] == version:
|
2011-03-20 20:50:19 +00:00
|
|
|
return
|
2013-08-31 18:17:38 +00:00
|
|
|
self.version_list.append({'version': version, 'copyright': copyright, 'permission': permission})
|
2011-03-20 20:50:19 +00:00
|
|
|
|
|
|
|
def format_verses(self):
|
2015-04-07 22:01:52 +00:00
|
|
|
verse_sep = get_reference_separator('sep_v_display')
|
|
|
|
range_sep = get_reference_separator('sep_r_display')
|
|
|
|
list_sep = get_reference_separator('sep_l_display')
|
2013-08-31 18:17:38 +00:00
|
|
|
result = ''
|
2011-03-20 20:50:19 +00:00
|
|
|
for index, verse in enumerate(self.verse_list):
|
|
|
|
if index == 0:
|
2015-04-07 22:01:52 +00:00
|
|
|
result = '%s %s%s%s' % (verse['book'], verse['chapter'], verse_sep, verse['start'])
|
2013-08-31 18:17:38 +00:00
|
|
|
if verse['start'] != verse['end']:
|
2015-04-07 22:01:52 +00:00
|
|
|
result = '%s%s%s' % (result, range_sep, verse['end'])
|
2011-03-20 20:50:19 +00:00
|
|
|
continue
|
|
|
|
prev = index - 1
|
2013-08-31 18:17:38 +00:00
|
|
|
if self.verse_list[prev]['version'] != verse['version']:
|
|
|
|
result = '%s (%s)' % (result, self.verse_list[prev]['version'])
|
2015-04-07 22:01:52 +00:00
|
|
|
result += '%s ' % list_sep
|
2013-08-31 18:17:38 +00:00
|
|
|
if self.verse_list[prev]['book'] != verse['book']:
|
2015-04-07 22:01:52 +00:00
|
|
|
result = '%s%s %s%s' % (result, verse['book'], verse['chapter'], verse_sep)
|
2013-08-31 18:17:38 +00:00
|
|
|
elif self.verse_list[prev]['chapter'] != verse['chapter']:
|
2015-04-07 22:01:52 +00:00
|
|
|
result = '%s%s%s' % (result, verse['chapter'], verse_sep)
|
2013-08-31 18:17:38 +00:00
|
|
|
result += str(verse['start'])
|
|
|
|
if verse['start'] != verse['end']:
|
2015-04-07 22:01:52 +00:00
|
|
|
result = '%s%s%s' % (result, range_sep, verse['end'])
|
2011-03-20 20:50:19 +00:00
|
|
|
if len(self.version_list) > 1:
|
2013-08-31 18:17:38 +00:00
|
|
|
result = '%s (%s)' % (result, verse['version'])
|
2011-03-20 20:50:19 +00:00
|
|
|
return result
|
|
|
|
|
2015-04-07 22:01:52 +00:00
|
|
|
def format_versions(self, copyright=True, permission=True):
|
|
|
|
"""
|
|
|
|
Format a string with the bible versions used
|
|
|
|
|
|
|
|
:param copyright: If the copyright info should be included, default is true.
|
|
|
|
:param permission: If the permission info should be included, default is true.
|
|
|
|
:return: A formatted string with the bible versions used
|
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
result = ''
|
2011-03-20 20:50:19 +00:00
|
|
|
for index, version in enumerate(self.version_list):
|
|
|
|
if index > 0:
|
2013-08-31 18:17:38 +00:00
|
|
|
if result[-1] not in [';', ',', '.']:
|
|
|
|
result += ';'
|
|
|
|
result += ' '
|
2015-02-13 20:19:05 +00:00
|
|
|
result += version['version']
|
2015-04-07 22:01:52 +00:00
|
|
|
if copyright and version['copyright'].strip():
|
2015-02-13 20:19:05 +00:00
|
|
|
result += ', ' + version['copyright']
|
2015-04-07 22:01:52 +00:00
|
|
|
if permission and version['permission'].strip():
|
2015-02-13 20:19:05 +00:00
|
|
|
result += ', ' + version['permission']
|
2011-04-10 06:27:23 +00:00
|
|
|
result = result.rstrip()
|
2013-08-31 18:17:38 +00:00
|
|
|
if result.endswith(','):
|
2014-04-12 20:19:22 +00:00
|
|
|
return result[:len(result) - 1]
|
2011-03-20 20:50:19 +00:00
|
|
|
return result
|