From f313ba473ec1025d178cfc62de610a9021dfbfdc Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 14 Aug 2012 12:17:36 +0200 Subject: [PATCH] Add contact support. --- src/widgets/AccountWidget.cpp | 41 ++++++++++++++++++++++++++++++++++- src/widgets/AccountWidget.h | 3 +++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/widgets/AccountWidget.cpp b/src/widgets/AccountWidget.cpp index 7108990ca..da57f01e4 100644 --- a/src/widgets/AccountWidget.cpp +++ b/src/widgets/AccountWidget.cpp @@ -22,6 +22,7 @@ #include "SlideSwitchButton.h" #include "accounts/Account.h" #include "accounts/AccountModel.h" +#include "sip/SipPlugin.h" #include "utils/TomahawkUtilsGui.h" #include "utils/AnimatedSpinner.h" #include "widgets/ElidedLabel.h" @@ -33,6 +34,7 @@ #include #include #include +#include #include AccountWidget::AccountWidget( QWidget* parent ) @@ -124,6 +126,8 @@ AccountWidget::AccountWidget( QWidget* parent ) m_inviteButton->setFixedWidth( m_inviteButton->logicalDpiX() * 0.8 ); m_inviteButton->setText( tr( "Invite" ) ); vLayout->addWidget( m_inviteButton, 1, 1 ); + + setInviteWidgetsEnabled( false ); } AccountWidget::~AccountWidget() @@ -169,21 +173,25 @@ AccountWidget::update( const QPersistentModelIndex& idx, int accountIdx ) m_spinner->fadeOut(); m_statusToggle->setChecked( false ); m_statusToggle->setBackChecked( false ); + setInviteWidgetsEnabled( false ); break; case Tomahawk::Accounts::Account::Connecting: m_spinner->fadeIn(); m_statusToggle->setChecked( true ); m_statusToggle->setBackChecked( false ); + setInviteWidgetsEnabled( false ); break; case Tomahawk::Accounts::Account::Connected: m_spinner->fadeOut(); m_statusToggle->setChecked( true ); m_statusToggle->setBackChecked( true ); + setInviteWidgetsEnabled( true ); break; case Tomahawk::Accounts::Account::Disconnecting: m_spinner->fadeIn(); m_statusToggle->setChecked( false ); m_statusToggle->setBackChecked( true ); + setInviteWidgetsEnabled( false ); } } } @@ -207,6 +215,36 @@ AccountWidget::changeAccountConnectionState( bool connected ) } } +void +AccountWidget::sendInvite() +{ + Tomahawk::Accounts::Account* account = + m_myFactoryIdx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole ) + .value< QList< Tomahawk::Accounts::Account* > >().at( m_myAccountIdx ); + if ( account ) + { + if ( !m_inviteEdit->text().isEmpty() ) + account->sipPlugin()->addContact( m_inviteEdit->text() ); + m_inviteButton->setEnabled( false ); + m_inviteEdit->setEnabled( false ); + QTimer::singleShot( 500, this, SLOT( clearInviteWidgets() ) ); + } +} + +void +AccountWidget::clearInviteWidgets() +{ + setInviteWidgetsEnabled( m_statusToggle->backChecked() ); + m_inviteEdit->clear(); +} + +void +AccountWidget::setInviteWidgetsEnabled( bool enabled ) +{ + m_inviteButton->setEnabled( enabled ); + m_inviteEdit->setEnabled( enabled ); +} + void AccountWidget::setupConnections( const QPersistentModelIndex& idx, int accountIdx ) { @@ -220,6 +258,7 @@ AccountWidget::setupConnections( const QPersistentModelIndex& idx, int accountId { connect( m_statusToggle, SIGNAL( toggled( bool ) ), this, SLOT( changeAccountConnectionState( bool ) ) ); - //TODO: invite/tweet + connect( m_inviteButton, SIGNAL( clicked() ), + this, SLOT( sendInvite() ) ); } } diff --git a/src/widgets/AccountWidget.h b/src/widgets/AccountWidget.h index ff9177438..fd4d17992 100644 --- a/src/widgets/AccountWidget.h +++ b/src/widgets/AccountWidget.h @@ -44,6 +44,9 @@ public: private slots: void changeAccountConnectionState( bool connected ); + void sendInvite(); + void clearInviteWidgets(); + void setInviteWidgetsEnabled( bool enabled ); private: QLabel* m_imageLabel;