mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 05:37:29 +02:00
More cleanup work. Also, move twitter authentication to the account, so it's centralized
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#define TOMAHAWKOAUTHTWITTERACCOUNT
|
#define TOMAHAWKOAUTHTWITTERACCOUNT
|
||||||
|
|
||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
|
#include <utils/tomahawkutils.h>
|
||||||
|
|
||||||
#include <QTweetLib/qtweetlib_global.h>
|
#include <QTweetLib/qtweetlib_global.h>
|
||||||
#include <QTweetLib/oauthtwitter.h>
|
#include <QTweetLib/oauthtwitter.h>
|
||||||
@@ -11,7 +12,7 @@ class DLLEXPORT TomahawkOAuthTwitter : public OAuthTwitter
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TomahawkOAuthTwitter( QNetworkAccessManager *nam, QObject *parent = 0 );
|
TomahawkOAuthTwitter( QNetworkAccessManager *nam = TomahawkUtils::nam() , QObject *parent = 0 );
|
||||||
|
|
||||||
~TomahawkOAuthTwitter() {}
|
~TomahawkOAuthTwitter() {}
|
||||||
|
|
||||||
|
@@ -17,11 +17,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "twitteraccount.h"
|
#include "twitteraccount.h"
|
||||||
|
|
||||||
#include "twitterconfigwidget.h"
|
#include "twitterconfigwidget.h"
|
||||||
|
#include "accounts/twitter/tomahawkoauthtwitter.h"
|
||||||
|
|
||||||
#include "sip/SipPlugin.h"
|
#include "sip/SipPlugin.h"
|
||||||
|
|
||||||
|
#include <QTweetLib/qtweetaccountverifycredentials.h>
|
||||||
|
#include <QTweetLib/qtweetuser.h>
|
||||||
|
#include <QTweetLib/qtweetstatus.h>
|
||||||
|
#include <QTweetLib/qtweetusershow.h>
|
||||||
|
|
||||||
#include <QtCore/QtPlugin>
|
#include <QtCore/QtPlugin>
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
@@ -50,6 +55,8 @@ TwitterAccount::TwitterAccount( const QString &accountId )
|
|||||||
|
|
||||||
m_configWidget = QWeakPointer< TwitterConfigWidget >( new TwitterConfigWidget( this, 0 ) );
|
m_configWidget = QWeakPointer< TwitterConfigWidget >( new TwitterConfigWidget( this, 0 ) );
|
||||||
connect( m_configWidget.data(), SIGNAL( twitterAuthed( bool ) ), SLOT( configDialogAuthedSignalSlot( bool ) ) );
|
connect( m_configWidget.data(), SIGNAL( twitterAuthed( bool ) ), SLOT( configDialogAuthedSignalSlot( bool ) ) );
|
||||||
|
|
||||||
|
m_twitterAuth = QWeakPointer< TomahawkOAuthTwitter >( new TomahawkOAuthTwitter( TomahawkUtils::nam(), this ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -83,6 +90,86 @@ TwitterAccount::sipPlugin()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TwitterAccount::authenticate()
|
||||||
|
{
|
||||||
|
tDebug() << Q_FUNC_INFO << "credentials: " << m_credentials.keys();
|
||||||
|
|
||||||
|
if ( m_credentials[ "oauthtoken" ].toString().isEmpty() || m_credentials[ "oauthtokensecret" ].toString().isEmpty() )
|
||||||
|
{
|
||||||
|
qDebug() << "TwitterSipPlugin has empty Twitter credentials; not connecting";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( refreshTwitterAuth() )
|
||||||
|
{
|
||||||
|
QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( m_twitterAuth.data(), this );
|
||||||
|
connect( credVerifier, SIGNAL( parsedUser( const QTweetUser & ) ), SLOT( connectAuthVerifyReply( const QTweetUser & ) ) );
|
||||||
|
credVerifier->verify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TwitterAccount::deauthenticate()
|
||||||
|
{
|
||||||
|
if ( sipPlugin() )
|
||||||
|
sipPlugin()->disconnectPlugin();
|
||||||
|
|
||||||
|
m_isAuthenticated = false;
|
||||||
|
emit nowDeauthenticated();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
TwitterAccount::refreshTwitterAuth()
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << " begin";
|
||||||
|
if( !m_twitterAuth.isNull() )
|
||||||
|
delete m_twitterAuth.data();
|
||||||
|
|
||||||
|
Q_ASSERT( TomahawkUtils::nam() != 0 );
|
||||||
|
qDebug() << Q_FUNC_INFO << " with nam " << TomahawkUtils::nam();
|
||||||
|
m_twitterAuth = QWeakPointer< TomahawkOAuthTwitter >( new TomahawkOAuthTwitter( TomahawkUtils::nam(), this ) );
|
||||||
|
|
||||||
|
if( m_twitterAuth.isNull() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_twitterAuth.data()->setOAuthToken( m_credentials[ "oauthtoken" ].toString().toLatin1() );
|
||||||
|
m_twitterAuth.data()->setOAuthTokenSecret( m_credentials[ "oauthtokensecret" ].toString().toLatin1() );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TwitterAccount::connectAuthVerifyReply( const QTweetUser &user )
|
||||||
|
{
|
||||||
|
if ( user.id() == 0 )
|
||||||
|
{
|
||||||
|
qDebug() << "TwitterAccount could not authenticate to Twitter";
|
||||||
|
deauthenticate();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tDebug() << "TwitterAccount successfully authenticated to Twitter as user " << user.screenName();
|
||||||
|
m_configuration[ "screenname" ] = user.screenName();
|
||||||
|
sync();
|
||||||
|
emit nowAuthenticated( m_twitterAuth, user );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TwitterAccount::refreshProxy()
|
||||||
|
{
|
||||||
|
//FIXME: Could this cause a race condition if a client is threaded?
|
||||||
|
if ( !m_twitterAuth.isNull() )
|
||||||
|
m_twitterAuth.data()->setNetworkAccessManager( TomahawkUtils::nam() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -60,8 +60,9 @@ public:
|
|||||||
|
|
||||||
QIcon icon() const { return QIcon( ":/twitter-icon.png" ); }
|
QIcon icon() const { return QIcon( ":/twitter-icon.png" ); }
|
||||||
|
|
||||||
bool canSelfAuthenticate() const { return false; }
|
bool canSelfAuthenticate() const { return true; }
|
||||||
bool authenticate() { return false; }
|
void authenticate();
|
||||||
|
void deauthenticate();
|
||||||
bool isAuthenticated() const { return m_isAuthenticated; }
|
bool isAuthenticated() const { return m_isAuthenticated; }
|
||||||
|
|
||||||
Tomahawk::InfoSystem::InfoPlugin* infoPlugin() { return 0; }
|
Tomahawk::InfoSystem::InfoPlugin* infoPlugin() { return 0; }
|
||||||
@@ -70,11 +71,22 @@ public:
|
|||||||
QWidget* configurationWidget() { return m_configWidget.data(); }
|
QWidget* configurationWidget() { return m_configWidget.data(); }
|
||||||
QWidget* aclWidget() { return 0; }
|
QWidget* aclWidget() { return 0; }
|
||||||
|
|
||||||
|
bool refreshTwitterAuth();
|
||||||
|
TomahawkOAuthTwitter* twitterAuth() const { return m_twitterAuth.data(); }
|
||||||
|
|
||||||
|
void refreshProxy();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void nowAuthenticated( const QWeakPointer< TomahawkOAuthTwitter >&, const QTweetUser &user );
|
||||||
|
void nowDeauthenticated();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void configDialogAuthedSignalSlot( bool authed );
|
void configDialogAuthedSignalSlot( bool authed );
|
||||||
|
void connectAuthVerifyReply( const QTweetUser &user );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_isAuthenticated;
|
bool m_isAuthenticated;
|
||||||
|
QWeakPointer< TomahawkOAuthTwitter > m_twitterAuth;
|
||||||
QWeakPointer< TwitterConfigWidget > m_configWidget;
|
QWeakPointer< TwitterConfigWidget > m_configWidget;
|
||||||
QWeakPointer< TwitterSipPlugin > m_twitterSipPlugin;
|
QWeakPointer< TwitterSipPlugin > m_twitterSipPlugin;
|
||||||
|
|
||||||
|
@@ -56,6 +56,20 @@ XmppAccount::~XmppAccount()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
XmppAccount::authenticate()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
XmppAccount::deauthenticate()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SipPlugin*
|
SipPlugin*
|
||||||
XmppAccount::sipPlugin()
|
XmppAccount::sipPlugin()
|
||||||
{
|
{
|
||||||
|
@@ -61,7 +61,8 @@ public:
|
|||||||
QIcon icon() const { return QIcon( ":/xmpp-icon.png" ); }
|
QIcon icon() const { return QIcon( ":/xmpp-icon.png" ); }
|
||||||
|
|
||||||
bool canSelfAuthenticate() const { return false; }
|
bool canSelfAuthenticate() const { return false; }
|
||||||
bool authenticate() { return false; }
|
void authenticate();
|
||||||
|
void deauthenticate();
|
||||||
bool isAuthenticated() const { return m_isAuthenticated; }
|
bool isAuthenticated() const { return m_isAuthenticated; }
|
||||||
|
|
||||||
Tomahawk::InfoSystem::InfoPlugin* infoPlugin() { return 0; }
|
Tomahawk::InfoSystem::InfoPlugin* infoPlugin() { return 0; }
|
||||||
@@ -70,6 +71,8 @@ public:
|
|||||||
QWidget* configurationWidget() { return m_configWidget.data(); }
|
QWidget* configurationWidget() { return m_configWidget.data(); }
|
||||||
QWidget* aclWidget() { return 0; }
|
QWidget* aclWidget() { return 0; }
|
||||||
|
|
||||||
|
void refreshProxy() {};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui_XmppConfigWidget* m_ui; // so the google wrapper can change the config dialog a bit
|
Ui_XmppConfigWidget* m_ui; // so the google wrapper can change the config dialog a bit
|
||||||
bool m_isAuthenticated;
|
bool m_isAuthenticated;
|
||||||
|
@@ -52,10 +52,17 @@ Account::canSelfAuthenticate() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
void
|
||||||
Account::authenticate()
|
Account::authenticate()
|
||||||
{
|
{
|
||||||
return false;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Account::deauthenticate()
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -66,6 +73,13 @@ Account::isAuthenticated() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Account::refreshProxy()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -80,7 +80,8 @@ public:
|
|||||||
virtual QIcon icon() const = 0;
|
virtual QIcon icon() const = 0;
|
||||||
|
|
||||||
virtual bool canSelfAuthenticate() const = 0;
|
virtual bool canSelfAuthenticate() const = 0;
|
||||||
virtual bool authenticate() = 0; //if none needed, just return true
|
virtual void authenticate() = 0;
|
||||||
|
virtual void deauthenticate() = 0;
|
||||||
virtual bool isAuthenticated() const = 0;
|
virtual bool isAuthenticated() const = 0;
|
||||||
|
|
||||||
virtual Tomahawk::InfoSystem::InfoPlugin* infoPlugin() = 0;
|
virtual Tomahawk::InfoSystem::InfoPlugin* infoPlugin() = 0;
|
||||||
@@ -106,11 +107,8 @@ public:
|
|||||||
virtual void setAutoConnect( bool autoConnect ) { QMutexLocker locker( &m_mutex ); m_autoConnect = autoConnect; }
|
virtual void setAutoConnect( bool autoConnect ) { QMutexLocker locker( &m_mutex ); m_autoConnect = autoConnect; }
|
||||||
virtual void setAccountId( const QString &accountId ) { QMutexLocker locker( &m_mutex ); m_accountId = accountId; }
|
virtual void setAccountId( const QString &accountId ) { QMutexLocker locker( &m_mutex ); m_accountId = accountId; }
|
||||||
virtual void setCredentials( const QVariantHash &credentialHash ) { QMutexLocker locker( &m_mutex ); m_credentials = credentialHash; }
|
virtual void setCredentials( const QVariantHash &credentialHash ) { QMutexLocker locker( &m_mutex ); m_credentials = credentialHash; }
|
||||||
|
|
||||||
virtual void setConfiguration( const QVariantHash &configuration ) { QMutexLocker locker( &m_mutex ); m_configuration = configuration; }
|
virtual void setConfiguration( const QVariantHash &configuration ) { QMutexLocker locker( &m_mutex ); m_configuration = configuration; }
|
||||||
|
|
||||||
virtual void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_acl = acl; }
|
virtual void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_acl = acl; }
|
||||||
|
|
||||||
virtual void setTypes( const QSet< AccountType > types )
|
virtual void setTypes( const QSet< AccountType > types )
|
||||||
{
|
{
|
||||||
QMutexLocker locker( &m_mutex );
|
QMutexLocker locker( &m_mutex );
|
||||||
@@ -130,10 +128,13 @@ public:
|
|||||||
syncConfig();
|
syncConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void refreshProxy() = 0;
|
||||||
|
|
||||||
virtual void sync() { QMutexLocker locker( &m_mutex ); syncConfig(); };
|
virtual void sync() { QMutexLocker locker( &m_mutex ); syncConfig(); };
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void configurationChanged();
|
void configurationChanged();
|
||||||
|
void authenticated( bool );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void loadFromConfig( const QString &accountId )
|
virtual void loadFromConfig( const QString &accountId )
|
||||||
|
@@ -60,7 +60,7 @@ public:
|
|||||||
virtual const QStringList peersOnline() const;
|
virtual const QStringList peersOnline() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual bool connectPlugin() = 0;
|
virtual void connectPlugin() = 0;
|
||||||
virtual void disconnectPlugin() = 0;
|
virtual void disconnectPlugin() = 0;
|
||||||
virtual void checkSettings() = 0;
|
virtual void checkSettings() = 0;
|
||||||
virtual void configurationChanged() = 0;
|
virtual void configurationChanged() = 0;
|
||||||
|
@@ -38,14 +38,12 @@
|
|||||||
|
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include "accounts/twitter/tomahawkoauthtwitter.h"
|
#include "accounts/twitter/tomahawkoauthtwitter.h"
|
||||||
|
#include <accounts/twitter/twitteraccount.h>
|
||||||
|
|
||||||
static QString s_gotTomahawkRegex = QString( "^(@[a-zA-Z0-9]+ )?(Got Tomahawk\\?) (\\{[a-fA-F0-9\\-]+\\}) (.*)$" );
|
static QString s_gotTomahawkRegex = QString( "^(@[a-zA-Z0-9]+ )?(Got Tomahawk\\?) (\\{[a-fA-F0-9\\-]+\\}) (.*)$" );
|
||||||
|
|
||||||
TwitterSipPlugin::TwitterSipPlugin( Tomahawk::Accounts::Account* account )
|
TwitterSipPlugin::TwitterSipPlugin( Tomahawk::Accounts::Account* account )
|
||||||
: SipPlugin( account )
|
: SipPlugin( account )
|
||||||
, m_configuration( account->configuration() )
|
|
||||||
, m_credentials( account->credentials() )
|
|
||||||
, m_isAuthed( false )
|
|
||||||
, m_checkTimer( this )
|
, m_checkTimer( this )
|
||||||
, m_connectTimer( this )
|
, m_connectTimer( this )
|
||||||
, m_dmPollTimer( this )
|
, m_dmPollTimer( this )
|
||||||
@@ -58,6 +56,8 @@ TwitterSipPlugin::TwitterSipPlugin( Tomahawk::Accounts::Account* account )
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
connect( account, SIGNAL( nowAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &, const QTweetUser & ) ), SLOT( accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &, const QTweetUser & ) ) );
|
||||||
|
|
||||||
if ( Database::instance()->dbid() != m_configuration[ "saveddbid" ].toString() )
|
if ( Database::instance()->dbid() != m_configuration[ "saveddbid" ].toString() )
|
||||||
{
|
{
|
||||||
m_configuration[ "cachedpeers" ] = QVariantHash();
|
m_configuration[ "cachedpeers" ] = QVariantHash();
|
||||||
@@ -82,7 +82,7 @@ TwitterSipPlugin::TwitterSipPlugin( Tomahawk::Accounts::Account* account )
|
|||||||
bool
|
bool
|
||||||
TwitterSipPlugin::isValid() const
|
TwitterSipPlugin::isValid() const
|
||||||
{
|
{
|
||||||
return m_account->enabled() && m_isAuthed;
|
return m_account->enabled() && m_account->isAuthenticated() && !m_cachedTwitterAuth.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -93,68 +93,37 @@ TwitterSipPlugin::connectionState() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TwitterSipPlugin::checkSettings()
|
void
|
||||||
|
TwitterSipPlugin::checkSettings()
|
||||||
{
|
{
|
||||||
configurationChanged();
|
configurationChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
void
|
||||||
TwitterSipPlugin::connectPlugin()
|
TwitterSipPlugin::connectPlugin()
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
if ( !m_account->enabled() )
|
if ( !m_account->enabled() )
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO << "account isn't enabled";
|
tDebug() << Q_FUNC_INFO << "account isn't enabled";
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_cachedPeers = m_configuration[ "cachedpeers" ].toHash();
|
m_cachedPeers = m_configuration[ "cachedpeers" ].toHash();
|
||||||
QStringList peerList = m_cachedPeers.keys();
|
QStringList peerList = m_cachedPeers.keys();
|
||||||
qStableSort( peerList.begin(), peerList.end() );
|
qStableSort( peerList.begin(), peerList.end() );
|
||||||
|
|
||||||
registerOffers( peerList );
|
|
||||||
|
|
||||||
tDebug() << Q_FUNC_INFO << "credentials: " << m_credentials.keys();
|
|
||||||
|
|
||||||
if ( m_credentials[ "oauthtoken" ].toString().isEmpty() || m_credentials[ "oauthtokensecret" ].toString().isEmpty() )
|
if ( !m_account->isAuthenticated() )
|
||||||
{
|
{
|
||||||
qDebug() << "TwitterSipPlugin has empty Twitter credentials; not connecting";
|
tDebug() << Q_FUNC_INFO << "account isn't authenticated, attempting";
|
||||||
return m_cachedPeers.isEmpty();
|
m_account->authenticate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( refreshTwitterAuth() )
|
m_state = Connecting;
|
||||||
{
|
emit stateChanged( m_state );
|
||||||
QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( m_twitterAuth.data(), this );
|
|
||||||
connect( credVerifier, SIGNAL( parsedUser( const QTweetUser & ) ), SLOT( connectAuthVerifyReply( const QTweetUser & ) ) );
|
|
||||||
credVerifier->verify();
|
|
||||||
|
|
||||||
m_state = Connecting;
|
|
||||||
emit stateChanged( m_state );
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
TwitterSipPlugin::refreshTwitterAuth()
|
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO << " begin";
|
|
||||||
if( !m_twitterAuth.isNull() )
|
|
||||||
delete m_twitterAuth.data();
|
|
||||||
|
|
||||||
Q_ASSERT( TomahawkUtils::nam() != 0 );
|
|
||||||
qDebug() << Q_FUNC_INFO << " with nam " << TomahawkUtils::nam();
|
|
||||||
m_twitterAuth = QWeakPointer< TomahawkOAuthTwitter >( new TomahawkOAuthTwitter( TomahawkUtils::nam(), this ) );
|
|
||||||
|
|
||||||
if( m_twitterAuth.isNull() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
m_twitterAuth.data()->setOAuthToken( m_credentials[ "oauthtoken" ].toString().toLatin1() );
|
|
||||||
m_twitterAuth.data()->setOAuthTokenSecret( m_credentials[ "oauthtokensecret" ].toString().toLatin1() );
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TwitterSipPlugin::disconnectPlugin()
|
TwitterSipPlugin::disconnectPlugin()
|
||||||
@@ -173,9 +142,9 @@ TwitterSipPlugin::disconnectPlugin()
|
|||||||
delete m_directMessageNew.data();
|
delete m_directMessageNew.data();
|
||||||
if( !m_directMessageDestroy.isNull() )
|
if( !m_directMessageDestroy.isNull() )
|
||||||
delete m_directMessageDestroy.data();
|
delete m_directMessageDestroy.data();
|
||||||
if( !m_twitterAuth.isNull() )
|
|
||||||
delete m_twitterAuth.data();
|
|
||||||
|
|
||||||
|
m_cachedTwitterAuth.clear();
|
||||||
|
|
||||||
m_configuration[ "cachedpeers" ] = m_cachedPeers;
|
m_configuration[ "cachedpeers" ] = m_cachedPeers;
|
||||||
syncConfig();
|
syncConfig();
|
||||||
m_cachedPeers.empty();
|
m_cachedPeers.empty();
|
||||||
@@ -184,72 +153,42 @@ TwitterSipPlugin::disconnectPlugin()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TwitterSipPlugin::connectAuthVerifyReply( const QTweetUser &user )
|
TwitterSipPlugin::accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &twitterAuth, const QTweetUser &user )
|
||||||
{
|
{
|
||||||
if ( user.id() == 0 )
|
if ( !isValid() )
|
||||||
{
|
return;
|
||||||
qDebug() << "TwitterSipPlugin could not authenticate to Twitter";
|
|
||||||
m_isAuthed = false;
|
m_cachedTwitterAuth = twitterAuth;
|
||||||
m_state = Disconnected;
|
|
||||||
m_connectTimer.stop();
|
m_friendsTimeline = QWeakPointer<QTweetFriendsTimeline>( new QTweetFriendsTimeline( m_cachedTwitterAuth.data(), this ) );
|
||||||
m_checkTimer.stop();
|
m_mentions = QWeakPointer<QTweetMentions>( new QTweetMentions( m_cachedTwitterAuth.data(), this ) );
|
||||||
m_dmPollTimer.stop();
|
m_directMessages = QWeakPointer<QTweetDirectMessages>( new QTweetDirectMessages( m_cachedTwitterAuth.data(), this ) );
|
||||||
emit stateChanged( m_state );
|
m_directMessageNew = QWeakPointer<QTweetDirectMessageNew>( new QTweetDirectMessageNew( m_cachedTwitterAuth.data(), this ) );
|
||||||
}
|
m_directMessageDestroy = QWeakPointer<QTweetDirectMessageDestroy>( new QTweetDirectMessageDestroy( m_cachedTwitterAuth.data(), this ) );
|
||||||
else
|
connect( m_friendsTimeline.data(), SIGNAL( parsedStatuses(const QList< QTweetStatus > &) ), SLOT( friendsTimelineStatuses(const QList<QTweetStatus> &) ) );
|
||||||
{
|
connect( m_mentions.data(), SIGNAL( parsedStatuses(const QList< QTweetStatus > &) ), SLOT( mentionsStatuses(const QList<QTweetStatus> &) ) );
|
||||||
qDebug() << "TwitterSipPlugin successfully authenticated to Twitter as user " << user.screenName();
|
connect( m_directMessages.data(), SIGNAL( parsedDirectMessages(const QList<QTweetDMStatus> &)), SLOT( directMessages(const QList<QTweetDMStatus> &) ) );
|
||||||
m_isAuthed = true;
|
connect( m_directMessageNew.data(), SIGNAL( parsedDirectMessage(const QTweetDMStatus &)), SLOT( directMessagePosted(const QTweetDMStatus &) ) );
|
||||||
if ( !m_twitterAuth.isNull() )
|
connect( m_directMessageNew.data(), SIGNAL( error(QTweetNetBase::ErrorCode, const QString &) ), SLOT( directMessagePostError(QTweetNetBase::ErrorCode, const QString &) ) );
|
||||||
{
|
connect( m_directMessageDestroy.data(), SIGNAL( parsedDirectMessage(const QTweetDMStatus &) ), SLOT( directMessageDestroyed(const QTweetDMStatus &) ) );
|
||||||
m_configuration[ "screenname" ] = user.screenName();
|
m_state = Connected;
|
||||||
syncConfig();
|
emit stateChanged( m_state );
|
||||||
m_friendsTimeline = QWeakPointer<QTweetFriendsTimeline>( new QTweetFriendsTimeline( m_twitterAuth.data(), this ) );
|
QStringList peerList = m_cachedPeers.keys();
|
||||||
m_mentions = QWeakPointer<QTweetMentions>( new QTweetMentions( m_twitterAuth.data(), this ) );
|
qStableSort( peerList.begin(), peerList.end() );
|
||||||
m_directMessages = QWeakPointer<QTweetDirectMessages>( new QTweetDirectMessages( m_twitterAuth.data(), this ) );
|
registerOffers( peerList );
|
||||||
m_directMessageNew = QWeakPointer<QTweetDirectMessageNew>( new QTweetDirectMessageNew( m_twitterAuth.data(), this ) );
|
m_connectTimer.start();
|
||||||
m_directMessageDestroy = QWeakPointer<QTweetDirectMessageDestroy>( new QTweetDirectMessageDestroy( m_twitterAuth.data(), this ) );
|
m_checkTimer.start();
|
||||||
connect( m_friendsTimeline.data(), SIGNAL( parsedStatuses(const QList< QTweetStatus > &) ), SLOT( friendsTimelineStatuses(const QList<QTweetStatus> &) ) );
|
m_dmPollTimer.start();
|
||||||
connect( m_mentions.data(), SIGNAL( parsedStatuses(const QList< QTweetStatus > &) ), SLOT( mentionsStatuses(const QList<QTweetStatus> &) ) );
|
|
||||||
connect( m_directMessages.data(), SIGNAL( parsedDirectMessages(const QList<QTweetDMStatus> &)), SLOT( directMessages(const QList<QTweetDMStatus> &) ) );
|
QMetaObject::invokeMethod( this, "checkTimerFired", Qt::AutoConnection );
|
||||||
connect( m_directMessageNew.data(), SIGNAL( parsedDirectMessage(const QTweetDMStatus &)), SLOT( directMessagePosted(const QTweetDMStatus &) ) );
|
QTimer::singleShot( 20000, this, SLOT( connectTimerFired() ) );
|
||||||
connect( m_directMessageNew.data(), SIGNAL( error(QTweetNetBase::ErrorCode, const QString &) ), SLOT( directMessagePostError(QTweetNetBase::ErrorCode, const QString &) ) );
|
|
||||||
connect( m_directMessageDestroy.data(), SIGNAL( parsedDirectMessage(const QTweetDMStatus &) ), SLOT( directMessageDestroyed(const QTweetDMStatus &) ) );
|
|
||||||
m_state = Connected;
|
|
||||||
emit stateChanged( m_state );
|
|
||||||
m_connectTimer.start();
|
|
||||||
m_checkTimer.start();
|
|
||||||
m_dmPollTimer.start();
|
|
||||||
QMetaObject::invokeMethod( this, "checkTimerFired", Qt::AutoConnection );
|
|
||||||
QTimer::singleShot( 20000, this, SLOT( connectTimerFired() ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( refreshTwitterAuth() )
|
|
||||||
{
|
|
||||||
QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( m_twitterAuth.data(), this );
|
|
||||||
connect( credVerifier, SIGNAL( parsedUser(const QTweetUser &) ), SLOT( connectAuthVerifyReply(const QTweetUser &) ) );
|
|
||||||
credVerifier->verify();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug() << "TwitterSipPlugin auth pointer was null!";
|
|
||||||
m_isAuthed = false;
|
|
||||||
m_state = Disconnected;
|
|
||||||
m_connectTimer.stop();
|
|
||||||
m_checkTimer.stop();
|
|
||||||
m_dmPollTimer.stop();
|
|
||||||
emit stateChanged( m_state );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TwitterSipPlugin::checkTimerFired()
|
TwitterSipPlugin::checkTimerFired()
|
||||||
{
|
{
|
||||||
if ( !isValid() || m_twitterAuth.isNull() )
|
if ( !isValid() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( m_cachedFriendsSinceId == 0 )
|
if ( m_cachedFriendsSinceId == 0 )
|
||||||
@@ -273,6 +212,9 @@ TwitterSipPlugin::checkTimerFired()
|
|||||||
void
|
void
|
||||||
TwitterSipPlugin::registerOffers( const QStringList &peerList )
|
TwitterSipPlugin::registerOffers( const QStringList &peerList )
|
||||||
{
|
{
|
||||||
|
if ( !isValid() )
|
||||||
|
return;
|
||||||
|
|
||||||
foreach( QString screenName, peerList )
|
foreach( QString screenName, peerList )
|
||||||
{
|
{
|
||||||
QVariantHash peerData = m_cachedPeers[screenName].toHash();
|
QVariantHash peerData = m_cachedPeers[screenName].toHash();
|
||||||
@@ -318,14 +260,12 @@ void
|
|||||||
TwitterSipPlugin::connectTimerFired()
|
TwitterSipPlugin::connectTimerFired()
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO << " beginning";
|
tDebug() << Q_FUNC_INFO << " beginning";
|
||||||
if ( !isValid() || m_cachedPeers.isEmpty() || m_twitterAuth.isNull() )
|
if ( !isValid() || m_cachedPeers.isEmpty() )
|
||||||
{
|
{
|
||||||
if ( !isValid() )
|
if ( !isValid() )
|
||||||
tDebug() << Q_FUNC_INFO << " is not valid";
|
tDebug() << Q_FUNC_INFO << " is not valid";
|
||||||
if ( m_cachedPeers.isEmpty() )
|
if ( m_cachedPeers.isEmpty() )
|
||||||
tDebug() << Q_FUNC_INFO << " has empty cached peers";
|
tDebug() << Q_FUNC_INFO << " has empty cached peers";
|
||||||
if ( m_twitterAuth.isNull() )
|
|
||||||
tDebug() << Q_FUNC_INFO << " has null twitterAuth";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,7 +328,7 @@ TwitterSipPlugin::parseGotTomahawk( const QRegExp ®ex, const QString &screenN
|
|||||||
void
|
void
|
||||||
TwitterSipPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses )
|
TwitterSipPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
QRegExp regex( s_gotTomahawkRegex, Qt::CaseSensitive, QRegExp::RegExp2 );
|
QRegExp regex( s_gotTomahawkRegex, Qt::CaseSensitive, QRegExp::RegExp2 );
|
||||||
|
|
||||||
QHash< QString, QTweetStatus > latestHash;
|
QHash< QString, QTweetStatus > latestHash;
|
||||||
@@ -411,7 +351,7 @@ TwitterSipPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses
|
|||||||
if ( status.id() > m_cachedFriendsSinceId )
|
if ( status.id() > m_cachedFriendsSinceId )
|
||||||
m_cachedFriendsSinceId = status.id();
|
m_cachedFriendsSinceId = status.id();
|
||||||
|
|
||||||
qDebug() << "TwitterSipPlugin checking mention from " << status.user().screenName() << " with content " << status.text();
|
tDebug() << "TwitterSipPlugin checking mention from " << status.user().screenName() << " with content " << status.text();
|
||||||
parseGotTomahawk( regex, status.user().screenName(), status.text() );
|
parseGotTomahawk( regex, status.user().screenName(), status.text() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,7 +362,7 @@ TwitterSipPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses
|
|||||||
void
|
void
|
||||||
TwitterSipPlugin::mentionsStatuses( const QList< QTweetStatus > &statuses )
|
TwitterSipPlugin::mentionsStatuses( const QList< QTweetStatus > &statuses )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
QRegExp regex( s_gotTomahawkRegex, Qt::CaseSensitive, QRegExp::RegExp2 );
|
QRegExp regex( s_gotTomahawkRegex, Qt::CaseSensitive, QRegExp::RegExp2 );
|
||||||
|
|
||||||
QHash< QString, QTweetStatus > latestHash;
|
QHash< QString, QTweetStatus > latestHash;
|
||||||
@@ -445,7 +385,7 @@ TwitterSipPlugin::mentionsStatuses( const QList< QTweetStatus > &statuses )
|
|||||||
if ( status.id() > m_cachedMentionsSinceId )
|
if ( status.id() > m_cachedMentionsSinceId )
|
||||||
m_cachedMentionsSinceId = status.id();
|
m_cachedMentionsSinceId = status.id();
|
||||||
|
|
||||||
qDebug() << "TwitterSipPlugin checking mention from " << status.user().screenName() << " with content " << status.text();
|
tDebug() << "TwitterSipPlugin checking mention from " << status.user().screenName() << " with content " << status.text();
|
||||||
parseGotTomahawk( regex, status.user().screenName(), status.text() );
|
parseGotTomahawk( regex, status.user().screenName(), status.text() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,7 +402,7 @@ TwitterSipPlugin::pollDirectMessages()
|
|||||||
if ( m_cachedDirectMessagesSinceId == 0 )
|
if ( m_cachedDirectMessagesSinceId == 0 )
|
||||||
m_cachedDirectMessagesSinceId = m_configuration[ "cacheddirectmentionssinceid" ].toLongLong();
|
m_cachedDirectMessagesSinceId = m_configuration[ "cacheddirectmentionssinceid" ].toLongLong();
|
||||||
|
|
||||||
qDebug() << "TwitterSipPlugin looking for direct messages since id " << m_cachedDirectMessagesSinceId;
|
tDebug() << "TwitterSipPlugin looking for direct messages since id " << m_cachedDirectMessagesSinceId;
|
||||||
|
|
||||||
if ( !m_directMessages.isNull() )
|
if ( !m_directMessages.isNull() )
|
||||||
m_directMessages.data()->fetch( m_cachedDirectMessagesSinceId, 0, 800 );
|
m_directMessages.data()->fetch( m_cachedDirectMessagesSinceId, 0, 800 );
|
||||||
@@ -471,7 +411,7 @@ TwitterSipPlugin::pollDirectMessages()
|
|||||||
void
|
void
|
||||||
TwitterSipPlugin::directMessages( const QList< QTweetDMStatus > &messages )
|
TwitterSipPlugin::directMessages( const QList< QTweetDMStatus > &messages )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
QRegExp regex( s_gotTomahawkRegex, Qt::CaseSensitive, QRegExp::RegExp2 );
|
QRegExp regex( s_gotTomahawkRegex, Qt::CaseSensitive, QRegExp::RegExp2 );
|
||||||
QString myScreenName = m_configuration[ "screenname" ].toString();
|
QString myScreenName = m_configuration[ "screenname" ].toString();
|
||||||
@@ -709,9 +649,10 @@ void
|
|||||||
TwitterSipPlugin::fetchAvatar( const QString& screenName )
|
TwitterSipPlugin::fetchAvatar( const QString& screenName )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
if ( m_twitterAuth.isNull() )
|
if ( !isValid() )
|
||||||
return;
|
return;
|
||||||
QTweetUserShow *userShowFetch = new QTweetUserShow( m_twitterAuth.data(), this );
|
|
||||||
|
QTweetUserShow *userShowFetch = new QTweetUserShow( m_cachedTwitterAuth.data(), this );
|
||||||
connect( userShowFetch, SIGNAL( parsedUserInfo( QTweetUser ) ), SLOT( avatarUserDataSlot( QTweetUser ) ) );
|
connect( userShowFetch, SIGNAL( parsedUserInfo( QTweetUser ) ), SLOT( avatarUserDataSlot( QTweetUser ) ) );
|
||||||
userShowFetch->fetch( screenName );
|
userShowFetch->fetch( screenName );
|
||||||
}
|
}
|
||||||
@@ -720,11 +661,11 @@ void
|
|||||||
TwitterSipPlugin::avatarUserDataSlot( const QTweetUser &user )
|
TwitterSipPlugin::avatarUserDataSlot( const QTweetUser &user )
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
if ( user.profileImageUrl().isEmpty() || m_twitterAuth.isNull() )
|
if ( !isValid() || user.profileImageUrl().isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QNetworkRequest request( user.profileImageUrl() );
|
QNetworkRequest request( user.profileImageUrl() );
|
||||||
QNetworkReply *reply = m_twitterAuth.data()->networkAccessManager()->get( request );
|
QNetworkReply *reply = m_cachedTwitterAuth.data()->networkAccessManager()->get( request );
|
||||||
reply->setProperty( "screenname", user.screenName() );
|
reply->setProperty( "screenname", user.screenName() );
|
||||||
connect( reply, SIGNAL( finished() ), this, SLOT( profilePicReply() ) );
|
connect( reply, SIGNAL( finished() ), this, SLOT( profilePicReply() ) );
|
||||||
}
|
}
|
||||||
@@ -732,8 +673,7 @@ TwitterSipPlugin::avatarUserDataSlot( const QTweetUser &user )
|
|||||||
void
|
void
|
||||||
TwitterSipPlugin::refreshProxy()
|
TwitterSipPlugin::refreshProxy()
|
||||||
{
|
{
|
||||||
if ( !m_twitterAuth.isNull() )
|
//handled by TwitterAccount::refreshProxy()
|
||||||
m_twitterAuth.data()->setNetworkAccessManager( TomahawkUtils::nam() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -761,6 +701,6 @@ TwitterSipPlugin::configurationChanged()
|
|||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
if ( m_state != Disconnected )
|
if ( m_state != Disconnected )
|
||||||
disconnectPlugin();
|
m_account->deauthenticate();
|
||||||
connectPlugin();
|
connectPlugin();
|
||||||
}
|
}
|
||||||
|
@@ -50,7 +50,7 @@ public:
|
|||||||
virtual ConnectionState connectionState() const;
|
virtual ConnectionState connectionState() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual bool connectPlugin();
|
virtual void connectPlugin();
|
||||||
void disconnectPlugin();
|
void disconnectPlugin();
|
||||||
void refreshProxy();
|
void refreshProxy();
|
||||||
void configurationChanged();
|
void configurationChanged();
|
||||||
@@ -75,7 +75,7 @@ public slots:
|
|||||||
void checkSettings();
|
void checkSettings();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void connectAuthVerifyReply( const QTweetUser &user );
|
void accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &twitterAuth, const QTweetUser &user );
|
||||||
void checkTimerFired();
|
void checkTimerFired();
|
||||||
void connectTimerFired();
|
void connectTimerFired();
|
||||||
void friendsTimelineStatuses( const QList< QTweetStatus > &statuses );
|
void friendsTimelineStatuses( const QList< QTweetStatus > &statuses );
|
||||||
@@ -98,7 +98,8 @@ private:
|
|||||||
bool refreshTwitterAuth();
|
bool refreshTwitterAuth();
|
||||||
void parseGotTomahawk( const QRegExp ®ex, const QString &screenName, const QString &text );
|
void parseGotTomahawk( const QRegExp ®ex, const QString &screenName, const QString &text );
|
||||||
|
|
||||||
QWeakPointer< TomahawkOAuthTwitter > m_twitterAuth;
|
QWeakPointer< TomahawkOAuthTwitter > m_cachedTwitterAuth;
|
||||||
|
|
||||||
QWeakPointer< QTweetFriendsTimeline > m_friendsTimeline;
|
QWeakPointer< QTweetFriendsTimeline > m_friendsTimeline;
|
||||||
QWeakPointer< QTweetMentions > m_mentions;
|
QWeakPointer< QTweetMentions > m_mentions;
|
||||||
QWeakPointer< QTweetDirectMessages > m_directMessages;
|
QWeakPointer< QTweetDirectMessages > m_directMessages;
|
||||||
@@ -108,7 +109,6 @@ private:
|
|||||||
QVariantHash m_configuration;
|
QVariantHash m_configuration;
|
||||||
QVariantHash m_credentials;
|
QVariantHash m_credentials;
|
||||||
|
|
||||||
bool m_isAuthed;
|
|
||||||
QTimer m_checkTimer;
|
QTimer m_checkTimer;
|
||||||
QTimer m_connectTimer;
|
QTimer m_connectTimer;
|
||||||
QTimer m_dmPollTimer;
|
QTimer m_dmPollTimer;
|
||||||
|
@@ -133,15 +133,15 @@ XmppSipPlugin::menu()
|
|||||||
return m_menu;
|
return m_menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
XmppSipPlugin::connectPlugin()
|
XmppSipPlugin::connectPlugin()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
if(m_client->isConnected())
|
if( m_client->isConnected() )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "Already connected to server, not connecting again...";
|
qDebug() << Q_FUNC_INFO << "Already connected to server, not connecting again...";
|
||||||
return true; //FIXME: should i return false here?!
|
return; //FIXME: should i return false here?!
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Connecting to the Xmpp server..." << m_client->jid().full();
|
qDebug() << "Connecting to the Xmpp server..." << m_client->jid().full();
|
||||||
@@ -154,7 +154,7 @@ XmppSipPlugin::connectPlugin()
|
|||||||
|
|
||||||
m_state = Connecting;
|
m_state = Connecting;
|
||||||
emit stateChanged( m_state );
|
emit stateChanged( m_state );
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -62,7 +62,7 @@ signals:
|
|||||||
void jidChanged( const QString& );
|
void jidChanged( const QString& );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual bool connectPlugin();
|
virtual void connectPlugin();
|
||||||
void disconnectPlugin();
|
void disconnectPlugin();
|
||||||
void checkSettings();
|
void checkSettings();
|
||||||
void configurationChanged();
|
void configurationChanged();
|
||||||
|
Reference in New Issue
Block a user