rev 5123 - people/ana/packages/amarok/debian/patches
Ana Beatriz Guerrero López
ana at alioth.debian.org
Tue Dec 12 17:03:20 CET 2006
Author: ana
Date: 2006-12-12 17:03:18 +0100 (Tue, 12 Dec 2006)
New Revision: 5123
Added:
people/ana/packages/amarok/debian/patches/magnatune.patch
Modified:
people/ana/packages/amarok/debian/patches/series
Log:
Adding magnatune patch.
Added: people/ana/packages/amarok/debian/patches/magnatune.patch
===================================================================
--- people/ana/packages/amarok/debian/patches/magnatune.patch 2006-12-12 09:02:49 UTC (rev 5122)
+++ people/ana/packages/amarok/debian/patches/magnatune.patch 2006-12-12 16:03:18 UTC (rev 5123)
@@ -0,0 +1,2741 @@
+diff -Nrua amarok/src/magnatunebrowser/magnatunealbumdownloader.cpp amarok/src/magnatunebrowser/magnatunealbumdownloader.cpp
+--- amarok/src/magnatunebrowser/magnatunealbumdownloader.cpp 1970-01-01 01:00:00.000000000 +0100
++++ amarok/src/magnatunebrowser/magnatunealbumdownloader.cpp 2006-12-11 12:57:25.000000000 +0100
+@@ -0,0 +1,141 @@
++/*
++ Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
++
++ This library is free software; you can redistribute it and/or
++ modify it under the terms of the GNU Library General Public
++ License as published by the Free Software Foundation; either
++ version 2 of the License, or (at your option) any later version.
++
++ This library is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
++ Library General Public License for more details.
++
++ You should have received a copy of the GNU Library General Public License
++ along with this library; see the file COPYING.LIB. If not, write to
++ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
++ Boston, MA 02110-1301, USA.
++*/
++
++#include "amarok.h"
++#include "debug.h"
++#include "magnatunealbumdownloader.h"
++#include "statusbar.h"
++
++
++MagnatuneAlbumDownloader::MagnatuneAlbumDownloader()
++{}
++
++
++MagnatuneAlbumDownloader::~MagnatuneAlbumDownloader()
++{}
++
++void MagnatuneAlbumDownloader::downloadAlbum( MagnatuneDownloadInfo * info )
++{
++ KURL downloadUrl = info->getCompleteDownloadUrl();
++ m_currentAlbumFileName = downloadUrl.fileName( false );
++
++ m_currentAlbumUnpackLocation = info->getUnpackLocation();
++
++
++
++ debug() << "Download: " << downloadUrl.url() << " to: " << m_currentAlbumUnpackLocation << endl;
++
++ m_albumDownloadJob = KIO::file_copy( downloadUrl, KURL( "/tmp/" + m_currentAlbumFileName ), -1, true, false, false );
++
++ connect( m_albumDownloadJob, SIGNAL( result( KIO::Job* ) ), SLOT( albumDownloadComplete( KIO::Job* ) ) );
++
++ Amarok::StatusBar::instance() ->newProgressOperation( m_albumDownloadJob )
++ .setDescription( i18n( "Downloading album" ) )
++ .setAbortSlot( this, SLOT( albumDownloadAborted() ) );
++}
++
++void MagnatuneAlbumDownloader::downloadCover( QString albumCoverUrlString, QString fileName )
++{
++ KURL downloadUrl( albumCoverUrlString );
++
++ debug() << "Download Cover: " << downloadUrl.url() << " to: /tmp/" << fileName << endl;
++
++ m_albumDownloadJob = KIO::file_copy( downloadUrl, KURL( "/tmp/" + fileName ), -1, true, false, false );
++
++ connect( m_albumDownloadJob, SIGNAL( result( KIO::Job* ) ), SLOT( coverDownloadComplete( KIO::Job* ) ) );
++
++ Amarok::StatusBar::instance() ->newProgressOperation( m_albumDownloadJob )
++ .setDescription( i18n( "Downloading album cover" ) )
++ .setAbortSlot( this, SLOT( coverDownloadAborted() ) );
++}
++
++
++
++void MagnatuneAlbumDownloader::albumDownloadComplete( KIO::Job * downloadJob )
++{
++
++ debug() << "album download complete" << endl;
++
++ if ( !downloadJob->error() == 0 )
++ {
++ //TODO: error handling here
++ return ;
++ }
++ if ( downloadJob != m_albumDownloadJob )
++ return ; //not the right job, so let's ignore it
++
++ //ok, now we have the .zip file downloaded. All we need is to unpack it to the desired location and add it to the collection.
++
++ QString unzipString = "unzip \"/tmp/" + m_currentAlbumFileName + "\" -d \"" + m_currentAlbumUnpackLocation + "\" &";
++
++ debug() << "unpacking: " << unzipString << endl;
++
++ system( unzipString.ascii() );
++
++ //delete m_albumDownloadJob; //whoa... this crashes everything... but not instantly... Is this job automatically deleted?
++
++ emit( downloadComplete( true ) );
++
++}
++
++void MagnatuneAlbumDownloader::coverDownloadComplete( KIO::Job * downloadJob )
++{
++ debug() << "cover download complete" << endl;
++
++ if ( !downloadJob->error() == 0 )
++ {
++ //TODO: error handling here
++ return ;
++ }
++ if ( downloadJob != m_albumDownloadJob )
++ return ; //not the right job, so let's ignore it
++
++ emit( coverDownloadCompleted( true ) );
++}
++
++
++void MagnatuneAlbumDownloader::albumDownloadAborted( )
++{
++ Amarok::StatusBar::instance()->endProgressOperation( m_albumDownloadJob );
++ m_albumDownloadJob->kill( true );
++ delete m_albumDownloadJob;
++ m_albumDownloadJob = 0;
++ debug() << "Aborted album download" << endl;
++
++ emit( downloadComplete( false ) );
++
++}
++
++void MagnatuneAlbumDownloader::coverDownloadAborted( )
++{
++ Amarok::StatusBar::instance()->endProgressOperation( m_albumDownloadJob );
++ m_albumDownloadJob->kill( true );
++ delete m_albumDownloadJob;
++ m_albumDownloadJob = 0;
++ debug() << "Aborted cover download" << endl;
++
++ emit( coverDownloadComplete( false ) );
++}
++
++
++
++
++
++
++
+diff -Nrua amarok/src/magnatunebrowser/magnatunealbumdownloader.h amarok/src/magnatunebrowser/magnatunealbumdownloader.h
+--- amarok/src/magnatunebrowser/magnatunealbumdownloader.h 1970-01-01 01:00:00.000000000 +0100
++++ amarok/src/magnatunebrowser/magnatunealbumdownloader.h 2006-12-11 12:57:25.000000000 +0100
+@@ -0,0 +1,80 @@
++/*
++ Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
++
++ This library is free software; you can redistribute it and/or
++ modify it under the terms of the GNU Library General Public
++ License as published by the Free Software Foundation; either
++ version 2 of the License, or (at your option) any later version.
++
++ This library is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
++ Library General Public License for more details.
++
++ You should have received a copy of the GNU Library General Public License
++ along with this library; see the file COPYING.LIB. If not, write to
++ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
++ Boston, MA 02110-1301, USA.
++*/
++
++#ifndef MAGNATUNEALBUMDOWNLOADER_H
++#define MAGNATUNEALBUMDOWNLOADER_H
++
++#include "magnatunedownloadinfo.h"
++
++#include <kio/job.h>
++#include <kio/jobclasses.h>
++
++#include <qobject.h>
++
++/**
++This class encapsulates the downloading of an album once all required information has been retrieved
++
++ @author Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
++*/
++class MagnatuneAlbumDownloader: public QObject
++{
++Q_OBJECT
++public:
++ MagnatuneAlbumDownloader();
++
++ ~MagnatuneAlbumDownloader();
++
++ void downloadCover( QString albumCoverUrlString, QString fileName );
++
++signals:
++
++ /**
++ * This signal is emitted when a download is finished or cancelled
++ * @param success true is download completed, false if download was cancelled.
++ */
++ void downloadComplete(bool success);
++ void coverDownloadCompleted(bool success);
++
++public slots:
++ /**
++ * Initiates the download of an album
++ * @param url A MagnatuneDownloadInfo object containing all needed information
++ */
++ void downloadAlbum( MagnatuneDownloadInfo * info );
++
++protected:
++
++ KIO::FileCopyJob * m_albumDownloadJob;
++ QString m_currentAlbumUnpackLocation;
++ QString m_currentAlbumFileName;
++
++protected slots:
++ /**
++ * Unzip the downloaded album
++ * @param downLoadJob
++ */
++ void albumDownloadComplete( KIO::Job* downloadJob );
++ void albumDownloadAborted();
++
++ void coverDownloadComplete( KIO::Job* downloadJob );
++ void coverDownloadAborted();
++
++};
++
++#endif
+diff -Nrua amarok/src/magnatunebrowser/magnatunebrowser.cpp amarok/src/magnatunebrowser/magnatunebrowser.cpp
+--- amarok/src/magnatunebrowser/magnatunebrowser.cpp 2006-10-26 22:40:20.000000000 +0200
++++ amarok/src/magnatunebrowser/magnatunebrowser.cpp 2006-12-11 12:57:25.000000000 +0100
+@@ -1,20 +1,20 @@
+ /*
+- Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
++ Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
+
+- This library is free software; you can redistribute it and/or
+- modify it under the terms of the GNU Library General Public
+- License as published by the Free Software Foundation; either
+- version 2 of the License, or (at your option) any later version.
+-
+- This library is distributed in the hope that it will be useful,
+- but WITHOUT ANY WARRANTY; without even the implied warranty of
+- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+- Library General Public License for more details.
+-
+- You should have received a copy of the GNU Library General Public License
+- along with this library; see the file COPYING.LIB. If not, write to
+- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+- Boston, MA 02110-1301, USA.
++ This library is free software; you can redistribute it and/or
++ modify it under the terms of the GNU Library General Public
++ License as published by the Free Software Foundation; either
++ version 2 of the License, or (at your option) any later version.
++
++ This library is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
++ Library General Public License for more details.
++
++ You should have received a copy of the GNU Library General Public License
++ along with this library; see the file COPYING.LIB. If not, write to
++ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
++ Boston, MA 02110-1301, USA.
+ */
+
+
+@@ -35,233 +35,246 @@
+ MagnatuneBrowser *MagnatuneBrowser::s_instance = 0;
+
+ MagnatuneBrowser::MagnatuneBrowser( const char *name )
+- : QVBox( 0, name )
++ : QVBox( 0, name )
+ {
+-DEBUG_BLOCK
++ DEBUG_BLOCK
+ initTopPanel( );
+
+ QSplitter *spliter = new QSplitter( Qt::Vertical, this );
+
+ debug() << "Magnatune browser starting..." << endl;
+- m_listView = new MagnatuneListView(spliter);
++ m_listView = new MagnatuneListView( spliter );
+
+- m_popupMenu = new QPopupMenu( spliter, "MagnatuneMenu" );
++ m_popupMenu = new QPopupMenu( spliter, "MagnatuneMenu" );
+ m_artistInfobox = new MagnatuneArtistInfoBox( spliter, "ArtistInfoBox" );
+
+
+ initBottomPanel();
+
+ //connect (m_listView, SIGNAL(executed(QListViewItem *)), this, SLOT(itemExecuted(QListViewItem *)));
+- connect( m_listView, SIGNAL( doubleClicked(QListViewItem *) ),
+- this, SLOT( itemExecuted(QListViewItem *) ) );
+- connect( m_listView, SIGNAL( selectionChanged(QListViewItem *) ),
+- this, SLOT( selectionChanged(QListViewItem *) ) );
+- connect( m_listView, SIGNAL( rightButtonClicked ( QListViewItem *, const QPoint &, int ) ),
+- this, SLOT( showPopupMenu( QListViewItem *, const QPoint &, int) ) );
++ connect( m_listView, SIGNAL( doubleClicked( QListViewItem * ) ),
++ this, SLOT( itemExecuted( QListViewItem * ) ) );
++ connect( m_listView, SIGNAL( selectionChanged( QListViewItem * ) ),
++ this, SLOT( selectionChanged( QListViewItem * ) ) );
++ connect( m_listView, SIGNAL( rightButtonClicked ( QListViewItem *, const QPoint &, int ) ),
++ this, SLOT( showPopupMenu( QListViewItem *, const QPoint &, int ) ) );
+ connect( m_popupMenu, SIGNAL( aboutToShow() ),
+- this, SLOT(menuAboutToShow()));
++ this, SLOT( menuAboutToShow() ) );
+
+ updateList( );
+
+ m_currentInfoUrl = "";
+
+- m_artistInfobox->openURL( KURL(locate( "data", "amarok/data/magnatune_start_page.html" ) ) );
++ m_artistInfobox->openURL( KURL( locate( "data", "amarok/data/magnatune_start_page.html" ) ) );
+
+ m_purchaseHandler = 0;
++ m_redownloadHandler = 0;
++
++ m_purchaseInProgress = 0;
+ }
+
+ void MagnatuneBrowser::itemExecuted( QListViewItem * item )
+ {
+-DEBUG_BLOCK
+- switch( item->depth() )
++ DEBUG_BLOCK
++ switch ( item->depth() )
+ {
+- case 2:
+- addTrackToPlaylist( dynamic_cast<MagnatuneListViewTrackItem *>(item) );
+- break;
+-
+- case 1:
+- addAlbumToPlaylist( dynamic_cast<MagnatuneListViewAlbumItem *>(item) );
+- break;
+-
+- case 0:
+- addArtistToPlaylist( dynamic_cast<MagnatuneListViewArtistItem *>(item) );
+- break;
++ case 2:
++ addTrackToPlaylist( dynamic_cast<MagnatuneListViewTrackItem *>( item ) );
++ break;
++
++ case 1:
++ addAlbumToPlaylist( dynamic_cast<MagnatuneListViewAlbumItem *>( item ) );
++ break;
++
++ case 0:
++ addArtistToPlaylist( dynamic_cast<MagnatuneListViewArtistItem *>( item ) );
++ break;
+
+- default:
+- break;
++ default:
++ break;
+ }
+ }
+
+ void MagnatuneBrowser::addTrackToPlaylist( MagnatuneTrack *item )
+ {
+- if( !item ) return; // sanity check
++ if ( !item ) return ; // sanity check
+
+ debug() << "Magnatune browser: adding single track" << endl;
+ QString url = item->getHifiURL();
+- Playlist * playlist = Playlist::instance();
++ Playlist * playlist = Playlist::instance();
+ playlist->insertMedia( KURL( url ) );
+ }
+
+ void MagnatuneBrowser::addAlbumToPlaylist( MagnatuneAlbum * item )
+ {
+- if( !item ) return; // sanity check
++ if ( !item ) return ; // sanity check
+ debug() << "Magnatune browser: adding album" << endl;
+
+- MagnatuneTrackList tracks = MagnatuneDatabaseHandler::instance()->getTracksByAlbumId(item->getId());
++ MagnatuneTrackList tracks = MagnatuneDatabaseHandler::instance() ->getTracksByAlbumId( item->getId() );
+
+ MagnatuneTrackList::iterator it;
+ for ( it = tracks.begin(); it != tracks.end(); ++it )
+- addTrackToPlaylist( &(*it) );
++ addTrackToPlaylist( &( *it ) );
+
+ }
+
+ void MagnatuneBrowser::addArtistToPlaylist( MagnatuneArtist *item )
+ {
+- if( !item ) return; // sanity check
++ if ( !item ) return ; // sanity check
+ debug() << "Magnatune browser: adding artist" << endl;
+
+- MagnatuneAlbumList albums = MagnatuneDatabaseHandler::instance()->getAlbumsByArtistId( item->getId(), "" );
++ MagnatuneAlbumList albums = MagnatuneDatabaseHandler::instance() ->getAlbumsByArtistId( item->getId(), "" );
+
+ MagnatuneAlbumList::iterator it;
+ for ( it = albums.begin(); it != albums.end(); ++it )
+- addAlbumToPlaylist( &(*it) );
++ addAlbumToPlaylist( &( *it ) );
+ }
+
+ void MagnatuneBrowser::selectionChanged( QListViewItem *item )
+ {
+- if( !item ) return; // sanity check
++ if ( !item ) return ; // sanity check
+
+ debug() << "Selection changed..." << endl;
+
+- if( item->depth() == 0 )
++
++ if ( item->depth() == 0 )
+ m_purchaseAlbumButton->setEnabled( false );
+ else
+- m_purchaseAlbumButton->setEnabled( true );
++ if ( ! m_purchaseInProgress )
++ m_purchaseAlbumButton->setEnabled( true );
+
+
+- if( !m_isInfoShown )
+- return;
++ if ( !m_isInfoShown )
++ return ;
+
+- switch( item->depth() )
++ switch ( item->depth() )
+ {
+- case 0:
++ case 0:
++ {
++ MagnatuneListViewArtistItem * artistItem = dynamic_cast<MagnatuneListViewArtistItem *>( item );
++ if ( artistItem && m_currentInfoUrl != artistItem->getHomeURL() )
+ {
+- MagnatuneListViewArtistItem *artistItem = dynamic_cast<MagnatuneListViewArtistItem *>(item);
+- if( artistItem && m_currentInfoUrl != artistItem->getHomeURL() )
+- {
+- m_currentInfoUrl = artistItem->getHomeURL();
+- m_artistInfobox->displayArtistInfo( KURL( m_currentInfoUrl ) );
+- }
++ m_currentInfoUrl = artistItem->getHomeURL();
++ m_artistInfobox->displayArtistInfo( KURL( m_currentInfoUrl ) );
+ }
+- break;
++ }
++ break;
+
+- case 1:
++ case 1:
++ {
++ MagnatuneListViewAlbumItem *albumItem = dynamic_cast<MagnatuneListViewAlbumItem *>( item );
++ if ( albumItem && m_currentInfoUrl != albumItem->getCoverURL() )
+ {
+- MagnatuneListViewAlbumItem *albumItem = dynamic_cast<MagnatuneListViewAlbumItem *>(item);
+- if( albumItem && m_currentInfoUrl != albumItem->getCoverURL() )
+- {
+- m_currentInfoUrl = albumItem->getCoverURL();
+- m_artistInfobox->displayAlbumInfo(albumItem);
+- }
++ m_currentInfoUrl = albumItem->getCoverURL();
++ m_artistInfobox->displayAlbumInfo( albumItem );
+ }
+- break;
++ }
++ break;
+
+- case 2:
+- {
+- // a track is selected, show the corrosponding album info!
+- MagnatuneListViewTrackItem *trackItem = dynamic_cast<MagnatuneListViewTrackItem*>(item);
+- int albumId = trackItem->getAlbumId();
+- MagnatuneAlbum album = MagnatuneDatabaseHandler::instance()->getAlbumById(albumId);
+- m_artistInfobox->displayAlbumInfo(&album);
+- }
+- break;
++ case 2:
++ {
++ // a track is selected, show the corrosponding album info!
++ MagnatuneListViewTrackItem *trackItem = dynamic_cast<MagnatuneListViewTrackItem*>( item );
++ int albumId = trackItem->getAlbumId();
++ MagnatuneAlbum album = MagnatuneDatabaseHandler::instance() ->getAlbumById( albumId );
++ m_artistInfobox->displayAlbumInfo( &album );
++ }
++ break;
+
+- default:
+- break;
++ default:
++ break;
+ }
+ }
+
+ void MagnatuneBrowser::showPopupMenu( QListViewItem * item, const QPoint & pos, int /*column*/ )
+ {
+- if( !item ) return;
++ if ( !item ) return ;
+
+ m_popupMenu->exec( pos );
+ }
+
+ void MagnatuneBrowser::addSelectionToPlaylist( )
+ {
+- QListViewItem *selectedItem = m_listView->selectedItem();
++ QListViewItem * selectedItem = m_listView->selectedItem();
+
+- switch( selectedItem->depth() )
++ switch ( selectedItem->depth() )
+ {
+- case 0:
+- addArtistToPlaylist( dynamic_cast<MagnatuneListViewArtistItem *>(selectedItem) );
+- break;
+- case 1:
+- addAlbumToPlaylist( dynamic_cast<MagnatuneListViewAlbumItem *>(selectedItem) );
+- break;
+- case 2:
+- addTrackToPlaylist( dynamic_cast<MagnatuneListViewTrackItem *>(selectedItem) );
+- }
++ case 0:
++ addArtistToPlaylist( dynamic_cast<MagnatuneListViewArtistItem *>( selectedItem ) );
++ break;
++ case 1:
++ addAlbumToPlaylist( dynamic_cast<MagnatuneListViewAlbumItem *>( selectedItem ) );
++ break;
++ case 2:
++ addTrackToPlaylist( dynamic_cast<MagnatuneListViewTrackItem *>( selectedItem ) );
+ }
++}
+
+ void MagnatuneBrowser::menuAboutToShow( )
+ {
+ m_popupMenu->clear();
+
+- QListViewItem *selectedItem = m_listView->selectedItem();
++ QListViewItem *selectedItem = m_listView->selectedItem();
+
+- if( !selectedItem ) return;
++ if ( !selectedItem ) return ;
+
+- switch( selectedItem->depth() )
++ switch ( selectedItem->depth() )
+ {
+- case 0:
+- m_popupMenu->insertItem( i18n( "Add artist to playlist" ), this, SLOT( addSelectionToPlaylist() ) );
+- break;
+- case 1:
+- m_popupMenu->insertItem( i18n( "Add album to playlist" ), this, SLOT( addSelectionToPlaylist() ) );
+- m_popupMenu->insertItem( i18n( "Purchase album" ), this, SLOT( purchaseSelectedAlbum()) );
+- break;
+- case 2:
+- m_popupMenu->insertItem( i18n( "Add track to playlist" ), this, SLOT( addSelectionToPlaylist() ) );
+- m_popupMenu->insertItem( i18n( "Purchase album" ), this, SLOT( purchaseAlbumContainingSelectedTrack() ) );
++ case 0:
++ m_popupMenu->insertItem( i18n( "Add artist to playlist" ), this, SLOT( addSelectionToPlaylist() ) );
++ break;
++ case 1:
++ m_popupMenu->insertItem( i18n( "Add album to playlist" ), this, SLOT( addSelectionToPlaylist() ) );
++ m_popupMenu->insertItem( i18n( "Purchase album" ), this, SLOT( purchaseSelectedAlbum() ) );
++ break;
++ case 2:
++ m_popupMenu->insertItem( i18n( "Add track to playlist" ), this, SLOT( addSelectionToPlaylist() ) );
++ m_popupMenu->insertItem( i18n( "Purchase album" ), this, SLOT( purchaseAlbumContainingSelectedTrack() ) );
+ }
+ }
+
+ void MagnatuneBrowser::purchaseButtonClicked( )
+ {
+- if (m_listView->selectedItem()->depth() == 1)
+- purchaseSelectedAlbum( );
+- else if (m_listView->selectedItem()->depth() == 2)
+- purchaseAlbumContainingSelectedTrack( );
++
++ if (!m_purchaseInProgress) {
++ m_purchaseInProgress = true;
++ m_purchaseAlbumButton->setEnabled( false );
++
++ if ( m_listView->selectedItem() ->depth() == 1 )
++ purchaseSelectedAlbum( );
++ else if ( m_listView->selectedItem() ->depth() == 2 )
++ purchaseAlbumContainingSelectedTrack( );
++ }
+ }
+
+ void MagnatuneBrowser::purchaseSelectedAlbum( )
+ {
+- if( !m_purchaseHandler )
++ if ( !m_purchaseHandler )
+ {
+ m_purchaseHandler = new MagnatunePurchaseHandler();
+ m_purchaseHandler->setParent( this );
++ connect( m_purchaseHandler, SIGNAL( purchaseCompleted( bool ) ), this, SLOT( purchaseCompleted( bool ) ) );
+ }
+
+- MagnatuneListViewAlbumItem *selectedAlbum = dynamic_cast<MagnatuneListViewAlbumItem *>(m_listView->selectedItem() );
++ MagnatuneListViewAlbumItem *selectedAlbum = dynamic_cast<MagnatuneListViewAlbumItem *>( m_listView->selectedItem() );
+
+ m_purchaseHandler->purchaseAlbum( selectedAlbum );
+ }
+
+ void MagnatuneBrowser::purchaseAlbumContainingSelectedTrack( )
+ {
+- if( !m_purchaseHandler )
++ if ( !m_purchaseHandler )
+ {
+ m_purchaseHandler = new MagnatunePurchaseHandler();
+ m_purchaseHandler->setParent( this );
++ connect( m_purchaseHandler, SIGNAL( purchaseCompleted( bool ) ), this, SLOT( purchaseCompleted( bool ) ) );
+ }
+
+- MagnatuneListViewTrackItem * selectedTrack = (MagnatuneListViewTrackItem *) m_listView->selectedItem();
++ MagnatuneListViewTrackItem *selectedTrack = dynamic_cast<MagnatuneListViewTrackItem *>( m_listView->selectedItem() );
+
+- MagnatuneAlbum album = MagnatuneDatabaseHandler::instance()->getAlbumById(selectedTrack->getAlbumId());
++ MagnatuneAlbum *album = new MagnatuneAlbum(MagnatuneDatabaseHandler::instance()->getAlbumById( selectedTrack->getAlbumId() ) );
+
+- m_purchaseHandler->purchaseAlbum(&album);
++ m_purchaseHandler->purchaseAlbum( album );
+ }
+
+ void MagnatuneBrowser::initTopPanel( )
+@@ -271,12 +284,15 @@
+ m_topPanel->setSpacing( 2 );
+ m_topPanel->setMargin( 2 );
+
+- new QLabel ( i18n("Genre: "), m_topPanel, "genreLabel", 0 );
++ new QLabel ( i18n( "Genre: " ), m_topPanel, "genreLabel", 0 );
+
+ m_genreComboBox = new QComboBox( false, m_topPanel, "genreComboBox" );
+
+ updateGenreBox();
+
++ m_advancedFeaturesButton = new QPushButton( i18n( "Advanced" ), m_topPanel, "advancedButton" );
++ connect( m_advancedFeaturesButton, SIGNAL( clicked() ), this, SLOT( processRedownload() ) );
++
+ connect( m_genreComboBox, SIGNAL( activated ( int ) ), this, SLOT( genreChanged() ) );
+ }
+
+@@ -299,20 +315,21 @@
+
+ m_updateListButton = new QPushButton( i18n( "Update" ), hBox, "updateButton" );
+ m_updateListButton->setIconSet( SmallIconSet( Amarok::icon( "rescan" ) ) );
+- m_showInfoToggleButton = new QPushButton( i18n( "Show Info" ) ,hBox, "showInfoCheckbox" );
++ m_showInfoToggleButton = new QPushButton( i18n( "Show Info" ) , hBox, "showInfoCheckbox" );
+ m_showInfoToggleButton->setToggleButton( true );
+ m_showInfoToggleButton->setIconSet( SmallIconSet( Amarok::icon( "info" ) ) );
+ m_showInfoToggleButton->setOn( true );
+
+ m_isInfoShown = true;
+
+- connect( m_showInfoToggleButton, SIGNAL( toggled( bool ) ), this, SLOT( showInfo(bool) ) );
+- connect( m_updateListButton, SIGNAL( clicked() ), this, SLOT( updateButtonClicked()) );
+- connect( m_purchaseAlbumButton, SIGNAL( clicked() ) , this, SLOT(purchaseButtonClicked()));
++ connect( m_showInfoToggleButton, SIGNAL( toggled( bool ) ), this, SLOT( showInfo( bool ) ) );
++ connect( m_updateListButton, SIGNAL( clicked() ), this, SLOT( updateButtonClicked() ) );
++ connect( m_purchaseAlbumButton, SIGNAL( clicked() ) , this, SLOT( purchaseButtonClicked() ) );
+ }
+
+ void MagnatuneBrowser::updateButtonClicked()
+ {
++ m_updateListButton->setEnabled( false );
+ updateMagnatuneList();
+ }
+
+@@ -321,8 +338,9 @@
+ //download new list from magnatune
+
+ m_listDownloadJob = KIO::storedGet( KURL( "http://magnatune.com/info/album_info.xml" ), false, false );
+- Amarok::StatusBar::instance()->newProgressOperation( m_listDownloadJob )
+- .setDescription( i18n( "Downloading Magnatune.com Database" ) );
++ Amarok::StatusBar::instance() ->newProgressOperation( m_listDownloadJob )
++ .setDescription( i18n( "Downloading Magnatune.com Database" ) )
++ .setAbortSlot( this, SLOT( listDownloadCancelled() ) );
+
+ connect( m_listDownloadJob, SIGNAL( result( KIO::Job* ) ), SLOT( listDownloadComplete( KIO::Job* ) ) );
+
+@@ -332,13 +350,17 @@
+
+ void MagnatuneBrowser::listDownloadComplete( KIO::Job * downLoadJob )
+ {
++
++ if ( downLoadJob != m_listDownloadJob )
++ return ; //not the right job, so let's ignore it
++
++ m_updateListButton->setEnabled( true );
+ if ( !downLoadJob->error() == 0 )
+ {
+ //TODO: error handling here
+- return;
++ return ;
+ }
+- if ( downLoadJob != m_listDownloadJob )
+- return; //not the right job, so let's ignore it
++
+
+ KIO::StoredTransferJob* const storedJob = static_cast<KIO::StoredTransferJob*>( downLoadJob );
+ QString list = QString( storedJob->data() );
+@@ -346,7 +368,7 @@
+
+ QFile file( "/tmp/album_info.xml" );
+
+- if( file.exists() )
++ if ( file.exists() )
+ file.remove();
+
+ if ( file.open( IO_WriteOnly ) )
+@@ -360,19 +382,32 @@
+ MagnatuneXmlParser * parser = new MagnatuneXmlParser( "/tmp/album_info.xml" );
+ connect( parser, SIGNAL( doneParsing() ), SLOT( doneParsing() ) );
+
+- ThreadWeaver::instance()->queueJob(parser);
++ ThreadWeaver::instance() ->queueJob( parser );
++}
++
++void MagnatuneBrowser::listDownloadCancelled( )
++{
++
++
++ Amarok::StatusBar::instance() ->endProgressOperation( m_listDownloadJob );
++ m_listDownloadJob->kill( true );
++ delete m_listDownloadJob;
++ m_listDownloadJob = 0;
++ debug() << "Aborted xml download" << endl;
++
++ m_updateListButton->setEnabled( true );
+ }
+
+ void MagnatuneBrowser::showInfo( bool show )
+ {
+- if( show )
++ if ( show )
+ {
+ m_isInfoShown = true;
+- m_artistInfobox->widget()->setMaximumHeight( 2000 );
++ m_artistInfobox->widget() ->setMaximumHeight( 2000 );
+ }
+ else
+ {
+- m_artistInfobox->widget()->setMaximumHeight( 0 );
++ m_artistInfobox->widget() ->setMaximumHeight( 0 );
+ m_isInfoShown = false;
+ }
+ }
+@@ -382,12 +417,12 @@
+ const QString genre = m_genreComboBox->currentText();
+
+ MagnatuneArtistList artists;
+- artists = MagnatuneDatabaseHandler::instance()->getArtistsByGenre( genre );
++ artists = MagnatuneDatabaseHandler::instance() ->getArtistsByGenre( genre );
+
+ m_listView->clear();
+ MagnatuneArtistList::iterator it;
+ for ( it = artists.begin(); it != artists.end(); ++it )
+- new MagnatuneListViewArtistItem( (*it), m_listView );
++ new MagnatuneListViewArtistItem( ( *it ), m_listView );
+
+ m_listView->repaintContents();
+ }
+@@ -408,14 +443,43 @@
+
+ void MagnatuneBrowser::updateGenreBox()
+ {
+- const QStringList genres = MagnatuneDatabaseHandler::instance()->getAlbumGenres();
++ const QStringList genres = MagnatuneDatabaseHandler::instance() ->getAlbumGenres();
+
+ m_genreComboBox->clear();
+ m_genreComboBox->insertItem ( "All" , 0 ); // should not be i18n'ed as it is
+ //used as a trigger in the code in the database handler.
+
+ foreach( genres )
+- m_genreComboBox->insertItem( (*it), -1 );
++ m_genreComboBox->insertItem( ( *it ), -1 );
++}
++
++void MagnatuneBrowser::processRedownload( )
++{
++ if ( m_redownloadHandler == 0 )
++ {
++ m_redownloadHandler = new MagnatuneRedownloadHandler( this );
++ }
++ m_redownloadHandler->showRedownloadDialog();
+ }
+
++void MagnatuneBrowser::purchaseCompleted( bool success )
++{
++
++ if (m_purchaseHandler != 0) {
++ delete m_purchaseHandler;
++ m_purchaseHandler = 0;
++ }
++
++ m_purchaseAlbumButton->setEnabled( true );
++ m_purchaseInProgress = false;
++
++ debug() << "Purchase operation complete" << endl;
++
++ //TODO: display some kind of success dialog here?
++
++
++}
++
++
++
+ #include "magnatunebrowser.moc"
+diff -Nrua amarok/src/magnatunebrowser/magnatunebrowser.h amarok/src/magnatunebrowser/magnatunebrowser.h
+--- amarok/src/magnatunebrowser/magnatunebrowser.h 2006-10-26 22:40:20.000000000 +0200
++++ amarok/src/magnatunebrowser/magnatunebrowser.h 2006-12-11 12:57:25.000000000 +0100
+@@ -27,6 +27,7 @@
+ #include "magnatunelistviewitems.h"
+ #include "magnatunepurchasedialog.h"
+ #include "magnatunepurchasehandler.h"
++#include "magnatuneredownloadhandler.h"
+ #include "magnatunexmlparser.h"
+
+ #include <kio/job.h>
+@@ -140,6 +141,11 @@
+ void listDownloadComplete( KIO::Job* downLoadJob);
+
+ /**
++ * Slot for catching cancelled list downloads
++ */
++ void listDownloadCancelled();
++
++ /**
+ * Slot called when the genre combo box selection changes. Triggers an update of the list view.
+ */
+ void genreChanged();
+@@ -150,6 +156,17 @@
+ */
+ void doneParsing();
+
++ /**
++ * Starts the process of redownloading a previously bought album
++ */
++ void processRedownload();
++
++ /**
++ * Slot for recieving notifications of completed purchase operations
++ * @param success Was the operation a success?
++ */
++ void purchaseCompleted( bool success );
++
+ private:
+
+ MagnatuneBrowser( const char *name );
+@@ -207,15 +224,18 @@
+ QString m_currentInfoUrl;
+ QPopupMenu *m_popupMenu;
+ MagnatunePurchaseHandler *m_purchaseHandler;
++ MagnatuneRedownloadHandler *m_redownloadHandler;
+
+ QHBox *m_topPanel;
+ QVBox *m_bottomPanel;
++ QPushButton *m_advancedFeaturesButton;
+ QPushButton *m_updateListButton;
+ QPushButton *m_purchaseAlbumButton;
+ QPushButton *m_showInfoToggleButton;
+
+ QComboBox *m_genreComboBox;
+ bool m_isInfoShown;
++ bool m_purchaseInProgress;
+
+ KIO::TransferJob * m_listDownloadJob;
+ };
+diff -Nrua amarok/src/magnatunebrowser/magnatunedownloaddialog.cpp amarok/src/magnatunebrowser/magnatunedownloaddialog.cpp
+--- amarok/src/magnatunebrowser/magnatunedownloaddialog.cpp 2006-10-26 22:40:20.000000000 +0200
++++ amarok/src/magnatunebrowser/magnatunedownloaddialog.cpp 2006-12-11 12:57:25.000000000 +0100
+@@ -1,20 +1,20 @@
+ /*
+- Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
++Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
+
+- This library is free software; you can redistribute it and/or
+- modify it under the terms of the GNU Library General Public
+- License as published by the Free Software Foundation; either
+- version 2 of the License, or (at your option) any later version.
+-
+- This library is distributed in the hope that it will be useful,
+- but WITHOUT ANY WARRANTY; without even the implied warranty of
+- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+- Library General Public License for more details.
+-
+- You should have received a copy of the GNU Library General Public License
+- along with this library; see the file COPYING.LIB. If not, write to
+- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+- Boston, MA 02110-1301, USA.
++This library is free software; you can redistribute it and/or
++modify it under the terms of the GNU Library General Public
++License as published by the Free Software Foundation; either
++version 2 of the License, or (at your option) any later version.
++
++This library is distributed in the hope that it will be useful,
++but WITHOUT ANY WARRANTY; without even the implied warranty of
++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
++Library General Public License for more details.
++
++You should have received a copy of the GNU Library General Public License
++along with this library; see the file COPYING.LIB. If not, write to
++the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
++Boston, MA 02110-1301, USA.
+ */
+
+
+@@ -32,35 +32,47 @@
+ MagnatuneDownloadDialog::MagnatuneDownloadDialog( QWidget *parent, const char *name, bool modal, WFlags fl )
+ : MagnatuneDownloadDialogBase( parent, name, modal, fl )
+ {
+- downloadTargetURLRequester->fileDialog()->setMode( KFile::Directory );
++ downloadTargetURLRequester->fileDialog() ->setMode( KFile::Directory );
++ m_currentDownloadInfo = 0;
+
+ }
+
+ MagnatuneDownloadDialog::~MagnatuneDownloadDialog()
+-{}
+-
+-void MagnatuneDownloadDialog::setMessage( QString message )
+ {
+- infoEdit->setText( message );
++ delete m_currentDownloadInfo;
+ }
+
+-void MagnatuneDownloadDialog::addFormat( QString name, QString link )
++
++void MagnatuneDownloadDialog::downloadButtonClicked( )
+ {
+
+- m_map[ name ] = link;
+- formatComboBox->insertItem( name );
++ if (m_currentDownloadInfo == 0) return;
++
++ m_currentDownloadInfo->setFormatSelection(formatComboBox->currentText());
++ m_currentDownloadInfo->setUnpackUrl(downloadTargetURLRequester->url());
++
++ emit( downloadAlbum( m_currentDownloadInfo ) );
++
++ close();
+
+ }
+
+-void MagnatuneDownloadDialog::downloadButtonClicked( )
++void MagnatuneDownloadDialog::setDownloadInfo( MagnatuneDownloadInfo * info )
+ {
++ if (m_currentDownloadInfo != 0) delete m_currentDownloadInfo;
+
+- QString sourceUrl = m_map[ formatComboBox->currentText() ];
+- QString targetUrl = downloadTargetURLRequester->url();
++ m_currentDownloadInfo = info;
+
+- emit( downloadAlbum( sourceUrl, targetUrl ) );
++ DownloadFormatMap formatMap = info->getFormatMap();
+
+- close();
++ DownloadFormatMap::Iterator it;
++
++ for ( it = formatMap.begin(); it != formatMap.end(); ++it )
++ {
++ formatComboBox->insertItem( it.key() );
++ }
++
++ infoEdit->setText( info->getDownloadMessage() );
+
+ }
+
+diff -Nrua amarok/src/magnatunebrowser/magnatunedownloaddialog.h amarok/src/magnatunebrowser/magnatunedownloaddialog.h
+--- amarok/src/magnatunebrowser/magnatunedownloaddialog.h 2006-10-26 22:40:20.000000000 +0200
++++ amarok/src/magnatunebrowser/magnatunedownloaddialog.h 2006-12-11 12:57:25.000000000 +0100
+@@ -21,6 +21,7 @@
+ #define MAGNATUNEDOWNLOADDIALOG_H
+
+ #include "magnatunedownloaddialogbase.h"
++#include "magnatunedownloadinfo.h"
+
+ #include <qmap.h>
+
+@@ -51,35 +52,27 @@
+ /*$PUBLIC_FUNCTIONS$*/
+
+ /**
+- * Sets the message to display in the message box
+- * @param message The message string.
++ * Sets the current download info
++ * @param the MagnatuneDownloadInfo class containing the information abut the
++ * download to display
+ */
+- void setMessage( QString message );
+-
+- /**
+- * Add a format option to the format selection combo box.
+- * @param name The name of the format
+- * @param link The download url
+- */
+- void addFormat( QString name, QString link );
++ void setDownloadInfo( MagnatuneDownloadInfo * info );
+
+ signals:
+
+ /**
+ * Signal emitted when all needed info has been gathered and handler
+ * should start album download.
+- * @param url The url of the labum to download.
+- * @param downloadLocation The location where the album should be downloaded to.
++ * @param completedInfo A DownloadInfo object containing all needed information
+ */
+- void downloadAlbum( QString url, QString downloadLocation );
++ void downloadAlbum(MagnatuneDownloadInfo * completedInfo);
+
+ public slots:
+ /*$PUBLIC_SLOTS$*/
+
+ protected:
+ /*$PROTECTED_FUNCTIONS$*/
+- typedef QMap<QString, QString> DownloadUrlMap;
+- DownloadUrlMap m_map;
++ MagnatuneDownloadInfo * m_currentDownloadInfo;
+
+ protected slots:
+ /*$PROTECTED_SLOTS$*/
+diff -Nrua amarok/src/magnatunebrowser/magnatunedownloadinfo.cpp amarok/src/magnatunebrowser/magnatunedownloadinfo.cpp
+--- amarok/src/magnatunebrowser/magnatunedownloadinfo.cpp 1970-01-01 01:00:00.000000000 +0100
++++ amarok/src/magnatunebrowser/magnatunedownloadinfo.cpp 2006-12-11 12:57:25.000000000 +0100
+@@ -0,0 +1,250 @@
++/*
++ Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
++
++ This library is free software; you can redistribute it and/or
++ modify it under the terms of the GNU Library General Public
++ License as published by the Free Software Foundation; either
++ version 2 of the License, or (at your option) any later version.
++
++ This library is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
++ Library General Public License for more details.
++
++ You should have received a copy of the GNU Library General Public License
++ along with this library; see the file COPYING.LIB. If not, write to
++ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
++ Boston, MA 02110-1301, USA.
++*/
++
++
++#include "magnatunedownloadinfo.h"
++
++
++#include "debug.h"
++
++#include <qfile.h>
++
++MagnatuneDownloadInfo::MagnatuneDownloadInfo()
++{
++ m_selectedDownloadFormat = "";
++}
++
++
++MagnatuneDownloadInfo::~MagnatuneDownloadInfo()
++{}
++
++bool MagnatuneDownloadInfo::initFromFile( QString downloadInfoFileName )
++{
++ QString xml;
++
++ QFile file( downloadInfoFileName );
++ if ( file.open( IO_ReadOnly ) )
++ {
++ QTextStream stream( &file );
++ while ( !stream.atEnd() )
++ {
++ xml += (stream.readLine() + '\n');
++ }
++ file.close();
++ } else {
++ debug() << "Error opening file: '" << downloadInfoFileName << "'" << endl;
++ return false;
++ }
++
++
++ //debug() << "XML from file: '" << xml << "'" << endl;
++ return initFromString( xml );
++}
++
++bool MagnatuneDownloadInfo::initFromString( QString downloadInfoString )
++{
++
++ //complete overkill to do a full SAX2 parser for this at the moment... I think....
++
++ // lets make sure that this is actually a valid result
++
++ int testIndex = downloadInfoString.find( "<RESULT>" );
++ if ( testIndex == -1 )
++ {
++ return false;
++ };
++
++ int startIndex;
++ int endIndex;
++
++ startIndex = downloadInfoString.find( "<DL_USERNAME>", 0, false );
++ if ( startIndex != -1 )
++ {
++ endIndex = downloadInfoString.find( "</DL_USERNAME>", 0, false );
++ if ( endIndex != -1 )
++ {
++ startIndex += 13;
++
++ debug() << "found username: " << downloadInfoString.mid( startIndex, endIndex - startIndex ) << endl;
++ m_userName = downloadInfoString.mid( startIndex, endIndex - startIndex );
++ }
++ else
++ {
++ return false;
++ }
++ }
++ else
++ {
++ return false;
++ }
++
++
++ startIndex = downloadInfoString.find( "<DL_PASSWORD>", 0, false );
++ if ( startIndex != -1 )
++ {
++ endIndex = downloadInfoString.find( "</DL_PASSWORD>", 0, false );
++ if ( endIndex != -1 )
++ {
++ startIndex += 13;
++ debug() << "found password: " << downloadInfoString.mid( startIndex, endIndex - startIndex ) << endl;
++ m_password = downloadInfoString.mid( startIndex, endIndex - startIndex );
++ }
++ else
++ {
++ return false;
++ }
++ }
++ else
++ {
++ return false;
++ }
++
++
++ startIndex = downloadInfoString.find( "<URL_WAVZIP>", 0, false );
++ if ( startIndex != -1 )
++ {
++ endIndex = downloadInfoString.find( "</URL_WAVZIP>", 0, false );
++ if ( endIndex != -1 )
++ {
++ startIndex += 12;
++ debug() << "found wav" << endl;
++ m_downloadFormats[ "Wav" ] = downloadInfoString.mid( startIndex, endIndex - startIndex );
++
++ }
++ }
++
++ startIndex = downloadInfoString.find( "<URL_128KMP3ZIP>", 0, false );
++ if ( startIndex != -1 )
++ {
++ endIndex = downloadInfoString.find( "</URL_128KMP3ZIP>", 0, false );
++ if ( endIndex != -1 )
++ {
++ startIndex += 16;
++ debug() << "found 128k mp3" << endl;
++ m_downloadFormats[ "128 kbit/s MP3" ] = downloadInfoString.mid( startIndex, endIndex - startIndex );
++
++ }
++ }
++
++ startIndex = downloadInfoString.find( "<URL_OGGZIP>", 0, false );
++ if ( startIndex != -1 )
++ {
++ endIndex = downloadInfoString.find( "</URL_OGGZIP>", 0, false );
++ if ( endIndex != -1 )
++ {
++ startIndex += 12;
++ debug() << "found ogg-vorbis" << endl;
++ m_downloadFormats[ "Ogg-Vorbis" ] = downloadInfoString.mid( startIndex, endIndex - startIndex );
++
++ }
++ }
++
++ startIndex = downloadInfoString.find( "<URL_VBRZIP>", 0, false );
++ if ( startIndex != -1 )
++ {
++ endIndex = downloadInfoString.find( "</URL_VBRZIP>", 0, false );
++ if ( endIndex != -1 )
++ {
++ startIndex += 12;
++ debug() << "found vbr mp3" << endl;
++ m_downloadFormats[ "VBR MP3" ] = downloadInfoString.mid( startIndex, endIndex - startIndex );
++
++ }
++ }
++
++ startIndex = downloadInfoString.find( "<URL_FLACZIP>", 0, false );
++ if ( startIndex != -1 )
++ {
++ endIndex = downloadInfoString.find( "</URL_FLACZIP>", 0, false );
++ if ( endIndex != -1 )
++ {
++ startIndex += 13;
++ debug() << "found flac" << endl;
++ m_downloadFormats[ "FLAC" ] = downloadInfoString.mid( startIndex, endIndex - startIndex );
++
++ }
++ }
++
++ startIndex = downloadInfoString.find( "<DL_MSG>", 0, false );
++ if ( startIndex != -1 )
++ {
++ endIndex = downloadInfoString.find( "</DL_MSG>", 0, false );
++ if ( endIndex != -1 )
++ {
++ startIndex += 9;
++ debug() << "found dl-message" << endl;
++ m_downloadMessage = downloadInfoString.mid( startIndex, endIndex - startIndex );
++ }
++ }
++
++ return true;
++}
++
++QString MagnatuneDownloadInfo::getUserName( )
++{
++ return m_userName;
++}
++
++QString MagnatuneDownloadInfo::getPassword( )
++{
++ return m_password;
++}
++
++QString MagnatuneDownloadInfo::getDownloadMessage( )
++{
++ return m_downloadMessage;
++}
++
++DownloadFormatMap MagnatuneDownloadInfo::getFormatMap()
++{
++ return m_downloadFormats;
++}
++
++void MagnatuneDownloadInfo::setFormatSelection( QString selectedFormat )
++{
++ m_selectedDownloadFormat = selectedFormat;
++}
++
++bool MagnatuneDownloadInfo::isReadyForDownload( )
++{
++ return !m_selectedDownloadFormat.isEmpty();
++}
++
++KURL MagnatuneDownloadInfo::getCompleteDownloadUrl( )
++{
++
++ QString url = m_downloadFormats[ m_selectedDownloadFormat ];
++ KURL downloadUrl(url);
++ downloadUrl.setUser(m_userName);
++ downloadUrl.setPass(m_password);
++
++ return downloadUrl;
++}
++
++void MagnatuneDownloadInfo::setUnpackUrl( QString unpackUrl )
++{
++ m_unpackUrl = unpackUrl;
++}
++
++QString MagnatuneDownloadInfo::getUnpackLocation( )
++{
++ return m_unpackUrl;
++}
++
++
+diff -Nrua amarok/src/magnatunebrowser/magnatunedownloadinfo.h amarok/src/magnatunebrowser/magnatunedownloadinfo.h
+--- amarok/src/magnatunebrowser/magnatunedownloadinfo.h 1970-01-01 01:00:00.000000000 +0100
++++ amarok/src/magnatunebrowser/magnatunedownloadinfo.h 2006-12-11 12:57:25.000000000 +0100
+@@ -0,0 +1,72 @@
++/*
++ Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
++
++ This library is free software; you can redistribute it and/or
++ modify it under the terms of the GNU Library General Public
++ License as published by the Free Software Foundation; either
++ version 2 of the License, or (at your option) any later version.
++
++ This library is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
++ Library General Public License for more details.
++
++ You should have received a copy of the GNU Library General Public License
++ along with this library; see the file COPYING.LIB. If not, write to
++ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
++ Boston, MA 02110-1301, USA.
++*/
++
++
++#ifndef MAGNATUNE_DOWNLOAD_INFO_H
++#define MAGNATUNE_DOWNLOAD_INFO_H
++
++#include <kurl.h>
++
++#include <qmap.h>
++#include <qstring.h>
++
++
++typedef QMap<QString, QString> DownloadFormatMap;
++
++/**
++Class for parsing and storing the info from a download xml file or string
++
++ @author Nikolaj Hald Nielsen
++*/
++class MagnatuneDownloadInfo{
++public:
++ MagnatuneDownloadInfo();
++ ~MagnatuneDownloadInfo();
++
++ bool initFromString( QString downloadInfoString );
++ bool initFromFile( QString downloadInfoFileName );
++
++ DownloadFormatMap getFormatMap();
++ QString getUserName();
++ QString getPassword();
++ QString getDownloadMessage();
++
++
++ void setFormatSelection(QString selectedFormat);
++ void setUnpackUrl(QString unpackUrl);
++ bool isReadyForDownload();
++ KURL getCompleteDownloadUrl();
++ QString getUnpackLocation();
++
++
++
++protected:
++
++ DownloadFormatMap m_downloadFormats;
++ QString m_userName;
++ QString m_password;
++ QString m_downloadMessage;
++
++ //the following members are for storing the user selections regarding a download
++ QString m_unpackUrl;
++ QString m_selectedDownloadFormat;
++
++};
++
++#endif
+diff -Nrua amarok/src/magnatunebrowser/magnatunepurchasedialogbase.ui amarok/src/magnatunebrowser/magnatunepurchasedialogbase.ui
+--- amarok/src/magnatunebrowser/magnatunepurchasedialogbase.ui 2006-10-26 22:40:20.000000000 +0200
++++ amarok/src/magnatunebrowser/magnatunepurchasedialogbase.ui 2006-12-11 12:57:25.000000000 +0100
+@@ -4,12 +4,15 @@
+ <property name="name">
+ <cstring>magnatunePurchaseDialogBase</cstring>
+ </property>
++ <property name="enabled">
++ <bool>true</bool>
++ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+- <width>550</width>
+- <height>507</height>
++ <width>678</width>
++ <height>561</height>
+ </rect>
+ </property>
+ <property name="caption">
+@@ -19,23 +22,10 @@
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+- <widget class="QPushButton" row="2" column="0">
+- <property name="name">
+- <cstring>cancelButton</cstring>
+- </property>
+- <property name="text">
+- <string>Ca&ncel</string>
+- </property>
+- </widget>
+- <widget class="QPushButton" row="2" column="1">
+- <property name="name">
+- <cstring>purchaseButton</cstring>
+- </property>
+- <property name="text">
+- <string>P&urchase</string>
+- </property>
+- </widget>
+- <widget class="QGroupBox" row="1" column="0" rowspan="1" colspan="2">
++ <property name="resizeMode">
++ <enum>Minimum</enum>
++ </property>
++ <widget class="QGroupBox" row="1" column="0">
+ <property name="name">
+ <cstring>groupBox2</cstring>
+ </property>
+@@ -473,7 +463,7 @@
+ </widget>
+ </grid>
+ </widget>
+- <widget class="QGroupBox" row="0" column="0" rowspan="1" colspan="2">
++ <widget class="QGroupBox" row="0" column="0">
+ <property name="name">
+ <cstring>groupBox1</cstring>
+ </property>
+@@ -484,6 +474,37 @@
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
++ <widget class="QLabel" row="0" column="2" rowspan="5" colspan="1">
++ <property name="name">
++ <cstring>coverPixmapLabel</cstring>
++ </property>
++ <property name="sizePolicy">
++ <sizepolicy>
++ <hsizetype>0</hsizetype>
++ <vsizetype>0</vsizetype>
++ <horstretch>0</horstretch>
++ <verstretch>0</verstretch>
++ </sizepolicy>
++ </property>
++ <property name="minimumSize">
++ <size>
++ <width>200</width>
++ <height>201</height>
++ </size>
++ </property>
++ <property name="maximumSize">
++ <size>
++ <width>200</width>
++ <height>201</height>
++ </size>
++ </property>
++ <property name="pixmap">
++ <pixmap>image0</pixmap>
++ </property>
++ <property name="scaledContents">
++ <bool>true</bool>
++ </property>
++ </widget>
+ <widget class="QLabel" row="0" column="0" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>infoLabel</cstring>
+@@ -506,6 +527,14 @@
+ <bool>true</bool>
+ </property>
+ </widget>
++ <widget class="QLabel" row="1" column="0">
++ <property name="name">
++ <cstring>textLabel13</cstring>
++ </property>
++ <property name="text">
++ <string>Album:</string>
++ </property>
++ </widget>
+ <widget class="QLineEdit" row="2" column="1">
+ <property name="name">
+ <cstring>artistEdit</cstring>
+@@ -517,7 +546,15 @@
+ <bool>true</bool>
+ </property>
+ </widget>
+- <widget class="QLineEdit" row="3" column="1" rowspan="2" colspan="1">
++ <widget class="QLabel" row="2" column="0">
++ <property name="name">
++ <cstring>textLabel14</cstring>
++ </property>
++ <property name="text">
++ <string>Artist:</string>
++ </property>
++ </widget>
++ <widget class="QLineEdit" row="3" column="1">
+ <property name="name">
+ <cstring>genresEdit</cstring>
+ </property>
+@@ -528,7 +565,7 @@
+ <bool>true</bool>
+ </property>
+ </widget>
+- <widget class="QLineEdit" row="5" column="1">
++ <widget class="QLineEdit" row="4" column="1">
+ <property name="name">
+ <cstring>launchDateEdit</cstring>
+ </property>
+@@ -539,42 +576,103 @@
+ <bool>true</bool>
+ </property>
+ </widget>
+- <widget class="QLabel" row="4" column="0" rowspan="2" colspan="1">
++ <widget class="QLabel" row="3" column="0">
+ <property name="name">
+- <cstring>textLabel16</cstring>
++ <cstring>textLabel15</cstring>
+ </property>
+ <property name="text">
+- <string>Launch Year:</string>
++ <string>Genre:</string>
+ </property>
+ </widget>
+- <widget class="QLabel" row="3" column="0">
++ <widget class="QLabel" row="4" column="0">
+ <property name="name">
+- <cstring>textLabel15</cstring>
++ <cstring>textLabel16</cstring>
+ </property>
+ <property name="text">
+- <string>Genre:</string>
++ <string>Launch Year:</string>
+ </property>
+ </widget>
+- <widget class="QLabel" row="2" column="0">
++ </grid>
++ </widget>
++ <spacer row="2" column="0">
++ <property name="name">
++ <cstring>spacer1</cstring>
++ </property>
++ <property name="orientation">
++ <enum>Vertical</enum>
++ </property>
++ <property name="sizeType">
++ <enum>Minimum</enum>
++ </property>
++ <property name="sizeHint">
++ <size>
++ <width>20</width>
++ <height>16</height>
++ </size>
++ </property>
++ </spacer>
++ <widget class="QLayoutWidget" row="3" column="0">
++ <property name="name">
++ <cstring>layout2</cstring>
++ </property>
++ <hbox>
++ <property name="name">
++ <cstring>unnamed</cstring>
++ </property>
++ <property name="margin">
++ <number>0</number>
++ </property>
++ <property name="spacing">
++ <number>5</number>
++ </property>
++ <spacer>
+ <property name="name">
+- <cstring>textLabel14</cstring>
++ <cstring>spacer3</cstring>
++ </property>
++ <property name="orientation">
++ <enum>Horizontal</enum>
++ </property>
++ <property name="sizeType">
++ <enum>Expanding</enum>
++ </property>
++ <property name="sizeHint">
++ <size>
++ <width>41</width>
++ <height>21</height>
++ </size>
++ </property>
++ </spacer>
++ <widget class="QPushButton">
++ <property name="name">
++ <cstring>purchaseButton</cstring>
+ </property>
+ <property name="text">
+- <string>Artist:</string>
++ <string>P&urchase</string>
++ </property>
++ <property name="accel">
++ <string>Alt+U</string>
+ </property>
+ </widget>
+- <widget class="QLabel" row="1" column="0">
++ <widget class="QPushButton">
+ <property name="name">
+- <cstring>textLabel13</cstring>
++ <cstring>cancelButton</cstring>
+ </property>
+ <property name="text">
+- <string>Album:</string>
++ <string>Ca&ncel</string>
++ </property>
++ <property name="accel">
++ <string>Alt+N</string>
+ </property>
+ </widget>
+- </grid>
++ </hbox>
+ </widget>
+ </grid>
+ </widget>
++<images>
++ <image name="image0">
++ <data format="XPM.GZ" length="4833">789c8597596f23470e80dfe75718c3b7c182e9eabb11ec834fc9873cbeaf601fc86ec9966df994cfc5fef794483633934d10c836fcb9582cde55fee5dbd2d9de68e9db2f5f9ee7349fb64bed153d2d7deb5e66b38fdffef3efff7ef99aa64b8baf2c5b4abffeebcb57dc5c6a9720499290640b8613e110ff22eb941b07657e7256f90be742e4a7c6a9ed076791c7a1732efbd784d3f817615a71167db0e55c0a17ce95c88f8ced3c7e74d6f306cea29fd159f583b3e8a75367d18f5bce8df0b63389be67e3ccfcd97716fd78e22cfaf1d459edefedcbedbc63e75af4cf85b33edeb8616cfef1b5b39eb7e72cf6c28b7166fb53678df7b5b3fadf388b3d503a8b3d40c6b9eaa35767d9cf37c6a5e53f73d6f3769d55bedf5f2789ac6bfcf2de1fda33ce4cdfbb716eeb6fce1acf1de3c2f2bbe7acf573605cdafe2b67f5efd359f20bb97165febe38b3c453fd2bfa7cd0a67165fea97c9db416ff1de3b1e9d77a6d12567bf8c159ed9d1ab7969fc2b8d378e2ba304579c93769bd719457fd524f2184cae221f51bd250a8fd3c35ae4cfec1b8b6fa06e3c6eaffc859d651f215b2d0c7efdab8327b969d459e9e8d7bfd57c68df587c43be4c1e20b685c1b9f0b17c1e283cfce927f96f911ca40d63fcbce7afebd31eb3a91b3fa37376ead9e64dea5759606a94f546eb23499883d9bc69932bef4acf22cf594725c1f8bfca9b3c8d3aa711e82c82bb73de3817111a4fe2171d67e1a1b97ba8e87ce5a8f12bfb48b2cfae8ceb85206894f9666135bff2e5c45d6fae894a3393a3f5be13aaeb7729eca4ff2d6ce3f5b701ef2b1c95f0aa7715dfb4de657519675d0fc8d8c9ba0f527f12faab234fd8fc695f1ab716dfa3f84ebb2089dec5f779678d381711d74beae398b7f540b3751bfd6e39ab1c9033b6bbd07e326687dcb3c2da8ecf47cfa301e9bbe37e389c94b3c0a2edba0f5f361dc194b3c8b36eed77acf9c453fab7f6d95587e6e8d83c957c25dc9668fdc5fc538b2c6e3a6e754e7adcc836252b6a9d69bccffb2ad535d67e98fb2ab538befaab3e8439947e5b84e82f6ffa17165f1bd7096fcc1ccb8b67a981b375a0f20f92d2775b078493dd54c75aaef0de9dfba75167fea2eb2f683dc5771388d753fbe396b7fca7c6b52ea2c5e57ce621fcbfdd26464f1812767ed8f63e3ced665de34c464fe9e1bb3d5b3f45bc3dca67a7fc9fba7697b46a9bf66cc13cb8fcc8b66c2960f3832b6f3988dad1e2828b799c53371d6f9766b9c5b7f4afe286983f5c3aeb3be177ace6c1ecc9cb51f6a678def8a7169f351fca710f5a93d9db3d64febacf9981aa76a2f5e3b6b7d5d1af7f6df3aebfb67e4acf93f72d6f972675cd83c7d77d67cac3bebfdfce9acf7eb87b3c66b665cdabc5feed9f44bfd51caade59395dbc4fc3f33cecc9f9b9e35bf786fdccfffc459e7ffc059eb7fe2acefcfd459df13dbceda5f4367bddffed8affdf0665c243a6f769c351f6367f51f7ad6fcefcf9dd57e72567fd959e3dd3a6bbc3b677daf34ce6affadb3dadbdb57263a5f46ce7adf8e9dd5dededfbe5e2f9cb5de5b678df7bb71a5fa59f767dccf77cd57d6f7136c185b7e79d359f3159cf53df7e8acf19e19f7f57ee5acef9b0d67f5b733b6fa844b63f38f07ceea9fcc3fca5b9bef58199b3dbce5acefa53567bd6fee8c73d54f95b3fa3b34b6fcc3b3b3f6dba1b3f6afe6a788fb6bad9f1f3f08f19b90b18ddff0f3dafefc2fe4bb284948f1b7f1e2e73fca4ff012af708ad77883b77f2f8f33bc8b9aeff1011ff1099f718e2ff88a6ff88e1ff8196da33fc92fe30aaee21aaee3060e70889bb885dbb88323dc8d7a407df941be8dd2dfa3ec5e94dac7033cc4233cc6133cc5333cc78bffb327c18029669863812556d1ef1a9ba8168080a1850ec608daaf30814bb882296ec035dc486426700b33b8837b78c0213cc2133ce367af3f7a93c01c5e700b5ee10d6fe11d093ee01396610556f104d6601d36a2d77abf0da2f41036610bb6b1841d18c12e7c873dd887033884233886133885b318297d3fc558e114cee1021208d1e01432c8a180122aa8e3c5190f2322c63bb507995aea62bc37698c9f34a14bba822d9ad235ddd02dcde80e87744f0f7fc823d1233de1363d634d737aa1577aa3ebf8047ba70ffaa4655aa1555aa375b37f0c298e6923ca0fb0a1212cd3266dd136edd08876e93bedd13e1dd0211d997e88f6031dd3099d624e67744e17f15f8b40296594cb273ef61632aa5ff34515d5d43032707c19449fd6e993db283b8217ee62fc0630fa31bf1cdf037c493bb1724ef98a162d30e56bcae185467cc3b731dfa0f935f919dff13daef1033ff2133fc77d039e73d41da55ff90d268b8afba17ea27d30a18edff9833f7999577895d7a88421aff31b6fc0e04ff5c6314acc031ef2266cc4c7ce036ff12ca66a10ff75d95eacfd2ccf3b0bfd38e651ac93f7d83b77f84e47d1e6f1222e0bf9c5ef3ff7a3f690766f4ffd0490aa85affffbf5cbef985d44a8</data>
++ </image>
++</images>
+ <connections>
+ <connection>
+ <sender>cancelButton</sender>
+@@ -589,6 +687,20 @@
+ <slot>purchase()</slot>
+ </connection>
+ </connections>
++<tabstops>
++ <tabstop>albumEdit</tabstop>
++ <tabstop>artistEdit</tabstop>
++ <tabstop>genresEdit</tabstop>
++ <tabstop>launchDateEdit</tabstop>
++ <tabstop>nameEdit</tabstop>
++ <tabstop>emailEdit</tabstop>
++ <tabstop>ccEdit</tabstop>
++ <tabstop>expMonthEdit</tabstop>
++ <tabstop>expYearEdit</tabstop>
++ <tabstop>amountComboBox</tabstop>
++ <tabstop>purchaseButton</tabstop>
++ <tabstop>cancelButton</tabstop>
++</tabstops>
+ <slots>
+ <slot>purchase()</slot>
+ <slot>cancel()</slot>
+diff -Nrua amarok/src/magnatunebrowser/magnatunepurchasedialog.cpp amarok/src/magnatunebrowser/magnatunepurchasedialog.cpp
+--- amarok/src/magnatunebrowser/magnatunepurchasedialog.cpp 2006-10-26 22:40:20.000000000 +0200
++++ amarok/src/magnatunebrowser/magnatunepurchasedialog.cpp 2006-12-11 12:57:25.000000000 +0100
+@@ -24,7 +24,9 @@
+ #include <qcombobox.h>
+ #include <qlineedit.h>
+ #include <qmessagebox.h>
++#include <qpushbutton.h>
+ #include <qregexp.h>
++#include <qlabel.h>
+
+
+ MagnatunePurchaseDialog::MagnatunePurchaseDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
+@@ -55,6 +57,7 @@
+ if ( verifyEntries( ) )
+ {
+
++ setEnabled( false ); //to prevent accidental double purchases
+ emit( makePurchase( ccEdit->text(), expYearEdit->text(), expMonthEdit->text(), nameEdit->text(), emailEdit->text(), m_albumCode, amountComboBox->currentText().toInt() ) );
+
+ //close();
+@@ -65,7 +68,9 @@
+
+ void MagnatunePurchaseDialog::cancel( )
+ {
+- close();
++ hide();
++ emit ( cancelled() );
++
+ }
+
+ bool MagnatunePurchaseDialog::verifyEntries( )
+@@ -129,6 +134,12 @@
+ }
+
+
++void MagnatunePurchaseDialog::setCover( QString coverFile )
++{
++ coverPixmapLabel->setPixmap( QPixmap( coverFile ) );
++}
++
++
+ /*$SPECIALIZATION$*/
+
+
+diff -Nrua amarok/src/magnatunebrowser/magnatunepurchasedialog.h amarok/src/magnatunebrowser/magnatunepurchasedialog.h
+--- amarok/src/magnatunebrowser/magnatunepurchasedialog.h 2006-10-26 22:40:20.000000000 +0200
++++ amarok/src/magnatunebrowser/magnatunepurchasedialog.h 2006-12-11 12:57:25.000000000 +0100
+@@ -51,6 +51,12 @@
+ */
+ void setAlbum( MagnatuneAlbum * album );
+
++ /**
++ * Loads image into the cover label.
++ * @param coverFile image file to load.
++ */
++ void setCover( QString coverFile );
++
+
+ signals:
+
+@@ -67,6 +73,11 @@
+ */
+ void makePurchase( QString ccNumber, QString expYear, QString expMonth, QString name, QString email, QString albumCode, int amount );
+
++ /**
++ * Signal emited if purchase operation is cancelled
++ */
++ void cancelled();
++
+ public slots:
+ /*$PUBLIC_SLOTS$*/
+
+diff -Nrua amarok/src/magnatunebrowser/magnatunepurchasehandler.cpp amarok/src/magnatunebrowser/magnatunepurchasehandler.cpp
+--- amarok/src/magnatunebrowser/magnatunepurchasehandler.cpp 2006-10-26 22:40:20.000000000 +0200
++++ amarok/src/magnatunebrowser/magnatunepurchasehandler.cpp 2006-12-11 12:57:25.000000000 +0100
+@@ -1,20 +1,20 @@
+ /*
+- Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
++ Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
+
+- This library is free software; you can redistribute it and/or
+- modify it under the terms of the GNU Library General Public
+- License as published by the Free Software Foundation; either
+- version 2 of the License, or (at your option) any later version.
+-
+- This library is distributed in the hope that it will be useful,
+- but WITHOUT ANY WARRANTY; without even the implied warranty of
+- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+- Library General Public License for more details.
+-
+- You should have received a copy of the GNU Library General Public License
+- along with this library; see the file COPYING.LIB. If not, write to
+- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+- Boston, MA 02110-1301, USA.
++ This library is free software; you can redistribute it and/or
++ modify it under the terms of the GNU Library General Public
++ License as published by the Free Software Foundation; either
++ version 2 of the License, or (at your option) any later version.
++
++ This library is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
++ Library General Public License for more details.
++
++ You should have received a copy of the GNU Library General Public License
++ along with this library; see the file COPYING.LIB. If not, write to
++ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
++ Boston, MA 02110-1301, USA.
+ */
+
+ #include "amarok.h"
+@@ -28,268 +28,172 @@
+ #include <qmessagebox.h>
+
+ MagnatunePurchaseHandler::MagnatunePurchaseHandler()
+- : QObject()
++ : QObject()
+ {
+
+- m_downloadDialog = 0;
+- m_purchaseDialog = 0;
+- m_currentAlbum = 0;
++ m_downloadDialog = 0;
++ m_purchaseDialog = 0;
++ m_albumDownloader = 0;
++ m_currentAlbum = 0;
+ }
+
+
+ MagnatunePurchaseHandler::~MagnatunePurchaseHandler()
+ {
++ if (m_downloadDialog != 0) delete m_downloadDialog;
++ if (m_purchaseDialog != 0) delete m_purchaseDialog;
++ if (m_albumDownloader != 0) delete m_albumDownloader;
++
+ }
+
+
+-void MagnatunePurchaseHandler::purchaseAlbum(MagnatuneAlbum * album )
++void MagnatunePurchaseHandler::purchaseAlbum( MagnatuneAlbum * album )
+ {
+- m_currentAlbum = album;
+-
+- if (m_purchaseDialog == 0) {
+- m_purchaseDialog = new MagnatunePurchaseDialog(m_parent, "PurchaseDialog", true, 0);
+- }
+-
+-
+- connect(m_purchaseDialog, SIGNAL(makePurchase(QString, QString, QString, QString, QString, QString, int )), this, SLOT(processPayment( QString, QString, QString, QString, QString, QString, int)));
+-
+
+- if (album != 0) {
+- m_purchaseDialog->setAlbum(album);
+- m_purchaseDialog->show();
+- }
++ m_currentAlbum = album;
+
+-}
++ //first lets get the album cover for the album we are about to purchase.
++ //Then we can show it on the purchase dialog as well as put it in the
++ //same directory as the album.
+
+-void MagnatunePurchaseHandler::processPayment( QString ccNumber, QString expYear, QString expMonth, QString name, QString email, QString albumCode, int amount)
+-{
+- QString amountString;
+- amountString.setNum(amount, 10);
++ QString albumCoverUrlString = album->getCoverURL();
+
+- QString purchaseURL = "https://magnatune.com/buy/buy_dl_cc_xml?cc=" + ccNumber + "&mm=" + expMonth + "&yy="+ expYear + "&sku=" + albumCode + "&name=" + name + "&email=" + email + "&id=amarok&amount=" + amountString;
++ if ( m_albumDownloader == 0 )
++ {
++ m_albumDownloader = new MagnatuneAlbumDownloader();
++ connect( m_albumDownloader, SIGNAL( coverDownloadCompleted( bool ) ), this, SLOT( showPurchaseDialog( bool ) ));
++ }
+
+- debug() << "purchase url : " << purchaseURL << endl;
++ m_currentAlbumCoverName = album->getName() + " - cover.jpg";
+
+- m_resultDownloadJob = KIO::storedGet( KURL(purchaseURL), false, false );
+- Amarok::StatusBar::instance()->newProgressOperation( m_resultDownloadJob ).setDescription( i18n( "Processing Payment" ) );
+-
+- connect( m_resultDownloadJob, SIGNAL( result( KIO::Job* ) ), SLOT( xmlDownloadComplete( KIO::Job* ) ) );
+
++ m_albumDownloader->downloadCover( albumCoverUrlString, m_currentAlbumCoverName );
+
+ }
+
+-void MagnatunePurchaseHandler::xmlDownloadComplete( KIO::Job * downloadJob )
++void MagnatunePurchaseHandler::showPurchaseDialog( bool useCover )
+ {
+
+- debug() << "xml download complete" << endl;
+-
+- if ( !downloadJob->error() == 0 )
++ if ( m_albumDownloader != 0 )
+ {
+- //TODO: error handling here
+- return;
++ delete m_albumDownloader;
++ m_albumDownloader = 0;
+ }
+- if ( downloadJob != m_resultDownloadJob )
+- return; //not the right job, so let's ignore it
+
+- KIO::StoredTransferJob* const storedJob = static_cast<KIO::StoredTransferJob*>( downloadJob );
+- QString resultXml = QString( storedJob->data() );
++ if ( m_purchaseDialog == 0 )
++ {
++ m_purchaseDialog = new MagnatunePurchaseDialog( m_parent, "PurchaseDialog", true, 0 );
++
++ connect( m_purchaseDialog, SIGNAL( makePurchase( QString, QString, QString, QString, QString, QString, int ) ), this, SLOT( processPayment( QString, QString, QString, QString, QString, QString, int ) ) );
++ connect ( m_purchaseDialog, SIGNAL( cancelled() ), this, SLOT( albumPurchaseCancelled() ) );
++ }
+
+- debug() << endl << endl << "result: " << resultXml << endl << endl;
+
+- saveDownloadInfo( resultXml );
+-
+-
+- if (m_downloadDialog == 0) {
+- m_downloadDialog = new MagnatuneDownloadDialog(m_parent, "downloaddialog", true, 0);
+-
+- }
+-
+- connect(m_downloadDialog, SIGNAL(downloadAlbum(QString, QString)), this, SLOT(downloadAlbum(QString, QString)));
+-
+- //delete m_resultDownloadJob;
+-
+- if (parseDownloadXml(resultXml)) {
+-
+- m_purchaseDialog->close();
+- m_downloadDialog->show();
+- } else {
+
+- QMessageBox::information( m_parent, "Could not process payment",
+- "There seems to be an error in the information entered (check the credit card number), please try again\n");
+
+- //m_purchaseDialog->show();
+
+-
+- }
++ if ( m_currentAlbum != 0 )
++ {
++ m_purchaseDialog->setAlbum( m_currentAlbum );
++ m_purchaseDialog->setCover( "/tmp/" + m_currentAlbumCoverName );
++ m_purchaseDialog->show();
++ }
+ }
+
+-
+-
+-bool MagnatunePurchaseHandler::parseDownloadXml( QString xml )
++void MagnatunePurchaseHandler::processPayment( QString ccNumber, QString expYear, QString expMonth, QString name, QString email, QString albumCode, int amount )
+ {
++ QString amountString;
++ amountString.setNum( amount, 10 );
+
++ QString purchaseURL = "https://magnatune.com/buy/buy_dl_cc_xml?cc=" + ccNumber + "&mm=" + expMonth + "&yy=" + expYear + "&sku=" + albumCode + "&name=" + name + "&email=" + email + "&id=amarok&amount=" + amountString;
+
+- //complete overkill to do a full SAX2 parser for this at the moment... I think....
+-
++ debug() << "purchase url : " << purchaseURL << endl;
+
+- // lets make sure that this is actually a valid result
++ m_resultDownloadJob = KIO::storedGet( KURL( purchaseURL ), false, false );
++ Amarok::StatusBar::instance() ->newProgressOperation( m_resultDownloadJob ).setDescription( i18n( "Processing Payment" ) );
+
+- int testIndex = xml.find("<RESULT>");
+- if (testIndex == -1) {
+- return false;
+- };
+-
+- int startIndex;
+- int endIndex;
+-
+- startIndex = xml.find("<DL_USERNAME>", 0, false);
+- if (startIndex != -1) {
+- endIndex = xml.find("</DL_USERNAME>", 0, false);
+- if (endIndex != -1) {
+- startIndex += 13;
+-
+- debug() << "found username: " << xml.mid(startIndex, endIndex - startIndex) << endl;
+- m_currentDlUsername = xml.mid(startIndex, endIndex - startIndex);
+- } else {
+- return false;
+- }
+- } else {
+- return false;
+- }
+-
+-
+- startIndex = xml.find("<DL_PASSWORD>", 0, false);
+- if (startIndex != -1) {
+- endIndex = xml.find("</DL_PASSWORD>", 0, false);
+- if (endIndex != -1) {
+- startIndex += 13;
+- debug() << "found password: " << xml.mid(startIndex, endIndex - startIndex) << endl;
+- m_currentDlPassword = xml.mid(startIndex, endIndex - startIndex);
+- } else {
+- return false;
+- }
+- } else {
+- return false;
+- }
+-
+-
+- startIndex = xml.find("<URL_WAVZIP>", 0, false);
+- if (startIndex != -1) {
+- endIndex = xml.find("</URL_WAVZIP>", 0, false);
+- if (endIndex != -1) {
+- startIndex += 12;
+- debug() << "found wav" << endl;
+- m_downloadDialog->addFormat("Wav" , xml.mid(startIndex, endIndex - startIndex));
+-
+- }
+- }
+-
+- startIndex = xml.find("<URL_128KMP3ZIP>", 0, false);
+- if (startIndex != -1) {
+- endIndex = xml.find("</URL_128KMP3ZIP>", 0, false);
+- if (endIndex != -1) {
+- startIndex += 16;
+- debug() << "found 128k mp3" << endl;
+- m_downloadDialog->addFormat("128 kbit/s MP3" , xml.mid(startIndex, endIndex - startIndex));
+-
+- }
+- }
+-
+- startIndex = xml.find("<URL_OGGZIP>", 0, false);
+- if (startIndex != -1) {
+- endIndex = xml.find("</URL_OGGZIP>", 0, false);
+- if (endIndex != -1) {
+- startIndex += 12;
+- debug() << "found ogg-vorbis" << endl;
+- m_downloadDialog->addFormat("Ogg-Vorbis" , xml.mid(startIndex, endIndex - startIndex));
+-
+- }
+- }
+-
+- startIndex = xml.find("<URL_VBRZIP>", 0, false);
+- if (startIndex != -1) {
+- endIndex = xml.find("</URL_VBRZIP>", 0, false);
+- if (endIndex != -1) {
+- startIndex += 12;
+- debug() << "found vbr mp3" << endl;
+- m_downloadDialog->addFormat("VBR MP3" , xml.mid(startIndex, endIndex - startIndex));
+-
+- }
+- }
+-
+- startIndex = xml.find("<URL_FLACZIP>", 0, false);
+- if (startIndex != -1) {
+- endIndex = xml.find("</URL_FLACZIP>", 0, false);
+- if (endIndex != -1) {
+- startIndex += 13;
+- debug() << "found flac" << endl;
+- m_downloadDialog->addFormat("FLAC" , xml.mid(startIndex, endIndex - startIndex));
+-
+- }
+- }
+-
+- startIndex = xml.find("<DL_MSG>", 0, false);
+- if (startIndex != -1) {
+- endIndex = xml.find("</DL_MSG>", 0, false);
+- if (endIndex != -1) {
+- startIndex += 9;
+- debug() << "found dl-message" << endl;
+- m_downloadDialog->setMessage(xml.mid(startIndex, endIndex - startIndex));
+- }
+- }
++ connect( m_resultDownloadJob, SIGNAL( result( KIO::Job* ) ), SLOT( xmlDownloadComplete( KIO::Job* ) ) );
+
+- return true;
+
+ }
+
+-void MagnatunePurchaseHandler::setParent( QWidget * parent )
++void MagnatunePurchaseHandler::xmlDownloadComplete( KIO::Job * downloadJob )
+ {
+- m_parent = parent;
+
+-}
++ debug() << "xml download complete" << endl;
+
+-void MagnatunePurchaseHandler::downloadAlbum( QString url, QString downloadLocation)
+-{
+-
+- KURL downloadUrl(url);
++ if ( !downloadJob->error() == 0 )
++ {
++ //TODO: error handling here
++ return ;
++ }
++ if ( downloadJob != m_resultDownloadJob )
++ return ; //not the right job, so let's ignore it
++
++ KIO::StoredTransferJob* const storedJob = static_cast<KIO::StoredTransferJob*>( downloadJob );
++ QString resultXml = QString( storedJob->data() );
+
+- m_currentAlbumFileName = downloadUrl.fileName(false);
++ debug() << endl << endl << "result: " << resultXml << endl << endl;
++
++ saveDownloadInfo( resultXml );
+
+- m_currentAlbumUnpackLocation = downloadLocation;
+
+- downloadUrl.setUser(m_currentDlUsername);
+- downloadUrl.setPass(m_currentDlPassword);
++ if ( m_albumDownloader == 0 )
++ {
++ m_albumDownloader = new MagnatuneAlbumDownloader();
++ connect( m_albumDownloader, SIGNAL( downloadComplete( bool ) ), this, SLOT( albumDownloadComplete( bool ) ) );
++ }
++
++ if ( m_downloadDialog == 0 )
++ {
++ m_downloadDialog = new MagnatuneDownloadDialog( m_parent, "downloaddialog", true, 0 );
++ connect( m_downloadDialog, SIGNAL( downloadAlbum( MagnatuneDownloadInfo * ) ), m_albumDownloader, SLOT( downloadAlbum( MagnatuneDownloadInfo * ) ) );
+
+- debug() << "Download: " << downloadUrl.url() << " to: " << m_currentAlbumUnpackLocation << endl;
++ }
+
+- m_albumDownloadJob = KIO::file_copy(downloadUrl, KURL("/tmp/" + m_currentAlbumFileName), -1, true, false, false);
+
+- connect( m_albumDownloadJob, SIGNAL( result( KIO::Job* ) ), SLOT( albumDownloadComplete( KIO::Job* ) ) );
+
+- Amarok::StatusBar::instance()->newProgressOperation( m_albumDownloadJob )
+- .setDescription( i18n( "Downloading album" ))
+- .setAbortSlot( this, SLOT(albumDownloadAborted()) );
+
++ MagnatuneDownloadInfo * downloadInfo = new MagnatuneDownloadInfo();
++ if ( downloadInfo->initFromString( resultXml ) )
++ {
++ m_downloadDialog->setDownloadInfo( downloadInfo );
++ m_purchaseDialog->close();
++ delete m_purchaseDialog;
++ m_purchaseDialog = 0;
++ m_downloadDialog->show();
++ }
++ else
++ {
+
++ QMessageBox::information( m_parent, "Could not process payment",
++ "There seems to be an error in the information entered (check the credit card number), please try again\n" );
++ m_purchaseDialog->setEnabled( true );
++ }
+ }
+
+
++void MagnatunePurchaseHandler::setParent( QWidget * parent )
++{
++ m_parent = parent;
+
++}
+
+ void MagnatunePurchaseHandler::saveDownloadInfo( QString infoXml )
+ {
+
+ QDir purchaseDir( Amarok::saveLocation( "magnatune.com/purchases/" ) );
+-
++
+ debug() << "magnatune save location" << purchaseDir.absPath() << endl;
+
+ //if directory does not exist, create it
+- if (! purchaseDir.exists () ) {
++ if ( ! purchaseDir.exists () )
++ {
+ purchaseDir.mkdir( ".", false );
+ }
+
+ //Create file name
+- MagnatuneArtist artist = MagnatuneDatabaseHandler::instance()->getArtistById( m_currentAlbum->getArtistId() );
++ MagnatuneArtist artist = MagnatuneDatabaseHandler::instance() ->getArtistById( m_currentAlbum->getArtistId() );
+ QString artistName = artist.getName();
+ QString fileName = artistName + " - " + m_currentAlbum->getName();
+
+@@ -297,53 +201,46 @@
+
+ //Skip if file already exists
+ if ( file.exists () )
+- return;
++ return ;
+
+ //write info
+- if ( file.open( IO_WriteOnly ) ) {
++ if ( file.open( IO_WriteOnly ) )
++ {
+ QTextStream stream( &file );
+- stream << infoXml << "\n";
++ stream << infoXml << "\n";
+ file.close();
+ }
+ }
+
+-
+-
+-void MagnatunePurchaseHandler::albumDownloadComplete( KIO::Job * downloadJob )
++void MagnatunePurchaseHandler::albumDownloadComplete( bool success )
+ {
++ //cleanup time!
+
+- debug() << "album download complete" << endl;
++ debug() << "MagnatunePurchaseHandler::albumDownloadComplete" << endl;
+
+- if ( !downloadJob->error() == 0 )
+- {
+- //TODO: error handling here
+- return;
+- }
+- if ( downloadJob != m_albumDownloadJob )
+- return; //not the right job, so let's ignore it
++ delete m_downloadDialog;
++ m_downloadDialog = 0;
+
+- //ok, now we have the .zip file downloaded. All we need is to unpack it to the desired location and add it to the collection.
++ emit( purchaseCompleted( success ) );
+
+- QString unzipString = "unzip \"/tmp/" + m_currentAlbumFileName +"\" -d \"" + m_currentAlbumUnpackLocation + "\" &";
++}
+
+- debug() << "unpacking: " << unzipString << endl;
++void MagnatunePurchaseHandler::albumPurchaseCancelled( )
++{
++ debug() << "Purchased dialog cancelled, deleting..." << endl;
+
+- system(unzipString.ascii());
++ delete m_purchaseDialog;
++ m_purchaseDialog = 0;
+
+- //delete m_albumDownloadJob; //whoa... this crashes everything... but not instantly... Is this job automatically deleted?
+
+- //debug() << "Album download job deleted!" << endl;
++ emit( purchaseCompleted( false) );
+ }
+
+
+
+-void MagnatunePurchaseHandler::albumDownloadAborted()
+-{
+- Amarok::StatusBar::instance()->endProgressOperation(m_albumDownloadJob);
+- m_albumDownloadJob->kill(true);
+- delete m_albumDownloadJob;
+- debug() << "Aborted album download" << endl;
+-}
++
++
++
+
+ #include "magnatunepurchasehandler.moc"
+
+diff -Nrua amarok/src/magnatunebrowser/magnatunepurchasehandler.h amarok/src/magnatunebrowser/magnatunepurchasehandler.h
+--- amarok/src/magnatunebrowser/magnatunepurchasehandler.h 2006-10-26 22:40:20.000000000 +0200
++++ amarok/src/magnatunebrowser/magnatunepurchasehandler.h 2006-12-11 12:57:25.000000000 +0100
+@@ -24,9 +24,10 @@
+ #include <kio/job.h>
+ #include <kio/jobclasses.h>
+
+-#include "magnatunetypes.h"
++#include "magnatunealbumdownloader.h"
+ #include "magnatunedownloaddialog.h"
+ #include "magnatunepurchasedialog.h"
++#include "magnatunetypes.h"
+
+
+ /**
+@@ -42,30 +43,31 @@
+ ~MagnatunePurchaseHandler();
+
+ void setParent( QWidget * parent );
++ /**
++ * Starts a purchase operation
++ * @param album The album to purchase
++ */
+ void purchaseAlbum( MagnatuneAlbum * album );
+
++signals:
++
++ void purchaseCompleted( bool success );
++
+ protected:
+
+ KIO::TransferJob * m_resultDownloadJob;
+- KIO::FileCopyJob * m_albumDownloadJob;
++
+
+- //need a parent to passe to any dialogs we spawn
++ //need a parent to pass to any dialogs we spawn
+ QWidget * m_parent;
+ MagnatunePurchaseDialog * m_purchaseDialog;
+ MagnatuneDownloadDialog * m_downloadDialog;
+-
+- QString m_currentDlUsername;
+- QString m_currentDlPassword;
+-
++ MagnatuneAlbumDownloader * m_albumDownloader;
+ MagnatuneAlbum * m_currentAlbum;
++ QString m_currentAlbumCoverName;
+
+- QString m_currentAlbumUnpackLocation;
+- QString m_currentAlbumFileName;
+-
+ bool parseDownloadXml( QString xml );
+
+-
+-
+ /**
+ * This function saves the xml download info received from Magnatune.com after a
+ * successful payment. This information can be used to later redownload a lost album,
+@@ -80,14 +82,15 @@
+
+ protected slots:
+
++ void showPurchaseDialog(bool useCover);
+ void xmlDownloadComplete( KIO::Job* downLoadJob );
+- void albumDownloadComplete( KIO::Job* downLoadJob );
+- void albumDownloadAborted();
++ void albumDownloadComplete(bool success);
++ void albumPurchaseCancelled();
+
+ public slots:
+
+ void processPayment( QString ccNumber, QString expYear, QString expMonth, QString name, QString email, QString albumCode, int amount );
+- void downloadAlbum( QString url, QString downloadLocation );
++
+
+
+ };
+diff -Nrua amarok/src/magnatunebrowser/magnatuneredownloaddialogbase.ui amarok/src/magnatunebrowser/magnatuneredownloaddialogbase.ui
+--- amarok/src/magnatunebrowser/magnatuneredownloaddialogbase.ui 1970-01-01 01:00:00.000000000 +0100
++++ amarok/src/magnatunebrowser/magnatuneredownloaddialogbase.ui 2006-12-11 12:57:25.000000000 +0100
+@@ -0,0 +1,95 @@
++<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
++<class>magnatuneReDownloadDialogBase</class>
++<widget class="QDialog">
++ <property name="name">
++ <cstring>magnatuneReDownloadDialogBase</cstring>
++ </property>
++ <property name="geometry">
++ <rect>
++ <x>0</x>
++ <y>0</y>
++ <width>466</width>
++ <height>431</height>
++ </rect>
++ </property>
++ <property name="caption">
++ <string>Redownload manager</string>
++ </property>
++ <grid>
++ <property name="name">
++ <cstring>unnamed</cstring>
++ </property>
++ <widget class="QLabel" row="0" column="0" rowspan="1" colspan="2">
++ <property name="name">
++ <cstring>textLabel1</cstring>
++ </property>
++ <property name="text">
++ <string>These are the albums that you have previously downloaded:</string>
++ </property>
++ </widget>
++ <widget class="QPushButton" row="2" column="0">
++ <property name="name">
++ <cstring>cancelButton</cstring>
++ </property>
++ <property name="text">
++ <string>&Cancel</string>
++ </property>
++ <property name="accel">
++ <string>Alt+C</string>
++ </property>
++ </widget>
++ <widget class="QPushButton" row="2" column="1">
++ <property name="name">
++ <cstring>redownloadButton</cstring>
++ </property>
++ <property name="text">
++ <string>Re&download</string>
++ </property>
++ <property name="accel">
++ <string>Alt+D</string>
++ </property>
++ </widget>
++ <widget class="QListView" row="1" column="0" rowspan="1" colspan="2">
++ <column>
++ <property name="text">
++ <string>Artist - Album</string>
++ </property>
++ <property name="clickable">
++ <bool>true</bool>
++ </property>
++ <property name="resizable">
++ <bool>true</bool>
++ </property>
++ </column>
++ <property name="name">
++ <cstring>redownloadListView</cstring>
++ </property>
++ </widget>
++ </grid>
++</widget>
++<connections>
++ <connection>
++ <sender>redownloadButton</sender>
++ <signal>clicked()</signal>
++ <receiver>magnatuneReDownloadDialogBase</receiver>
++ <slot>redownload()</slot>
++ </connection>
++ <connection>
++ <sender>cancelButton</sender>
++ <signal>clicked()</signal>
++ <receiver>magnatuneReDownloadDialogBase</receiver>
++ <slot>reject()</slot>
++ </connection>
++ <connection>
++ <sender>redownloadListView</sender>
++ <signal>selectionChanged(QListViewItem*)</signal>
++ <receiver>magnatuneReDownloadDialogBase</receiver>
++ <slot>selectionChanged()</slot>
++ </connection>
++</connections>
++<slots>
++ <slot access="protected">redownload()</slot>
++ <slot access="protected">selectionChanged()</slot>
++</slots>
++<layoutdefaults spacing="6" margin="11"/>
++</UI>
+diff -Nrua amarok/src/magnatunebrowser/magnatuneredownloaddialog.cpp amarok/src/magnatunebrowser/magnatuneredownloaddialog.cpp
+--- amarok/src/magnatunebrowser/magnatuneredownloaddialog.cpp 1970-01-01 01:00:00.000000000 +0100
++++ amarok/src/magnatunebrowser/magnatuneredownloaddialog.cpp 2006-12-11 12:57:25.000000000 +0100
+@@ -0,0 +1,69 @@
++/*
++ Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
++
++ This library is free software; you can redistribute it and/or
++ modify it under the terms of the GNU Library General Public
++ License as published by the Free Software Foundation; either
++ version 2 of the License, or (at your option) any later version.
++
++ This library is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
++ Library General Public License for more details.
++
++ You should have received a copy of the GNU Library General Public License
++ along with this library; see the file COPYING.LIB. If not, write to
++ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
++ Boston, MA 02110-1301, USA.
++*/
++
++
++#include "magnatuneredownloaddialog.h"
++
++#include <qpushbutton.h>
++#include <qlistview.h>
++
++MagnatuneRedownloadDialog::MagnatuneRedownloadDialog(QWidget* parent, const char* name, bool modal, WFlags fl)
++: magnatuneReDownloadDialogBase(parent,name, modal,fl)
++{
++ redownloadButton->setEnabled ( false );
++}
++
++MagnatuneRedownloadDialog::~MagnatuneRedownloadDialog()
++{
++}
++
++void MagnatuneRedownloadDialog::setRedownloadItems( QStringList items )
++{
++
++ for ( QStringList::Iterator it = items.begin(); it != items.end(); ++it ) {
++ new QListViewItem(redownloadListView, (*it));
++ }
++
++}
++
++void MagnatuneRedownloadDialog::redownload( )
++{
++ emit ( redownload( redownloadListView->currentItem()->text( 0 ) ) );
++}
++
++void MagnatuneRedownloadDialog::reject( )
++{
++ hide();
++ emit(cancelled());
++}
++
++void MagnatuneRedownloadDialog::selectionChanged( )
++{
++ if (redownloadListView->currentItem() != 0) {
++ redownloadButton->setEnabled ( true );
++ } else {
++ redownloadButton->setEnabled ( false );
++ }
++}
++
++/*$SPECIALIZATION$*/
++
++
++#include "magnatuneredownloaddialog.moc"
++
+diff -Nrua amarok/src/magnatunebrowser/magnatuneredownloaddialog.h amarok/src/magnatunebrowser/magnatuneredownloaddialog.h
+--- amarok/src/magnatunebrowser/magnatuneredownloaddialog.h 1970-01-01 01:00:00.000000000 +0100
++++ amarok/src/magnatunebrowser/magnatuneredownloaddialog.h 2006-12-11 12:57:25.000000000 +0100
+@@ -0,0 +1,59 @@
++/*
++ Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
++
++ This library is free software; you can redistribute it and/or
++ modify it under the terms of the GNU Library General Public
++ License as published by the Free Software Foundation; either
++ version 2 of the License, or (at your option) any later version.
++
++ This library is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
++ Library General Public License for more details.
++
++ You should have received a copy of the GNU Library General Public License
++ along with this library; see the file COPYING.LIB. If not, write to
++ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
++ Boston, MA 02110-1301, USA.
++*/
++
++
++#ifndef MAGNATUNE_REDOWNLOAD_DIALOG_H
++#define MAGNATUNE_REDOWNLOAD_DIALOG_H
++
++#include "magnatuneredownloaddialogbase.h"
++
++#include <qstringlist.h>
++
++class MagnatuneRedownloadDialog : public magnatuneReDownloadDialogBase
++{
++ Q_OBJECT
++
++public:
++ MagnatuneRedownloadDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
++ ~MagnatuneRedownloadDialog();
++ /*$PUBLIC_FUNCTIONS$*/
++
++ void setRedownloadItems(QStringList items);
++
++signals:
++
++ void redownload(QString downloadInfoFileName);
++ void cancelled();
++
++public slots:
++ /*$PUBLIC_SLOTS$*/
++
++protected:
++ /*$PROTECTED_FUNCTIONS$*/
++
++protected slots:
++ /*$PROTECTED_SLOTS$*/
++ void redownload();
++ void selectionChanged();
++ void reject();
++
++};
++
++#endif
++
+diff -Nrua amarok/src/magnatunebrowser/magnatuneredownloadhandler.cpp amarok/src/magnatunebrowser/magnatuneredownloadhandler.cpp
+--- amarok/src/magnatunebrowser/magnatuneredownloadhandler.cpp 1970-01-01 01:00:00.000000000 +0100
++++ amarok/src/magnatunebrowser/magnatuneredownloadhandler.cpp 2006-12-11 12:57:25.000000000 +0100
+@@ -0,0 +1,161 @@
++/*
++ Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
++
++ This library is free software; you can redistribute it and/or
++ modify it under the terms of the GNU Library General Public
++ License as published by the Free Software Foundation; either
++ version 2 of the License, or (at your option) any later version.
++
++ This library is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
++ Library General Public License for more details.
++
++ You should have received a copy of the GNU Library General Public License
++ along with this library; see the file COPYING.LIB. If not, write to
++ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
++ Boston, MA 02110-1301, USA.
++*/
++
++#include "magnatuneredownloadhandler.h"
++
++
++#include "amarok.h"
++#include "debug.h"
++
++
++#include "qdir.h"
++#include "qmessagebox.h"
++
++
++
++MagnatuneRedownloadHandler::MagnatuneRedownloadHandler(QWidget * parent)
++{
++ m_parent = parent;
++ m_redownloadDialog = 0;
++ m_downloadDialog = 0;
++ m_albumDownloader = 0;
++}
++
++
++MagnatuneRedownloadHandler::~MagnatuneRedownloadHandler()
++{
++}
++
++void MagnatuneRedownloadHandler::showRedownloadDialog( )
++{
++
++ QStringList previousDownloads = GetPurchaseList();
++
++ if (previousDownloads.isEmpty()) {
++
++ //No previously purchased trak information found. No more to do here...
++ QMessageBox::information( m_parent, "No purchases found!",
++ "No previous purchases has been found. Nothing to redownload...\n" );
++ return;
++ }
++
++ if (m_redownloadDialog == 0)
++ m_redownloadDialog = new MagnatuneRedownloadDialog( m_parent );
++
++
++ m_redownloadDialog->setRedownloadItems( previousDownloads );
++
++ connect( m_redownloadDialog, SIGNAL( redownload( QString) ), this, SLOT( redownload( QString ) ) );
++ connect( m_redownloadDialog, SIGNAL(cancelled() ), this, SLOT( selectionDialogCancelled() ));
++ m_redownloadDialog->show();
++
++}
++
++QStringList MagnatuneRedownloadHandler::GetPurchaseList( )
++{
++ QDir purchaseInfoDir( Amarok::saveLocation( "magnatune.com/purchases/" ) );
++
++ purchaseInfoDir.setFilter( QDir::Files);
++ purchaseInfoDir.setSorting( QDir::Name );
++
++ const QFileInfoList *list = purchaseInfoDir.entryInfoList();
++ QFileInfoListIterator it( *list );
++ QFileInfo *fi;
++
++ QStringList returnList;
++
++ while ( (fi = it.current()) != 0 ) {
++ returnList.append(fi->fileName());
++ ++it;
++ }
++
++ return returnList;
++
++}
++
++void MagnatuneRedownloadHandler::redownload( QString storedInfoFileName )
++{
++
++ QDir purchaseInfoDir( Amarok::saveLocation( "magnatune.com/purchases/" ) );
++ QString absFileName = purchaseInfoDir.absPath() + '/' + storedInfoFileName;
++
++ debug() << "Redownload file: " << absFileName << endl;
++
++ if (m_downloadDialog == 0)
++ m_downloadDialog = new MagnatuneDownloadDialog(m_parent);
++
++
++
++ if ( m_albumDownloader == 0 )
++ {
++ m_albumDownloader = new MagnatuneAlbumDownloader();
++ }
++
++
++ debug() << "Setting up connections" << endl;
++ connect( m_downloadDialog, SIGNAL( downloadAlbum( MagnatuneDownloadInfo * ) ), m_albumDownloader, SLOT( downloadAlbum( MagnatuneDownloadInfo * ) ) );
++
++ connect( m_albumDownloader, SIGNAL( downloadComplete( bool ) ), this, SLOT( albumDownloadComplete( bool ) ) );
++ debug() << "Done setting up connections" << endl;
++
++ MagnatuneDownloadInfo * downloadInfo = new MagnatuneDownloadInfo();
++ if ( downloadInfo->initFromFile( absFileName ) )
++ {
++
++ debug() << "Showing download dialog" << endl;
++ m_downloadDialog->setDownloadInfo( downloadInfo );
++ m_downloadDialog->show();
++ }
++ else
++ {
++
++ QMessageBox::information( m_parent, "Could not re-download album",
++ "There seems to be a problem with the selected redownload info file.\n" );
++
++ }
++
++}
++
++void MagnatuneRedownloadHandler::selectionDialogCancelled( )
++{
++ if (m_redownloadDialog != 0) {
++ m_redownloadDialog->hide();
++ delete m_redownloadDialog;
++ m_redownloadDialog = 0;
++ }
++}
++
++void MagnatuneRedownloadHandler::albumDownloadComplete( bool success )
++{
++ //cleanup time!
++
++ if (m_downloadDialog != 0) {
++ delete m_downloadDialog;
++ m_downloadDialog = 0;
++ }
++ if (m_albumDownloader != 0) {
++ delete m_albumDownloader;
++ m_albumDownloader = 0;
++ }
++
++}
++
++
++
++
+diff -Nrua amarok/src/magnatunebrowser/magnatuneredownloadhandler.h amarok/src/magnatunebrowser/magnatuneredownloadhandler.h
+--- amarok/src/magnatunebrowser/magnatuneredownloadhandler.h 1970-01-01 01:00:00.000000000 +0100
++++ amarok/src/magnatunebrowser/magnatuneredownloadhandler.h 2006-12-11 12:57:25.000000000 +0100
+@@ -0,0 +1,66 @@
++/*
++ Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
++
++ This library is free software; you can redistribute it and/or
++ modify it under the terms of the GNU Library General Public
++ License as published by the Free Software Foundation; either
++ version 2 of the License, or (at your option) any later version.
++
++ This library is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
++ Library General Public License for more details.
++
++ You should have received a copy of the GNU Library General Public License
++ along with this library; see the file COPYING.LIB. If not, write to
++ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
++ Boston, MA 02110-1301, USA.
++*/
++
++#ifndef MAGNATUNE_REDOWNLOAD_HANDLER_H
++#define MAGNATUNE_REDOWNLOAD_HANDLER_H
++
++#include "magnatunealbumdownloader.h"
++#include "magnatunedownloaddialog.h"
++#include "magnatunedownloadinfo.h"
++#include "magnatuneredownloaddialog.h"
++
++#include <qobject.h>
++
++/**
++This class handles the redownloading of previously purchased albums
++
++ @author Nikolaj Hald Nielsen <nhnFreespirit at gmail.com>
++*/
++
++class MagnatuneRedownloadHandler : public QObject {
++Q_OBJECT
++public:
++ MagnatuneRedownloadHandler(QWidget * parent);
++
++ ~MagnatuneRedownloadHandler();
++
++ /**
++ * Calls forth the redownload dialog.
++ */
++ void showRedownloadDialog();
++
++protected:
++
++ QWidget * m_parent;
++ QStringList GetPurchaseList( );
++ MagnatuneRedownloadDialog * m_redownloadDialog;
++ MagnatuneDownloadDialog * m_downloadDialog;
++ MagnatuneAlbumDownloader * m_albumDownloader;
++
++protected slots:
++
++ void redownload(QString storedInfoFileName);
++ void selectionDialogCancelled();
++ void albumDownloadComplete( bool success );
++
++
++
++};
++
++#endif
+diff -Nrua amarok/src/magnatunebrowser/Makefile.am amarok/src/magnatunebrowser/Makefile.am
+--- amarok/src/magnatunebrowser/Makefile.am 2006-12-12 13:38:58.000000000 +0000
++++ amarok/src/magnatunebrowser/Makefile.am 2006-12-12 13:39:46.000000000 +0000
+@@ -4,10 +4,13 @@
+
+ noinst_LTLIBRARIES = libmagnatunebrowser.la
+ libmagnatunebrowser_la_SOURCES = magnatuneartistinfobox.cpp \
+- magnatunebrowser.cpp magnatunedownloaddialogbase.ui magnatunedownloaddialog.cpp \
+- magnatunepurchasedialogbase.ui magnatunepurchasedialog.cpp magnatunepurchasehandler.cpp \
+- magnatunetypes.cpp magnatunexmlparser.cpp magnatunedatabasehandler.cpp \
+- magnatunelistviewitems.cpp magnatunelistview.cpp
++ magnatunebrowser.cpp magnatunedownloaddialogbase.ui magnatunedownloaddialog.cpp \
++ magnatunepurchasedialogbase.ui magnatunepurchasedialog.cpp magnatunepurchasehandler.cpp \
++ magnatunetypes.cpp magnatunexmlparser.cpp magnatunedatabasehandler.cpp \
++ magnatunelistviewitems.cpp magnatunelistview.cpp magnatuneredownloaddialog.cpp \
++ magnatuneredownloadhandler.cpp magnatunedownloadinfo.cpp magnatunealbumdownloader.cpp \
++ magnatuneredownloaddialogbase.ui
+ noinst_HEADERS = magnatunedatabasehandler.h magnatunelistviewitems.h \
+- magnatunelistview.h magnatuneartistinfobox.h magnatunebrowser.h magnatunedownloaddialog.h \
+- magnatunepurchasedialog.h magnatunepurchasehandler.h magnatunetypes.h magnatunexmlparser.h
++ magnatunelistview.h magnatuneartistinfobox.h magnatunebrowser.h magnatunedownloaddialog.h \
++ magnatunepurchasedialog.h magnatunepurchasehandler.h magnatunetypes.h magnatunexmlparser.h \
++ magnatunedownloadinfo.h magnatunealbumdownloader.h
Modified: people/ana/packages/amarok/debian/patches/series
===================================================================
--- people/ana/packages/amarok/debian/patches/series 2006-12-12 09:02:49 UTC (rev 5122)
+++ people/ana/packages/amarok/debian/patches/series 2006-12-12 16:03:18 UTC (rev 5123)
@@ -7,3 +7,4 @@
sparc-asm.patch -p0
invoke_browser.patch -p0
kde134333_negative_length_fix.diff -p0
+magnatune.patch -p0
More information about the pkg-kde-commits
mailing list