1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 06:07:37 +02:00

* Use the new SipPlugin::addContact() api.

This commit is contained in:
Christian Muehlhaeuser
2013-09-03 22:01:36 +02:00
parent 8b09d19341
commit 1e545dcc6c
3 changed files with 85 additions and 63 deletions

View File

@@ -1,22 +1,23 @@
/* /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
Copyright (C) 2011 Leo Franchi <leo.franchi@kdab.com> *
Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org> * Copyright 2010-2013, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
This program is free software: you can redistribute it and/or modify * Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
it under the terms of the GNU General Public License as published by *
the Free Software Foundation, either version 3 of the License, or * Tomahawk is free software: you can redistribute it and/or modify
(at your option) any later version. * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
This program is distributed in the hope that it will be useful, * (at your option) any later version.
but WITHOUT ANY WARRANTY; without even the implied warranty of *
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * Tomahawk is distributed in the hope that it will be useful,
GNU General Public License for more details. * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
You should have received a copy of the GNU General Public License * GNU General Public License for more details.
along with this program. If not, see <http://www.gnu.org/licenses/>. *
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GOOGLEWRAPPER_H #ifndef GOOGLEWRAPPER_H
#define GOOGLEWRAPPER_H #define GOOGLEWRAPPER_H

View File

@@ -65,7 +65,7 @@ public slots:
virtual void sendSipInfos( const Tomahawk::peerinfo_ptr& /* receiver */, const QList<SipInfo>& /* info */ ) {} virtual void sendSipInfos( const Tomahawk::peerinfo_ptr& /* receiver */, const QList<SipInfo>& /* info */ ) {}
void broadcastMsg( const QString& ) {} void broadcastMsg( const QString& ) {}
void addContact( const QString&, const QString& ) {} bool addContact( const QString&, AddContactOptions, const QString& ) { return false; }
private slots: private slots:
void lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid ); void lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid );

View File

@@ -134,7 +134,6 @@ AccountWidget::AccountWidget( QWidget* parent )
vLayout->addWidget( m_inviteButton, 1, 1 ); vLayout->addWidget( m_inviteButton, 1, 1 );
vLayout->setColumnStretch( 0, 1 ); vLayout->setColumnStretch( 0, 1 );
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
layout()->setContentsMargins( 0, 0, 0, 0 ); layout()->setContentsMargins( 0, 0, 0, 0 );
#endif #endif
@@ -142,6 +141,7 @@ AccountWidget::AccountWidget( QWidget* parent )
setInviteWidgetsEnabled( false ); setInviteWidgetsEnabled( false );
} }
AccountWidget::~AccountWidget() AccountWidget::~AccountWidget()
{ {
delete m_spinner; delete m_spinner;
@@ -154,6 +154,7 @@ AccountWidget::update( const QPersistentModelIndex& idx, int accountIdx )
Tomahawk::Accounts::Account* account = Tomahawk::Accounts::Account* account =
idx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole ) idx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole )
.value< QList< Tomahawk::Accounts::Account* > >().at( accountIdx ); .value< QList< Tomahawk::Accounts::Account* > >().at( accountIdx );
if ( account ) if ( account )
{ {
const QPixmap& pixmap = account->icon(); const QPixmap& pixmap = account->icon();
@@ -182,6 +183,7 @@ AccountWidget::update( const QPersistentModelIndex& idx, int accountIdx )
switch ( account->connectionState() ) switch ( account->connectionState() )
{ {
case Tomahawk::Accounts::Account::Connected: case Tomahawk::Accounts::Account::Connected:
{
if ( account->enabled() ) if ( account->enabled() )
m_statusToggle->setChecked( true ); m_statusToggle->setChecked( true );
else else
@@ -191,7 +193,10 @@ AccountWidget::update( const QPersistentModelIndex& idx, int accountIdx )
m_statusToggle->setBackChecked( true ); m_statusToggle->setBackChecked( true );
setInviteWidgetsEnabled( true ); setInviteWidgetsEnabled( true );
break; break;
}
case Tomahawk::Accounts::Account::Connecting: case Tomahawk::Accounts::Account::Connecting:
{
if ( !account->enabled() ) if ( !account->enabled() )
qDebug() << "AccountWidget warning:" << account->accountFriendlyName() qDebug() << "AccountWidget warning:" << account->accountFriendlyName()
<< "is Connecting but Disabled!"; << "is Connecting but Disabled!";
@@ -199,7 +204,10 @@ AccountWidget::update( const QPersistentModelIndex& idx, int accountIdx )
m_statusToggle->setBackChecked( false ); m_statusToggle->setBackChecked( false );
setInviteWidgetsEnabled( false ); setInviteWidgetsEnabled( false );
break; break;
}
case Tomahawk::Accounts::Account::Disconnected: case Tomahawk::Accounts::Account::Disconnected:
{
if ( !account->enabled() ) if ( !account->enabled() )
m_statusToggle->setChecked( false ); m_statusToggle->setChecked( false );
else else
@@ -209,7 +217,10 @@ AccountWidget::update( const QPersistentModelIndex& idx, int accountIdx )
m_statusToggle->setBackChecked( false ); m_statusToggle->setBackChecked( false );
setInviteWidgetsEnabled( false ); setInviteWidgetsEnabled( false );
break; break;
}
case Tomahawk::Accounts::Account::Disconnecting: case Tomahawk::Accounts::Account::Disconnecting:
{
if ( account->enabled() ) if ( account->enabled() )
qDebug() << "AccountWidget warning:" << account->accountFriendlyName() qDebug() << "AccountWidget warning:" << account->accountFriendlyName()
<< "is Disconnecting but Enabled!"; << "is Disconnecting but Enabled!";
@@ -217,6 +228,7 @@ AccountWidget::update( const QPersistentModelIndex& idx, int accountIdx )
m_statusToggle->setBackChecked( true ); m_statusToggle->setBackChecked( true );
setInviteWidgetsEnabled( false ); setInviteWidgetsEnabled( false );
} }
}
if ( !account->enabled() && account->connectionState() == Tomahawk::Accounts::Account::Disconnected ) if ( !account->enabled() && account->connectionState() == Tomahawk::Accounts::Account::Disconnected )
{ {
@@ -235,12 +247,14 @@ AccountWidget::update( const QPersistentModelIndex& idx, int accountIdx )
} }
} }
void void
AccountWidget::changeAccountConnectionState( bool connected ) AccountWidget::changeAccountConnectionState( bool connected )
{ {
Tomahawk::Accounts::Account* account = Tomahawk::Accounts::Account* account =
m_myFactoryIdx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole ) m_myFactoryIdx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole )
.value< QList< Tomahawk::Accounts::Account* > >().at( m_myAccountIdx ); .value< QList< Tomahawk::Accounts::Account* > >().at( m_myAccountIdx );
if ( account ) if ( account )
{ {
if ( connected ) if ( connected )
@@ -254,16 +268,19 @@ AccountWidget::changeAccountConnectionState( bool connected )
} }
} }
void void
AccountWidget::sendInvite() AccountWidget::sendInvite()
{ {
Tomahawk::Accounts::Account* account = Tomahawk::Accounts::Account* account =
m_myFactoryIdx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole ) m_myFactoryIdx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole )
.value< QList< Tomahawk::Accounts::Account* > >().at( m_myAccountIdx ); .value< QList< Tomahawk::Accounts::Account* > >().at( m_myAccountIdx );
if ( account ) if ( account )
{ {
if ( !m_inviteEdit->text().isEmpty() ) if ( !m_inviteEdit->text().isEmpty() )
account->sipPlugin()->addContact( m_inviteEdit->text() ); account->sipPlugin()->addContact( m_inviteEdit->text(), SipPlugin::SendInvite );
m_inviteButton->setEnabled( false ); m_inviteButton->setEnabled( false );
m_inviteEdit->setEnabled( false ); m_inviteEdit->setEnabled( false );
QTimer::singleShot( 500, this, SLOT( clearInviteWidgets() ) ); QTimer::singleShot( 500, this, SLOT( clearInviteWidgets() ) );
@@ -277,6 +294,7 @@ AccountWidget::onInviteSentSuccess( const QString& inviteId )
JobStatusView::instance()->model()->addJob( new SipStatusMessage( SipStatusMessage::SipInviteSuccess, inviteId ) ); JobStatusView::instance()->model()->addJob( new SipStatusMessage( SipStatusMessage::SipInviteSuccess, inviteId ) );
} }
void void
AccountWidget::onInviteSentFailure( const QString& inviteId ) AccountWidget::onInviteSentFailure( const QString& inviteId )
{ {
@@ -291,6 +309,7 @@ AccountWidget::clearInviteWidgets()
m_inviteEdit->clear(); m_inviteEdit->clear();
} }
void void
AccountWidget::setInviteWidgetsEnabled( bool enabled ) AccountWidget::setInviteWidgetsEnabled( bool enabled )
{ {
@@ -298,6 +317,7 @@ AccountWidget::setInviteWidgetsEnabled( bool enabled )
m_inviteEdit->setEnabled( enabled ); m_inviteEdit->setEnabled( enabled );
} }
void void
AccountWidget::setupConnections( const QPersistentModelIndex& idx, int accountIdx ) AccountWidget::setupConnections( const QPersistentModelIndex& idx, int accountIdx )
{ {
@@ -307,14 +327,12 @@ AccountWidget::setupConnections( const QPersistentModelIndex& idx, int accountId
Tomahawk::Accounts::Account* account = Tomahawk::Accounts::Account* account =
idx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole ) idx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole )
.value< QList< Tomahawk::Accounts::Account* > >().at( accountIdx ); .value< QList< Tomahawk::Accounts::Account* > >().at( accountIdx );
if ( account ) if ( account )
{ {
connect( m_statusToggle, SIGNAL( toggled( bool ) ), connect( m_statusToggle, SIGNAL( toggled( bool ) ), SLOT( changeAccountConnectionState( bool ) ) );
this, SLOT( changeAccountConnectionState( bool ) ) ); connect( m_inviteButton, SIGNAL( clicked() ), SLOT( sendInvite() ) );
connect( m_inviteButton, SIGNAL( clicked() ), connect( m_inviteEdit, SIGNAL( returnPressed() ), SLOT( sendInvite() ) );
this, SLOT( sendInvite() ) );
connect( m_inviteEdit, SIGNAL( returnPressed() ),
this, SLOT( sendInvite() ) );
if ( account->sipPlugin() ) if ( account->sipPlugin() )
{ {
@@ -325,13 +343,16 @@ AccountWidget::setupConnections( const QPersistentModelIndex& idx, int accountId
} }
} }
void void
AccountWidget::setConnectionState( bool state ) AccountWidget::setConnectionState( bool state )
{ {
m_statusToggle->setChecked( state ); m_statusToggle->setChecked( state );
} }
bool AccountWidget::connectionState() const
bool
AccountWidget::connectionState() const
{ {
return m_statusToggle->isChecked() || m_statusToggle->backChecked(); return m_statusToggle->isChecked() || m_statusToggle->backChecked();
} }