File indexing completed on 2025-02-23 04:34:15
0001 /** 0002 * \file batchimportdialog.cpp 0003 * Dialog to add or edit a batch import source. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 2 Jan 2013 0008 * 0009 * Copyright (C) 2013-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 "batchimportsourcedialog.h" 0028 #include <QHBoxLayout> 0029 #include <QVBoxLayout> 0030 #include <QComboBox> 0031 #include <QCheckBox> 0032 #include <QSpinBox> 0033 #include <QLabel> 0034 #include <QDialogButtonBox> 0035 0036 /** 0037 * Constructor. 0038 * @param parent parent widget 0039 */ 0040 BatchImportSourceDialog::BatchImportSourceDialog(QWidget* parent) 0041 : QDialog(parent) 0042 { 0043 setObjectName(QLatin1String("BatchImportSourceDialog")); 0044 setWindowTitle(tr("Import Source")); 0045 setSizeGripEnabled(true); 0046 0047 auto vlayout = new QVBoxLayout(this); 0048 0049 auto serverLayout = new QHBoxLayout; 0050 auto serverLabel = new QLabel(tr("&Server:")); 0051 serverLayout->addWidget(serverLabel); 0052 m_serverComboBox = new QComboBox; 0053 serverLabel->setBuddy(m_serverComboBox); 0054 serverLayout->addWidget(m_serverComboBox); 0055 vlayout->addLayout(serverLayout); 0056 0057 auto accuracyLayout = new QHBoxLayout; 0058 auto accuracyLabel = new QLabel(tr("&Accuracy:")); 0059 accuracyLayout->addWidget(accuracyLabel); 0060 m_accuracySpinBox = new QSpinBox; 0061 m_accuracySpinBox->setRange(0, 100); 0062 m_accuracySpinBox->setValue(75); 0063 accuracyLabel->setBuddy(m_accuracySpinBox); 0064 accuracyLayout->addWidget(m_accuracySpinBox); 0065 vlayout->addLayout(accuracyLayout); 0066 0067 auto tagsCoverLayout = new QHBoxLayout; 0068 m_standardTagsCheckBox = new QCheckBox(tr("&Standard Tags")); 0069 m_standardTagsCheckBox->setChecked(true); 0070 m_additionalTagsCheckBox = new QCheckBox(tr("&Additional Tags")); 0071 m_additionalTagsCheckBox->setChecked(true); 0072 m_coverArtCheckBox = new QCheckBox(tr("C&over Art")); 0073 m_coverArtCheckBox->setChecked(true); 0074 tagsCoverLayout->addWidget(m_standardTagsCheckBox); 0075 tagsCoverLayout->addWidget(m_additionalTagsCheckBox); 0076 tagsCoverLayout->addWidget(m_coverArtCheckBox); 0077 vlayout->addLayout(tagsCoverLayout); 0078 0079 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | 0080 QDialogButtonBox::Cancel); 0081 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0082 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0083 vlayout->addWidget(buttonBox); 0084 } 0085 0086 /** 0087 * Set names of import servers. 0088 * @param servers server names 0089 */ 0090 void BatchImportSourceDialog::setServerNames(const QStringList& servers) 0091 { 0092 if (m_serverComboBox) { 0093 m_serverComboBox->clear(); 0094 m_serverComboBox->addItems(servers); 0095 m_serverComboBox->setCurrentIndex(servers.size() - 1); 0096 } 0097 } 0098 0099 /** 0100 * Fill batch import source from dialog controls. 0101 * @param source batch import source to be filled 0102 */ 0103 void BatchImportSourceDialog::getSource(BatchImportProfile::Source& source) const 0104 { 0105 source.setName(m_serverComboBox->currentText()); 0106 source.setRequiredAccuracy(m_accuracySpinBox->value()); 0107 source.enableStandardTags(m_standardTagsCheckBox->isChecked()); 0108 source.enableAdditionalTags(m_additionalTagsCheckBox->isChecked()); 0109 source.enableCoverArt(m_coverArtCheckBox->isChecked()); 0110 } 0111 0112 /** 0113 * Set dialog controls from batch import source. 0114 * @param source batch import source containing properties to be set 0115 */ 0116 void BatchImportSourceDialog::setSource(const BatchImportProfile::Source& source) 0117 { 0118 if (int index = m_serverComboBox->findText(source.getName()); index != -1) { 0119 m_serverComboBox->setCurrentIndex(index); 0120 } 0121 m_accuracySpinBox->setValue(source.getRequiredAccuracy()); 0122 m_standardTagsCheckBox->setChecked(source.standardTagsEnabled()); 0123 m_additionalTagsCheckBox->setChecked(source.additionalTagsEnabled()); 0124 m_coverArtCheckBox->setChecked(source.coverArtEnabled()); 0125 }