From ad68b7fb04d790f31346904f00211542a2e8ce36 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Sat, 15 Jun 2013 22:02:16 +0200 Subject: [PATCH] Pimple SipStatusMessage --- src/libtomahawk/sip/SipStatusMessage.cpp | 39 ++++++++++------- src/libtomahawk/sip/SipStatusMessage.h | 13 ++---- src/libtomahawk/sip/SipStatusMessage_p.h | 54 ++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 25 deletions(-) create mode 100644 src/libtomahawk/sip/SipStatusMessage_p.h diff --git a/src/libtomahawk/sip/SipStatusMessage.cpp b/src/libtomahawk/sip/SipStatusMessage.cpp index bf7588c66..7ddbd7c97 100644 --- a/src/libtomahawk/sip/SipStatusMessage.cpp +++ b/src/libtomahawk/sip/SipStatusMessage.cpp @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2013, Dominik Schmidt + * Copyright 2013, Uwe L. Korn * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,30 +17,32 @@ * along with Tomahawk. If not, see . */ -#include "SipStatusMessage.h" +#include "SipStatusMessage_p.h" #include "utils/TomahawkUtilsGui.h" #include "utils/Logger.h" #include #include +QHash< SipStatusMessage::SipStatusMessageType, QPixmap > SipStatusMessagePrivate::s_typesPixmaps = QHash< SipStatusMessage::SipStatusMessageType, QPixmap >(); + SipStatusMessage::SipStatusMessage( SipStatusMessageType statusMessageType, const QString& contactId, const QString& message ) - : m_contactId( contactId ) - , m_statusMessageType( statusMessageType ) - , m_message( message ) + : d_ptr( new SipStatusMessagePrivate( this, statusMessageType, contactId, message ) ) { + Q_D( SipStatusMessage ); + // make this temporary for now, as soon as i know how: add ack button - m_timer = new QTimer( this ); - m_timer->setInterval( 8 * 1000 ); - m_timer->setSingleShot( true ); + d->timer = new QTimer( this ); + d->timer->setInterval( 8 * 1000 ); + d->timer->setSingleShot( true ); - connect( m_timer, SIGNAL( timeout() ), this, SIGNAL( finished() ) ); - m_timer->start(); + connect( d->timer, SIGNAL( timeout() ), this, SIGNAL( finished() ) ); + d->timer->start(); - if( s_typesPixmaps.value( m_statusMessageType ).isNull() ) + if( SipStatusMessagePrivate::s_typesPixmaps.value( d->statusMessageType ).isNull() ) { TomahawkUtils::ImageType imageType; - switch( m_statusMessageType ) + switch( d->statusMessageType ) { case SipLoginFailure: case SipInviteFailure: @@ -51,7 +54,7 @@ SipStatusMessage::SipStatusMessage( SipStatusMessageType statusMessageType, cons default: imageType = TomahawkUtils::AddContact; } - s_typesPixmaps.insert( m_statusMessageType, TomahawkUtils::defaultPixmap( imageType, TomahawkUtils::Original, QSize( 64, 64 ) ) ); + SipStatusMessagePrivate::s_typesPixmaps.insert( d->statusMessageType, TomahawkUtils::defaultPixmap( imageType, TomahawkUtils::Original, QSize( 64, 64 ) ) ); } } @@ -59,15 +62,19 @@ SipStatusMessage::SipStatusMessage( SipStatusMessageType statusMessageType, cons QPixmap SipStatusMessage::icon() const { - return s_typesPixmaps.value( m_statusMessageType ); + Q_D( const SipStatusMessage ); + + return SipStatusMessagePrivate::s_typesPixmaps.value( d->statusMessageType ); } QString SipStatusMessage::mainText() const { + Q_D( const SipStatusMessage ); + QString text; - switch( m_statusMessageType ) + switch( d->statusMessageType ) { case SipInviteFailure: text = "Could not invite %1. Please check his/her id!"; @@ -94,9 +101,9 @@ SipStatusMessage::mainText() const Q_ASSERT(false); } - text = text.arg( m_contactId ); + text = text.arg( d->contactId ); if(text.contains( "%2") ) - text = text.arg( m_message ); + text = text.arg( d->message ); return text; } diff --git a/src/libtomahawk/sip/SipStatusMessage.h b/src/libtomahawk/sip/SipStatusMessage.h index 5a34cdd2a..f248875a9 100644 --- a/src/libtomahawk/sip/SipStatusMessage.h +++ b/src/libtomahawk/sip/SipStatusMessage.h @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2013, Dominik Schmidt + * Copyright 2013, Uwe L. Korn * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,9 +24,8 @@ #include "DllMacro.h" #include -#include -class QTimer; +class SipStatusMessagePrivate; class DLLEXPORT SipStatusMessage : public JobStatusItem { @@ -49,13 +49,8 @@ public: bool allowMultiLine() const { return true; } private: - QString m_contactId; - SipStatusMessageType m_statusMessageType; - QString m_message; - - QHash< SipStatusMessageType, QPixmap > s_typesPixmaps; - - QTimer* m_timer; + Q_DECLARE_PRIVATE( SipStatusMessage ) + SipStatusMessagePrivate* d_ptr; }; #endif // SIPSTATUSMESSAGE_H diff --git a/src/libtomahawk/sip/SipStatusMessage_p.h b/src/libtomahawk/sip/SipStatusMessage_p.h new file mode 100644 index 000000000..033eaaaaf --- /dev/null +++ b/src/libtomahawk/sip/SipStatusMessage_p.h @@ -0,0 +1,54 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Dominik Schmidt + * Copyright 2013, Uwe L. Korn + * + * 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 SIPSTATUSMESSAGE_P_H +#define SIPSTATUSMESSAGE_P_H + +#include "SipStatusMessage.h" + +#include + +class QTimer; + +class SipStatusMessagePrivate +{ +public: + SipStatusMessagePrivate( SipStatusMessage* q, SipStatusMessage::SipStatusMessageType _statusMessageType, const QString& _contactId, const QString& _message ) + : q_ptr ( q ) + , contactId( _contactId ) + , statusMessageType( _statusMessageType ) + , message( _message ) + + { + } + SipStatusMessage* q_ptr; + Q_DECLARE_PUBLIC ( SipStatusMessage ) + +private: + QString contactId; + SipStatusMessage::SipStatusMessageType statusMessageType; + QString message; + + static QHash< SipStatusMessage::SipStatusMessageType, QPixmap > s_typesPixmaps; + + QTimer* timer; +}; + + +#endif // SIPSTATUSMESSAGE_P_H