From a70db6d245719b644cc93f8118248591c98ce2f1 Mon Sep 17 00:00:00 2001 From: "mscott%netscape.com" Date: Wed, 3 May 2000 21:21:35 +0000 Subject: [PATCH] pass progress not as a percent but with a current and max byte count Use progress event sink instead of nsIMsgStatusFeedback. --- mailnews/news/src/nsNNTPProtocol.cpp | 79 +++++----------------------- mailnews/news/src/nsNNTPProtocol.h | 4 +- 2 files changed, 15 insertions(+), 68 deletions(-) diff --git a/mailnews/news/src/nsNNTPProtocol.cpp b/mailnews/news/src/nsNNTPProtocol.cpp index 6d8b9fc4b3f..a01ca3a44d2 100644 --- a/mailnews/news/src/nsNNTPProtocol.cpp +++ b/mailnews/news/src/nsNNTPProtocol.cpp @@ -3526,15 +3526,7 @@ PRInt32 nsNNTPProtocol::DisplayNewsRC() nsCOMPtr mailnewsurl = do_QueryInterface(m_runningURL); if (mailnewsurl) status = SendData(mailnewsurl, outputBuffer); - - percent = (m_newsRCListCount) ? - (PRInt32) (100.0 * ( (double)m_newsRCListIndex / (double)m_newsRCListCount )) : - 0; -#ifdef UNREADY_CODE - FE_SetProgressBarPercent (ce->window_id, percent); -#else - SetProgressBarPercent(percent); -#endif + SetProgressBarPercent(m_newsRCListCount, m_newsRCListIndex); /* only update every 20 groups for speed */ if ((m_newsRCListCount <= NEWS_GROUP_DISPLAY_FREQ) || (m_newsRCListIndex % NEWS_GROUP_DISPLAY_FREQ) == 0 || @@ -3546,18 +3538,11 @@ PRInt32 nsNNTPProtocol::DisplayNewsRC() PR_snprintf (thisGroup, sizeof(thisGroup), "%ld", (long) m_newsRCListIndex); PR_snprintf (totalGroups, sizeof(totalGroups), "%ld", (long) m_newsRCListCount); -#ifdef UNREADY_CODE - statusText = PR_smprintf (XP_GetString(XP_THERMO_PERCENT_FORM), thisGroup, totalGroups); -#else + statusText = PR_smprintf ("%s / %s", thisGroup, totalGroups); -#endif if (statusText) { -#ifdef UNREADY_CODE - FE_Progress (ce->window_id, statusText); -#else SetProgressStatus(statusText); -#endif PR_Free(statusText); } } @@ -3572,11 +3557,7 @@ PRInt32 nsNNTPProtocol::DisplayNewsRC() { if (m_newsRCListCount) { -#ifdef UNREADY_CODE - FE_SetProgressBarPercent (ce->window_id, -1); -#else - SetProgressBarPercent(-1); -#endif + SetProgressBarPercent(0, -1); m_newsRCListCount = 0; } else if (m_responseCode == MK_NNTP_RESPONSE_LIST_OK) @@ -4974,56 +4955,22 @@ nsresult nsNNTPProtocol::CloseSocket() return nsMsgProtocol::CloseSocket(); } -void nsNNTPProtocol::SetProgressBarPercent(int percent) +void nsNNTPProtocol::SetProgressBarPercent(PRUint32 aProgress, PRUint32 aProgressMax) { - PR_LOG(NNTP,PR_LOG_ALWAYS,("nsNNTPProtocol::SetProgressBarPercent(%d)",percent)); - PRUnichar *progressMsg = nsnull; - // PRUnichar *progressMsg = NNTPGetStringByID(aMsgId); - - if (!m_runningURL) return; - - nsCOMPtr mailnewsUrl = do_QueryInterface(m_runningURL); - if (mailnewsUrl) { - nsCOMPtr feedback; - mailnewsUrl->GetStatusFeedback(getter_AddRefs(feedback)); - - char *printfString = PR_smprintf("%d%%", percent); - if (printfString) { - nsString formattedString; formattedString.AssignWithConversion(printfString); - progressMsg = nsCRT::strdup(formattedString.GetUnicode()); - } - if (feedback) { - feedback->ShowProgress(percent); - feedback->ShowStatusString(progressMsg); - } - } - PR_FREEIF(progressMsg); + if (mProgressEventSink) + mProgressEventSink->OnProgress(this, m_channelContext, aProgress, aProgressMax); } void nsNNTPProtocol::SetProgressStatus(char *message) { - PR_LOG(NNTP,PR_LOG_ALWAYS,("nsNNTPProtocol::SetProgressStatus(%s)",message)); - PRUnichar *progressMsg = nsnull; - // PRUnichar *progressMsg = NNTPGetStringByID(aMsgId); - - if (!m_runningURL) return; - - nsCOMPtr mailnewsUrl = do_QueryInterface(m_runningURL); - if (mailnewsUrl) { - nsCOMPtr feedback; - mailnewsUrl->GetStatusFeedback(getter_AddRefs(feedback)); - - char *printfString = PR_smprintf("%s", message); - if (printfString) { - nsString formattedString; formattedString.AssignWithConversion(printfString); - progressMsg = nsCRT::strdup(formattedString.GetUnicode()); - } - if (feedback) { - feedback->ShowStatusString(progressMsg); - } - } - PR_FREEIF(progressMsg); + PR_LOG(NNTP,PR_LOG_ALWAYS,("nsNNTPProtocol::SetProgressStatus(%s)",message)); + if (mProgressEventSink) + { + nsAutoString formattedString; + formattedString.AssignWithConversion(message); + mProgressEventSink->OnStatus(this, m_channelContext, formattedString.GetUnicode()); + } } NS_IMETHODIMP nsNNTPProtocol::GetContentType(char * *aContentType) diff --git a/mailnews/news/src/nsNNTPProtocol.h b/mailnews/news/src/nsNNTPProtocol.h index e7e5652e1ed..c1ee52d7016 100644 --- a/mailnews/news/src/nsNNTPProtocol.h +++ b/mailnews/news/src/nsNNTPProtocol.h @@ -385,9 +385,9 @@ private: nsresult ParseURL(nsIURI * aURL, PRBool * bValP, char ** aGroup, char ** aMessageID, char ** aCommandSpecificData); - void SetProgressBarPercent(int percent); + void SetProgressBarPercent(PRUint32 aProgress, PRUint32 aProgressMax); void SetProgressStatus(char * message); - nsresult InitializeNewsFolderFromUri(const char *uri); + nsresult InitializeNewsFolderFromUri(const char *uri); }; NS_BEGIN_EXTERN_C