From 87278456f4319574556eb8213d96f36d015c219d Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Wed, 3 Feb 2016 13:28:43 +0100 Subject: [PATCH] Add download context menu to all playlist views but database collections --- src/libtomahawk/playlist/TrackView.cpp | 35 ++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/libtomahawk/playlist/TrackView.cpp b/src/libtomahawk/playlist/TrackView.cpp index bedde7a41..fd8241d0b 100644 --- a/src/libtomahawk/playlist/TrackView.cpp +++ b/src/libtomahawk/playlist/TrackView.cpp @@ -775,24 +775,42 @@ TrackView::onCustomContextMenu( const QPoint& pos ) m_contextMenu->setSupportedActions( m_contextMenu->supportedActions() | ContextMenu::ActionMarkListened | ContextMenu::ActionDelete ); - if ( proxyModel()->style() == PlayableProxyModel::Locker ) + if ( proxyModel()->style() != PlayableProxyModel::Collection ) { bool allDownloaded = true; + bool noneDownloadable = true; + bool downloadable = false; foreach ( const QModelIndex& index, selectedIndexes() ) { if ( index.column() ) continue; PlayableItem* item = proxyModel()->itemFromIndex( proxyModel()->mapToSource( index ) ); - if ( DownloadManager::instance()->localFileForDownload( item->query()->results().first()->downloadFormats().first().url.toString() ).isEmpty() ) + + if( item->query()->results().isEmpty() ) + continue; + + downloadable = !item->query()->results().first()->downloadFormats().isEmpty(); + if ( downloadable ) + { + noneDownloadable = false; + } + + if ( downloadable && DownloadManager::instance()->localFileForDownload( item->query()->results().first()->downloadFormats().first().url.toString() ).isEmpty() ) { allDownloaded = false; + } + + if ( !allDownloaded || !noneDownloadable ) + { break; } } - if ( !allDownloaded ) + if ( !allDownloaded || !noneDownloadable ) + { m_contextMenu->setSupportedActions( m_contextMenu->supportedActions() | ContextMenu::ActionDownload ); + } } QList queries; @@ -915,13 +933,16 @@ TrackView::downloadSelectedItems() PlayableItem* item = proxyModel()->itemFromIndex( proxyModel()->mapToSource( index ) ); - if ( !DownloadManager::instance()->localFileForDownload( item->query()->results().first()->downloadFormats().first().url.toString() ).isEmpty() ) - continue; if ( !item ) continue; - if ( !item->result()->downloadFormats().isEmpty() ) - DownloadManager::instance()->addJob( item->result()->toDownloadJob( item->result()->downloadFormats().first() ) ); + if ( item->query()->results().isEmpty() || item->query()->results().first()->downloadFormats().isEmpty() ) + continue; + + if ( !DownloadManager::instance()->localFileForDownload( item->query()->results().first()->downloadFormats().first().url.toString() ).isEmpty() ) + continue; + + DownloadManager::instance()->addJob( item->result()->toDownloadJob( item->result()->downloadFormats().first() ) ); } }