mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 06:36:55 +02:00
Work towards getting friends statuses
This commit is contained in:
@@ -16,10 +16,11 @@ public:
|
||||
virtual ~SipPlugin() {}
|
||||
|
||||
virtual bool isValid() = 0;
|
||||
virtual const QString name() = 0;
|
||||
|
||||
public slots:
|
||||
virtual bool connect( bool startup = false ) = 0;
|
||||
virtual void disconnect() = 0;
|
||||
virtual bool connectPlugin( bool startup = false ) = 0;
|
||||
virtual void disconnectPlugin() = 0;
|
||||
|
||||
virtual void addContact( const QString &jid, const QString& msg = QString() ) = 0;
|
||||
virtual void sendMsg( const QString& to, const QString& msg ) = 0;
|
||||
|
@@ -402,6 +402,30 @@ TomahawkSettings::setTwitterOAuthTokenSecret( const QString& oauthtokensecret )
|
||||
setValue( "twitter/oauthtokensecret", oauthtokensecret );
|
||||
}
|
||||
|
||||
qint64
|
||||
TomahawkSettings::twitterCachedFriendsSinceId() const
|
||||
{
|
||||
return value( "twitter/cachedfriendssinceid", 0 ).toLongLong();
|
||||
}
|
||||
|
||||
void
|
||||
TomahawkSettings::setTwitterCachedFriendsSinceId( qint64 cachedId )
|
||||
{
|
||||
setValue( "twitter/cachedfriendssinceid", cachedId );
|
||||
}
|
||||
|
||||
qint64
|
||||
TomahawkSettings::twitterCachedMentionsSinceId() const
|
||||
{
|
||||
return value( "twitter/cachedmentionssinceid", 0 ).toLongLong();
|
||||
}
|
||||
|
||||
void
|
||||
TomahawkSettings::setTwitterCachedMentionsSinceId( qint64 cachedId )
|
||||
{
|
||||
setValue( "twitter/cachedmentionssinceid", cachedId );
|
||||
}
|
||||
|
||||
bool
|
||||
TomahawkSettings::scrobblingEnabled() const
|
||||
{
|
||||
|
@@ -103,6 +103,12 @@ public:
|
||||
QString twitterOAuthTokenSecret() const;
|
||||
void setTwitterOAuthTokenSecret( const QString& oauthtokensecret );
|
||||
|
||||
qint64 twitterCachedFriendsSinceId() const;
|
||||
void setTwitterCachedFriendsSinceId( qint64 sinceid );
|
||||
|
||||
qint64 twitterCachedMentionsSinceId() const;
|
||||
void setTwitterCachedMentionsSinceId( qint64 sinceid );
|
||||
|
||||
/// XMPP Component Settings
|
||||
QString xmppBotServer() const;
|
||||
void setXmppBotServer( const QString &server );
|
||||
|
@@ -1,7 +1,3 @@
|
||||
#include "settingsdialog.h"
|
||||
#include "ui_settingsdialog.h"
|
||||
#include "ui_proxydialog.h"
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
@@ -14,14 +10,17 @@
|
||||
#include <lastfm/XmlQuery>
|
||||
#endif
|
||||
|
||||
#include <qtweetaccountverifycredentials.h>
|
||||
#include <qtweetstatusupdate.h>
|
||||
|
||||
#include "settingsdialog.h"
|
||||
#include "ui_settingsdialog.h"
|
||||
#include "ui_proxydialog.h"
|
||||
#include "tomahawk/tomahawkapp.h"
|
||||
#include "musicscanner.h"
|
||||
#include "tomahawksettings.h"
|
||||
#include "sip/SipHandler.h"
|
||||
#include "sip/twitter/tomahawkoauthtwitter.h"
|
||||
#include <qtweetaccountverifycredentials.h>
|
||||
#include <qtweetstatusupdate.h>
|
||||
|
||||
|
||||
static QString
|
||||
md5( const QByteArray& src )
|
||||
@@ -156,8 +155,8 @@ SettingsDialog::~SettingsDialog()
|
||||
|
||||
if( rejabber )
|
||||
{
|
||||
APP->sipHandler()->disconnect();
|
||||
APP->sipHandler()->connect();
|
||||
APP->sipHandler()->disconnectPlugins();
|
||||
APP->sipHandler()->connectPlugins();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -303,6 +302,7 @@ SettingsDialog::authenticateTwitter()
|
||||
ui->twitterStatusLabel->setText("Status: Credentials saved");
|
||||
ui->twitterAuthenticateButton->setText( "Re-authenticate" );
|
||||
ui->twitterInstructionsBox->setVisible( true );
|
||||
TomahawkApp::instance()->sipHandler()->connectPlugins( false, "SIPTWITTER" );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -114,30 +114,39 @@ SipHandler::loadPlugin( QObject* plugin )
|
||||
|
||||
|
||||
void
|
||||
SipHandler::connect( bool startup )
|
||||
SipHandler::connectPlugins( bool startup, const QString &pluginName )
|
||||
{
|
||||
foreach( SipPlugin* sip, m_plugins )
|
||||
sip->connect( startup );
|
||||
{
|
||||
if ( pluginName.isEmpty() || ( !pluginName.isEmpty() && sip->name() == pluginName ) )
|
||||
sip->connectPlugin( startup );
|
||||
}
|
||||
m_connected = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::disconnect()
|
||||
SipHandler::disconnectPlugins( const QString &pluginName )
|
||||
{
|
||||
foreach( SipPlugin* sip, m_plugins )
|
||||
sip->disconnect();
|
||||
{
|
||||
if ( pluginName.isEmpty() || ( !pluginName.isEmpty() && sip->name() == pluginName ) )
|
||||
sip->disconnectPlugin();
|
||||
}
|
||||
if( pluginName.isEmpty() )
|
||||
{
|
||||
SourceList::instance()->removeAllRemote();
|
||||
m_connected = false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SipHandler::toggleConnect()
|
||||
{
|
||||
if( m_connected )
|
||||
disconnect();
|
||||
disconnectPlugins();
|
||||
else
|
||||
connect();
|
||||
connectPlugins();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -19,8 +19,8 @@ public:
|
||||
public slots:
|
||||
void addContact( const QString& id ) { qDebug() << Q_FUNC_INFO << id; }
|
||||
|
||||
void connect( bool startup = false );
|
||||
void disconnect();
|
||||
void connectPlugins( bool startup = false, const QString &pluginName = QString() );
|
||||
void disconnectPlugins( const QString &pluginName = QString() );
|
||||
void toggleConnect();
|
||||
|
||||
signals:
|
||||
|
@@ -12,9 +12,14 @@ JabberPlugin::setProxy( QNetworkProxy* proxy )
|
||||
p->setProxy( proxy );
|
||||
}
|
||||
|
||||
const QString
|
||||
JabberPlugin::name()
|
||||
{
|
||||
return QString( MYNAME );
|
||||
}
|
||||
|
||||
bool
|
||||
JabberPlugin::connect( bool startup )
|
||||
JabberPlugin::connectPlugin( bool startup )
|
||||
{
|
||||
qDebug() << "JabberPlugin::connect";
|
||||
if ( startup && !TomahawkSettings::instance()->jabberAutoConnect() )
|
||||
|
@@ -6,6 +6,8 @@
|
||||
|
||||
#include "../sipdllmacro.h"
|
||||
|
||||
#define MYNAME "SIPJABBER"
|
||||
|
||||
class SIPDLLEXPORT JabberPlugin : public SipPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -20,13 +22,14 @@ public:
|
||||
|
||||
//FIXME: Make this more correct
|
||||
virtual bool isValid() { return true; }
|
||||
virtual const QString name();
|
||||
|
||||
void setProxy( QNetworkProxy* proxy );
|
||||
|
||||
public slots:
|
||||
virtual bool connect( bool startup );
|
||||
virtual bool connectPlugin( bool startup );
|
||||
|
||||
void disconnect()
|
||||
void disconnectPlugin()
|
||||
{
|
||||
QMetaObject::invokeMethod( p,
|
||||
"disconnect",
|
||||
|
@@ -1,28 +1,46 @@
|
||||
#include "twitter.h"
|
||||
|
||||
#include <tomahawksettings.h>
|
||||
#include <QtPlugin>
|
||||
#include <QRegExp>
|
||||
|
||||
#include <qtweetaccountverifycredentials.h>
|
||||
#include <qtweetuser.h>
|
||||
#include <qtweetfriendstimeline.h>
|
||||
#include <qtweetstatus.h>
|
||||
|
||||
#include <QtPlugin>
|
||||
#include <utils/tomahawkutils.h>
|
||||
#include <tomahawksettings.h>
|
||||
|
||||
|
||||
TwitterPlugin::TwitterPlugin()
|
||||
: m_twitterAuth( 0 )
|
||||
, m_isAuthed( false )
|
||||
: SipPlugin()
|
||||
, m_isValid( false )
|
||||
, m_checkTimer( this )
|
||||
{
|
||||
m_checkTimer.setInterval( 60000 );
|
||||
m_checkTimer.setSingleShot( false );
|
||||
QObject::connect( &m_checkTimer, SIGNAL( timeout() ), SLOT( checkTimerFired() ) );
|
||||
m_checkTimer.start();
|
||||
}
|
||||
|
||||
bool
|
||||
TwitterPlugin::isValid()
|
||||
{
|
||||
return m_isAuthed;
|
||||
return m_isValid;
|
||||
}
|
||||
|
||||
const QString
|
||||
TwitterPlugin::name()
|
||||
{
|
||||
qDebug() << "TwitterPlugin returning plugin name " << QString( MYNAME );
|
||||
return QString( MYNAME );
|
||||
}
|
||||
|
||||
bool
|
||||
TwitterPlugin::connect( bool /*startup*/ )
|
||||
TwitterPlugin::connectPlugin( bool /*startup*/ )
|
||||
{
|
||||
qDebug() << "TwitterPlugin connectPlugin called";
|
||||
|
||||
TomahawkSettings *settings = TomahawkSettings::instance();
|
||||
|
||||
if ( settings->twitterOAuthToken().isEmpty() || settings->twitterOAuthTokenSecret().isEmpty() )
|
||||
@@ -31,13 +49,13 @@ TwitterPlugin::connect( bool /*startup*/ )
|
||||
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() );
|
||||
delete m_twitterAuth.data();
|
||||
m_twitterAuth = QWeakPointer<TomahawkOAuthTwitter>( new TomahawkOAuthTwitter( this ) );
|
||||
m_twitterAuth.data()->setNetworkAccessManager( TomahawkUtils::nam() );
|
||||
m_twitterAuth.data()->setOAuthToken( settings->twitterOAuthToken().toLatin1() );
|
||||
m_twitterAuth.data()->setOAuthTokenSecret( settings->twitterOAuthTokenSecret().toLatin1() );
|
||||
|
||||
QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( m_twitterAuth, this );
|
||||
QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( m_twitterAuth.data(), this );
|
||||
QObject::connect( credVerifier, SIGNAL( parsedUser(const QTweetUser &) ), SLOT( connectAuthVerifyReply(const QTweetUser &) ) );
|
||||
credVerifier->verify();
|
||||
/*
|
||||
@@ -48,18 +66,66 @@ TwitterPlugin::connect( bool /*startup*/ )
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
TwitterPlugin::disconnectPlugin()
|
||||
{
|
||||
if( !m_friendsTimeline.isNull() )
|
||||
m_friendsTimeline.data()->deleteLater();
|
||||
if( !m_twitterAuth.isNull() )
|
||||
m_twitterAuth.data()->deleteLater();
|
||||
}
|
||||
|
||||
void
|
||||
TwitterPlugin::connectAuthVerifyReply( const QTweetUser &user )
|
||||
{
|
||||
if ( user.id() == 0 )
|
||||
{
|
||||
qDebug() << "Could not authenticate to Twitter";
|
||||
m_isAuthed = false;
|
||||
m_isValid = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Successfully authenticated to Twitter as user " << user.screenName();
|
||||
m_isAuthed = true;
|
||||
qDebug() << "TwitterPlugin successfully authenticated to Twitter as user " << user.screenName();
|
||||
m_isValid = true;
|
||||
if ( !m_twitterAuth.isNull() )
|
||||
{
|
||||
m_friendsTimeline = QWeakPointer<QTweetFriendsTimeline>( new QTweetFriendsTimeline( m_twitterAuth.data(), this ) );
|
||||
QObject::connect( m_friendsTimeline.data(), SIGNAL( parsedStatuses(const QList< QTweetStatus > &) ), SLOT( friendsTimelineStatuses(const QList<QTweetStatus> &) ) );
|
||||
QMetaObject::invokeMethod( this, "checkTimerFired", Qt::DirectConnection );
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Twitter auth pointer was null!";
|
||||
m_isValid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TwitterPlugin::checkTimerFired()
|
||||
{
|
||||
if ( isValid() )
|
||||
{
|
||||
qint64 cachedfriendssinceid = TomahawkSettings::instance()->twitterCachedFriendsSinceId();
|
||||
if ( !m_friendsTimeline.isNull() )
|
||||
m_friendsTimeline.data()->fetch( cachedfriendssinceid, 0, 800 );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus >& statuses )
|
||||
{
|
||||
QRegExp regex( QString( "^(@[a-zA-Z0-9]+ )?Got Tomahawk\\?(.*)$" ) );
|
||||
foreach( QTweetStatus status, statuses )
|
||||
{
|
||||
QString statusText = status.text();
|
||||
qDebug() << "Performing matching on status text " << statusText;
|
||||
if ( regex.exactMatch( statusText ) )
|
||||
{
|
||||
qDebug() << "Found an exact matching Tweet from user " << status.user().screenName();
|
||||
}
|
||||
else
|
||||
qDebug() << "No match, matched length is " << regex.matchedLength();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,12 +1,18 @@
|
||||
#ifndef ZEROCONF_H
|
||||
#define ZEROCONF_H
|
||||
#ifndef TWITTER_H
|
||||
#define TWITTER_H
|
||||
|
||||
#include <QTimer>
|
||||
#include <QWeakPointer>
|
||||
|
||||
#include "sip/SipPlugin.h"
|
||||
#include "tomahawkoauthtwitter.h"
|
||||
#include <qtweetuser.h>
|
||||
#include <qtweetnetbase.h>
|
||||
#include <qtweetfriendstimeline.h>
|
||||
|
||||
#include "../sipdllmacro.h"
|
||||
#include "sip/SipPlugin.h"
|
||||
#include "tomahawkoauthtwitter.h"
|
||||
|
||||
#define MYNAME "SIPTWITTER"
|
||||
|
||||
class SIPDLLEXPORT TwitterPlugin : public SipPlugin
|
||||
{
|
||||
@@ -19,13 +25,12 @@ public:
|
||||
virtual ~TwitterPlugin() {}
|
||||
|
||||
virtual bool isValid();
|
||||
virtual const QString name();
|
||||
|
||||
public slots:
|
||||
virtual bool connect( bool startup );
|
||||
virtual bool connectPlugin( bool startup );
|
||||
|
||||
void disconnect()
|
||||
{
|
||||
}
|
||||
void disconnectPlugin();
|
||||
|
||||
void sendMsg( const QString& to, const QString& msg )
|
||||
{
|
||||
@@ -42,11 +47,14 @@ 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 );
|
||||
void checkTimerFired();
|
||||
void friendsTimelineStatuses( const QList< QTweetStatus > &statuses );
|
||||
|
||||
private:
|
||||
TomahawkOAuthTwitter *m_twitterAuth;
|
||||
bool m_isAuthed;
|
||||
QWeakPointer<TomahawkOAuthTwitter> m_twitterAuth;
|
||||
bool m_isValid;
|
||||
QTimer m_checkTimer;
|
||||
QWeakPointer<QTweetFriendsTimeline> m_friendsTimeline;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -2,9 +2,14 @@
|
||||
|
||||
#include <QtPlugin>
|
||||
|
||||
const QString
|
||||
ZeroconfPlugin::name()
|
||||
{
|
||||
return QString( MYNAME );
|
||||
}
|
||||
|
||||
bool
|
||||
ZeroconfPlugin::connect( bool /*startup*/ )
|
||||
ZeroconfPlugin::connectPlugin( bool /*startup*/ )
|
||||
{
|
||||
delete m_zeroconf;
|
||||
m_zeroconf = new TomahawkZeroconf( Servent::instance()->port(), this );
|
||||
|
@@ -6,6 +6,8 @@
|
||||
|
||||
#include "../sipdllmacro.h"
|
||||
|
||||
#define MYNAME "SIPZEROCONF"
|
||||
|
||||
class SIPDLLEXPORT ZeroconfPlugin : public SipPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -19,11 +21,12 @@ public:
|
||||
virtual ~ZeroconfPlugin() {}
|
||||
|
||||
virtual bool isValid() { return true; }
|
||||
virtual const QString name();
|
||||
|
||||
public slots:
|
||||
virtual bool connect( bool startup );
|
||||
virtual bool connectPlugin( bool startup );
|
||||
|
||||
void disconnect()
|
||||
void disconnectPlugin()
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -422,7 +422,7 @@ TomahawkApp::setupSIP()
|
||||
{
|
||||
m_xmppBot = new XMPPBot( this );
|
||||
qDebug() << "Connecting SIP classes";
|
||||
m_sipHandler->connect( true );
|
||||
m_sipHandler->connectPlugins( true );
|
||||
// m_sipHandler->setProxy( *TomahawkUtils::proxy() );
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user