Revert previous commit, was incorrect
[amarok.git] / src / podcastsettings.cpp
blobd42bb26d8e32c15b48cca5c63141e0b67f12b097
1 // (c) 2005-2006 Seb Ruiz <ruiz@kde.org>
2 // (c) 2006 Bart Cerneels <shanachie@yucom.be>
3 // See COPYING file for licensing information.
5 #include "podcastsettings.h"
7 #include "mediabrowser.h"
8 #include "podcastsettingsbase.h"
10 #include <KLineEdit>
11 #include <KLocale>
12 #include <KMessageBox> //global changes confirmation
13 #include <KNumInput>
14 #include <KUrl>
15 #include <KUrlRequester>
16 #include <KWindowSystem>
18 #include <QCheckBox>
19 #include <QLabel>
20 #include <QPushButton>
21 #include <QRadioButton>
22 #include <QTextEdit>
24 PodcastSettings::PodcastSettings( const QDomNode &channelSettings, const QString &title )
25 : m_title( title )
27 m_saveLocation = channelSettings.namedItem( "savelocation").toElement().text();
28 m_autoScan = channelSettings.namedItem( "autoscan").toElement().text() == "true";
29 m_fetch = channelSettings.namedItem("fetch").toElement().text() == "automatic"?AUTOMATIC:STREAM;
30 m_addToMediaDevice = channelSettings.namedItem( "autotransfer").toElement().text() == "true";
31 m_purge = channelSettings.namedItem( "purge").toElement().text() == "true";
32 m_purgeCount = channelSettings.namedItem( "purgecount").toElement().text().toInt();
35 // default settings
36 PodcastSettings::PodcastSettings( const QString &title )
37 : m_title( title )
39 m_saveLocation = Amarok::saveLocation( "podcasts/" );
40 m_saveLocation += Amarok::vfatPath( m_title );
41 m_autoScan = true;
42 m_fetch = STREAM;
43 m_addToMediaDevice = false;
44 m_purge = false;
45 m_purgeCount = 0;
48 PodcastSettings::PodcastSettings( const QString &title, const QString &save, const bool autoScan,
49 const int fetchType, const bool autotransfer, const bool purge, const int purgecount )
51 m_title = title;
52 if( save.isEmpty() )
54 m_saveLocation = Amarok::saveLocation( "podcasts/" );
55 m_saveLocation += Amarok::vfatPath( m_title );
57 else
58 m_saveLocation = save;
60 m_autoScan = autoScan;
61 m_fetch = fetchType;
62 m_addToMediaDevice = autotransfer;
63 m_purge = purge;
64 m_purgeCount = purgecount;
67 PodcastSettingsDialog::PodcastSettingsDialog( PodcastSettings *settings, QWidget* parent )
68 : KDialog( parent )
69 , m_settings( settings )
71 setCaption( i18nc("change options", "Configure %1", settings->m_title ) );
72 setModal( true );
73 setButtons( Ok | Cancel | User1 );
74 setButtonGuiItem( User1, KGuiItem( i18n("Reset") ) );
75 setDefaultButton( Ok );
76 showButtonSeparator( true );
77 init();
78 setSettings( settings );
81 PodcastSettingsDialog::PodcastSettingsDialog( const Q3PtrList<PodcastSettings> &list, const QString &caption, QWidget* parent )
82 : KDialog( parent )
83 , m_settingsList( list )
85 setCaption( i18nc("change options", "Configure %1", caption ) );
86 setModal( true );
87 setButtons( Ok | Cancel | User1 );
88 setButtonGuiItem( User1, KGuiItem( i18n("Reset") ) );
89 setDefaultButton( Ok );
90 showButtonSeparator( true );
92 init();
93 m_settings = m_settingsList.first();
94 if( !m_settings->m_saveLocation.endsWith( '/' ) )
95 m_settings->m_saveLocation = m_settings->m_saveLocation.section( "/", 0, -2 );
96 setSettings( m_settings );
99 void
100 PodcastSettingsDialog::init()
102 m_ps = new PodcastSettingsDialogBase(this);
104 #ifdef Q_WS_X11
105 KWindowSystem::setState( winId(), NET::SkipTaskbar );
106 #endif
108 setMainWidget(m_ps);
109 m_ps->m_saveLocation->setMode( KFile::Directory | KFile::ExistingOnly );
111 m_ps->m_addToMediaDeviceCheck->setEnabled( MediaBrowser::isAvailable() );
113 enableButtonOk( false );
115 // Connects for modification check
116 connect( m_ps->m_purgeCountSpinBox->findChild<QTextEdit *>( "qt_spinbox_edit" ), SIGNAL(textChanged( const QString& )), SLOT(checkModified()) );
117 connect( m_ps->m_saveLocation, SIGNAL(textChanged( const QString& )), SLOT(checkModified()) );
118 connect( m_ps->m_autoFetchCheck, SIGNAL(clicked()), SLOT(checkModified()) );
119 connect( m_ps->m_streamRadio, SIGNAL(clicked()), SLOT(checkModified()) );
120 connect( m_ps->m_addToMediaDeviceCheck, SIGNAL(clicked()), SLOT(checkModified()) );
121 connect( m_ps->m_downloadRadio, SIGNAL(clicked()), SLOT(checkModified()) );
122 connect( m_ps->m_purgeCheck, SIGNAL(clicked()), SLOT(checkModified()) );
123 connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
124 connect(this,SIGNAL(user1Clicked()), this,SLOT(slotUser1()));
127 bool
128 PodcastSettingsDialog::hasChanged()
130 bool fetchTypeChanged = true;
132 if( m_ps->m_streamRadio->isChecked() && m_settings->m_fetch == STREAM ||
133 m_ps->m_downloadRadio->isChecked() && m_settings->m_fetch == AUTOMATIC )
135 fetchTypeChanged = false;
137 return( m_settings->m_saveLocation != requesterSaveLocation() ||
138 m_settings->m_autoScan != m_ps->m_autoFetchCheck->isChecked() ||
139 m_settings->m_addToMediaDevice != m_ps->m_addToMediaDeviceCheck->isChecked() ||
140 m_settings->m_purge != m_ps->m_purgeCheck->isChecked() ||
141 m_settings->m_purgeCount != m_ps->m_purgeCountSpinBox->value() ||
142 fetchTypeChanged );
145 void
146 PodcastSettingsDialog::checkModified() //slot
148 enableButtonOk( hasChanged() );
151 void PodcastSettingsDialog::slotOk() //slot
153 enableButtonOk( false ); //visual feedback
155 if ( !m_settingsList.isEmpty() )
157 oldForeachType( Q3PtrList<PodcastSettings>, m_settingsList)
159 (*it)->m_saveLocation = requesterSaveLocation().append( Amarok::vfatPath( (*it)->title() ) );
160 (*it)->m_autoScan = m_ps->m_autoFetchCheck->isChecked();
161 (*it)->m_addToMediaDevice = m_ps->m_addToMediaDeviceCheck->isChecked();
162 (*it)->m_purge = m_ps->m_purgeCheck->isChecked();
163 (*it)->m_purgeCount = m_ps->m_purgeCountSpinBox->value();
164 if( m_ps->m_streamRadio->isChecked() )
165 (*it)->m_fetch = STREAM;
166 else
167 (*it)->m_fetch = AUTOMATIC;
170 else
172 m_settings->m_saveLocation = requesterSaveLocation();
173 m_settings->m_autoScan = m_ps->m_autoFetchCheck->isChecked();
174 m_settings->m_addToMediaDevice = m_ps->m_addToMediaDeviceCheck->isChecked();
175 m_settings->m_purge = m_ps->m_purgeCheck->isChecked();
176 m_settings->m_purgeCount = m_ps->m_purgeCountSpinBox->value();
178 if( m_ps->m_streamRadio->isChecked() )
179 m_settings->m_fetch = STREAM;
180 else
181 m_settings->m_fetch = AUTOMATIC;
185 // KUrlRequester doesn't provide us with convenient functions for adding trailing slashes
186 QString PodcastSettingsDialog::requesterSaveLocation()
188 return m_ps->m_saveLocation->url().path( KUrl::AddTrailingSlash );
191 void PodcastSettingsDialog::setSettings( PodcastSettings *settings )
193 QString saveLocation = settings->m_saveLocation;
195 m_ps->m_saveLocation->setUrl( saveLocation );
196 m_ps->m_autoFetchCheck->setChecked( settings->m_autoScan );
198 if( settings->m_fetch == STREAM )
200 m_ps->m_streamRadio->setChecked( true );
201 m_ps->m_downloadRadio->setChecked( false );
203 else if( settings->m_fetch == AUTOMATIC )
205 m_ps->m_streamRadio->setChecked( false );
206 m_ps->m_downloadRadio->setChecked( true );
209 m_ps->m_addToMediaDeviceCheck->setChecked( settings->m_addToMediaDevice );
210 m_ps->m_purgeCheck->setChecked( settings->m_purge );
211 m_ps->m_purgeCountSpinBox->setValue( settings->m_purgeCount );
213 if( !settings->m_purge )
215 m_ps->m_purgeCountSpinBox->setEnabled( false );
216 m_ps->m_purgeCountLabel->setEnabled( false );
220 //reset to default settings button
221 void PodcastSettingsDialog::slotUser1() //slot
223 PodcastSettings settings( m_settings->m_title );
224 setSettings( &settings );
225 checkModified();
228 bool PodcastSettingsDialog::configure()
230 return exec() == QDialog::Accepted;
233 #include "podcastsettings.moc"