PageRenderTime 113ms CodeModel.GetById 41ms app.highlight 7ms RepoModel.GetById 43ms app.codeStats 0ms

/src/libtomahawk/utils/DropJobNotifier.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 120 lines | 75 code | 26 blank | 19 comment | 10 complexity | e390ed8b8034e2db285e7c5b14bf2633 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 *   Copyright 2010-2011, Hugo Lindström <hugolm84@gmail.com>
  5 *   Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  6 *
  7 *   Tomahawk is free software: you can redistribute it and/or modify
  8 *   it under the terms of the GNU General Public License as published by
  9 *   the Free Software Foundation, either version 3 of the License, or
 10 *   (at your option) any later version.
 11 *
 12 *   Tomahawk is distributed in the hope that it will be useful,
 13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15 *   GNU General Public License for more details.
 16 *
 17 *   You should have received a copy of the GNU General Public License
 18 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 19 */
 20
 21#include "DropJobNotifier.h"
 22
 23#include <QtNetwork/QNetworkAccessManager>
 24#include <QtNetwork/QNetworkReply>
 25
 26#include "Query.h"
 27#include "SourceList.h"
 28#include "DropJob.h"
 29#include "DropJobNotifier.h"
 30#include "jobview/JobStatusView.h"
 31#include "jobview/JobStatusModel.h"
 32#include "utils/NetworkReply.h"
 33#include "utils/TomahawkUtils.h"
 34#include "utils/Logger.h"
 35
 36using namespace Tomahawk;
 37
 38
 39DropJobNotifier::DropJobNotifier( QPixmap servicePixmap, QString service, DropJob::DropType type, NetworkReply* job )
 40    : JobStatusItem()
 41    , m_type( "unknown" )
 42    , m_job( 0 )
 43    , m_pixmap( servicePixmap )
 44    , m_service( service )
 45{
 46    init( type );
 47
 48    if ( m_service.isEmpty() )
 49        m_service = "DropJob";
 50
 51    connect( job, SIGNAL( finished() ), this, SLOT( setFinished() ) );
 52}
 53
 54
 55DropJobNotifier::DropJobNotifier( QPixmap pixmap, DropJob::DropType type )
 56    : JobStatusItem()
 57    , m_job( 0 )
 58    , m_pixmap( pixmap )
 59{
 60    init( type );
 61}
 62
 63
 64DropJobNotifier::~DropJobNotifier()
 65{
 66}
 67
 68
 69void
 70DropJobNotifier::init( DropJob::DropType type )
 71{
 72    if ( type == DropJob::Playlist )
 73        m_type = tr( "playlist" );
 74
 75    if ( type == DropJob::Artist )
 76        m_type = tr( "artist" );
 77
 78    if ( type == DropJob::Track )
 79        m_type = tr( "track" );
 80
 81    if ( type == DropJob::Album )
 82        m_type = tr( "album" );
 83}
 84
 85
 86QString
 87DropJobNotifier::rightColumnText() const
 88{
 89    return QString();
 90}
 91
 92
 93QPixmap
 94DropJobNotifier::icon() const
 95{
 96    return m_pixmap;
 97}
 98
 99
100QString
101DropJobNotifier::mainText() const
102{
103    if ( m_service.isEmpty() )
104    {
105        return tr( "Fetching %1 from database" ).arg( m_type );
106    }
107    else
108    {
109        return tr( "Parsing %1 %2" ).arg( m_service )
110                                    .arg( m_type );
111    }
112}
113
114
115void
116DropJobNotifier::setFinished()
117{
118    emit finished();
119}
120