This commit is contained in:
putterman%netscape.com 1999-03-11 19:50:54 +00:00
Родитель 7717960dc4
Коммит 42d33601da
2 изменённых файлов: 132 добавлений и 0 удалений

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

@ -31,6 +31,7 @@
#include "nsIScriptNameSpaceManager.h" #include "nsIScriptNameSpaceManager.h"
#include "nsRepository.h" #include "nsRepository.h"
#include "nsDOMCID.h" #include "nsDOMCID.h"
#include "nsIDOMXULTreeElement.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
@ -277,7 +278,54 @@ MsgAppCoreOpenURL(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *
return JS_TRUE; return JS_TRUE;
} }
//
// Native method DeleteMessage
//
PR_STATIC_CALLBACK(JSBool)
MsgAppCoreDeleteMessage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMMsgAppCore *nativeThis = (nsIDOMMsgAppCore*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNodeList *nodeList;
nsIDOMXULTreeElement *tree;
const nsString typeName;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
rBool = nsJSUtils::nsConvertJSValToObject((nsISupports**)&tree,
nsIDOMXULTreeElement::GetIID(),
typeName,
cx,
argv[0]);
rBool = rBool && nsJSUtils::nsConvertJSValToObject((nsISupports**)&nodeList,
nsIDOMNodeList::GetIID(),
typeName,
cx,
argv[1]);
if (!rBool || NS_OK != nativeThis->DeleteMessage(tree, nodeList)) {
return JS_FALSE;
}
NS_RELEASE(nodeList);
NS_RELEASE(tree);
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function DeleteMessage requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/ /***********************************************************************/
// //
// class for MsgAppCore // class for MsgAppCore
@ -314,6 +362,7 @@ static JSFunctionSpec MsgAppCoreMethods[] =
{"Open3PaneWindow", MsgAppCoreOpen3PaneWindow, 0}, {"Open3PaneWindow", MsgAppCoreOpen3PaneWindow, 0},
{"SetWindow", MsgAppCoreSetWindow, 1}, {"SetWindow", MsgAppCoreSetWindow, 1},
{"OpenURL", MsgAppCoreOpenURL, 1}, {"OpenURL", MsgAppCoreOpenURL, 1},
{"DeleteMessage", MsgAppCoreDeleteMessage, 2},
{0} {0}
}; };

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

@ -42,9 +42,17 @@
#include "nsNNTPProtocol.h" // mscott - hopefully this dependency should only be temporary... #include "nsNNTPProtocol.h" // mscott - hopefully this dependency should only be temporary...
#include "nsIDOMXULTreeElement.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFResource.h"
#include "nsIRDFService.h"
#include "nsRDFCID.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_CID(kCMailboxServiceCID, NS_MAILBOXSERVICE_CID); static NS_DEFINE_CID(kCMailboxServiceCID, NS_MAILBOXSERVICE_CID);
static NS_DEFINE_CID(kCMsgMailSessionCID, NS_MSGMAILSESSION_CID); static NS_DEFINE_CID(kCMsgMailSessionCID, NS_MSGMAILSESSION_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
NS_BEGIN_EXTERN_C NS_BEGIN_EXTERN_C
@ -77,6 +85,7 @@ public:
NS_IMETHOD GetNewMail(); NS_IMETHOD GetNewMail();
NS_IMETHOD SetWindow(nsIDOMWindow* aWin); NS_IMETHOD SetWindow(nsIDOMWindow* aWin);
NS_IMETHOD OpenURL(const char * url); NS_IMETHOD OpenURL(const char * url);
NS_IMETHOD DeleteMessage(nsIDOMXULTreeElement *tree, nsIDOMNodeList *nodeList);
private: private:
@ -92,6 +101,46 @@ private:
void InitializeFolderRoot(); void InitializeFolderRoot();
}; };
static nsresult ConvertDOMListToResourceArray(nsIDOMNodeList *nodeList, nsISupportsArray **resourceArray)
{
nsresult rv = NS_OK;
PRUint32 listLength;
nsIDOMNode *node;
nsIDOMXULTreeElement *xulElement;
nsIRDFResource *resource;
if(!resourceArray)
return NS_ERROR_NULL_POINTER;
if(NS_FAILED(rv = nodeList->GetLength(&listLength)))
return rv;
if(NS_FAILED(NS_NewISupportsArray(resourceArray)))
{
return NS_ERROR_OUT_OF_MEMORY;
}
for(PRUint32 i = 0; i < listLength; i++)
{
if(NS_FAILED(nodeList->Item(i, &node)))
return rv;
if(NS_SUCCEEDED(rv = node->QueryInterface(nsIDOMXULElement::GetIID(), (void**)&xulElement)))
{
if(NS_SUCCEEDED(rv = xulElement->GetResource(&resource)))
{
(*resourceArray)->AppendElement(resource);
NS_RELEASE(resource);
}
NS_RELEASE(xulElement);
}
NS_RELEASE(node);
}
return rv;
}
nsresult nsMsgAppCore::SetDocumentCharset(class nsString const & aCharset) nsresult nsMsgAppCore::SetDocumentCharset(class nsString const & aCharset)
{ {
nsresult res = NS_OK; nsresult res = NS_OK;
@ -400,6 +449,40 @@ nsMsgAppCore::OpenURL(const char * url)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsMsgAppCore::DeleteMessage(nsIDOMXULTreeElement *tree, nsIDOMNodeList *nodeList)
{
nsresult rv;
nsIRDFCompositeDataSource *database;
nsISupportsArray *resourceArray;
if(NS_FAILED(rv = tree->GetDatabase(&database)))
return rv;
if(NS_FAILED(rv =ConvertDOMListToResourceArray(nodeList, &resourceArray)))
return rv;
nsIRDFService* gRDFService = nsnull;
nsIRDFResource* deleteResource;
rv = nsServiceManager::GetService(kRDFServiceCID,
nsIRDFService::GetIID(),
(nsISupports**) &gRDFService);
if(NS_SUCCEEDED(rv))
{
if(NS_SUCCEEDED(rv = gRDFService->GetResource("http://home.netscape.com/NC-rdf#Delete", &deleteResource)))
{
rv = database->DoCommand(resourceArray, deleteResource, nsnull);
NS_RELEASE(deleteResource);
}
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
}
NS_RELEASE(database);
NS_RELEASE(resourceArray);
return rv;
}
// to load the webshell! // to load the webshell!
// mWebShell->LoadURL(nsAutoString("http://www.netscape.com"), // mWebShell->LoadURL(nsAutoString("http://www.netscape.com"),
// nsnull, PR_TRUE, nsURLReload, 0); // nsnull, PR_TRUE, nsURLReload, 0);