1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
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. *
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. *
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 ***************************************************************************/
21 * @file KwBiblePassage.cpp
22 * @brief A passage of rendered bible text.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwBiblePassage.h"
31 * Constructors + destructor
34 /// Default constructor.
35 KwBiblePassage::KwBiblePassage()
45 /// Fill the passage from a given module.
46 KwBiblePassage::KwBiblePassage(const QString
& managerId
, const QString
& moduleId
, const KwBibleModule::Key
& key
)
47 : m_managerId(managerId
)
48 , m_moduleId(moduleId
)
54 /// @todo Iterate through the verses getting the data.
58 KwBiblePassage::~KwBiblePassage()
60 // Deep cleanup operation
61 for (int bookIndex
= 0; bookIndex
< m_numBooks
; ++bookIndex
)
63 Book
* book
= &m_books
[bookIndex
];
64 for (int chapterIndex
= 0; chapterIndex
< book
->numChapters
; ++chapterIndex
)
66 Chapter
* chapter
= &book
->chapters
[chapterIndex
];
67 delete chapter
->verses
;
69 delete book
->chapters
;
78 /// Get textual key of this passage.
79 QString
KwBiblePassage::textualKey() const
84 return i18nc("empty bible passage", "empty");
86 Q_ASSERT(m_books
[0].numChapters
> 0);
87 Q_ASSERT(m_books
[0].chapters
[0].numVerses
> 0);
89 QString result
= i18nc("bible index (book, chapter:verse)", "%1 %2",
91 i18nc("bible index (chapter:verse)", "%1:%2",
92 m_books
[0].firstChapter
,
93 m_books
[0].chapters
[0].firstVerse
));
94 Book
* lastBook
= &m_books
[m_numBooks
- 1];
95 Chapter
* lastChapter
= &lastBook
->chapters
[lastBook
->numChapters
- 1];
96 // Overlapping multiple books
99 result
= i18nc("bible passage range (book chapter:verse, book chapter:verse)", "%1 - %2", result
,
100 i18nc("bible index (book, chapter:verse)", "%1 %2",
102 i18nc("bible index (chapter:verse)", "%1:%2",
103 lastBook
->firstChapter
+ lastBook
->numChapters
- 1,
104 lastChapter
->firstVerse
+ lastChapter
->numVerses
- 1)));
106 // Overlapping multiple chapters
107 else if (lastBook
->numChapters
> 1)
109 result
= i18nc("bible passage range (book chapter:verse, chapter:verse)", "%1 - %2", result
,
110 i18nc("bible index (chapter:verse)", "%1:%2",
111 lastBook
->firstChapter
+ lastBook
->numChapters
- 1,
112 lastChapter
->firstVerse
+ lastChapter
->numVerses
- 1));
114 // Overlapping multiple verses
115 else if (lastChapter
->numVerses
> 1)
117 result
= i18nc("bible passage range (book chapter:verse, verse)", "%1-%2", result
,
118 lastChapter
->firstVerse
+ lastChapter
->numVerses
- 1);
121 // Module name is quite important too
122 return i18nc("bible index (range, version)", "%1 (%2)", result
, m_moduleId
);