File indexing completed on 2025-02-23 04:34:23

0001 /**
0002  * \file filenameformatbox.cpp
0003  * Group box containing filename format options.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 12 Nov 2017
0008  *
0009  * Copyright (C) 2017-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 "filenameformatbox.h"
0028 #include <QFormLayout>
0029 #include <QCheckBox>
0030 #include <QSpinBox>
0031 #include "formatconfig.h"
0032 
0033 /**
0034  * Constructor.
0035  *
0036  * @param title  title
0037  * @param parent parent widget
0038  */
0039 FilenameFormatBox::FilenameFormatBox(const QString& title, QWidget* parent)
0040   : FormatBox(title, parent),
0041     m_useForOtherFileNamesCheckBox(nullptr),
0042     m_maximumLengthCheckBox(nullptr), m_maximumLengthSpinBox(nullptr)
0043 {
0044   if (auto formLayout = getFormLayout()) {
0045     m_useForOtherFileNamesCheckBox =
0046         new QCheckBox(tr("Use for playlist and folder names"));
0047     m_maximumLengthCheckBox = new QCheckBox(tr("Maximum length:"));
0048     m_maximumLengthSpinBox = new QSpinBox;
0049     m_maximumLengthSpinBox->setMinimum(10);
0050     m_maximumLengthSpinBox->setMaximum(255);
0051     formLayout->insertRow(1, m_useForOtherFileNamesCheckBox);
0052     formLayout->setLabelAlignment(Qt::AlignLeft);
0053     formLayout->insertRow(2, m_maximumLengthCheckBox, m_maximumLengthSpinBox);
0054     connect(m_maximumLengthCheckBox, &QAbstractButton::toggled,
0055             m_maximumLengthSpinBox, &QWidget::setEnabled);
0056   }
0057 }
0058 
0059 /**
0060  * Set the values from a format configuration.
0061  *
0062  * @param cfg format configuration
0063  */
0064 void FilenameFormatBox::fromFormatConfig(const FormatConfig& cfg)
0065 {
0066   FormatBox::fromFormatConfig(cfg);
0067   if (m_useForOtherFileNamesCheckBox) {
0068     m_useForOtherFileNamesCheckBox->setChecked(cfg.useForOtherFileNames());
0069   }
0070   if (m_maximumLengthCheckBox) {
0071     m_maximumLengthCheckBox->setChecked(cfg.enableMaximumLength());
0072   }
0073   if (m_maximumLengthSpinBox) {
0074     m_maximumLengthSpinBox->setValue(cfg.maximumLength());
0075     m_maximumLengthSpinBox->setEnabled(cfg.enableMaximumLength());
0076   }
0077 }
0078 
0079 /**
0080  * Store the values in a format configuration.
0081  *
0082  * @param cfg format configuration
0083  */
0084 void FilenameFormatBox::toFormatConfig(FormatConfig& cfg) const
0085 {
0086   FormatBox::toFormatConfig(cfg);
0087   if (m_useForOtherFileNamesCheckBox) {
0088     cfg.setUseForOtherFileNames(m_useForOtherFileNamesCheckBox->isChecked());
0089   }
0090   if (m_maximumLengthCheckBox) {
0091     cfg.setEnableMaximumLength(m_maximumLengthCheckBox->isChecked());
0092   }
0093   if (m_maximumLengthSpinBox) {
0094     cfg.setMaximumLength(m_maximumLengthSpinBox->value());
0095   }
0096 }