summaryrefslogtreecommitdiffstats
path: root/juk/tagrenameroptions.h
blob: 56ff036ed1c23c5fed5834441ceea449d95bcc11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/***************************************************************************
    begin                : Sun Oct 31 2004
    copyright            : (C) 2004 by Michael Pyne
    email                : [email protected]
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef JUK_TAGRENAMEROPTIONS_H
#define JUK_TAGRENAMEROPTIONS_H

// Insert all new tag types before NumTypes, that way NumTypes will always be
// the count of valid tag types.
enum TagType {
    StartTag, Title = StartTag, Artist, Album,
    Track, Genre, Year, NumTypes, Unknown
};

/**
 * Class that uniquely identifies a user's category (since the user may have
 * the same category more than once in their file renaming structure).
 */
struct CategoryID
{
    CategoryID() : category(Unknown), categoryNumber(0)
    {
    }

    CategoryID(const CategoryID &other) : category(other.category),
                                          categoryNumber(other.categoryNumber)
    {
    }

    CategoryID(TagType cat, unsigned num) : category(cat), categoryNumber(num)
    {
    }

    CategoryID &operator=(const CategoryID &other)
    {
        if(this == &other)
            return *this;

        category = other.category;
        categoryNumber = other.categoryNumber;

        return *this;
    }

    bool operator==(const CategoryID &other) const
    {
        return category == other.category && categoryNumber == other.categoryNumber;
    }

    bool operator!=(const CategoryID &other) const
    {
        return !(*this == other);
    }

    bool operator<(const CategoryID &other) const
    {
        if(category == other.category)
            return categoryNumber < other.categoryNumber;

        return category < other.category;
    }

    TagType category;
    unsigned categoryNumber;
};

/**
 * Defines options for a tag type.  Used by FileRenamerTagOptions as its
 * data type.
 *
 * @author Michael Pyne <[email protected]>
 */
class TagRenamerOptions
{
public:
    enum EmptyActions { ForceEmptyInclude, IgnoreEmptyTag, UseReplacementValue };

    TagRenamerOptions();

    /**
     * Construct the options by loading from TDEConfig.
     *
     * @param category The category to load the options for.
     */
    TagRenamerOptions(const CategoryID &category);
    TagRenamerOptions(const TagRenamerOptions &other);

    TQString prefix() const { return m_prefix; }
    TQString suffix() const { return m_suffix; }
    TQString emptyText() const { return m_emptyText; }
    EmptyActions emptyAction() const { return m_emptyAction; }
    unsigned trackWidth() const { return m_trackWidth; }
    bool disabled() const { return m_disabled; }
    TagType category() const { return m_category; }

    void setPrefix(const TQString &prefix) { m_prefix = prefix; }
    void setSuffix(const TQString &suffix) { m_suffix = suffix; }
    void setEmptyText(const TQString &emptyText) { m_emptyText = emptyText; }
    void setEmptyAction(EmptyActions action) { m_emptyAction = action; }
    void setTrackWidth(unsigned width) { m_trackWidth = width; }
    void setDisabled(bool disabled) { m_disabled = disabled; }
    void setCategory(TagType category) { m_category = category; }

    /**
     * Maps \p type to a textual representation of its name.  E.g. Track => "Track"
     *
     * @param type the category to retrieve a text representation of.
     * @param translate if true, the string is translated (if possible).
     * @return text representation of category.
     */
    static TQString tagTypeText(TagType category, bool translate = true);

    TQString tagTypeText(bool translate = true) const
    {
        return tagTypeText(category(), translate);
    }

    /**
     * Function that tries to match a string back to its category.  Uses
     * the case-sensitive form of the string.  If it fails it will return
     * Unknown.
     *
     * @param translated If true, @p text is translated, if false, it is the untranslated
     *                   version.
     */
    static TagType tagFromCategoryText(const TQString &text, bool translate = true);

    /**
     * This saves the options to the global TDEConfig object.
     *
     * @param categoryNum The zero-based count of the number of this type of
     *           category.  For example, this would be 1 for the
     *           second category of this type.  The stored category
     *           number is not used in order to allow you to save with
     *           a different one (for compaction purposes perhaps).
     */
    void saveConfig(unsigned categoryNum) const;

private:

    // Member variables

    TQString m_prefix;
    TQString m_suffix;

    /// Defines the action to take when the tag is empty.
    EmptyActions m_emptyAction;

    /// If m_emptyAction is UseReplacementValue, this holds the text of the value
    /// to use.
    TQString m_emptyText;

    /// Used only for the Track type.  Defines the minimum track width when
    /// expanding the track token.
    unsigned m_trackWidth;

    /// This is true if this tag is always disabled when expanding file names.
    bool m_disabled;

    TagType m_category;
};

#endif /* JUK_TAGRENAMEROPTIONS_H */

// vim: set et ts=4 sw=4: