mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 08:34:34 +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
|
QString
|
||||||
DownloadJob::localPath() const
|
DownloadJob::localPath( const Tomahawk::album_ptr& album )
|
||||||
{
|
{
|
||||||
QDir dir = TomahawkSettings::instance()->downloadsPath();
|
QDir dir = TomahawkSettings::instance()->downloadsPath();
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ DownloadJob::localPath() const
|
|||||||
dir.mkpath( "." );
|
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 );
|
dir.mkpath( path );
|
||||||
|
|
||||||
return QString( dir.path() + "/" + path ).replace( "//", "/" );
|
return QString( dir.path() + "/" + path ).replace( "//", "/" );
|
||||||
@@ -138,7 +138,7 @@ QUrl
|
|||||||
DownloadJob::prepareFilename()
|
DownloadJob::prepareFilename()
|
||||||
{
|
{
|
||||||
QString filename = QString( "%1. %2.%3" ).arg( m_track->albumpos() ).arg( safeEncode( m_track->track() ) ).arg( m_format.extension );
|
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 );
|
QString localFile = QString( path + "/" + filename );
|
||||||
|
|
||||||
if ( !m_tryResuming )
|
if ( !m_tryResuming )
|
||||||
@@ -444,7 +444,7 @@ DownloadJob::checkForResumedFile()
|
|||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
DownloadJob::safeEncode( const QString& filename, bool removeTrailingDots ) const
|
DownloadJob::safeEncode( const QString& filename, bool removeTrailingDots )
|
||||||
{
|
{
|
||||||
//FIXME: make it a regexp
|
//FIXME: make it a regexp
|
||||||
QString res = QString( filename ).toLatin1().replace( "/", "_" ).replace( "\\", "_" )
|
QString res = QString( filename ).toLatin1().replace( "/", "_" ).replace( "\\", "_" )
|
||||||
|
@@ -58,7 +58,7 @@ public:
|
|||||||
long receivedSize() const { return m_rcvdSize; }
|
long receivedSize() const { return m_rcvdSize; }
|
||||||
long fileSize() const { return m_fileSize; }
|
long fileSize() const { return m_fileSize; }
|
||||||
|
|
||||||
QString localPath() const;
|
static QString localPath( const Tomahawk::album_ptr& album );
|
||||||
QString localFile() const;
|
QString localFile() const;
|
||||||
DownloadFormat format() const;
|
DownloadFormat format() const;
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void storeState();
|
void storeState();
|
||||||
QString safeEncode( const QString& filename, bool removeTrailingDots = false ) const;
|
static QString safeEncode( const QString& filename, bool removeTrailingDots = false );
|
||||||
bool checkForResumedFile();
|
bool checkForResumedFile();
|
||||||
QUrl prepareFilename();
|
QUrl prepareFilename();
|
||||||
|
|
||||||
|
@@ -18,12 +18,6 @@
|
|||||||
|
|
||||||
#include "TrackDetailView.h"
|
#include "TrackDetailView.h"
|
||||||
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QScrollArea>
|
|
||||||
#include <QSizePolicy>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
|
|
||||||
#include "Album.h"
|
#include "Album.h"
|
||||||
#include "Track.h"
|
#include "Track.h"
|
||||||
#include "audio/AudioEngine.h"
|
#include "audio/AudioEngine.h"
|
||||||
@@ -39,6 +33,13 @@
|
|||||||
#include "utils/WebPopup.h"
|
#include "utils/WebPopup.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QScrollArea>
|
||||||
|
#include <QSizePolicy>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
TrackDetailView::TrackDetailView( QWidget* parent )
|
TrackDetailView::TrackDetailView( QWidget* parent )
|
||||||
@@ -219,8 +220,44 @@ TrackDetailView::onAlbumUpdated()
|
|||||||
{
|
{
|
||||||
if ( m_query->track()->albumPtr()->purchased() )
|
if ( m_query->track()->albumPtr()->purchased() )
|
||||||
{
|
{
|
||||||
m_buyButton->setText( tr( "Download Album" ) );
|
m_allTracksAvailableLocally = true;
|
||||||
m_buyButton->setVisible( 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
|
else
|
||||||
{
|
{
|
||||||
@@ -251,7 +288,14 @@ TrackDetailView::onBuyButtonClicked()
|
|||||||
{
|
{
|
||||||
if ( m_query->track()->albumPtr()->purchased() )
|
if ( m_query->track()->albumPtr()->purchased() )
|
||||||
{
|
{
|
||||||
emit downloadAll();
|
if ( m_allTracksAvailableLocally )
|
||||||
|
{
|
||||||
|
QDesktopServices::openUrl( DownloadJob::localPath( m_query->track()->albumPtr() ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emit downloadAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -77,6 +77,7 @@ private:
|
|||||||
CaptionLabel* m_resultsBoxLabel;
|
CaptionLabel* m_resultsBoxLabel;
|
||||||
QPushButton* m_buyButton;
|
QPushButton* m_buyButton;
|
||||||
bool m_buyButtonVisible;
|
bool m_buyButtonVisible;
|
||||||
|
bool m_allTracksAvailableLocally;
|
||||||
|
|
||||||
QWidget* m_infoBox;
|
QWidget* m_infoBox;
|
||||||
QWidget* m_resultsBox;
|
QWidget* m_resultsBox;
|
||||||
|
Reference in New Issue
Block a user