~ubuntu-branches/ubuntu/trusty/kid3/trusty

« back to all changes in this revision

Viewing changes to kid3/playlistcreator.h

  • Committer: Bazaar Package Importer
  • Author(s): Maia Kozheva
  • Date: 2009-11-08 15:55:34 UTC
  • mfrom: (1.1.10 upstream) (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20091108155534-4ses1tpuj8nxjxj6
Tags: 1.3-1ubuntu1
* Merged from Debian, remaining Ubuntu changes:
  + debian/control:
    - Build-depend on libmp4v2-dev.
  + debian/rules:
    - Build WITH_MP4V2.
* Removed Ubuntu patch fix_gnome_file_dialog.diff, fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * \file playlistcreator.h
 
3
 * Playlist creator.
 
4
 *
 
5
 * \b Project: Kid3
 
6
 * \author Urs Fleisch
 
7
 * \date 21 Sep 2009
 
8
 *
 
9
 * Copyright (C) 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 PLAYLISTCREATOR_H
 
28
#define PLAYLISTCREATOR_H
 
29
 
 
30
#include <qstring.h>
 
31
#include <qmap.h>
 
32
 
 
33
class FileListItem;
 
34
class DirInfo;
 
35
class TaggedFile;
 
36
class ImportTrackData;
 
37
class PlaylistConfig;
 
38
 
 
39
/**
 
40
 * Playlist creator.
 
41
 * Creates playlists from added items according to a playlist configuration.
 
42
 */
 
43
class PlaylistCreator {
 
44
public:
 
45
        /**
 
46
         * An item from the file list which can be added to a playlist.
 
47
         * The item will only be added to the playlist if add() is called.
 
48
         */
 
49
        class Item {
 
50
        public:
 
51
                /**
 
52
                 * Constructor.
 
53
                 *
 
54
                 * @param item item in file list
 
55
                 * @param ctr  associated playlist creator
 
56
                 */
 
57
                Item(FileListItem* item, PlaylistCreator& ctr);
 
58
 
 
59
                /**
 
60
                 * Destructor.
 
61
                 */
 
62
                ~Item();
 
63
 
 
64
                /**
 
65
                 * Check if item is a directory.
 
66
                 * @return true if item is directory.
 
67
                 */
 
68
                bool isDir() const { return m_dirInfo != 0; }
 
69
 
 
70
                /**
 
71
                 * Check if item is a tagged file.
 
72
                 * @return true if item is file.
 
73
                 */
 
74
                bool isFile() const { return m_taggedFile != 0; }
 
75
 
 
76
                /**
 
77
                 * Get the directory of the item.
 
78
                 * @return directory path with trailing separator.
 
79
                 */
 
80
                const QString& getDirName() { return m_dirName; }
 
81
 
 
82
                /**
 
83
                 * Add item to playlist.
 
84
                 * This operation will write a playlist if the configuration is set to write
 
85
                 * a playlist in every directory and a new directory is entered.
 
86
                 *
 
87
                 * @return true if ok.
 
88
                 */
 
89
                bool add();
 
90
 
 
91
        private:
 
92
                /**
 
93
                 * Format string using tags and properties of item.
 
94
                 *
 
95
                 * @param format format string
 
96
                 *
 
97
                 * @return string with percent codes replaced.
 
98
                 */
 
99
                QString formatString(const QString& format);
 
100
 
 
101
                PlaylistCreator& m_ctr;
 
102
                FileListItem* m_item;
 
103
                const DirInfo* m_dirInfo;
 
104
                TaggedFile* m_taggedFile;
 
105
                ImportTrackData* m_trackData;
 
106
                QString m_dirName;
 
107
        };
 
108
 
 
109
        /**
 
110
         * Constructor.
 
111
         *
 
112
         * @param topLevelDir top-level directory of playlist
 
113
         * @param cfg         playlist configuration
 
114
         */
 
115
        PlaylistCreator(const QString& topLevelDir, const PlaylistConfig& cfg);
 
116
 
 
117
        /**
 
118
         * Write playlist containing added Entry elements.
 
119
         *
 
120
         * @return true if ok.
 
121
         */
 
122
        bool write();
 
123
 
 
124
private:
 
125
        friend class Item;
 
126
 
 
127
        struct Entry {
 
128
                unsigned long duration;
 
129
                QString filePath;
 
130
                QString info;
 
131
        };
 
132
 
 
133
        const PlaylistConfig& m_cfg;
 
134
        QString m_playlistDirName;
 
135
        QString m_playlistFileName;
 
136
        QMap<QString, Entry> m_entries;
 
137
};
 
138
 
 
139
#endif // PLAYLISTCREATOR_H