Added KwBiblePassage and label bible passage playlist item
[kworship.git] / kworship / bible / KwBiblePassage.cpp
blob3470a70da741ec9bf09a0efa5ed8538bc203e015
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 KwBiblePassage.cpp
22 * @brief A passage of rendered bible text.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwBiblePassage.h"
28 #include <KLocale>
31 * Constructors + destructor
34 /// Default constructor.
35 KwBiblePassage::KwBiblePassage()
36 : m_managerId()
37 , m_moduleId()
38 , m_key()
39 , m_firstBook(0)
40 , m_numBooks(0)
41 , m_books(0)
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)
49 , m_key(key)
50 , m_firstBook(0)
51 , m_numBooks(0)
52 , m_books(0)
54 /// @todo Iterate through the verses getting the data.
57 /// Destructor.
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;
71 delete m_books;
75 * Main interface
78 /// Get textual key of this passage.
79 QString KwBiblePassage::textualKey() const
81 // Empty range
82 if (0 == m_numBooks)
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",
90 m_books[0].name,
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
97 if (m_numBooks > 1)
99 result = i18nc("bible passage range (book chapter:verse, book chapter:verse)", "%1 - %2", result,
100 i18nc("bible index (book, chapter:verse)", "%1 %2",
101 lastBook->name,
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);