myLastSendTime (0),
myLastReadTime (0),
myNetworkTimer (this),
+ myNetworkError (false),
myRefreshTrayIconTimer (this),
myRefreshActionSensitivityTimer (this)
{
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 ())
{
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";
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);
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
#include <QSystemTrayIcon>
#include <QTimer>
#include <QWidgetList>
+#include <QNetworkReply>
extern "C"
{
time_t myLastSendTime;
time_t myLastReadTime;
QTimer myNetworkTimer;
+ bool myNetworkError;
QTimer myRefreshTrayIconTimer;
QTimer myRefreshActionSensitivityTimer;
QAction * myDlimitOffAction;
void toggleSpeedMode ();
void dataReadProgress ();
void dataSendProgress ();
+ void onError (QNetworkReply::NetworkError);
+ void errorMessage (const QString);
void toggleWindows (bool doShow);
void onSetPrefs ();
void onSetPrefs (bool);
QLabel * myDownloadSpeedLabel;
QLabel * myUploadSpeedLabel;
QLabel * myNetworkLabel;
+ QString myErrorMessage;
public slots:
void startAll ();
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;
}
else if (reply->error () != QNetworkReply::NoError)
{
- std::cerr << "http error: " << qPrintable (reply->errorString ()) << std::endl;
+ emit (errorMessage(reply->errorString ()));
}
else
{
int jsonLength (response.size ());
if (jsonLength>0 && json[jsonLength-1] == '\n') --jsonLength;
parseResponse (json, jsonLength);
+ emit (error(QNetworkReply::NoError));
}
reply->deleteLater ();