diff --git a/src/libtomahawk/network/Servent.cpp b/src/libtomahawk/network/Servent.cpp index 95aed6beb..b2e476e9e 100644 --- a/src/libtomahawk/network/Servent.cpp +++ b/src/libtomahawk/network/Servent.cpp @@ -976,6 +976,7 @@ Servent::ipDetected() { tLog() << Q_FUNC_INFO << "Failed parsing ip-autodetection response"; d->externalPort = -1; + emit ipDetectionFailed( QNetworkReply::NoError, tr( "Automatically detecting external IP failed: Could not parse JSON response." ) ); } else { @@ -988,6 +989,7 @@ Servent::ipDetected() { d->externalPort = -1; tLog() << Q_FUNC_INFO << "ip-autodetection returned an error:" << reply->errorString(); + emit ipDetectionFailed( reply->error(), tr( "Automatically detecting external IP failed: %1" ).arg( reply->errorString() ) ); } d->ready = true; diff --git a/src/libtomahawk/network/Servent.h b/src/libtomahawk/network/Servent.h index 0b879fafe..018b2f1e8 100644 --- a/src/libtomahawk/network/Servent.h +++ b/src/libtomahawk/network/Servent.h @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -83,10 +84,6 @@ public: void registerPeer( const Tomahawk::peerinfo_ptr& peerInfo ); void handleSipInfo( const Tomahawk::peerinfo_ptr& peerInfo ); -public slots: - void onSipInfoChanged(); - -public: void initiateConnection( const SipInfo& sipInfo, Connection* conn ); void reverseOfferRequest( ControlConnection* orig_conn, const QString &theirdbid, const QString& key, const QString& theirkey ); @@ -139,6 +136,14 @@ public: void queueForAclResult( const QString& username, const QSet& peerInfos ); signals: void dbSyncTriggered(); + + /** + * @brief ipDetectionFailed Emitted when the automatic external IP detection failed. + * @param error If the failure was caused by a network error, this is its error code. + * If the error wasn't network related, QNetworkReply::NoError will be returned. + * @param errorString A string explaining the error. + */ + void ipDetectionFailed( QNetworkReply::NetworkError error, QString errorString ); void streamStarted( StreamConnection* ); void streamFinished( StreamConnection* ); void ready(); @@ -157,6 +162,8 @@ public slots: void socketConnected(); void triggerDBSync(); + void onSipInfoChanged(); + private slots: void deleteLazyOffer( const QString& key ); void readyRead(); diff --git a/src/tomahawk/TomahawkApp.cpp b/src/tomahawk/TomahawkApp.cpp index a169de60b..103b1113d 100644 --- a/src/tomahawk/TomahawkApp.cpp +++ b/src/tomahawk/TomahawkApp.cpp @@ -31,13 +31,6 @@ #include "collection/Collection.h" #include "infosystem/InfoSystem.h" #include "infosystem/InfoSystemCache.h" -#include "accounts/AccountManager.h" -#include "accounts/spotify/SpotifyAccount.h" -#include "accounts/lastfm/LastFmAccount.h" -#include "database/Database.h" -#include "database/DatabaseCollection.h" -#include "database/DatabaseCommand_CollectionStats.h" -#include "database/DatabaseResolver.h" #include "playlist/dynamic/GeneratorFactory.h" #include "playlist/dynamic/echonest/EchonestGenerator.h" #include "playlist/dynamic/database/DatabaseGenerator.h" @@ -57,14 +50,22 @@ #include "database/DatabaseImpl.h" #include "network/Msg.h" +#include "accounts/lastfm/LastFmAccount.h" +#include "accounts/spotify/SpotifyAccount.h" +#include "accounts/spotify/SpotifyPlaylistUpdater.h" +#include "accounts/AccountManager.h" +#include "database/Database.h" +#include "database/DatabaseCollection.h" +#include "database/DatabaseCommand_CollectionStats.h" +#include "database/DatabaseResolver.h" #include "audio/AudioEngine.h" +#include "jobview/ErrorStatusMessage.h" +#include "jobview/JobStatusModel.h" +#include "jobview/JobStatusView.h" #include "utils/XspfLoader.h" #include "utils/JspfLoader.h" #include "utils/Logger.h" #include "utils/TomahawkUtilsGui.h" -#include "accounts/lastfm/LastFmAccount.h" -#include "accounts/spotify/SpotifyAccount.h" -#include "accounts/spotify/SpotifyPlaylistUpdater.h" #include "utils/TomahawkCache.h" #ifndef ENABLE_HEADLESS @@ -542,6 +543,7 @@ TomahawkApp::initServent() bool upnp = !arguments().contains( "--noupnp" ); int port = TomahawkSettings::instance()->externalPort(); + connect( Servent::instance(), SIGNAL( ipDetectionFailed( QNetworkReply::NetworkError, QString ) ), this, SLOT( ipDetectionFailed( QNetworkReply::NetworkError, QString ) ) ); #if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) if ( !Servent::instance()->startListening( QHostAddress( QHostAddress::Any ), upnp, port ) ) #else @@ -691,6 +693,20 @@ TomahawkApp::onInfoSystemReady() } +void +TomahawkApp::ipDetectionFailed( QNetworkReply::NetworkError error, QString errorString ) +{ + tLog() << Q_FUNC_INFO; + Q_UNUSED( error ); +#ifdef QT_NO_DEBUG + Q_UNUSED( errorString ); + JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Automatically detecting external IP failed." ) ) ); +#else + JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( errorString ) ); +#endif +} + + void TomahawkApp::spotifyApiCheckFinished() { diff --git a/src/tomahawk/TomahawkApp.h b/src/tomahawk/TomahawkApp.h index 39611b4c7..54e35ca54 100644 --- a/src/tomahawk/TomahawkApp.h +++ b/src/tomahawk/TomahawkApp.h @@ -115,6 +115,8 @@ private slots: void spotifyApiCheckFinished(); void onInfoSystemReady(); + void ipDetectionFailed( QNetworkReply::NetworkError error, QString errorString ); + private: void registerMetaTypes();