Back to index

lightning-sunbird  0.9+nobinonly
UDownloadDisplay.h
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.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) 2002
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *  Conrad Carlen <ccarlen@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * 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 
00039 #ifndef UDownloadDisplay_h__
00040 #define UDownloadDisplay_h__
00041 #pragma once
00042 
00043 #include "UDownload.h"
00044 
00045 #include <LWindow.h>
00046 
00047 class CMultiDownloadProgressWindow;
00048 class CDownloadProgressView;
00049 
00050 class LProgressBar;
00051 class LStaticText;
00052 
00053 
00054 //*****************************************************************************
00055 // CMultiDownloadProgress
00056 //
00057 // A concrete instance of ADownloadProgressView which displays each download
00058 // as a subpane of the same window.
00059 //
00060 // NOTE: The implementation uses nsILocalFile::Launch() to "open" a downloaded
00061 // item. If the app which opens it is Stuffit Expander, we will receive an
00062 // ae_ApplicationDied event when Stuffit finishes and terminates.
00063 // PowerPlant will throw an exception for any unhandled Apple Event. To inhibit
00064 // this, add a case for ae_ApplicationDied to your application's HandleAppleEvent().
00065 // The event does not need to be handled, just prevented from reaching
00066 // the default handler.
00067 //*****************************************************************************
00068 
00069 class CMultiDownloadProgress : public ADownloadProgressView,
00070                                public LCommander,
00071                                public LListener
00072 {
00073 public:
00074                             CMultiDownloadProgress();
00075     virtual                 ~CMultiDownloadProgress();
00076 
00077     // ADownloadProgressView
00078     virtual void            AddDownloadItem(CDownload *aDownloadItem);
00079     
00080     // LCommander
00081     virtual Boolean         AllowSubRemoval(LCommander* inSub);
00082     virtual Boolean         AttemptQuitSelf(SInt32 inSaveOption);
00083     
00084     // LListener
00085     virtual void            ListenToMessage(MessageT inMessage,
00086                                             void* ioParam);
00087 
00088 protected:
00089     static bool             sRegisteredViewClasses;
00090 
00091     CMultiDownloadProgressWindow *mWindow;
00092 };
00093 
00094 
00095 //*****************************************************************************
00096 // CMultiDownloadProgressWindow
00097 //
00098 // A window class which holds an array of progress views.
00099 //*****************************************************************************
00100 
00101 class CMultiDownloadProgressWindow : public LWindow,
00102                                      public LBroadcaster
00103 {
00104 public:
00105     enum { class_ID = FOUR_CHAR_CODE('MDPW') };
00106 
00107                             CMultiDownloadProgressWindow();
00108                             CMultiDownloadProgressWindow(LStream* inStream);
00109                             
00110     virtual                 ~CMultiDownloadProgressWindow();
00111                                             
00112     // CMultiDownloadProgressWindow
00113     virtual void            AddDownloadView(CDownloadProgressView *aView);
00114     virtual void            RemoveDownloadView(CDownloadProgressView *aView);
00115     virtual Boolean         ConfirmClose();    
00116     
00117 protected:
00118     SInt32                  mDownloadViewCount;
00119 };
00120 
00121 
00122 //*****************************************************************************
00123 // CDownloadProgressView
00124 //
00125 // A view class which tracks a single download.
00126 //*****************************************************************************
00127 
00128 class CDownloadProgressView : public LView,
00129                               public LCommander,
00130                               public LListener
00131 {
00132 public:
00133     enum { class_ID = FOUR_CHAR_CODE('DPrV') };
00134 
00135                             CDownloadProgressView();
00136                             CDownloadProgressView(LStream* inStream);
00137                             
00138     virtual                 ~CDownloadProgressView();
00139 
00140     // LCommander
00141     virtual Boolean         ObeyCommand(CommandT inCommand,
00142                                         void *ioParam);
00143                                         
00144 
00145     // LPane
00146     virtual void            FinishCreateSelf();
00147 
00148     // LListener
00149     virtual void            ListenToMessage(MessageT inMessage,
00150                                             void* ioParam);
00151 
00152     // CDownloadProgressView
00153     virtual void            SetDownload(CDownload *aDownload);
00154     virtual void            CancelDownload();
00155     virtual Boolean         IsActive();
00156                                                         
00157     virtual void            UpdateStatus(CDownload::MsgOnDLProgressChangeInfo *info);
00158     LStr255&                FormatBytes(float inBytes, LStr255& ioString);
00159     LStr255&                FormatFuzzyTime(PRInt32 inSecs, LStr255& ioString);
00160 
00161     static OSErr            CreateStyleRecFromThemeFont(ThemeFontID inThemeID,
00162                                                         ControlFontStyleRec& outStyle);
00163 
00164 protected:
00165     enum { kStatusUpdateIntervalTicks = 60 };
00166 
00167     LProgressBar            *mProgressBar;
00168     LControl                *mCancelButton, *mOpenButton, *mRevealButton;
00169     LControl                *mCloseButton;
00170     LStaticText             *mStatusText, *mTimeRemainingText;
00171     LStaticText             *mSrcURIText, *mDestFileText;
00172 
00173     nsCOMPtr<nsIDownload>   mDownload;
00174     Boolean                 mDownloadActive;
00175     SInt32                  mLastStatusUpdateTicks;
00176 };
00177 
00178 #endif // DownloadProgressViews_h__