diff --git a/mailnews/news/resources/locale/en-US/news.properties b/mailnews/news/resources/locale/en-US/news.properties index 215e34580aa..6e4b78561e5 100644 --- a/mailnews/news/resources/locale/en-US/news.properties +++ b/mailnews/news/resources/locale/en-US/news.properties @@ -38,7 +38,7 @@ enterPassword=Please enter a password for news server access enterPasswordTitle=News Server Password Required okButtonText=Download -bytesReceived=received %S bytes +bytesReceived=%S K read (at %SK/sec) checkingForNewNews=Checking newsgroup %S of %S for new messages # LOCALIZATION NOTE (Error -304): In the following item, don't translate "NNTP" diff --git a/mailnews/news/src/nsNNTPProtocol.cpp b/mailnews/news/src/nsNNTPProtocol.cpp index 0932e75a020..50217a94c1f 100644 --- a/mailnews/news/src/nsNNTPProtocol.cpp +++ b/mailnews/news/src/nsNNTPProtocol.cpp @@ -456,7 +456,9 @@ nsNNTPProtocol::nsNNTPProtocol(nsIURI * aURL, nsIMsgWindow *aMsgWindow) m_commandSpecificData = nsnull; m_searchData = nsnull; + mBytesReceived = 0; + mBytesReceivedSinceLastStatusUpdate = 0; if (aMsgWindow) { m_msgWindow = aMsgWindow; @@ -1262,6 +1264,7 @@ PRInt32 nsNNTPProtocol::NewsResponse(nsIInputStream * inputStream, PRUint32 leng FE_GraphProgress(ce->window_id, ce->URL_s, ce->bytes_received, status, ce->URL_s->content_length); #else mBytesReceived += status; + mBytesReceivedSinceLastStatusUpdate += status; #endif } @@ -2278,6 +2281,7 @@ PRInt32 nsNNTPProtocol::ReadArticle(nsIInputStream * inputStream, PRUint32 lengt ce->URL_s->content_length); #else mBytesReceived += status; + mBytesReceivedSinceLastStatusUpdate += status; #endif } @@ -2733,6 +2737,7 @@ PRInt32 nsNNTPProtocol::BeginNewsgroups() ce->bytes_received = 0; #else mBytesReceived = 0; + mBytesReceivedSinceLastStatusUpdate = 0; #endif return(status); } @@ -2805,6 +2810,7 @@ PRInt32 nsNNTPProtocol::ProcessNewsgroups(nsIInputStream * inputStream, PRUint32 FE_GraphProgress(ce->window_id, ce->URL_s, ce->bytes_received, status, ce->URL_s->content_length); #else mBytesReceived += status; + mBytesReceivedSinceLastStatusUpdate += status; #endif } @@ -2835,6 +2841,7 @@ PRInt32 nsNNTPProtocol::ProcessNewsgroups(nsIInputStream * inputStream, PRUint32 ce->bytes_received++; /* small numbers of groups never seem to trigger this */ #else mBytesReceived += status; + mBytesReceivedSinceLastStatusUpdate += status; #endif #if 0 m_newsHost->AddNewNewsgroup(line, oldest, youngest, flag, PR_FALSE); @@ -2865,7 +2872,10 @@ PRInt32 nsNNTPProtocol::BeginReadNewsList() { m_readNewsListCount = 0; m_nextState = NNTP_READ_LIST; + mBytesReceived = 0; + mBytesReceivedSinceLastStatusUpdate = 0; + PRInt32 status = 0; #ifdef UNREADY_CODE NET_Progress(ce->window_id, XP_GetString(XP_PROGRESS_RECEIVE_NEWSGROUP)); @@ -2924,12 +2934,15 @@ PRInt32 nsNNTPProtocol::ReadNewsList(nsIInputStream * inputStream, PRUint32 leng FE_GraphProgress(ce->window_id, ce->URL_s, ce->bytes_received, status, ce->URL_s->content_length); #else mBytesReceived += status; + mBytesReceivedSinceLastStatusUpdate += status; - if (m_msgWindow) { - nsCOMPtr msgStatusFeedback; + // only update every 10 KB + if ((mBytesReceivedSinceLastStatusUpdate > (1024 * 25)) && m_msgWindow) { + mBytesReceivedSinceLastStatusUpdate = 0; + nsCOMPtr msgStatusFeedback; - rv = m_msgWindow->GetStatusFeedback(getter_AddRefs(msgStatusFeedback)); - if (NS_FAILED(rv)) return rv; + rv = m_msgWindow->GetStatusFeedback(getter_AddRefs(msgStatusFeedback)); + if (NS_FAILED(rv)) return rv; // XXXXX nsXPIDLString statusString; @@ -2942,17 +2955,22 @@ PRInt32 nsNNTPProtocol::ReadNewsList(nsIInputStream * inputStream, PRUint32 leng getter_AddRefs(bundle)); NS_ENSURE_SUCCESS(rv, rv); - nsAutoString bytesStr; bytesStr.AppendInt(mBytesReceived); - - const PRUnichar *formatStrings[] = { bytesStr.GetUnicode() }; - NS_NAMED_LITERAL_STRING(literalPropertyTag, "bytesReceived"); + nsString kBytesStr; + kBytesStr.AppendInt(mBytesReceived / 1024); + + nsString kRateStr; + // todo, fix this + //kRateStr.AppendFloat(0.0); + kRateStr.AppendWithConversion("?.?"); + const PRUnichar *formatStrings[2] = { kBytesStr.GetUnicode(), kRateStr.GetUnicode() }; + NS_NAMED_LITERAL_STRING(literalPropertyTag, "bytesReceived"); const PRUnichar *propertyTag = literalPropertyTag.get(); rv = bundle->FormatStringFromName(propertyTag, - formatStrings, 1, + formatStrings, 2, getter_Copies(statusString)); - rv = msgStatusFeedback->ShowStatusString(statusString); - if (NS_FAILED(rv)) return rv; + rv = msgStatusFeedback->ShowStatusString(statusString); + if (NS_FAILED(rv)) return rv; } #endif } @@ -3266,6 +3284,7 @@ PRInt32 nsNNTPProtocol::ReadXover(nsIInputStream * inputStream, PRUint32 length) ce->URL_s->content_length); #else mBytesReceived += status; + mBytesReceivedSinceLastStatusUpdate += status; #endif } @@ -4395,6 +4414,7 @@ PRInt32 nsNNTPProtocol::ListXActiveResponse(nsIInputStream * inputStream, PRUint FE_GraphProgress(ce->window_id, ce->URL_s, ce->bytes_received, status, ce->URL_s->content_length); #else mBytesReceived += status; + mBytesReceivedSinceLastStatusUpdate += status; #endif } diff --git a/mailnews/news/src/nsNNTPProtocol.h b/mailnews/news/src/nsNNTPProtocol.h index 9fd0dc998b9..df90d4bf1e3 100644 --- a/mailnews/news/src/nsNNTPProtocol.h +++ b/mailnews/news/src/nsNNTPProtocol.h @@ -404,6 +404,7 @@ private: nsCOMPtr mUpdateTimer; nsresult AlertError(PRInt32 errorCode, const char *text); PRInt32 mBytesReceived; + PRInt32 mBytesReceivedSinceLastStatusUpdate; }; NS_BEGIN_EXTERN_C diff --git a/mailnews/news/src/nsNntpIncomingServer.cpp b/mailnews/news/src/nsNntpIncomingServer.cpp index 58c235ae629..cd67dd2429b 100644 --- a/mailnews/news/src/nsNntpIncomingServer.cpp +++ b/mailnews/news/src/nsNntpIncomingServer.cpp @@ -43,6 +43,9 @@ #define PREF_MAIL_NEWSRC_ROOT "mail.newsrc_root" #define HOSTINFO_FILE_NAME "hostinfo.dat" +#define OLD_PERCENT_INITIAL_VALUE 0 +#define PERCENT_CHANGE_THRESHHOLD 10 + #define NEWS_DELIMITER '.' #define HOSTINFO_COUNT_MAX 200 /* number of groups to process at a time when reading the list from the hostinfo.dat file */ @@ -92,6 +95,7 @@ nsNntpIncomingServer::nsNntpIncomingServer() : nsMsgLineBuffer(nsnull, PR_FALSE) mHasSeenBeginGroups = PR_FALSE; mVersion = 0; mGroupsOnServerIndex = 0; + mOldPercent = OLD_PERCENT_INITIAL_VALUE; mGroupsOnServerCount = 0; SetupNewsrcSaveTimer(); } @@ -868,6 +872,7 @@ nsNntpIncomingServer::StartPopulatingFromHostInfo() #endif mGroupsOnServerCount = mGroupsOnServer.Count(); + mOldPercent = OLD_PERCENT_INITIAL_VALUE; nsCString currentGroup; while (mGroupsOnServerIndex < mGroupsOnServerCount) { @@ -890,10 +895,12 @@ nsNntpIncomingServer::StartPopulatingFromHostInfo() if (NS_FAILED(rv)) return rv; if (mGroupsOnServerCount != 0) { - // xxx todo - // if old percent == new percent, don't call ShowProgress() - // why poke the front end, through xpconnect, if we don't have to? - rv = msgStatusFeedback->ShowProgress((mGroupsOnServerIndex * 100) / mGroupsOnServerCount); + // only poke the front end if the percentage has grown by at least PERCENT_CHANGE_THRESHHOLD + PRInt32 newPercent = (mGroupsOnServerIndex * 100) / mGroupsOnServerCount; + if (newPercent > (mOldPercent + PERCENT_CHANGE_THRESHHOLD)) { + rv = msgStatusFeedback->ShowProgress(newPercent); + } + mOldPercent = newPercent; } if (NS_FAILED(rv)) return rv; } diff --git a/mailnews/news/src/nsNntpIncomingServer.h b/mailnews/news/src/nsNntpIncomingServer.h index 48e19c43d27..4318cd2704a 100644 --- a/mailnews/news/src/nsNntpIncomingServer.h +++ b/mailnews/news/src/nsNntpIncomingServer.h @@ -87,6 +87,7 @@ protected: private: PRInt32 mGroupsOnServerIndex; PRInt32 mGroupsOnServerCount; + PRInt32 mOldPercent; nsCStringArray mGroupsOnServer; nsCStringArray mSubscribedNewsgroups;