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

0001 /**
0002  * \file serverimporterconfig.cpp
0003  * Configuration for server import.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 09 Oct 2006
0008  *
0009  * Copyright (C) 2006-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 "serverimporterconfig.h"
0028 #include <QtGlobal>
0029 #include "isettings.h"
0030 
0031 /**
0032  * Constructor.
0033  * Set default configuration.
0034  *
0035  * @param grp         configuration group
0036  */
0037 ServerImporterConfig::ServerImporterConfig(const QString& grp)
0038   : GeneralConfig(grp),
0039     m_cgiPathUsed(true), m_additionalTagsUsed(false),
0040     m_standardTags(true), m_additionalTags(true), m_coverArt(true)
0041 {
0042 }
0043 
0044 /**
0045  * Constructor.
0046  * Used to create temporary configuration.
0047  */
0048 ServerImporterConfig::ServerImporterConfig()
0049   : GeneralConfig(QLatin1String("Temporary")),
0050     m_cgiPathUsed(false),
0051     m_additionalTagsUsed(false), m_standardTags(false), m_additionalTags(false),
0052     m_coverArt(false) {}
0053 
0054 /**
0055  * Persist configuration.
0056  *
0057  * @param config configuration
0058  */
0059 void ServerImporterConfig::writeToConfig(ISettings* config) const
0060 {
0061   config->beginGroup(m_group);
0062   config->setValue(QLatin1String("Server"), QVariant(m_server));
0063   if (m_cgiPathUsed)
0064     config->setValue(QLatin1String("CgiPath"), QVariant(m_cgiPath));
0065   if (m_additionalTagsUsed) {
0066     config->setValue(QLatin1String("StandardTags"), QVariant(m_standardTags));
0067     config->setValue(QLatin1String("AdditionalTags"), QVariant(m_additionalTags));
0068     config->setValue(QLatin1String("CoverArt"), QVariant(m_coverArt));
0069   }
0070   QStringList propertiesKv;
0071   const QList<QByteArray> propertyNames = dynamicPropertyNames();
0072   for (const QByteArray& propertyName : propertyNames) {
0073     propertiesKv.append(QString::fromLatin1(propertyName));
0074     propertiesKv.append(property(propertyName).toString());
0075   }
0076   config->setValue(QLatin1String("Properties"), QVariant(propertiesKv));
0077   config->endGroup();
0078   config->beginGroup(m_group, true);
0079   config->setValue(QLatin1String("WindowGeometry"), QVariant(m_windowGeometry));
0080   config->endGroup();
0081 }
0082 
0083 /**
0084  * Read persisted configuration.
0085  *
0086  * @param config configuration
0087  */
0088 void ServerImporterConfig::readFromConfig(ISettings* config)
0089 {
0090   config->beginGroup(m_group);
0091   m_server = config->value(QLatin1String("Server"), m_server).toString();
0092   if (m_cgiPathUsed)
0093     m_cgiPath = config->value(QLatin1String("CgiPath"), m_cgiPath).toString();
0094   if (m_additionalTagsUsed) {
0095     m_standardTags = config->value(QLatin1String("StandardTags"),
0096                                    m_standardTags).toBool();
0097     m_additionalTags = config->value(QLatin1String("AdditionalTags"),
0098                                      m_additionalTags).toBool();
0099     m_coverArt = config->value(QLatin1String("CoverArt"), m_coverArt).toBool();
0100   }
0101   QStringList propertiesKv =
0102       config->value(QLatin1String("Properties"), QStringList()).toStringList();
0103   for (auto it = propertiesKv.constBegin();
0104        it != propertiesKv.constEnd();
0105        ++it) {
0106     QString key = *it;
0107     if (++it == propertiesKv.constEnd()) {
0108       break;
0109     }
0110     setProperty(key.toLatin1(), *it);
0111   }
0112   config->endGroup();
0113   config->beginGroup(m_group, true);
0114   m_windowGeometry = config->value(QLatin1String("WindowGeometry"),
0115                                    m_windowGeometry).toByteArray();
0116   config->endGroup();
0117 }
0118 
0119 void ServerImporterConfig::setServer(const QString& server)
0120 {
0121   if (m_server != server) {
0122     m_server = server;
0123     emit serverChanged(m_server);
0124   }
0125 }
0126 
0127 void ServerImporterConfig::setCgiPath(const QString& cgiPath)
0128 {
0129   if (m_cgiPath != cgiPath) {
0130     m_cgiPath = cgiPath;
0131     emit cgiPathChanged(m_cgiPath);
0132   }
0133 }
0134 
0135 void ServerImporterConfig::setWindowGeometry(const QByteArray& windowGeometry)
0136 {
0137   if (m_windowGeometry != windowGeometry) {
0138     m_windowGeometry = windowGeometry;
0139     emit windowGeometryChanged(m_windowGeometry);
0140   }
0141 }
0142 
0143 void ServerImporterConfig::setCgiPathUsed(bool cgiPathUsed)
0144 {
0145   if (m_cgiPathUsed != cgiPathUsed) {
0146     m_cgiPathUsed = cgiPathUsed;
0147     emit cgiPathUsedChanged(m_cgiPathUsed);
0148   }
0149 }
0150 
0151 void ServerImporterConfig::setAdditionalTagsUsed(bool additionalTagsUsed)
0152 {
0153   if (m_additionalTagsUsed != additionalTagsUsed) {
0154     m_additionalTagsUsed = additionalTagsUsed;
0155     emit additionalTagsUsedChanged(m_additionalTagsUsed);
0156   }
0157 }
0158 
0159 void ServerImporterConfig::setStandardTags(bool standardTags)
0160 {
0161   if (m_standardTags != standardTags) {
0162     m_standardTags = standardTags;
0163     emit standardTagsChanged(m_standardTags);
0164   }
0165 }
0166 
0167 void ServerImporterConfig::setAdditionalTags(bool additionalTags)
0168 {
0169   if (m_additionalTags != additionalTags) {
0170     m_additionalTags = additionalTags;
0171     emit additionalTagsChanged(m_additionalTags);
0172   }
0173 }
0174 
0175 void ServerImporterConfig::setCoverArt(bool coverArt)
0176 {
0177   if (m_coverArt != coverArt) {
0178     m_coverArt = coverArt;
0179     emit coverArtChanged(m_coverArt);
0180   }
0181 }