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

0001 /**
0002  * \file findreplaceconfig.cpp
0003  * Configuration for find/replace dialog.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 5 Mar 2014
0008  *
0009  * Copyright (C) 2014-2024  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 "findreplaceconfig.h"
0028 #include "isettings.h"
0029 
0030 int FindReplaceConfig::s_index = -1;
0031 
0032 /**
0033  * Constructor.
0034  */
0035 FindReplaceConfig::FindReplaceConfig()
0036   : StoredConfig(QLatin1String("FindReplace"))
0037 {
0038 }
0039 
0040 /**
0041  * Persist configuration.
0042  *
0043  * @param config configuration
0044  */
0045 void FindReplaceConfig::writeToConfig(ISettings* config) const
0046 {
0047   config->beginGroup(m_group);
0048   config->setValue(QLatin1String("Flags"),
0049                    QVariant(static_cast<int>(m_params.getFlags())));
0050   config->setValue(QLatin1String("Frames"), QVariant(m_params.getFrameMask()
0051 #ifdef Q_OS_MAC
0052                    // Convince Mac OS X to store a 64-bit value.
0053                                                      | (Q_UINT64_C(1) << 63)
0054 #endif
0055                                                      ));
0056   config->endGroup();
0057   config->beginGroup(m_group, true);
0058   config->setValue(QLatin1String("WindowGeometry"), QVariant(m_windowGeometry));
0059   config->endGroup();
0060 }
0061 
0062 /**
0063  * Read persisted configuration.
0064  *
0065  * @param config configuration
0066  */
0067 void FindReplaceConfig::readFromConfig(ISettings* config)
0068 {
0069   config->beginGroup(m_group);
0070   m_params.setFlags(static_cast<TagSearcher::SearchFlags>(
0071                       config->value(QLatin1String("Flags"),
0072                         static_cast<int>(m_params.getFlags())).toInt()));
0073   m_params.setFrameMask(config->value(QLatin1String("Frames"),
0074                                       m_params.getFrameMask()).toULongLong()
0075 #ifdef Q_OS_MAC
0076                         & ~(Q_UINT64_C(1) << 63)
0077 #endif
0078                         );
0079   config->endGroup();
0080   config->beginGroup(m_group, true);
0081   m_windowGeometry = config->value(QLatin1String("WindowGeometry"),
0082                                    m_windowGeometry).toByteArray();
0083   config->endGroup();
0084 }
0085 
0086 void FindReplaceConfig::setParameterList(const QVariantList& lst)
0087 {
0088   if (parameterList() != lst) {
0089     m_params.fromVariantList(lst);
0090     emit parameterListChanged();
0091   }
0092 }
0093 
0094 void FindReplaceConfig::setWindowGeometry(const QByteArray& windowGeometry)
0095 {
0096   if (m_windowGeometry != windowGeometry) {
0097     m_windowGeometry = windowGeometry;
0098     emit windowGeometryChanged(m_windowGeometry);
0099   }
0100 }