1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +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}
sip/SipHandler.cpp
sip/twitter/tomahawkoauthtwitter.cpp
infosystem/infosystem.cpp
infosystem/infoplugins/echonestplugin.cpp
@@ -62,6 +63,7 @@ SET( tomahawkHeaders ${tomahawkHeaders}
"${TOMAHAWK_INC_DIR}/tomahawk/infosystem.h"
sip/SipHandler.h
sip/twitter/tomahawkoauthtwitter.h
infosystem/infoplugins/echonestplugin.h
infosystem/infoplugins/musixmatchplugin.h
@@ -113,6 +115,7 @@ INCLUDE_DIRECTORIES(
../alsa-playback
../rtaudio
../qxt/qxtweb-standalone/qxtweb
../thirdparty/qtweetlib/src
/usr/include/taglib
/usr/local/include/taglib
@@ -168,6 +171,7 @@ TARGET_LINK_LIBRARIES( tomahawk
qjson
tag
tomahawk_qtweetlib
)
INCLUDE( "CPack.txt" )

View File

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

View File

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

View File

@@ -18,6 +18,7 @@
#include "musicscanner.h"
#include "tomahawksettings.h"
#include "sip/SipHandler.h"
#include "sip/twitter/tomahawkoauthtwitter.h"
static QString
@@ -62,6 +63,17 @@ SettingsDialog::SettingsDialog( QWidget *parent )
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
ui->lineEditMusicPath->setText( s->scannerPath() );
@@ -273,6 +285,29 @@ SettingsDialog::onLastFmFinished()
#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 )
: QDialog( parent )

View File

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

View File

@@ -412,6 +412,71 @@
</item>
</layout>
</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">
<attribute name="title">
<string>Last.fm</string>
@@ -688,5 +753,21 @@
</hint>
</hints>
</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>
</ui>

View File

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

View File

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

View File

@@ -8,7 +8,7 @@ bool
TwitterPlugin::connect( bool /*startup*/ )
{
delete m_twitterAuth;
m_twitterAuth = new TomahawkOAuthTwitter( this );
m_twitterAuth = new OAuthTwitter( this );
TomahawkSettings *settings = TomahawkSettings::instance();
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 );
private:
TomahawkOAuthTwitter *m_twitterAuth;
OAuthTwitter *m_twitterAuth;
};
#endif