From d3bd359e1a297be8cb990296a60c3d3c6b3038e9 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Thu, 24 Jan 2013 02:47:43 +0100 Subject: [PATCH] Be more responsive about adding contacts --- src/accounts/xmpp/sip/XmppSip.cpp | 15 ++-- src/libtomahawk/CMakeLists.txt | 1 + src/libtomahawk/jobview/JobStatusItem.h | 2 +- src/libtomahawk/sip/SipPlugin.h | 2 + src/libtomahawk/sip/SipStatusMessage.cpp | 89 ++++++++++++++++++++++++ src/libtomahawk/sip/SipStatusMessage.h | 58 +++++++++++++++ src/widgets/AccountWidget.cpp | 20 ++++++ src/widgets/AccountWidget.h | 2 + 8 files changed, 183 insertions(+), 6 deletions(-) create mode 100644 src/libtomahawk/sip/SipStatusMessage.cpp create mode 100644 src/libtomahawk/sip/SipStatusMessage.h diff --git a/src/accounts/xmpp/sip/XmppSip.cpp b/src/accounts/xmpp/sip/XmppSip.cpp index 861a5598b..69881c7b5 100644 --- a/src/accounts/xmpp/sip/XmppSip.cpp +++ b/src/accounts/xmpp/sip/XmppSip.cpp @@ -462,11 +462,16 @@ void XmppSipPlugin::addContact( const QString& jid, const QString& msg ) { // Add contact to the Tomahawk group on the roster - QString realJid = jid; - if ( !realJid.contains( '@' ) ) - realJid += defaultSuffix(); - - m_roster->subscribe( realJid, msg, realJid, QStringList() << "Tomahawk" ); + QStringList jidParts = jid.split( '@' ); + if( jidParts.count() == 2 && !jidParts[0].trimmed().isEmpty() && !jidParts[1].trimmed().isEmpty() ) + { + m_roster->subscribe( jid, msg, jid, QStringList() << "Tomahawk" ); + emit inviteSentSuccess( jid ); + } + else + { + emit inviteSentFailure( jid ); + } } diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index fe54f76c8..086c820cf 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -210,6 +210,7 @@ list(APPEND libSources sip/SipPlugin.cpp sip/SipInfo.cpp sip/PeerInfo.cpp + sip/SipStatusMessage.cpp audio/AudioEngine.cpp diff --git a/src/libtomahawk/jobview/JobStatusItem.h b/src/libtomahawk/jobview/JobStatusItem.h index bd3041415..d03f31f05 100644 --- a/src/libtomahawk/jobview/JobStatusItem.h +++ b/src/libtomahawk/jobview/JobStatusItem.h @@ -49,7 +49,7 @@ public: /// Please cache this. virtual QPixmap icon() const = 0; virtual QString mainText() const = 0; - virtual QString rightColumnText() const = 0; + virtual QString rightColumnText() const { return QString(); }; /** * If collapse item is true, sending multiple items of the same type will "collapse" them into one diff --git a/src/libtomahawk/sip/SipPlugin.h b/src/libtomahawk/sip/SipPlugin.h index f7f179e2b..6503c282e 100644 --- a/src/libtomahawk/sip/SipPlugin.h +++ b/src/libtomahawk/sip/SipPlugin.h @@ -75,6 +75,8 @@ public slots: signals: void peerStatusChanged( const Tomahawk::peerinfo_ptr& ); void dataError( bool ); + void inviteSentSuccess( const QString& inviteId ); + void inviteSentFailure( const QString& inviteId ); #ifndef ENABLE_HEADLESS // new data for own source diff --git a/src/libtomahawk/sip/SipStatusMessage.cpp b/src/libtomahawk/sip/SipStatusMessage.cpp new file mode 100644 index 000000000..6c6861760 --- /dev/null +++ b/src/libtomahawk/sip/SipStatusMessage.cpp @@ -0,0 +1,89 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Dominik Schmidt + * + * 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 "SipStatusMessage.h" +#include "utils/TomahawkUtilsGui.h" +#include "utils/Logger.h" + +#include +#include + +SipStatusMessage::SipStatusMessage( SipStatusMessageType statusMessageType, const QString& contactId ) + : m_statusMessageType( statusMessageType ) + , m_contactId( contactId ) +{ + // 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 ); + + connect( m_timer, SIGNAL( timeout() ), this, SIGNAL( finished() ) ); + m_timer->start(); + + if( s_typesPixmaps.value( m_statusMessageType ).isNull() ) + { + TomahawkUtils::ImageType imageType; + switch( m_statusMessageType ) + { + case SipInviteFailure: + imageType = TomahawkUtils::ProcessStop; + break; + + case SipInviteSuccess: + case SipAuthReceived: + default: + imageType = TomahawkUtils::AddContact; + } + s_typesPixmaps.insert( m_statusMessageType, TomahawkUtils::defaultPixmap( imageType, TomahawkUtils::Original, QSize( 64, 64 ) ) ); + } +} + + +QPixmap +SipStatusMessage::icon() const +{ + return s_typesPixmaps.value( m_statusMessageType ); +} + + +QString +SipStatusMessage::mainText() const +{ + QString text; + switch( m_statusMessageType ) + { + case SipInviteFailure: + text = "Could not invite %1. Please check his/her id!"; + break; + + case SipInviteSuccess: + text = "Invitation sent to %1!"; + break; + + case SipAuthReceived: + text = "Received authorization from %1"; + break; + + default: + tLog() << Q_FUNC_INFO << "Not all status types handled"; + Q_ASSERT(false); + } + + return text.arg( m_contactId ); +} + diff --git a/src/libtomahawk/sip/SipStatusMessage.h b/src/libtomahawk/sip/SipStatusMessage.h new file mode 100644 index 000000000..7e0c8cb1d --- /dev/null +++ b/src/libtomahawk/sip/SipStatusMessage.h @@ -0,0 +1,58 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Dominik Schmidt + * + * 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_H +#define SIPSTATUSMESSAGE_H + +#include "jobview/JobStatusItem.h" +#include "DllMacro.h" + +#include +#include + +class QTimer; + +class DLLEXPORT SipStatusMessage : public JobStatusItem +{ + Q_OBJECT +public: + enum SipStatusMessageType + { + SipInviteSuccess, + SipInviteFailure, + SipAuthReceived + }; + + explicit SipStatusMessage( SipStatusMessageType statusMessageType, const QString& contactId ); + + QString type() const { return "sipstatusmessage"; } + + QPixmap icon() const; + QString mainText() const; + + bool allowMultiLine() const { return true; } +private: + QString m_contactId; + SipStatusMessageType m_statusMessageType; + + QHash< SipStatusMessageType, QPixmap > s_typesPixmaps; + + QTimer* m_timer; +}; + +#endif // SIPSTATUSMESSAGE_H diff --git a/src/widgets/AccountWidget.cpp b/src/widgets/AccountWidget.cpp index e20512546..8a9bfcff4 100644 --- a/src/widgets/AccountWidget.cpp +++ b/src/widgets/AccountWidget.cpp @@ -28,6 +28,10 @@ #include "utils/AnimatedSpinner.h" #include "widgets/ElidedLabel.h" +#include "jobview/JobStatusView.h" +#include "jobview/JobStatusModel.h" +#include "sip/SipStatusMessage.h" + #include #include #include @@ -264,6 +268,20 @@ AccountWidget::sendInvite() } } + +void +AccountWidget::onInviteSentSuccess( const QString& inviteId ) +{ + JobStatusView::instance()->model()->addJob( new SipStatusMessage( SipStatusMessage::SipInviteSuccess, inviteId ) ); +} + +void +AccountWidget::onInviteSentFailure( const QString& inviteId ) +{ + JobStatusView::instance()->model()->addJob( new SipStatusMessage( SipStatusMessage::SipInviteFailure, inviteId ) ); +} + + void AccountWidget::clearInviteWidgets() { @@ -297,6 +315,8 @@ AccountWidget::setupConnections( const QPersistentModelIndex& idx, int accountId this, SLOT( sendInvite() ) ); m_inviteEdit->setPlaceholderText( account->sipPlugin()->inviteString() ); + connect( account->sipPlugin(), SIGNAL( inviteSentSuccess( QString ) ), SLOT( onInviteSentSuccess( QString ) ) ); + connect( account->sipPlugin(), SIGNAL( inviteSentFailure( QString ) ), SLOT( onInviteSentFailure( QString ) ) ); } } diff --git a/src/widgets/AccountWidget.h b/src/widgets/AccountWidget.h index ce78fd492..dfcd44f15 100644 --- a/src/widgets/AccountWidget.h +++ b/src/widgets/AccountWidget.h @@ -48,6 +48,8 @@ public: private slots: void changeAccountConnectionState( bool connected ); void sendInvite(); + void onInviteSentSuccess( const QString& inviteId ); + void onInviteSentFailure( const QString& inviteId ); void clearInviteWidgets(); void setInviteWidgetsEnabled( bool enabled );