1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-12 09:04:33 +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:
Jeff Mitchell
2011-02-12 10:54:07 -05:00
parent 63655a968e
commit 68d3f066e3
8 changed files with 63 additions and 18 deletions

View File

@@ -15,6 +15,8 @@ public:
virtual ~SipPlugin() {} virtual ~SipPlugin() {}
virtual bool isValid() = 0;
public slots: public slots:
virtual bool connect( bool startup = false ) = 0; virtual bool connect( bool startup = false ) = 0;
virtual void disconnect() = 0; virtual void disconnect() = 0;

View File

@@ -349,7 +349,8 @@ SettingsDialog::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user )
twitAuth->setOAuthTokenSecret( s->twitterOAuthTokenSecret().toLatin1() ); twitAuth->setOAuthTokenSecret( s->twitterOAuthTokenSecret().toLatin1() );
QTweetStatusUpdate *statUpdate = new QTweetStatusUpdate( twitAuth, this ); QTweetStatusUpdate *statUpdate = new QTweetStatusUpdate( twitAuth, this );
connect( statUpdate, SIGNAL( postedStatus(const QTweetStatus &) ), SLOT( postGotTomahawkStatusUpdateReply(const QTweetStatus &) ) ); 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 void

View File

@@ -29,7 +29,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tabJabber"> <widget class="QWidget" name="tabJabber">
<attribute name="title"> <attribute name="title">

View File

@@ -18,6 +18,9 @@ public:
virtual ~JabberPlugin() { delete p; } virtual ~JabberPlugin() { delete p; }
//FIXME: Make this more correct
virtual bool isValid() { return true; }
void setProxy( QNetworkProxy* proxy ); void setProxy( QNetworkProxy* proxy );
public slots: public slots:

View File

@@ -4,14 +4,15 @@ include( ${QT_USE_FILE} )
add_definitions( ${QT_DEFINITIONS} ) add_definitions( ${QT_DEFINITIONS} )
add_definitions( -DQT_PLUGIN ) add_definitions( -DQT_PLUGIN )
add_definitions( -DQT_SHARED ) add_definitions( -DQT_SHARED )
add_definitions( -DSIPDLLEXPORT_PRO )
set( twitterSources set( twitterSources
# twitter.cpp twitter.cpp
tomahawkoauthtwitter.cpp tomahawkoauthtwitter.cpp
) )
set( twitterHeaders set( twitterHeaders
# twitter.h twitter.h
tomahawkoauthtwitter.h tomahawkoauthtwitter.h
) )

View File

@@ -2,27 +2,44 @@
#include <tomahawksettings.h> #include <tomahawksettings.h>
#include <qtweetaccountverifycredentials.h>
#include <qtweetuser.h>
#include <QtPlugin> #include <QtPlugin>
#include <utils/tomahawkutils.h>
TwitterPlugin::TwitterPlugin()
: m_twitterAuth( 0 )
, m_isAuthed( false )
{
}
bool
TwitterPlugin::isValid()
{
return m_isAuthed;
}
bool bool
TwitterPlugin::connect( bool /*startup*/ ) TwitterPlugin::connect( bool /*startup*/ )
{ {
delete m_twitterAuth;
m_twitterAuth = new OAuthTwitter( this );
TomahawkSettings *settings = TomahawkSettings::instance(); 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"; qDebug() << "Empty Twitter credentials; not connecting";
return false; return false;
} }
m_twitterAuth->setOAuthToken( oauthtoken ); delete m_twitterAuth;
m_twitterAuth->setOAuthTokenSecret( oauthtokensecret ); m_twitterAuth = new TomahawkOAuthTwitter( this );
m_twitterAuth->setNetworkAccessManager( TomahawkUtils::nam() );
m_twitterAuth->setOAuthToken( settings->twitterOAuthToken().toLatin1() );
m_twitterAuth->setOAuthTokenSecret( settings->twitterOAuthTokenSecret().toLatin1() );
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& ) ), QObject::connect( m_zeroconf, SIGNAL( tomahawkHostFound( const QString&, int, const QString&, const QString& ) ),
SLOT( lanHostFound( 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; 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 void
TwitterPlugin::lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid ) TwitterPlugin::lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid )

View File

@@ -3,6 +3,8 @@
#include "sip/SipPlugin.h" #include "sip/SipPlugin.h"
#include "tomahawkoauthtwitter.h" #include "tomahawkoauthtwitter.h"
#include <qtweetuser.h>
#include <qtweetnetbase.h>
#include "../sipdllmacro.h" #include "../sipdllmacro.h"
@@ -12,12 +14,12 @@ class SIPDLLEXPORT TwitterPlugin : public SipPlugin
Q_INTERFACES( SipPlugin ) Q_INTERFACES( SipPlugin )
public: public:
TwitterPlugin() TwitterPlugin();
: m_twitterAuth( 0 )
{}
virtual ~TwitterPlugin() {} virtual ~TwitterPlugin() {}
virtual bool isValid();
public slots: public slots:
virtual bool connect( bool startup ); virtual bool connect( bool startup );
@@ -39,9 +41,12 @@ public slots:
private slots: private slots:
void lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid ); 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: private:
OAuthTwitter *m_twitterAuth; TomahawkOAuthTwitter *m_twitterAuth;
bool m_isAuthed;
}; };
#endif #endif

View File

@@ -18,6 +18,8 @@ public:
virtual ~ZeroconfPlugin() {} virtual ~ZeroconfPlugin() {}
virtual bool isValid() { return true; }
public slots: public slots:
virtual bool connect( bool startup ); virtual bool connect( bool startup );