1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-08 10:02:29 +02:00

More twitter changeover to accounts work, mostly on sip -- does not

compile, does not work yet
This commit is contained in:
Jeff Mitchell 2011-10-04 19:34:44 -04:00
parent 60aec5ac0f
commit c3064d8249
11 changed files with 186 additions and 716 deletions

View File

@ -20,6 +20,8 @@
#include "twitterconfigwidget.h"
#include "sip/SipPlugin.h"
#include <QtCore/QtPlugin>
namespace Tomahawk
@ -68,6 +70,18 @@ TwitterAccount::configDialogAuthedSignalSlot( bool authed )
}
SipPlugin*
TwitterAccount::sipPlugin()
{
if ( m_twitterSipPlugin.isNull() )
{
m_twitterSipPlugin = QWeakPointer< TwitterSipPlugin >( new TwitterSipPlugin( this ) );
return m_twitterSipPlugin.data();
}
return m_twitterSipPlugin.data();
}
}
}

View File

@ -24,6 +24,7 @@
#include "twitterconfigwidget.h"
#include "tomahawkoauthtwitter.h"
#include "sip/twitter/twittersip.h"
#include "accounts/account.h"
#define MYNAME "ACCOUNTTWITTER"
@ -64,7 +65,7 @@ public:
bool isAuthenticated() { return m_isAuthenticated; }
Tomahawk::InfoSystem::InfoPlugin* infoPlugin() { return 0; }
SipPlugin* sipPlugin() { return 0; }
SipPlugin* sipPlugin();
QWidget* configurationWidget() { return m_configWidget.data(); }
QWidget* aclWidget() { return 0; }
@ -75,6 +76,7 @@ private slots:
private:
bool m_isAuthenticated;
QWeakPointer< TwitterConfigWidget > m_configWidget;
QWeakPointer< TwitterSipPlugin > m_twitterSipPlugin;
// for settings access
friend class TwitterConfigWidget;

View File

@ -27,13 +27,18 @@
#include "typedefs.h"
#include "dllmacro.h"
#include "infosystem/infosystem.h"
#include "sip/SipPlugin.h"
#include "tomahawksettings.h"
class SipPlugin;
namespace Tomahawk
{
namespace InfoSystem
{
class InfoPlugin;
}
namespace Accounts
{
@ -52,12 +57,14 @@ class DLLEXPORT Account : public QObject
public:
explicit Account( const QString &accountId )
: QObject()
, m_enabled( false )
, m_autoConnect( false )
, m_accountId( accountId ) {}
virtual ~Account() {}
virtual QString accountServiceName() const { return m_accountServiceName; } // e.g. "Twitter", "Last.fm"
virtual QString accountFriendlyName() const { return m_accountFriendlyName; } // e.g. screen name on the service, JID, etc.
virtual bool enabled() const { return m_enabled; }
virtual bool autoConnect() const { return m_autoConnect; }
virtual QString accountId() const { return m_accountId; }
@ -90,12 +97,9 @@ public:
return set;
}
signals:
void configurationChanged();
protected:
virtual void setAccountServiceName( const QString &serviceName ) { m_accountServiceName = serviceName; }
virtual void setAccountFriendlyName( const QString &friendlyName ) { m_accountFriendlyName = friendlyName; }
virtual void setEnabled( bool enabled ) { m_enabled = enabled; }
virtual void setAutoConnect( bool autoConnect ) { m_autoConnect = autoConnect; }
virtual void setAccountId( const QString &accountId ) { m_accountId = accountId; }
virtual void setCredentials( const QVariantHash &credentialHash ) { m_credentials = credentialHash; }
@ -103,7 +107,7 @@ protected:
virtual void setConfiguration( const QVariantHash &configuration ) { m_configuration = configuration; }
virtual void setAcl( const QVariantMap &acl ) { m_acl = acl; }
virtual void setTypes( const QSet< AccountType > types )
{
m_types = QStringList();
@ -128,6 +132,7 @@ protected:
TomahawkSettings* s = TomahawkSettings::instance();
s->beginGroup( "accounts/" + m_accountId );
m_accountFriendlyName = s->value( "accountFriendlyName", QString() ).toString();
m_enabled = s->value( "enabled", false ).toBool();
m_autoConnect = s->value( "autoConnect", false ).toBool();
m_credentials = s->value( "credentials", QVariantHash() ).toHash();
m_configuration = s->value( "configuration", QVariantHash() ).toHash();
@ -136,12 +141,13 @@ protected:
s->endGroup();
s->sync();
}
virtual void syncConfig()
{
TomahawkSettings* s = TomahawkSettings::instance();
s->beginGroup( "accounts/" + m_accountId );
s->setValue( "accountFriendlyName", m_accountFriendlyName );
s->setValue( "enabled", m_enabled );
s->setValue( "autoConnect", m_autoConnect );
s->setValue( "credentials", m_credentials );
s->setValue( "configuration", m_configuration );
@ -152,15 +158,20 @@ protected:
emit configurationChanged();
}
QString m_accountServiceName;
QString m_accountFriendlyName;
bool m_enabled;
bool m_autoConnect;
QString m_accountId;
QVariantHash m_credentials;
QVariantHash m_configuration;
QVariantMap m_acl;
QStringList m_types;
signals:
void configurationChanged();
};
class DLLEXPORT AccountFactory : public QObject

View File

@ -32,6 +32,7 @@
#include "sourcelist.h"
#include "tomahawksettings.h"
#include "utils/logger.h"
#include "accounts/accountmanager.h"
#include "config.h"
@ -54,8 +55,6 @@ SipHandler::SipHandler( QObject* parent )
{
s_instance = this;
loadPluginFactories( findPluginFactories() );
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) );
}
@ -87,13 +86,13 @@ SipHandler::avatar( const QString& name ) const
const SipInfo
SipHandler::sipInfo(const QString& peerId) const
SipHandler::sipInfo( const QString& peerId ) const
{
return m_peersSipInfos.value( peerId );
}
const QString
SipHandler::versionString(const QString& peerId) const
SipHandler::versionString( const QString& peerId ) const
{
return m_peersSoftwareVersions.value( peerId );
}
@ -106,103 +105,6 @@ SipHandler::onSettingsChanged()
}
QStringList
SipHandler::findPluginFactories()
{
QStringList paths;
QList< QDir > pluginDirs;
QDir appDir( qApp->applicationDirPath() );
#ifdef Q_WS_MAC
if ( appDir.dirName() == "MacOS" )
{
// Development convenience-hack
appDir.cdUp();
appDir.cdUp();
appDir.cdUp();
}
#endif
QDir libDir( CMAKE_INSTALL_PREFIX "/lib" );
QDir lib64Dir( appDir );
lib64Dir.cdUp();
lib64Dir.cd( "lib64" );
pluginDirs << appDir << libDir << lib64Dir << QDir( qApp->applicationDirPath() );
foreach ( const QDir& pluginDir, pluginDirs )
{
qDebug() << "Checking directory for plugins:" << pluginDir;
foreach ( QString fileName, pluginDir.entryList( QStringList() << "*tomahawk_sip*.so" << "*tomahawk_sip*.dylib" << "*tomahawk_sip*.dll", QDir::Files ) )
{
if ( fileName.startsWith( "libtomahawk_sip" ) )
{
const QString path = pluginDir.absoluteFilePath( fileName );
if ( !paths.contains( path ) )
paths << path;
}
}
}
return paths;
}
void
SipHandler::loadPluginFactories( const QStringList& paths )
{
foreach ( QString fileName, paths )
{
if ( !QLibrary::isLibrary( fileName ) )
continue;
qDebug() << "Trying to load plugin:" << fileName;
loadPluginFactory( fileName );
}
}
SipPlugin*
SipHandler::createPlugin( const QString& factoryId )
{
Q_ASSERT( m_pluginFactories.contains( factoryId ) );
SipPlugin* sip = m_pluginFactories[ factoryId ]->createPlugin();
hookUpPlugin( sip );
emit pluginAdded( sip );
return sip;
}
SipPlugin*
SipHandler::loadPlugin( const QString& pluginId )
{
QString factoryName = factoryFromId( pluginId );
Q_ASSERT( m_pluginFactories.contains( factoryName ) );
SipPlugin* sip = m_pluginFactories[ factoryName ]->createPlugin( pluginId );
// caller responsible for calling pluginAdded() and hookupPlugin
return sip;
}
void
SipHandler::removePlugin( SipPlugin* p )
{
p->disconnectPlugin();
m_allPlugins.removeAll( p );
m_enabledPlugins.removeAll( p );
TomahawkSettings::instance()->removeSipPlugin( p->pluginId() );
emit pluginRemoved( p );
}
void
SipHandler::hookUpPlugin( SipPlugin* sip )
{
@ -217,28 +119,8 @@ SipHandler::hookUpPlugin( SipPlugin* sip )
QObject::connect( sip, SIGNAL( avatarReceived( QString, QPixmap ) ), SLOT( onAvatarReceived( QString, QPixmap ) ) );
QObject::connect( sip, SIGNAL( avatarReceived( QPixmap ) ), SLOT( onAvatarReceived( QPixmap ) ) );
}
void
SipHandler::loadPluginFactory( const QString& path )
{
QPluginLoader loader( path );
QObject* plugin = loader.instance();
if ( !plugin )
{
qDebug() << "Error loading plugin:" << loader.errorString();
}
SipPluginFactory* sipfactory = qobject_cast<SipPluginFactory*>(plugin);
if ( sipfactory )
{
qDebug() << "Loaded plugin factory:" << loader.fileName() << sipfactory->factoryId() << sipfactory->prettyName();
m_pluginFactories[ sipfactory->factoryId() ] = sipfactory;
} else
{
qDebug() << "Loaded invalid plugin.." << loader.fileName();
}
QObject::connect( sip->account(), SIGNAL( configurationChanged() ), sip, SLOT( configurationChanged() ) );
}
@ -266,16 +148,12 @@ SipHandler::checkSettings()
void
SipHandler::addSipPlugin( SipPlugin* p, bool enabled )
SipHandler::addSipPlugin( SipPlugin* p )
{
m_allPlugins << p;
hookUpPlugin( p );
if ( enabled )
{
p->connectPlugin();
m_enabledPlugins << p;
}
p->connectPlugin();
emit pluginAdded( p );
}
@ -285,41 +163,21 @@ void
SipHandler::removeSipPlugin( SipPlugin* p )
{
p->disconnectPlugin();
p->deletePlugin();
emit pluginRemoved( p );
// emit first so sipmodel can find the indexOf
TomahawkSettings::instance()->removeSipPlugin( p->pluginId() );
m_allPlugins.removeAll( p );
m_enabledPlugins.removeAll( p );
}
bool
SipHandler::hasPluginType( const QString& factoryId ) const
{
foreach( SipPlugin* p, m_allPlugins ) {
if( factoryFromId( p->pluginId() ) == factoryId )
return true;
}
return false;
}
void
SipHandler::loadFromConfig()
SipHandler::loadFromAccountManager()
{
QStringList pluginIds = TomahawkSettings::instance()->sipPlugins();
QStringList enabled = TomahawkSettings::instance()->enabledSipPlugins();
foreach( const QString& pluginId, pluginIds )
QList< Tomahawk::Accounts::Account* > accountList = Tomahawk::Accounts::AccountManager::instance()->getAccounts( Tomahawk::Accounts::SipType );
foreach( const Tomahawk::Accounts::Account* account, accountList )
{
QString pluginFactory = factoryFromId( pluginId );
if( m_pluginFactories.contains( pluginFactory ) )
{
SipPlugin* p = loadPlugin( pluginId );
addSipPlugin( p, enabled.contains( pluginId ) );
}
SipPlugin* p = account->sipPlugin();
addSipPlugin( p );
}
m_connected = true;
}
@ -328,7 +186,7 @@ SipHandler::loadFromConfig()
void
SipHandler::connectAll()
{
foreach( SipPlugin* sip, m_enabledPlugins )
foreach( SipPlugin* sip, m_allPlugins )
{
sip->connectPlugin();
}
@ -347,29 +205,6 @@ SipHandler::disconnectAll()
}
void
SipHandler::disablePlugin( SipPlugin* p )
{
Q_ASSERT( m_enabledPlugins.contains( p ) );
TomahawkSettings::instance()->disableSipPlugin( p->pluginId() );
p->disconnectPlugin();
m_enabledPlugins.removeAll( p );
}
void
SipHandler::enablePlugin( SipPlugin* p )
{
Q_ASSERT( !m_enabledPlugins.contains( p ) );
p->connectPlugin();
TomahawkSettings::instance()->enableSipPlugin( p->pluginId() );
m_enabledPlugins << p;
}
void
SipHandler::connectPlugin( const QString &pluginId )
{
@ -392,7 +227,7 @@ SipHandler::connectPlugin( const QString &pluginId )
{
if ( sip->pluginId() == pluginId )
{
Q_ASSERT( m_enabledPlugins.contains( sip ) ); // make sure the plugin we're connecting is enabled. should always be the case
Q_ASSERT( m_allPlugins.contains( sip ) ); // make sure the plugin we're connecting is enabled. should always be the case
//each sip should refreshProxy() or take care of that function in some other way during connection
sip->connectPlugin();
}
@ -418,13 +253,6 @@ SipHandler::allPlugins() const
}
QList< SipPlugin* >
SipHandler::enabledPlugins() const
{
return m_enabledPlugins;
}
QList< SipPlugin* >
SipHandler::connectedPlugins() const
{
@ -432,13 +260,6 @@ SipHandler::connectedPlugins() const
}
QList< SipPluginFactory* >
SipHandler::pluginFactories() const
{
return m_pluginFactories.values();
}
void
SipHandler::toggleConnect()
{
@ -644,18 +465,3 @@ SipHandler::onAvatarReceived( const QPixmap& avatar )
// qDebug() << Q_FUNC_INFO << "Set own avatar on MyCollection";
SourceList::instance()->getLocal()->setAvatar( avatar );
}
QString
SipHandler::factoryFromId( const QString& pluginId ) const
{
return pluginId.split( "_" ).first();
}
SipPluginFactory*
SipHandler::factoryFromPlugin( SipPlugin* p ) const
{
QString factoryId = factoryFromId( p->pluginId() );
return m_pluginFactories.value( factoryId, 0 );
}

View File

@ -39,9 +39,8 @@ public:
QList< SipPluginFactory* > pluginFactories() const;
QList< SipPlugin* > allPlugins() const;
QList< SipPlugin* > enabledPlugins() const;
QList< SipPlugin* > connectedPlugins() const;
void loadFromConfig();
void loadFromAccountManager();
void addSipPlugin( SipPlugin* p, bool enable = true );
void removeSipPlugin( SipPlugin* p );

View File

@ -19,24 +19,15 @@
#include "sip/SipPlugin.h"
#include <QUuid>
#include "utils/logger.h"
QString
SipPluginFactory::generateId()
{
QString uniq = QUuid::createUuid().toString().mid( 1, 8 );
return factoryId() + "_" + uniq;
}
SipPlugin::SipPlugin() : QObject() {}
SipPlugin::~SipPlugin() {}
SipPlugin::SipPlugin( const QString& pluginId, QObject* parent )
SipPlugin::SipPlugin( Tomahawk::Accounts::Account *account, QObject* parent )
: QObject( parent )
, m_pluginId( pluginId )
, m_account( account )
{
connect( this, SIGNAL( error( int, QString ) ), this, SLOT( onError( int,QString ) ) );
connect( this, SIGNAL( stateChanged( SipPlugin::ConnectionState ) ), this, SLOT( onStateChange( SipPlugin::ConnectionState ) ) );
@ -48,7 +39,21 @@ SipPlugin::SipPlugin( const QString& pluginId, QObject* parent )
QString
SipPlugin::pluginId() const
{
return m_pluginId;
return m_account->accountId();
}
const QString
SipPlugin::friendlyName() const
{
return m_account->accountFriendlyName();
}
const QString
SipPlugin::serviceName() const
{
return m_account->accountServiceName();
}
@ -59,10 +64,10 @@ SipPlugin::menu()
}
QWidget*
SipPlugin::configWidget()
Tomahawk::Accounts::Account*
SipPlugin::account() const
{
return 0;
return m_account;
}
@ -76,7 +81,7 @@ SipPlugin::errorMessage() const
QIcon
SipPlugin::icon() const
{
return QIcon();
return m_account->icon();
}

View File

@ -27,31 +27,12 @@
#include <QMenu>
#include <QNetworkProxy>
#include "accounts/account.h"
#include "dllmacro.h"
class SipPlugin;
class DLLEXPORT SipPluginFactory : public QObject
{
Q_OBJECT
public:
SipPluginFactory() {}
virtual ~SipPluginFactory() {}
// display name for plugin
virtual QString prettyName() const = 0;
// internal name
virtual QString factoryId() const = 0;
// if the user can create multiple
virtual QIcon icon() const { return QIcon(); }
virtual bool isUnique() const { return false; }
virtual SipPlugin* createPlugin( const QString& pluginId = QString() ) = 0;
protected:
QString generateId();
};
class DLLEXPORT SipPlugin : public QObject
{
Q_OBJECT
@ -61,23 +42,20 @@ public:
enum ConnectionState { Disconnected, Connecting, Connected, Disconnecting };
SipPlugin();
explicit SipPlugin( const QString& pluginId, QObject* parent = 0 );
explicit SipPlugin( Tomahawk::Accounts::Account *account, QObject* parent = 0 );
virtual ~SipPlugin();
// plugin id is "pluginfactoryname_someuniqueid". get it from SipPluginFactory::generateId
QString pluginId() const;
virtual bool isValid() const = 0;
virtual const QString name() const = 0;
virtual const QString friendlyName() const = 0;
virtual const QString accountName() const = 0;
virtual const QString friendlyName() const;
virtual const QString serviceName() const;
virtual ConnectionState connectionState() const = 0;
virtual QString errorMessage() const;
virtual QMenu* menu();
virtual QWidget* configWidget();
virtual void saveConfig() {} // called when the widget has been edited
virtual QIcon icon() const;
virtual Tomahawk::Accounts::Account* account() const;
// peer infos
virtual const QStringList peersOnline() const;
@ -85,6 +63,7 @@ public slots:
virtual bool connectPlugin() = 0;
virtual void disconnectPlugin() = 0;
virtual void checkSettings() = 0;
virtual void configurationChanged() = 0;
virtual void addContact( const QString &jid, const QString& msg = QString() ) = 0;
virtual void sendMsg( const QString& to, const QString& msg ) = 0;
@ -124,11 +103,9 @@ private slots:
void onPeerOffline( const QString &peerId );
private:
QString m_pluginId;
Tomahawk::Accounts::Account *m_account;
QString m_cachedError;
QStringList m_peersOnline;
};
Q_DECLARE_INTERFACE( SipPluginFactory, "tomahawk.SipFactory/1.0" )
#endif

View File

@ -1,9 +1,9 @@
IF( LIBJREEN_FOUND )
ADD_SUBDIRECTORY( jabber )
ENDIF( LIBJREEN_FOUND )
#IF( LIBJREEN_FOUND )
# ADD_SUBDIRECTORY( jabber )
#ENDIF( LIBJREEN_FOUND )
IF( QTWEETLIB_FOUND )
ADD_SUBDIRECTORY( twitter )
ENDIF( QTWEETLIB_FOUND )
ADD_SUBDIRECTORY( zeroconf )
#ADD_SUBDIRECTORY( zeroconf )

View File

@ -42,21 +42,10 @@
static QString s_gotTomahawkRegex = QString( "^(@[a-zA-Z0-9]+ )?(Got Tomahawk\\?) (\\{[a-fA-F0-9\\-]+\\}) (.*)$" );
SipPlugin*
TwitterFactory::createPlugin( const QString& pluginId )
{
return new TwitterPlugin( pluginId.isEmpty() ? generateId() : pluginId );
}
QIcon TwitterFactory::icon() const
{
return QIcon( ":/twitter-icon.png" );
}
TwitterPlugin::TwitterPlugin( const QString& pluginId )
: SipPlugin( pluginId )
TwitterSipPlugin::TwitterSipPlugin( Tomahawk::Accounts::Account* account )
: SipPlugin( account )
, m_configuration( account->configuration() )
, m_credentials( account->credentials() )
, m_isAuthed( false )
, m_checkTimer( this )
, m_connectTimer( this )
@ -70,10 +59,12 @@ TwitterPlugin::TwitterPlugin( const QString& pluginId )
{
qDebug() << Q_FUNC_INFO;
if ( Database::instance()->dbid() != twitterSavedDbid() )
setTwitterCachedPeers( QVariantHash() );
setTwitterSavedDbid( Database::instance()->dbid() );
if ( Database::instance()->dbid() != m_configuration[ "savedDbid" ].toString() )
{
m_configuration[ "cachedPeers" ] = QVariantHash();
m_configuration[ "savedDbid" ] = Database::instance()->dbid();
syncConfig();
}
m_checkTimer.setInterval( 180000 );
m_checkTimer.setSingleShot( false );
@ -89,92 +80,44 @@ TwitterPlugin::TwitterPlugin( const QString& pluginId )
}
void
TwitterPlugin::configDialogAuthedSignalSlot( bool authed )
{
if ( !authed )
{
if( m_isAuthed ) {
m_state = Disconnected;
emit stateChanged( m_state );
}
setTwitterScreenName( QString() );
setTwitterOAuthToken( QString() );
setTwitterOAuthTokenSecret( QString() );
}
m_isAuthed = authed;
}
bool
TwitterPlugin::isValid() const
TwitterSipPlugin::isValid() const
{
return m_isAuthed;
}
const QString
TwitterPlugin::name() const
{
return QString( MYNAME );
}
const QString
TwitterPlugin::friendlyName() const
{
return tr("Twitter");
}
const QString
TwitterPlugin::accountName() const
{
if( twitterScreenName().isEmpty() )
return friendlyName();
else
return twitterScreenName();
}
QIcon
TwitterPlugin::icon() const
{
return QIcon( ":/twitter-icon.png" );
return m_account->enabled() && m_isAuthed;
}
SipPlugin::ConnectionState
TwitterPlugin::connectionState() const
TwitterSipPlugin::connectionState() const
{
return m_state;
}
QWidget* TwitterPlugin::configWidget()
{
return m_configWidget.data();
}
bool
TwitterPlugin::connectPlugin()
TwitterSipPlugin::connectPlugin()
{
qDebug() << Q_FUNC_INFO;
m_cachedPeers = twitterCachedPeers();
if ( !m_account->enabled() )
return;
m_cachedPeers = m_configuration[ "cachedPeers" ].toHash();
QStringList peerList = m_cachedPeers.keys();
qStableSort( peerList.begin(), peerList.end() );
registerOffers( peerList );
if ( twitterOAuthToken().isEmpty() || twitterOAuthTokenSecret().isEmpty() )
if ( m_credentials[ "oauthToken" ].toString().isEmpty() || m_credentials[ "oauthTokenSecret" ].toString().isEmpty() )
{
qDebug() << "TwitterPlugin has empty Twitter credentials; not connecting";
qDebug() << "TwitterSipPlugin has empty Twitter credentials; not connecting";
return m_cachedPeers.isEmpty();
}
if ( refreshTwitterAuth() )
{
QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( m_twitterAuth.data(), this );
connect( credVerifier, SIGNAL( parsedUser(const QTweetUser &) ), SLOT( connectAuthVerifyReply(const QTweetUser &) ) );
connect( credVerifier, SIGNAL( parsedUser( const QTweetUser & ) ), SLOT( connectAuthVerifyReply( const QTweetUser & ) ) );
credVerifier->verify();
m_state = Connecting;
@ -185,7 +128,7 @@ TwitterPlugin::connectPlugin()
}
bool
TwitterPlugin::refreshTwitterAuth()
TwitterSipPlugin::refreshTwitterAuth()
{
qDebug() << Q_FUNC_INFO << " begin";
if( !m_twitterAuth.isNull() )
@ -198,14 +141,14 @@ TwitterPlugin::refreshTwitterAuth()
if( m_twitterAuth.isNull() )
return false;
m_twitterAuth.data()->setOAuthToken( twitterOAuthToken().toLatin1() );
m_twitterAuth.data()->setOAuthTokenSecret( twitterOAuthTokenSecret().toLatin1() );
m_twitterAuth.data()->setOAuthToken( m_credentials[ "oauthToken" ].toString().toLatin1() );
m_twitterAuth.data()->setOAuthTokenSecret( m_credentials[ "oauthTokenSecret" ].toString().toLatin1() );
return true;
}
void
TwitterPlugin::disconnectPlugin()
TwitterSipPlugin::disconnectPlugin()
{
qDebug() << Q_FUNC_INFO;
m_checkTimer.stop();
@ -224,6 +167,7 @@ TwitterPlugin::disconnectPlugin()
if( !m_twitterAuth.isNull() )
delete m_twitterAuth.data();
m_configuration[ "cachedPeers" ] = m_cachedPeers;
syncConfig();
m_cachedPeers.empty();
m_state = Disconnected;
@ -231,11 +175,11 @@ TwitterPlugin::disconnectPlugin()
}
void
TwitterPlugin::connectAuthVerifyReply( const QTweetUser &user )
TwitterSipPlugin::connectAuthVerifyReply( const QTweetUser &user )
{
if ( user.id() == 0 )
{
qDebug() << "TwitterPlugin could not authenticate to Twitter";
qDebug() << "TwitterSipPlugin could not authenticate to Twitter";
m_isAuthed = false;
m_state = Disconnected;
m_connectTimer.stop();
@ -245,11 +189,12 @@ TwitterPlugin::connectAuthVerifyReply( const QTweetUser &user )
}
else
{
qDebug() << "TwitterPlugin successfully authenticated to Twitter as user " << user.screenName();
qDebug() << "TwitterSipPlugin successfully authenticated to Twitter as user " << user.screenName();
m_isAuthed = true;
if ( !m_twitterAuth.isNull() )
{
setTwitterScreenName( user.screenName() );
m_configuration[ "screenName" ] = user.screenName;
syncConfig();
m_friendsTimeline = QWeakPointer<QTweetFriendsTimeline>( new QTweetFriendsTimeline( m_twitterAuth.data(), this ) );
m_mentions = QWeakPointer<QTweetMentions>( new QTweetMentions( m_twitterAuth.data(), this ) );
m_directMessages = QWeakPointer<QTweetDirectMessages>( new QTweetDirectMessages( m_twitterAuth.data(), this ) );
@ -279,7 +224,7 @@ TwitterPlugin::connectAuthVerifyReply( const QTweetUser &user )
}
else
{
qDebug() << "TwitterPlugin auth pointer was null!";
qDebug() << "TwitterSipPlugin auth pointer was null!";
m_isAuthed = false;
m_state = Disconnected;
m_connectTimer.stop();
@ -291,30 +236,25 @@ TwitterPlugin::connectAuthVerifyReply( const QTweetUser &user )
}
}
void
TwitterPlugin::deletePlugin()
{
TomahawkSettings::instance()->remove( pluginId() );
}
void
TwitterPlugin::checkTimerFired()
TwitterSipPlugin::checkTimerFired()
{
if ( !isValid() || m_twitterAuth.isNull() )
return;
if ( m_cachedFriendsSinceId == 0 )
m_cachedFriendsSinceId = twitterCachedFriendsSinceId();
m_cachedFriendsSinceId = m_configuration[ "cachedFriendsSinceId" ].toLongLong();
qDebug() << "TwitterPlugin looking at friends timeline since id " << m_cachedFriendsSinceId;
qDebug() << "TwitterSipPlugin looking at friends timeline since id " << m_cachedFriendsSinceId;
if ( !m_friendsTimeline.isNull() )
m_friendsTimeline.data()->fetch( m_cachedFriendsSinceId, 0, 800 );
if ( m_cachedMentionsSinceId == 0 )
m_cachedMentionsSinceId = twitterCachedMentionsSinceId();
m_cachedMentionsSinceId = m_configuration[ "cachedMentionsSinceId" ].toLongLong();
qDebug() << "TwitterPlugin looking at mentions timeline since id " << m_cachedMentionsSinceId;
qDebug() << "TwitterSipPlugin looking at mentions timeline since id " << m_cachedMentionsSinceId;
if ( !m_mentions.isNull() )
m_mentions.data()->fetch( m_cachedMentionsSinceId, 0, 800 );
@ -322,7 +262,7 @@ TwitterPlugin::checkTimerFired()
void
TwitterPlugin::registerOffers( const QStringList &peerList )
TwitterSipPlugin::registerOffers( const QStringList &peerList )
{
foreach( QString screenName, peerList )
{
@ -331,6 +271,7 @@ TwitterPlugin::registerOffers( const QStringList &peerList )
if ( peerData.contains( "onod" ) && peerData["onod"] != Database::instance()->dbid() )
{
m_cachedPeers.remove( screenName );
m_configuration[ "cachedPeers" ] = m_cachedPeers;
syncConfig();
}
@ -338,6 +279,7 @@ TwitterPlugin::registerOffers( const QStringList &peerList )
{
peerData["lastseen"] = QDateTime::currentMSecsSinceEpoch();
m_cachedPeers[screenName] = peerData;
m_configuration[ "cachedPeers" ] = m_cachedPeers;
syncConfig();
qDebug() << Q_FUNC_INFO << " already connected";
continue;
@ -346,6 +288,7 @@ TwitterPlugin::registerOffers( const QStringList &peerList )
{
qDebug() << Q_FUNC_INFO << " aging peer " << screenName << " out of cache";
m_cachedPeers.remove( screenName );
m_configuration[ "cachedPeers" ] = m_cachedPeers;
syncConfig();
m_cachedAvatars.remove( screenName );
continue;
@ -353,7 +296,7 @@ TwitterPlugin::registerOffers( const QStringList &peerList )
if ( !peerData.contains( "host" ) || !peerData.contains( "port" ) || !peerData.contains( "pkey" ) )
{
qDebug() << "TwitterPlugin does not have host, port and/or pkey values for " << screenName << " (this is usually *not* a bug or problem but a normal part of the process)";
qDebug() << "TwitterSipPlugin does not have host, port and/or pkey values for " << screenName << " (this is usually *not* a bug or problem but a normal part of the process)";
continue;
}
@ -363,7 +306,7 @@ TwitterPlugin::registerOffers( const QStringList &peerList )
void
TwitterPlugin::connectTimerFired()
TwitterSipPlugin::connectTimerFired()
{
qDebug() << Q_FUNC_INFO << " beginning";
if ( !isValid() || m_cachedPeers.isEmpty() || m_twitterAuth.isNull() )
@ -378,21 +321,21 @@ TwitterPlugin::connectTimerFired()
}
qDebug() << Q_FUNC_INFO << " continuing";
QString myScreenName = twitterScreenName();
QString myScreenName = m_configuration[ "screenName" ].toString();
QStringList peerList = m_cachedPeers.keys();
qStableSort( peerList.begin(), peerList.end() );
registerOffers( peerList );
}
void
TwitterPlugin::parseGotTomahawk( const QRegExp &regex, const QString &screenName, const QString &text )
TwitterSipPlugin::parseGotTomahawk( const QRegExp &regex, const QString &screenName, const QString &text )
{
QString myScreenName = twitterScreenName();
qDebug() << "TwitterPlugin found an exact matching Got Tomahawk? mention or direct message from user " << screenName << ", now parsing";
QString myScreenName = m_configuration[ "screenName" ].toString();
qDebug() << "TwitterSipPlugin found an exact matching Got Tomahawk? mention or direct message from user " << screenName << ", now parsing";
regex.exactMatch( text );
if ( text.startsWith( '@' ) && regex.captureCount() >= 2 && regex.cap( 1 ) != QString( '@' + myScreenName ) )
{
qDebug() << "TwitterPlugin skipping mention because it's directed @someone that isn't us";
qDebug() << "TwitterSipPlugin skipping mention because it's directed @someone that isn't us";
return;
}
@ -408,11 +351,11 @@ TwitterPlugin::parseGotTomahawk( const QRegExp &regex, const QString &screenName
}
if ( node.isEmpty() )
{
qDebug() << "TwitterPlugin could not parse node out of the tweet";
qDebug() << "TwitterSipPlugin could not parse node out of the tweet";
return;
}
else
qDebug() << "TwitterPlugin parsed node " << node << " out of the tweet";
qDebug() << "TwitterSipPlugin parsed node " << node << " out of the tweet";
if ( node == Database::instance()->dbid() )
{
@ -434,7 +377,7 @@ TwitterPlugin::parseGotTomahawk( const QRegExp &regex, const QString &screenName
}
void
TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses )
TwitterSipPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses )
{
qDebug() << Q_FUNC_INFO;
QRegExp regex( s_gotTomahawkRegex, Qt::CaseSensitive, QRegExp::RegExp2 );
@ -459,15 +402,16 @@ TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses )
if ( status.id() > m_cachedFriendsSinceId )
m_cachedFriendsSinceId = status.id();
qDebug() << "TwitterPlugin checking mention from " << status.user().screenName() << " with content " << status.text();
qDebug() << "TwitterSipPlugin checking mention from " << status.user().screenName() << " with content " << status.text();
parseGotTomahawk( regex, status.user().screenName(), status.text() );
}
setTwitterCachedFriendsSinceId( m_cachedFriendsSinceId );
m_configuration[ "cachedFriendsSinceId" ] = m_cachedFriendsSinceId;
syncConfig();
}
void
TwitterPlugin::mentionsStatuses( const QList< QTweetStatus > &statuses )
TwitterSipPlugin::mentionsStatuses( const QList< QTweetStatus > &statuses )
{
qDebug() << Q_FUNC_INFO;
QRegExp regex( s_gotTomahawkRegex, Qt::CaseSensitive, QRegExp::RegExp2 );
@ -492,35 +436,36 @@ TwitterPlugin::mentionsStatuses( const QList< QTweetStatus > &statuses )
if ( status.id() > m_cachedMentionsSinceId )
m_cachedMentionsSinceId = status.id();
qDebug() << "TwitterPlugin checking mention from " << status.user().screenName() << " with content " << status.text();
qDebug() << "TwitterSipPlugin checking mention from " << status.user().screenName() << " with content " << status.text();
parseGotTomahawk( regex, status.user().screenName(), status.text() );
}
setTwitterCachedMentionsSinceId( m_cachedMentionsSinceId );
m_configuration[ "cachedMentionsSinceId" ] = m_cachedMentionsSinceId;
syncConfig();
}
void
TwitterPlugin::pollDirectMessages()
TwitterSipPlugin::pollDirectMessages()
{
if ( !isValid() )
return;
if ( m_cachedDirectMessagesSinceId == 0 )
m_cachedDirectMessagesSinceId = twitterCachedDirectMessagesSinceId();
m_cachedDirectMessagesSinceId = m_configuration[ "cachedDirectMentionsSinceId" ].toLongLong();
qDebug() << "TwitterPlugin looking for direct messages since id " << m_cachedDirectMessagesSinceId;
qDebug() << "TwitterSipPlugin looking for direct messages since id " << m_cachedDirectMessagesSinceId;
if ( !m_directMessages.isNull() )
m_directMessages.data()->fetch( m_cachedDirectMessagesSinceId, 0, 800 );
}
void
TwitterPlugin::directMessages( const QList< QTweetDMStatus > &messages )
TwitterSipPlugin::directMessages( const QList< QTweetDMStatus > &messages )
{
qDebug() << Q_FUNC_INFO;
QRegExp regex( s_gotTomahawkRegex, Qt::CaseSensitive, QRegExp::RegExp2 );
QString myScreenName = twitterScreenName();
QString myScreenName = m_configuration[ "screenName" ].toString();
QHash< QString, QTweetDMStatus > latestHash;
foreach ( QTweetDMStatus status, messages )
@ -550,7 +495,7 @@ TwitterPlugin::directMessages( const QList< QTweetDMStatus > &messages )
foreach( QTweetDMStatus status, latestHash.values() )
{
qDebug() << "TwitterPlugin checking direct message from " << status.senderScreenName() << " with content " << status.text();
qDebug() << "TwitterSipPlugin checking direct message from " << status.senderScreenName() << " with content " << status.text();
if ( status.id() > m_cachedDirectMessagesSinceId )
m_cachedDirectMessagesSinceId = status.id();
@ -559,7 +504,7 @@ TwitterPlugin::directMessages( const QList< QTweetDMStatus > &messages )
else
{
QStringList splitList = status.text().split(':');
qDebug() << "TwitterPlugin found " << splitList.length() << " parts to the message; the parts are:";
qDebug() << "TwitterSipPlugin found " << splitList.length() << " parts to the message; the parts are:";
foreach( QString part, splitList )
qDebug() << part;
//validity is checked above
@ -573,7 +518,7 @@ TwitterPlugin::directMessages( const QList< QTweetDMStatus > &messages )
qDebug() << "Old-style node info found, ignoring";
continue;
}
qDebug() << "TwitterPlugin found a peerstart message from " << status.senderScreenName() << " with host " << host << " and port " << port << " and pkey " << pkey << " and node " << splitNode[0] << " destined for node " << splitNode[1];
qDebug() << "TwitterSipPlugin found a peerstart message from " << status.senderScreenName() << " with host " << host << " and port " << port << " and pkey " << pkey << " and node " << splitNode[0] << " destined for node " << splitNode[1];
QVariantHash peerData = ( m_cachedPeers.contains( status.senderScreenName() ) ) ?
@ -590,18 +535,19 @@ TwitterPlugin::directMessages( const QList< QTweetDMStatus > &messages )
if ( Database::instance()->dbid().startsWith( splitNode[1] ) )
{
qDebug() << "TwitterPlugin found message destined for this node; destroying it";
qDebug() << "TwitterSipPlugin found message destined for this node; destroying it";
if ( !m_directMessageDestroy.isNull() )
m_directMessageDestroy.data()->destroyMessage( status.id() );
}
}
}
setTwitterCachedDirectMessagesSinceId( m_cachedDirectMessagesSinceId );
m_configuration[ "cachedDirectMessagesSinceId" ] = m_cachedDirectMessagesSinceId;
syncConfig();
}
void
TwitterPlugin::registerOffer( const QString &screenName, const QVariantHash &peerData )
TwitterSipPlugin::registerOffer( const QString &screenName, const QVariantHash &peerData )
{
qDebug() << Q_FUNC_INFO;
@ -656,26 +602,27 @@ TwitterPlugin::registerOffer( const QString &screenName, const QVariantHash &pee
if( needToAddToCache && _peerData.contains( "node" ) )
{
qDebug() << "TwitterPlugin registering offer to " << friendlyName << " with node " << _peerData["node"].toString() << " and offeredkey " << _peerData["okey"].toString();
qDebug() << "TwitterSipPlugin registering offer to " << friendlyName << " with node " << _peerData["node"].toString() << " and offeredkey " << _peerData["okey"].toString();
m_keyCache << Servent::instance()->createConnectionKey( friendlyName, _peerData["node"].toString(), _peerData["okey"].toString(), false );
}
if( needToSend && _peerData.contains( "node") )
{
qDebug() << "TwitterPlugin needs to send and has node";
qDebug() << "TwitterSipPlugin needs to send and has node";
_peerData["ohst"] = QVariant::fromValue< QString >( Servent::instance()->externalAddress() );
_peerData["oprt"] = QVariant::fromValue< int >( Servent::instance()->externalPort() );
peersChanged = true;
if( !Servent::instance()->externalAddress().isEmpty() && !Servent::instance()->externalPort() == 0 )
QMetaObject::invokeMethod( this, "sendOffer", Q_ARG( QString, screenName ), Q_ARG( QVariantHash, _peerData ) );
else
qDebug() << "TwitterPlugin did not send offer because external address is " << Servent::instance()->externalAddress() << " and external port is " << Servent::instance()->externalPort();
qDebug() << "TwitterSipPlugin did not send offer because external address is " << Servent::instance()->externalAddress() << " and external port is " << Servent::instance()->externalPort();
}
if ( peersChanged )
{
_peerData["lastseen"] = QString::number( QDateTime::currentMSecsSinceEpoch() );
m_cachedPeers[screenName] = QVariant::fromValue< QVariantHash >( _peerData );
m_configuration[ "cachedPeers" ] = m_cachedPeers;
syncConfig();
}
@ -685,7 +632,7 @@ TwitterPlugin::registerOffer( const QString &screenName, const QVariantHash &pee
}
void
TwitterPlugin::sendOffer( const QString &screenName, const QVariantHash &peerData )
TwitterSipPlugin::sendOffer( const QString &screenName, const QVariantHash &peerData )
{
qDebug() << Q_FUNC_INFO;
QString offerString = QString( "TOMAHAWKPEER:Host=%1:Port=%2:Node=%3*%4:PKey=%5" ).arg( peerData["ohst"].toString() )
@ -693,26 +640,26 @@ TwitterPlugin::sendOffer( const QString &screenName, const QVariantHash &peerDat
.arg( Database::instance()->dbid() )
.arg( peerData["node"].toString().left( 8 ) )
.arg( peerData["okey"].toString() );
qDebug() << "TwitterPlugin sending message to " << screenName << ": " << offerString;
qDebug() << "TwitterSipPlugin sending message to " << screenName << ": " << offerString;
if( !m_directMessageNew.isNull() )
m_directMessageNew.data()->post( screenName, offerString );
}
void
TwitterPlugin::makeConnection( const QString &screenName, const QVariantHash &peerData )
TwitterSipPlugin::makeConnection( const QString &screenName, const QVariantHash &peerData )
{
qDebug() << Q_FUNC_INFO;
if ( !peerData.contains( "host" ) || !peerData.contains( "port" ) || !peerData.contains( "pkey" ) || !peerData.contains( "node" ) ||
peerData["host"].toString().isEmpty() || peerData["port"].toString().isEmpty() || peerData["pkey"].toString().isEmpty() || peerData["node"].toString().isEmpty() )
{
qDebug() << "TwitterPlugin could not find host and/or port and/or pkey and/or node for peer " << screenName;
qDebug() << "TwitterSipPlugin could not find host and/or port and/or pkey and/or node for peer " << screenName;
return;
}
if ( peerData["host"].toString() == Servent::instance()->externalAddress() &&
peerData["port"].toInt() == Servent::instance()->externalPort() )
{
qDebug() << "TwitterPlugin asked to make connection to our own host and port, ignoring " << screenName;
qDebug() << "TwitterSipPlugin asked to make connection to our own host and port, ignoring " << screenName;
return;
}
@ -726,31 +673,31 @@ TwitterPlugin::makeConnection( const QString &screenName, const QVariantHash &pe
}
void
TwitterPlugin::directMessagePosted( const QTweetDMStatus& message )
TwitterSipPlugin::directMessagePosted( const QTweetDMStatus& message )
{
qDebug() << Q_FUNC_INFO;
qDebug() << "TwitterPlugin sent message to " << message.recipientScreenName() << " containing: " << message.text();
qDebug() << "TwitterSipPlugin sent message to " << message.recipientScreenName() << " containing: " << message.text();
}
void
TwitterPlugin::directMessagePostError( QTweetNetBase::ErrorCode errorCode, const QString &message )
TwitterSipPlugin::directMessagePostError( QTweetNetBase::ErrorCode errorCode, const QString &message )
{
Q_UNUSED( errorCode );
Q_UNUSED( message );
qDebug() << Q_FUNC_INFO;
qDebug() << "TwitterPlugin received an error posting direct message: " << m_directMessageNew.data()->lastErrorMessage();
qDebug() << "TwitterSipPlugin received an error posting direct message: " << m_directMessageNew.data()->lastErrorMessage();
}
void
TwitterPlugin::directMessageDestroyed( const QTweetDMStatus& message )
TwitterSipPlugin::directMessageDestroyed( const QTweetDMStatus& message )
{
qDebug() << Q_FUNC_INFO;
qDebug() << "TwitterPlugin destroyed message " << message.text();
qDebug() << "TwitterSipPlugin destroyed message " << message.text();
}
void
TwitterPlugin::fetchAvatar( const QString& screenName )
TwitterSipPlugin::fetchAvatar( const QString& screenName )
{
qDebug() << Q_FUNC_INFO;
if ( m_twitterAuth.isNull() )
@ -761,7 +708,7 @@ TwitterPlugin::fetchAvatar( const QString& screenName )
}
void
TwitterPlugin::avatarUserDataSlot( const QTweetUser &user )
TwitterSipPlugin::avatarUserDataSlot( const QTweetUser &user )
{
qDebug() << Q_FUNC_INFO;
if ( user.profileImageUrl().isEmpty() || m_twitterAuth.isNull() )
@ -774,14 +721,14 @@ TwitterPlugin::avatarUserDataSlot( const QTweetUser &user )
}
void
TwitterPlugin::refreshProxy()
TwitterSipPlugin::refreshProxy()
{
if ( !m_twitterAuth.isNull() )
m_twitterAuth.data()->setNetworkAccessManager( TomahawkUtils::nam() );
}
void
TwitterPlugin::profilePicReply()
TwitterSipPlugin::profilePicReply()
{
qDebug() << Q_FUNC_INFO;
QNetworkReply *reply = qobject_cast< QNetworkReply* >( sender() );
@ -801,267 +748,9 @@ TwitterPlugin::profilePicReply()
}
void
TwitterPlugin::checkSettings()
TwitterSipPlugin::configurationChanged()
{
if ( m_state == Disconnected )
return;
disconnectPlugin();
if ( m_state != Disconnected )
disconnectPlugin();
connectPlugin();
}
void
TwitterPlugin::setTwitterSavedDbid( const QString& dbid )
{
TomahawkSettings::instance()->setValue( pluginId() + "/saveddbid", dbid );
}
QString
TwitterPlugin::twitterSavedDbid() const
{
return TomahawkSettings::instance()->value( pluginId() + "/saveddbid", QString() ).toString();
}
QString
TwitterPlugin::twitterScreenName() const
{
TomahawkSettings* s = TomahawkSettings::instance();
s->beginGroup( pluginId() );
QStringList keys = s->childKeys();
if ( keys.contains( "ScreenName", Qt::CaseSensitive ) )
{
s->setValue( "screenname_tmp",
s->value( "ScreenName" ).toString() );
s->remove( "ScreenName" );
s->sync();
}
keys = s->childKeys();
if ( keys.contains( "screenname_tmp", Qt::CaseSensitive ) )
{
s->setValue( "screenname",
s->value( "screenname_tmp" ).toString() );
s->remove( "screenname_tmp" );
s->sync();
}
s->endGroup();
return s->value( pluginId() + "/screenname" ).toString();
}
void
TwitterPlugin::setTwitterScreenName( const QString& screenName )
{
TomahawkSettings::instance()->setValue( pluginId() + "/screenname", screenName );
}
QString
TwitterPlugin::twitterOAuthToken() const
{
TomahawkSettings* s = TomahawkSettings::instance();
s->beginGroup( pluginId() );
QStringList keys = s->childKeys();
if ( keys.contains( "OAuthToken", Qt::CaseSensitive ) )
{
s->setValue( "oauthtoken_tmp",
s->value( "OAuthToken" ).toString() );
s->remove( "OAuthToken" );
s->sync();
}
keys = s->childKeys();
if ( keys.contains( "oauthtoken_tmp", Qt::CaseSensitive ) )
{
s->setValue( "oauthtoken",
s->value( "oauthtoken_tmp" ).toString() );
s->remove( "oauthtoken_tmp" );
s->sync();
}
s->endGroup();
return s->value( pluginId() + "/oauthtoken" ).toString();
}
void
TwitterPlugin::setTwitterOAuthToken( const QString& oauthtoken )
{
TomahawkSettings::instance()->setValue( pluginId() + "/oauthtoken", oauthtoken );
}
QString
TwitterPlugin::twitterOAuthTokenSecret() const
{
TomahawkSettings* s = TomahawkSettings::instance();
s->beginGroup( pluginId() );
QStringList keys = s->childKeys();
if ( keys.contains( "OAuthTokenSecret", Qt::CaseSensitive ) )
{
s->setValue( "oauthtokensecret_tmp",
s->value( "OAuthTokenSecret" ).toString() );
s->remove( "OAuthTokenSecret" );
s->sync();
}
keys = s->childKeys();
if ( keys.contains( "oauthtokensecret_tmp", Qt::CaseSensitive ) )
{
s->setValue( "oauthtokensecret",
s->value( "oauthtokensecret_tmp" ).toString() );
s->remove( "oauthtokensecret_tmp" );
s->sync();
}
s->endGroup();
return s->value( pluginId() + "/oauthtokensecret" ).toString();
}
void
TwitterPlugin::setTwitterOAuthTokenSecret( const QString& oauthtokensecret )
{
TomahawkSettings::instance()->setValue( pluginId() + "/oauthtokensecret", oauthtokensecret );
}
qint64
TwitterPlugin::twitterCachedFriendsSinceId() const
{
TomahawkSettings* s = TomahawkSettings::instance();
s->beginGroup( pluginId() );
QStringList keys = s->childKeys();
if ( keys.contains( "CachedFriendsSinceID", Qt::CaseSensitive ) )
{
s->setValue( "cachedfriendssinceid_tmp",
s->value( "CachedFriendsSinceID" ).toLongLong() );
s->remove( "CachedFriendsSinceID" );
s->sync();
}
keys = s->childKeys();
if ( keys.contains( "cachedfriendssinceid_tmp", Qt::CaseSensitive ) )
{
s->setValue( "cachedfriendssinceid",
s->value( "cachedfriendssinceid_tmp" ).toLongLong() );
s->remove( "cachedfriendssinceid_tmp" );
s->sync();
}
s->endGroup();
return s->value( pluginId() + "/cachedfriendssinceid", 0 ).toLongLong();
}
void
TwitterPlugin::setTwitterCachedFriendsSinceId( qint64 cachedId )
{
TomahawkSettings::instance()->setValue( pluginId() + "/cachedfriendssinceid", cachedId );
}
qint64
TwitterPlugin::twitterCachedMentionsSinceId() const
{
TomahawkSettings* s = TomahawkSettings::instance();
s->beginGroup( pluginId() );
QStringList keys = s->childKeys();
if ( keys.contains( "CachedMentionsSinceID", Qt::CaseSensitive ) )
{
s->setValue( "cachedmentionssinceid_tmp",
s->value( "CachedMentionsSinceID" ).toLongLong() );
s->remove( "CachedMentionsSinceID" );
s->sync();
}
keys = s->childKeys();
if ( keys.contains( "cachedmentionssinceid_tmp", Qt::CaseSensitive ) )
{
s->setValue( "cachedmentionssinceid",
s->value( "cachedmentionssinceid_tmp" ).toLongLong() );
s->remove( "cachedmentionssinceid_tmp" );
s->sync();
}
s->endGroup();
return s->value( pluginId() + "/cachedmentionssinceid", 0 ).toLongLong();
}
void
TwitterPlugin::setTwitterCachedMentionsSinceId( qint64 cachedId )
{
TomahawkSettings::instance()->setValue( pluginId() + "/cachedmentionssinceid", cachedId );
}
qint64
TwitterPlugin::twitterCachedDirectMessagesSinceId() const
{
TomahawkSettings* s = TomahawkSettings::instance();
s->beginGroup( pluginId() );
QStringList keys = s->childKeys();
if ( keys.contains( "CachedDirectMessagesSinceID", Qt::CaseSensitive ) )
{
s->setValue( "cacheddirectmessagessinceid_tmp",
s->value( "CachedDirectMessagesSinceID" ).toLongLong() );
s->remove( "CachedDirectMessagesSinceID" );
s->sync();
}
keys = s->childKeys();
if ( keys.contains( "cacheddirectmessagessinceid_tmp", Qt::CaseSensitive ) )
{
s->setValue( "cacheddirectmessagessinceid",
s->value( "cacheddirectmessagessinceid_tmp" ).toLongLong() );
s->remove( "cacheddirectmessagessinceid_tmp" );
s->sync();
}
s->endGroup();
return s->value( pluginId() + "/cacheddirectmessagessinceid", 0 ).toLongLong();
}
void
TwitterPlugin::setTwitterCachedDirectMessagesSinceId( qint64 cachedId )
{
TomahawkSettings::instance()->setValue( pluginId() + "/cacheddirectmessagessinceid", cachedId );
}
QVariantHash
TwitterPlugin::twitterCachedPeers() const
{
TomahawkSettings* s = TomahawkSettings::instance();
s->beginGroup( pluginId() );
QStringList keys = s->childKeys();
if ( keys.contains( "CachedPeers", Qt::CaseSensitive ) )
{
s->setValue( "cachedpeers_tmp",
s->value( "CachedPeers" ).toHash() );
s->remove( "CachedPeers" );
s->sync();
}
keys = s->childKeys();
if ( keys.contains( "cachedpeers_tmp", Qt::CaseSensitive ) )
{
s->setValue( "cachedpeers",
s->value( "cachedpeers_tmp" ).toHash() );
s->remove( "cachedpeers_tmp" );
s->sync();
}
s->endGroup();
return s->value( pluginId() + "/cachedpeers", QVariantHash() ).toHash();
}
void
TwitterPlugin::setTwitterCachedPeers( const QVariantHash &cachedPeers )
{
TomahawkSettings::instance()->setValue( pluginId() + "/cachedpeers", cachedPeers );
TomahawkSettings::instance()->sync();
}
Q_EXPORT_PLUGIN2( sipfactory, TwitterFactory )

View File

@ -19,8 +19,6 @@
#ifndef TWITTER_H
#define TWITTER_H
#include "twitterconfigwidget.h"
#include <QTimer>
#include <QWeakPointer>
#include <QSet>
@ -36,48 +34,28 @@
#include "../sipdllmacro.h"
#include "sip/SipPlugin.h"
#include "accounts/account.h"
#include "tomahawkoauthtwitter.h"
#define MYNAME "SIPTWITTER"
class SIPDLLEXPORT TwitterFactory : public SipPluginFactory
{
Q_OBJECT
Q_INTERFACES( SipPluginFactory )
public:
TwitterFactory() {}
virtual ~TwitterFactory() {}
virtual QString prettyName() const { return "Twitter"; }
virtual QString factoryId() const { return "siptwitter"; }
virtual QIcon icon() const;
virtual SipPlugin* createPlugin( const QString& pluginId = QString() );
};
class SIPDLLEXPORT TwitterPlugin : public SipPlugin
class SIPDLLEXPORT TwitterSipPlugin : public SipPlugin
{
Q_OBJECT
public:
TwitterPlugin( const QString& pluginId );
TwitterSipPlugin( Tomahawk::Accounts::Account *account );
virtual ~TwitterPlugin() {}
virtual ~TwitterSipPlugin() {}
virtual bool isValid() const;
virtual const QString name() const;
virtual const QString accountName() const;
virtual const QString friendlyName() const;
virtual ConnectionState connectionState() const;
virtual QIcon icon() const;
virtual QWidget* configWidget();
public slots:
virtual bool connectPlugin();
void disconnectPlugin();
void checkSettings();
void refreshProxy();
void deletePlugin();
void configurationChanged();
void sendMsg( const QString& to, const QString& msg )
{
@ -97,7 +75,6 @@ public slots:
}
private slots:
void configDialogAuthedSignalSlot( bool authed );
void connectAuthVerifyReply( const QTweetUser &user );
void checkTimerFired();
void connectTimerFired();
@ -117,26 +94,14 @@ private slots:
void profilePicReply();
private:
inline void syncConfig() { setTwitterCachedPeers( m_cachedPeers ); }
inline void syncConfig() { m_account->setCredentials( m_credentials ); m_account->setConfiguration( m_configuration ); m_account->syncConfig(); }
bool refreshTwitterAuth();
void parseGotTomahawk( const QRegExp &regex, const QString &screenName, const QString &text );
// handle per-plugin config
QString twitterSavedDbid() const;
void setTwitterSavedDbid( const QString& dbid );
QString twitterScreenName() const;
void setTwitterScreenName( const QString& screenName );
QString twitterOAuthToken() const;
void setTwitterOAuthToken( const QString& oauthtoken );
QString twitterOAuthTokenSecret() const;
void setTwitterOAuthTokenSecret( const QString& oauthtokensecret );
qint64 twitterCachedFriendsSinceId() const;
void setTwitterCachedFriendsSinceId( qint64 sinceid );
qint64 twitterCachedMentionsSinceId() const;
void setTwitterCachedMentionsSinceId( qint64 sinceid );
qint64 twitterCachedDirectMessagesSinceId() const;
void setTwitterCachedDirectMessagesSinceId( qint64 sinceid );
QVariantHash twitterCachedPeers() const;
void setTwitterCachedPeers( const QVariantHash &cachedPeers );
QWeakPointer< TomahawkOAuthTwitter > m_twitterAuth;
QWeakPointer< QTweetFriendsTimeline > m_friendsTimeline;
@ -145,6 +110,9 @@ private:
QWeakPointer< QTweetDirectMessageNew > m_directMessageNew;
QWeakPointer< QTweetDirectMessageDestroy > m_directMessageDestroy;
QVariantHash m_configuration;
QVariantHash m_credentials;
bool m_isAuthed;
QTimer m_checkTimer;
QTimer m_connectTimer;

View File

@ -523,8 +523,7 @@ TomahawkApp::initSIP()
#endif
tDebug( LOGINFO ) << "Connecting SIP classes";
//SipHandler::instance()->refreshProxy();
SipHandler::instance()->loadFromConfig();
SipHandler::instance()->loadFromAccountManager();
}
}