File indexing completed on 2024-03-24 04:50:55
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 "profiledataplaylistdialog.h" 0009 0010 #include <QDialogButtonBox> 0011 #include <QVBoxLayout> 0012 0013 ProfileDataPlaylistDialog::ProfileDataPlaylistDialog(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 // profile data playlist data 0025 QString format = profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_FORMAT_INDEX)).toString(); 0026 QString scheme = profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_NAME_INDEX)).toString(); 0027 bool abs_file_path = profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_ABS_FILE_PATH_INDEX)).toBool(); 0028 bool utf8 = profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_UTF8_INDEX)).toBool(); 0029 0030 setWindowTitle(i18n("Playlist Settings")); 0031 0032 auto *mainLayout = new QVBoxLayout; 0033 setLayout(mainLayout); 0034 0035 QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok | QDialogButtonBox::Cancel; 0036 if (!new_profile_mode) 0037 buttons |= QDialogButtonBox::Apply; 0038 0039 QDialogButtonBox *buttonBox = new QDialogButtonBox(buttons); 0040 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0041 okButton->setDefault(true); 0042 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0043 if (!new_profile_mode) 0044 applyButton = buttonBox->button(QDialogButtonBox::Apply); 0045 connect(buttonBox, &QDialogButtonBox::accepted, this, &ProfileDataPlaylistDialog::slotAccepted); 0046 connect(buttonBox, &QDialogButtonBox::rejected, this, &ProfileDataPlaylistDialog::reject); 0047 if (!new_profile_mode) 0048 connect(applyButton, &QPushButton::clicked, this, &ProfileDataPlaylistDialog::slotApplied); 0049 0050 QWidget *widget = new QWidget(this); 0051 mainLayout->addWidget(widget); 0052 mainLayout->addWidget(buttonBox); 0053 ui.setupUi(widget); 0054 0055 connect(ui.kpushbutton_scheme, SIGNAL(clicked()), this, SLOT(scheme_wizard())); 0056 ui.kpushbutton_scheme->setIcon(QIcon::fromTheme("tools-wizard")); 0057 0058 ui.kcombobox_format->addItem("M3U (Textbased Winamp Playlist)", "M3U"); 0059 ui.kcombobox_format->addItem("PLS (Textbased Playlist)", "PLS"); 0060 ui.kcombobox_format->addItem("XSPF (XML Shareable Playlist Format)", "XSPF"); 0061 { 0062 int i = ui.kcombobox_format->findData(format); 0063 ui.kcombobox_format->setCurrentIndex(i); 0064 } 0065 enable_abs_file_path(!(format == "XSPF")); 0066 enable_utf8(!(format == "XSPF")); 0067 connect(ui.kcombobox_format, SIGNAL(currentIndexChanged(int)), this, SLOT(trigger_changed())); 0068 0069 ui.qlineedit_scheme->setText(scheme); 0070 connect(ui.qlineedit_scheme, SIGNAL(textEdited(const QString &)), this, SLOT(trigger_changed())); 0071 0072 ui.checkBox_abs_file_path->setChecked(abs_file_path); 0073 connect(ui.checkBox_abs_file_path, SIGNAL(toggled(bool)), this, SLOT(trigger_changed())); 0074 0075 ui.checkBox_utf8->setChecked(utf8); 0076 connect(ui.checkBox_utf8, SIGNAL(toggled(bool)), this, SLOT(trigger_changed())); 0077 0078 if (applyButton) 0079 applyButton->setEnabled(false); 0080 } 0081 0082 ProfileDataPlaylistDialog::~ProfileDataPlaylistDialog() 0083 { 0084 } 0085 0086 void ProfileDataPlaylistDialog::slotAccepted() 0087 { 0088 if (save()) 0089 accept(); 0090 else 0091 ErrorDialog::show(this, error.message(), error.details()); 0092 } 0093 0094 void ProfileDataPlaylistDialog::slotApplied() 0095 { 0096 if (!save()) 0097 ErrorDialog::show(this, error.message(), error.details()); 0098 } 0099 0100 void ProfileDataPlaylistDialog::scheme_wizard() 0101 { 0102 QString suffix = ui.kcombobox_format->itemData(ui.kcombobox_format->currentIndex()).toString().toLower(); 0103 0104 FilenameSchemeWizardDialog *dialog = new FilenameSchemeWizardDialog(ui.qlineedit_scheme->text(), suffix, this); 0105 0106 if (dialog->exec() != QDialog::Accepted) { 0107 delete dialog; 0108 return; 0109 } 0110 0111 ui.qlineedit_scheme->setText(dialog->scheme); 0112 0113 delete dialog; 0114 0115 trigger_changed(); 0116 } 0117 0118 void ProfileDataPlaylistDialog::trigger_changed() 0119 { 0120 enable_abs_file_path(ui.kcombobox_format->itemData(ui.kcombobox_format->currentIndex()).toString() != "XSPF"); 0121 enable_utf8(ui.kcombobox_format->itemData(ui.kcombobox_format->currentIndex()).toString() != "XSPF"); 0122 0123 if (applyButton) { 0124 QString format = profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_FORMAT_INDEX)).toString(); 0125 QString scheme = profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_NAME_INDEX)).toString(); 0126 bool abs_file_path = profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_ABS_FILE_PATH_INDEX)).toBool(); 0127 bool utf8 = profile_model->data(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_UTF8_INDEX)).toBool(); 0128 0129 if (ui.checkBox_abs_file_path->isChecked() != abs_file_path) { 0130 applyButton->setEnabled(true); 0131 return; 0132 } 0133 if (ui.checkBox_utf8->isChecked() != utf8) { 0134 applyButton->setEnabled(true); 0135 return; 0136 } 0137 if (ui.kcombobox_format->itemData(ui.kcombobox_format->currentIndex()).toString() != format) { 0138 applyButton->setEnabled(true); 0139 return; 0140 } 0141 if (ui.qlineedit_scheme->text() != scheme) { 0142 applyButton->setEnabled(true); 0143 return; 0144 } 0145 applyButton->setEnabled(false); 0146 } 0147 } 0148 0149 void ProfileDataPlaylistDialog::enable_abs_file_path(bool enabled) 0150 { 0151 ui.checkBox_abs_file_path->setEnabled(enabled); 0152 } 0153 0154 void ProfileDataPlaylistDialog::enable_utf8(bool enabled) 0155 { 0156 ui.checkBox_utf8->setEnabled(enabled); 0157 } 0158 0159 bool ProfileDataPlaylistDialog::save() 0160 { 0161 QString format = ui.kcombobox_format->itemData(ui.kcombobox_format->currentIndex()).toString(); 0162 QString scheme = ui.qlineedit_scheme->text(); 0163 bool abs_file_path = ui.checkBox_abs_file_path->isChecked(); 0164 bool utf8 = ui.checkBox_utf8->isChecked(); 0165 0166 error.clear(); 0167 bool success = true; 0168 0169 if (success) 0170 success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_FORMAT_INDEX), format); 0171 if (success) 0172 success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_NAME_INDEX), scheme); 0173 if (success) 0174 success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_ABS_FILE_PATH_INDEX), abs_file_path); 0175 if (success) 0176 success = profile_model->setData(profile_model->index(profile_row, PROFILE_MODEL_COLUMN_PL_UTF8_INDEX), utf8); 0177 0178 if (!success) 0179 error = profile_model->lastError(); 0180 0181 if (success) { 0182 profile_model->commit(); 0183 if (applyButton) 0184 applyButton->setEnabled(false); 0185 return true; 0186 } 0187 0188 return false; 0189 }