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

View File

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