File indexing completed on 2024-04-28 16:06:15
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 "profiledatasinglefiledialog.h" 0009 0010 #include <QDialogButtonBox> 0011 #include <QVBoxLayout> 0012 0013 ProfileDataSingleFileDialog::ProfileDataSingleFileDialog(ProfileModel *profile_model, const int profile_row, const bool new_profile_mode, QWidget *parent) 0014 : QDialog(parent) 0015 { 0016 Q_UNUSED(parent); 0017 0018 this->profile_model = profile_model; 0019 this->profile_row = profile_row; 0020 this->new_profile_mode = new_profile_mode; 0021 0022 applyButton = nullptr; 0023 0024 setWindowTitle(i18n("Single File Settings")); 0025 0026 // profile data single file data 0027 QString scheme = profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_SF_NAME_INDEX)).toString(); 0028 0029 auto *mainLayout = new QVBoxLayout; 0030 setLayout(mainLayout); 0031 0032 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply); 0033 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0034 okButton->setDefault(true); 0035 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0036 applyButton = buttonBox->button(QDialogButtonBox::Apply); 0037 connect(buttonBox, &QDialogButtonBox::accepted, this, &ProfileDataSingleFileDialog::slotAccepted); 0038 connect(buttonBox, &QDialogButtonBox::rejected, this, &ProfileDataSingleFileDialog::reject); 0039 connect(applyButton, &QPushButton::clicked, this, &ProfileDataSingleFileDialog::slotApplied); 0040 0041 QWidget *widget = new QWidget(this); 0042 mainLayout->addWidget(widget); 0043 mainLayout->addWidget(buttonBox); 0044 ui.setupUi(widget); 0045 0046 connect(ui.kpushbutton_scheme, SIGNAL(clicked()), this, SLOT(scheme_wizard())); 0047 ui.kpushbutton_scheme->setIcon(QIcon::fromTheme("tools-wizard")); 0048 0049 ui.qlineedit_scheme->setText(scheme); 0050 connect(ui.qlineedit_scheme, SIGNAL(textEdited(const QString &)), this, SLOT(trigger_changed())); 0051 0052 if (applyButton) 0053 applyButton->setEnabled(false); 0054 } 0055 0056 ProfileDataSingleFileDialog::~ProfileDataSingleFileDialog() 0057 { 0058 } 0059 0060 void ProfileDataSingleFileDialog::slotAccepted() 0061 { 0062 if (save()) 0063 accept(); 0064 else 0065 ErrorDialog::show(this, error.message(), error.details()); 0066 } 0067 0068 void ProfileDataSingleFileDialog::slotApplied() 0069 { 0070 if (!save()) 0071 ErrorDialog::show(this, error.message(), error.details()); 0072 } 0073 0074 void ProfileDataSingleFileDialog::scheme_wizard() 0075 { 0076 FilenameSchemeWizardDialog *dialog = new FilenameSchemeWizardDialog(ui.qlineedit_scheme->text(), "wav", this); 0077 0078 if (dialog->exec() != QDialog::Accepted) { 0079 delete dialog; 0080 return; 0081 } 0082 0083 ui.qlineedit_scheme->setText(dialog->scheme); 0084 0085 delete dialog; 0086 0087 trigger_changed(); 0088 } 0089 0090 void ProfileDataSingleFileDialog::trigger_changed() 0091 { 0092 if (applyButton) { 0093 QString scheme = profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_SF_NAME_INDEX)).toString(); 0094 if (ui.qlineedit_scheme->text() != scheme) { 0095 applyButton->setEnabled(true); 0096 return; 0097 } 0098 applyButton->setEnabled(false); 0099 } 0100 } 0101 0102 bool ProfileDataSingleFileDialog::save() 0103 { 0104 QString scheme = ui.qlineedit_scheme->text(); 0105 0106 error.clear(); 0107 bool success = true; 0108 0109 if (success) 0110 success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_SF_NAME_INDEX), scheme); 0111 0112 if (!success) 0113 error = profile_model->lastError(); 0114 0115 if (success) { 0116 profile_model->commit(); 0117 if (applyButton) 0118 applyButton->setEnabled(false); 0119 return true; 0120 } 0121 0122 return false; 0123 }