1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 21:57:41 +02:00

Add dbFriendlyName to Source as fallback if the normal friendlyname is not available

This commit is contained in:
Dominik Schmidt
2013-01-28 00:50:24 +01:00
parent 78c2a2e733
commit 76b21e3742
4 changed files with 28 additions and 5 deletions

View File

@@ -175,6 +175,20 @@ Source::setFriendlyName( const QString& fname )
} }
QString
Source::dbFriendlyName() const
{
return m_dbFriendlyName;
}
void
Source::setDbFriendlyName( const QString& dbFriendlyName )
{
m_dbFriendlyName = dbFriendlyName;
}
void void
Source::addCollection( const collection_ptr& c ) Source::addCollection( const collection_ptr& c )
{ {
@@ -228,7 +242,7 @@ Source::setOnline()
if ( !isLocal() ) if ( !isLocal() )
{ {
// ensure username is in the database // ensure username is in the database
DatabaseCommand_addSource* cmd = new DatabaseCommand_addSource( m_nodeId, friendlyName() ); DatabaseCommand_addSource* cmd = new DatabaseCommand_addSource( m_nodeId, dbFriendlyName() );
connect( cmd, SIGNAL( done( unsigned int, QString ) ), connect( cmd, SIGNAL( done( unsigned int, QString ) ),
SLOT( dbLoaded( unsigned int, const QString& ) ) ); SLOT( dbLoaded( unsigned int, const QString& ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
@@ -240,7 +254,7 @@ void
Source::dbLoaded( unsigned int id, const QString& fname ) Source::dbLoaded( unsigned int id, const QString& fname )
{ {
m_id = id; m_id = id;
setFriendlyName( fname ); setDbFriendlyName( fname );
emit syncedWithDatabase(); emit syncedWithDatabase();
} }

View File

@@ -62,9 +62,17 @@ public:
bool isOnline() const { return m_online || m_isLocal; } bool isOnline() const { return m_online || m_isLocal; }
QString nodeId() const { return m_nodeId; } QString nodeId() const { return m_nodeId; }
QString friendlyName() const; QString friendlyName() const;
void setFriendlyName( const QString& fname ); void setFriendlyName( const QString& fname );
// fallback when the normal friendlyname from cache is not available
// this is usually the jabber id or whatever was used when first connected
QString dbFriendlyName() const;
void setDbFriendlyName( const QString& dbFriendlyName );
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS
QPixmap avatar( TomahawkUtils::ImageMode style = TomahawkUtils::Original, const QSize& size = QSize() ); QPixmap avatar( TomahawkUtils::ImageMode style = TomahawkUtils::Original, const QSize& size = QSize() );
#endif #endif
@@ -144,6 +152,7 @@ private:
bool m_online; bool m_online;
QString m_nodeId; QString m_nodeId;
QString m_friendlyname; QString m_friendlyname;
QString m_dbFriendlyName;
int m_id; int m_id;
bool m_scrubFriendlyName; bool m_scrubFriendlyName;
bool m_updateIndexWhenSynced; bool m_updateIndexWhenSynced;

View File

@@ -202,14 +202,14 @@ SourceList::get( const QString& username, const QString& friendlyName, bool auto
{ {
Q_ASSERT( !friendlyName.isEmpty() ); Q_ASSERT( !friendlyName.isEmpty() );
source = source_ptr( new Source( -1, username ) ); source = source_ptr( new Source( -1, username ) );
source->setFriendlyName( friendlyName ); source->setDbFriendlyName( friendlyName );
add( source ); add( source );
} }
} }
else else
{ {
source = m_sources.value( username ); source = m_sources.value( username );
source->setFriendlyName( friendlyName ); source->setDbFriendlyName( friendlyName );
} }
return source; return source;

View File

@@ -40,7 +40,7 @@ DatabaseCommand_LoadAllSources::exec( DatabaseImpl* dbi )
while ( query.next() ) while ( query.next() )
{ {
source_ptr src( new Source( query.value( 0 ).toUInt(), query.value( 1 ).toString() ) ); source_ptr src( new Source( query.value( 0 ).toUInt(), query.value( 1 ).toString() ) );
src->setFriendlyName( query.value( 2 ).toString() ); src->setDbFriendlyName( query.value( 2 ).toString() );
sources << src; sources << src;
} }