зеркало из https://github.com/mozilla/pjs.git
Add delete message
This commit is contained in:
Родитель
7717960dc4
Коммит
42d33601da
|
@ -31,6 +31,7 @@
|
|||
#include "nsIScriptNameSpaceManager.h"
|
||||
#include "nsRepository.h"
|
||||
#include "nsDOMCID.h"
|
||||
#include "nsIDOMXULTreeElement.h"
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
|
@ -314,6 +362,7 @@ static JSFunctionSpec MsgAppCoreMethods[] =
|
|||
{"Open3PaneWindow", MsgAppCoreOpen3PaneWindow, 0},
|
||||
{"SetWindow", MsgAppCoreSetWindow, 1},
|
||||
{"OpenURL", MsgAppCoreOpenURL, 1},
|
||||
{"DeleteMessage", MsgAppCoreDeleteMessage, 2},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
|
@ -42,9 +42,17 @@
|
|||
|
||||
#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_CID(kCMailboxServiceCID, NS_MAILBOXSERVICE_CID);
|
||||
static NS_DEFINE_CID(kCMsgMailSessionCID, NS_MSGMAILSESSION_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
||||
|
||||
NS_BEGIN_EXTERN_C
|
||||
|
||||
|
@ -77,6 +85,7 @@ public:
|
|||
NS_IMETHOD GetNewMail();
|
||||
NS_IMETHOD SetWindow(nsIDOMWindow* aWin);
|
||||
NS_IMETHOD OpenURL(const char * url);
|
||||
NS_IMETHOD DeleteMessage(nsIDOMXULTreeElement *tree, nsIDOMNodeList *nodeList);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -92,6 +101,46 @@ private:
|
|||
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 res = NS_OK;
|
||||
|
@ -400,6 +449,40 @@ nsMsgAppCore::OpenURL(const char * url)
|
|||
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!
|
||||
// mWebShell->LoadURL(nsAutoString("http://www.netscape.com"),
|
||||
// nsnull, PR_TRUE, nsURLReload, 0);
|
||||
|
|
Загрузка…
Ссылка в новой задаче