EBN warnings-- QClass -> KClass fixes
[amarok.git] / src / servicebrowser / magnatunestore / magnatuneredownloadhandler.cpp
blobf6befccb361d60f3a90f24251050498766ae4e72
1 /***************************************************************************
2 * Copyright (c) 2006, 2007 *
3 * Nikolaj Hald Nielsen <nhnFreespirit@gmail.com> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "magnatuneredownloadhandler.h"
22 #include "magnatuneredownloadhandler.moc"
24 #include "amarok.h"
25 #include "debug.h"
27 #include <KLocale>
28 #include "KMessageBox"
30 #include "QDir"
37 MagnatuneRedownloadHandler::MagnatuneRedownloadHandler(QWidget * parent)
39 m_parent = parent;
40 m_redownloadDialog = 0;
41 m_downloadDialog = 0;
42 m_albumDownloader = 0;
46 MagnatuneRedownloadHandler::~MagnatuneRedownloadHandler()
50 void MagnatuneRedownloadHandler::showRedownloadDialog( )
53 debug() << "Show redownload dialog" << endl;
55 QStringList previousDownloads = GetPurchaseList();
57 if (previousDownloads.isEmpty()) {
59 //No previously purchased track information found. No more to do here...
60 KMessageBox::information( m_parent, i18n( "No purchases found!" ) ,
61 i18n( "No previous purchases have been found. Nothing to redownload..." ) + '\n' );
62 return;
65 if (m_redownloadDialog == 0) {
66 m_redownloadDialog = new MagnatuneRedownloadDialog( m_parent );
67 connect( m_redownloadDialog, SIGNAL( redownload( const QString &) ), this, SLOT( redownload( const QString &) ) );
68 connect( m_redownloadDialog, SIGNAL(cancelled() ), this, SLOT( selectionDialogCancelled() ));
72 m_redownloadDialog->setRedownloadItems( previousDownloads );
74 m_redownloadDialog->show();
78 QStringList MagnatuneRedownloadHandler::GetPurchaseList( )
81 debug() << "MagnatuneRedownloadHandler::GetPurchaseList( )" << endl;
83 QStringList returnList;
84 QDir purchaseInfoDir( Amarok::saveLocation( "magnatune.com/purchases/" ) );
86 if ( !purchaseInfoDir.exists () ) {
87 return returnList;
90 purchaseInfoDir.setFilter( QDir::Files);
91 purchaseInfoDir.setSorting( QDir::Name );
93 const QFileInfoList list = purchaseInfoDir.entryInfoList();
94 QFileInfoList::const_iterator it( list.begin() );
95 QFileInfo fi;
97 while ( it != list.end() ) {
98 fi = *it;
99 returnList.append( fi.fileName() );
100 ++it;
102 debug() << "Done parsing previous purchases!" << endl;
103 return returnList;
107 void MagnatuneRedownloadHandler::redownload( const QString &storedInfoFileName )
110 QDir purchaseInfoDir( Amarok::saveLocation( "magnatune.com/purchases/" ) );
111 QString absFileName = purchaseInfoDir.absolutePath() + '/' + storedInfoFileName;
113 debug() << "Redownload file: " << absFileName << endl;
115 if ( m_albumDownloader == 0 )
117 m_albumDownloader = new MagnatuneAlbumDownloader();
118 connect( m_albumDownloader, SIGNAL( downloadComplete( bool ) ), this, SLOT( albumDownloadComplete( bool ) ) );
122 if (m_downloadDialog == 0) {
123 m_downloadDialog = new MagnatuneDownloadDialog(m_parent);
124 connect( m_downloadDialog, SIGNAL( downloadAlbum( MagnatuneDownloadInfo * ) ), m_albumDownloader, SLOT( downloadAlbum( MagnatuneDownloadInfo * ) ) );
128 MagnatuneDownloadInfo * downloadInfo = new MagnatuneDownloadInfo();
129 if ( downloadInfo->initFromFile( absFileName ) )
132 debug() << "Showing download dialog" << endl;
133 m_downloadDialog->setDownloadInfo( downloadInfo );
134 m_downloadDialog->show();
136 else
139 KMessageBox::information( m_parent, i18n( "Could not re-download album" ),
140 i18n( "There seems to be a problem with the selected redownload info file." ) + '\n' );
146 void MagnatuneRedownloadHandler::selectionDialogCancelled( )
148 if (m_redownloadDialog != 0) {
149 m_redownloadDialog->hide();
150 delete m_redownloadDialog;
151 m_redownloadDialog = 0;
155 void MagnatuneRedownloadHandler::albumDownloadComplete( bool success )
157 Q_UNUSED( success );
158 //cleanup time!
160 if (m_downloadDialog != 0) {
161 delete m_downloadDialog;
162 m_downloadDialog = 0;
164 if (m_albumDownloader != 0) {
165 delete m_albumDownloader;
166 m_albumDownloader = 0;