File indexing completed on 2024-04-21 04:48:17
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 "profilewidget.h" 0009 0010 #include <QDebug> 0011 #include <QFileDialog> 0012 #include <QIcon> 0013 0014 profileWidget::profileWidget(ProfileModel* profileModel, QWidget* parent) 0015 : profileWidgetUI(parent) 0016 { 0017 profile_model = profileModel; 0018 if (!profile_model) { 0019 qDebug() << "ProfileModel is NULL!"; 0020 return; 0021 } 0022 0023 listView->setModel(profile_model); 0024 listView->setModelColumn(1); 0025 listView->setIconSize(QSize(22, 22)); 0026 connect(listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(_update())); 0027 connect(listView, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(mod_profile(const QModelIndex&))); 0028 connect(kpushbutton_add, SIGNAL(clicked()), this, SLOT(add_profile())); 0029 connect(kpushbutton_rem, SIGNAL(clicked()), this, SLOT(rem_profile())); 0030 connect(kpushbutton_mod, SIGNAL(clicked()), this, SLOT(mod_profile())); 0031 connect(kpushbutton_copy, SIGNAL(clicked()), this, SLOT(copy_profile())); 0032 connect(kpushbutton_load, SIGNAL(clicked()), this, SLOT(load_profiles())); 0033 connect(kpushbutton_save, SIGNAL(clicked()), this, SLOT(save_profiles())); 0034 connect(kpushbutton_init, SIGNAL(clicked()), this, SLOT(init_profiles())); 0035 0036 kpushbutton_add->setIcon(QIcon::fromTheme("list-add")); 0037 kpushbutton_rem->setIcon(QIcon::fromTheme("list-remove")); 0038 0039 kpushbutton_load->setIcon(QIcon::fromTheme("document-open")); 0040 kpushbutton_save->setIcon(QIcon::fromTheme("document-save")); 0041 0042 kpushbutton_init->setIcon(QIcon::fromTheme("view-refresh")); 0043 0044 _update(); 0045 } 0046 0047 profileWidget::~profileWidget() 0048 { 0049 } 0050 0051 void profileWidget::_update() 0052 { 0053 kpushbutton_rem->setEnabled(listView->selectionModel()->selectedIndexes().count() > 0); 0054 kpushbutton_mod->setEnabled(listView->selectionModel()->selectedIndexes().count() > 0); 0055 kpushbutton_copy->setEnabled(listView->selectionModel()->selectedIndexes().count() > 0); 0056 kpushbutton_save->setEnabled(profile_model->rowCount() > 0); 0057 } 0058 0059 void profileWidget::add_profile() 0060 { 0061 auto* dialog = new ProfileDataDialog(profile_model, -1, this); 0062 0063 if (dialog->exec() != QDialog::Accepted) { 0064 delete dialog; 0065 return; 0066 } 0067 delete dialog; 0068 0069 profile_model->sortItems(); 0070 0071 _update(); 0072 } 0073 0074 void profileWidget::rem_profile() 0075 { 0076 if (KMessageBox::warningTwoActions( 0077 this, 0078 i18n("Do you really want to delete profile \"%1\"?", profile_model->data(profile_model->index(listView->currentIndex().row(), PROFILE_MODEL_COLUMN_NAME_INDEX)).toString()), 0079 i18n("Delete profile"), 0080 KStandardGuiItem::ok(), 0081 KStandardGuiItem::cancel()) 0082 == KMessageBox::SecondaryAction) 0083 return; 0084 0085 QModelIndex ci = listView->currentIndex(); 0086 profile_model->removeRows(ci.row(), 1); 0087 0088 profile_model->commit(); 0089 0090 if (ci.isValid()) 0091 listView->setCurrentIndex(ci); 0092 0093 _update(); 0094 } 0095 0096 void profileWidget::mod_profile(const QModelIndex& index) 0097 { 0098 auto* dialog = new ProfileDataDialog(profile_model, index.row(), this); 0099 0100 dialog->exec(); 0101 0102 delete dialog; 0103 0104 _update(); 0105 } 0106 0107 void profileWidget::mod_profile() 0108 { 0109 mod_profile(listView->currentIndex()); 0110 } 0111 0112 void profileWidget::copy_profile() 0113 { 0114 profile_model->copy(listView->currentIndex().row()); 0115 profile_model->commit(); 0116 profile_model->sortItems(); 0117 _update(); 0118 } 0119 0120 void profileWidget::save_profiles() 0121 { 0122 QString filename = QFileDialog::getSaveFileName(this, i18n("Save Cover"), QDir::homePath(), "*.apf"); 0123 if (!filename.isEmpty()) { 0124 profile_model->saveProfilesToFile(filename); 0125 } 0126 } 0127 0128 void profileWidget::load_profiles() 0129 { 0130 QString filename = QFileDialog::getOpenFileName(this, i18n("Load Profiles"), QDir::homePath(), "*.apf"); 0131 if (!filename.isEmpty()) { 0132 profile_model->loadProfilesFromFile(filename); 0133 } 0134 } 0135 0136 void profileWidget::init_profiles() 0137 { 0138 if (KMessageBox::PrimaryAction == KMessageBox::questionTwoActions(this, i18n("<p>Do you wish to rescan your system for codecs (Lame, Opus, FLAC, etc.)?</p>" 0139 "<p><font style=\"font-style:italic;\">This will attempt to create some sample profiles based upon any found codecs.</font></p>"), 0140 i18n("Codec Scan"), KStandardGuiItem::ok(), KStandardGuiItem::cancel())) { 0141 int sizeBefore = profile_model->rowCount(); 0142 profile_model->autoCreate(); 0143 int diff = profile_model->rowCount() - sizeBefore; 0144 KMessageBox::information(this, 0 == diff ? i18n("No new codecs found") : i18np("1 new profile added", "%1 new profiles added", diff), i18n("Codec Scan")); 0145 } 0146 }