Back to index

lightning-sunbird  0.9+nobinonly
nsMsgDeliveryListener.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Pierre Phaneuf <pp@ludusdesign.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 #include "nsMsgDeliveryListener.h"
00039 
00040 #include "nsIMsgMailNewsUrl.h"
00041 #include "nsMsgPrompts.h"
00042 
00043 NS_IMPL_ISUPPORTS1(nsMsgDeliveryListener, nsIUrlListener)
00044 
00045 nsresult 
00046 nsMsgDeliveryListener::OnStartRunningUrl(nsIURI * aUrl)
00047 {
00048 #ifdef NS_DEBUG
00049 //  printf("Starting to run the delivery operation\n");
00050 #endif
00051 
00052   if (mMsgSendObj)
00053     mMsgSendObj->NotifyListenerOnStartSending(nsnull, nsnull);
00054 
00055   if (mMsgSendLaterObj)
00056     mMsgSendLaterObj->NotifyListenersOnStartSending(nsnull);
00057   
00058        return NS_OK;
00059 }
00060 
00061 nsresult 
00062 nsMsgDeliveryListener::OnStopRunningUrl(nsIURI * aUrl, nsresult aExitCode)
00063 {
00064   nsresult rv = NS_ERROR_UNEXPECTED;
00065 #ifdef NS_DEBUG
00066 //  printf("\nOnStopRunningUrl() called!\n");
00067 #endif
00068 
00069   // First, stop being a listener since we are done.
00070   if (aUrl)
00071        {
00072               // query it for a mailnews interface for now....
00073               nsCOMPtr<nsIMsgMailNewsUrl> mailUrl = do_QueryInterface(aUrl);
00074               if (mailUrl)
00075                      mailUrl->UnRegisterListener(this);
00076        }
00077 
00078   if (mMsgSendObj)
00079     mMsgSendObj->NotifyListenerOnStopSending(
00080                                   nsnull,     // const char *aMsgID, 
00081                                   aExitCode,  // nsresult aStatus, 
00082                                   nsnull,     // const PRUnichar *aMsg, 
00083                                   nsnull);    // nsIFileSpec *returnFileSpec);
00084 
00085   if (mMsgSendLaterObj)
00086     mMsgSendLaterObj->NotifyListenersOnStopSending(aExitCode,
00087                             nsnull,  // const PRUnichar *aMsg, 
00088                             nsnull,  // PRUint32 aTotalTried, 
00089                             nsnull); // PRUint32 aSuccessful);
00090 
00091   // 
00092   // Now, important, if there was a callback registered, call the 
00093   // creators exit routine.
00094   //
00095   if (mCompletionCallback)
00096     rv = (*mCompletionCallback) (aUrl, aExitCode, mDeliveryType, mTagData);
00097   else
00098     rv = NS_OK;
00099 
00100        return rv;
00101 }
00102 
00103 nsMsgDeliveryListener::nsMsgDeliveryListener(nsMsgDeliveryCompletionCallback callback,
00104                                              nsMsgDeliveryType delivType, nsISupports *tagData)
00105 {
00106 #if defined(DEBUG_ducarroz)
00107   printf("CREATE nsMsgDeliveryListener: %x\n", this);
00108 #endif
00109 
00110   mTempFileSpec = nsnull;
00111   mDeliveryType = delivType;
00112   mTagData = tagData;
00113   mCompletionCallback = callback;
00114   mMsgSendObj = nsnull;
00115   mMsgSendLaterObj = nsnull;
00116 }
00117 
00118 nsMsgDeliveryListener::~nsMsgDeliveryListener()
00119 {
00120 #if defined(DEBUG_ducarroz)
00121   printf("DISPOSE nsMsgDeliveryListener: %x\n", this);
00122 #endif
00123 
00124   delete mTempFileSpec;
00125 }
00126 
00127 nsresult 
00128 nsMsgDeliveryListener::SetMsgComposeAndSendObject(nsIMsgSend *obj)
00129 {
00130   mMsgSendObj = obj;
00131   return NS_OK;
00132 }
00133 
00134 nsresult 
00135 nsMsgDeliveryListener::SetMsgSendLaterObject(nsMsgSendLater *obj)
00136 {
00137   mMsgSendLaterObj = obj;
00138   return NS_OK;
00139 }