~ubuntu-branches/ubuntu/wily/kid3/wily-proposed

« back to all changes in this revision

Viewing changes to kid3/importtrackdata.h

  • Committer: Package Import Robot
  • Author(s): Ana Beatriz Guerrero Lopez, Patrick Matthäi, Ana Beatriz Guerrero Lopez
  • Date: 2011-11-13 16:34:13 UTC
  • mfrom: (1.1.13) (2.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20111113163413-5y0anlc4dqf511uh
Tags: 2.0.1-1
* New upstream release.

[ Patrick Matthäi ]
* Adjust build system.
* Add build dependency xsltproc.

[ Ana Beatriz Guerrero Lopez ]
* Some more adjustments to the build system taken from upstream's deb/
* directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * \file importtrackdata.h
3
 
 * Track data used for import.
4
 
 *
5
 
 * \b Project: Kid3
6
 
 * \author Urs Fleisch
7
 
 * \date 7 Jul 2005
8
 
 *
9
 
 * Copyright (C) 2005-2009  Urs Fleisch
10
 
 *
11
 
 * This file is part of Kid3.
12
 
 *
13
 
 * Kid3 is free software; you can redistribute it and/or modify
14
 
 * it under the terms of the GNU General Public License as published by
15
 
 * the Free Software Foundation; either version 2 of the License, or
16
 
 * (at your option) any later version.
17
 
 *
18
 
 * Kid3 is distributed in the hope that it will be useful,
19
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 
 * GNU General Public License for more details.
22
 
 *
23
 
 * You should have received a copy of the GNU General Public License
24
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
 
 */
26
 
 
27
 
#ifndef IMPORTTRACKDATA_H
28
 
#define IMPORTTRACKDATA_H
29
 
 
30
 
#include "frame.h"
31
 
#include "taggedfile.h"
32
 
#include <qglobal.h>
33
 
#include "qtcompatmac.h"
34
 
#if QT_VERSION >= 0x040000
35
 
#include <QVector>
36
 
#else
37
 
#include <qvaluevector.h>
38
 
#endif
39
 
 
40
 
/**
41
 
 * Track data used for import.
42
 
 */
43
 
class ImportTrackData : public FrameCollection {
44
 
public:
45
 
        /**
46
 
         * Constructor.
47
 
         * @param absFilename  absolute filename
48
 
         * @param fileDuration duration in seconds
49
 
         */
50
 
        explicit ImportTrackData(const QString& absFilename = QString::null,
51
 
                                                                                                         int fileDuration = 0) :
52
 
                m_fileDuration(fileDuration), m_importDuration(0),
53
 
                m_absFilename(absFilename) {}
54
 
 
55
 
        /**
56
 
         * Constructor.
57
 
         * All fields except the import duration are set from the tagged file,
58
 
         * which should be read using readTags() before. The frames are merged
59
 
         * from tag 2 and tag 1 (where tag 2 is not set).
60
 
         *
61
 
         * @param taggedFile tagged file providing track data
62
 
         */
63
 
        ImportTrackData(TaggedFile& taggedFile);
64
 
 
65
 
        /**
66
 
         * Destructor.
67
 
         */
68
 
        ~ImportTrackData() {}
69
 
 
70
 
        /**
71
 
         * Get duration of file.
72
 
         * @return duration of file.
73
 
         */
74
 
        int getFileDuration() const { return m_fileDuration; }
75
 
 
76
 
        /**
77
 
         * Set duration of file.
78
 
         * @param duration duration of file
79
 
         */
80
 
        void setFileDuration(int duration) { m_fileDuration = duration; }
81
 
 
82
 
        /**
83
 
         * Get duration of import.
84
 
         * @return duration of import.
85
 
         */
86
 
        int getImportDuration() const { return m_importDuration; }
87
 
 
88
 
        /**
89
 
         * Set duration of import.
90
 
         * @param duration duration of import
91
 
         */
92
 
        void setImportDuration(int duration) { m_importDuration = duration; }
93
 
 
94
 
        /**
95
 
         * Get absolute filename.
96
 
         *
97
 
         * @return absolute file path.
98
 
         */
99
 
        QString getAbsFilename() const { return m_absFilename; }
100
 
 
101
 
        /**
102
 
         * Set absolute filename.
103
 
         *
104
 
         * @param absFilename absolute file path
105
 
         */
106
 
        void setAbsFilename(const QString& absFilename) {
107
 
                m_absFilename = absFilename;
108
 
        }
109
 
 
110
 
        /**
111
 
         * Get file extension including the dot.
112
 
         *
113
 
         * @return file extension, e.g. ".mp3".
114
 
         */
115
 
        QString getFileExtension() const;
116
 
 
117
 
        /**
118
 
         * Set file extension.
119
 
         * @param fileExtension file extension
120
 
         */
121
 
        void setFileExtension(const QString& fileExtension) {
122
 
                m_fileExtension = fileExtension;
123
 
        }
124
 
 
125
 
        /**
126
 
         * Get the format of tag 1.
127
 
         *
128
 
         * @return string describing format of tag 1,
129
 
         *         e.g. "ID3v1.1", "ID3v2.3", "Vorbis", "APE",
130
 
         *         QString::null if unknown.
131
 
         */
132
 
        QString getTagFormatV1() const { return m_tagFormatV1; }
133
 
 
134
 
        /**
135
 
         * Set the format of tag 1.
136
 
         * @param tagFormatV1 string describing format of tag 1
137
 
         */
138
 
        void setTagFormatV1(const QString& tagFormatV1) { m_tagFormatV1 = tagFormatV1; }
139
 
 
140
 
        /**
141
 
         * Get the format of tag 2.
142
 
         *
143
 
         * @return string describing format of tag 2,
144
 
         *         e.g. "ID3v2.3", "Vorbis", "APE",
145
 
         *         QString::null if unknown.
146
 
         */
147
 
        QString getTagFormatV2() const { return m_tagFormatV2; }
148
 
 
149
 
        /**
150
 
         * Set the format of tag 2.
151
 
         * @param tagFormatV2 string describing format of tag 2
152
 
         */
153
 
        void setTagFormatV2(const QString& tagFormatV2) { m_tagFormatV2 = tagFormatV2; }
154
 
 
155
 
        /**
156
 
         * Get detail info.
157
 
         * @return detail info.
158
 
         */
159
 
        const TaggedFile::DetailInfo& getDetailInfo() const { return m_detailInfo; }
160
 
 
161
 
        /**
162
 
         * Set detail info.
163
 
         * @param detailInfo detail info
164
 
         */
165
 
        void setDetailInfo(const TaggedFile::DetailInfo& detailInfo) { m_detailInfo = detailInfo; }
166
 
 
167
 
        /**
168
 
         * Format a string from track data.
169
 
         * Supported format fields:
170
 
         * Those supported by TrackDataFormatReplacer::getReplacement()
171
 
         *
172
 
         * @param format    format specification
173
 
         * @param numTracks number of tracks in album
174
 
         *
175
 
         * @return formatted string.
176
 
         */
177
 
        QString formatString(const QString& format, unsigned numTracks = 0) const;
178
 
 
179
 
        /**
180
 
         * Get frames.
181
 
         * @return frames.
182
 
         */
183
 
        FrameCollection& getFrameCollection() {
184
 
                return *(static_cast<FrameCollection*>(this));
185
 
        }
186
 
 
187
 
        /**
188
 
         * Set frames.
189
 
         * @param frames frames
190
 
         */
191
 
        void setFrameCollection(const FrameCollection& frames) {
192
 
                *(static_cast<FrameCollection*>(this)) = frames;
193
 
        }
194
 
 
195
 
        /**
196
 
         * Get help text for format codes supported by formatString().
197
 
         *
198
 
         * @param onlyRows if true only the tr elements are returned,
199
 
         *                 not the surrounding table
200
 
         *
201
 
         * @return help text.
202
 
         */
203
 
        static QString getFormatToolTip(bool onlyRows = false);
204
 
 
205
 
private:
206
 
        int m_fileDuration;
207
 
        int m_importDuration;
208
 
        QString m_absFilename;
209
 
        QString m_fileExtension;
210
 
        QString m_tagFormatV1;
211
 
        QString m_tagFormatV2;
212
 
        TaggedFile::DetailInfo m_detailInfo;
213
 
};
214
 
 
215
 
/**
216
 
 * Vector containing tracks to import and artist, album names.
217
 
 */
218
 
class ImportTrackDataVector : public
219
 
#if QT_VERSION >= 0x040000
220
 
QVector<ImportTrackData>
221
 
#else
222
 
QValueVector<ImportTrackData>
223
 
#endif
224
 
{
225
 
public:
226
 
        /**
227
 
         * Clear vector and associated data.
228
 
         */
229
 
        void clearData() {
230
 
                clear();
231
 
                m_artist = QString();
232
 
                m_album = QString();
233
 
                m_coverArtUrl = QString();
234
 
        }
235
 
 
236
 
        /**
237
 
         * Get album artist.
238
 
         * @return album artist.
239
 
         */
240
 
        QString getArtist() const { return m_artist; }
241
 
 
242
 
        /**
243
 
         * Set album artist.
244
 
         * @param artist artist
245
 
         */
246
 
        void setArtist(const QString& artist) { m_artist = artist; }
247
 
 
248
 
        /**
249
 
         * Get album title.
250
 
         * @return album title.
251
 
         */
252
 
        QString getAlbum() const { return m_album; }
253
 
 
254
 
        /**
255
 
         * Set album title.
256
 
         * @param album album
257
 
         */
258
 
        void setAlbum(const QString& album) { m_album = album; }
259
 
 
260
 
        /**
261
 
         * Get cover art URL.
262
 
         * @return cover art URL.
263
 
         */
264
 
        QString getCoverArtUrl() const { return m_coverArtUrl; }
265
 
 
266
 
        /**
267
 
         * Set cover art URL.
268
 
         * @param coverArtUrl cover art URL
269
 
         */
270
 
        void setCoverArtUrl(const QString& coverArtUrl) { m_coverArtUrl = coverArtUrl; }
271
 
 
272
 
private:
273
 
        QString m_artist;
274
 
        QString m_album;
275
 
        QString m_coverArtUrl;
276
 
};
277
 
 
278
 
 
279
 
/**
280
 
 * Replaces track data format codes in a string.
281
 
 */
282
 
class TrackDataFormatReplacer : public FrameFormatReplacer {
283
 
public:
284
 
        /**
285
 
         * Constructor.
286
 
         *
287
 
         * @param trackData track data
288
 
         * @param numTracks number of tracks in album
289
 
         * @param str       string with format codes
290
 
         */
291
 
        explicit TrackDataFormatReplacer(
292
 
                const ImportTrackData& trackData, unsigned numTracks = 0,
293
 
                const QString& str = QString());
294
 
 
295
 
        /**
296
 
         * Destructor.
297
 
         */
298
 
        virtual ~TrackDataFormatReplacer();
299
 
 
300
 
        /**
301
 
         * Get help text for supported format codes.
302
 
         *
303
 
         * @param onlyRows if true only the tr elements are returned,
304
 
         *                 not the surrounding table
305
 
         *
306
 
         * @return help text.
307
 
         */
308
 
        static QString getToolTip(bool onlyRows = false);
309
 
 
310
 
protected:
311
 
        /**
312
 
         * Replace a format code (one character %c or multiple characters %{chars}).
313
 
         * Supported format fields:
314
 
         * Those supported by FrameFormatReplacer::getReplacement()
315
 
         * %f filename
316
 
         * %p path to file
317
 
         * %u URL of file
318
 
         * %d duration in minutes:seconds
319
 
         * %D duration in seconds
320
 
         * %n number of tracks
321
 
         *
322
 
         * @param code format code
323
 
         *
324
 
         * @return replacement string,
325
 
         *         QString::null if code not found.
326
 
         */
327
 
        virtual QString getReplacement(const QString& code) const;
328
 
 
329
 
private:
330
 
        const ImportTrackData& m_trackData;
331
 
        const unsigned m_numTracks;
332
 
};
333
 
 
334
 
#endif // IMPORTTRACKDATA_H