(trunk, qt) #5514 'enhanced network status in transmission-qt' -- patch by rb07
This commit is contained in:
parent
ce6b9dfad4
commit
632edad03d
|
@ -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
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <QSystemTrayIcon>
|
||||
#include <QTimer>
|
||||
#include <QWidgetList>
|
||||
#include <QNetworkReply>
|
||||
|
||||
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 ();
|
||||
|
|
|
@ -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 ();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
#include <QNetworkReply>
|
||||
|
||||
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:
|
||||
|
|
Loading…
Reference in New Issue