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

Twitter authentication works

This commit is contained in:
Jeff Mitchell
2011-02-12 00:17:25 -05:00
parent c7b99d44a0
commit 2e57adb218
10 changed files with 136 additions and 7 deletions

View File

@@ -28,6 +28,7 @@ SET( TOMAHAWK_INC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../include/" )
SET( tomahawkSources ${tomahawkSources} SET( tomahawkSources ${tomahawkSources}
sip/SipHandler.cpp sip/SipHandler.cpp
sip/twitter/tomahawkoauthtwitter.cpp
infosystem/infosystem.cpp infosystem/infosystem.cpp
infosystem/infoplugins/echonestplugin.cpp infosystem/infoplugins/echonestplugin.cpp
@@ -62,6 +63,7 @@ SET( tomahawkHeaders ${tomahawkHeaders}
"${TOMAHAWK_INC_DIR}/tomahawk/infosystem.h" "${TOMAHAWK_INC_DIR}/tomahawk/infosystem.h"
sip/SipHandler.h sip/SipHandler.h
sip/twitter/tomahawkoauthtwitter.h
infosystem/infoplugins/echonestplugin.h infosystem/infoplugins/echonestplugin.h
infosystem/infoplugins/musixmatchplugin.h infosystem/infoplugins/musixmatchplugin.h
@@ -113,6 +115,7 @@ INCLUDE_DIRECTORIES(
../alsa-playback ../alsa-playback
../rtaudio ../rtaudio
../qxt/qxtweb-standalone/qxtweb ../qxt/qxtweb-standalone/qxtweb
../thirdparty/qtweetlib/src
/usr/include/taglib /usr/include/taglib
/usr/local/include/taglib /usr/local/include/taglib
@@ -168,6 +171,7 @@ TARGET_LINK_LIBRARIES( tomahawk
qjson qjson
tag tag
tomahawk_qtweetlib
) )
INCLUDE( "CPack.txt" ) INCLUDE( "CPack.txt" )

View File

@@ -366,6 +366,7 @@ target_link_libraries( tomahawklib
ogg ogg
FLAC++ FLAC++
tomahawk_jdns tomahawk_jdns
tomahawk_qtweetlib
${CLUCENE_LIBRARY} ${CLUCENE_LIBRARY}
) )

View File

@@ -387,7 +387,7 @@ TomahawkSettings::twitterOAuthToken() const
void void
TomahawkSettings::setTwitterOAuthToken( const QString& oauthtoken ) TomahawkSettings::setTwitterOAuthToken( const QString& oauthtoken )
{ {
setValue( "twitter/username", oauthtoken ); setValue( "twitter/oauthtoken", oauthtoken );
} }
QString QString

View File

@@ -18,6 +18,7 @@
#include "musicscanner.h" #include "musicscanner.h"
#include "tomahawksettings.h" #include "tomahawksettings.h"
#include "sip/SipHandler.h" #include "sip/SipHandler.h"
#include "sip/twitter/tomahawkoauthtwitter.h"
static QString static QString
@@ -62,6 +63,17 @@ SettingsDialog::SettingsDialog( QWidget *parent )
ui->groupBoxNetworkAdvanced->setVisible( false ); ui->groupBoxNetworkAdvanced->setVisible( false );
} }
if ( s->twitterOAuthToken().isEmpty() || s->twitterOAuthTokenSecret().isEmpty() )
{
ui->twitterStatusLabel->setText("Status: No saved credentials");
ui->twitterAuthenticateButton->setText( "Authenticate" );
}
else
{
ui->twitterStatusLabel->setText("Status: Credentials saved");
ui->twitterAuthenticateButton->setText( "Re-authenticate" );
}
// MUSIC SCANNER // MUSIC SCANNER
ui->lineEditMusicPath->setText( s->scannerPath() ); ui->lineEditMusicPath->setText( s->scannerPath() );
@@ -273,6 +285,29 @@ SettingsDialog::onLastFmFinished()
#endif #endif
} }
void
SettingsDialog::authenticateTwitter()
{
TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this );
twitAuth->setNetworkAccessManager( TomahawkUtils::nam() );
twitAuth->authorizePin();
if ( !twitAuth->oauthToken().isEmpty() && !twitAuth->oauthTokenSecret().isEmpty() )
{
TomahawkSettings* s = TomahawkSettings::instance();
s->setTwitterOAuthToken( twitAuth->oauthToken() );
s->setTwitterOAuthTokenSecret( twitAuth->oauthTokenSecret() );
ui->twitterStatusLabel->setText("Status: Credentials saved");
ui->twitterAuthenticateButton->setText( "Re-authenticate" );
}
else
{
TomahawkSettings* s = TomahawkSettings::instance();
s->setTwitterOAuthToken( QString() );
s->setTwitterOAuthTokenSecret( QString() );
ui->twitterStatusLabel->setText("Status: No saved credentials");
ui->twitterAuthenticateButton->setText( "Authenticate" );
}
}
ProxyDialog::ProxyDialog( QWidget *parent ) ProxyDialog::ProxyDialog( QWidget *parent )
: QDialog( parent ) : QDialog( parent )

View File

@@ -50,6 +50,8 @@ private slots:
void testLastFmLogin(); void testLastFmLogin();
void onLastFmFinished(); void onLastFmFinished();
void authenticateTwitter();
void addScriptResolver(); void addScriptResolver();
void scriptSelectionChanged(); void scriptSelectionChanged();

View File

@@ -412,6 +412,71 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tabTwitter">
<attribute name="title">
<string>Twitter</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<layout class="QVBoxLayout" name="twitterVertLayout">
<item>
<widget class="QLabel" name="twitterInfoLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Authenticating with Twitter allows you to discover and play music from your Twitter friends running Tomahawk.
This feature works best when you have set a static host name in the &quot;Jabber&quot; settings tab under Advanced Settings, but may work even if you do not. Please note: this discovery uses Direct Messages and will only work when both Twitter users have followed each other. Tomahawk will attempt to &quot;clean up&quot; after itself to keep your Direct Message inbox tidy, but may miss some.
When you press the button your web browser will launch and take you to Twitter.com to authenticate. You must copy and paste the PIN number into the dialog box that appears.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="twitterHorizontalLayout">
<item>
<widget class="QLabel" name="twitterStatusLabel">
<property name="text">
<string>Status: No saved credentials</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="twitterAuthenticateButton">
<property name="text">
<string>Authenticate with Twitter</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer name="twitterVertSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabLastfm"> <widget class="QWidget" name="tabLastfm">
<attribute name="title"> <attribute name="title">
<string>Last.fm</string> <string>Last.fm</string>
@@ -688,5 +753,21 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>twitterAuthenticateButton</sender>
<signal>pressed()</signal>
<receiver>SettingsDialog</receiver>
<slot>authenticateTwitter()</slot>
<hints>
<hint type="sourcelabel">
<x>459</x>
<y>205</y>
</hint>
<hint type="destinationlabel">
<x>310</x>
<y>216</y>
</hint>
</hints>
</connection>
</connections> </connections>
</ui> </ui>

View File

@@ -1,6 +1,12 @@
#include "tomahawkoauthtwitter.h" #include "tomahawkoauthtwitter.h"
#include <QInputDialog> #include <QInputDialog>
TomahawkOAuthTwitter::TomahawkOAuthTwitter( QObject* parent )
: OAuthTwitter( parent )
{
}
int TomahawkOAuthTwitter::authorizationWidget() int TomahawkOAuthTwitter::authorizationWidget()
{ {
bool ok; bool ok;

View File

@@ -3,14 +3,14 @@
#include <oauthtwitter.h> #include <oauthtwitter.h>
class TomahawkOAuthTwitter : public OAuthTwitter #include "../sipdllmacro.h"
class SIPDLLEXPORT TomahawkOAuthTwitter : public OAuthTwitter
{ {
Q_OBJECT Q_OBJECT
public: public:
TomahawkOAuthTwitter(QObject *parent = 0) TomahawkOAuthTwitter( QObject *parent = 0 );
: OAuthTwitter( parent )
{}
~TomahawkOAuthTwitter() {} ~TomahawkOAuthTwitter() {}

View File

@@ -8,7 +8,7 @@ bool
TwitterPlugin::connect( bool /*startup*/ ) TwitterPlugin::connect( bool /*startup*/ )
{ {
delete m_twitterAuth; delete m_twitterAuth;
m_twitterAuth = new TomahawkOAuthTwitter( this ); m_twitterAuth = new OAuthTwitter( this );
TomahawkSettings *settings = TomahawkSettings::instance(); TomahawkSettings *settings = TomahawkSettings::instance();
QString oauthtoken = settings->twitterOAuthToken(); QString oauthtoken = settings->twitterOAuthToken();

View File

@@ -41,7 +41,7 @@ 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 );
private: private:
TomahawkOAuthTwitter *m_twitterAuth; OAuthTwitter *m_twitterAuth;
}; };
#endif #endif