mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 03:40:16 +02:00
Add avatar/profile pic support to Twitter SIP
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
Version 0.1.0:
|
Version 0.1.0:
|
||||||
|
* Twitter peer profile pictures are shown
|
||||||
* Initial SOCKS5 proxy support.
|
* Initial SOCKS5 proxy support.
|
||||||
* Fix issue where track resolving spinner never stopped if tracks were
|
* Fix issue where track resolving spinner never stopped if tracks were
|
||||||
removed from playlist while resolving.
|
removed from playlist while resolving.
|
||||||
|
@@ -372,6 +372,7 @@ void
|
|||||||
setProxy( QNetworkProxy* proxy )
|
setProxy( QNetworkProxy* proxy )
|
||||||
{
|
{
|
||||||
s_proxy = proxy;
|
s_proxy = proxy;
|
||||||
|
s_nam.data()->setProxy( *proxy );
|
||||||
qDebug() << Q_FUNC_INFO << " setting proxy to use proxy DNS? " << (TomahawkSettings::instance()->proxyDns() ? "true" : "false");
|
qDebug() << Q_FUNC_INFO << " setting proxy to use proxy DNS? " << (TomahawkSettings::instance()->proxyDns() ? "true" : "false");
|
||||||
if ( !TomahawkSettings::instance()->proxyDns() )
|
if ( !TomahawkSettings::instance()->proxyDns() )
|
||||||
s_proxy->setCapabilities( QNetworkProxy::TunnelingCapability | QNetworkProxy::ListeningCapability | QNetworkProxy::UdpTunnelingCapability );
|
s_proxy->setCapabilities( QNetworkProxy::TunnelingCapability | QNetworkProxy::ListeningCapability | QNetworkProxy::UdpTunnelingCapability );
|
||||||
|
@@ -22,17 +22,22 @@
|
|||||||
|
|
||||||
#include <QtPlugin>
|
#include <QtPlugin>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QNetworkReply>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#include <qtweetaccountverifycredentials.h>
|
#include <qtweetaccountverifycredentials.h>
|
||||||
#include <qtweetuser.h>
|
#include <qtweetuser.h>
|
||||||
#include <qtweetstatus.h>
|
#include <qtweetstatus.h>
|
||||||
|
#include <qtweetusershow.h>
|
||||||
|
|
||||||
#include <utils/tomahawkutils.h>
|
#include <utils/tomahawkutils.h>
|
||||||
#include <tomahawksettings.h>
|
#include <tomahawksettings.h>
|
||||||
#include <database/database.h>
|
#include <database/database.h>
|
||||||
#include <network/servent.h>
|
#include <network/servent.h>
|
||||||
|
|
||||||
|
|
||||||
static QString s_gotTomahawkRegex = QString( "^(@[a-zA-Z0-9]+ )?(Got Tomahawk\\?) (\\{[a-fA-F0-9\\-]+\\}) (.*)$" );
|
static QString s_gotTomahawkRegex = QString( "^(@[a-zA-Z0-9]+ )?(Got Tomahawk\\?) (\\{[a-fA-F0-9\\-]+\\}) (.*)$" );
|
||||||
|
|
||||||
SipPlugin*
|
SipPlugin*
|
||||||
@@ -325,6 +330,7 @@ TwitterPlugin::connectTimerFired()
|
|||||||
{
|
{
|
||||||
qDebug() << "Aging peer " << screenName << " out of cache";
|
qDebug() << "Aging peer " << screenName << " out of cache";
|
||||||
m_cachedPeers.remove( screenName );
|
m_cachedPeers.remove( screenName );
|
||||||
|
m_cachedAvatars.remove( screenName );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -576,6 +582,9 @@ TwitterPlugin::registerOffer( const QString &screenName, const QHash< QString, Q
|
|||||||
|
|
||||||
QString friendlyName = QString( '@' + screenName );
|
QString friendlyName = QString( '@' + screenName );
|
||||||
|
|
||||||
|
if ( !m_cachedAvatars.contains( screenName ) )
|
||||||
|
QMetaObject::invokeMethod( this, "fetchAvatar", Q_ARG( QString, screenName ) );
|
||||||
|
|
||||||
QHash< QString, QVariant > _peerData( peerData );
|
QHash< QString, QVariant > _peerData( peerData );
|
||||||
|
|
||||||
if ( _peerData.contains( "dirty" ) )
|
if ( _peerData.contains( "dirty" ) )
|
||||||
@@ -700,6 +709,56 @@ TwitterPlugin::directMessageDestroyed( const QTweetDMStatus& message )
|
|||||||
qDebug() << "TwitterPlugin destroyed message " << message.text();
|
qDebug() << "TwitterPlugin destroyed message " << message.text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TwitterPlugin::fetchAvatar( const QString& screenName )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
QTweetUserShow *userShowFetch = new QTweetUserShow( m_twitterAuth.data(), this );
|
||||||
|
connect( userShowFetch, SIGNAL( parsedUserInfo( QTweetUser ) ), SLOT( avatarUserDataSlot( QTweetUser ) ) );
|
||||||
|
userShowFetch->fetch( screenName );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TwitterPlugin::avatarUserDataSlot( const QTweetUser &user )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
if ( user.profileImageUrl().isEmpty() || m_twitterAuth.isNull() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QNetworkRequest request( user.profileImageUrl() );
|
||||||
|
QNetworkReply *reply = m_twitterAuth.data()->networkAccessManager()->get( request );
|
||||||
|
reply->setProperty( "screenname", user.screenName() );
|
||||||
|
connect( reply, SIGNAL( finished() ), this, SLOT( profilePicReply() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TwitterPlugin::setProxy( const QNetworkProxy& proxy )
|
||||||
|
{
|
||||||
|
Q_UNUSED( proxy );
|
||||||
|
if ( !m_twitterAuth.isNull() )
|
||||||
|
m_twitterAuth.data()->setNetworkAccessManager( TomahawkUtils::nam() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TwitterPlugin::profilePicReply()
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
QNetworkReply *reply = qobject_cast< QNetworkReply* >( sender() );
|
||||||
|
if ( !reply || reply->error() != QNetworkReply::NoError || !reply->property( "screenname" ).isValid() )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << " reply not valid or came back with error";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QString screenName = reply->property( "screenname" ).toString();
|
||||||
|
QString friendlyName = '@' + screenName;
|
||||||
|
QByteArray rawData = reply->readAll();
|
||||||
|
QImage image;
|
||||||
|
image.loadFromData( rawData, "PNG" );
|
||||||
|
QPixmap pixmap = QPixmap::fromImage( image );
|
||||||
|
m_cachedAvatars[screenName] = pixmap;
|
||||||
|
emit avatarReceived( friendlyName, QPixmap::fromImage( image ) );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TwitterPlugin::checkSettings()
|
TwitterPlugin::checkSettings()
|
||||||
{
|
{
|
||||||
@@ -707,7 +766,6 @@ TwitterPlugin::checkSettings()
|
|||||||
connectPlugin( false );
|
connectPlugin( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
TwitterPlugin::twitterScreenName() const
|
TwitterPlugin::twitterScreenName() const
|
||||||
{
|
{
|
||||||
|
@@ -72,10 +72,14 @@ public:
|
|||||||
virtual QIcon icon() const;
|
virtual QIcon icon() const;
|
||||||
virtual QWidget* configWidget();
|
virtual QWidget* configWidget();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void avatarReceived( QString, QPixmap );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual bool connectPlugin( bool startup );
|
virtual bool connectPlugin( bool startup );
|
||||||
void disconnectPlugin();
|
void disconnectPlugin();
|
||||||
void checkSettings();
|
void checkSettings();
|
||||||
|
void setProxy( const QNetworkProxy &proxy );
|
||||||
|
|
||||||
void sendMsg( const QString& to, const QString& msg )
|
void sendMsg( const QString& to, const QString& msg )
|
||||||
{
|
{
|
||||||
@@ -109,6 +113,9 @@ private slots:
|
|||||||
void registerOffer( const QString &screenName, const QHash< QString, QVariant > &peerdata );
|
void registerOffer( const QString &screenName, const QHash< QString, QVariant > &peerdata );
|
||||||
void sendOffer( const QString &screenName, const QHash< QString, QVariant > &peerdata );
|
void sendOffer( const QString &screenName, const QHash< QString, QVariant > &peerdata );
|
||||||
void makeConnection( const QString &screenName, const QHash< QString, QVariant > &peerdata );
|
void makeConnection( const QString &screenName, const QHash< QString, QVariant > &peerdata );
|
||||||
|
void fetchAvatar( const QString &screenName );
|
||||||
|
void avatarUserDataSlot( const QTweetUser &user );
|
||||||
|
void profilePicReply();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool refreshTwitterAuth();
|
bool refreshTwitterAuth();
|
||||||
@@ -145,6 +152,7 @@ private:
|
|||||||
qint64 m_cachedMentionsSinceId;
|
qint64 m_cachedMentionsSinceId;
|
||||||
qint64 m_cachedDirectMessagesSinceId;
|
qint64 m_cachedDirectMessagesSinceId;
|
||||||
QHash< QString, QVariant > m_cachedPeers;
|
QHash< QString, QVariant > m_cachedPeers;
|
||||||
|
QHash< QString, QPixmap > m_cachedAvatars;
|
||||||
QSet<QString> m_keyCache;
|
QSet<QString> m_keyCache;
|
||||||
bool m_finishedFriends;
|
bool m_finishedFriends;
|
||||||
bool m_finishedMentions;
|
bool m_finishedMentions;
|
||||||
|
Reference in New Issue
Block a user