PageRenderTime 34ms CodeModel.GetById 20ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/src/libtomahawk/jobview/LatchedStatusItem.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 120 lines | 84 code | 19 blank | 17 comment | 10 complexity | 10452f85b032b7226c9acd91ca0932d0 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  4 *
  5 *   Tomahawk is free software: you can redistribute it and/or modify
  6 *   it under the terms of the GNU General Public License as published by
  7 *   the Free Software Foundation, either version 3 of the License, or
  8 *   (at your option) any later version.
  9 *
 10 *   Tomahawk is distributed in the hope that it will be useful,
 11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 13 *   GNU General Public License for more details.
 14 *
 15 *   You should have received a copy of the GNU General Public License
 16 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 17 */
 18
 19#include "LatchedStatusItem.h"
 20
 21#include "Source.h"
 22#include "SourceList.h"
 23#include "JobStatusView.h"
 24#include "JobStatusModel.h"
 25#include "utils/TomahawkUtilsGui.h"
 26
 27LatchedStatusItem::LatchedStatusItem( const Tomahawk::source_ptr& from, const Tomahawk::source_ptr& to, LatchedStatusManager* parent )
 28    : JobStatusItem()
 29    , m_from( from )
 30    , m_to( to )
 31    , m_parent( parent )
 32{
 33    m_text = tr( "%1 is listening along with you!" ).arg( from->friendlyName() );
 34}
 35
 36LatchedStatusItem::~LatchedStatusItem()
 37{
 38}
 39
 40QPixmap
 41LatchedStatusItem::icon() const
 42{
 43    return m_parent->pixmap();
 44}
 45
 46QString
 47LatchedStatusItem::mainText() const
 48{
 49    return m_text;
 50}
 51
 52QString
 53LatchedStatusItem::type() const
 54{
 55    return "latched";
 56}
 57
 58void LatchedStatusItem::stop()
 59{
 60    emit finished();
 61}
 62
 63LatchedStatusManager::LatchedStatusManager( QObject* parent )
 64    : QObject( parent )
 65{
 66    connect( SourceList::instance(), SIGNAL( sourceLatchedOn( Tomahawk::source_ptr, Tomahawk::source_ptr ) ), this, SLOT( latchedOn( Tomahawk::source_ptr, Tomahawk::source_ptr ) ) );
 67    connect( SourceList::instance(), SIGNAL( sourceLatchedOff( Tomahawk::source_ptr, Tomahawk::source_ptr ) ), this, SLOT( latchedOff( Tomahawk::source_ptr, Tomahawk::source_ptr ) ) );
 68}
 69
 70void
 71LatchedStatusManager::latchedOn( const Tomahawk::source_ptr& from, const Tomahawk::source_ptr& to )
 72{
 73    if ( from.isNull() || to.isNull() )
 74        return;
 75
 76    if ( to->isLocal() )
 77    {
 78        LatchedStatusItem* item = new LatchedStatusItem( from, to, this );
 79        m_jobs[ from->nodeId() ] = item;
 80        JobStatusView::instance()->model()->addJob( item );
 81
 82        connect( from.data(), SIGNAL( offline() ), this, SLOT( sourceOffline() ), Qt::UniqueConnection );
 83    }
 84}
 85
 86void
 87LatchedStatusManager::sourceOffline()
 88{
 89    Tomahawk::Source* s = qobject_cast< Tomahawk::Source* >( sender() );
 90    Q_ASSERT( s );
 91
 92    if ( m_jobs.contains( s->nodeId() ) )
 93    {
 94        QPointer< LatchedStatusItem> job = m_jobs.take( s->nodeId() ).data();
 95        if ( !job.isNull() )
 96            job.data()->stop();
 97    }
 98}
 99
100
101void
102LatchedStatusManager::latchedOff( const Tomahawk::source_ptr& from, const Tomahawk::source_ptr& to )
103{
104    if ( from.isNull() || to.isNull() )
105        return;
106
107    if ( to->isLocal() && m_jobs.contains( from->nodeId() ) )
108    {
109        QPointer< LatchedStatusItem > item = m_jobs.take( from->nodeId() );
110        if ( !item.isNull() )
111            item.data()->stop();
112    }
113}
114
115
116QPixmap
117LatchedStatusManager::pixmap() const
118{
119    return TomahawkUtils::defaultPixmap( TomahawkUtils::HeadphonesOn, TomahawkUtils::Original, QSize( 128, 128 ) );
120}