From 8b09d19341c081af6ed5ebc1ffc47b5b58f9a7a3 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 3 Sep 2013 22:00:51 +0200 Subject: [PATCH] * New SipPlugin::addContact() api. You can specify whether this is an invitation or a simple contact addition. --- src/accounts/google/GoogleWrapper.cpp | 40 +++++++++++++-------------- src/accounts/hatchet/sip/HatchetSip.h | 2 +- src/accounts/twitter/sip/TwitterSip.h | 5 +++- src/accounts/xmpp/sip/XmppSip.cpp | 20 ++++++++++---- src/accounts/xmpp/sip/XmppSip.h | 2 +- src/libtomahawk/sip/SipPlugin.h | 6 ++-- 6 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/accounts/google/GoogleWrapper.cpp b/src/accounts/google/GoogleWrapper.cpp index ae0d1c222..bbee72154 100644 --- a/src/accounts/google/GoogleWrapper.cpp +++ b/src/accounts/google/GoogleWrapper.cpp @@ -1,22 +1,22 @@ -/* - - Copyright (C) 2011 Leo Franchi - Copyright 2010-2011, Jeff Mitchell - - This program 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. - - This program 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 this program. If not, see . -*/ - +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2013, Christian Muehlhaeuser + * Copyright 2010-2011, Leo Franchi + * Copyright 2010-2011, Jeff Mitchell + * + * 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 "GoogleWrapper.h" #include "../xmpp/XmppConfigWidget.h" @@ -70,7 +70,7 @@ GoogleWrapperSip::showAddFriendDialog() return; qDebug() << "Attempting to add google contact to roster:" << id; - addContact( id ); + addContact( id, SendInvite ); } diff --git a/src/accounts/hatchet/sip/HatchetSip.h b/src/accounts/hatchet/sip/HatchetSip.h index 7ade8c967..64d3754a5 100644 --- a/src/accounts/hatchet/sip/HatchetSip.h +++ b/src/accounts/hatchet/sip/HatchetSip.h @@ -57,7 +57,7 @@ public slots: void disconnectPlugin(); void checkSettings() {} void configurationChanged() {} - void addContact( const QString &, const QString& ) {} + bool addContact( const QString&, AddContactOptions, const QString& ) { return false; } void sendMsg( const QString&, const SipInfo& ) {} void webSocketConnected(); void webSocketDisconnected(); diff --git a/src/accounts/twitter/sip/TwitterSip.h b/src/accounts/twitter/sip/TwitterSip.h index 7086cb21e..89ac5d26e 100644 --- a/src/accounts/twitter/sip/TwitterSip.h +++ b/src/accounts/twitter/sip/TwitterSip.h @@ -72,10 +72,13 @@ public slots: Q_UNUSED( msg ); } - void addContact( const QString &peerId, const QString& msg = QString() ) + bool addContact( const QString &peerId, AddContactOptions options, const QString& msg = QString() ) { Q_UNUSED( peerId ); Q_UNUSED( msg ); + Q_UNUSED( options ); + + return false; } void checkSettings(); diff --git a/src/accounts/xmpp/sip/XmppSip.cpp b/src/accounts/xmpp/sip/XmppSip.cpp index c85415efb..0d3e5a575 100644 --- a/src/accounts/xmpp/sip/XmppSip.cpp +++ b/src/accounts/xmpp/sip/XmppSip.cpp @@ -465,20 +465,28 @@ XmppSipPlugin::sendSipInfos( const Tomahawk::peerinfo_ptr& receiver, const QList } -void -XmppSipPlugin::addContact( const QString& jid, const QString& msg ) +bool +XmppSipPlugin::addContact( const QString& jid, AddContactOptions options, const QString& msg ) { // Add contact to the Tomahawk group on the roster 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 ); + + if ( options & SendInvite ) + { + emit inviteSentSuccess( jid ); + } + return true; } - else + + if ( options & SendInvite ) { emit inviteSentFailure( jid ); } + + return false; } @@ -494,7 +502,7 @@ XmppSipPlugin::showAddFriendDialog() return; qDebug() << "Attempting to add xmpp contact to roster:" << id; - addContact( id ); + addContact( id, SendInvite ); #endif } @@ -847,7 +855,7 @@ XmppSipPlugin::onSubscriptionRequestConfirmed( int result ) if ( allowSubscription == QMessageBox::Yes ) { qDebug() << Q_FUNC_INFO << jid.bare() << "accepted by user, adding to roster"; - addContact( jid, "" ); + addContact( jid ); } else { diff --git a/src/accounts/xmpp/sip/XmppSip.h b/src/accounts/xmpp/sip/XmppSip.h index 24ff380da..82da16446 100644 --- a/src/accounts/xmpp/sip/XmppSip.h +++ b/src/accounts/xmpp/sip/XmppSip.h @@ -90,7 +90,7 @@ public slots: virtual void disconnectPlugin(); virtual void checkSettings(); virtual void configurationChanged(); - virtual void addContact( const QString& peerId, const QString& msg = QString() ); + virtual bool addContact( const QString& peerId, AddContactOptions options = NoOptions, const QString& msg = QString() ); virtual void sendSipInfos( const Tomahawk::peerinfo_ptr& receiver, const QList& info ); diff --git a/src/libtomahawk/sip/SipPlugin.h b/src/libtomahawk/sip/SipPlugin.h index a11d4046d..bf7d48510 100644 --- a/src/libtomahawk/sip/SipPlugin.h +++ b/src/libtomahawk/sip/SipPlugin.h @@ -51,8 +51,10 @@ class DLLEXPORT SipPlugin : public QObject friend class Tomahawk::PeerInfo; public: + enum AddContactOptions { NoOptions = 0, SendInvite = 1 }; + SipPlugin(); - explicit SipPlugin( Tomahawk::Accounts::Account *account, QObject* parent = 0 ); + explicit SipPlugin( Tomahawk::Accounts::Account* account, QObject* parent = 0 ); virtual ~SipPlugin(); // plugin id is "pluginfactoryname_someuniqueid". get it from SipPluginFactory::generateId @@ -76,7 +78,7 @@ public slots: virtual void checkSettings() = 0; virtual void configurationChanged() = 0; - virtual void addContact( const QString& peerId, const QString& msg = QString() ) = 0; + virtual bool addContact( const QString& peerId, AddContactOptions options = NoOptions, const QString& msg = QString() ) = 0; /** * Send a list of SipInfos to all contacts.