From 0800aa6ac72585ea31fc3f7b0d0b9b0dd3f4689a Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 19 Apr 2013 22:52:12 +0200 Subject: [PATCH] Show discreet JobStatusItem for incoming tracks. --- src/libtomahawk/CMakeLists.txt | 1 + .../database/DatabaseCommand_ShareTrack.cpp | 9 +-- src/libtomahawk/jobview/InboxJobItem.cpp | 65 +++++++++++++++++++ src/libtomahawk/jobview/InboxJobItem.h | 51 +++++++++++++++ 4 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 src/libtomahawk/jobview/InboxJobItem.cpp create mode 100644 src/libtomahawk/jobview/InboxJobItem.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 37d15fe2d..6d22cab8d 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -40,6 +40,7 @@ set( libGuiSources jobview/LatchedStatusItem.cpp jobview/ErrorStatusMessage.cpp jobview/IndexingJobItem.cpp + jobview/InboxJobItem.cpp infobar/InfoBar.cpp diff --git a/src/libtomahawk/database/DatabaseCommand_ShareTrack.cpp b/src/libtomahawk/database/DatabaseCommand_ShareTrack.cpp index 291558a7d..bfed48b37 100644 --- a/src/libtomahawk/database/DatabaseCommand_ShareTrack.cpp +++ b/src/libtomahawk/database/DatabaseCommand_ShareTrack.cpp @@ -26,7 +26,7 @@ #include "playlist/InboxModel.h" #include "jobview/JobStatusView.h" #include "jobview/JobStatusModel.h" -#include "jobview/ErrorStatusMessage.h" +#include "jobview/InboxJobItem.h" DatabaseCommand_ShareTrack::DatabaseCommand_ShareTrack( QObject* parent ) : DatabaseCommand_SocialAction( parent ) @@ -106,12 +106,9 @@ DatabaseCommand_ShareTrack::postCommitHook() Q_ARG( const Tomahawk::query_ptr&, m_query ), Q_ARG( int, 0 ) /*row*/ ); - //TODO: replace with a proper JobStatusItem + QString friendlyName = source()->friendlyName(); if( ViewManager::instance()->currentPage() != ViewManager::instance()->inboxWidget() ) - JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "%1 recommended %2 by %3" ) - .arg( source()->friendlyName() ) - .arg( m_query->track() ) - .arg( m_query->artist() ) ) ); + JobStatusView::instance()->model()->addJob( new InboxJobItem( friendlyName, m_query ) ); } diff --git a/src/libtomahawk/jobview/InboxJobItem.cpp b/src/libtomahawk/jobview/InboxJobItem.cpp new file mode 100644 index 000000000..6fcccf893 --- /dev/null +++ b/src/libtomahawk/jobview/InboxJobItem.cpp @@ -0,0 +1,65 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Leo Franchi + * Copyright 2012, Jeff Mitchell + * Copyright 2013, Teo Mrnjavac + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "InboxJobItem.h" + +#include "Query.h" +#include "utils/TomahawkUtilsGui.h" +#include "utils/Logger.h" +#include "audio/AudioEngine.h" + +#include + + +InboxJobItem::InboxJobItem( const QString& sender, + const Tomahawk::query_ptr& query, + QObject* parent ) + : JobStatusItem() + , m_query( query ) + , m_sender( sender ) +{ + m_timer = new QTimer( this ); + m_timer->setInterval( 8000 ); + m_timer->setSingleShot( true ); + + connect( m_timer, SIGNAL( timeout() ), this, SIGNAL( finished() ) ); + m_timer->start(); +} + + +InboxJobItem::~InboxJobItem() +{} + + +QString +InboxJobItem::mainText() const +{ + return tr( "%1 sent you %2 by %3." ) + .arg( m_sender ) + .arg( m_query->track() ) + .arg( m_query->artist() ); +} + + +QPixmap +InboxJobItem::icon() const +{ + return TomahawkUtils::defaultPixmap( TomahawkUtils::Inbox, TomahawkUtils::Original, QSize( 64, 64 ) ); +} diff --git a/src/libtomahawk/jobview/InboxJobItem.h b/src/libtomahawk/jobview/InboxJobItem.h new file mode 100644 index 000000000..7667bd976 --- /dev/null +++ b/src/libtomahawk/jobview/InboxJobItem.h @@ -0,0 +1,51 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Leo Franchi + * Copyright 2012, Jeff Mitchell + * Copyright 2013, Teo Mrnjavac + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef INBOXJOBITEM_H +#define INBOXJOBITEM_H + +#include "DllMacro.h" +#include "jobview/JobStatusView.h" +#include "jobview/JobStatusItem.h" + + +class DLLEXPORT InboxJobItem : public JobStatusItem +{ + Q_OBJECT +public: + explicit InboxJobItem( const QString& sender, const Tomahawk::query_ptr& query, QObject* parent = 0 ); + virtual ~InboxJobItem(); + + virtual QString rightColumnText() const { return QString(); } + virtual QString mainText() const; + virtual QPixmap icon() const; + virtual QString type() const { return "inboxjob"; } + + bool allowMultiLine() const { return true; } + +private: + Tomahawk::query_ptr m_query; + QString m_sender; + + QTimer* m_timer; + static QPixmap* s_pixmap; +}; + +#endif // INBOXJOBITEM_H