tagrenameroptions.h 5.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * Copyright (C) 2004 Michael Pyne <mpyne@kde.org>
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */
16

17 18
#ifndef TAGRENAMEROPTIONS_H
#define TAGRENAMEROPTIONS_H
19

Yuri Chornoivan's avatar
Yuri Chornoivan committed
20
#include <QString>
21

22 23
// Insert all new tag types before NumTypes, that way NumTypes will always be
// the count of valid tag types.
24
enum TagType {
25
    StartTag, Title = StartTag, Artist, Album,
26
    Track, Genre, Year, NumTypes, TagUnknown
27
};
28

29 30 31 32 33 34
/**
 * 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
{
35
    CategoryID() : category(TagUnknown), categoryNumber(0)
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
    {
    }

    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;
};

81 82 83 84
/**
 * Defines options for a tag type.  Used by FileRenamerTagOptions as its
 * data type.
 *
85
 * @author Michael Pyne <mpyne@kde.org>
86 87 88 89
 */
class TagRenamerOptions
{
public:
90
    enum EmptyActions { ForceEmptyInclude, IgnoreEmptyTag, UseReplacementValue };
91 92

    TagRenamerOptions();
93 94 95 96 97 98 99

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

102 103
    TagRenamerOptions& operator=(const TagRenamerOptions &) = default;

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    QString prefix() const { return m_prefix; }
    QString suffix() const { return m_suffix; }
    QString 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 QString &prefix) { m_prefix = prefix; }
    void setSuffix(const QString &suffix) { m_suffix = suffix; }
    void setEmptyText(const QString &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; }

Scott Wheeler's avatar
Scott Wheeler committed
120 121 122 123 124 125 126 127
    /**
     * 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 QString tagTypeText(TagType category, bool translate = true);
128

Scott Wheeler's avatar
Scott Wheeler committed
129
    QString tagTypeText(bool translate = true) const
130
    {
Scott Wheeler's avatar
Scott Wheeler committed
131
        return tagTypeText(category(), translate);
132 133
    }

134 135 136
    /**
     * Function that tries to match a string back to its category.  Uses only
     * the untranslated and case-sensitive form of the string.  If it fails it
137
     * will return TagUnknown.
138 139 140
     */
    static TagType tagFromCategoryText(const QString &text);

141 142
    /**
     * This saves the options to the global KConfig object.
143 144 145 146 147 148
     *
     * @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).
149
     */
150
    void saveConfig(unsigned categoryNum) const;
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

private:

    // Member variables

    QString m_prefix;
    QString 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.
    QString 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;
};

176
#endif /* TAGRENAMEROPTIONS_H */
177

178
// vim: set et sw=4 tw=0 sta: