mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 16:14:40 +02:00
Show View In Folder button when album is completely downloaded
This commit is contained in:
@@ -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( "\\", "_" )
|
||||
|
@@ -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();
|
||||
|
||||
|
@@ -18,12 +18,6 @@
|
||||
|
||||
#include "TrackDetailView.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QScrollArea>
|
||||
#include <QSizePolicy>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "Album.h"
|
||||
#include "Track.h"
|
||||
#include "audio/AudioEngine.h"
|
||||
@@ -39,6 +33,13 @@
|
||||
#include "utils/WebPopup.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QScrollArea>
|
||||
#include <QSizePolicy>
|
||||
#include <QVBoxLayout>
|
||||
#include <QDesktopServices>
|
||||
|
||||
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
|
||||
{
|
||||
|
@@ -77,6 +77,7 @@ private:
|
||||
CaptionLabel* m_resultsBoxLabel;
|
||||
QPushButton* m_buyButton;
|
||||
bool m_buyButtonVisible;
|
||||
bool m_allTracksAvailableLocally;
|
||||
|
||||
QWidget* m_infoBox;
|
||||
QWidget* m_resultsBox;
|
||||
|
Reference in New Issue
Block a user