1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-01 03:40:16 +02:00

Pimple SipStatusMessage

This commit is contained in:
Uwe L. Korn
2013-06-15 22:02:16 +02:00
parent eeab7332ad
commit ad68b7fb04
3 changed files with 81 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2013, Dominik Schmidt <domme@tomahawk-player.org> * Copyright 2013, Dominik Schmidt <domme@tomahawk-player.org>
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,30 +17,32 @@
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "SipStatusMessage.h" #include "SipStatusMessage_p.h"
#include "utils/TomahawkUtilsGui.h" #include "utils/TomahawkUtilsGui.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include <QHash> #include <QHash>
#include <QTimer> #include <QTimer>
QHash< SipStatusMessage::SipStatusMessageType, QPixmap > SipStatusMessagePrivate::s_typesPixmaps = QHash< SipStatusMessage::SipStatusMessageType, QPixmap >();
SipStatusMessage::SipStatusMessage( SipStatusMessageType statusMessageType, const QString& contactId, const QString& message ) SipStatusMessage::SipStatusMessage( SipStatusMessageType statusMessageType, const QString& contactId, const QString& message )
: m_contactId( contactId ) : d_ptr( new SipStatusMessagePrivate( this, statusMessageType, contactId, message ) )
, m_statusMessageType( statusMessageType )
, m_message( message )
{ {
Q_D( SipStatusMessage );
// make this temporary for now, as soon as i know how: add ack button // make this temporary for now, as soon as i know how: add ack button
m_timer = new QTimer( this ); d->timer = new QTimer( this );
m_timer->setInterval( 8 * 1000 ); d->timer->setInterval( 8 * 1000 );
m_timer->setSingleShot( true ); d->timer->setSingleShot( true );
connect( m_timer, SIGNAL( timeout() ), this, SIGNAL( finished() ) ); connect( d->timer, SIGNAL( timeout() ), this, SIGNAL( finished() ) );
m_timer->start(); d->timer->start();
if( s_typesPixmaps.value( m_statusMessageType ).isNull() ) if( SipStatusMessagePrivate::s_typesPixmaps.value( d->statusMessageType ).isNull() )
{ {
TomahawkUtils::ImageType imageType; TomahawkUtils::ImageType imageType;
switch( m_statusMessageType ) switch( d->statusMessageType )
{ {
case SipLoginFailure: case SipLoginFailure:
case SipInviteFailure: case SipInviteFailure:
@@ -51,7 +54,7 @@ SipStatusMessage::SipStatusMessage( SipStatusMessageType statusMessageType, cons
default: default:
imageType = TomahawkUtils::AddContact; 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 QPixmap
SipStatusMessage::icon() const SipStatusMessage::icon() const
{ {
return s_typesPixmaps.value( m_statusMessageType ); Q_D( const SipStatusMessage );
return SipStatusMessagePrivate::s_typesPixmaps.value( d->statusMessageType );
} }
QString QString
SipStatusMessage::mainText() const SipStatusMessage::mainText() const
{ {
Q_D( const SipStatusMessage );
QString text; QString text;
switch( m_statusMessageType ) switch( d->statusMessageType )
{ {
case SipInviteFailure: case SipInviteFailure:
text = "Could not invite %1. Please check his/her id!"; text = "Could not invite %1. Please check his/her id!";
@@ -94,9 +101,9 @@ SipStatusMessage::mainText() const
Q_ASSERT(false); Q_ASSERT(false);
} }
text = text.arg( m_contactId ); text = text.arg( d->contactId );
if(text.contains( "%2") ) if(text.contains( "%2") )
text = text.arg( m_message ); text = text.arg( d->message );
return text; return text;
} }

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2013, Dominik Schmidt <domme@tomahawk-player.org> * Copyright 2013, Dominik Schmidt <domme@tomahawk-player.org>
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -23,9 +24,8 @@
#include "DllMacro.h" #include "DllMacro.h"
#include <QPixmap> #include <QPixmap>
#include <QHash>
class QTimer; class SipStatusMessagePrivate;
class DLLEXPORT SipStatusMessage : public JobStatusItem class DLLEXPORT SipStatusMessage : public JobStatusItem
{ {
@@ -49,13 +49,8 @@ public:
bool allowMultiLine() const { return true; } bool allowMultiLine() const { return true; }
private: private:
QString m_contactId; Q_DECLARE_PRIVATE( SipStatusMessage )
SipStatusMessageType m_statusMessageType; SipStatusMessagePrivate* d_ptr;
QString m_message;
QHash< SipStatusMessageType, QPixmap > s_typesPixmaps;
QTimer* m_timer;
}; };
#endif // SIPSTATUSMESSAGE_H #endif // SIPSTATUSMESSAGE_H

View File

@@ -0,0 +1,54 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Dominik Schmidt <domme@tomahawk-player.org>
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef SIPSTATUSMESSAGE_P_H
#define SIPSTATUSMESSAGE_P_H
#include "SipStatusMessage.h"
#include <QHash>
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