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

Make the Connect/Disconnect button do as advertised. Needs some more safety checks likely, but this will do for now.

This commit is contained in:
Alejandro Wainzinger
2010-12-13 18:49:02 -08:00
parent e882c4f0a9
commit 3b507ff7a8
7 changed files with 34 additions and 4 deletions

View File

@@ -19,6 +19,7 @@ public:
void add( const Tomahawk::source_ptr& s ); void add( const Tomahawk::source_ptr& s );
void remove( const Tomahawk::source_ptr& s ); void remove( const Tomahawk::source_ptr& s );
void remove( Tomahawk::Source* s ); void remove( Tomahawk::Source* s );
void removeAllRemote();
QList<Tomahawk::source_ptr> sources() const; QList<Tomahawk::source_ptr> sources() const;
Tomahawk::source_ptr get( const QString& username ) const; Tomahawk::source_ptr get( const QString& username ) const;

View File

@@ -12,6 +12,7 @@
SipHandler::SipHandler( QObject* parent ) SipHandler::SipHandler( QObject* parent )
: QObject( parent ) : QObject( parent )
{ {
m_connected = false;
loadPlugins(); loadPlugins();
} }
@@ -80,6 +81,7 @@ SipHandler::connect()
{ {
foreach( SipPlugin* sip, m_plugins ) foreach( SipPlugin* sip, m_plugins )
sip->connect(); sip->connect();
m_connected = true;
} }
@@ -88,6 +90,17 @@ SipHandler::disconnect()
{ {
foreach( SipPlugin* sip, m_plugins ) foreach( SipPlugin* sip, m_plugins )
sip->disconnect(); sip->disconnect();
APP->sourcelist().removeAllRemote();
m_connected = false;
}
void
SipHandler::toggleConnect()
{
if( m_connected )
disconnect();
else
connect();
} }

View File

@@ -21,6 +21,7 @@ public slots:
void connect(); void connect();
void disconnect(); void disconnect();
void toggleConnect();
signals: signals:
void connected(); void connected();
@@ -38,6 +39,7 @@ private:
void loadPlugin( QObject* plugin ); void loadPlugin( QObject* plugin );
QList< SipPlugin* > m_plugins; QList< SipPlugin* > m_plugins;
bool m_connected;
}; };
#endif #endif

View File

@@ -247,6 +247,7 @@ Jabber_p::onDisconnect( ConnectionError e )
{ {
qDebug() << "Jabber Disconnected"; qDebug() << "Jabber Disconnected";
QString error; QString error;
bool triggeredDisconnect = false;
switch( e ) switch( e )
{ {
@@ -330,14 +331,17 @@ Jabber_p::onDisconnect( ConnectionError e )
default : default :
error = "UNKNOWN ERROR"; error = "UNKNOWN ERROR";
triggeredDisconnect = true;
} }
qDebug() << "Connection error msg:" << error; qDebug() << "Connection error msg:" << error;
emit authError( e, error ); // Assume that an unknown error is due to a disconnect triggered by the user
if( !triggeredDisconnect )
emit authError( e, error ); // trigger reconnect
emit disconnected(); emit disconnected();
// trigger reconnect
} }

View File

@@ -66,8 +66,6 @@ public:
void setProxy( QNetworkProxy* proxy ); void setProxy( QNetworkProxy* proxy );
void disconnect();
/// GLOOX IMPLEMENTATION STUFF FOLLOWS /// GLOOX IMPLEMENTATION STUFF FOLLOWS
virtual void onConnect(); virtual void onConnect();
virtual void onDisconnect( gloox::ConnectionError e ); virtual void onDisconnect( gloox::ConnectionError e );
@@ -124,6 +122,7 @@ public slots:
void sendMsg( const QString& to, const QString& msg ); void sendMsg( const QString& to, const QString& msg );
void broadcastMsg( const QString& msg ); void broadcastMsg( const QString& msg );
void addContact( const QString& jid, const QString& msg = QString() ); void addContact( const QString& jid, const QString& msg = QString() );
void disconnect();
private slots: private slots:
void doJabberRecv(); void doJabberRecv();

View File

@@ -69,6 +69,16 @@ SourceList::remove( Tomahawk::Source* s )
emit sourceRemoved( src ); emit sourceRemoved( src );
} }
void
SourceList::removeAllRemote()
{
foreach( source_ptr s, m_sources )
{
if( s != m_local )
remove( s );
}
}
QList<source_ptr> QList<source_ptr>
SourceList::sources() const SourceList::sources() const

View File

@@ -170,6 +170,7 @@ TomahawkWindow::setupSignals()
connect( ui->actionCreatePlaylist, SIGNAL( triggered() ), SLOT( createPlaylist() )); connect( ui->actionCreatePlaylist, SIGNAL( triggered() ), SLOT( createPlaylist() ));
connect( ui->actionAboutTomahawk, SIGNAL( triggered() ), SLOT( showAboutTomahawk() ) ); connect( ui->actionAboutTomahawk, SIGNAL( triggered() ), SLOT( showAboutTomahawk() ) );
connect( ui->actionExit, SIGNAL( triggered() ), APP, SLOT( quit() ) ); connect( ui->actionExit, SIGNAL( triggered() ), APP, SLOT( quit() ) );
connect( ui->statusButton, SIGNAL( clicked() ), APP->sipHandler(), SLOT(toggleConnect() ) );
// <SipHandler> // <SipHandler>
connect( APP->sipHandler(), SIGNAL( connected() ), SLOT( onSipConnected() ) ); connect( APP->sipHandler(), SIGNAL( connected() ), SLOT( onSipConnected() ) );