More definition of bible module structure
[kworship.git] / kworship / bible / KwBibleModule.cpp
blob35efa062b9a46f5840a387e5de7fbeef8801bb78
1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 /**
21 * @file KwBibleModule.cpp
22 * @brief An abstract bible module (analagous to a SWORD module).
23 * @author James Hogan <james@albanarts.com>
26 #include "KwBibleModule.h"
29 * Constructors + destructor
32 /// Default constructor.
33 KwBibleModule::KwBibleModule()
34 : m_books()
38 /// Destructor.
39 KwBibleModule::~KwBibleModule()
44 * Main interface
47 /// Create a key from a string.
48 KwBibleModule::Key KwBibleModule::createKey(const QString& text)
50 // parse the key
51 //Key key = { { -1, -1, -1 },
52 // { -1, -1, -1 } };
53 Key key = { { 0, 1, 1 },
54 { 0, 1, 6 } };
55 return key;
58 /// Create a key from individual values.
59 KwBibleModule::Key KwBibleModule::createKey(const QString& book, int chapter, int verse)
61 int bookId = bookIndex(book);
62 Key key = { { bookId, chapter, verse },
63 { -1, -1, -1 } };
64 return key;
67 /// Create a range key between two verses in the same chapter.
68 KwBibleModule::Key KwBibleModule::createKey(const QString& book, int chapter, int verseStart,
69 int verseEnd)
71 int bookId = bookIndex(book);
72 Key key = { { bookId, chapter, verseStart },
73 { bookId, chapter, verseEnd } };
74 return key;
77 /// Create a range key between two verses in different chapters.
78 KwBibleModule::Key KwBibleModule::createKey(const QString& book, int chapterStart, int verseStart,
79 int chapterEnd, int verseEnd)
81 int bookId = bookIndex(book);
82 Key key = { { bookId, chapterStart, verseStart },
83 { bookId, chapterEnd, verseEnd } };
84 return key;
87 /// Create a range key between two verses in different books.
88 KwBibleModule::Key KwBibleModule::createKey(const QString& bookStart, int chapterStart, int verseStart,
89 const QString& bookEnd, int chapterEnd, int verseEnd)
91 int bookIdStart = bookIndex(bookStart);
92 int bookIdEnd = bookIndex(bookEnd);
93 Key key = { { bookIdStart, chapterStart, verseStart },
94 { bookIdEnd, chapterEnd, verseEnd } };
95 return key;
98 /// List the books in this module.
99 const QStringList& KwBibleModule::books()
101 if (m_books.isEmpty())
103 obtainBooks();
105 return m_books;
108 /// Get the index of a book from it's name.
109 int KwBibleModule::bookIndex(const QString& name)
111 if (m_books.isEmpty())
113 obtainBooks();
115 return m_books.indexOf(name);
118 /// Get the name of a book from it's index.
119 QString KwBibleModule::bookName(int book)
121 if (m_books.isEmpty())
123 obtainBooks();
125 if (book >= 0 && book < m_books.size())
127 return m_books[book];
129 else
131 return QString();
136 * Protected virtual interface
139 /// Ensure that the book list is up to date.
140 void KwBibleModule::obtainBooks()
145 * Protected interface
148 /// Update the list of books.
149 void KwBibleModule::setBooks(const QStringList& books)
151 m_books = books;