File indexing completed on 2021-12-21 13:27:50

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 #include "categoryreaderinterface.h"
0018 #include "filerenameroptions.h"
0019 
0020 #include <QString>
0021 
0022 QString CategoryReaderInterface::value(const CategoryID &category) const
0023 {
0024     QString value = categoryValue(category.category).trimmed();
0025 
0026     if(category.category == Track)
0027         value = fixupTrack(value, category.categoryNumber).trimmed();
0028 
0029     if(value.isEmpty()) {
0030         switch(emptyAction(category)) {
0031             case TagRenamerOptions::UseReplacementValue:
0032                 value = emptyText(category);
0033                 break;
0034 
0035             case TagRenamerOptions::IgnoreEmptyTag:
0036                 return QString();
0037 
0038             default:
0039                 // No extra action needed.
0040                 break;
0041         }
0042     }
0043 
0044     return prefix(category) + value + suffix(category);
0045 }
0046 
0047 bool CategoryReaderInterface::isRequired(const CategoryID &category) const
0048 {
0049     return emptyAction(category) != TagRenamerOptions::IgnoreEmptyTag;
0050 }
0051 
0052 bool CategoryReaderInterface::isEmpty(TagType category) const
0053 {
0054     return categoryValue(category).isEmpty();
0055 }
0056 
0057 QString CategoryReaderInterface::fixupTrack(const QString &track, int categoryNum) const
0058 {
0059     QString str(track);
0060     CategoryID trackId(Track, categoryNum);
0061 
0062     if(track == "0") {
0063         if(emptyAction(trackId) == TagRenamerOptions::UseReplacementValue)
0064             str = emptyText(trackId);
0065         else
0066             return QString();
0067     }
0068 
0069     int minimumWidth = trackWidth(categoryNum);
0070 
0071     if(str.length() < minimumWidth) {
0072         QString prefix;
0073         prefix.fill('0', minimumWidth - str.length());
0074         return prefix + str;
0075     }
0076 
0077     return str;
0078 }
0079 
0080 // vim: set et sw=4 tw=0 sta: