mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-30 19:00:12 +02:00
Properly handle online state for database and scriptcollections
This commit is contained in:
@@ -975,8 +975,7 @@ DropJob::removeRemoteSources()
|
||||
|
||||
foreach ( const Tomahawk::result_ptr& result, item->results() )
|
||||
{
|
||||
if ( !result->resolvedByCollection().isNull() && !result->resolvedByCollection()->source().isNull()
|
||||
&& result->resolvedByCollection()->source()->isLocal() )
|
||||
if ( !result->resolvedByCollection().isNull() && !result->resolvedByCollection()->isLocal() )
|
||||
{
|
||||
list.append( item );
|
||||
break;
|
||||
|
@@ -409,11 +409,11 @@ Query::resultSorter( const result_ptr& left, const result_ptr& right )
|
||||
|
||||
if ( ls == rs )
|
||||
{
|
||||
/* if ( left->collection() && left->collection()->source()->isLocal() )
|
||||
/* if ( left->collection() && left->collection()->isLocal() )
|
||||
{
|
||||
return true;
|
||||
}*/
|
||||
if ( right->resolvedByCollection() && right->resolvedByCollection()->source()->isLocal() )
|
||||
if ( right->resolvedByCollection() && right->resolvedByCollection()->isLocal() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@@ -191,7 +191,7 @@ Result::isOnline() const
|
||||
{
|
||||
if ( !resolvedByCollection().isNull() )
|
||||
{
|
||||
return resolvedByCollection()->source()->isOnline();
|
||||
return resolvedByCollection()->isOnline();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -205,7 +205,7 @@ Result::playable() const
|
||||
{
|
||||
if ( resolvedByCollection() )
|
||||
{
|
||||
return resolvedByCollection()->source()->isOnline();
|
||||
return resolvedByCollection()->isOnline();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -305,8 +305,8 @@ Result::setResolvedByCollection( const Tomahawk::collection_ptr& collection , bo
|
||||
{
|
||||
Q_ASSERT( !collection.isNull() );
|
||||
connect( collection.data(), SIGNAL( destroyed( QObject * ) ), SLOT( onOffline() ), Qt::QueuedConnection );
|
||||
connect( collection->source().data(), SIGNAL( online() ), SLOT( onOnline() ), Qt::QueuedConnection );
|
||||
connect( collection->source().data(), SIGNAL( offline() ), SLOT( onOffline() ), Qt::QueuedConnection );
|
||||
connect( collection.data(), SIGNAL( online() ), SLOT( onOnline() ), Qt::QueuedConnection );
|
||||
connect( collection.data(), SIGNAL( offline() ), SLOT( onOffline() ), Qt::QueuedConnection );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,7 +391,7 @@ Result::friendlySource() const
|
||||
return m_friendlySource;
|
||||
}
|
||||
else
|
||||
return resolvedByCollection()->source()->friendlyName();
|
||||
return resolvedByCollection()->prettyName();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -119,8 +119,15 @@ Collection::bigIcon() const
|
||||
}
|
||||
|
||||
|
||||
const
|
||||
source_ptr& Collection::source() const
|
||||
bool
|
||||
Collection::isLocal() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const source_ptr
|
||||
Collection::source() const
|
||||
{
|
||||
return m_source;
|
||||
}
|
||||
|
@@ -82,6 +82,9 @@ public:
|
||||
virtual const QPixmap icon( const QSize& size ) const override;
|
||||
virtual QPixmap bigIcon() const; //for the ViewPage header
|
||||
|
||||
virtual bool isOnline() const = 0;
|
||||
virtual bool isLocal() const;
|
||||
|
||||
virtual void loadPlaylists();
|
||||
virtual void loadAutoPlaylists();
|
||||
virtual void loadStations();
|
||||
@@ -108,7 +111,6 @@ public:
|
||||
virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist ) = 0;
|
||||
virtual Tomahawk::TracksRequest* requestTracks( const Tomahawk::album_ptr& album ) = 0;
|
||||
|
||||
const source_ptr& source() const;
|
||||
unsigned int lastmodified() const { return m_lastmodified; }
|
||||
|
||||
virtual int trackCount() const;
|
||||
@@ -128,6 +130,9 @@ signals:
|
||||
|
||||
void changed();
|
||||
|
||||
void online();
|
||||
void offline();
|
||||
|
||||
public slots:
|
||||
void setPlaylists( const QList<Tomahawk::playlist_ptr>& plists );
|
||||
void setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& autoplists );
|
||||
@@ -137,14 +142,18 @@ public slots:
|
||||
void delTracks( const QList<unsigned int>& fileids );
|
||||
|
||||
protected:
|
||||
QString m_name;
|
||||
unsigned int m_lastmodified; // unix time of last change to collection
|
||||
QSet< BrowseCapability > m_browseCapabilities;
|
||||
const source_ptr source() const;
|
||||
|
||||
private slots:
|
||||
void onSynced();
|
||||
void doLoadPlaylistUpdater( const playlist_ptr& p );
|
||||
|
||||
|
||||
protected:
|
||||
QString m_name;
|
||||
unsigned int m_lastmodified; // unix time of last change to collection
|
||||
QSet< BrowseCapability > m_browseCapabilities;
|
||||
|
||||
private:
|
||||
bool m_changed;
|
||||
|
||||
|
@@ -43,6 +43,17 @@ DatabaseCollection::DatabaseCollection( const source_ptr& src, QObject* parent )
|
||||
<< CapabilityBrowseArtists
|
||||
<< CapabilityBrowseAlbums
|
||||
<< CapabilityBrowseTracks;
|
||||
|
||||
|
||||
connect( source().data(), SIGNAL( online() ), SIGNAL( online() ) );
|
||||
connect( source().data(), SIGNAL( offline() ), SIGNAL( offline() ) );
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DatabaseCollection::isOnline() const
|
||||
{
|
||||
return source()->isOnline();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -45,6 +45,11 @@ public:
|
||||
|
||||
BackendType backendType() const override { return DatabaseCollectionType; }
|
||||
|
||||
bool isOnline() const override;
|
||||
bool isLocal() const override { return source()->isLocal(); }
|
||||
|
||||
using Collection::source;
|
||||
|
||||
void loadPlaylists() override;
|
||||
void loadAutoPlaylists() override;
|
||||
void loadStations() override;
|
||||
|
@@ -35,7 +35,7 @@ namespace Tomahawk
|
||||
|
||||
DatabaseCommand_AllAlbums::DatabaseCommand_AllAlbums( const Tomahawk::collection_ptr& collection, const Tomahawk::artist_ptr& artist, QObject* parent )
|
||||
: DatabaseCommand( parent )
|
||||
, m_collection( collection )
|
||||
, m_collection( collection.objectCast< DatabaseCollection >() )
|
||||
, m_artist( artist )
|
||||
, m_amount( 0 )
|
||||
, m_sortOrder( DatabaseCommand_AllAlbums::None )
|
||||
@@ -74,7 +74,7 @@ DatabaseCommand_AllAlbums::execForArtist( DatabaseImpl* dbi )
|
||||
}
|
||||
|
||||
if ( !m_collection.isNull() )
|
||||
sourceToken = QString( "AND file.source %1" ).arg( m_collection->source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( m_collection->source()->id() ) );
|
||||
sourceToken = QString( "AND file.source %1" ).arg( m_collection->isLocal() ? "IS NULL" : QString( "= %1" ).arg( m_collection->source()->id() ) );
|
||||
|
||||
if ( !m_filter.isEmpty() )
|
||||
{
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include "Typedefs.h"
|
||||
#include "DatabaseCommand.h"
|
||||
#include "Database.h"
|
||||
#include "DatabaseCollection.h"
|
||||
|
||||
#include "DllMacro.h"
|
||||
|
||||
@@ -74,7 +75,7 @@ signals:
|
||||
void done();
|
||||
|
||||
private:
|
||||
Tomahawk::collection_ptr m_collection;
|
||||
QSharedPointer< DatabaseCollection > m_collection;
|
||||
Tomahawk::artist_ptr m_artist;
|
||||
|
||||
unsigned int m_amount;
|
||||
|
@@ -33,7 +33,7 @@ namespace Tomahawk
|
||||
|
||||
DatabaseCommand_AllArtists::DatabaseCommand_AllArtists( const Tomahawk::collection_ptr& collection, QObject* parent )
|
||||
: DatabaseCommand( parent )
|
||||
, m_collection( collection )
|
||||
, m_collection( collection.objectCast< DatabaseCollection >() )
|
||||
, m_amount( 0 )
|
||||
, m_sortOrder( DatabaseCommand_AllArtists::None )
|
||||
, m_sortDescending( false )
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include "Typedefs.h"
|
||||
#include "DatabaseCommand.h"
|
||||
#include "Database.h"
|
||||
#include "DatabaseCollection.h"
|
||||
|
||||
#include "DllMacro.h"
|
||||
|
||||
@@ -65,7 +66,7 @@ signals:
|
||||
void done();
|
||||
|
||||
private:
|
||||
Tomahawk::collection_ptr m_collection;
|
||||
QSharedPointer< DatabaseCollection > m_collection;
|
||||
unsigned int m_amount;
|
||||
DatabaseCommand_AllArtists::SortOrder m_sortOrder;
|
||||
bool m_sortDescending;
|
||||
|
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "DatabaseCommand.h"
|
||||
#include "Database.h"
|
||||
#include "DatabaseCollection.h"
|
||||
#include "collection/Collection.h"
|
||||
#include "collection/TracksRequest.h"
|
||||
#include "Typedefs.h"
|
||||
@@ -49,7 +50,7 @@ public:
|
||||
|
||||
explicit DatabaseCommand_AllTracks( const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr(), QObject* parent = nullptr )
|
||||
: DatabaseCommand( parent )
|
||||
, m_collection( collection )
|
||||
, m_collection( collection.objectCast< DatabaseCollection >() )
|
||||
, m_artist( nullptr )
|
||||
, m_album( nullptr )
|
||||
, m_amount( 0 )
|
||||
@@ -77,7 +78,7 @@ signals:
|
||||
void done( const Tomahawk::collection_ptr& );
|
||||
|
||||
private:
|
||||
Tomahawk::collection_ptr m_collection;
|
||||
QSharedPointer< DatabaseCollection > m_collection;
|
||||
|
||||
Tomahawk::artist_ptr m_artist;
|
||||
Tomahawk::album_ptr m_album;
|
||||
|
@@ -59,7 +59,7 @@ DatabaseCommand_Resolve::exec( DatabaseImpl* lib )
|
||||
tDebug() << "Using result-hint to speed up resolving:" << m_query->resultHint();
|
||||
|
||||
Tomahawk::result_ptr result = lib->resultFromHint( m_query );
|
||||
if ( result && ( !result->resolvedByCollection() || result->resolvedByCollection()->source()->isOnline() ) )
|
||||
if ( result && ( !result->resolvedByCollection() || result->resolvedByCollection()->isOnline() ) )
|
||||
{
|
||||
QList<Tomahawk::result_ptr> res;
|
||||
res << result;
|
||||
|
@@ -240,7 +240,7 @@ MetadataEditor::loadResult( const Tomahawk::result_ptr& result )
|
||||
return;
|
||||
|
||||
m_result = result;
|
||||
setEditable( result->resolvedByCollection() && result->resolvedByCollection()->source()->isLocal() );
|
||||
setEditable( result->resolvedByCollection() && result->resolvedByCollection()->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()->source()->isLocal() )
|
||||
if ( result->resolvedByCollection() && result->resolvedByCollection()->isLocal() )
|
||||
{
|
||||
QString furl = m_result->url();
|
||||
if ( furl.startsWith( "file://" ) )
|
||||
|
@@ -49,10 +49,6 @@ AlbumModel::~AlbumModel()
|
||||
void
|
||||
AlbumModel::addCollection( const collection_ptr& collection, bool overwrite )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << collection->name()
|
||||
<< collection->source()->id()
|
||||
<< collection->source()->nodeId();
|
||||
|
||||
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection );
|
||||
m_overwriteOnAdd = overwrite;
|
||||
m_collection = collection;
|
||||
@@ -62,7 +58,7 @@ AlbumModel::addCollection( const collection_ptr& collection, bool overwrite )
|
||||
|
||||
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
|
||||
|
||||
setTitle( tr( "All albums from %1" ).arg( collection->source()->friendlyName() ) );
|
||||
setTitle( tr( "All albums from %1" ).arg( collection->prettyName() ) );
|
||||
|
||||
if ( collection.isNull() )
|
||||
{
|
||||
@@ -86,11 +82,6 @@ AlbumModel::addCollection( const collection_ptr& collection, bool overwrite )
|
||||
void
|
||||
AlbumModel::addFilteredCollection( const collection_ptr& collection, unsigned int amount, DatabaseCommand_AllAlbums::SortOrder order, bool overwrite )
|
||||
{
|
||||
/* qDebug() << Q_FUNC_INFO << collection->name()
|
||||
<< collection->source()->id()
|
||||
<< collection->source()->nodeId()
|
||||
<< amount << order;*/
|
||||
|
||||
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection );
|
||||
cmd->setLimit( amount );
|
||||
cmd->setSortOrder( order );
|
||||
@@ -104,7 +95,7 @@ AlbumModel::addFilteredCollection( const collection_ptr& collection, unsigned in
|
||||
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
|
||||
|
||||
if ( !collection.isNull() )
|
||||
setTitle( tr( "All albums from %1" ).arg( collection->source()->friendlyName() ) );
|
||||
setTitle( tr( "All albums from %1" ).arg( collection->prettyName() ) );
|
||||
else
|
||||
setTitle( tr( "All albums" ) );
|
||||
|
||||
|
@@ -221,10 +221,6 @@ TreeModel::addTracks( const album_ptr& album, const QModelIndex& parent )
|
||||
void
|
||||
TreeModel::addCollection( const collection_ptr& collection )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << collection->name()
|
||||
<< collection->source()->id()
|
||||
<< collection->source()->nodeId();
|
||||
|
||||
startLoading();
|
||||
|
||||
m_collection = collection;
|
||||
|
@@ -238,8 +238,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()->source()->isLocal() ) &&
|
||||
!ti->result()->resolvedByCollection().isNull() && ti->result()->resolvedByCollection()->source()->isLocal() )
|
||||
if ( ( item->result()->resolvedByCollection().isNull() || !item->result()->resolvedByCollection()->isLocal() ) &&
|
||||
!ti->result()->resolvedByCollection().isNull() && ti->result()->resolvedByCollection()->isLocal() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@@ -44,6 +44,7 @@ ScriptCollection::ScriptCollection( const scriptobject_ptr& scriptObject,
|
||||
, ScriptPlugin( scriptObject )
|
||||
, m_scriptAccount( scriptAccount )
|
||||
, m_trackCount( -1 ) //null value
|
||||
, m_isOnline( true )
|
||||
{
|
||||
Q_ASSERT( scriptAccount );
|
||||
qDebug() << Q_FUNC_INFO << scriptAccount->name() << Collection::name();
|
||||
@@ -87,6 +88,31 @@ ScriptCollection::itemName() const
|
||||
}
|
||||
|
||||
|
||||
bool ScriptCollection::isOnline() const
|
||||
{
|
||||
return m_isOnline;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCollection::setOnline( bool isOnline )
|
||||
{
|
||||
m_isOnline = isOnline;
|
||||
|
||||
if ( isOnline )
|
||||
{
|
||||
emit online();
|
||||
}
|
||||
else
|
||||
{
|
||||
emit offline();
|
||||
}
|
||||
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCollection::setIcon( const QPixmap& icon )
|
||||
{
|
||||
|
@@ -55,6 +55,8 @@ public:
|
||||
virtual ~ScriptCollection();
|
||||
|
||||
ScriptAccount* scriptAccount() const;
|
||||
bool isOnline() const override;
|
||||
void setOnline( bool isOnline );
|
||||
|
||||
/**
|
||||
* @brief setServiceName sets the name of the service that provides the ScriptCollection.
|
||||
@@ -98,6 +100,7 @@ private:
|
||||
QString m_description;
|
||||
int m_trackCount;
|
||||
QPixmap m_icon;
|
||||
bool m_isOnline;
|
||||
};
|
||||
|
||||
} //ns
|
||||
|
@@ -27,11 +27,13 @@ void ScriptCollectionFactory::addPlugin( const QSharedPointer<ScriptCollection>&
|
||||
// FIXME: no need for the same javascript call, already done in createPlugin
|
||||
collection->parseMetaData();
|
||||
|
||||
collection->setOnline( true );
|
||||
SourceList::instance()->addScriptCollection( collection );
|
||||
}
|
||||
|
||||
void ScriptCollectionFactory::removePlugin( const QSharedPointer<ScriptCollection>& collection ) const
|
||||
{
|
||||
collection->setOnline( false );
|
||||
SourceList::instance()->removeScriptCollection( collection );
|
||||
}
|
||||
|
||||
|
@@ -409,7 +409,7 @@ CollectionViewPage::onCollectionChanged()
|
||||
flatModel->appendTracks( m_collection );
|
||||
albumModel->appendAlbums( m_collection );
|
||||
|
||||
if ( m_collection && m_collection->source() && m_collection->source()->isLocal() )
|
||||
if ( m_collection && m_collection->isLocal() )
|
||||
{
|
||||
setEmptyTip( tr( "After you have scanned your music collection you will find your tracks right here." ) );
|
||||
}
|
||||
|
Reference in New Issue
Block a user