From 31ce7a5a2de1c54c6da7539c9a6208fa46739b72 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Fri, 11 Feb 2011 22:39:19 -0500 Subject: [PATCH] Add beginnings of twitter sip plugin --- src/CMakeLists.txt | 1 + src/sip/twitter/CMakeLists.txt | 44 ++++++++++++++++++++++ src/sip/twitter/tomahawkoauthtwitter.cpp | 12 ++++++ src/sip/twitter/tomahawkoauthtwitter.h | 21 +++++++++++ src/sip/twitter/twitter.cpp | 29 +++++++++++++++ src/sip/twitter/twitter.h | 47 ++++++++++++++++++++++++ 6 files changed, 154 insertions(+) create mode 100644 src/sip/twitter/CMakeLists.txt create mode 100644 src/sip/twitter/tomahawkoauthtwitter.cpp create mode 100644 src/sip/twitter/tomahawkoauthtwitter.h create mode 100644 src/sip/twitter/twitter.cpp create mode 100644 src/sip/twitter/twitter.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d486966e0..bb90964cd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -132,6 +132,7 @@ IF( UNIX ) ENDIF( UNIX ) ADD_SUBDIRECTORY( sip/jabber ) +ADD_SUBDIRECTORY( sip/twitter ) ADD_SUBDIRECTORY( sip/zeroconf ) kde4_add_app_icon( tomahawkSources "${CMAKE_CURRENT_SOURCE_DIR}/../data/icons/tomahawk-icon-*.png" ) diff --git a/src/sip/twitter/CMakeLists.txt b/src/sip/twitter/CMakeLists.txt new file mode 100644 index 000000000..6fd91e9d6 --- /dev/null +++ b/src/sip/twitter/CMakeLists.txt @@ -0,0 +1,44 @@ +project( tomahawk ) + +include( ${QT_USE_FILE} ) +add_definitions( ${QT_DEFINITIONS} ) +add_definitions( -DQT_PLUGIN ) +add_definitions( -DQT_SHARED ) + +set( twitterSources + # twitter.cpp + tomahawkoauthtwitter.cpp +) + +set( twitterHeaders + # twitter.h + tomahawkoauthtwitter.h +) + +include_directories( . ${CMAKE_CURRENT_BINARY_DIR} .. + ${QT_INCLUDE_DIR} + ${CMAKE_SOURCE_DIR}/thirdparty/qtweetlib/src +) + +qt4_wrap_cpp( twitterMoc ${twitterHeaders} ) +add_library( sip_twitter SHARED ${twitterSources} ${twitterMoc} ) + +IF( WIN32 ) +SET( OS_SPECIFIC_LINK_LIBRARIES + ${OS_SPECIFIC_LINK_LIBRARIES} + "winmm.dll" + "iphlpapi.a" + "${CMAKE_CURRENT_SOURCE_DIR}/../../../build/src/libtomahawk/libtomahawklib.dll" +) +ENDIF( WIN32 ) + +target_link_libraries( sip_twitter + ${QT_LIBRARIES} + ${OS_SPECIFIC_LINK_LIBRARIES} +) + +IF( APPLE ) + SET( CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} "-undefined dynamic_lookup" ) +ENDIF( APPLE ) + +install( TARGETS sip_twitter DESTINATION lib ) diff --git a/src/sip/twitter/tomahawkoauthtwitter.cpp b/src/sip/twitter/tomahawkoauthtwitter.cpp new file mode 100644 index 000000000..1031f0d2f --- /dev/null +++ b/src/sip/twitter/tomahawkoauthtwitter.cpp @@ -0,0 +1,12 @@ +#include "tomahawkoauthtwitter.h" +#include + +int TomahawkOAuthTwitter::authorizationWidget() +{ + bool ok; + int i = QInputDialog::getInt(0, QString( "Twitter PIN" ), QString( "After authenticating, enter the displayed PIN number here:" ), 0, 0, 2147483647, 1, &ok); + if (ok) + return i; + + return 0; +} diff --git a/src/sip/twitter/tomahawkoauthtwitter.h b/src/sip/twitter/tomahawkoauthtwitter.h new file mode 100644 index 000000000..b40e2b87d --- /dev/null +++ b/src/sip/twitter/tomahawkoauthtwitter.h @@ -0,0 +1,21 @@ +#ifndef TOMAHAWKOAUTHTWITTER +#define TOMAHAWKOAUTHTWITTER + +#include + +class TomahawkOAuthTwitter : public OAuthTwitter +{ + Q_OBJECT + +public: + TomahawkOAuthTwitter(QObject *parent = 0) + : OAuthTwitter( parent ) + {} + + ~TomahawkOAuthTwitter() {} + +protected: + virtual int authorizationWidget(); +}; + +#endif diff --git a/src/sip/twitter/twitter.cpp b/src/sip/twitter/twitter.cpp new file mode 100644 index 000000000..702c7983b --- /dev/null +++ b/src/sip/twitter/twitter.cpp @@ -0,0 +1,29 @@ +#include "zeroconf.h" + +#include + + +bool +ZeroconfPlugin::connect( bool /*startup*/ ) +{ + delete m_zeroconf; + m_zeroconf = new TomahawkZeroconf( Servent::instance()->port(), this ); + QObject::connect( m_zeroconf, SIGNAL( tomahawkHostFound( const QString&, int, const QString&, const QString& ) ), + SLOT( lanHostFound( const QString&, int, const QString&, const QString& ) ) ); + + m_zeroconf->advertise(); + + return true; +} + + +void +ZeroconfPlugin::lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid ) +{ + qDebug() << "Found LAN host:" << host << port << nodeid; + + if ( !Servent::instance()->connectedToSession( nodeid ) ) + Servent::instance()->connectToPeer( host, port, "whitelist", name, nodeid ); +} + +Q_EXPORT_PLUGIN2( sip, ZeroconfPlugin ) diff --git a/src/sip/twitter/twitter.h b/src/sip/twitter/twitter.h new file mode 100644 index 000000000..c347608ad --- /dev/null +++ b/src/sip/twitter/twitter.h @@ -0,0 +1,47 @@ +#ifndef ZEROCONF_H +#define ZEROCONF_H + +#include "sip/SipPlugin.h" +#include "tomahawkzeroconf.h" + +#include "../sipdllmacro.h" + +class SIPDLLEXPORT ZeroconfPlugin : public SipPlugin +{ + Q_OBJECT + Q_INTERFACES( SipPlugin ) + +public: + ZeroconfPlugin() + : m_zeroconf( 0 ) + {} + + virtual ~ZeroconfPlugin() {} + +public slots: + virtual bool connect( bool startup ); + + void disconnect() + { + } + + void sendMsg( const QString& to, const QString& msg ) + { + } + + void broadcastMsg( const QString &msg ) + { + } + + void addContact( const QString &jid, const QString& msg = QString() ) + { + } + +private slots: + void lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid ); + +private: + TomahawkZeroconf* m_zeroconf; +}; + +#endif