Simplified lyrics storage into a string instead of complex verses
[kworship.git] / kworship / songdb / KwSongdbVersion.cpp
blob8faf9ee23b6c4761b60c5ad9f5dab6fa033f03d3
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 KwSongdbVersion.cpp
22 * @brief A song version from the database.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwSongdb.h"
27 #include "KwSongdbVersion.h"
29 #include <KLocale>
31 #include <QSqlQuery>
32 #include <QVariant>
34 #include <cassert>
37 * Constructors + destructor
40 /// Primary constructor.
41 KwSongdbVersion::KwSongdbVersion(int id)
42 : m_id(id)
43 , m_song(0)
44 , m_name()
45 , m_writer()
46 , m_copyright()
47 , m_lyrics()
49 // Get the song version data
50 QSqlQuery query(KwSongdb::self()->database());
51 query.prepare("SELECT song_id, name, writer, copyright, lyrics, css_style_sheet_id "
52 "FROM SongVersion "
53 "WHERE id = ?");
54 query.addBindValue(QVariant(id));
55 bool worked = query.exec();
56 assert(worked);
58 // Copy the data
59 assert(query.first());
60 m_song = KwSongdb::self()->songById(query.value(0).toInt());
61 m_name = query.value(1).toString();
62 m_writer = query.value(2).toString();
63 m_copyright = query.value(3).toString();
64 m_lyrics.setMarkup(query.value(4).toString());
67 /// Destructor.
68 KwSongdbVersion::~KwSongdbVersion()
73 * Accessors
76 /// Get the song this is a version of.
77 KwSongdbSong* KwSongdbVersion::song()
79 return m_song;
82 /// Get the name of this version.
83 QString KwSongdbVersion::name() const
85 return m_name;
88 /// Get a non-empty name of this version.
89 QString KwSongdbVersion::niceName() const
91 if (m_name.isEmpty())
93 return i18n("Default version");
95 else
97 return m_name;
101 /// Get the name of the writer.
102 QString KwSongdbVersion::writer() const
104 return m_writer;
107 /// Get the copyright notice.
108 QString KwSongdbVersion::copyright() const
110 return m_copyright;
113 /// Get the copyright notice.
114 const KwSongdbLyrics& KwSongdbVersion::lyrics() const
116 return m_lyrics;