From 1b743b0e9d3539c93d84e436b1e0688d21ece54b Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Thu, 7 Jun 2012 09:16:37 +0200 Subject: [PATCH] * Let local source know when we go off- / online. --- src/libtomahawk/Source.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/libtomahawk/Source.cpp b/src/libtomahawk/Source.cpp index 9f98d4b02..26e15dd40 100644 --- a/src/libtomahawk/Source.cpp +++ b/src/libtomahawk/Source.cpp @@ -23,6 +23,7 @@ #include "SourceList.h" #include "SourcePlaylistInterface.h" +#include "accounts/AccountManager.h" #include "network/ControlConnection.h" #include "database/DatabaseCommand_AddSource.h" #include "database/DatabaseCommand_CollectionStats.h" @@ -65,6 +66,12 @@ Source::Source( int id, const QString& username ) m_currentTrackTimer.setSingleShot( true ); connect( &m_currentTrackTimer, SIGNAL( timeout() ), this, SLOT( trackTimerFired() ) ); + + if ( m_isLocal ) + { + connect( Accounts::AccountManager::instance(), SIGNAL( connected( Tomahawk::Accounts::Account* ) ), SLOT( setOnline() ) ); + connect( Accounts::AccountManager::instance(), SIGNAL( disconnected( Tomahawk::Accounts::Account* ) ), SLOT( setOffline() ) ); + } } @@ -228,12 +235,15 @@ Source::setOffline() m_online = false; emit offline(); - m_currentTrack.clear(); - emit stateChanged(); + if ( !isLocal() ) + { + m_currentTrack.clear(); + emit stateChanged(); - m_cc = 0; - DatabaseCommand_SourceOffline* cmd = new DatabaseCommand_SourceOffline( id() ); - Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); + m_cc = 0; + DatabaseCommand_SourceOffline* cmd = new DatabaseCommand_SourceOffline( id() ); + Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); + } } @@ -247,11 +257,14 @@ Source::setOnline() m_online = true; emit online(); - // ensure username is in the database - DatabaseCommand_addSource* cmd = new DatabaseCommand_addSource( m_username, friendlyName() ); - connect( cmd, SIGNAL( done( unsigned int, QString ) ), - SLOT( dbLoaded( unsigned int, const QString& ) ) ); - Database::instance()->enqueue( QSharedPointer(cmd) ); + if ( !isLocal() ) + { + // ensure username is in the database + DatabaseCommand_addSource* cmd = new DatabaseCommand_addSource( m_username, friendlyName() ); + connect( cmd, SIGNAL( done( unsigned int, QString ) ), + SLOT( dbLoaded( unsigned int, const QString& ) ) ); + Database::instance()->enqueue( QSharedPointer(cmd) ); + } }