From: Jordan Lee Date: Sun, 20 Oct 2013 19:57:48 +0000 (+0000) Subject: (trunk, qt) #5514 'enhanced network status in transmission-qt' -- patch by rb07 X-Git-Tag: 2.83~67 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=632edad03df1f007e4943f53dbb934c3cbdd5a47;p=transmission (trunk, qt) #5514 'enhanced network status in transmission-qt' -- patch by rb07 --- diff --git a/qt/mainwin.cc b/qt/mainwin.cc index 82eac9086..d29191d06 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -118,6 +118,7 @@ TrMainWindow :: TrMainWindow (Session& session, Prefs& prefs, TorrentModel& mode myLastSendTime (0), myLastReadTime (0), myNetworkTimer (this), + myNetworkError (false), myRefreshTrayIconTimer (this), myRefreshActionSensitivityTimer (this) { @@ -289,6 +290,8 @@ TrMainWindow :: TrMainWindow (Session& session, Prefs& prefs, TorrentModel& mode connect (&mySession, SIGNAL (dataReadProgress ()), this, SLOT (dataReadProgress ())); connect (&mySession, SIGNAL (dataSendProgress ()), this, SLOT (dataSendProgress ())); connect (&mySession, SIGNAL (httpAuthenticationRequired ()), this, SLOT (wrongAuthentication ())); + connect (&mySession, SIGNAL (error (QNetworkReply::NetworkError)), this, SLOT (onError (QNetworkReply::NetworkError))); + connect (&mySession, SIGNAL (errorMessage (const QString)), this, SLOT (errorMessage(const QString))); if (mySession.isServer ()) { @@ -1346,7 +1349,9 @@ TrMainWindow :: updateNetworkIcon () const bool isReading = secondsSinceLastRead <= period; const char * key; - if (isSending && isReading) + if (myNetworkError) + key = "network-error"; + else if (isSending && isReading) key = "network-transmit-receive"; else if (isSending) key = "network-transmit"; @@ -1361,9 +1366,11 @@ TrMainWindow :: updateNetworkIcon () const QString url = mySession.getRemoteUrl ().host (); if (!myLastReadTime) tip = tr ("%1 has not responded yet").arg (url); - else if (secondsSinceLastRead < 60) + else if (myNetworkError) + tip = tr (myErrorMessage.toLatin1 ().constData ()); + else if (secondsSinceLastRead < 30) tip = tr ("%1 is responding").arg (url); - else if (secondsSinceLastRead < (60*10)) + else if (secondsSinceLastRead < (60*2)) tip = tr ("%1 last responded %2 ago").arg (url).arg (Formatter::timeToString (secondsSinceLastRead)); else tip = tr ("%1 is not responding").arg (url); @@ -1381,15 +1388,29 @@ TrMainWindow :: onNetworkTimer () void TrMainWindow :: dataReadProgress () { + if (!myNetworkError) myLastReadTime = time (NULL); - updateNetworkIcon (); } void TrMainWindow :: dataSendProgress () { myLastSendTime = time (NULL); - updateNetworkIcon (); +} + +void +TrMainWindow :: onError (QNetworkReply::NetworkError code) +{ + if (code != QNetworkReply::NoError) + myNetworkError = true; + else + myNetworkError = false; +} + +void +TrMainWindow :: errorMessage (const QString msg) +{ + myErrorMessage = msg; } void diff --git a/qt/mainwin.h b/qt/mainwin.h index 09279d69b..7b282aace 100644 --- a/qt/mainwin.h +++ b/qt/mainwin.h @@ -23,6 +23,7 @@ #include #include #include +#include extern "C" { @@ -76,6 +77,7 @@ class TrMainWindow: public QMainWindow time_t myLastSendTime; time_t myLastReadTime; QTimer myNetworkTimer; + bool myNetworkError; QTimer myRefreshTrayIconTimer; QTimer myRefreshActionSensitivityTimer; QAction * myDlimitOffAction; @@ -121,6 +123,8 @@ class TrMainWindow: public QMainWindow void toggleSpeedMode (); void dataReadProgress (); void dataSendProgress (); + void onError (QNetworkReply::NetworkError); + void errorMessage (const QString); void toggleWindows (bool doShow); void onSetPrefs (); void onSetPrefs (bool); @@ -155,6 +159,7 @@ class TrMainWindow: public QMainWindow QLabel * myDownloadSpeedLabel; QLabel * myUploadSpeedLabel; QLabel * myNetworkLabel; + QString myErrorMessage; public slots: void startAll (); diff --git a/qt/session.cc b/qt/session.cc index 374ec9c99..a78d40cec 100644 --- a/qt/session.cc +++ b/qt/session.cc @@ -701,6 +701,7 @@ Session :: exec (const char * json) reply->setProperty (REQUEST_DATA_PROPERTY_KEY, requestData); connect (reply, SIGNAL (downloadProgress (qint64,qint64)), this, SIGNAL (dataReadProgress ())); connect (reply, SIGNAL (uploadProgress (qint64,qint64)), this, SIGNAL (dataSendProgress ())); + connect (reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SIGNAL(error(QNetworkReply::NetworkError))); #ifdef DEBUG_HTTP std::cerr << "sending " << "POST " << qPrintable (myUrl.path ()) << std::endl; @@ -737,7 +738,7 @@ Session :: onFinished (QNetworkReply * reply) } else if (reply->error () != QNetworkReply::NoError) { - std::cerr << "http error: " << qPrintable (reply->errorString ()) << std::endl; + emit (errorMessage(reply->errorString ())); } else { @@ -746,6 +747,7 @@ Session :: onFinished (QNetworkReply * reply) int jsonLength (response.size ()); if (jsonLength>0 && json[jsonLength-1] == '\n') --jsonLength; parseResponse (json, jsonLength); + emit (error(QNetworkReply::NoError)); } reply->deleteLater (); diff --git a/qt/session.h b/qt/session.h index 3fd30ef99..ef72b1948 100644 --- a/qt/session.h +++ b/qt/session.h @@ -21,6 +21,7 @@ #include #include #include +#include class QStringList; @@ -144,6 +145,8 @@ class Session: public QObject void torrentsRemoved (struct tr_variant * torrentList); void dataReadProgress (); void dataSendProgress (); + void error (QNetworkReply::NetworkError); + void errorMessage (const QString); void httpAuthenticationRequired (); private: