File indexing completed on 2024-05-19 04:50:18
0001 /**************************************************************************************** 0002 * Copyright (c) 2006,2007 Nikolaj Hald Nielsen <nhn@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 "MagnatuneDownloadDialog.h" 0018 0019 #include "core/support/Amarok.h" 0020 #include "core/support/Debug.h" 0021 0022 #include <KConfigGroup> 0023 #include <KIOWidgets/KUrlRequester> 0024 0025 0026 MagnatuneDownloadDialog::MagnatuneDownloadDialog( QWidget *parent, Qt::WindowFlags fl ) 0027 : QDialog( parent, fl ) 0028 { 0029 setupUi(this); 0030 downloadTargetURLRequester->setMode( KFile::Directory ); 0031 0032 } 0033 0034 MagnatuneDownloadDialog::~MagnatuneDownloadDialog() 0035 { 0036 } 0037 0038 0039 void MagnatuneDownloadDialog::downloadButtonClicked( ) 0040 { 0041 0042 if ( m_currentDownloadInfo.password().isEmpty() ) return; 0043 0044 QString format = formatComboBox->currentText(); 0045 QString path = downloadTargetURLRequester->url().url(); 0046 0047 //store to config for next download: 0048 KConfigGroup config = Amarok::config( "Service_Magnatune" ); 0049 config.writeEntry( "Download Format", format ); 0050 config.writeEntry( "Download Path", path ); 0051 0052 m_currentDownloadInfo.setFormatSelection( format ); 0053 0054 QUrl unpackLocation = downloadTargetURLRequester->url(); 0055 m_currentDownloadInfo.setUnpackUrl( unpackLocation.path() ); 0056 0057 Q_EMIT( downloadAlbum( m_currentDownloadInfo ) ); 0058 0059 close(); 0060 0061 } 0062 0063 void MagnatuneDownloadDialog::setDownloadInfo( const MagnatuneDownloadInfo &info ) 0064 { 0065 0066 m_currentDownloadInfo = info; 0067 0068 DownloadFormatMap formatMap = info.formatMap(); 0069 0070 for (DownloadFormatMap::Iterator it = formatMap.begin(), total = formatMap.end(); it != total; ++it ) 0071 { 0072 formatComboBox->addItem( it.key() ); 0073 } 0074 0075 infoEdit->setText( info.downloadMessage() ); 0076 0077 //restore format and path from last time, if any. 0078 KConfigGroup config = Amarok::config("Service_Magnatune"); 0079 QString format = config.readEntry( "Download Format", QString() ); 0080 QString path = config.readEntry( "Download Path", QString() ); 0081 0082 if ( !format.isEmpty() ) { 0083 int index = formatComboBox->findText( format ); 0084 if ( index != -1 ) 0085 formatComboBox->setCurrentIndex( index ); 0086 } 0087 0088 if ( !path.isEmpty() ) { 0089 downloadTargetURLRequester->setUrl( QUrl::fromLocalFile(path) ); 0090 } 0091 0092 } 0093 0094 /*$SPECIALIZATION$*/ 0095 0096 0097