1/*
2 Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
3 Copyright (C) 2002-2005 Benjamin Meyer <ben-devel@meyerhome.net>
4 Copyright (C) 2002-2004 Nadeem Hasan <nhasan@nadmm.com>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#ifndef KCDDB_CDINFO_H
23#define KCDDB_CDINFO_H
24
25#include <QtCore/QStringList>
26#include <QtCore/QVariant>
27#include <libkcddb/kcddb_export.h>
28
29namespace KCDDB
30{
31 /**
32 * The most common types
33 */
34 enum Type
35 {
36 Title, /**< The title of the track or CD */
37 Comment, /**< A comment for the track or CD */
38 Artist, /**< The artist of the track or CD */
39 Genre, /**< The genre of the track or CD */
40 Year, /**< The year the cd or track was produced
41 By default, the year of the track is the
42 same as for the whole cd
43 @todo Doesn't do that for tracks right now.*/
44 Length, /**< The length of a track or a full CD
45 @todo In what unit? */
46 Category /**< The freedb category of the entry.
47 Needs to be one of: blues, classical,
48 country, data, fold, jazz, misc, newage,
49 reggae, rock, soundtrack */
50 };
51
52 /**
53 * Information about a sepecific track in a cd.
54 */
55 class KCDDB_EXPORT TrackInfo
56 {
57 public:
58
59 TrackInfo();
60 virtual ~TrackInfo();
61 TrackInfo(const TrackInfo& clone);
62 TrackInfo& operator=(const TrackInfo& clone);
63
64 bool operator==(const TrackInfo&) const;
65 bool operator!=(const TrackInfo&) const;
66
67 /**
68 * Get data for type that has been assigned to this track.
69 * @p type is case insensitive.
70 * For example <code>get("title")</code>
71 */
72 QVariant get(const QString &type) const;
73 /**
74 * Helper function that calls type with the common name
75 */
76 QVariant get(Type type) const;
77
78 /**
79 * Set any data from this track.
80 * @p type is case insensitive.
81 * For example <code>set("title", "Rock this world")</code>
82 * Useful for atributes that other apps want to add.
83 * Data will be stored in the local cddb cache, but not sent to the cddb server
84 */
85 void set(const QString &type, const QVariant &data);
86 /**
87 * Helper function that calls type with the common name
88 */
89 void set(Type type, const QVariant &data);
90
91 /**
92 * @return a CDDB compatible string of all the data assigned to this track
93 * tracknumber must be assigned before calling this.
94 */
95 QString toString() const;
96
97 /**
98 * internal
99 */
100 void clear();
101
102 private:
103 class TrackInfoPrivate *d;
104
105 };
106
107 typedef QList<TrackInfo> TrackInfoList;
108
109 /**
110 * Information about a CD
111 *
112 * Typically CDInfo is obtained from the client such as:
113 * <code>KCDDB::Client *cddb = new KCDDB::Client();
114 * cddb->lookup(discSignature);
115 * CDInfo info = cddb->lookupResponse().first();</code>
116 */
117 class KCDDB_EXPORT CDInfo
118 {
119 public:
120 CDInfo();
121 virtual ~CDInfo();
122
123 CDInfo(const CDInfo& clone);
124 CDInfo& operator=(const CDInfo& clone);
125
126 bool operator==(const CDInfo&) const;
127 bool operator!=(const CDInfo&) const;
128
129 /**
130 * Load CDInfo from a string that is CDDB compatible
131 * @return true if successful
132 */
133 bool load(const QString &string);
134 /**
135 * Load CDInfo from a stringList that is CDDB compatible
136 * @return true if successful
137 */
138 bool load(const QStringList &stringList);
139
140 /**
141 * Clear all information, setting this to invalid
142 * internal
143 */
144 void clear();
145
146 /**
147 * @return true if the cd information is valid
148 */
149 bool isValid() const;
150
151 /**
152 * @param submit If submit is true only returns CDDB compatible information
153 * @return a string containing all of the CD's information.
154 */
155 QString toString(bool submit=false) const;
156
157 /**
158 * Get data for type that has been assigned to this disc.
159 * @p type is case insensitive.
160 * For example <code>get("title")</code>
161 */
162 QVariant get(const QString &type) const;
163 /**
164 * Helper function that calls type with the common name
165 */
166 QVariant get(Type type) const;
167
168 /**
169 * Set any data from this disc.
170 * @p type is case insensitive.
171 * For example <code>set("title", "Rock this world")</code>
172 * Useful for atributes that other apps want to add.
173 * Data will be stored in the local cddb cache, but not sent to the cddb server
174 */
175 void set(const QString &type, const QVariant &data);
176 /**
177 * Helper function that calls type with the common name
178 */
179 void set(Type type, const QVariant &data);
180
181 /**
182 * Returns track with nr @p trackNumber and adds it to
183 * the track list if it doesn't exist (first track is 0)
184 */
185 TrackInfo & track( int trackNumber );
186
187 /**
188 * Returns a const track with nr @p trackNumber
189 * or a new if it doesn't exist (first track is 0)
190 */
191 TrackInfo track( int trackNumber ) const;
192
193 /**
194 * Returns number of tracks on CD
195 */
196 int numberOfTracks() const;
197
198 protected:
199 /**
200 * Checks to make sure that trackNumber exists
201 */
202 void checkTrack( int trackNumber );
203
204 private:
205 class CDInfoPrivate * const d;
206 };
207
208 typedef QList<CDInfo> CDInfoList;
209}
210
211#endif // KCDDB_CDINFO_H
212// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
213