diff --git a/src/libtomahawk/DownloadJob.cpp b/src/libtomahawk/DownloadJob.cpp index d8aa11f34..6d0c15a15 100644 --- a/src/libtomahawk/DownloadJob.cpp +++ b/src/libtomahawk/DownloadJob.cpp @@ -118,7 +118,7 @@ DownloadJob::localFile() const QString -DownloadJob::localPath() const +DownloadJob::localPath( const Tomahawk::album_ptr& album ) { QDir dir = TomahawkSettings::instance()->downloadsPath(); @@ -127,7 +127,7 @@ DownloadJob::localPath() const dir.mkpath( "." ); } - QString path = QString( "%1/%2" ).arg( safeEncode( m_track->artist(), true ) ).arg( safeEncode( m_track->album(), true ) ); + QString path = QString( "%1/%2" ).arg( safeEncode( album->artist()->name(), true ) ).arg( safeEncode( album->name(), true ) ); dir.mkpath( path ); return QString( dir.path() + "/" + path ).replace( "//", "/" ); @@ -138,7 +138,7 @@ QUrl DownloadJob::prepareFilename() { QString filename = QString( "%1. %2.%3" ).arg( m_track->albumpos() ).arg( safeEncode( m_track->track() ) ).arg( m_format.extension ); - QString path = localPath(); + QString path = localPath( m_track->albumPtr() ); QString localFile = QString( path + "/" + filename ); if ( !m_tryResuming ) @@ -444,7 +444,7 @@ DownloadJob::checkForResumedFile() QString -DownloadJob::safeEncode( const QString& filename, bool removeTrailingDots ) const +DownloadJob::safeEncode( const QString& filename, bool removeTrailingDots ) { //FIXME: make it a regexp QString res = QString( filename ).toLatin1().replace( "/", "_" ).replace( "\\", "_" ) diff --git a/src/libtomahawk/DownloadJob.h b/src/libtomahawk/DownloadJob.h index 331f763bf..0f2ff70a4 100644 --- a/src/libtomahawk/DownloadJob.h +++ b/src/libtomahawk/DownloadJob.h @@ -58,7 +58,7 @@ public: long receivedSize() const { return m_rcvdSize; } long fileSize() const { return m_fileSize; } - QString localPath() const; + static QString localPath( const Tomahawk::album_ptr& album ); QString localFile() const; DownloadFormat format() const; @@ -90,7 +90,7 @@ private slots: private: void storeState(); - QString safeEncode( const QString& filename, bool removeTrailingDots = false ) const; + static QString safeEncode( const QString& filename, bool removeTrailingDots = false ); bool checkForResumedFile(); QUrl prepareFilename(); diff --git a/src/libtomahawk/playlist/TrackDetailView.cpp b/src/libtomahawk/playlist/TrackDetailView.cpp index da3c490a2..3c4b186a1 100644 --- a/src/libtomahawk/playlist/TrackDetailView.cpp +++ b/src/libtomahawk/playlist/TrackDetailView.cpp @@ -18,12 +18,6 @@ #include "TrackDetailView.h" -#include -#include -#include -#include -#include - #include "Album.h" #include "Track.h" #include "audio/AudioEngine.h" @@ -39,6 +33,13 @@ #include "utils/WebPopup.h" #include "utils/Logger.h" +#include +#include +#include +#include +#include +#include + using namespace Tomahawk; TrackDetailView::TrackDetailView( QWidget* parent ) @@ -219,8 +220,44 @@ TrackDetailView::onAlbumUpdated() { if ( m_query->track()->albumPtr()->purchased() ) { - m_buyButton->setText( tr( "Download Album" ) ); - m_buyButton->setVisible( true ); + m_allTracksAvailableLocally = true; + foreach( const query_ptr& currentQuery, m_playlistInterface->tracks() ) + { + if ( currentQuery->results().isEmpty() ) + { + m_allTracksAvailableLocally = false; + break; + } + else + { + m_allTracksAvailableLocally = false; + foreach ( const result_ptr& currentResult, currentQuery->results() ) + { + QList< DownloadFormat > formats = currentResult->downloadFormats(); + bool isDownloaded = formats.isEmpty() ? false : !DownloadManager::instance()->localFileForDownload( currentResult->downloadFormats().first().url.toString() ).isEmpty(); + if ( currentResult->isLocal() || isDownloaded ) + { + m_allTracksAvailableLocally = true; + break; + } + } + if ( !m_allTracksAvailableLocally ) + { + break; + } + } + } + + if ( m_allTracksAvailableLocally ) + { + m_buyButton->setText( tr( "View in Folder" ) ); + m_buyButton->setVisible( true ); + } + else + { + m_buyButton->setText( tr( "Download Album" ) ); + m_buyButton->setVisible( true ); + } } else { @@ -251,7 +288,14 @@ TrackDetailView::onBuyButtonClicked() { if ( m_query->track()->albumPtr()->purchased() ) { - emit downloadAll(); + if ( m_allTracksAvailableLocally ) + { + QDesktopServices::openUrl( DownloadJob::localPath( m_query->track()->albumPtr() ) ); + } + else + { + emit downloadAll(); + } } else { diff --git a/src/libtomahawk/playlist/TrackDetailView.h b/src/libtomahawk/playlist/TrackDetailView.h index 77c189bff..cb633d3d4 100644 --- a/src/libtomahawk/playlist/TrackDetailView.h +++ b/src/libtomahawk/playlist/TrackDetailView.h @@ -77,6 +77,7 @@ private: CaptionLabel* m_resultsBoxLabel; QPushButton* m_buyButton; bool m_buyButtonVisible; + bool m_allTracksAvailableLocally; QWidget* m_infoBox; QWidget* m_resultsBox;