diff --git a/mozilla/mailnews/base/public/nsIMsgProgress.idl b/mozilla/mailnews/base/public/nsIMsgProgress.idl new file mode 100644 index 00000000000..856a13432e3 --- /dev/null +++ b/mozilla/mailnews/base/public/nsIMsgProgress.idl @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Jean-Francois Ducarroz +*/ +#include "nsISupports.idl" +#include "domstubs.idl" +#include "nsIPrompt.idl" +#include "nsIWebProgressListener.idl" + +interface nsIDOMWindowInternal; + +[scriptable, uuid(9f4dd200-3b1f-11d5-9daa-c345c9453d3c)] +interface nsIMsgProgress: nsIWebProgressListener { + + /* Open the progress dialog + you can specify parameters through an xpcom object + */ + void openProgressDialog(in nsIDOMWindowInternal parent, in string dialogURL, in nsISupports parameters); + + /* Close the progress dialog */ + void closeProgressDialog(in boolean forceClose); + + /* Register a Web Progress Listener */ + void registerListener(in nsIWebProgressListener listener); + + /* Unregister a Web Progress Listener */ + void unregisterListener(in nsIWebProgressListener listener); + + /* Retrive the prompter, needed to display modal dialog on top of progress dialog */ + nsIPrompt getPrompter(); + + /* Indicated if the user asked to cancel the current process */ + attribute boolean processCanceledByUser; +}; + + diff --git a/mozilla/mailnews/base/src/nsMsgProgress.cpp b/mozilla/mailnews/base/src/nsMsgProgress.cpp new file mode 100644 index 00000000000..1b5f1aa886f --- /dev/null +++ b/mozilla/mailnews/base/src/nsMsgProgress.cpp @@ -0,0 +1,287 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Jean-Francois Ducarroz + */ + +#include "nsMsgProgress.h" + +#include "nsIScriptGlobalObject.h" +#include "nsIBaseWindow.h" + +NS_IMPL_ISUPPORTS1(nsMsgProgress, nsIMsgProgress) + +nsMsgProgress::nsMsgProgress() +{ + NS_INIT_ISUPPORTS(); + m_closeProgress = PR_FALSE; + m_processCanceled = PR_FALSE; + m_pendingStateFlags = -1; + m_pendingStateValue = 0; +} + +nsMsgProgress::~nsMsgProgress() +{ + (void)ReleaseListeners(); +} + +/* void openProgressDialog (in nsIDOMWindowInternal parent, in string dialogURL, in nsISupports parameters); */ +NS_IMETHODIMP nsMsgProgress::OpenProgressDialog(nsIDOMWindowInternal *parent, const char *dialogURL, nsISupports *parameters) +{ + nsresult rv = NS_ERROR_FAILURE; + + if (m_dialog) + return NS_ERROR_ALREADY_INITIALIZED; + + if (!dialogURL || !*dialogURL) + return NS_ERROR_INVALID_ARG; + + if (parent) + { + // Get JS context from parent window. + nsCOMPtr sgo = do_QueryInterface(parent, &rv); + if (NS_SUCCEEDED(rv) && sgo) + { + nsCOMPtr context; + sgo->GetContext(getter_AddRefs(context)); + if (context) + { + // Get native context. + JSContext *jsContext = (JSContext*)context->GetNativeContext(); + if (jsContext) + { + // Set up window.arguments[0]... + void *stackPtr; + jsval *argv = JS_PushArguments( jsContext, + &stackPtr, + "sss%ip%ip", + dialogURL, + "_blank", + "chrome,titlebar,dependent", + (const nsIID*)(&NS_GET_IID(nsIMsgProgress)), + (nsISupports*)this, + (const nsIID*)(&NS_GET_IID(nsISupports)), + (nsISupports*)parameters + ); + if (argv) + { + // Open the dialog. + rv = parent->OpenDialog(jsContext, argv, 5, getter_AddRefs(m_dialog)); + // Pop arguments. + JS_PopArguments(jsContext, stackPtr); + } + } + } + } + } + return rv; +} + +/* void closeProgressDialog (in boolean forceClose); */ +NS_IMETHODIMP nsMsgProgress::CloseProgressDialog(PRBool forceClose) +{ + m_closeProgress = PR_TRUE; + return OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, forceClose); +} + +/* nsIPrompt GetPrompter (); */ +NS_IMETHODIMP nsMsgProgress::GetPrompter(nsIPrompt **_retval) +{ + NS_ENSURE_ARG_POINTER(_retval); + *_retval = nsnull; + + if (! m_closeProgress && m_dialog) + return m_dialog->GetPrompter(_retval); + + return NS_ERROR_FAILURE; +} + +/* attribute boolean processCanceledByUser; */ +NS_IMETHODIMP nsMsgProgress::GetProcessCanceledByUser(PRBool *aProcessCanceledByUser) +{ + NS_ENSURE_ARG_POINTER(aProcessCanceledByUser); + *aProcessCanceledByUser = m_processCanceled; + return NS_OK; +} +NS_IMETHODIMP nsMsgProgress::SetProcessCanceledByUser(PRBool aProcessCanceledByUser) +{ + m_processCanceled = aProcessCanceledByUser; + OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, PR_FALSE); + return NS_OK; +} + +/* void RegisterListener (in nsIWebProgressListener listener); */ +NS_IMETHODIMP nsMsgProgress::RegisterListener(nsIWebProgressListener * listener) +{ + nsresult rv = NS_OK; + + if (!listener) //Nothing to do with a null listener! + return NS_OK; + + if (!m_listenerList) + rv = NS_NewISupportsArray(getter_AddRefs(m_listenerList)); + + if (NS_SUCCEEDED(rv) && m_listenerList) + { + m_listenerList->AppendElement(listener); + if (m_closeProgress || m_processCanceled) + listener->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, 0); + else + { + listener->OnStatusChange(nsnull, nsnull, 0, m_pendingStatus.GetUnicode()); + if (m_pendingStateFlags != -1) + listener->OnStateChange(nsnull, nsnull, m_pendingStateFlags, m_pendingStateValue); + } + } + + return NS_OK; +} + +/* void UnregisterListener (in nsIWebProgressListener listener); */ +NS_IMETHODIMP nsMsgProgress::UnregisterListener(nsIWebProgressListener *listener) +{ + if (m_listenerList && listener) + m_listenerList->RemoveElement(listener); + + return NS_OK; +} + +/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */ +NS_IMETHODIMP nsMsgProgress::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus) +{ + nsresult rv = NS_OK; + + m_pendingStateFlags = aStateFlags; + m_pendingStateValue = aStatus; + + if (m_listenerList) + { + PRUint32 count; + PRInt32 i; + + rv = m_listenerList->Count(&count); + NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed"); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr aSupports; + nsCOMPtr aProgressListener; + for (i = count - 1; i >= 0; i --) + { + m_listenerList->GetElementAt(i, getter_AddRefs(aSupports)); + aProgressListener = do_QueryInterface(aSupports); + if (aProgressListener) + aProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus); + } + } + + return rv; +} + +/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ +NS_IMETHODIMP nsMsgProgress::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) +{ + nsresult rv = NS_OK; + + if (m_listenerList) + { + PRUint32 count; + PRInt32 i; + + rv = m_listenerList->Count(&count); + NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed"); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr aSupports; + nsCOMPtr aProgressListener; + for (i = count - 1; i >= 0; i --) + { + m_listenerList->GetElementAt(i, getter_AddRefs(aSupports)); + aProgressListener = do_QueryInterface(aSupports); + if (aProgressListener) + aProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress); + } + } + + return rv; +} + +/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ +NS_IMETHODIMP nsMsgProgress::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ +NS_IMETHODIMP nsMsgProgress::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage) +{ + nsresult rv = NS_OK; + + m_pendingStatus = aMessage; + if (m_listenerList) + { + PRUint32 count; + PRInt32 i; + + rv = m_listenerList->Count(&count); + NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed"); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr aSupports; + nsCOMPtr aProgressListener; + for (i = count - 1; i >= 0; i --) + { + m_listenerList->GetElementAt(i, getter_AddRefs(aSupports)); + aProgressListener = do_QueryInterface(aSupports); + if (aProgressListener) + aProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage); + } + } + + return rv; +} + +/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */ +NS_IMETHODIMP nsMsgProgress::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +nsresult nsMsgProgress::ReleaseListeners() +{ + nsresult rv = NS_OK; + + if (m_listenerList) + { + PRUint32 count; + PRInt32 i; + + rv = m_listenerList->Count(&count); + NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed"); + if (NS_SUCCEEDED(rv)) + for (i = count - 1; i >= 0; i --) + m_listenerList->RemoveElementAt(i); + } + + return rv; +} + diff --git a/mozilla/mailnews/base/src/nsMsgProgress.h b/mozilla/mailnews/base/src/nsMsgProgress.h new file mode 100644 index 00000000000..c5858e0d03d --- /dev/null +++ b/mozilla/mailnews/base/src/nsMsgProgress.h @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Jean-Francois Ducarroz + */ + +#include "nsIMsgProgress.h" + +#include "nsCOMPtr.h" +#include "nsISupportsArray.h" +#include "nsIDOMWindowInternal.h" + +class nsMsgProgress : public nsIMsgProgress +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIMSGPROGRESS + NS_DECL_NSIWEBPROGRESSLISTENER + + nsMsgProgress(); + virtual ~nsMsgProgress(); + +private: + nsresult ReleaseListeners(void); + + PRBool m_closeProgress; + PRBool m_processCanceled; + nsString m_pendingStatus; + PRInt32 m_pendingStateFlags; + PRInt32 m_pendingStateValue; + nsCOMPtr m_dialog; + nsCOMPtr m_listenerList; +}; diff --git a/mozilla/mailnews/compose/public/nsIMsgComposeProgressParams.idl b/mozilla/mailnews/compose/public/nsIMsgComposeProgressParams.idl new file mode 100644 index 00000000000..16393af2bdb --- /dev/null +++ b/mozilla/mailnews/compose/public/nsIMsgComposeProgressParams.idl @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Jean-Francois Ducarroz +*/ +#include "nsISupports.idl" +#include "nsIMsgCompose.idl" + +[scriptable, uuid(1e0e7c00-3e4c-11d5-9daa-f88d288130fc)] +interface nsIMsgComposeProgressParams: nsISupports { + + /* message subject */ + attribute wstring subject; + + /* delivery mode */ + attribute MSG_DeliverMode deliveryMode; +}; diff --git a/mozilla/mailnews/compose/src/nsMsgComposeProgressParams.cpp b/mozilla/mailnews/compose/src/nsMsgComposeProgressParams.cpp new file mode 100644 index 00000000000..ead0eaf30d5 --- /dev/null +++ b/mozilla/mailnews/compose/src/nsMsgComposeProgressParams.cpp @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Jean-Francois Ducarroz + */ + +#include "nsMsgComposeProgressParams.h" + + +NS_IMPL_ISUPPORTS1(nsMsgComposeProgressParams, nsIMsgComposeProgressParams) + +nsMsgComposeProgressParams::nsMsgComposeProgressParams() : + m_deliveryMode(nsIMsgCompDeliverMode::Now) +{ + NS_INIT_ISUPPORTS(); +} + +nsMsgComposeProgressParams::~nsMsgComposeProgressParams() +{ +} + +/* attribute wstring subject; */ +NS_IMETHODIMP nsMsgComposeProgressParams::GetSubject(PRUnichar * *aSubject) +{ + NS_ENSURE_ARG(aSubject); + + *aSubject = m_subject.ToNewUnicode(); + return NS_OK; +} +NS_IMETHODIMP nsMsgComposeProgressParams::SetSubject(const PRUnichar * aSubject) +{ + m_subject = aSubject; + return NS_OK; +} + +/* attribute MSG_DeliverMode deliveryMode; */ +NS_IMETHODIMP nsMsgComposeProgressParams::GetDeliveryMode(MSG_DeliverMode *aDeliveryMode) +{ + NS_ENSURE_ARG(aDeliveryMode); + + *aDeliveryMode = m_deliveryMode; + return NS_OK; +} +NS_IMETHODIMP nsMsgComposeProgressParams::SetDeliveryMode(MSG_DeliverMode aDeliveryMode) +{ + m_deliveryMode = aDeliveryMode; + return NS_OK; +} diff --git a/mozilla/mailnews/compose/src/nsMsgComposeProgressParams.h b/mozilla/mailnews/compose/src/nsMsgComposeProgressParams.h new file mode 100644 index 00000000000..687b138bf6a --- /dev/null +++ b/mozilla/mailnews/compose/src/nsMsgComposeProgressParams.h @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Jean-Francois Ducarroz + */ + +#include "nsIMsgComposeProgressParams.h" + +class nsMsgComposeProgressParams : public nsIMsgComposeProgressParams +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIMSGCOMPOSEPROGRESSPARAMS + + nsMsgComposeProgressParams(); + virtual ~nsMsgComposeProgressParams(); + +private: + nsString m_subject; + MSG_DeliverMode m_deliveryMode; +};