File indexing completed on 2024-04-14 04:43:13

0001 /* AUDEX CDDA EXTRACTOR
0002  * SPDX-FileCopyrightText: Copyright (C) 2007 Marco Nelles
0003  * <https://userbase.kde.org/Audex>
0004  *
0005  * SPDX-License-Identifier: GPL-3.0-or-later
0006  */
0007 
0008 #include "profiledatadialog.h"
0009 #include "models/profilemodel.h"
0010 
0011 #include <KConfigGroup>
0012 #include <QDebug>
0013 #include <QDialogButtonBox>
0014 #include <QVBoxLayout>
0015 
0016 ProfileDataDialog::ProfileDataDialog(ProfileModel *profileModel, const int profileRow, QWidget *parent)
0017     : QDialog(parent)
0018 {
0019     Q_UNUSED(parent);
0020 
0021     profile_model = profileModel;
0022     if (!profile_model) {
0023         qDebug() << "ProfileModel is NULL!";
0024         return;
0025     }
0026 
0027     if (profileRow < 0) { // find next free row index
0028         int row = 0;
0029         while (profile_model->hasIndex(row, PROFILE_MODEL_COLUMN_NAME_INDEX))
0030             ++row;
0031         profile_model->insertRows(row, 1);
0032         profile_row = row;
0033         new_profile_mode = true;
0034     } else {
0035         profile_row = profileRow;
0036         new_profile_mode = false;
0037     }
0038 
0039     applyButton = nullptr;
0040 
0041     QWidget *widget = new QWidget(this);
0042     ui.setupUi(widget);
0043 
0044     auto *mainLayout = new QVBoxLayout;
0045     setLayout(mainLayout);
0046     mainLayout->addWidget(widget);
0047 
0048     if (!new_profile_mode) {
0049         lame_parameters.fromString(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_LAME_PARAMETERS_INDEX)).toString());
0050         oggenc_parameters.fromString(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_OGGENC_PARAMETERS_INDEX)).toString());
0051         opusenc_parameters.fromString(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_OPUSENC_PARAMETERS_INDEX)).toString());
0052         flac_parameters.fromString(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_FLAC_PARAMETERS_INDEX)).toString());
0053         faac_parameters.fromString(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_FAAC_PARAMETERS_INDEX)).toString());
0054         wave_parameters.fromString(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_WAVE_PARAMETERS_INDEX)).toString());
0055         custom_parameters.fromString(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_CUSTOM_PARAMETERS_INDEX)).toString());
0056     }
0057 
0058     lame_widget = new lameWidget(&lame_parameters, this);
0059     connect(lame_widget, SIGNAL(triggerChanged()), this, SLOT(trigger_changed()));
0060     oggenc_widget = new oggencWidget(&oggenc_parameters, this);
0061     connect(oggenc_widget, SIGNAL(triggerChanged()), this, SLOT(trigger_changed()));
0062     opusenc_widget = new opusencWidget(&opusenc_parameters, this);
0063     connect(opusenc_widget, SIGNAL(triggerChanged()), this, SLOT(trigger_changed()));
0064     flac_widget = new flacWidget(&flac_parameters, this);
0065     connect(flac_widget, SIGNAL(triggerChanged()), this, SLOT(trigger_changed()));
0066     faac_widget = new faacWidget(&faac_parameters, this);
0067     connect(faac_widget, SIGNAL(triggerChanged()), this, SLOT(trigger_changed()));
0068     wave_widget = new waveWidget(&wave_parameters, this);
0069     connect(wave_widget, SIGNAL(triggerChanged()), this, SLOT(trigger_changed()));
0070     custom_widget = new customWidget(&custom_parameters, this);
0071     connect(custom_widget, SIGNAL(triggerChanged()), this, SLOT(trigger_changed()));
0072 
0073     ui.stackedWidget_encoder->addWidget(lame_widget);
0074     ui.stackedWidget_encoder->addWidget(oggenc_widget);
0075     ui.stackedWidget_encoder->addWidget(opusenc_widget);
0076     ui.stackedWidget_encoder->addWidget(flac_widget);
0077     ui.stackedWidget_encoder->addWidget(faac_widget);
0078     ui.stackedWidget_encoder->addWidget(wave_widget);
0079     ui.stackedWidget_encoder->addWidget(custom_widget);
0080 
0081     QMap<int, QString> encoders = EncoderAssistant::availableEncoderNameList();
0082     QMap<int, QString>::const_iterator i = encoders.constBegin();
0083     while (i != encoders.constEnd()) {
0084         ui.kcombobox_encoder->addItem(i.value(), i.key());
0085         ++i;
0086     }
0087     connect(ui.kcombobox_encoder, SIGNAL(activated(int)), this, SLOT(set_encoder_by_combobox(int)));
0088 
0089     connect(ui.kpushbutton_scheme, SIGNAL(clicked()), this, SLOT(scheme_wizard()));
0090     ui.kpushbutton_scheme->setIcon(QIcon::fromTheme("tools-wizard"));
0091 
0092     connect(ui.kpushbutton_cover, SIGNAL(clicked()), this, SLOT(cover_settings()));
0093     connect(ui.kpushbutton_playlist, SIGNAL(clicked()), this, SLOT(playlist_settings()));
0094     connect(ui.kpushbutton_info, SIGNAL(clicked()), this, SLOT(info_settings()));
0095     connect(ui.kpushbutton_hashlist, SIGNAL(clicked()), this, SLOT(hashlist_settings()));
0096     connect(ui.kpushbutton_cuesheet, SIGNAL(clicked()), this, SLOT(cuesheet_settings()));
0097     connect(ui.kpushbutton_logfile, SIGNAL(clicked()), this, SLOT(logfile_settings()));
0098     connect(ui.kpushbutton_singlefile, SIGNAL(clicked()), this, SLOT(singlefile_settings()));
0099 
0100     connect(ui.checkBox_cover, SIGNAL(toggled(bool)), this, SLOT(enable_settings_cover(bool)));
0101     connect(ui.checkBox_playlist, SIGNAL(toggled(bool)), this, SLOT(enable_settings_playlist(bool)));
0102     connect(ui.checkBox_info, SIGNAL(toggled(bool)), this, SLOT(enable_settings_info(bool)));
0103     connect(ui.checkBox_hashlist, SIGNAL(toggled(bool)), this, SLOT(enable_settings_hashlist(bool)));
0104     connect(ui.checkBox_cuesheet, SIGNAL(toggled(bool)), this, SLOT(enable_settings_cuesheet(bool)));
0105     connect(ui.checkBox_logfile, SIGNAL(toggled(bool)), this, SLOT(enable_settings_logfile(bool)));
0106     connect(ui.checkBox_singlefile, SIGNAL(toggled(bool)), this, SLOT(enable_settings_singlefile(bool)));
0107     connect(ui.checkBox_singlefile, SIGNAL(toggled(bool)), this, SLOT(disable_filenames(bool)));
0108     connect(ui.checkBox_singlefile, SIGNAL(toggled(bool)), this, SLOT(disable_playlist(bool)));
0109 
0110     connect(this, SIGNAL(rejected()), this, SLOT(slotRejected()));
0111 
0112     if (!new_profile_mode) {
0113         setWindowTitle(i18n("Modify Profile"));
0114 
0115         QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply);
0116         QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0117         okButton->setDefault(true);
0118         okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0119         applyButton = buttonBox->button(QDialogButtonBox::Apply);
0120         connect(buttonBox, &QDialogButtonBox::accepted, this, &ProfileDataDialog::slotAccepted);
0121         connect(buttonBox, &QDialogButtonBox::rejected, this, &ProfileDataDialog::reject);
0122         connect(applyButton, &QPushButton::clicked, this, &ProfileDataDialog::slotApplied);
0123         mainLayout->addWidget(buttonBox);
0124 
0125         ui.qlineedit_name->setText(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_NAME_INDEX)).toString());
0126         connect(ui.qlineedit_name, SIGNAL(textEdited(const QString &)), this, SLOT(trigger_changed()));
0127         ui.qlineedit_name->setCursorPosition(0);
0128 
0129         ui.kiconbutton_icon->setIcon(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ICON_INDEX)).toString());
0130         connect(ui.kiconbutton_icon, SIGNAL(iconChanged(const QString &)), this, SLOT(trigger_changed()));
0131 
0132         set_encoder(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_SELECTED_INDEX)).toInt());
0133         connect(ui.kcombobox_encoder, SIGNAL(activated(int)), this, SLOT(trigger_changed()));
0134 
0135         ui.qlineedit_scheme->setText(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_SCHEME_INDEX)).toString());
0136         connect(ui.qlineedit_scheme, SIGNAL(textEdited(const QString &)), this, SLOT(trigger_changed()));
0137         ui.qlineedit_scheme->setCursorPosition(0);
0138 
0139         ui.checkBox_fat32compatible->setChecked(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_FAT32COMPATIBLE_INDEX)).toBool());
0140         connect(ui.checkBox_fat32compatible, SIGNAL(toggled(bool)), this, SLOT(trigger_changed()));
0141 
0142         ui.checkBox_underscore->setChecked(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_UNDERSCORE_INDEX)).toBool());
0143         connect(ui.checkBox_underscore, SIGNAL(toggled(bool)), this, SLOT(trigger_changed()));
0144 
0145         ui.checkBox_2digitstracknum->setChecked(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_2DIGITSTRACKNUM_INDEX)).toBool());
0146         connect(ui.checkBox_2digitstracknum, SIGNAL(toggled(bool)), this, SLOT(trigger_changed()));
0147 
0148         ui.checkBox_cover->setChecked(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_SC_INDEX)).toBool());
0149         enable_settings_cover(ui.checkBox_cover->isChecked());
0150         connect(ui.checkBox_cover, SIGNAL(toggled(bool)), this, SLOT(trigger_changed()));
0151 
0152         ui.checkBox_playlist->setChecked(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_INDEX)).toBool());
0153         enable_settings_playlist(ui.checkBox_playlist->isChecked());
0154         connect(ui.checkBox_playlist, SIGNAL(toggled(bool)), this, SLOT(trigger_changed()));
0155 
0156         ui.checkBox_info->setChecked(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_INF_INDEX)).toBool());
0157         enable_settings_info(ui.checkBox_info->isChecked());
0158         connect(ui.checkBox_info, SIGNAL(toggled(bool)), this, SLOT(trigger_changed()));
0159 
0160         ui.checkBox_hashlist->setChecked(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_HL_INDEX)).toBool());
0161         enable_settings_hashlist(ui.checkBox_hashlist->isChecked());
0162         connect(ui.checkBox_hashlist, SIGNAL(toggled(bool)), this, SLOT(trigger_changed()));
0163 
0164         ui.checkBox_cuesheet->setChecked(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_CUE_INDEX)).toBool());
0165         enable_settings_cuesheet(ui.checkBox_cuesheet->isChecked());
0166         connect(ui.checkBox_cuesheet, SIGNAL(toggled(bool)), this, SLOT(trigger_changed()));
0167 
0168         ui.checkBox_logfile->setChecked(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_LOG_INDEX)).toBool());
0169         enable_settings_logfile(ui.checkBox_logfile->isChecked());
0170         connect(ui.checkBox_logfile, SIGNAL(toggled(bool)), this, SLOT(trigger_changed()));
0171 
0172         ui.checkBox_singlefile->setChecked(profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_SF_INDEX)).toBool());
0173         enable_settings_singlefile(ui.checkBox_singlefile->isChecked());
0174         connect(ui.checkBox_singlefile, SIGNAL(toggled(bool)), this, SLOT(trigger_changed()));
0175 
0176         if (ui.checkBox_singlefile->isChecked())
0177             disable_playlist(true);
0178 
0179         applyButton->setEnabled(false);
0180 
0181     } else {
0182         setWindowTitle(i18n("Create Profile"));
0183 
0184         QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0185         QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0186         okButton->setDefault(true);
0187         okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0188         connect(buttonBox, &QDialogButtonBox::accepted, this, &ProfileDataDialog::slotAccepted);
0189         connect(buttonBox, &QDialogButtonBox::rejected, this, &ProfileDataDialog::reject);
0190 
0191         mainLayout->addWidget(buttonBox);
0192 
0193         ui.qlineedit_name->setText(i18n("New Profile"));
0194         ui.kiconbutton_icon->setIcon(DEFAULT_ICON);
0195 
0196         set_encoder(DEFAULT_ENCODER_SELECTED);
0197 
0198         ui.qlineedit_scheme->setText(DEFAULT_SCHEME);
0199         ui.checkBox_fat32compatible->setChecked(DEFAULT_FAT32);
0200         ui.checkBox_underscore->setChecked(DEFAULT_UNDERSCORE);
0201         ui.checkBox_2digitstracknum->setChecked(DEFAULT_2DIGITSTRACKNUM);
0202 
0203         ui.checkBox_cover->setChecked(DEFAULT_SC);
0204         ui.checkBox_playlist->setChecked(DEFAULT_PL);
0205         ui.checkBox_info->setChecked(DEFAULT_INF);
0206         ui.checkBox_hashlist->setChecked(DEFAULT_HL);
0207         ui.checkBox_cuesheet->setChecked(DEFAULT_CUE);
0208         ui.checkBox_logfile->setChecked(DEFAULT_LOG);
0209         ui.checkBox_singlefile->setChecked(DEFAULT_SF);
0210         cover_scale = DEFAULT_SC_SCALE;
0211         cover_size = DEFAULT_SC_SIZE;
0212         cover_format = DEFAULT_SC_FORMAT;
0213         cover_scheme = DEFAULT_SC_NAME;
0214         playlist_format = DEFAULT_PL_FORMAT;
0215         playlist_scheme = DEFAULT_PL_NAME;
0216         infofile_text.clear();
0217         infofile_scheme = DEFAULT_INF_NAME;
0218         infofile_suffix = DEFAULT_INF_SUFFIX;
0219         hashlist_format = DEFAULT_HL_FORMAT;
0220         hashlist_scheme = DEFAULT_HL_NAME;
0221         cuesheet_scheme = DEFAULT_CUE_NAME;
0222         cuesheet_write_mcn_and_isrc = DEFAULT_CUE_ADD_MCN_AND_ISRC;
0223         logfile_scheme = DEFAULT_CUE_NAME;
0224         logfile_write_timestamps = DEFAULT_LOG_WRITE_TIMESTAMPS;
0225         singlefile_scheme = DEFAULT_SF_NAME;
0226 
0227         enable_settings_cover(ui.checkBox_cover->isChecked());
0228         enable_settings_playlist(ui.checkBox_playlist->isChecked());
0229         enable_settings_info(ui.checkBox_info->isChecked());
0230         enable_settings_hashlist(ui.checkBox_hashlist->isChecked());
0231         enable_settings_cuesheet(ui.checkBox_cuesheet->isChecked());
0232         enable_settings_logfile(ui.checkBox_logfile->isChecked());
0233         enable_settings_singlefile(ui.checkBox_singlefile->isChecked());
0234 
0235         disable_playlist(ui.checkBox_singlefile->isChecked());
0236     }
0237 
0238     enable_filenames(!ui.checkBox_singlefile->isChecked());
0239 
0240     ui.qlineedit_name->setFocus();
0241     resize(0, 0); // For some reason dialog start of big...
0242 }
0243 
0244 ProfileDataDialog::~ProfileDataDialog()
0245 {
0246     delete lame_widget;
0247     delete oggenc_widget;
0248     delete opusenc_widget;
0249     delete flac_widget;
0250     delete faac_widget;
0251     delete wave_widget;
0252     delete custom_widget;
0253 }
0254 
0255 void ProfileDataDialog::slotAccepted()
0256 {
0257     if (save())
0258         accept();
0259     else
0260         ErrorDialog::show(this, error.message(), error.details());
0261 }
0262 
0263 void ProfileDataDialog::slotApplied()
0264 {
0265     if (!save())
0266         ErrorDialog::show(this, error.message(), error.details());
0267 }
0268 
0269 void ProfileDataDialog::slotRejected()
0270 {
0271     if (new_profile_mode)
0272         profile_model->removeRows(profile_row, 1);
0273 }
0274 
0275 void ProfileDataDialog::set_encoder(const int encoder)
0276 {
0277     set_encoder_widget((EncoderAssistant::Encoder)encoder);
0278 
0279     ui.kcombobox_encoder->setCurrentIndex(ui.kcombobox_encoder->findData(encoder));
0280 }
0281 
0282 void ProfileDataDialog::set_encoder_by_combobox(const int index)
0283 {
0284     set_encoder_widget((EncoderAssistant::Encoder)ui.kcombobox_encoder->itemData(index).toInt());
0285 }
0286 
0287 void ProfileDataDialog::trigger_changed()
0288 {
0289     if (applyButton) {
0290         applyButton->setEnabled(
0291             ui.qlineedit_name->text() != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_NAME_INDEX)).toString()
0292             || ui.kiconbutton_icon->icon() != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ICON_INDEX)).toString()
0293             || ui.kcombobox_encoder->itemData(ui.kcombobox_encoder->currentIndex())
0294                 != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_SELECTED_INDEX)).toString()
0295             || ui.qlineedit_scheme->text() != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_SCHEME_INDEX)).toString()
0296             || ui.checkBox_fat32compatible->isChecked()
0297                 != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_FAT32COMPATIBLE_INDEX)).toBool()
0298             || ui.checkBox_underscore->isChecked() != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_UNDERSCORE_INDEX)).toBool()
0299             || ui.checkBox_cover->isChecked() != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_SC_INDEX)).toBool()
0300             || ui.checkBox_playlist->isChecked() != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_INDEX)).toBool()
0301             || ui.checkBox_info->isChecked() != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_INF_INDEX)).toBool()
0302             || ui.checkBox_hashlist->isChecked() != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_HL_INDEX)).toBool()
0303             || ui.checkBox_cuesheet->isChecked() != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_CUE_INDEX)).toBool()
0304             || ui.checkBox_logfile->isChecked() != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_LOG_INDEX)).toBool()
0305             || ui.checkBox_singlefile->isChecked() != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_SF_INDEX)).toBool()
0306             || playlist_format != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_FORMAT_INDEX)).toString()
0307             || playlist_scheme != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_NAME_INDEX)).toString()
0308             || playlist_abs_file_path != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_ABS_FILE_PATH_INDEX)).toBool()
0309             || playlist_utf8 != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_UTF8_INDEX)).toBool()
0310             || infofile_text != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_INF_TEXT_INDEX)).toStringList()
0311             || infofile_scheme != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_INF_NAME_INDEX)).toString()
0312             || infofile_suffix != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_INF_SUFFIX_INDEX)).toString()
0313             || hashlist_format != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_HL_FORMAT_INDEX)).toString()
0314             || hashlist_scheme != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_HL_NAME_INDEX)).toString()
0315             || logfile_scheme != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_LOG_NAME_INDEX)).toString()
0316             || logfile_write_timestamps != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_LOG_WRITE_TIMESTAMPS_INDEX)).toBool()
0317             || singlefile_scheme != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_SF_NAME_INDEX)).toString()
0318             || singlefile_scheme != profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_SF_NAME_INDEX)).toString()
0319             || lame_widget->isChanged() || oggenc_widget->isChanged() || flac_widget->isChanged() || faac_widget->isChanged() || wave_widget->isChanged()
0320             || custom_widget->isChanged());
0321     }
0322 }
0323 
0324 void ProfileDataDialog::enable_settings_cover(bool enabled)
0325 {
0326     ui.kpushbutton_cover->setEnabled(enabled);
0327 }
0328 
0329 void ProfileDataDialog::enable_settings_playlist(bool enabled)
0330 {
0331     ui.kpushbutton_playlist->setEnabled(enabled);
0332 }
0333 
0334 void ProfileDataDialog::enable_settings_info(bool enabled)
0335 {
0336     ui.kpushbutton_info->setEnabled(enabled);
0337 }
0338 
0339 void ProfileDataDialog::enable_settings_hashlist(bool enabled)
0340 {
0341     ui.kpushbutton_hashlist->setEnabled(enabled);
0342 }
0343 
0344 void ProfileDataDialog::enable_settings_cuesheet(bool enabled)
0345 {
0346     ui.kpushbutton_cuesheet->setEnabled(enabled);
0347 }
0348 
0349 void ProfileDataDialog::enable_settings_logfile(bool enabled)
0350 {
0351     ui.kpushbutton_logfile->setEnabled(enabled);
0352 }
0353 
0354 void ProfileDataDialog::enable_settings_singlefile(bool enabled)
0355 {
0356     ui.kpushbutton_singlefile->setEnabled(enabled);
0357 }
0358 
0359 void ProfileDataDialog::disable_playlist(bool disabled)
0360 {
0361     ui.checkBox_playlist->setEnabled(!disabled);
0362     ui.kpushbutton_playlist->setEnabled(!disabled);
0363 }
0364 
0365 void ProfileDataDialog::enable_filenames(bool enabled)
0366 {
0367     ui.groupBox_filenames->setEnabled(enabled);
0368 }
0369 
0370 void ProfileDataDialog::disable_filenames(bool disabled)
0371 {
0372     ui.groupBox_filenames->setEnabled(!disabled);
0373 }
0374 
0375 void ProfileDataDialog::scheme_wizard()
0376 {
0377     SchemeWizardDialog *dialog = new SchemeWizardDialog(ui.qlineedit_scheme->text(), this);
0378 
0379     if (dialog->exec() != QDialog::Accepted) {
0380         delete dialog;
0381         return;
0382     }
0383 
0384     ui.qlineedit_scheme->setText(dialog->scheme);
0385 
0386     delete dialog;
0387 
0388     trigger_changed();
0389 }
0390 
0391 void ProfileDataDialog::cover_settings()
0392 {
0393     ProfileDataCoverDialog *dialog = new ProfileDataCoverDialog(profile_model, profile_row, new_profile_mode, this);
0394 
0395     if (dialog->exec() != QDialog::Accepted) {
0396         delete dialog;
0397         return;
0398     }
0399 
0400     delete dialog;
0401 }
0402 
0403 void ProfileDataDialog::playlist_settings()
0404 {
0405     ProfileDataPlaylistDialog *dialog = new ProfileDataPlaylistDialog(profile_model, profile_row, new_profile_mode, this);
0406 
0407     if (dialog->exec() != QDialog::Accepted) {
0408         delete dialog;
0409         return;
0410     }
0411 
0412     delete dialog;
0413 }
0414 
0415 void ProfileDataDialog::info_settings()
0416 {
0417     ProfileDataInfoDialog *dialog = new ProfileDataInfoDialog(profile_model, profile_row, new_profile_mode, this);
0418 
0419     if (dialog->exec() != QDialog::Accepted) {
0420         delete dialog;
0421         return;
0422     }
0423 
0424     delete dialog;
0425 }
0426 
0427 void ProfileDataDialog::hashlist_settings()
0428 {
0429     ProfileDataHashlistDialog *dialog = new ProfileDataHashlistDialog(profile_model, profile_row, new_profile_mode, this);
0430 
0431     if (dialog->exec() != QDialog::Accepted) {
0432         delete dialog;
0433         return;
0434     }
0435 
0436     delete dialog;
0437 }
0438 
0439 void ProfileDataDialog::cuesheet_settings()
0440 {
0441     ProfileDataCueSheetDialog *dialog = new ProfileDataCueSheetDialog(profile_model, profile_row, new_profile_mode, this);
0442 
0443     if (dialog->exec() != QDialog::Accepted) {
0444         delete dialog;
0445         return;
0446     }
0447 
0448     delete dialog;
0449 }
0450 
0451 void ProfileDataDialog::logfile_settings()
0452 {
0453     ProfileDataLogFileDialog *dialog = new ProfileDataLogFileDialog(profile_model, profile_row, new_profile_mode, this);
0454 
0455     if (dialog->exec() != QDialog::Accepted) {
0456         delete dialog;
0457         return;
0458     }
0459 
0460     delete dialog;
0461 }
0462 
0463 void ProfileDataDialog::singlefile_settings()
0464 {
0465     ProfileDataSingleFileDialog *dialog = new ProfileDataSingleFileDialog(profile_model, profile_row, new_profile_mode, this);
0466 
0467     if (dialog->exec() != QDialog::Accepted) {
0468         delete dialog;
0469         return;
0470     }
0471 
0472     delete dialog;
0473 
0474     trigger_changed();
0475 }
0476 
0477 void ProfileDataDialog::set_encoder_widget(const EncoderAssistant::Encoder encoder)
0478 {
0479     switch (encoder) {
0480     case EncoderAssistant::LAME:
0481         ui.stackedWidget_encoder->setCurrentWidget(lame_widget);
0482         break;
0483     case EncoderAssistant::OGGENC:
0484         ui.stackedWidget_encoder->setCurrentWidget(oggenc_widget);
0485         break;
0486     case EncoderAssistant::OPUSENC:
0487         ui.stackedWidget_encoder->setCurrentWidget(opusenc_widget);
0488         break;
0489     case EncoderAssistant::FLAC:
0490         ui.stackedWidget_encoder->setCurrentWidget(flac_widget);
0491         break;
0492     case EncoderAssistant::FAAC:
0493         ui.stackedWidget_encoder->setCurrentWidget(faac_widget);
0494         break;
0495     case EncoderAssistant::WAVE:
0496         ui.stackedWidget_encoder->setCurrentWidget(wave_widget);
0497         break;
0498     case EncoderAssistant::CUSTOM:
0499         ui.stackedWidget_encoder->setCurrentWidget(custom_widget);
0500         break;
0501     case EncoderAssistant::NUM:
0502         break;
0503     }
0504 }
0505 
0506 bool ProfileDataDialog::save()
0507 {
0508     bool success = true;
0509 
0510     error.clear();
0511 
0512     if (success)
0513         success = lame_widget->save();
0514     if (!success)
0515         error = lame_widget->lastError();
0516 
0517     if (success) {
0518         success = oggenc_widget->save();
0519         if (!success)
0520             error = oggenc_widget->lastError();
0521     }
0522 
0523     if (success) {
0524         success = opusenc_widget->save();
0525         if (!success)
0526             error = opusenc_widget->lastError();
0527     }
0528 
0529     if (success) {
0530         success = flac_widget->save();
0531         if (!success)
0532             error = flac_widget->lastError();
0533     }
0534 
0535     if (success) {
0536         success = faac_widget->save();
0537         if (!success)
0538             error = faac_widget->lastError();
0539     }
0540 
0541     if (success) {
0542         success = wave_widget->save();
0543         if (!success)
0544             error = wave_widget->lastError();
0545     }
0546 
0547     if (success) {
0548         success = custom_widget->save();
0549         if (!success)
0550             error = custom_widget->lastError();
0551     }
0552 
0553     if (success)
0554         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_NAME_INDEX), ui.qlineedit_name->text());
0555     if (success)
0556         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ICON_INDEX), ui.kiconbutton_icon->icon());
0557     if (success)
0558         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_SELECTED_INDEX),
0559                                          ui.kcombobox_encoder->itemData(ui.kcombobox_encoder->currentIndex()));
0560     if (success)
0561         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_SCHEME_INDEX), ui.qlineedit_scheme->text());
0562     if (success)
0563         success =
0564             profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_FAT32COMPATIBLE_INDEX), ui.checkBox_fat32compatible->isChecked());
0565     if (success)
0566         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_UNDERSCORE_INDEX), ui.checkBox_underscore->isChecked());
0567     if (success)
0568         success =
0569             profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_2DIGITSTRACKNUM_INDEX), ui.checkBox_2digitstracknum->isChecked());
0570     if (success)
0571         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_SC_INDEX), ui.checkBox_cover->isChecked());
0572     if (success)
0573         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_INDEX), ui.checkBox_playlist->isChecked());
0574     if (success)
0575         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_INF_INDEX), ui.checkBox_info->isChecked());
0576     if (success)
0577         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_HL_INDEX), ui.checkBox_hashlist->isChecked());
0578     if (success)
0579         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_CUE_INDEX), ui.checkBox_cuesheet->isChecked());
0580     if (success)
0581         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_LOG_INDEX), ui.checkBox_logfile->isChecked());
0582     if (success)
0583         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_SF_INDEX), ui.checkBox_singlefile->isChecked());
0584     if (success)
0585         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_LAME_PARAMETERS_INDEX), lame_parameters.toString());
0586     if (success)
0587         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_OGGENC_PARAMETERS_INDEX), oggenc_parameters.toString());
0588     if (success)
0589         success =
0590             profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_OPUSENC_PARAMETERS_INDEX), opusenc_parameters.toString());
0591     if (success)
0592         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_FLAC_PARAMETERS_INDEX), flac_parameters.toString());
0593     if (success)
0594         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_FAAC_PARAMETERS_INDEX), faac_parameters.toString());
0595     if (success)
0596         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_WAVE_PARAMETERS_INDEX), wave_parameters.toString());
0597     if (success)
0598         success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_ENCODER_CUSTOM_PARAMETERS_INDEX), custom_parameters.toString());
0599     if (!success)
0600         error = profile_model->lastError();
0601 
0602     if (success) {
0603         profile_model->commit();
0604         if (applyButton)
0605             applyButton->setEnabled(false);
0606         return true;
0607     }
0608 
0609     return false;
0610 }