File indexing completed on 2025-02-23 04:34:18
0001 /** 0002 * \file numbertracksdialog.cpp 0003 * Number tracks dialog. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 25 May 2006 0008 * 0009 * Copyright (C) 2006-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 "numbertracksdialog.h" 0028 #include <QLayout> 0029 #include <QPushButton> 0030 #include <QLabel> 0031 #include <QSpinBox> 0032 #include <QString> 0033 #include <QComboBox> 0034 #include <QCheckBox> 0035 #include <QVBoxLayout> 0036 #include <QHBoxLayout> 0037 #include "numbertracksconfig.h" 0038 #include "contexthelp.h" 0039 0040 /** 0041 * Constructor. 0042 * 0043 * @param parent parent widget 0044 */ 0045 NumberTracksDialog::NumberTracksDialog(QWidget* parent) 0046 : QDialog(parent) 0047 { 0048 setObjectName(QLatin1String("NumberTracksDialog")); 0049 setModal(true); 0050 setWindowTitle(tr("Number Tracks")); 0051 0052 const NumberTracksConfig& cfg = NumberTracksConfig::instance(); 0053 auto vlayout = new QVBoxLayout(this); 0054 auto trackLayout = new QHBoxLayout; 0055 m_numberTracksCheckBox = new QCheckBox(tr("Start &number:"), this); 0056 m_numberTracksCheckBox->setChecked(cfg.isTrackNumberingEnabled()); 0057 m_trackSpinBox = new QSpinBox(this); 0058 m_trackSpinBox->setMaximum(9999); 0059 m_trackSpinBox->setValue(cfg.numberTracksStart()); 0060 trackLayout->addWidget(m_numberTracksCheckBox); 0061 trackLayout->addWidget(m_trackSpinBox); 0062 0063 auto trackSpacer = new QSpacerItem(16, 0, QSizePolicy::Expanding, 0064 QSizePolicy::Minimum); 0065 trackLayout->addItem(trackSpacer); 0066 0067 auto destLabel = new QLabel(tr("&Destination:"), this); 0068 m_destComboBox = new QComboBox(this); 0069 m_destComboBox->setEditable(false); 0070 const QList<QPair<Frame::TagVersion, QString> > tagVersions = 0071 Frame::availableTagVersions(); 0072 for (auto it = tagVersions.constBegin(); it != tagVersions.constEnd(); ++it) { 0073 m_destComboBox->addItem(it->second, it->first); 0074 } 0075 m_destComboBox->setCurrentIndex( 0076 m_destComboBox->findData(cfg.numberTracksDestination())); 0077 trackLayout->addWidget(destLabel); 0078 trackLayout->addWidget(m_destComboBox); 0079 destLabel->setBuddy(m_destComboBox); 0080 0081 vlayout->addLayout(trackLayout); 0082 0083 m_resetCounterCheckBox = new QCheckBox(tr("&Reset counter for each folder"), 0084 this); 0085 m_resetCounterCheckBox->setChecked(cfg.isDirectoryCounterResetEnabled()); 0086 vlayout->addWidget(m_resetCounterCheckBox); 0087 0088 auto totalLayout = new QHBoxLayout; 0089 m_totalNumTracksCheckBox = new QCheckBox(tr("&Total number of tracks:"), 0090 this); 0091 m_totalNumTrackSpinBox = new QSpinBox(this); 0092 if (m_totalNumTracksCheckBox && m_totalNumTrackSpinBox) { 0093 m_totalNumTrackSpinBox->setMaximum(999); 0094 totalLayout->addWidget(m_totalNumTracksCheckBox); 0095 totalLayout->addWidget(m_totalNumTrackSpinBox); 0096 } 0097 auto totalSpacer = new QSpacerItem(16, 0, QSizePolicy::Expanding, 0098 QSizePolicy::Minimum); 0099 totalLayout->addItem(totalSpacer); 0100 vlayout->addLayout(totalLayout); 0101 0102 auto hlayout = new QHBoxLayout; 0103 auto helpButton = new QPushButton(tr("&Help"), this); 0104 helpButton->setAutoDefault(false); 0105 hlayout->addWidget(helpButton); 0106 connect(helpButton, &QAbstractButton::clicked, this, &NumberTracksDialog::showHelp); 0107 0108 auto saveButton = new QPushButton(tr("&Save Settings"), this); 0109 saveButton->setAutoDefault(false); 0110 hlayout->addWidget(saveButton); 0111 connect(saveButton, &QAbstractButton::clicked, this, &NumberTracksDialog::saveConfig); 0112 0113 auto hspacer = new QSpacerItem(16, 0, QSizePolicy::Expanding, 0114 QSizePolicy::Minimum); 0115 hlayout->addItem(hspacer); 0116 0117 auto okButton = new QPushButton(tr("&OK"), this); 0118 okButton->setAutoDefault(false); 0119 okButton->setDefault(true); 0120 hlayout->addWidget(okButton); 0121 connect(okButton, &QAbstractButton::clicked, this, &QDialog::accept); 0122 0123 auto cancelButton = new QPushButton(tr("&Cancel"), this); 0124 cancelButton->setAutoDefault(false); 0125 hlayout->addWidget(cancelButton); 0126 connect(cancelButton, &QAbstractButton::clicked, this, &QDialog::reject); 0127 0128 vlayout->addLayout(hlayout); 0129 0130 if (QByteArray geometry = cfg.windowGeometry(); !geometry.isEmpty()) { 0131 restoreGeometry(geometry); 0132 } 0133 } 0134 0135 /** 0136 * Get start number. 0137 */ 0138 int NumberTracksDialog::getStartNumber() const 0139 { 0140 return m_trackSpinBox->value(); 0141 } 0142 0143 /** 0144 * Get destination. 0145 * 0146 * @return TagV1, TagV2 or TagV2V1 if ID3v1, ID2v2 or both are destination 0147 */ 0148 Frame::TagVersion NumberTracksDialog::getDestination() const 0149 { 0150 return Frame::tagVersionCast( 0151 m_destComboBox->itemData(m_destComboBox->currentIndex()).toInt()); 0152 } 0153 0154 /** 0155 * Save the local settings to the configuration. 0156 */ 0157 void NumberTracksDialog::saveConfig() 0158 { 0159 NumberTracksConfig& cfg = NumberTracksConfig::instance(); 0160 cfg.setNumberTracksDestination(getDestination()); 0161 cfg.setNumberTracksStart(m_trackSpinBox->value()); 0162 cfg.setTrackNumberingEnabled(isTrackNumberingEnabled()); 0163 cfg.setDirectoryCounterResetEnabled(isDirectoryCounterResetEnabled()); 0164 QByteArray geometry = saveGeometry(); 0165 cfg.setWindowGeometry(geometry); 0166 } 0167 0168 /** 0169 * Show help. 0170 */ 0171 void NumberTracksDialog::showHelp() 0172 { 0173 ContextHelp::displayHelp(QLatin1String("number-tracks")); 0174 } 0175 0176 /** 0177 * Set the total number of tracks. 0178 * 0179 * @param numTracks number of tracks 0180 * @param enable true to enable setting of total 0181 */ 0182 void NumberTracksDialog::setTotalNumberOfTracks(int numTracks, bool enable) 0183 { 0184 m_totalNumTrackSpinBox->setValue(numTracks); 0185 m_totalNumTracksCheckBox->setChecked(enable); 0186 } 0187 0188 /** 0189 * Get the total number of tracks. 0190 * 0191 * @param enable true is returned here if total number of tracks is checked 0192 * 0193 * @return number of tracks entered 0194 */ 0195 int NumberTracksDialog::getTotalNumberOfTracks(bool* enable) const 0196 { 0197 *enable = m_totalNumTracksCheckBox->isChecked(); 0198 return m_totalNumTrackSpinBox->value(); 0199 } 0200 0201 /** 0202 * Check if track numbering is enabled. 0203 * @return true if enabled. 0204 */ 0205 bool NumberTracksDialog::isTrackNumberingEnabled() const 0206 { 0207 return m_numberTracksCheckBox->isChecked(); 0208 } 0209 0210 /** 0211 * Check if counter has to be reset for each directory. 0212 * @return true if enabled. 0213 */ 0214 bool NumberTracksDialog::isDirectoryCounterResetEnabled() const 0215 { 0216 return m_resetCounterCheckBox->isChecked(); 0217 }