mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-19 07:22:32 +02:00
Extend sip_plugin api to support config widgets. Start with twitter.
This commit is contained in:
parent
727e2f4c28
commit
97e68bff49
@ -144,9 +144,7 @@ IF( UNIX )
|
||||
INCLUDE( "CMakeLists.unix.txt" )
|
||||
ENDIF( UNIX )
|
||||
|
||||
ADD_SUBDIRECTORY( sip/jabber )
|
||||
ADD_SUBDIRECTORY( sip/twitter )
|
||||
ADD_SUBDIRECTORY( sip/zeroconf )
|
||||
ADD_SUBDIRECTORY( sip )
|
||||
|
||||
kde4_add_app_icon( tomahawkSources "${CMAKE_CURRENT_SOURCE_DIR}/../data/icons/tomahawk-icon-*.png" )
|
||||
qt4_add_resources( RC_SRCS "../resources.qrc" )
|
||||
@ -187,7 +185,6 @@ TARGET_LINK_LIBRARIES( tomahawk
|
||||
qjson
|
||||
tag
|
||||
tomahawk_qtweetlib
|
||||
sip_twitter
|
||||
)
|
||||
|
||||
INCLUDE( "CPack.txt" )
|
||||
|
@ -4,4 +4,10 @@ QMenu*
|
||||
SipPlugin::menu()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
QWidget*
|
||||
SipPlugin::configWidget()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -15,11 +15,13 @@ public:
|
||||
enum SipErrorCode { AuthError, ConnectionError }; // Placeholder for errors, to be defined
|
||||
|
||||
virtual ~SipPlugin() {}
|
||||
|
||||
|
||||
virtual bool isValid() = 0;
|
||||
virtual const QString name() = 0;
|
||||
virtual const QString friendlyName() = 0;
|
||||
virtual const QString accountName() = 0;
|
||||
virtual QMenu *menu();
|
||||
virtual QMenu* menu();
|
||||
virtual QWidget* configWidget();
|
||||
|
||||
public slots:
|
||||
virtual bool connectPlugin( bool startup = false ) = 0;
|
||||
|
@ -10,9 +10,6 @@
|
||||
#include <lastfm/XmlQuery>
|
||||
#endif
|
||||
|
||||
#include <qtweetaccountverifycredentials.h>
|
||||
#include <qtweetstatusupdate.h>
|
||||
|
||||
#include "settingsdialog.h"
|
||||
#include "ui_settingsdialog.h"
|
||||
#include "ui_proxydialog.h"
|
||||
@ -20,7 +17,6 @@
|
||||
#include "musicscanner.h"
|
||||
#include "tomahawksettings.h"
|
||||
#include "sip/SipHandler.h"
|
||||
#include "tomahawkoauthtwitter.h"
|
||||
#include <database/database.h>
|
||||
#include "scanmanager.h"
|
||||
|
||||
@ -53,23 +49,20 @@ SettingsDialog::SettingsDialog( QWidget *parent )
|
||||
ui->jabberPassword->setText( s->jabberPassword() );
|
||||
ui->jabberServer->setText( s->jabberServer() );
|
||||
ui->jabberPort->setValue( s->jabberPort() );
|
||||
|
||||
|
||||
ui->staticHostName->setText( s->externalHostname() );
|
||||
ui->staticPort->setValue( s->externalPort() );
|
||||
|
||||
ui->proxyButton->setVisible( false );
|
||||
|
||||
if ( s->twitterOAuthToken().isEmpty() || s->twitterOAuthTokenSecret().isEmpty() )
|
||||
|
||||
// SIP PLUGINS
|
||||
foreach(SipPlugin *plugin, APP->sipHandler()->plugins())
|
||||
{
|
||||
ui->twitterStatusLabel->setText("Status: No saved credentials");
|
||||
ui->twitterAuthenticateButton->setText( "Authenticate" );
|
||||
ui->twitterInstructionsBox->setVisible( false );
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->twitterStatusLabel->setText("Status: Credentials saved");
|
||||
ui->twitterAuthenticateButton->setText( "Re-authenticate" );
|
||||
ui->twitterInstructionsBox->setVisible( true );
|
||||
if(plugin->configWidget())
|
||||
{
|
||||
qDebug() << "Adding configWidget for " << plugin->name();
|
||||
ui->tabWidget->addTab(plugin->configWidget(), plugin->friendlyName());
|
||||
}
|
||||
}
|
||||
|
||||
// MUSIC SCANNER
|
||||
@ -260,98 +253,6 @@ SettingsDialog::onLastFmFinished()
|
||||
}
|
||||
|
||||
|
||||
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" );
|
||||
ui->twitterInstructionsBox->setVisible( true );
|
||||
TomahawkSettings::instance()->setTwitterCachedFriendsSinceId( 0 );
|
||||
TomahawkSettings::instance()->setTwitterCachedMentionsSinceId( 0 );
|
||||
TomahawkApp::instance()->sipHandler()->connectPlugins( false, "SIPTWITTER" );
|
||||
}
|
||||
else
|
||||
{
|
||||
TomahawkSettings* s = TomahawkSettings::instance();
|
||||
s->setTwitterOAuthToken( QString() );
|
||||
s->setTwitterOAuthTokenSecret( QString() );
|
||||
ui->twitterStatusLabel->setText("Status: No saved credentials");
|
||||
ui->twitterAuthenticateButton->setText( "Authenticate" );
|
||||
ui->twitterInstructionsBox->setVisible( false );
|
||||
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("There was an error validating your authentication") );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsDialog::startPostGotTomahawkStatus()
|
||||
{
|
||||
qDebug() << "Posting Got Tomahawk status";
|
||||
TomahawkSettings* s = TomahawkSettings::instance();
|
||||
if ( s->twitterOAuthToken().isEmpty() || s->twitterOAuthTokenSecret().isEmpty() )
|
||||
{
|
||||
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("Your saved credentials could not be loaded.\nYou may wish to try re-authenticating.") );
|
||||
return;
|
||||
}
|
||||
TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this );
|
||||
twitAuth->setNetworkAccessManager( TomahawkUtils::nam() );
|
||||
twitAuth->setOAuthToken( s->twitterOAuthToken().toLatin1() );
|
||||
twitAuth->setOAuthTokenSecret( s->twitterOAuthTokenSecret().toLatin1() );
|
||||
QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( twitAuth, this );
|
||||
connect( credVerifier, SIGNAL( parsedUser(const QTweetUser &) ), SLOT( postGotTomahawkStatusAuthVerifyReply(const QTweetUser &) ) );
|
||||
credVerifier->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsDialog::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user )
|
||||
{
|
||||
if ( user.id() == 0 )
|
||||
{
|
||||
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("Your saved credentials could not be verified.\nYou may wish to try re-authenticating.") );
|
||||
return;
|
||||
}
|
||||
TomahawkSettings* s = TomahawkSettings::instance();
|
||||
s->setTwitterScreenName( user.screenName() );
|
||||
TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this );
|
||||
twitAuth->setNetworkAccessManager( TomahawkUtils::nam() );
|
||||
twitAuth->setOAuthToken( s->twitterOAuthToken().toLatin1() );
|
||||
twitAuth->setOAuthTokenSecret( s->twitterOAuthTokenSecret().toLatin1() );
|
||||
QTweetStatusUpdate *statUpdate = new QTweetStatusUpdate( twitAuth, this );
|
||||
connect( statUpdate, SIGNAL( postedStatus(const QTweetStatus &) ), SLOT( postGotTomahawkStatusUpdateReply(const QTweetStatus &) ) );
|
||||
connect( statUpdate, SIGNAL( error(QTweetNetBase::ErrorCode, const QString&) ), SLOT( postGotTomahawkStatusUpdateError(QTweetNetBase::ErrorCode, const QString &) ) );
|
||||
QString uuid = QUuid::createUuid();
|
||||
statUpdate->post( QString( "Got Tomahawk? {" ) + Database::instance()->dbid() + QString( "} (" ) + uuid.mid( 1, 8 ) + QString( ")" ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsDialog::postGotTomahawkStatusUpdateReply( const QTweetStatus& status )
|
||||
{
|
||||
if ( status.id() == 0 )
|
||||
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("There was an error posting your status -- sorry!") );
|
||||
else
|
||||
QMessageBox::information( 0, QString("Tweeted!"), QString("Your tweet has been posted!") );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsDialog::postGotTomahawkStatusUpdateError( QTweetNetBase::ErrorCode code, const QString& errorMsg )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
qDebug() << "Error posting Got Tomahawk message, error code is " << code << ", error message is " << errorMsg;
|
||||
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("There was an error posting your status -- sorry!") );
|
||||
}
|
||||
|
||||
|
||||
ProxyDialog::ProxyDialog( QWidget *parent )
|
||||
: QDialog( parent )
|
||||
, ui( new Ui::ProxyDialog )
|
||||
|
@ -3,10 +3,6 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include <qtweetstatus.h>
|
||||
#include <qtweetuser.h>
|
||||
#include <qtweetnetbase.h>
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
namespace Ui
|
||||
@ -53,13 +49,7 @@ private slots:
|
||||
|
||||
void testLastFmLogin();
|
||||
void onLastFmFinished();
|
||||
|
||||
void authenticateTwitter();
|
||||
void startPostGotTomahawkStatus();
|
||||
void postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user );
|
||||
void postGotTomahawkStatusUpdateReply( const QTweetStatus &status );
|
||||
void postGotTomahawkStatusUpdateError( QTweetNetBase::ErrorCode, const QString &errorMsg );
|
||||
|
||||
|
||||
void addScriptResolver();
|
||||
void scriptSelectionChanged();
|
||||
void removeScriptResolver();
|
||||
|
@ -485,104 +485,6 @@
|
||||
</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 "Network" 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 "clean up" 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>
|
||||
<widget class="QGroupBox" name="twitterInstructionsBox">
|
||||
<property name="title">
|
||||
<string>Instructions</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_12">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="twitterInstructionsVLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="twitterInstructionsInfoLabel">
|
||||
<property name="text">
|
||||
<string>How it works is simple: just press the button below to tweet "Got Tomahawk?" and some necessary information. Then be (very) patient. Twitter is an asynchronous protocol so it can take a bit!
|
||||
|
||||
If connections to peers seem to have been lost, just press the button again to re-post a tweet for resynchronization.
|
||||
</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="twitterTweetGotTomahawkButton">
|
||||
<property name="text">
|
||||
<string>Press here to have Tomahawk post a tweet</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</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>
|
||||
@ -811,37 +713,5 @@ If connections to peers seem to have been lost, just press the button again to r
|
||||
</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>
|
||||
<connection>
|
||||
<sender>twitterTweetGotTomahawkButton</sender>
|
||||
<signal>pressed()</signal>
|
||||
<receiver>SettingsDialog</receiver>
|
||||
<slot>startPostGotTomahawkStatus()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>310</x>
|
||||
<y>313</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>310</x>
|
||||
<y>216</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
#include "tomahawksettings.h"
|
||||
|
||||
#include "tomahawk/tomahawkapp.h"
|
||||
|
||||
#include <QtPlugin>
|
||||
#include <QStringList>
|
||||
#include <QInputDialog>
|
||||
@ -32,6 +30,12 @@ JabberPlugin::name()
|
||||
return QString( MYNAME );
|
||||
}
|
||||
|
||||
const QString
|
||||
JabberPlugin::friendlyName()
|
||||
{
|
||||
return QString( "Jabber" );
|
||||
}
|
||||
|
||||
const QString
|
||||
JabberPlugin::accountName()
|
||||
{
|
||||
@ -62,7 +66,7 @@ JabberPlugin::connectPlugin( bool startup )
|
||||
qDebug() << "JID did not have an @ in it, could not find a server part";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if ( server.isEmpty() )
|
||||
server = splitJid[1];
|
||||
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
//FIXME: Make this more correct
|
||||
virtual bool isValid() { return true; }
|
||||
virtual const QString name();
|
||||
|
||||
virtual const QString friendlyName();
|
||||
virtual const QString accountName();
|
||||
virtual QMenu* menu();
|
||||
|
||||
|
@ -8,20 +8,27 @@ add_definitions( -DSIPDLLEXPORT_PRO )
|
||||
|
||||
set( twitterSources
|
||||
twitter.cpp
|
||||
twitterconfigwidget.cpp
|
||||
)
|
||||
|
||||
set( twitterHeaders
|
||||
twitter.h
|
||||
twitterconfigwidget.h
|
||||
)
|
||||
|
||||
include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ..
|
||||
set( twitterUI
|
||||
twitterconfigwidget.ui
|
||||
)
|
||||
|
||||
include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ..
|
||||
${QT_INCLUDE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/thirdparty/qtweetlib/qtweetlib/src
|
||||
${CMAKE_SOURCE_DIR}/thirdparty/qtweetlib/tomahawk-custom
|
||||
)
|
||||
|
||||
qt4_wrap_cpp( twitterMoc ${twitterHeaders} )
|
||||
add_library( sip_twitter SHARED ${twitterSources} ${twitterMoc} )
|
||||
qt4_wrap_ui( twitterUI_H ${twitterUI} )
|
||||
add_library( sip_twitter SHARED ${twitterUI_H} ${twitterSources} ${twitterMoc} )
|
||||
|
||||
IF( WIN32 )
|
||||
SET( OS_SPECIFIC_LINK_LIBRARIES
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "twitter.h"
|
||||
|
||||
#include "twitterconfigwidget.h"
|
||||
|
||||
#include <QtPlugin>
|
||||
#include <QRegExp>
|
||||
#include <QStringList>
|
||||
|
@ -33,6 +33,9 @@ public:
|
||||
virtual bool isValid();
|
||||
virtual const QString name();
|
||||
virtual const QString accountName();
|
||||
virtual const QString friendlyName();
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
|
||||
public slots:
|
||||
virtual bool connectPlugin( bool startup );
|
||||
|
@ -14,6 +14,12 @@ ZeroconfPlugin::accountName()
|
||||
return QString();
|
||||
}
|
||||
|
||||
const QString
|
||||
ZeroconfPlugin::friendlyName()
|
||||
{
|
||||
return QString( "Zeroconf" );
|
||||
}
|
||||
|
||||
bool
|
||||
ZeroconfPlugin::connectPlugin( bool /*startup*/ )
|
||||
{
|
||||
|
@ -24,6 +24,7 @@ public:
|
||||
|
||||
virtual bool isValid() { return true; }
|
||||
virtual const QString name();
|
||||
virtual const QString friendlyName();
|
||||
virtual const QString accountName();
|
||||
|
||||
public slots:
|
||||
|
Loading…
x
Reference in New Issue
Block a user