more changes for simple subscribe. now, it writes out the new newsgroup to the newsrc file, so it will be there when you quit and come back.

This commit is contained in:
sspitzer%netscape.com 1999-09-17 11:43:24 +00:00
Родитель 59d4fd33cb
Коммит 8daa218d4e
2 изменённых файлов: 38 добавлений и 13 удалений

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

@ -48,6 +48,7 @@
#include "nsINntpIncomingServer.h"
#include "nsINewsDatabase.h"
#include "nsMsgBaseCID.h"
#include "nsFileStream.h"
#ifdef DEBUG_seth
#define DEBUG_NEWS 1
@ -153,11 +154,10 @@ nsMsgNewsFolder::CreateSubFolders(nsFileSpec &path)
getter_AddRefs(nntpServer));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIFileSpec> newsrcFilePath;
rv = nntpServer->GetNewsrcFilePath(getter_AddRefs(newsrcFilePath));
rv = nntpServer->GetNewsrcFilePath(getter_AddRefs(mNewsrcFilePath));
if (NS_FAILED(rv)) return rv;
rv = LoadNewsrcFileAndCreateNewsgroups(newsrcFilePath);
rv = LoadNewsrcFileAndCreateNewsgroups();
}
else {
#ifdef DEBUG_NEWS
@ -453,9 +453,8 @@ NS_IMETHODIMP nsMsgNewsFolder::CreateSubfolder(const char *newsgroupname)
// do we need to hash newsgroup name if it is too big?
path += newsgroupname;
#ifdef DEBUG_NEWS
printf("echo %s: to the newsrc file\n", newsgroupname);
#endif
rv = AddNewsgroupToNewsrcFile(newsgroupname);
if (NS_FAILED(rv)) return rv;
rv = nsComponentManager::CreateInstance(kCNewsDB, nsnull, nsIMsgDatabase::GetIID(), getter_AddRefs(newsDBFactory));
if (NS_SUCCEEDED(rv) && newsDBFactory) {
@ -990,9 +989,32 @@ NS_IMETHODIMP nsMsgNewsFolder::CreateMessageFromMsgDBHdr(nsIMsgDBHdr *msgDBHdr,
}
nsresult
nsMsgNewsFolder::LoadNewsrcFileAndCreateNewsgroups(nsIFileSpec * newsrcFile)
nsMsgNewsFolder::AddNewsgroupToNewsrcFile(const char *newsgroupname)
{
nsInputFileStream newsrcStream(newsrcFile);
nsresult rv;
if (!mNewsrcFilePath) return NS_ERROR_FAILURE;
nsFileSpec newsrcFile;
rv = mNewsrcFilePath->GetFileSpec(&newsrcFile);
if (NS_FAILED(rv)) return rv;
nsOutputFileStream newsrcStream(newsrcFile, (PR_WRONLY | PR_CREATE_FILE | PR_APPEND));
if (!newsrcStream.is_open()) {
return NS_ERROR_FAILURE;
}
newsrcStream << newsgroupname;
newsrcStream << ":";
newsrcStream << nsEndl;
newsrcStream.close();
return NS_OK;
}
nsresult
nsMsgNewsFolder::LoadNewsrcFileAndCreateNewsgroups()
{
if (!mNewsrcFilePath) return NS_ERROR_FAILURE;
nsInputFileStream newsrcStream(mNewsrcFilePath);
nsresult rv = NS_OK;
PRInt32 numread = 0;

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

@ -32,6 +32,7 @@
#include "nsNewsUtils.h"
#include "nsMsgLineBuffer.h"
#include "nsMsgKeySet.h"
#include "nsCOMPtr.h"
class nsMsgNewsFolder : public nsMsgDBFolder, public nsIMsgNewsFolder, public nsMsgLineBuffer
{
@ -94,6 +95,7 @@ public:
NS_IMETHOD GetPath(nsIFileSpec** aPathName);
protected:
nsresult AddNewsgroupToNewsrcFile(const char *newsgroupname);
nsresult AbbreviatePrettyName(PRUnichar ** prettyName, PRInt32 fullwords);
nsresult ParseFolder(nsFileSpec& path);
nsresult CreateSubFolders(nsFileSpec &path);
@ -104,7 +106,7 @@ protected:
//Returns the child as well.
nsresult AddSubfolder(nsAutoString name, nsIMsgFolder **child, char *setStr);
nsresult LoadNewsrcFileAndCreateNewsgroups(nsIFileSpec * newsrcFile);
nsresult LoadNewsrcFileAndCreateNewsgroups();
PRInt32 RememberLine(char *line);
nsresult ForgetLine(void);
@ -121,6 +123,7 @@ protected:
nsISupportsArray *mMessages;
char *mOptionLines;
char *mHostname;
nsCOMPtr<nsIFileSpec> mNewsrcFilePath;
};
#endif // nsMsgNewsFolder_h__