mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 00:54:20 +02:00
Enable twitter plugin, doesn't do much yet but does authenticate -- also
change status post to include a short UUID so we don't get duplicate tweet errors.
This commit is contained in:
@@ -14,6 +14,8 @@ public:
|
||||
enum SipErrorCode { AuthError, ConnectionError }; // Placeholder for errors, to be defined
|
||||
|
||||
virtual ~SipPlugin() {}
|
||||
|
||||
virtual bool isValid() = 0;
|
||||
|
||||
public slots:
|
||||
virtual bool connect( bool startup = false ) = 0;
|
||||
|
@@ -349,7 +349,8 @@ SettingsDialog::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user )
|
||||
twitAuth->setOAuthTokenSecret( s->twitterOAuthTokenSecret().toLatin1() );
|
||||
QTweetStatusUpdate *statUpdate = new QTweetStatusUpdate( twitAuth, this );
|
||||
connect( statUpdate, SIGNAL( postedStatus(const QTweetStatus &) ), SLOT( postGotTomahawkStatusUpdateReply(const QTweetStatus &) ) );
|
||||
statUpdate->post( QString( "Got Tomahawk?" ) );
|
||||
QString uuid = QUuid::createUuid();
|
||||
statUpdate->post( QString( "Got Tomahawk? (" ) + uuid.mid( 1, 8 ) + ")" );
|
||||
}
|
||||
|
||||
void
|
||||
|
@@ -29,7 +29,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tabJabber">
|
||||
<attribute name="title">
|
||||
|
@@ -18,6 +18,9 @@ public:
|
||||
|
||||
virtual ~JabberPlugin() { delete p; }
|
||||
|
||||
//FIXME: Make this more correct
|
||||
virtual bool isValid() { return true; }
|
||||
|
||||
void setProxy( QNetworkProxy* proxy );
|
||||
|
||||
public slots:
|
||||
|
@@ -4,14 +4,15 @@ include( ${QT_USE_FILE} )
|
||||
add_definitions( ${QT_DEFINITIONS} )
|
||||
add_definitions( -DQT_PLUGIN )
|
||||
add_definitions( -DQT_SHARED )
|
||||
add_definitions( -DSIPDLLEXPORT_PRO )
|
||||
|
||||
set( twitterSources
|
||||
# twitter.cpp
|
||||
twitter.cpp
|
||||
tomahawkoauthtwitter.cpp
|
||||
)
|
||||
|
||||
set( twitterHeaders
|
||||
# twitter.h
|
||||
twitter.h
|
||||
tomahawkoauthtwitter.h
|
||||
)
|
||||
|
||||
|
@@ -2,27 +2,44 @@
|
||||
|
||||
#include <tomahawksettings.h>
|
||||
|
||||
#include <qtweetaccountverifycredentials.h>
|
||||
#include <qtweetuser.h>
|
||||
|
||||
#include <QtPlugin>
|
||||
#include <utils/tomahawkutils.h>
|
||||
|
||||
TwitterPlugin::TwitterPlugin()
|
||||
: m_twitterAuth( 0 )
|
||||
, m_isAuthed( false )
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
TwitterPlugin::isValid()
|
||||
{
|
||||
return m_isAuthed;
|
||||
}
|
||||
|
||||
bool
|
||||
TwitterPlugin::connect( bool /*startup*/ )
|
||||
{
|
||||
delete m_twitterAuth;
|
||||
m_twitterAuth = new OAuthTwitter( this );
|
||||
|
||||
{
|
||||
TomahawkSettings *settings = TomahawkSettings::instance();
|
||||
QString oauthtoken = settings->twitterOAuthToken();
|
||||
QString oauthtokensecret = settings->twitterOAuthTokenSecret();
|
||||
|
||||
if ( oauthtoken.isEmpty() || oauthtokensecret.isEmpty() )
|
||||
if ( settings->twitterOAuthToken().isEmpty() || settings->twitterOAuthTokenSecret().isEmpty() )
|
||||
{
|
||||
qDebug() << "Empty Twitter credentials; not connecting";
|
||||
return false;
|
||||
}
|
||||
|
||||
delete m_twitterAuth;
|
||||
m_twitterAuth = new TomahawkOAuthTwitter( this );
|
||||
m_twitterAuth->setNetworkAccessManager( TomahawkUtils::nam() );
|
||||
m_twitterAuth->setOAuthToken( settings->twitterOAuthToken().toLatin1() );
|
||||
m_twitterAuth->setOAuthTokenSecret( settings->twitterOAuthTokenSecret().toLatin1() );
|
||||
|
||||
m_twitterAuth->setOAuthToken( oauthtoken );
|
||||
m_twitterAuth->setOAuthTokenSecret( oauthtokensecret );
|
||||
|
||||
QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( m_twitterAuth, this );
|
||||
QObject::connect( credVerifier, SIGNAL( parsedUser(const QTweetUser &) ), SLOT( connectAuthVerifyReply(const QTweetUser &) ) );
|
||||
credVerifier->verify();
|
||||
/*
|
||||
QObject::connect( m_zeroconf, SIGNAL( tomahawkHostFound( const QString&, int, const QString&, const QString& ) ),
|
||||
SLOT( lanHostFound( const QString&, int, const QString&, const QString& ) ) );
|
||||
@@ -31,6 +48,20 @@ TwitterPlugin::connect( bool /*startup*/ )
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
TwitterPlugin::connectAuthVerifyReply( const QTweetUser &user )
|
||||
{
|
||||
if ( user.id() == 0 )
|
||||
{
|
||||
qDebug() << "Could not authenticate to Twitter";
|
||||
m_isAuthed = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Successfully authenticated to Twitter as user " << user.screenName();
|
||||
m_isAuthed = true;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TwitterPlugin::lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid )
|
||||
|
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "sip/SipPlugin.h"
|
||||
#include "tomahawkoauthtwitter.h"
|
||||
#include <qtweetuser.h>
|
||||
#include <qtweetnetbase.h>
|
||||
|
||||
#include "../sipdllmacro.h"
|
||||
|
||||
@@ -12,11 +14,11 @@ class SIPDLLEXPORT TwitterPlugin : public SipPlugin
|
||||
Q_INTERFACES( SipPlugin )
|
||||
|
||||
public:
|
||||
TwitterPlugin()
|
||||
: m_twitterAuth( 0 )
|
||||
{}
|
||||
TwitterPlugin();
|
||||
|
||||
virtual ~TwitterPlugin() {}
|
||||
|
||||
virtual bool isValid();
|
||||
|
||||
public slots:
|
||||
virtual bool connect( bool startup );
|
||||
@@ -39,9 +41,12 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid );
|
||||
void connectAuthVerifyReply( const QTweetUser &user );
|
||||
void connectAuthVerifyError( QTweetNetBase::ErrorCode errorCode, const QString& errorMsg );
|
||||
|
||||
private:
|
||||
OAuthTwitter *m_twitterAuth;
|
||||
TomahawkOAuthTwitter *m_twitterAuth;
|
||||
bool m_isAuthed;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -17,6 +17,8 @@ public:
|
||||
{}
|
||||
|
||||
virtual ~ZeroconfPlugin() {}
|
||||
|
||||
virtual bool isValid() { return true; }
|
||||
|
||||
public slots:
|
||||
virtual bool connect( bool startup );
|
||||
|
Reference in New Issue
Block a user