~ubuntu-branches/ubuntu/intrepid/kid3/intrepid

« back to all changes in this revision

Viewing changes to kid3/taggedfile.h

  • Committer: Bazaar Package Importer
  • Author(s): Michele Angrisano
  • Date: 2008-01-09 23:20:54 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080109232054-gtcjxz4ahdnzbt01
Tags: 0.10-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - debian/rules:
    + Use dh_icons instead dh_iconcache.
  - debian/control:
    + Update maintainer field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 * \b Project: Kid3
6
6
 * \author Urs Fleisch
7
7
 * \date 25 Sep 2005
 
8
 *
 
9
 * Copyright (C) 2005-2007  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/>.
8
25
 */
9
26
 
10
27
#ifndef TAGGEDFILE_H
11
28
#define TAGGEDFILE_H
12
29
 
13
30
#include <qstring.h>
 
31
#include <qstringlist.h>
 
32
#include "qtcompatmac.h"
 
33
#if QT_VERSION >= 0x040000
 
34
#include <QList>
 
35
#else
 
36
#include <qvaluelist.h>
 
37
#endif
14
38
#include "standardtags.h"
 
39
#include "frame.h"
15
40
 
16
 
class FrameList;
17
41
class DirInfo;
18
42
 
19
43
/** Base class for tagged files. */
20
44
class TaggedFile {
21
45
public:
 
46
        /** Abstract base class for pluggable file type resolution. */
 
47
        class Resolver {
 
48
        public:
 
49
                /**
 
50
                 * Constructor.
 
51
                 */
 
52
                Resolver() {}
 
53
 
 
54
                /**
 
55
                 * Destructor.
 
56
                 */
 
57
                virtual ~Resolver() {}
 
58
 
 
59
                /**
 
60
                 * Create a TaggedFile subclass depending on the file extension.
 
61
                 *
 
62
                 * @param di directory information
 
63
                 * @param fn filename
 
64
                 *
 
65
                 * @return tagged file, 0 if type not supported.
 
66
                 */
 
67
                virtual TaggedFile* createFile(const DirInfo* di, const QString& fn) const = 0;
 
68
 
 
69
                /**
 
70
                 * Get a list with all extensions (e.g. ".mp3") supported by TaggedFile subclass.
 
71
                 *
 
72
                 * @return list of file extensions.
 
73
                 */
 
74
                virtual QStringList getSupportedFileExtensions() const = 0;
 
75
        };
 
76
 
 
77
 
22
78
        /**
23
79
         * Constructor.
24
80
         *
144
200
        virtual QString getGenreV1();
145
201
 
146
202
        /**
147
 
         * Remove all ID3v1 tags.
 
203
         * Remove ID3v1 frames.
148
204
         *
149
 
         * @param flt filter specifying which fields to remove
 
205
         * @param flt filter specifying which frames to remove
150
206
         */
151
 
        virtual void removeTagsV1(const StandardTagsFilter& flt);
 
207
        virtual void deleteFramesV1(const FrameFilter& flt);
152
208
 
153
209
        /**
154
210
         * Set ID3v1 title.
269
325
        virtual int getTrackNumV2() = 0;
270
326
 
271
327
        /**
272
 
         * Remove all ID3v2 tags.
 
328
         * Remove ID3v2 frames.
273
329
         *
274
 
         * @param flt filter specifying which fields to remove
 
330
         * @param flt filter specifying which frames to remove
275
331
         */
276
 
        virtual void removeTagsV2(const StandardTagsFilter& flt) = 0;
 
332
        virtual void deleteFramesV2(const FrameFilter& flt);
277
333
 
278
334
        /**
279
335
         * Get ID3v2 genre as text.
367
423
        virtual unsigned getDuration() const = 0;
368
424
 
369
425
        /**
370
 
         * Get frame list for this type of tagged file.
371
 
         *
372
 
         * @return frame list.
373
 
         */
374
 
        virtual FrameList* getFrameList() const = 0;
375
 
 
376
 
        /**
377
426
         * Get file extension including the dot.
378
427
         *
379
428
         * @return file extension, e.g. ".mp3".
399
448
        virtual QString getTagFormatV2() const;
400
449
 
401
450
        /**
 
451
         * Get a specific frame from the tags 1.
 
452
         *
 
453
         * @param type  frame type
 
454
         * @param frame the frame is returned here
 
455
         *
 
456
         * @return true if ok.
 
457
         */
 
458
        virtual bool getFrameV1(Frame::Type type, Frame& frame);
 
459
 
 
460
        /**
 
461
         * Set a frame in the tags 1.
 
462
         *
 
463
         * @param frame frame to set.
 
464
         *
 
465
         * @return true if ok.
 
466
         */
 
467
        virtual bool setFrameV1(const Frame& frame);
 
468
 
 
469
        /**
 
470
         * Get a specific frame from the tags 2.
 
471
         *
 
472
         * @param type  frame type
 
473
         * @param frame the frame is returned here
 
474
         *
 
475
         * @return true if ok.
 
476
         */
 
477
        virtual bool getFrameV2(Frame::Type type, Frame& frame);
 
478
 
 
479
        /**
 
480
         * Set a frame in the tags 2.
 
481
         *
 
482
         * @param frame frame to set
 
483
         *
 
484
         * @return true if ok.
 
485
         */
 
486
        virtual bool setFrameV2(const Frame& frame);
 
487
 
 
488
        /**
 
489
         * Add a frame in the tags 2.
 
490
         *
 
491
         * @param frame frame to add, a field list may be added by this method
 
492
         *
 
493
         * @return true if ok.
 
494
         */
 
495
        virtual bool addFrameV2(Frame& frame);
 
496
 
 
497
        /**
 
498
         * Delete a frame in the tags 2.
 
499
         *
 
500
         * @param frame frame to delete.
 
501
         *
 
502
         * @return true if ok.
 
503
         */
 
504
        virtual bool deleteFrameV2(const Frame& frame);
 
505
 
 
506
        /**
 
507
         * Get a list of frame IDs which can be added.
 
508
         *
 
509
         * @return list with frame IDs.
 
510
         */
 
511
        virtual QStringList getFrameIds() const;
 
512
 
 
513
        /**
 
514
         * Get all frames in tag 1.
 
515
         *
 
516
         * @param frames frame collection to set.
 
517
         */
 
518
        virtual void getAllFramesV1(FrameCollection& frames);
 
519
 
 
520
        /**
 
521
         * Get all frames in tag 2.
 
522
         * This generic implementation only supports the standard tags and should
 
523
         * be reimplemented in derived classes.
 
524
         *
 
525
         * @param frames frame collection to set.
 
526
         */
 
527
        virtual void getAllFramesV2(FrameCollection& frames);
 
528
 
 
529
        /**
 
530
         * Set frames in tag 1.
 
531
         *
 
532
         * @param frames      frame collection
 
533
         * @param onlyChanged only frames with value marked as changed are set
 
534
         */
 
535
        void setFramesV1(const FrameCollection& frames, bool onlyChanged = true);
 
536
 
 
537
        /**
 
538
         * Set frames in tag 2.
 
539
         *
 
540
         * @param frames      frame collection
 
541
         * @param onlyChanged only frames with value marked as changed are set
 
542
         */
 
543
        void setFramesV2(const FrameCollection& frames, bool onlyChanged = true);
 
544
 
 
545
        /**
402
546
         * Get ID3v1 tags from file.
403
547
         *
404
548
         * @param st tags to put result
512
656
        unsigned getTruncationFlags() const { return m_truncation; }
513
657
 
514
658
        /**
 
659
         * Add the total number of tracks to the track number if enabled.
 
660
         *
 
661
         * @param value string containing track number,
 
662
         *              "/t" with t = total number of tracks will be appended
 
663
         *              if enabled and value contains a number
 
664
         */
 
665
        void addTotalNumberOfTracksIfEnabled(QString& value) const;
 
666
 
 
667
        /**
515
668
         * Format a time string "h:mm:ss".
516
669
         * If the time is less than an hour, the hour is not put into the
517
670
         * string and the minute is not padded with zeroes.
522
675
         */
523
676
        static QString formatTime(unsigned seconds);
524
677
 
 
678
        /**
 
679
         * Add a file type resolver to the end of a list of resolvers.
 
680
         *
 
681
         * @param resolver file type resolver to add
 
682
         */
 
683
        static void addResolver(const Resolver* resolver);
 
684
 
 
685
        /**
 
686
         * Create a TaggedFile subclass using the first successful resolver.
 
687
         * @see addResolver()
 
688
         *
 
689
         * @param di directory information
 
690
         * @param fn filename
 
691
         *
 
692
         * @return tagged file, 0 if type not supported.
 
693
         */
 
694
        static TaggedFile* createFile(const DirInfo* di, const QString& fn);
 
695
 
 
696
        /**
 
697
         * Get a list with all extensions (e.g. ".mp3") supported by the resolvers.
 
698
         * @see addResolver()
 
699
         *
 
700
         * @return list of file extensions.
 
701
         */
 
702
        static QStringList getSupportedFileExtensions();
 
703
 
 
704
        /**
 
705
         * Free static resources.
 
706
         */
 
707
        static void staticCleanup();
 
708
 
525
709
protected:
526
710
        /**
527
711
         * Rename a file.
550
734
        int getTotalNumberOfTracksIfEnabled() const;
551
735
 
552
736
        /**
553
 
         * Remove the standard ID3v1 tags.
554
 
         *
555
 
         * @param flt filter specifying which fields to remove
556
 
         */
557
 
        void removeStandardTagsV1(const StandardTagsFilter& flt);
558
 
 
559
 
        /**
560
 
         * Remove the standard ID3v2 tags.
561
 
         *
562
 
         * @param flt filter specifying which fields to remove
563
 
         */
564
 
        void removeStandardTagsV2(const StandardTagsFilter& flt);
565
 
 
566
 
        /**
567
737
         * Get current filename.
568
738
         * @return existing name.
569
739
         */
634
804
        bool m_changedV2;
635
805
        /** Truncation flags. */
636
806
        unsigned m_truncation;
 
807
 
 
808
#if QT_VERSION >= 0x040000
 
809
        static QList<const Resolver*> s_resolvers;
 
810
#else
 
811
        static QValueList<const Resolver*> s_resolvers;
 
812
#endif
637
813
};
638
814
 
639
815
#endif // TAGGEDFILE_H