1 /**
2  * \file batchimportdialog.cpp
3  * Dialog to add or edit a batch import source.
4  *
5  * \b Project: Kid3
6  * \author Urs Fleisch
7  * \date 2 Jan 2013
8  *
9  * Copyright (C) 2013-2018  Urs Fleisch
10  *
11  * This file is part of Kid3.
12  *
13  * Kid3 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * Kid3 is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 #include "batchimportsourcedialog.h"
28 #include <QHBoxLayout>
29 #include <QVBoxLayout>
30 #include <QComboBox>
31 #include <QCheckBox>
32 #include <QSpinBox>
33 #include <QLabel>
34 #include <QDialogButtonBox>
35 
36 /**
37  * Constructor.
38  * @param parent parent widget
39  */
BatchImportSourceDialog(QWidget * parent)40 BatchImportSourceDialog::BatchImportSourceDialog(QWidget* parent)
41   : QDialog(parent)
42 {
43   setObjectName(QLatin1String("BatchImportSourceDialog"));
44   setWindowTitle(tr("Import Source"));
45   setSizeGripEnabled(true);
46 
47   auto vlayout = new QVBoxLayout(this);
48 
49   auto serverLayout = new QHBoxLayout;
50   QLabel* serverLabel = new QLabel(tr("&Server:"));
51   serverLayout->addWidget(serverLabel);
52   m_serverComboBox = new QComboBox;
53   serverLabel->setBuddy(m_serverComboBox);
54   serverLayout->addWidget(m_serverComboBox);
55   vlayout->addLayout(serverLayout);
56 
57   auto accuracyLayout = new QHBoxLayout;
58   QLabel* accuracyLabel = new QLabel(tr("&Accuracy:"));
59   accuracyLayout->addWidget(accuracyLabel);
60   m_accuracySpinBox = new QSpinBox;
61   m_accuracySpinBox->setRange(0, 100);
62   m_accuracySpinBox->setValue(75);
63   accuracyLabel->setBuddy(m_accuracySpinBox);
64   accuracyLayout->addWidget(m_accuracySpinBox);
65   vlayout->addLayout(accuracyLayout);
66 
67   auto tagsCoverLayout = new QHBoxLayout;
68   m_standardTagsCheckBox = new QCheckBox(tr("&Standard Tags"));
69   m_standardTagsCheckBox->setChecked(true);
70   m_additionalTagsCheckBox = new QCheckBox(tr("&Additional Tags"));
71   m_additionalTagsCheckBox->setChecked(true);
72   m_coverArtCheckBox = new QCheckBox(tr("C&over Art"));
73   m_coverArtCheckBox->setChecked(true);
74   tagsCoverLayout->addWidget(m_standardTagsCheckBox);
75   tagsCoverLayout->addWidget(m_additionalTagsCheckBox);
76   tagsCoverLayout->addWidget(m_coverArtCheckBox);
77   vlayout->addLayout(tagsCoverLayout);
78 
79   QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |
80                                                      QDialogButtonBox::Cancel);
81   connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
82   connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
83   vlayout->addWidget(buttonBox);
84 }
85 
86 /**
87  * Set names of import servers.
88  * @param servers server names
89  */
setServerNames(const QStringList & servers)90 void BatchImportSourceDialog::setServerNames(const QStringList& servers)
91 {
92   if (m_serverComboBox) {
93     m_serverComboBox->clear();
94     m_serverComboBox->addItems(servers);
95     m_serverComboBox->setCurrentIndex(servers.size() - 1);
96   }
97 }
98 
99 /**
100  * Fill batch import source from dialog controls.
101  * @param source batch import source to be filled
102  */
getSource(BatchImportProfile::Source & source)103 void BatchImportSourceDialog::getSource(BatchImportProfile::Source& source)
104 {
105   source.setName(m_serverComboBox->currentText());
106   source.setRequiredAccuracy(m_accuracySpinBox->value());
107   source.enableStandardTags(m_standardTagsCheckBox->isChecked());
108   source.enableAdditionalTags(m_additionalTagsCheckBox->isChecked());
109   source.enableCoverArt(m_coverArtCheckBox->isChecked());
110 }
111 
112 /**
113  * Set dialog controls from batch import source.
114  * @param source batch import source containing properties to be set
115  */
setSource(const BatchImportProfile::Source & source)116 void BatchImportSourceDialog::setSource(const BatchImportProfile::Source& source)
117 {
118   int index = m_serverComboBox->findText(source.getName());
119   if (index != -1) {
120     m_serverComboBox->setCurrentIndex(index);
121   }
122   m_accuracySpinBox->setValue(source.getRequiredAccuracy());
123   m_standardTagsCheckBox->setChecked(source.standardTagsEnabled());
124   m_additionalTagsCheckBox->setChecked(source.additionalTagsEnabled());
125   m_coverArtCheckBox->setChecked(source.coverArtEnabled());
126 }
127