File indexing completed on 2024-05-19 04:55:53

0001 /**
0002  * \file batchimportprofile.cpp
0003  * Profile containing a name list for source for batch import.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 2 Jan 2013
0008  *
0009  * Copyright (C) 2013-2018  Urs Fleisch
0010  *
0011  * This file is part of Kid3.
0012  *
0013  * Kid3 is free software; you can redistribute it and/or modify
0014  * it under the terms of the GNU General Public License as published by
0015  * the Free Software Foundation; either version 2 of the License, or
0016  * (at your option) any later version.
0017  *
0018  * Kid3 is distributed in the hope that it will be useful,
0019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0021  * GNU General Public License for more details.
0022  *
0023  * You should have received a copy of the GNU General Public License
0024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0025  */
0026 
0027 #include "batchimportprofile.h"
0028 #include <QStringList>
0029 
0030 /**
0031  * Constructor.
0032  */
0033 BatchImportProfile::BatchImportProfile() = default;
0034 
0035 /**
0036  * Restore batch import sources from serialized string.
0037  * @param str string representation of import sources
0038  */
0039 void BatchImportProfile::setSourcesFromString(const QString& str)
0040 {
0041   m_sources.clear();
0042   if (!str.isEmpty()) {
0043     const QStringList srcStrs = str.split(QLatin1Char(';'));
0044     for (const QString& srcStr : srcStrs) {
0045       const QStringList propStrs = srcStr.split(QLatin1Char(':'));
0046       const int propStrsSize = propStrs.size();
0047       Source src;
0048       if (propStrsSize > 0)
0049         src.setName(propStrs.at(0));
0050       if (propStrsSize > 1)
0051         src.setRequiredAccuracy(propStrs.at(1).toInt());
0052       if (propStrsSize > 2) {
0053         const QString& enableStr = propStrs.at(2);
0054         src.enableStandardTags(enableStr.contains(QLatin1Char('S')));
0055         src.enableAdditionalTags(enableStr.contains(QLatin1Char('A')));
0056         src.enableCoverArt(enableStr.contains(QLatin1Char('C')));
0057       }
0058       m_sources.append(src);
0059     }
0060   }
0061 }
0062 
0063 /**
0064  * Serialize batch import sources as a string.
0065  * @return string representation of import sources.
0066  */
0067 QString BatchImportProfile::getSourcesAsString() const
0068 {
0069   QStringList strs;
0070   const auto srcs = m_sources;
0071   strs.reserve(srcs.size());
0072   for (const Source& src : srcs) {
0073     QString enableStr;
0074     if (src.standardTagsEnabled())   enableStr += QLatin1Char('S');
0075     if (src.additionalTagsEnabled()) enableStr += QLatin1Char('A');
0076     if (src.coverArtEnabled())       enableStr += QLatin1Char('C');
0077     strs.append(src.getName() + QLatin1Char(':') +
0078                 QString::number(src.getRequiredAccuracy()) + QLatin1Char(':') +
0079                 enableStr);
0080   }
0081   return strs.join(QLatin1String(";"));
0082 }