From 3607d364e705469aed48c0210f793bdaf398e654 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 16 Dec 2011 17:31:54 -0500 Subject: [PATCH] port google wrapper over --- src/accounts/xmpp/CMakeLists.txt | 2 +- .../xmpp/googlewrapper/CMakeLists.txt | 31 ++++--- .../xmpp/googlewrapper/googlewrapper.cpp | 89 +++++++++++++------ .../xmpp/googlewrapper/googlewrapper.h | 51 ++++++++--- src/accounts/xmpp/xmppaccount.cpp | 4 +- src/accounts/xmpp/xmppaccount.h | 7 +- src/accounts/xmpp/xmppconfigwidget.h | 3 + 7 files changed, 127 insertions(+), 60 deletions(-) diff --git a/src/accounts/xmpp/CMakeLists.txt b/src/accounts/xmpp/CMakeLists.txt index 69fa87122..809ee5b03 100644 --- a/src/accounts/xmpp/CMakeLists.txt +++ b/src/accounts/xmpp/CMakeLists.txt @@ -60,5 +60,5 @@ ENDIF( APPLE ) install( TARGETS tomahawk_account_xmpp DESTINATION lib${LIB_SUFFIX} ) -#add_subdirectory(googlewrapper) +add_subdirectory(googlewrapper) diff --git a/src/accounts/xmpp/googlewrapper/CMakeLists.txt b/src/accounts/xmpp/googlewrapper/CMakeLists.txt index 8a3e47957..d8abd686f 100644 --- a/src/accounts/xmpp/googlewrapper/CMakeLists.txt +++ b/src/accounts/xmpp/googlewrapper/CMakeLists.txt @@ -2,31 +2,36 @@ # fake google plugin set( googleHeaders - ../jabber.h - ../avatarmanager.h - ../xmlconsole.h - googlewrapper.h ) + ../xmppaccount.h + ../xmppconfigwidget.h + ../sip/xmppsip.h + ../sip/avatarmanager.h + ../sip/xmlconsole.h + googlewrapper.h ) set( googleSources - ../jabber.cpp - ../tomahawkxmppmessage.cpp - ../tomahawkxmppmessagefactory.cpp - ../avatarmanager.cpp - ../xmlconsole.cpp - googlewrapper.cpp ) + ../xmppaccount.cpp + ../xmppconfigwidget.cpp + ../sip/xmppsip.cpp + ../sip/tomahawkxmppmessage.cpp + ../sip/tomahawkxmppmessagefactory.cpp + ../sip/avatarmanager.cpp + ../sip/xmlconsole.cpp + + googlewrapper.cpp ) add_definitions(-DGOOGLE_WRAPPER) qt4_add_resources( RCX_SRCS "resources.qrc" ) qt4_wrap_cpp( googleMoc ${googleHeaders} ) -add_library( tomahawk_sipgoogle SHARED ${googleSources} ${googleMoc} ${googleMoc} ${RCX_SRCS} ) +add_library( tomahawk_account_google SHARED ${googleSources} ${googleMoc} ${googleMoc} ${RCX_SRCS} ) -target_link_libraries( tomahawk_sipgoogle +target_link_libraries( tomahawk_account_google ${QT_LIBRARIES} ${LIBJREEN_LIBRARY} ${OS_SPECIFIC_LINK_LIBRARIES} tomahawklib ) -install( TARGETS tomahawk_sipgoogle DESTINATION lib${LIB_SUFFIX} ) +install( TARGETS tomahawk_account_google DESTINATION lib${LIB_SUFFIX} ) diff --git a/src/accounts/xmpp/googlewrapper/googlewrapper.cpp b/src/accounts/xmpp/googlewrapper/googlewrapper.cpp index 1e7c107f4..779aef58c 100644 --- a/src/accounts/xmpp/googlewrapper/googlewrapper.cpp +++ b/src/accounts/xmpp/googlewrapper/googlewrapper.cpp @@ -18,18 +18,21 @@ #include "googlewrapper.h" -#include "ui_configwidget.h" +#include "xmppconfigwidget.h" +#include "ui_xmppconfigwidget.h" #include "utils/tomahawkutils.h" #include #include +using namespace Tomahawk; +using namespace Accounts; -SipPlugin* -GoogleWrapperFactory::createPlugin( const QString& pluginId ) +Account* +GoogleWrapperFactory::createAccount( const QString& pluginId ) { - return new GoogleWrapper( pluginId.isEmpty() ? generateId() : pluginId ); + return new GoogleWrapper( pluginId.isEmpty() ? generateId( factoryId() ) : pluginId ); } @@ -39,36 +42,19 @@ GoogleWrapperFactory::icon() const return QIcon( ":/gmail-logo.png" ); } - -GoogleWrapper::GoogleWrapper ( const QString& pluginID ) - : JabberPlugin ( pluginID ) +GoogleWrapperSip::GoogleWrapperSip( Account* account ) + : XmppSipPlugin( account ) { - m_ui->headerLabel->setText( tr( "Configure this Google Account" ) ); - m_ui->emailLabel->setText( tr( "Google Address" ) ); - m_ui->jabberBlurb->setText( tr( "Enter your Google login to connect with your friends using Tomahawk!" ) ); - m_ui->logoLabel->setPixmap( QPixmap( ":/gmail-logo.png" ) ); - m_ui->jabberServer->setText( "talk.google.com" ); - m_ui->jabberPort->setValue( 5222 ); - m_ui->groupBoxJabberAdvanced->hide(); + } - -QIcon -GoogleWrapper::icon() const +GoogleWrapperSip::~GoogleWrapperSip() { - return QIcon( ":/gmail-logo.png" ); -} - - -QString -GoogleWrapper::defaultSuffix() const -{ - return "@gmail.com"; } void -GoogleWrapper::showAddFriendDialog() +GoogleWrapperSip::showAddFriendDialog() { bool ok; QString id = QInputDialog::getText( TomahawkUtils::tomahawkWindow(), tr( "Add Friend" ), @@ -81,6 +67,55 @@ GoogleWrapper::showAddFriendDialog() } +QString +GoogleWrapperSip::defaultSuffix() const +{ + return "@gmail.com"; +} + + +GoogleWrapper::GoogleWrapper ( const QString& pluginID ) + : XmppAccount ( pluginID ) +{ + XmppConfigWidget* config = static_cast< XmppConfigWidget* >( m_configWidget.data() ); + config->m_ui->headerLabel->setText( tr( "Configure this Google Account" ) ); + config->m_ui->emailLabel->setText( tr( "Google Address" ) ); + config->m_ui->xmppBlurb->setText( tr( "Enter your Google login to connect with your friends using Tomahawk!" ) ); + config->m_ui->logoLabel->setPixmap( QPixmap( ":/gmail-logo.png" ) ); + config->m_ui->xmppServer->setText( "talk.google.com" ); + config->m_ui->xmppPort->setValue( 5222 ); + config->m_ui->groupBoxXmppAdvanced->hide(); +} + +GoogleWrapper::~GoogleWrapper() +{ + delete m_sipPlugin.data(); +} + + +QIcon +GoogleWrapper::icon() const +{ + return QIcon( ":/gmail-logo.png" ); +} + + +SipPlugin* +GoogleWrapper::sipPlugin() +{ + if ( m_xmppSipPlugin.isNull() ) + { + m_xmppSipPlugin = QWeakPointer< XmppSipPlugin >( new GoogleWrapperSip( const_cast< GoogleWrapper* >( this ) ) ); + + connect( m_xmppSipPlugin.data(), SIGNAL( stateChanged( Tomahawk::Accounts::Account::ConnectionState ) ), this, SIGNAL( connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ) ); + connect( m_xmppSipPlugin.data(), SIGNAL( error( int, QString ) ), this, SIGNAL( error( int, QString ) ) ); + + return m_xmppSipPlugin.data(); + } + return m_xmppSipPlugin.data(); +} + + #ifdef GOOGLE_WRAPPER -Q_EXPORT_PLUGIN2( sipfactory, GoogleWrapperFactory ) +Q_EXPORT_PLUGIN2( Tomahawk::Accounts::AccountFactory, Tomahawk::Accounts::GoogleWrapperFactory ) #endif diff --git a/src/accounts/xmpp/googlewrapper/googlewrapper.h b/src/accounts/xmpp/googlewrapper/googlewrapper.h index f34238c6a..d765c67a9 100644 --- a/src/accounts/xmpp/googlewrapper/googlewrapper.h +++ b/src/accounts/xmpp/googlewrapper/googlewrapper.h @@ -19,12 +19,18 @@ #ifndef GOOGLEWRAPPER_H #define GOOGLEWRAPPER_H -#include "sip/jabber/jabber.h" +#include "xmppaccount.h" -class SIPDLLEXPORT GoogleWrapperFactory : public SipPluginFactory +namespace Tomahawk +{ + +namespace Accounts +{ + +class ACCOUNTDLLEXPORT GoogleWrapperFactory : public XmppAccountFactory { Q_OBJECT - Q_INTERFACES( SipPluginFactory ) + Q_INTERFACES( Tomahawk::Accounts::AccountFactory ) public: GoogleWrapperFactory() {} @@ -33,25 +39,42 @@ public: virtual QString prettyName() const { return "Google"; } virtual QString factoryId() const { return "sipgoogle"; } virtual QIcon icon() const; - virtual SipPlugin* createPlugin( const QString& pluginId ); + virtual Account* createAccount( const QString& pluginId ); }; -class SIPDLLEXPORT GoogleWrapper : public JabberPlugin +class ACCOUNTDLLEXPORT GoogleWrapperSip : public XmppSipPlugin { Q_OBJECT public: - GoogleWrapper( const QString& pluginID ); - virtual ~GoogleWrapper() {} - - virtual const QString name() const { return QString( "Google" ); } - virtual const QString friendlyName() const { return "Google"; } - virtual QIcon icon() const; - -protected: - QString defaultSuffix() const; + GoogleWrapperSip( Tomahawk::Accounts::Account* account ); + virtual ~GoogleWrapperSip(); public slots: void showAddFriendDialog(); + +protected: + QString defaultSuffix() const; }; +class ACCOUNTDLLEXPORT GoogleWrapper : public XmppAccount +{ + Q_OBJECT +public: + GoogleWrapper( const QString& pluginID ); + virtual ~GoogleWrapper(); + + virtual const QString name() const { return QString( "Google" ); } + virtual const QString friendlyName() const { return "Google"; } + virtual QIcon icon() const; + + virtual SipPlugin* sipPlugin(); + +private: + QWeakPointer< GoogleWrapperSip > m_sipPlugin; +}; + +} + +} + #endif // GOOGLEWRAPPER_H diff --git a/src/accounts/xmpp/xmppaccount.cpp b/src/accounts/xmpp/xmppaccount.cpp index b32aa2183..51a6dfc5b 100644 --- a/src/accounts/xmpp/xmppaccount.cpp +++ b/src/accounts/xmpp/xmppaccount.cpp @@ -83,8 +83,6 @@ XmppAccount::isAuthenticated() const Account::ConnectionState XmppAccount::connectionState() const { - // Ensure we exist - const_cast( this )->sipPlugin(); return m_xmppSipPlugin.data()->connectionState(); } @@ -116,4 +114,6 @@ XmppAccount::sipPlugin() } +#ifndef GOOGLE_WRAPPER Q_EXPORT_PLUGIN2( Tomahawk::Accounts::AccountFactory, Tomahawk::Accounts::XmppAccountFactory ) +#endif diff --git a/src/accounts/xmpp/xmppaccount.h b/src/accounts/xmpp/xmppaccount.h index 122d3171d..ff8961129 100644 --- a/src/accounts/xmpp/xmppaccount.h +++ b/src/accounts/xmpp/xmppaccount.h @@ -73,11 +73,12 @@ public: virtual Tomahawk::Accounts::Account::ConnectionState connectionState() const; -private: - Ui_XmppConfigWidget* m_ui; // so the google wrapper can change the config dialog a bit - QWeakPointer< QWidget > m_configWidget; +protected: + QWeakPointer< QWidget > m_configWidget; // so the google wrapper can change the config dialog a bit QWeakPointer< XmppSipPlugin > m_xmppSipPlugin; +private: + // for settings access friend class XmppConfigWidget; diff --git a/src/accounts/xmpp/xmppconfigwidget.h b/src/accounts/xmpp/xmppconfigwidget.h index ffe7e986b..d88e42631 100644 --- a/src/accounts/xmpp/xmppconfigwidget.h +++ b/src/accounts/xmpp/xmppconfigwidget.h @@ -35,6 +35,7 @@ namespace Accounts { class XmppAccount; +class GoogleWrapper; class DLLEXPORT XmppConfigWidget : public QWidget @@ -56,6 +57,8 @@ private slots: private: Ui::XmppConfigWidget *m_ui; XmppAccount *m_account; + + friend class GoogleWrapper; // So google wrapper can modify the labels and text }; }