From 3b507ff7a8d8daa3a9213f975ed09eee3ecce1d8 Mon Sep 17 00:00:00 2001 From: Alejandro Wainzinger Date: Mon, 13 Dec 2010 18:49:02 -0800 Subject: [PATCH] Make the Connect/Disconnect button do as advertised. Needs some more safety checks likely, but this will do for now. --- include/tomahawk/sourcelist.h | 1 + src/sip/SipHandler.cpp | 13 +++++++++++++ src/sip/SipHandler.h | 2 ++ src/sip/jabber/jabber_p.cpp | 8 ++++++-- src/sip/jabber/jabber_p.h | 3 +-- src/sourcelist.cpp | 10 ++++++++++ src/tomahawkwindow.cpp | 1 + 7 files changed, 34 insertions(+), 4 deletions(-) diff --git a/include/tomahawk/sourcelist.h b/include/tomahawk/sourcelist.h index 12320c6d7..4998ff350 100644 --- a/include/tomahawk/sourcelist.h +++ b/include/tomahawk/sourcelist.h @@ -19,6 +19,7 @@ public: void add( const Tomahawk::source_ptr& s ); void remove( const Tomahawk::source_ptr& s ); void remove( Tomahawk::Source* s ); + void removeAllRemote(); QList sources() const; Tomahawk::source_ptr get( const QString& username ) const; diff --git a/src/sip/SipHandler.cpp b/src/sip/SipHandler.cpp index f101eadcb..3767bdd05 100644 --- a/src/sip/SipHandler.cpp +++ b/src/sip/SipHandler.cpp @@ -12,6 +12,7 @@ SipHandler::SipHandler( QObject* parent ) : QObject( parent ) { + m_connected = false; loadPlugins(); } @@ -80,6 +81,7 @@ SipHandler::connect() { foreach( SipPlugin* sip, m_plugins ) sip->connect(); + m_connected = true; } @@ -88,6 +90,17 @@ SipHandler::disconnect() { foreach( SipPlugin* sip, m_plugins ) sip->disconnect(); + APP->sourcelist().removeAllRemote(); + m_connected = false; +} + +void +SipHandler::toggleConnect() +{ + if( m_connected ) + disconnect(); + else + connect(); } diff --git a/src/sip/SipHandler.h b/src/sip/SipHandler.h index f1ea7d3ff..7055cdacd 100644 --- a/src/sip/SipHandler.h +++ b/src/sip/SipHandler.h @@ -21,6 +21,7 @@ public slots: void connect(); void disconnect(); + void toggleConnect(); signals: void connected(); @@ -38,6 +39,7 @@ private: void loadPlugin( QObject* plugin ); QList< SipPlugin* > m_plugins; + bool m_connected; }; #endif diff --git a/src/sip/jabber/jabber_p.cpp b/src/sip/jabber/jabber_p.cpp index dea6f6604..d6409ce51 100644 --- a/src/sip/jabber/jabber_p.cpp +++ b/src/sip/jabber/jabber_p.cpp @@ -247,6 +247,7 @@ Jabber_p::onDisconnect( ConnectionError e ) { qDebug() << "Jabber Disconnected"; QString error; + bool triggeredDisconnect = false; switch( e ) { @@ -330,14 +331,17 @@ Jabber_p::onDisconnect( ConnectionError e ) default : error = "UNKNOWN ERROR"; + triggeredDisconnect = true; } 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(); - // trigger reconnect + } diff --git a/src/sip/jabber/jabber_p.h b/src/sip/jabber/jabber_p.h index 66ab35f77..87af4779a 100644 --- a/src/sip/jabber/jabber_p.h +++ b/src/sip/jabber/jabber_p.h @@ -66,8 +66,6 @@ public: void setProxy( QNetworkProxy* proxy ); - void disconnect(); - /// GLOOX IMPLEMENTATION STUFF FOLLOWS virtual void onConnect(); virtual void onDisconnect( gloox::ConnectionError e ); @@ -124,6 +122,7 @@ public slots: void sendMsg( const QString& to, const QString& msg ); void broadcastMsg( const QString& msg ); void addContact( const QString& jid, const QString& msg = QString() ); + void disconnect(); private slots: void doJabberRecv(); diff --git a/src/sourcelist.cpp b/src/sourcelist.cpp index 2999bbaeb..631028ad6 100644 --- a/src/sourcelist.cpp +++ b/src/sourcelist.cpp @@ -69,6 +69,16 @@ SourceList::remove( Tomahawk::Source* s ) emit sourceRemoved( src ); } +void +SourceList::removeAllRemote() +{ + foreach( source_ptr s, m_sources ) + { + if( s != m_local ) + remove( s ); + } +} + QList SourceList::sources() const diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index 56bd9166e..160e8ac34 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -170,6 +170,7 @@ TomahawkWindow::setupSignals() connect( ui->actionCreatePlaylist, SIGNAL( triggered() ), SLOT( createPlaylist() )); connect( ui->actionAboutTomahawk, SIGNAL( triggered() ), SLOT( showAboutTomahawk() ) ); connect( ui->actionExit, SIGNAL( triggered() ), APP, SLOT( quit() ) ); + connect( ui->statusButton, SIGNAL( clicked() ), APP->sipHandler(), SLOT(toggleConnect() ) ); // connect( APP->sipHandler(), SIGNAL( connected() ), SLOT( onSipConnected() ) );