mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 00:09:47 +01:00
More cleanup work. Also, move twitter authentication to the account, so it's centralized
This commit is contained in:
parent
eaab5df5be
commit
bfcf4d3bdb
@ -2,6 +2,7 @@
|
||||
#define TOMAHAWKOAUTHTWITTERACCOUNT
|
||||
|
||||
#include "dllmacro.h"
|
||||
#include <utils/tomahawkutils.h>
|
||||
|
||||
#include <QTweetLib/qtweetlib_global.h>
|
||||
#include <QTweetLib/oauthtwitter.h>
|
||||
@ -11,7 +12,7 @@ class DLLEXPORT TomahawkOAuthTwitter : public OAuthTwitter
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TomahawkOAuthTwitter( QNetworkAccessManager *nam, QObject *parent = 0 );
|
||||
TomahawkOAuthTwitter( QNetworkAccessManager *nam = TomahawkUtils::nam() , QObject *parent = 0 );
|
||||
|
||||
~TomahawkOAuthTwitter() {}
|
||||
|
||||
|
@ -17,11 +17,16 @@
|
||||
*/
|
||||
|
||||
#include "twitteraccount.h"
|
||||
|
||||
#include "twitterconfigwidget.h"
|
||||
#include "accounts/twitter/tomahawkoauthtwitter.h"
|
||||
|
||||
#include "sip/SipPlugin.h"
|
||||
|
||||
#include <QTweetLib/qtweetaccountverifycredentials.h>
|
||||
#include <QTweetLib/qtweetuser.h>
|
||||
#include <QTweetLib/qtweetstatus.h>
|
||||
#include <QTweetLib/qtweetusershow.h>
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
namespace Tomahawk
|
||||
@ -50,6 +55,8 @@ TwitterAccount::TwitterAccount( const QString &accountId )
|
||||
|
||||
m_configWidget = QWeakPointer< TwitterConfigWidget >( new TwitterConfigWidget( this, 0 ) );
|
||||
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" ); }
|
||||
|
||||
bool canSelfAuthenticate() const { return false; }
|
||||
bool authenticate() { return false; }
|
||||
bool canSelfAuthenticate() const { return true; }
|
||||
void authenticate();
|
||||
void deauthenticate();
|
||||
bool isAuthenticated() const { return m_isAuthenticated; }
|
||||
|
||||
Tomahawk::InfoSystem::InfoPlugin* infoPlugin() { return 0; }
|
||||
@ -70,11 +71,22 @@ public:
|
||||
QWidget* configurationWidget() { return m_configWidget.data(); }
|
||||
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:
|
||||
void configDialogAuthedSignalSlot( bool authed );
|
||||
void connectAuthVerifyReply( const QTweetUser &user );
|
||||
|
||||
private:
|
||||
bool m_isAuthenticated;
|
||||
QWeakPointer< TomahawkOAuthTwitter > m_twitterAuth;
|
||||
QWeakPointer< TwitterConfigWidget > m_configWidget;
|
||||
QWeakPointer< TwitterSipPlugin > m_twitterSipPlugin;
|
||||
|
||||
|
@ -56,6 +56,20 @@ XmppAccount::~XmppAccount()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmppAccount::authenticate()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmppAccount::deauthenticate()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SipPlugin*
|
||||
XmppAccount::sipPlugin()
|
||||
{
|
||||
|
@ -61,7 +61,8 @@ public:
|
||||
QIcon icon() const { return QIcon( ":/xmpp-icon.png" ); }
|
||||
|
||||
bool canSelfAuthenticate() const { return false; }
|
||||
bool authenticate() { return false; }
|
||||
void authenticate();
|
||||
void deauthenticate();
|
||||
bool isAuthenticated() const { return m_isAuthenticated; }
|
||||
|
||||
Tomahawk::InfoSystem::InfoPlugin* infoPlugin() { return 0; }
|
||||
@ -70,6 +71,8 @@ public:
|
||||
QWidget* configurationWidget() { return m_configWidget.data(); }
|
||||
QWidget* aclWidget() { return 0; }
|
||||
|
||||
void refreshProxy() {};
|
||||
|
||||
private:
|
||||
Ui_XmppConfigWidget* m_ui; // so the google wrapper can change the config dialog a bit
|
||||
bool m_isAuthenticated;
|
||||
|
@ -52,10 +52,17 @@ Account::canSelfAuthenticate() const
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
void
|
||||
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 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 Tomahawk::InfoSystem::InfoPlugin* infoPlugin() = 0;
|
||||
@ -106,11 +107,8 @@ public:
|
||||
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 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 setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_acl = acl; }
|
||||
|
||||
virtual void setTypes( const QSet< AccountType > types )
|
||||
{
|
||||
QMutexLocker locker( &m_mutex );
|
||||
@ -130,10 +128,13 @@ public:
|
||||
syncConfig();
|
||||
}
|
||||
|
||||
virtual void refreshProxy() = 0;
|
||||
|
||||
virtual void sync() { QMutexLocker locker( &m_mutex ); syncConfig(); };
|
||||
|
||||
signals:
|
||||
void configurationChanged();
|
||||
void authenticated( bool );
|
||||
|
||||
protected:
|
||||
virtual void loadFromConfig( const QString &accountId )
|
||||
|
@ -60,7 +60,7 @@ public:
|
||||
virtual const QStringList peersOnline() const;
|
||||
|
||||
public slots:
|
||||
virtual bool connectPlugin() = 0;
|
||||
virtual void connectPlugin() = 0;
|
||||
virtual void disconnectPlugin() = 0;
|
||||
virtual void checkSettings() = 0;
|
||||
virtual void configurationChanged() = 0;
|
||||
|
@ -38,14 +38,12 @@
|
||||
|
||||
#include "utils/logger.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\\-]+\\}) (.*)$" );
|
||||
|
||||
TwitterSipPlugin::TwitterSipPlugin( Tomahawk::Accounts::Account* account )
|
||||
: SipPlugin( account )
|
||||
, m_configuration( account->configuration() )
|
||||
, m_credentials( account->credentials() )
|
||||
, m_isAuthed( false )
|
||||
, m_checkTimer( this )
|
||||
, m_connectTimer( this )
|
||||
, m_dmPollTimer( this )
|
||||
@ -58,6 +56,8 @@ TwitterSipPlugin::TwitterSipPlugin( Tomahawk::Accounts::Account* account )
|
||||
{
|
||||
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() )
|
||||
{
|
||||
m_configuration[ "cachedpeers" ] = QVariantHash();
|
||||
@ -82,7 +82,7 @@ TwitterSipPlugin::TwitterSipPlugin( Tomahawk::Accounts::Account* account )
|
||||
bool
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
void
|
||||
TwitterSipPlugin::connectPlugin()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
if ( !m_account->enabled() )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << "account isn't enabled";
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
m_cachedPeers = m_configuration[ "cachedpeers" ].toHash();
|
||||
QStringList peerList = m_cachedPeers.keys();
|
||||
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";
|
||||
return m_cachedPeers.isEmpty();
|
||||
tDebug() << Q_FUNC_INFO << "account isn't authenticated, attempting";
|
||||
m_account->authenticate();
|
||||
}
|
||||
|
||||
if ( refreshTwitterAuth() )
|
||||
{
|
||||
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;
|
||||
m_state = Connecting;
|
||||
emit stateChanged( m_state );
|
||||
}
|
||||
|
||||
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
|
||||
TwitterSipPlugin::disconnectPlugin()
|
||||
@ -173,9 +142,9 @@ TwitterSipPlugin::disconnectPlugin()
|
||||
delete m_directMessageNew.data();
|
||||
if( !m_directMessageDestroy.isNull() )
|
||||
delete m_directMessageDestroy.data();
|
||||
if( !m_twitterAuth.isNull() )
|
||||
delete m_twitterAuth.data();
|
||||
|
||||
m_cachedTwitterAuth.clear();
|
||||
|
||||
m_configuration[ "cachedpeers" ] = m_cachedPeers;
|
||||
syncConfig();
|
||||
m_cachedPeers.empty();
|
||||
@ -184,72 +153,42 @@ TwitterSipPlugin::disconnectPlugin()
|
||||
}
|
||||
|
||||
void
|
||||
TwitterSipPlugin::connectAuthVerifyReply( const QTweetUser &user )
|
||||
TwitterSipPlugin::accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &twitterAuth, const QTweetUser &user )
|
||||
{
|
||||
if ( user.id() == 0 )
|
||||
{
|
||||
qDebug() << "TwitterSipPlugin could not authenticate to Twitter";
|
||||
m_isAuthed = false;
|
||||
m_state = Disconnected;
|
||||
m_connectTimer.stop();
|
||||
m_checkTimer.stop();
|
||||
m_dmPollTimer.stop();
|
||||
emit stateChanged( m_state );
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "TwitterSipPlugin successfully authenticated to Twitter as user " << user.screenName();
|
||||
m_isAuthed = true;
|
||||
if ( !m_twitterAuth.isNull() )
|
||||
{
|
||||
m_configuration[ "screenname" ] = user.screenName();
|
||||
syncConfig();
|
||||
m_friendsTimeline = QWeakPointer<QTweetFriendsTimeline>( new QTweetFriendsTimeline( m_twitterAuth.data(), this ) );
|
||||
m_mentions = QWeakPointer<QTweetMentions>( new QTweetMentions( m_twitterAuth.data(), this ) );
|
||||
m_directMessages = QWeakPointer<QTweetDirectMessages>( new QTweetDirectMessages( m_twitterAuth.data(), this ) );
|
||||
m_directMessageNew = QWeakPointer<QTweetDirectMessageNew>( new QTweetDirectMessageNew( m_twitterAuth.data(), this ) );
|
||||
m_directMessageDestroy = QWeakPointer<QTweetDirectMessageDestroy>( new QTweetDirectMessageDestroy( m_twitterAuth.data(), this ) );
|
||||
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> &) ) );
|
||||
connect( m_directMessages.data(), SIGNAL( parsedDirectMessages(const QList<QTweetDMStatus> &)), SLOT( directMessages(const QList<QTweetDMStatus> &) ) );
|
||||
connect( m_directMessageNew.data(), SIGNAL( parsedDirectMessage(const QTweetDMStatus &)), SLOT( directMessagePosted(const QTweetDMStatus &) ) );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !isValid() )
|
||||
return;
|
||||
|
||||
m_cachedTwitterAuth = twitterAuth;
|
||||
|
||||
m_friendsTimeline = QWeakPointer<QTweetFriendsTimeline>( new QTweetFriendsTimeline( m_cachedTwitterAuth.data(), this ) );
|
||||
m_mentions = QWeakPointer<QTweetMentions>( new QTweetMentions( m_cachedTwitterAuth.data(), this ) );
|
||||
m_directMessages = QWeakPointer<QTweetDirectMessages>( new QTweetDirectMessages( m_cachedTwitterAuth.data(), this ) );
|
||||
m_directMessageNew = QWeakPointer<QTweetDirectMessageNew>( new QTweetDirectMessageNew( m_cachedTwitterAuth.data(), this ) );
|
||||
m_directMessageDestroy = QWeakPointer<QTweetDirectMessageDestroy>( new QTweetDirectMessageDestroy( m_cachedTwitterAuth.data(), this ) );
|
||||
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> &) ) );
|
||||
connect( m_directMessages.data(), SIGNAL( parsedDirectMessages(const QList<QTweetDMStatus> &)), SLOT( directMessages(const QList<QTweetDMStatus> &) ) );
|
||||
connect( m_directMessageNew.data(), SIGNAL( parsedDirectMessage(const QTweetDMStatus &)), SLOT( directMessagePosted(const QTweetDMStatus &) ) );
|
||||
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 );
|
||||
QStringList peerList = m_cachedPeers.keys();
|
||||
qStableSort( peerList.begin(), peerList.end() );
|
||||
registerOffers( peerList );
|
||||
m_connectTimer.start();
|
||||
m_checkTimer.start();
|
||||
m_dmPollTimer.start();
|
||||
|
||||
QMetaObject::invokeMethod( this, "checkTimerFired", Qt::AutoConnection );
|
||||
QTimer::singleShot( 20000, this, SLOT( connectTimerFired() ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TwitterSipPlugin::checkTimerFired()
|
||||
{
|
||||
if ( !isValid() || m_twitterAuth.isNull() )
|
||||
if ( !isValid() )
|
||||
return;
|
||||
|
||||
if ( m_cachedFriendsSinceId == 0 )
|
||||
@ -273,6 +212,9 @@ TwitterSipPlugin::checkTimerFired()
|
||||
void
|
||||
TwitterSipPlugin::registerOffers( const QStringList &peerList )
|
||||
{
|
||||
if ( !isValid() )
|
||||
return;
|
||||
|
||||
foreach( QString screenName, peerList )
|
||||
{
|
||||
QVariantHash peerData = m_cachedPeers[screenName].toHash();
|
||||
@ -318,14 +260,12 @@ void
|
||||
TwitterSipPlugin::connectTimerFired()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << " beginning";
|
||||
if ( !isValid() || m_cachedPeers.isEmpty() || m_twitterAuth.isNull() )
|
||||
if ( !isValid() || m_cachedPeers.isEmpty() )
|
||||
{
|
||||
if ( !isValid() )
|
||||
tDebug() << Q_FUNC_INFO << " is not valid";
|
||||
if ( m_cachedPeers.isEmpty() )
|
||||
tDebug() << Q_FUNC_INFO << " has empty cached peers";
|
||||
if ( m_twitterAuth.isNull() )
|
||||
tDebug() << Q_FUNC_INFO << " has null twitterAuth";
|
||||
return;
|
||||
}
|
||||
|
||||
@ -388,7 +328,7 @@ TwitterSipPlugin::parseGotTomahawk( const QRegExp ®ex, const QString &screenN
|
||||
void
|
||||
TwitterSipPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
QRegExp regex( s_gotTomahawkRegex, Qt::CaseSensitive, QRegExp::RegExp2 );
|
||||
|
||||
QHash< QString, QTweetStatus > latestHash;
|
||||
@ -411,7 +351,7 @@ TwitterSipPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses
|
||||
if ( status.id() > m_cachedFriendsSinceId )
|
||||
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() );
|
||||
}
|
||||
|
||||
@ -422,7 +362,7 @@ TwitterSipPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses
|
||||
void
|
||||
TwitterSipPlugin::mentionsStatuses( const QList< QTweetStatus > &statuses )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
QRegExp regex( s_gotTomahawkRegex, Qt::CaseSensitive, QRegExp::RegExp2 );
|
||||
|
||||
QHash< QString, QTweetStatus > latestHash;
|
||||
@ -445,7 +385,7 @@ TwitterSipPlugin::mentionsStatuses( const QList< QTweetStatus > &statuses )
|
||||
if ( status.id() > m_cachedMentionsSinceId )
|
||||
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() );
|
||||
}
|
||||
|
||||
@ -462,7 +402,7 @@ TwitterSipPlugin::pollDirectMessages()
|
||||
if ( m_cachedDirectMessagesSinceId == 0 )
|
||||
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() )
|
||||
m_directMessages.data()->fetch( m_cachedDirectMessagesSinceId, 0, 800 );
|
||||
@ -471,7 +411,7 @@ TwitterSipPlugin::pollDirectMessages()
|
||||
void
|
||||
TwitterSipPlugin::directMessages( const QList< QTweetDMStatus > &messages )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
|
||||
QRegExp regex( s_gotTomahawkRegex, Qt::CaseSensitive, QRegExp::RegExp2 );
|
||||
QString myScreenName = m_configuration[ "screenname" ].toString();
|
||||
@ -709,9 +649,10 @@ void
|
||||
TwitterSipPlugin::fetchAvatar( const QString& screenName )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
if ( m_twitterAuth.isNull() )
|
||||
if ( !isValid() )
|
||||
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 ) ) );
|
||||
userShowFetch->fetch( screenName );
|
||||
}
|
||||
@ -720,11 +661,11 @@ void
|
||||
TwitterSipPlugin::avatarUserDataSlot( const QTweetUser &user )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
if ( user.profileImageUrl().isEmpty() || m_twitterAuth.isNull() )
|
||||
if ( !isValid() || user.profileImageUrl().isEmpty())
|
||||
return;
|
||||
|
||||
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() );
|
||||
connect( reply, SIGNAL( finished() ), this, SLOT( profilePicReply() ) );
|
||||
}
|
||||
@ -732,8 +673,7 @@ TwitterSipPlugin::avatarUserDataSlot( const QTweetUser &user )
|
||||
void
|
||||
TwitterSipPlugin::refreshProxy()
|
||||
{
|
||||
if ( !m_twitterAuth.isNull() )
|
||||
m_twitterAuth.data()->setNetworkAccessManager( TomahawkUtils::nam() );
|
||||
//handled by TwitterAccount::refreshProxy()
|
||||
}
|
||||
|
||||
void
|
||||
@ -761,6 +701,6 @@ TwitterSipPlugin::configurationChanged()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
if ( m_state != Disconnected )
|
||||
disconnectPlugin();
|
||||
m_account->deauthenticate();
|
||||
connectPlugin();
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
virtual ConnectionState connectionState() const;
|
||||
|
||||
public slots:
|
||||
virtual bool connectPlugin();
|
||||
virtual void connectPlugin();
|
||||
void disconnectPlugin();
|
||||
void refreshProxy();
|
||||
void configurationChanged();
|
||||
@ -75,7 +75,7 @@ public slots:
|
||||
void checkSettings();
|
||||
|
||||
private slots:
|
||||
void connectAuthVerifyReply( const QTweetUser &user );
|
||||
void accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &twitterAuth, const QTweetUser &user );
|
||||
void checkTimerFired();
|
||||
void connectTimerFired();
|
||||
void friendsTimelineStatuses( const QList< QTweetStatus > &statuses );
|
||||
@ -98,7 +98,8 @@ private:
|
||||
bool refreshTwitterAuth();
|
||||
void parseGotTomahawk( const QRegExp ®ex, const QString &screenName, const QString &text );
|
||||
|
||||
QWeakPointer< TomahawkOAuthTwitter > m_twitterAuth;
|
||||
QWeakPointer< TomahawkOAuthTwitter > m_cachedTwitterAuth;
|
||||
|
||||
QWeakPointer< QTweetFriendsTimeline > m_friendsTimeline;
|
||||
QWeakPointer< QTweetMentions > m_mentions;
|
||||
QWeakPointer< QTweetDirectMessages > m_directMessages;
|
||||
@ -108,7 +109,6 @@ private:
|
||||
QVariantHash m_configuration;
|
||||
QVariantHash m_credentials;
|
||||
|
||||
bool m_isAuthed;
|
||||
QTimer m_checkTimer;
|
||||
QTimer m_connectTimer;
|
||||
QTimer m_dmPollTimer;
|
||||
|
@ -133,15 +133,15 @@ XmppSipPlugin::menu()
|
||||
return m_menu;
|
||||
}
|
||||
|
||||
bool
|
||||
void
|
||||
XmppSipPlugin::connectPlugin()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
if(m_client->isConnected())
|
||||
if( m_client->isConnected() )
|
||||
{
|
||||
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();
|
||||
@ -154,7 +154,7 @@ XmppSipPlugin::connectPlugin()
|
||||
|
||||
m_state = Connecting;
|
||||
emit stateChanged( m_state );
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -62,7 +62,7 @@ signals:
|
||||
void jidChanged( const QString& );
|
||||
|
||||
public slots:
|
||||
virtual bool connectPlugin();
|
||||
virtual void connectPlugin();
|
||||
void disconnectPlugin();
|
||||
void checkSettings();
|
||||
void configurationChanged();
|
||||
|
Loading…
x
Reference in New Issue
Block a user