File indexing completed on 2024-04-28 04:48:20
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 "filenameschemewizarddialog.h" 0009 0010 #include <QDialogButtonBox> 0011 #include <QVBoxLayout> 0012 0013 FilenameSchemeWizardDialog::FilenameSchemeWizardDialog(const QString &scheme, const QString &suffix, QWidget *parent) 0014 : QDialog(parent) 0015 { 0016 Q_UNUSED(parent); 0017 0018 setWindowTitle(i18n("Scheme Wizard")); 0019 0020 auto *mainLayout = new QVBoxLayout; 0021 setLayout(mainLayout); 0022 0023 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply); 0024 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0025 okButton->setDefault(true); 0026 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0027 applyButton = buttonBox->button(QDialogButtonBox::Apply); 0028 connect(buttonBox, &QDialogButtonBox::accepted, this, &FilenameSchemeWizardDialog::slotAccepted); 0029 connect(buttonBox, &QDialogButtonBox::rejected, this, &FilenameSchemeWizardDialog::reject); 0030 connect(applyButton, &QPushButton::clicked, this, &FilenameSchemeWizardDialog::slotApplied); 0031 0032 QWidget *widget = new QWidget(this); 0033 mainLayout->addWidget(widget); 0034 mainLayout->addWidget(buttonBox); 0035 ui.setupUi(widget); 0036 0037 help_dialog = new TextViewDialog(SchemeParser::helpHTMLDoc(3), i18n("Filename scheme help"), this); 0038 0039 ui.qlineedit_scheme->setText(scheme); 0040 connect(ui.qlineedit_scheme, SIGNAL(textEdited(const QString &)), this, SLOT(trigger_changed())); 0041 connect(ui.qlineedit_scheme, SIGNAL(textChanged(const QString &)), this, SLOT(update_example())); 0042 ui.qlineedit_scheme->setCursorPosition(0); 0043 0044 connect(ui.kurllabel_help, SIGNAL(leftClickedUrl()), this, SLOT(help())); 0045 0046 connect(ui.kpushbutton_albumartist, SIGNAL(clicked()), this, SLOT(insAlbumArtist())); 0047 connect(ui.kpushbutton_albumtitle, SIGNAL(clicked()), this, SLOT(insAlbumTitle())); 0048 connect(ui.kpushbutton_cdno, SIGNAL(clicked()), this, SLOT(insCDNo())); 0049 connect(ui.kpushbutton_date, SIGNAL(clicked()), this, SLOT(insDate())); 0050 connect(ui.kpushbutton_genre, SIGNAL(clicked()), this, SLOT(insGenre())); 0051 connect(ui.kpushbutton_suffix, SIGNAL(clicked()), this, SLOT(insSuffix())); 0052 connect(ui.kpushbutton_nooftracks, SIGNAL(clicked()), this, SLOT(insNoOfTracks())); 0053 0054 this->scheme = scheme; 0055 this->suffix = suffix; 0056 0057 applyButton->setEnabled(false); 0058 update_example(); 0059 } 0060 0061 FilenameSchemeWizardDialog::~FilenameSchemeWizardDialog() 0062 { 0063 if (help_dialog != nullptr) { 0064 help_dialog->close(); 0065 delete help_dialog; 0066 help_dialog = nullptr; 0067 } 0068 } 0069 0070 void FilenameSchemeWizardDialog::slotAccepted() 0071 { 0072 save(); 0073 accept(); 0074 } 0075 0076 void FilenameSchemeWizardDialog::slotApplied() 0077 { 0078 save(); 0079 } 0080 0081 void FilenameSchemeWizardDialog::trigger_changed() 0082 { 0083 if (ui.qlineedit_scheme->text() != scheme) { 0084 applyButton->setEnabled(true); 0085 return; 0086 } 0087 applyButton->setEnabled(false); 0088 } 0089 0090 void FilenameSchemeWizardDialog::help() 0091 { 0092 help_dialog->showNormal(); 0093 } 0094 0095 void FilenameSchemeWizardDialog::insAlbumArtist() 0096 { 0097 QString text = ui.qlineedit_scheme->text(); 0098 text.insert(ui.qlineedit_scheme->cursorPosition(), QString("$" VAR_ALBUM_ARTIST)); 0099 ui.qlineedit_scheme->setText(text); 0100 update_example(); 0101 } 0102 0103 void FilenameSchemeWizardDialog::insAlbumTitle() 0104 { 0105 QString text = ui.qlineedit_scheme->text(); 0106 text.insert(ui.qlineedit_scheme->cursorPosition(), QString("$" VAR_ALBUM_TITLE)); 0107 ui.qlineedit_scheme->setText(text); 0108 update_example(); 0109 } 0110 0111 void FilenameSchemeWizardDialog::insCDNo() 0112 { 0113 QString text = ui.qlineedit_scheme->text(); 0114 text.insert(ui.qlineedit_scheme->cursorPosition(), QString("$" VAR_CD_NO)); 0115 ui.qlineedit_scheme->setText(text); 0116 update_example(); 0117 } 0118 0119 void FilenameSchemeWizardDialog::insDate() 0120 { 0121 QString text = ui.qlineedit_scheme->text(); 0122 text.insert(ui.qlineedit_scheme->cursorPosition(), QString("$" VAR_DATE)); 0123 ui.qlineedit_scheme->setText(text); 0124 update_example(); 0125 } 0126 0127 void FilenameSchemeWizardDialog::insGenre() 0128 { 0129 QString text = ui.qlineedit_scheme->text(); 0130 text.insert(ui.qlineedit_scheme->cursorPosition(), QString("$" VAR_GENRE)); 0131 ui.qlineedit_scheme->setText(text); 0132 update_example(); 0133 } 0134 0135 void FilenameSchemeWizardDialog::insSuffix() 0136 { 0137 QString text = ui.qlineedit_scheme->text(); 0138 text.insert(ui.qlineedit_scheme->cursorPosition(), QString("$" VAR_SUFFIX)); 0139 ui.qlineedit_scheme->setText(text); 0140 update_example(); 0141 } 0142 0143 void FilenameSchemeWizardDialog::insNoOfTracks() 0144 { 0145 QString text = ui.qlineedit_scheme->text(); 0146 text.insert(ui.qlineedit_scheme->cursorPosition(), QString("$" VAR_NO_OF_TRACKS)); 0147 ui.qlineedit_scheme->setText(text); 0148 update_example(); 0149 } 0150 0151 bool FilenameSchemeWizardDialog::save() 0152 { 0153 scheme = ui.qlineedit_scheme->text(); 0154 applyButton->setEnabled(false); 0155 return true; 0156 } 0157 0158 void FilenameSchemeWizardDialog::update_example() 0159 { 0160 SchemeParser schemeparser; 0161 QString filename = schemeparser.parseFilenameScheme(ui.qlineedit_scheme->text(), 1, 12, "Meat Loaf", "Bat Out Of Hell III", "2006", "Rock", suffix, false); 0162 ui.qlineedit_example->setText(filename); 0163 ui.qlineedit_example->setCursorPosition(0); 0164 }