Back to index

lightning-sunbird  0.9+nobinonly
nsTopProgressNotifier.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 Communicator client code, released
00016  * March 31, 1998.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Douglas Turner <dougt@netscape.com>
00025  *   Daniel Veditz <dveditz@netscape.com>
00026  *   Pierre Phaneuf <pp@ludusdesign.com>
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either of the GNU General Public License Version 2 or later (the "GPL"),
00030  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 
00042 #include "nsTopProgressNotifier.h"
00043 
00044 nsTopProgressListener::nsTopProgressListener()
00045 {
00046     mListeners = new nsVoidArray();
00047     mActive = 0;
00048     mLock = PR_NewLock();
00049 }
00050 
00051 nsTopProgressListener::~nsTopProgressListener()
00052 {
00053     if (mLock) PR_Lock(mLock);
00054 
00055     if (mListeners)
00056     {
00057         PRInt32 i=0;
00058         for (; i < mListeners->Count(); i++)
00059         {
00060             nsIXPIListener* element = (nsIXPIListener*)mListeners->ElementAt(i);
00061             NS_IF_RELEASE(element);
00062         }
00063 
00064         mListeners->Clear();
00065         delete (mListeners);
00066     }
00067 
00068     if (mLock)
00069     {
00070         PR_Unlock(mLock);
00071         PR_DestroyLock(mLock);
00072     }
00073 }
00074 
00075 
00076 NS_IMPL_THREADSAFE_ISUPPORTS1(nsTopProgressListener, nsIXPIListener)
00077 
00078 
00079 long
00080 nsTopProgressListener::RegisterListener(nsIXPIListener * newListener)
00081 {
00082     if (mLock) PR_Lock(mLock);
00083     NS_IF_ADDREF( newListener );
00084     long retval = mListeners->AppendElement( newListener );
00085     if (mLock) PR_Unlock(mLock);
00086     return retval;
00087 }
00088 
00089 
00090 void
00091 nsTopProgressListener::UnregisterListener(long id)
00092 {
00093     if (mLock) PR_Lock(mLock);
00094     if (id < mListeners->Count())
00095     {
00096         nsIXPIListener *item = (nsIXPIListener*)mListeners->ElementAt(id);
00097         mListeners->ReplaceElementAt(nsnull, id);
00098         NS_IF_RELEASE(item);
00099     }
00100     if (mLock) PR_Unlock(mLock);
00101 }
00102 
00103 
00104 
00105 NS_IMETHODIMP
00106 nsTopProgressListener::OnInstallStart(const PRUnichar *URL)
00107 {
00108     if (mActive)
00109         mActive->OnInstallStart(URL);
00110 
00111     if (mListeners)
00112     {
00113         PRInt32 i=0;
00114         for (; i < mListeners->Count(); i++)
00115         {
00116             nsIXPIListener* element = (nsIXPIListener*)mListeners->ElementAt(i);
00117             if (element != NULL)
00118                 element->OnInstallStart(URL);
00119         }
00120     }
00121 
00122     return NS_OK;
00123 }
00124 
00125 NS_IMETHODIMP
00126 nsTopProgressListener::OnPackageNameSet(const PRUnichar *URL, const PRUnichar* UIPackageName, const PRUnichar* aVersion)
00127 {
00128     if (mActive)
00129         mActive->OnPackageNameSet(URL, UIPackageName, aVersion);
00130 
00131     if (mListeners)
00132     {
00133         PRInt32 i=0;
00134         for (; i < mListeners->Count(); i++)
00135         {
00136             nsIXPIListener* element = (nsIXPIListener*)mListeners->ElementAt(i);
00137             if (element != NULL)
00138                 element->OnPackageNameSet(URL, UIPackageName, aVersion);
00139         }
00140     }
00141     return NS_OK;
00142 }
00143 
00144 NS_IMETHODIMP
00145 nsTopProgressListener::OnItemScheduled( const PRUnichar* message )
00146 {
00147     long rv = 0;
00148 
00149     if (mActive)
00150         mActive->OnItemScheduled( message );
00151 
00152     if (mListeners)
00153     {
00154         PRInt32 i=0;
00155         for (; i < mListeners->Count(); i++)
00156         {
00157             nsIXPIListener* element = (nsIXPIListener*)mListeners->ElementAt(i);
00158             if (element != NULL)
00159                 element->OnItemScheduled( message );
00160         }
00161     }
00162 
00163     return rv;
00164 }
00165 
00166 NS_IMETHODIMP
00167 nsTopProgressListener::OnFinalizeProgress( const PRUnichar* message, PRInt32 itemNum, PRInt32 totNum )
00168 {
00169     if (mActive)
00170         mActive->OnFinalizeProgress( message, itemNum, totNum );
00171 
00172     if (mListeners)
00173     {
00174         PRInt32 i=0;
00175         for (; i < mListeners->Count(); i++)
00176         {
00177             nsIXPIListener* element = (nsIXPIListener*)mListeners->ElementAt(i);
00178             if (element != NULL)
00179                 element->OnFinalizeProgress( message, itemNum, totNum );
00180         }
00181     }
00182     return NS_OK;
00183 }
00184 
00185 NS_IMETHODIMP
00186 nsTopProgressListener::OnInstallDone(const PRUnichar *URL, PRInt32 status)
00187 {
00188     if (mActive)
00189         mActive->OnInstallDone(URL, status);
00190 
00191     if (mListeners)
00192     {
00193         PRInt32 i=0;
00194         for (; i < mListeners->Count(); i++)
00195         {
00196             nsIXPIListener* element = (nsIXPIListener*)mListeners->ElementAt(i);
00197             if (element != NULL)
00198                 element->OnInstallDone(URL,status);
00199         }
00200     }
00201    return NS_OK;
00202 }
00203 
00204 NS_IMETHODIMP
00205 nsTopProgressListener::OnLogComment(const PRUnichar* comment)
00206 {
00207     if (mActive)
00208         mActive->OnLogComment(comment);
00209 
00210    if (mListeners)
00211     {
00212         PRInt32 i=0;
00213         for (; i < mListeners->Count(); i++)
00214         {
00215             nsIXPIListener* element = (nsIXPIListener*)mListeners->ElementAt(i);
00216             if (element != NULL)
00217                 element->OnLogComment(comment);
00218         }
00219     }
00220    return NS_OK;
00221 }
00222