1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 06:07:37 +02:00

* New SipPlugin::addContact() api. You can specify whether this is an invitation or a simple contact addition.

This commit is contained in:
Christian Muehlhaeuser
2013-09-03 22:00:51 +02:00
parent f4aa6291c8
commit 8b09d19341
6 changed files with 44 additions and 31 deletions

View File

@@ -1,22 +1,22 @@
/* /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
<one line to give the program's name and a brief idea of what it does.> *
Copyright (C) 2011 Leo Franchi <leo.franchi@kdab.com> * Copyright 2010-2013, Christian Muehlhaeuser <muesli@tomahawk-player.org>
Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org> * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
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 * Tomahawk is free software: you can redistribute it and/or modify
the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
(at your option) any later version. * 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 * Tomahawk is distributed in the hope that it will be useful,
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details. * 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 <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
*/ * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "GoogleWrapper.h" #include "GoogleWrapper.h"
#include "../xmpp/XmppConfigWidget.h" #include "../xmpp/XmppConfigWidget.h"
@@ -70,7 +70,7 @@ GoogleWrapperSip::showAddFriendDialog()
return; return;
qDebug() << "Attempting to add google contact to roster:" << id; qDebug() << "Attempting to add google contact to roster:" << id;
addContact( id ); addContact( id, SendInvite );
} }

View File

@@ -57,7 +57,7 @@ public slots:
void disconnectPlugin(); void disconnectPlugin();
void checkSettings() {} void checkSettings() {}
void configurationChanged() {} void configurationChanged() {}
void addContact( const QString &, const QString& ) {} bool addContact( const QString&, AddContactOptions, const QString& ) { return false; }
void sendMsg( const QString&, const SipInfo& ) {} void sendMsg( const QString&, const SipInfo& ) {}
void webSocketConnected(); void webSocketConnected();
void webSocketDisconnected(); void webSocketDisconnected();

View File

@@ -72,10 +72,13 @@ public slots:
Q_UNUSED( msg ); 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( peerId );
Q_UNUSED( msg ); Q_UNUSED( msg );
Q_UNUSED( options );
return false;
} }
void checkSettings(); void checkSettings();

View File

@@ -465,20 +465,28 @@ XmppSipPlugin::sendSipInfos( const Tomahawk::peerinfo_ptr& receiver, const QList
} }
void bool
XmppSipPlugin::addContact( const QString& jid, const QString& msg ) XmppSipPlugin::addContact( const QString& jid, AddContactOptions options, const QString& msg )
{ {
// Add contact to the Tomahawk group on the roster // Add contact to the Tomahawk group on the roster
QStringList jidParts = jid.split( '@' ); QStringList jidParts = jid.split( '@' );
if ( jidParts.count() == 2 && !jidParts[0].trimmed().isEmpty() && !jidParts[1].trimmed().isEmpty() ) if ( jidParts.count() == 2 && !jidParts[0].trimmed().isEmpty() && !jidParts[1].trimmed().isEmpty() )
{ {
m_roster->subscribe( jid, msg, jid, QStringList() << "Tomahawk" ); 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 ); emit inviteSentFailure( jid );
} }
return false;
} }
@@ -494,7 +502,7 @@ XmppSipPlugin::showAddFriendDialog()
return; return;
qDebug() << "Attempting to add xmpp contact to roster:" << id; qDebug() << "Attempting to add xmpp contact to roster:" << id;
addContact( id ); addContact( id, SendInvite );
#endif #endif
} }
@@ -847,7 +855,7 @@ XmppSipPlugin::onSubscriptionRequestConfirmed( int result )
if ( allowSubscription == QMessageBox::Yes ) if ( allowSubscription == QMessageBox::Yes )
{ {
qDebug() << Q_FUNC_INFO << jid.bare() << "accepted by user, adding to roster"; qDebug() << Q_FUNC_INFO << jid.bare() << "accepted by user, adding to roster";
addContact( jid, "" ); addContact( jid );
} }
else else
{ {

View File

@@ -90,7 +90,7 @@ public slots:
virtual void disconnectPlugin(); virtual void disconnectPlugin();
virtual void checkSettings(); virtual void checkSettings();
virtual void configurationChanged(); 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<SipInfo>& info ); virtual void sendSipInfos( const Tomahawk::peerinfo_ptr& receiver, const QList<SipInfo>& info );

View File

@@ -51,8 +51,10 @@ class DLLEXPORT SipPlugin : public QObject
friend class Tomahawk::PeerInfo; friend class Tomahawk::PeerInfo;
public: public:
enum AddContactOptions { NoOptions = 0, SendInvite = 1 };
SipPlugin(); SipPlugin();
explicit SipPlugin( Tomahawk::Accounts::Account *account, QObject* parent = 0 ); explicit SipPlugin( Tomahawk::Accounts::Account* account, QObject* parent = 0 );
virtual ~SipPlugin(); virtual ~SipPlugin();
// plugin id is "pluginfactoryname_someuniqueid". get it from SipPluginFactory::generateId // plugin id is "pluginfactoryname_someuniqueid". get it from SipPluginFactory::generateId
@@ -76,7 +78,7 @@ public slots:
virtual void checkSettings() = 0; virtual void checkSettings() = 0;
virtual void configurationChanged() = 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. * Send a list of SipInfos to all contacts.