File indexing completed on 2025-01-05 04:26:13
0001 /**************************************************************************************** 0002 * Copyright (c) 2006-2008 Bart Cerneels <bart.cerneels@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "PodcastSettingsDialog.h" 0018 #include "ui_PodcastSettingsBase.h" 0019 #include "PodcastFilenameLayoutConfigDialog.h" 0020 0021 #include "core/support/Debug.h" 0022 0023 #include <QApplication> 0024 #include <QClipboard> 0025 #include <QFontMetrics> 0026 #include <KConfigGroup> 0027 #include <QDialogButtonBox> 0028 #include <QPushButton> 0029 #include <QVBoxLayout> 0030 0031 PodcastSettingsDialog::PodcastSettingsDialog( const Podcasts::SqlPodcastChannelPtr &channel, QWidget* parent ) 0032 : KPageDialog( parent ) 0033 , m_ps( new Ui::PodcastSettingsBase() ) 0034 , m_channel( channel ) 0035 { 0036 QWidget* main = new QWidget( this ); 0037 m_ps->setupUi( main ); 0038 0039 setWindowTitle( i18nc("change options", "Configure %1", m_channel->title() ) ); 0040 setModal( true ); 0041 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Apply); 0042 QVBoxLayout *mainLayout = new QVBoxLayout(this); 0043 mainLayout->addWidget(main); 0044 0045 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0046 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0047 connect(buttonBox, &QDialogButtonBox::accepted, this, &PodcastSettingsDialog::accept); 0048 connect(buttonBox, &QDialogButtonBox::rejected, this, &PodcastSettingsDialog::reject); 0049 0050 okButton->setDefault(true); 0051 mainLayout->addWidget(buttonBox); 0052 0053 init(); 0054 } 0055 0056 void 0057 PodcastSettingsDialog::init() 0058 { 0059 QString url = m_channel->url().url(); 0060 m_ps->m_urlLineEdit->setText( url ); 0061 0062 m_ps->m_saveLocation->setMode( KFile::Directory | KFile::ExistingOnly ); 0063 m_ps->m_saveLocation->setUrl( m_channel->saveLocation() ); 0064 0065 m_ps->m_autoFetchCheck->setChecked( m_channel->autoScan() ); 0066 0067 if( m_channel->fetchType() == Podcasts::PodcastChannel::StreamOrDownloadOnDemand ) 0068 { 0069 m_ps->m_streamRadio->setChecked( true ); 0070 m_ps->m_downloadRadio->setChecked( false ); 0071 } 0072 else if( m_channel->fetchType() == Podcasts::PodcastChannel::DownloadWhenAvailable ) 0073 { 0074 m_ps->m_streamRadio->setChecked( false ); 0075 m_ps->m_downloadRadio->setChecked( true ); 0076 } 0077 0078 m_ps->m_purgeCheck->setChecked( m_channel->hasPurge() ); 0079 m_ps->m_purgeCountSpinBox->setValue( m_channel->purgeCount() ); 0080 m_ps->m_purgeCountSpinBox->setSuffix( i18np( " Item", " Items", m_ps->m_purgeCountSpinBox->value() ) ); 0081 0082 if( !m_channel->hasPurge() ) 0083 { 0084 m_ps->m_purgeCountSpinBox->setEnabled( false ); 0085 m_ps->m_purgeCountLabel->setEnabled( false ); 0086 } 0087 0088 m_ps->m_writeTagsCheck->setChecked( m_channel->writeTags() ); 0089 0090 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled( false ); 0091 0092 // Connects for modification check 0093 connect( m_ps->m_urlLineEdit, &QLineEdit::textChanged, 0094 this, &PodcastSettingsDialog::checkModified ); 0095 connect( m_ps->m_saveLocation, &KUrlRequester::textChanged, 0096 this, &PodcastSettingsDialog::checkModified ); 0097 connect( m_ps->m_autoFetchCheck, &QAbstractButton::clicked, this, &PodcastSettingsDialog::checkModified ); 0098 connect( m_ps->m_streamRadio, &QAbstractButton::clicked, this, &PodcastSettingsDialog::checkModified ); 0099 connect( m_ps->m_downloadRadio, &QAbstractButton::clicked, this, &PodcastSettingsDialog::checkModified ); 0100 connect( m_ps->m_purgeCheck, &QAbstractButton::clicked, this, &PodcastSettingsDialog::checkModified ); 0101 connect( m_ps->m_purgeCountSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), 0102 this, &PodcastSettingsDialog::checkModified ); 0103 connect( m_ps->m_writeTagsCheck, &QAbstractButton::clicked, this, &PodcastSettingsDialog::checkModified ); 0104 connect( m_ps->m_filenameLayoutConfigWidgetButton, &QAbstractButton::clicked, 0105 this, &PodcastSettingsDialog::launchFilenameLayoutConfigDialog ); 0106 0107 connect(buttonBox()->button(QDialogButtonBox::Apply), &QAbstractButton::clicked, this, &PodcastSettingsDialog::slotApply ); 0108 connect(buttonBox()->button(QDialogButtonBox::Ok), &QAbstractButton::clicked, this, &PodcastSettingsDialog::slotApply ); 0109 } 0110 0111 void 0112 PodcastSettingsDialog::slotFeedUrlClicked( const QString &url ) //SLOT 0113 { 0114 //adding url to clipboard for users convenience 0115 QApplication::clipboard()->setText( url ); 0116 } 0117 0118 bool 0119 PodcastSettingsDialog::hasChanged() 0120 { 0121 bool fetchTypeChanged = true; 0122 0123 if( ( m_ps->m_streamRadio->isChecked() && m_channel->fetchType() == Podcasts::PodcastChannel::StreamOrDownloadOnDemand ) || 0124 ( m_ps->m_downloadRadio->isChecked() && m_channel->fetchType() == Podcasts::PodcastChannel::DownloadWhenAvailable ) ) 0125 { 0126 fetchTypeChanged = false; 0127 } 0128 0129 return( m_channel->url() != QUrl::fromUserInput(m_ps->m_urlLineEdit->text()) || 0130 m_channel->saveLocation() != m_ps->m_saveLocation->url() || 0131 m_channel->autoScan() != m_ps->m_autoFetchCheck->isChecked() || 0132 m_channel->hasPurge() != m_ps->m_purgeCheck->isChecked() || 0133 m_channel->purgeCount() != m_ps->m_purgeCountSpinBox->value() || 0134 fetchTypeChanged || 0135 m_channel->writeTags() != m_ps->m_writeTagsCheck->isChecked() 0136 ); 0137 } 0138 0139 void 0140 PodcastSettingsDialog::checkModified() //slot 0141 { 0142 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled( hasChanged() ); 0143 } 0144 0145 void 0146 PodcastSettingsDialog::slotApply() //slot 0147 { 0148 m_channel->setUrl( QUrl( m_ps->m_urlLineEdit->text() ) ); 0149 m_channel->setAutoScan( m_ps->m_autoFetchCheck->isChecked() ); 0150 m_channel->setFetchType( 0151 m_ps->m_downloadRadio->isChecked() ? 0152 Podcasts::PodcastChannel::DownloadWhenAvailable : 0153 Podcasts::PodcastChannel::StreamOrDownloadOnDemand 0154 ); 0155 m_channel->setSaveLocation( m_ps->m_saveLocation->url() ); 0156 0157 m_channel->setPurge( m_ps->m_purgeCheck->isChecked() ); 0158 m_channel->setPurgeCount( m_ps->m_purgeCountSpinBox->value() ); 0159 m_channel->setWriteTags( m_ps->m_writeTagsCheck->isChecked() ); 0160 0161 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled( false ); 0162 } 0163 0164 bool PodcastSettingsDialog::configure() 0165 { 0166 return exec() == QDialog::Accepted; 0167 } 0168 0169 void PodcastSettingsDialog::launchFilenameLayoutConfigDialog() 0170 { 0171 PodcastFilenameLayoutConfigDialog pflcDialog( m_channel, this ); 0172 pflcDialog.configure(); 0173 } 0174 0175 0176