fix for #47829 and #63382. some code clean up, move hard coded string into

properties files.  sr=bienvenu.  thanks to jag for the initial patch.
This commit is contained in:
sspitzer%netscape.com 2000-12-20 23:56:22 +00:00
Родитель a63c3e7c14
Коммит a3e9d4ceeb
6 изменённых файлов: 230 добавлений и 273 удалений

Просмотреть файл

@ -39,8 +39,12 @@ enterPassword=Please enter a password for news server access
enterPasswordTitle=News Server Password Required
okButtonText=Download
noNewMessages=There are no new messages on the server.
downloadingHeaders=Downloading %S of %S headers
downloadingArticles=Downloading articles %S-%S
bytesReceived=Downloading newsgroups: %S received (%SK read at %SK/sec)
checkingForNewNews=Checking newsgroup %S of %S for new messages
newsError=NEWS ERROR:
# LOCALIZATION NOTE (Error -304): In the following item, don't translate "NNTP"
# Error - server error

Просмотреть файл

@ -23,9 +23,7 @@
#ifndef _NNTPCore_H__
#define _NNTPCore_H__
#if defined (DEBUG_seth_) || defined(DEBUG_sspitzer_)
#define DEBUG_NEWS 1
#endif
#define NEWS_MSGS_URL "chrome://messenger/locale/news.properties"
// The following string constants are protocol strings. I'm defining them as macros here
// so I don't have to sprinkle all of the strings throughout the protocol.

Просмотреть файл

@ -57,7 +57,8 @@
#include "nsINNTPHost.h"
#include "nsNNTPHost.h"
#include "msgCore.h"
#include "nntpCore.h"
#include "nsIStringBundle.h"
#include "plstr.h"
#include "prmem.h"
@ -84,7 +85,6 @@
#include "nsIScriptContext.h"
static NS_DEFINE_CID(kCNewsDB, NS_NEWSDB_CID);
static NS_DEFINE_CID(kCPrefServiceCID, NS_PREF_CID);
extern PRInt32 net_NewsChunkSize;
@ -133,7 +133,6 @@ nsNNTPNewsgroupList::Initialize(nsINNTPHost *host, nsINntpUrl *runningURL, nsINN
m_finishingXover = PR_FALSE;
m_startedUpdate = PR_FALSE;
memset(&m_knownArts, 0, sizeof(m_knownArts));
m_knownArts.group_name = m_groupName;
m_host = host;
@ -282,16 +281,7 @@ nsNNTPNewsgroupList::GetRangeOfArtsToDownload(nsIMsgWindow * aMsgWindow,
*first = 0;
*last = 0;
#ifdef HAVE_PANES
if (m_pane != NULL && !m_finishingXover && !m_startedUpdate)
{
m_startedUpdate = PR_TRUE;
m_pane->StartingUpdate(MSG_NotifyNone, 0, 0);
}
#endif
if (!m_newsDB)
{
if (!m_newsDB) {
nsresult err;
if ((err = GetDatabase(GetURI(), &m_newsDB)) != NS_OK) {
return err;
@ -348,19 +338,18 @@ nsNNTPNewsgroupList::GetRangeOfArtsToDownload(nsIMsgWindow * aMsgWindow,
m_newsDB->ExpireUpTo(first_possible, m_pane->GetContext());
m_pane->EndingUpdate(MSG_NotifyNone, 0, 0);
#endif /* HAVE_PANES */
if (m_knownArts.set->IsMember(last_possible)) // will this be progress pane?
{
#ifdef HAVE_PANES
char *noNewMsgs = XP_GetString(MK_NO_NEW_DISC_MSGS);
MWContext *context = m_pane->GetContext();
MSG_Pane* parentpane = m_pane->GetParentPane();
// send progress to parent pane, if any, because progress pane is going down.
if (parentpane)
context = parentpane->GetContext();
FE_Progress (context, noNewMsgs);
#else
SetProgressStatus("There are no new messages on the server.");
#endif /* HAVE_PANES */
if (m_knownArts.set->IsMember(last_possible)) {
nsXPIDLString statusString;
nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(NEWS_MSGS_URL, nsnull, getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
rv = bundle->GetStringFromName(NS_LITERAL_STRING("noNewMessages"), getter_Copies(statusString));
NS_ENSURE_SUCCESS(rv, rv);
SetProgressStatus(statusString);
}
}
}
@ -421,11 +410,8 @@ nsNNTPNewsgroupList::GetRangeOfArtsToDownload(nsIMsgWindow * aMsgWindow,
if (m_getOldMessages || !m_knownArts.set->IsMember(last_possible))
{
NS_WITH_SERVICE(nsIPref, prefs, kCPrefServiceCID, &rv);
if (NS_FAILED(rv) || (!prefs)) {
return rv;
}
nsCOMPtr <nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
PRBool notifyMaxExceededOn = PR_TRUE;
rv = nntpServer->GetNotifyOn(&notifyMaxExceededOn);
@ -590,7 +576,7 @@ nsNNTPNewsgroupList::InitXOVER(PRInt32 first_msg, PRInt32 last_msg)
return status;
}
#define NEWS_ART_DISPLAY_FREQ 10
#define NEWS_ART_DISPLAY_FREQ 20
/* Given a string and a length, removes any "Re:" strings from the front.
It also deals with that "Re[2]:" thing that some mailers do.
@ -866,27 +852,37 @@ nsNNTPNewsgroupList::ProcessXOVERLINE(const char *line, PRUint32 *status)
*/
if (m_lastMsgNumber > m_firstMsgNumber)
{
PRInt32 totToDownload = m_lastMsgToDownload - m_firstMsgToDownload + 1;
PRInt32 totalToDownload = m_lastMsgToDownload - m_firstMsgToDownload + 1;
PRInt32 lastIndex = m_lastProcessedNumber - m_firstMsgNumber + 1;
PRInt32 numDownloaded = lastIndex;
PRInt32 totIndex = m_lastMsgNumber - m_firstMsgNumber + 1;
PRInt32 percent = (totIndex) ? (PRInt32)(100.0 * (double)numDownloaded / (double)totToDownload) : 0;
PRInt32 percent = (totIndex) ? (PRInt32)(100.0 * (double)numDownloaded / (double)totalToDownload) : 0;
SetProgressBarPercent(percent);
/* only update every NEWS_ART_DISPLAY_FREQ articles for speed */
if ( (totIndex <= NEWS_ART_DISPLAY_FREQ) || ((lastIndex % NEWS_ART_DISPLAY_FREQ) == 0) || (lastIndex == totIndex))
{
#ifdef HAVE_XPGETSTRING
char *statusTemplate = XP_GetString (MK_HDR_DOWNLOAD_COUNT);
char *statusString = PR_smprintf (statusTemplate, numDownloaded, totToDownload);
#else
char *statusString = PR_smprintf ("Downloading %d of %d headers", numDownloaded, totToDownload);
#endif
nsAutoString numDownloadedStr;
numDownloadedStr.AppendInt(numDownloaded);
nsAutoString totalToDownloadStr;
totalToDownloadStr.AppendInt(totalToDownload);
nsXPIDLString statusString;
nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(NEWS_MSGS_URL, nsnull, getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
const PRUnichar *formatStrings[2] = { numDownloadedStr.GetUnicode(), totalToDownloadStr.GetUnicode() };
rv = bundle->FormatStringFromName(NS_LITERAL_STRING("downloadingHeaders"), formatStrings, 2, getter_Copies(statusString));
NS_ENSURE_SUCCESS(rv, rv);
SetProgressStatus(statusString);
PR_FREEIF(statusString);
}
}
@ -921,6 +917,7 @@ nsNNTPNewsgroupList::ProcessNonXOVER (const char * /*line*/)
nsresult
nsNNTPNewsgroupList::FinishXOVERLINE(int status, int *newstatus)
{
nsresult rv;
struct MSG_NewsKnown* k;
/* If any XOVER lines from the last time failed to come in, mark those
@ -960,46 +957,34 @@ nsNNTPNewsgroupList::FinishXOVERLINE(int status, int *newstatus)
}
}
if (m_finishingXover)
if (!m_finishingXover)
{
// turn on m_finishingXover - this is a horrible hack to avoid recursive
// calls which happen when the fe selects a message as a result of getting EndingUpdate,
// which interrupts this url right before it was going to finish and causes FinishXOver
// to get called again.
m_finishingXover = PR_TRUE;
// if we haven't started an update, start one so the fe
// will know to update the size of the view.
if (!m_startedUpdate)
{
#ifdef HAVE_PANES
m_pane->StartingUpdate(MSG_NotifyNone, 0, 0);
#endif
m_startedUpdate = PR_TRUE;
}
#ifdef HAVE_PANES
m_pane->EndingUpdate(MSG_NotifyNone, 0, 0);
#endif
m_startedUpdate = PR_FALSE;
if (m_lastMsgNumber > 0)
{
#ifdef HAVE_PANES
MWContext *context = m_pane->GetContext();
MSG_Pane* parentpane = m_pane->GetParentPane();
// send progress to parent pane, if any, because progress pane is going down.
if (parentpane)
context = parentpane->GetContext();
if (m_lastMsgNumber > 0) {
nsAutoString firstStr;
firstStr.AppendInt(m_lastProcessedNumber - m_firstMsgNumber + 1);
nsAutoString lastStr;
lastStr.AppendInt(m_lastMsgNumber - m_firstMsgNumber + 1);
nsXPIDLString statusString;
nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(NEWS_MSGS_URL, nsnull, getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
const PRUnichar *formatStrings[2] = { firstStr.GetUnicode(), lastStr.GetUnicode() };
rv = bundle->FormatStringFromName(NS_LITERAL_STRING("downloadingArticles"), formatStrings, 2, getter_Copies(statusString));
NS_ENSURE_SUCCESS(rv, rv);
char *statusTemplate = XP_GetString (MK_HDR_DOWNLOAD_COUNT);
char *statusString = PR_smprintf (statusTemplate, m_lastProcessedNumber - m_firstMsgNumber + 1, m_lastMsgNumber - m_firstMsgNumber + 1);
#else
char *statusString = PR_smprintf ("Downloading articles %d-%d", m_lastProcessedNumber - m_firstMsgNumber + 1, m_lastMsgNumber - m_firstMsgNumber + 1);
#endif
if (statusString)
{
SetProgressStatus(statusString);
PR_FREEIF(statusString);
}
}
#ifdef HAVE_PANES
nsINNTPNewsgroup *newsFolder =
@ -1046,11 +1031,8 @@ nsNNTPNewsgroupList::GetGroupName(char **_retval)
}
void
nsNNTPNewsgroupList::SetProgressBarPercent(int percent)
nsNNTPNewsgroupList::SetProgressBarPercent(PRInt32 percent)
{
#ifdef DEBUG_NEWS
printf("nsNNTPNewsgroupList::SetProgressBarPercent(%d)\n",percent);
#endif
if (!m_runningURL) return;
nsCOMPtr <nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(m_runningURL);
@ -1065,14 +1047,8 @@ nsNNTPNewsgroupList::SetProgressBarPercent(int percent)
}
void
nsNNTPNewsgroupList::SetProgressStatus(char *message)
nsNNTPNewsgroupList::SetProgressStatus(const PRUnichar *message)
{
#ifdef DEBUG_NEWS
printf("nsNNTPNewsgroupList::SetProgressStatus(%s)\n",message);
#endif
PRUnichar *progressMsg = nsnull;
// PRUnichar *progressMsg = NNTPGetStringByID(aMsgId);
if (!m_runningURL) return;
nsCOMPtr <nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(m_runningURL);
@ -1080,17 +1056,10 @@ nsNNTPNewsgroupList::SetProgressStatus(char *message)
nsCOMPtr <nsIMsgStatusFeedback> feedback;
mailnewsUrl->GetStatusFeedback(getter_AddRefs(feedback));
char *printfString = PR_smprintf("%s", message);
if (printfString) {
nsString formattedString; formattedString.AssignWithConversion(printfString);
progressMsg = nsCRT::strdup(formattedString.GetUnicode());
PR_FREEIF(printfString);
}
if (feedback) {
feedback->ShowStatusString(progressMsg);
feedback->ShowStatusString(message);
}
}
PR_FREEIF(progressMsg);
}
NS_IMETHODIMP nsNNTPNewsgroupList::SetGetOldMessages(PRBool aGetOldMessages)

Просмотреть файл

@ -86,12 +86,11 @@ private:
nsresult ParseLine(char *line, PRUint32 *message_number);
PRBool msg_StripRE(const char **stringP, PRUint32 *lengthP);
nsresult GetDatabase(const char *uri, nsIMsgDatabase **db);
void SetProgressBarPercent(int percent);
void SetProgressStatus(char *message);
void SetProgressBarPercent(PRInt32 percent);
void SetProgressStatus(const PRUnichar *message);
protected:
nsIMsgDatabase *m_newsDB;
PRBool m_startedUpdate;
PRBool m_getOldMessages;
PRBool m_promptedAlready;
PRBool m_downloadAll;

Просмотреть файл

@ -104,7 +104,6 @@
// skip to the first nntp command.
//#define HAVE_PUSH_AUTH_AND_EXTENSIONS
#define NEWS_MSGS_URL "chrome://messenger/locale/news.properties"
// ***jt -- the following were pirated from xpcom/io/nsByteBufferInputStream
// which is not currently in the build system
class nsDummyBufferStream : public nsIInputStream
@ -159,8 +158,6 @@ static NS_DEFINE_CID(kCMsgMailSessionCID, NS_MSGMAILSESSION_CID);
static NS_DEFINE_CID(kCNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
static NS_DEFINE_CID(kCMsgAccountManagerCID, NS_MSGACCOUNTMANAGER_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kPrefServiceCID,NS_PREF_CID);
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
typedef struct _cancelInfoEntry {
char *from;
@ -872,7 +869,7 @@ nsresult nsNNTPProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer)
*/
m_currentGroup = group;
if (PL_strchr ((const char *)m_currentGroup, '*')) {
if (m_currentGroup.FindChar(PRUnichar('*')) != kNotFound) {
m_typeWanted = LIST_WANTED;
}
else {
@ -892,11 +889,11 @@ nsresult nsNNTPProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer)
PRBool containsGroup = PR_TRUE;
NS_ASSERTION(m_nntpServer,"no nntp server");
if (m_nntpServer) {
rv = m_nntpServer->ContainsNewsgroup((const char *)m_currentGroup,&containsGroup);
rv = m_nntpServer->ContainsNewsgroup(m_currentGroup,&containsGroup);
if (NS_FAILED(rv)) return rv;
if (!containsGroup) {
rv = m_nntpServer->SubscribeToNewsgroup((const char *)m_currentGroup);
rv = m_nntpServer->SubscribeToNewsgroup(m_currentGroup);
if (NS_FAILED(rv)) return rv;
}
}
@ -2202,7 +2199,7 @@ PRInt32 nsNNTPProtocol::BeginArticle()
msgurl->GetAddDummyEnvelope(&needDummyHeaders);
if (needDummyHeaders)
{
nsCString result;
nsCAutoString result;
char *ct;
PRUint32 writeCount;
time_t now = time ((time_t*) 0);
@ -2410,37 +2407,37 @@ PRInt32 nsNNTPProtocol::ReadArticle(nsIInputStream * inputStream, PRUint32 lengt
void nsNNTPProtocol::ParseHeaderForCancel(char *buf)
{
nsCString header(buf);
nsCAutoString header(buf);
PRInt32 colon = header.FindChar(':');
if (!colon)
return;
nsCString value("");
nsCAutoString value;
header.Right(value, header.Length() - colon -1);
value.StripWhitespace();
switch (header.First()) {
case 'F': case 'f':
if (header.Find("From") == 0) {
if (m_cancelFromHdr) PR_FREEIF(m_cancelFromHdr);
PR_FREEIF(m_cancelFromHdr);
m_cancelFromHdr = PL_strdup(value.GetBuffer());
}
break;
case 'M': case 'm':
if (header.Find("Message-ID") == 0) {
if (m_cancelID) PR_FREEIF(m_cancelID);
PR_FREEIF(m_cancelID);
m_cancelID = PL_strdup(value.GetBuffer());
}
break;
case 'N': case 'n':
if (header.Find("Newsgroups") == 0) {
if (m_cancelNewsgroups) PR_FREEIF(m_cancelNewsgroups);
PR_FREEIF(m_cancelNewsgroups);
m_cancelNewsgroups = PL_strdup(value.GetBuffer());
}
break;
case 'D': case 'd':
if (header.Find("Distributions") == 0) {
if (m_cancelDistribution) PR_FREEIF(m_cancelDistribution);
PR_FREEIF(m_cancelDistribution);
m_cancelDistribution = PL_strdup(value.GetBuffer());
}
break;
@ -3017,12 +3014,11 @@ PRInt32 nsNNTPProtocol::ReadNewsList(nsIInputStream * inputStream, PRUint32 leng
nsCOMPtr <nsIMsgStatusFeedback> msgStatusFeedback;
rv = m_msgWindow->GetStatusFeedback(getter_AddRefs(msgStatusFeedback));
if (NS_FAILED(rv)) return rv;
// XXXXX
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLString statusString;
nsCOMPtr<nsIStringBundleService> bundleService =
do_GetService(kStringBundleServiceCID, &rv);
nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundle> bundle;
@ -3030,7 +3026,7 @@ PRInt32 nsNNTPProtocol::ReadNewsList(nsIInputStream * inputStream, PRUint32 leng
getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
nsString bytesStr;
nsAutoString bytesStr;
bytesStr.AppendInt(mBytesReceived / 1024);
// compute the rate, and then convert it have one
@ -3040,16 +3036,14 @@ PRInt32 nsNNTPProtocol::ReadNewsList(nsIInputStream * inputStream, PRUint32 leng
char rate_buf[RATE_STR_BUF_LEN];
PR_snprintf(rate_buf,RATE_STR_BUF_LEN,"%.1f", rate);
nsString rateStr;
nsAutoString rateStr;
rateStr.AppendWithConversion(rate_buf);
nsString numGroupsStr;
nsAutoString numGroupsStr;
numGroupsStr.AppendInt(mNumGroupsListed);
const PRUnichar *formatStrings[3] = { numGroupsStr.GetUnicode(), bytesStr.GetUnicode(), rateStr.GetUnicode() };
NS_NAMED_LITERAL_STRING(literalPropertyTag, "bytesReceived");
const PRUnichar *propertyTag = literalPropertyTag.get();
rv = bundle->FormatStringFromName(propertyTag,
rv = bundle->FormatStringFromName(NS_LITERAL_STRING("bytesReceived"),
formatStrings, 3,
getter_Copies(statusString));
@ -3502,72 +3496,67 @@ PRInt32 nsNNTPProtocol::ReadNewsgroupBody(nsIInputStream * inputStream, PRUint32
nsresult nsNNTPProtocol::GetNewsStringByID(PRInt32 stringID, PRUnichar **aString)
{
nsresult res;
nsAutoString resultString; resultString.AssignWithConversion("???");
nsresult rv;
nsAutoString resultString(NS_LITERAL_STRING("???"));
if (!m_stringBundle)
{
char* propertyURL = NEWS_MSGS_URL;
NS_WITH_SERVICE(nsIStringBundleService, sBundleService, kStringBundleServiceCID, &res);
if (NS_SUCCEEDED(res) && (nsnull != sBundleService))
{
nsILocale *locale = nsnull;
nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
res = sBundleService->CreateBundle(propertyURL, locale, getter_AddRefs(m_stringBundle));
}
rv = bundleService->CreateBundle(propertyURL, nsnull, getter_AddRefs(m_stringBundle));
NS_ENSURE_SUCCESS(rv, rv);
}
if (m_stringBundle) {
PRUnichar *ptrv = nsnull;
res = m_stringBundle->GetStringFromID(stringID, &ptrv);
rv = m_stringBundle->GetStringFromID(stringID, &ptrv);
if (NS_FAILED(res))
{
resultString.AssignWithConversion("[StringID");
if (NS_FAILED(rv)) {
resultString.Assign(NS_LITERAL_STRING("[StringID"));
resultString.AppendInt(stringID, 10);
resultString.AppendWithConversion("?]");
resultString.Append(NS_LITERAL_STRING("?]"));
*aString = resultString.ToNewUnicode();
}
else
{
else {
*aString = ptrv;
}
}
else
{
res = NS_OK;
else {
rv = NS_OK;
*aString = resultString.ToNewUnicode();
}
return res;
return rv;
}
nsresult nsNNTPProtocol::GetNewsStringByName(const char *aName, PRUnichar **aString)
{
nsresult res;
nsAutoString resultString; resultString.AssignWithConversion("???");
nsresult rv;
nsAutoString resultString(NS_LITERAL_STRING("???"));
if (!m_stringBundle)
{
char* propertyURL = NEWS_MSGS_URL;
NS_WITH_SERVICE(nsIStringBundleService, sBundleService, kStringBundleServiceCID, &res);
if (NS_SUCCEEDED(res) && (nsnull != sBundleService))
{
nsILocale *locale = nsnull;
nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
res = sBundleService->CreateBundle(propertyURL, locale, getter_AddRefs(m_stringBundle));
}
rv = bundleService->CreateBundle(propertyURL, nsnull, getter_AddRefs(m_stringBundle));
}
if (m_stringBundle)
{
nsAutoString unicodeName; unicodeName.AssignWithConversion(aName);
PRUnichar *ptrv = nsnull;
res = m_stringBundle->GetStringFromName(unicodeName.GetUnicode(), &ptrv);
rv = m_stringBundle->GetStringFromName(unicodeName.GetUnicode(), &ptrv);
if (NS_FAILED(res))
if (NS_FAILED(rv))
{
resultString.AssignWithConversion("[StringName");
resultString.Assign(NS_LITERAL_STRING("[StringName"));
resultString.AppendWithConversion(aName);
resultString.AppendWithConversion("?]");
resultString.Append(NS_LITERAL_STRING("?]"));
*aString = resultString.ToNewUnicode();
}
else
@ -3577,10 +3566,10 @@ nsresult nsNNTPProtocol::GetNewsStringByName(const char *aName, PRUnichar **aStr
}
else
{
res = NS_OK;
rv = NS_OK;
*aString = resultString.ToNewUnicode();
}
return res;
return rv;
}
// sspitzer: PostMessageInFile is derived from nsSmtpProtocol::SendMessageInFile()
@ -3738,19 +3727,47 @@ PRInt32 nsNNTPProtocol::CheckForArticle()
}
}
#define NEWS_GROUP_DISPLAY_FREQ 20
#define NEWS_GROUP_DISPLAY_FREQ 5
nsresult
nsNNTPProtocol::SetCheckingForNewNewsStatus(PRInt32 current, PRInt32 total)
{
nsresult rv;
nsXPIDLString statusString;
nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(NEWS_MSGS_URL, nsnull, getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString thisGroupStr; thisGroupStr.AppendInt(current);
nsAutoString totalGroupStr; totalGroupStr.AppendInt(total);
const PRUnichar *formatStrings[] = { thisGroupStr.GetUnicode(),totalGroupStr.GetUnicode() };
rv = bundle->FormatStringFromName(NS_LITERAL_STRING("checkingForNewNews"),
formatStrings, 2,
getter_Copies(statusString));
NS_ENSURE_SUCCESS(rv, rv);
rv = SetProgressStatus(statusString);
NS_ENSURE_SUCCESS(rv, rv);
SetProgressBarPercent(current, total);
return NS_OK;
}
PRInt32 nsNNTPProtocol::DisplayNewsRC()
{
nsresult rv;
PRInt32 status = 0;
nsresult rv;
if(!TestFlag(NNTP_NEWSRC_PERFORMED))
{
if(!TestFlag(NNTP_NEWSRC_PERFORMED)) {
SetFlag(NNTP_NEWSRC_PERFORMED);
rv = m_nntpServer->GetNumGroupsNeedingCounts(&m_newsRCListCount);
if (NS_FAILED(rv))
return -1;
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr <nsISupports> currChild;
@ -3759,87 +3776,23 @@ PRInt32 nsNNTPProtocol::DisplayNewsRC()
ClearFlag(NNTP_NEWSRC_PERFORMED);
return -1;
}
else if (!currChild)
{
else if (!currChild) {
ClearFlag(NNTP_NEWSRC_PERFORMED);
m_nextState = NEWS_DONE;
return 0;
}
nsCOMPtr<nsIFolder> currFolder;
currFolder = do_QueryInterface(currChild, &rv);
if (NS_FAILED(rv)) return -1;
if (!currFolder) return -1;
m_newsFolder = do_QueryInterface(currFolder, &rv);
if (NS_FAILED(rv)) return -1;
if (!m_newsFolder) return -1;
nsXPIDLCString name;
rv = m_newsFolder->GetAsciiName(getter_Copies(name));
if (NS_FAILED(rv)) return -1;
if (!name) return -1;
m_currentGroup = (const char *)name;
if(NS_SUCCEEDED(rv) && ((const char *)m_currentGroup))
{
/* send group command to server
*/
char outputBuffer[OUTPUT_BUFFER_SIZE];
PR_snprintf(outputBuffer, OUTPUT_BUFFER_SIZE, "GROUP %.512s" CRLF, (const char *)m_currentGroup);
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_runningURL);
if (mailnewsurl)
status = SendData(mailnewsurl, outputBuffer);
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 ||
(m_newsRCListIndex == m_newsRCListCount)))
{
nsXPIDLString statusString;
nsCOMPtr<nsIStringBundleService> bundleService =
do_GetService(kStringBundleServiceCID, &rv);
if (m_newsRCListCount) {
rv = SetCheckingForNewNewsStatus(m_newsRCListCount, m_newsRCListCount);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(NEWS_MSGS_URL, nsnull,
getter_AddRefs(bundle));
// clear the status text.
// rv = SetProgressStatus(NS_LITERAL_STRING(""));
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString thisGroupStr; thisGroupStr.AppendInt((long) m_newsRCListIndex);
nsAutoString totalGroupStr; totalGroupStr.AppendInt((long) m_newsRCListCount);
const PRUnichar *formatStrings[] = { thisGroupStr.GetUnicode(),totalGroupStr.GetUnicode() };
NS_NAMED_LITERAL_STRING(literalPropertyTag, "checkingForNewNews");
const PRUnichar *propertyTag = literalPropertyTag.get();
rv = bundle->FormatStringFromName(propertyTag,
formatStrings, 2,
getter_Copies(statusString));
NS_ENSURE_SUCCESS(rv, rv);
rv = SetProgressStatus((const PRUnichar *)statusString);
NS_ENSURE_SUCCESS(rv, rv);
}
m_newsRCListIndex++;
SetFlag(NNTP_PAUSE_FOR_READ);
m_nextState = NNTP_RESPONSE;
m_nextStateAfterResponse = NEWS_DISPLAY_NEWS_RC_RESPONSE;
}
else
{
if (m_newsRCListCount)
{
SetProgressBarPercent(0, -1);
m_newsRCListCount = 0;
status = 0;
}
else if (m_responseCode == MK_NNTP_RESPONSE_LIST_OK)
{
else if (m_responseCode == MK_NNTP_RESPONSE_LIST_OK) {
/*
* 5-9-96 jefft
* If for some reason the news server returns an empty
@ -3849,7 +3802,6 @@ PRInt32 nsNNTPProtocol::DisplayNewsRC()
*/
status = MK_EMPTY_NEWS_LIST;
}
m_nextState = NEWS_DONE;
if(status > -1)
return MK_DATA_LOADED;
@ -3857,8 +3809,44 @@ PRInt32 nsNNTPProtocol::DisplayNewsRC()
return(status);
}
return(status); /* keep going */
nsCOMPtr<nsIFolder> currFolder;
currFolder = do_QueryInterface(currChild, &rv);
NS_ENSURE_SUCCESS(rv, rv);
if (!currFolder) return NS_ERROR_FAILURE;
m_newsFolder = do_QueryInterface(currFolder, &rv);
NS_ENSURE_SUCCESS(rv, rv);
if (!m_newsFolder) return NS_ERROR_FAILURE;
nsXPIDLCString name;
rv = m_newsFolder->GetAsciiName(getter_Copies(name));
NS_ENSURE_SUCCESS(rv, rv);
if (!name) return NS_ERROR_FAILURE;
m_currentGroup = (const char *)name;
/* send group command to server */
char outputBuffer[OUTPUT_BUFFER_SIZE];
PR_snprintf(outputBuffer, OUTPUT_BUFFER_SIZE, "GROUP %.512s" CRLF, (const char *)m_currentGroup);
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_runningURL);
if (mailnewsurl) {
status = SendData(mailnewsurl, outputBuffer);
}
/* only update every NEWS_GROUP_DISPLAY_FREQ groups for speed */
if ((m_newsRCListCount >= NEWS_GROUP_DISPLAY_FREQ) && ((m_newsRCListIndex % NEWS_GROUP_DISPLAY_FREQ) == 0 || (m_newsRCListIndex == m_newsRCListCount))) {
rv = SetCheckingForNewNewsStatus(m_newsRCListIndex, m_newsRCListCount);
NS_ENSURE_SUCCESS(rv, rv);
}
m_newsRCListIndex++;
SetFlag(NNTP_PAUSE_FOR_READ);
m_nextState = NNTP_RESPONSE;
m_nextStateAfterResponse = NEWS_DISPLAY_NEWS_RC_RESPONSE;
return status; /* keep going */
}
/* Parses output of GROUP command */
@ -3911,7 +3899,7 @@ PRInt32 nsNNTPProtocol::DisplayNewsRCResponse()
}
else if (m_responseCode == MK_NNTP_RESPONSE_GROUP_NO_GROUP)
{
m_newsHost->GroupNotFound((const char *)m_currentGroup, PR_FALSE);
m_newsHost->GroupNotFound(m_currentGroup, PR_FALSE);
}
/* it turns out subscribe ui depends on getting this displaysubscribedgroup call,
even if there was an error.
@ -4009,7 +3997,7 @@ PRBool nsNNTPProtocol::CheckIfAuthor(nsISupports *aElement, void *data)
PRInt32 nsNNTPProtocol::DoCancel()
{
int status = 0;
PRInt32 status = 0;
PRBool failure = PR_FALSE;
nsresult rv = NS_OK;
char *id = nsnull;
@ -4049,8 +4037,8 @@ PRInt32 nsNNTPProtocol::DoCancel()
cancelInfo.old_from = m_cancelFromHdr;
cancelInfo.from = nsnull;
nsCOMPtr <nsIPref> prefs = do_GetService(kPrefServiceCID, &rv);
if (NS_FAILED(rv) || !prefs) return -1; /* unable to get the pref service */
nsCOMPtr <nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIPrompt> dialog;
if (m_runningURL)
@ -4192,7 +4180,7 @@ PRInt32 nsNNTPProtocol::DoCancel()
if (status < 0) {
nsCAutoString errorText;
errorText.AppendInt(status);
AlertError(MK_TCP_WRITE_ERROR,(const char *)errorText);
AlertError(MK_TCP_WRITE_ERROR, errorText);
failure = PR_TRUE;
goto FAIL;
}
@ -5302,16 +5290,11 @@ NS_IMETHODIMP nsNNTPProtocol::GetContentType(char * *aContentType)
// otherwise do what we did before...
if ((const char *)m_currentGroup && nsCRT::strlen((const char *)m_currentGroup)) {
if (m_typeWanted != ARTICLE_WANTED && !m_currentGroup.IsEmpty() &&
// if it is an article url, it has a @ or %40 in it.
if (PL_strchr((const char *)m_currentGroup,'@') || PL_strstr((const char *)m_currentGroup,"%40")
|| m_typeWanted == ARTICLE_WANTED) {
*aContentType = nsCRT::strdup("message/rfc822");
}
else {
m_currentGroup.Find("@") == kNotFound && m_currentGroup.Find("%40") == kNotFound) {
*aContentType = nsCRT::strdup("x-application-newsgroup");
}
}
else {
*aContentType = nsCRT::strdup("message/rfc822");
}
@ -5325,25 +5308,28 @@ nsNNTPProtocol::AlertError(PRInt32 errorCode, const char *text)
nsresult rv = NS_OK;
// get the prompt from the running url....
if (m_runningURL)
{
if (m_runningURL) {
nsCOMPtr<nsIMsgMailNewsUrl> msgUrl (do_QueryInterface(m_runningURL));
nsCOMPtr<nsIPrompt> dialog;
rv = GetPromptDialogFromUrl(msgUrl, getter_AddRefs(dialog));
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLString newsString;
rv = GetNewsStringByID(errorCode, getter_Copies(newsString));
if (NS_FAILED(rv)) return rv;
nsAutoString alertText;
alertText.AssignWithConversion("NEWS ERROR: ");
alertText.Append((const PRUnichar *)newsString);
nsXPIDLString str;
rv = GetNewsStringByName("newsError", getter_Copies(str));
NS_ENSURE_SUCCESS(rv,rv);
alertText.Append(str);
if (text)
rv = GetNewsStringByID(errorCode, getter_Copies(str));
NS_ENSURE_SUCCESS(rv, rv);
alertText.Append(str);
if (text) {
alertText.AppendWithConversion(text);
}
rv = dialog->Alert(nsnull, alertText.GetUnicode());
NS_ENSURE_SUCCESS(rv, rv);
}
return rv;

Просмотреть файл

@ -396,6 +396,7 @@ private:
void SetProgressBarPercent(PRUint32 aProgress, PRUint32 aProgressMax);
nsresult SetProgressStatus(const PRUnichar *aMessage);
nsresult SetCheckingForNewNewsStatus(PRInt32 current, PRInt32 total);
nsresult SetNewsFolder(); /* sets m_newsFolder, if not already set */
nsresult CreateNewsFolderURI (const char *username, const char *hostname, const char *newsgroupname, char **uri);
nsresult InitializeNewsFolderFromUri(const char *uri);