From 6a4400240459703b7772c3496d661621b070f6b4 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Thu, 10 Mar 2016 00:05:42 +0100 Subject: [PATCH] Add Result::isLocal helper method --- src/libtomahawk/ContextMenu.cpp | 3 +-- src/libtomahawk/DropJob.cpp | 2 +- src/libtomahawk/Query.cpp | 2 +- src/libtomahawk/Result.cpp | 7 +++++++ src/libtomahawk/Result.h | 6 ++++++ src/libtomahawk/filemetadata/MetadataEditor.cpp | 4 ++-- src/libtomahawk/playlist/TreeProxyModel.cpp | 4 ++-- 7 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/libtomahawk/ContextMenu.cpp b/src/libtomahawk/ContextMenu.cpp index b8bf00876..08be77ae5 100644 --- a/src/libtomahawk/ContextMenu.cpp +++ b/src/libtomahawk/ContextMenu.cpp @@ -226,8 +226,7 @@ ContextMenu::setQueries( const QList& queries ) if ( m_supportedActions & ActionOpenFileManager && queries.length() == 1 && queries.first()->numResults() && - queries.first()->results().first()->resolvedByCollection() && - queries.first()->results().first()->resolvedByCollection()->isLocal() ) + queries.first()->results().first()->isLocal() ) { m_sigmap->setMapping( addAction( ImageRegistry::instance()->icon( RESPATH "images/folder.svg" ), tr( "Open Folder in File Manager..." ) ), ActionOpenFileManager ); diff --git a/src/libtomahawk/DropJob.cpp b/src/libtomahawk/DropJob.cpp index fc9663cda..e19a658e6 100644 --- a/src/libtomahawk/DropJob.cpp +++ b/src/libtomahawk/DropJob.cpp @@ -980,7 +980,7 @@ DropJob::removeRemoteSources() foreach ( const Tomahawk::result_ptr& result, item->results() ) { - if ( !result->resolvedByCollection().isNull() && !result->resolvedByCollection()->isLocal() ) + if ( !result->isLocal() ) { list.append( item ); break; diff --git a/src/libtomahawk/Query.cpp b/src/libtomahawk/Query.cpp index 057427d37..98a54a610 100644 --- a/src/libtomahawk/Query.cpp +++ b/src/libtomahawk/Query.cpp @@ -401,7 +401,7 @@ Query::resultSorter( const result_ptr& left, const result_ptr& right ) if ( ls == rs ) { - if ( right->resolvedByCollection() && right->resolvedByCollection()->isLocal() ) + if ( right->isLocal() ) { return false; } diff --git a/src/libtomahawk/Result.cpp b/src/libtomahawk/Result.cpp index 477b7192a..d8afa1cba 100644 --- a/src/libtomahawk/Result.cpp +++ b/src/libtomahawk/Result.cpp @@ -234,6 +234,13 @@ Result::playable() const } +bool +Result::isLocal() const +{ + return resolvedByCollection().isNull() ? false : resolvedByCollection()->isLocal(); +} + + QVariant Result::toVariant() const { diff --git a/src/libtomahawk/Result.h b/src/libtomahawk/Result.h index 25f623c1a..eaf6f660d 100644 --- a/src/libtomahawk/Result.h +++ b/src/libtomahawk/Result.h @@ -94,6 +94,12 @@ public: bool isOnline() const; bool playable() const; + /** + * @brief whether this result isLocal, i.e. resolved by a local collection + * @return isLocal + */ + bool isLocal() const; + QString url() const; /** * Has the given url been checked that it is accessible/valid. diff --git a/src/libtomahawk/filemetadata/MetadataEditor.cpp b/src/libtomahawk/filemetadata/MetadataEditor.cpp index 87ff5b16a..34ab2e21d 100644 --- a/src/libtomahawk/filemetadata/MetadataEditor.cpp +++ b/src/libtomahawk/filemetadata/MetadataEditor.cpp @@ -240,7 +240,7 @@ MetadataEditor::loadResult( const Tomahawk::result_ptr& result ) return; m_result = result; - setEditable( result->resolvedByCollection() && result->resolvedByCollection()->isLocal() ); + setEditable( result->isLocal() ); setTitle( result->track()->track() ); setArtist( result->track()->artist() ); @@ -250,7 +250,7 @@ MetadataEditor::loadResult( const Tomahawk::result_ptr& result ) setYear( result->track()->year() ); setBitrate( result->bitrate() ); - if ( result->resolvedByCollection() && result->resolvedByCollection()->isLocal() ) + if ( result->isLocal() ) { QString furl = m_result->url(); if ( furl.startsWith( "file://" ) ) diff --git a/src/libtomahawk/playlist/TreeProxyModel.cpp b/src/libtomahawk/playlist/TreeProxyModel.cpp index 089f1488c..fecea18b0 100644 --- a/src/libtomahawk/playlist/TreeProxyModel.cpp +++ b/src/libtomahawk/playlist/TreeProxyModel.cpp @@ -247,8 +247,8 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent if ( !item->result()->isOnline() && ti->result()->isOnline() ) return false; - if ( ( item->result()->resolvedByCollection().isNull() || !item->result()->resolvedByCollection()->isLocal() ) && - !ti->result()->resolvedByCollection().isNull() && ti->result()->resolvedByCollection()->isLocal() ) + if ( ( !item->result()->isLocal() ) && + !ti->result()->isLocal() ) { return false; }