1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 08:19:42 +01: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
Source::addCollection( const collection_ptr& c )
{
@ -228,7 +242,7 @@ Source::setOnline()
if ( !isLocal() )
{
// 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 ) ),
SLOT( dbLoaded( unsigned int, const QString& ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
@ -240,7 +254,7 @@ void
Source::dbLoaded( unsigned int id, const QString& fname )
{
m_id = id;
setFriendlyName( fname );
setDbFriendlyName( fname );
emit syncedWithDatabase();
}

View File

@ -62,9 +62,17 @@ public:
bool isOnline() const { return m_online || m_isLocal; }
QString nodeId() const { return m_nodeId; }
QString friendlyName() const;
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
QPixmap avatar( TomahawkUtils::ImageMode style = TomahawkUtils::Original, const QSize& size = QSize() );
#endif
@ -144,6 +152,7 @@ private:
bool m_online;
QString m_nodeId;
QString m_friendlyname;
QString m_dbFriendlyName;
int m_id;
bool m_scrubFriendlyName;
bool m_updateIndexWhenSynced;

View File

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

View File

@ -40,7 +40,7 @@ DatabaseCommand_LoadAllSources::exec( DatabaseImpl* dbi )
while ( query.next() )
{
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;
}