File indexing completed on 2023-05-30 11:30:53

0001 /**
0002  * Copyright (C) 2004 Michael Pyne <mpyne@kde.org>
0003  *
0004  * This program is free software; you can redistribute it and/or modify it under
0005  * the terms of the GNU General Public License as published by the Free Software
0006  * Foundation; either version 2 of the License, or (at your option) any later
0007  * version.
0008  *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.
0012  *
0013  * You should have received a copy of the GNU General Public License along with
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.
0015  */
0016 
0017 #ifndef TAGRENAMEROPTIONS_H
0018 #define TAGRENAMEROPTIONS_H
0019 
0020 #include <QString>
0021 
0022 // Insert all new tag types before NumTypes, that way NumTypes will always be
0023 // the count of valid tag types.
0024 enum TagType {
0025     StartTag, Title = StartTag, Artist, Album,
0026     Track, Genre, Year, NumTypes, TagUnknown
0027 };
0028 
0029 /**
0030  * Class that uniquely identifies a user's category (since the user may have
0031  * the same category more than once in their file renaming structure).
0032  */
0033 struct CategoryID
0034 {
0035     CategoryID() : category(TagUnknown), categoryNumber(0)
0036     {
0037     }
0038 
0039     CategoryID(const CategoryID &other) : category(other.category),
0040                                           categoryNumber(other.categoryNumber)
0041     {
0042     }
0043 
0044     CategoryID(TagType cat, unsigned num) : category(cat), categoryNumber(num)
0045     {
0046     }
0047 
0048     CategoryID &operator=(const CategoryID &other)
0049     {
0050         if(this == &other)
0051             return *this;
0052 
0053         category = other.category;
0054         categoryNumber = other.categoryNumber;
0055 
0056         return *this;
0057     }
0058 
0059     bool operator==(const CategoryID &other) const
0060     {
0061         return category == other.category && categoryNumber == other.categoryNumber;
0062     }
0063 
0064     bool operator!=(const CategoryID &other) const
0065     {
0066         return !(*this == other);
0067     }
0068 
0069     bool operator<(const CategoryID &other) const
0070     {
0071         if(category == other.category)
0072             return categoryNumber < other.categoryNumber;
0073 
0074         return category < other.category;
0075     }
0076 
0077     TagType category;
0078     unsigned categoryNumber;
0079 };
0080 
0081 /**
0082  * Defines options for a tag type.  Used by FileRenamerTagOptions as its
0083  * data type.
0084  *
0085  * @author Michael Pyne <mpyne@kde.org>
0086  */
0087 class TagRenamerOptions
0088 {
0089 public:
0090     enum EmptyActions { ForceEmptyInclude, IgnoreEmptyTag, UseReplacementValue };
0091 
0092     TagRenamerOptions();
0093 
0094     /**
0095      * Construct the options by loading from KConfig.
0096      *
0097      * @param category The category to load the options for.
0098      */
0099     TagRenamerOptions(const CategoryID &category);
0100     TagRenamerOptions(const TagRenamerOptions &other);
0101 
0102     TagRenamerOptions& operator=(const TagRenamerOptions &) = default;
0103 
0104     QString prefix() const { return m_prefix; }
0105     QString suffix() const { return m_suffix; }
0106     QString emptyText() const { return m_emptyText; }
0107     EmptyActions emptyAction() const { return m_emptyAction; }
0108     unsigned trackWidth() const { return m_trackWidth; }
0109     bool disabled() const { return m_disabled; }
0110     TagType category() const { return m_category; }
0111 
0112     void setPrefix(const QString &prefix) { m_prefix = prefix; }
0113     void setSuffix(const QString &suffix) { m_suffix = suffix; }
0114     void setEmptyText(const QString &emptyText) { m_emptyText = emptyText; }
0115     void setEmptyAction(EmptyActions action) { m_emptyAction = action; }
0116     void setTrackWidth(unsigned width) { m_trackWidth = width; }
0117     void setDisabled(bool disabled) { m_disabled = disabled; }
0118     void setCategory(TagType category) { m_category = category; }
0119 
0120     /**
0121      * Maps \p type to a textual representation of its name.  E.g. Track => "Track"
0122      *
0123      * @param type the category to retrieve a text representation of.
0124      * @param translate if true, the string is translated (if possible).
0125      * @return text representation of category.
0126      */
0127     static QString tagTypeText(TagType category, bool translate = true);
0128 
0129     QString tagTypeText(bool translate = true) const
0130     {
0131         return tagTypeText(category(), translate);
0132     }
0133 
0134     /**
0135      * Function that tries to match a string back to its category.  Uses only
0136      * the untranslated and case-sensitive form of the string.  If it fails it
0137      * will return TagUnknown.
0138      */
0139     static TagType tagFromCategoryText(const QString &text);
0140 
0141     /**
0142      * This saves the options to the global KConfig object.
0143      *
0144      * @param categoryNum The zero-based count of the number of this type of
0145      *           category.  For example, this would be 1 for the
0146      *           second category of this type.  The stored category
0147      *           number is not used in order to allow you to save with
0148      *           a different one (for compaction purposes perhaps).
0149      */
0150     void saveConfig(unsigned categoryNum) const;
0151 
0152 private:
0153 
0154     // Member variables
0155 
0156     QString m_prefix;
0157     QString m_suffix;
0158 
0159     /// Defines the action to take when the tag is empty.
0160     EmptyActions m_emptyAction;
0161 
0162     /// If m_emptyAction is UseReplacementValue, this holds the text of the value
0163     /// to use.
0164     QString m_emptyText;
0165 
0166     /// Used only for the Track type.  Defines the minimum track width when
0167     /// expanding the track token.
0168     unsigned m_trackWidth;
0169 
0170     /// This is true if this tag is always disabled when expanding file names.
0171     bool m_disabled;
0172 
0173     TagType m_category;
0174 };
0175 
0176 #endif /* TAGRENAMEROPTIONS_H */
0177 
0178 // vim: set et sw=4 tw=0 sta: