inetop.h

Go to the documentation of this file.
00001 // $Id: inetop.h 751 2006-03-31 15:43:49Z alex $
00002 // Webster web clipart gallery - asynchronous operations and support classes
00003 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00004 ================================XARAHEADERSTART===========================
00005  
00006                Xara LX, a vector drawing and manipulation program.
00007                     Copyright (C) 1993-2006 Xara Group Ltd.
00008        Copyright on certain contributions may be held in joint with their
00009               respective authors. See AUTHORS file for details.
00010 
00011 LICENSE TO USE AND MODIFY SOFTWARE
00012 ----------------------------------
00013 
00014 This file is part of Xara LX.
00015 
00016 Xara LX is free software; you can redistribute it and/or modify it
00017 under the terms of the GNU General Public License version 2 as published
00018 by the Free Software Foundation.
00019 
00020 Xara LX and its component source files are distributed in the hope
00021 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00022 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00023 See the GNU General Public License for more details.
00024 
00025 You should have received a copy of the GNU General Public License along
00026 with Xara LX (see the file GPL in the root directory of the
00027 distribution); if not, write to the Free Software Foundation, Inc., 51
00028 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00029 
00030 
00031 ADDITIONAL RIGHTS
00032 -----------------
00033 
00034 Conditional upon your continuing compliance with the GNU General Public
00035 License described above, Xara Group Ltd grants to you certain additional
00036 rights. 
00037 
00038 The additional rights are to use, modify, and distribute the software
00039 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00040 library and any other such library that any version of Xara LX relased
00041 by Xara Group Ltd requires in order to compile and execute, including
00042 the static linking of that library to XaraLX. In the case of the
00043 "CDraw" library, you may satisfy obligation under the GNU General Public
00044 License to provide source code by providing a binary copy of the library
00045 concerned and a copy of the license accompanying it.
00046 
00047 Nothing in this section restricts any of the rights you have under
00048 the GNU General Public License.
00049 
00050 
00051 SCOPE OF LICENSE
00052 ----------------
00053 
00054 This license applies to this program (XaraLX) and its constituent source
00055 files only, and does not necessarily apply to other Xara products which may
00056 in part share the same code base, and are subject to their own licensing
00057 terms.
00058 
00059 This license does not apply to files in the wxXtra directory, which
00060 are built into a separate library, and are subject to the wxWindows
00061 license contained within that directory in the file "WXXTRA-LICENSE".
00062 
00063 This license does not apply to the binary libraries (if any) within
00064 the "libs" directory, which are subject to a separate license contained
00065 within that directory in the file "LIBS-LICENSE".
00066 
00067 
00068 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00069 ----------------------------------------------
00070 
00071 Subject to the terms of the GNU Public License (see above), you are
00072 free to do whatever you like with your modifications. However, you may
00073 (at your option) wish contribute them to Xara's source tree. You can
00074 find details of how to do this at:
00075   http://www.xaraxtreme.org/developers/
00076 
00077 Prior to contributing your modifications, you will need to complete our
00078 contributor agreement. This can be found at:
00079   http://www.xaraxtreme.org/developers/contribute/
00080 
00081 Please note that Xara will not accept modifications which modify any of
00082 the text between the start and end of this header (marked
00083 XARAHEADERSTART and XARAHEADEREND).
00084 
00085 
00086 MARKS
00087 -----
00088 
00089 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00090 designs are registered or unregistered trademarks, design-marks, and/or
00091 service marks of Xara Group Ltd. All rights in these marks are reserved.
00092 
00093 
00094       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00095                         http://www.xara.com/
00096 
00097 =================================XARAHEADEREND============================
00098  */
00099 
00100 #ifndef _INETOP_H_
00101 #define _INETOP_H_
00102 
00103 #include "sgliboil.h"
00104 #include "sglib.h"
00105 #include "scrvw.h"
00106 #include "camnet.h"
00107 #include "stl.h"
00108 #include <list>
00109 
00110 
00111 
00112 // File download operation 
00114 
00115 /****************************************************************************
00116 
00117 >   class DownloadOpParam
00118 
00119     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com> 
00120     Created:    3/03/97
00121     Purpose:    Download operation parameter structure - passes the minimum necessary information to the Op
00122                     All operations derived from DownloadOp should be invoked with parameters derived from this class.
00123 
00124     NOTE:       Objects of this type and any derived types MUST BE CREATED ON THE HEAP. Also, never delete
00125                         objects of this type once you passed them to DownloadOp or a derived class
00126 
00127 ****************************************************************************/
00128 
00129 class DownloadOpParam : public OpParam
00130 {
00131 public:
00132     // Local path of file to download to
00133     PathName file;      
00134     // URL to be downloaded (can be http://, ftp://, file://)
00135     String_256 strURL;  
00136     // Flag indicating whether the operation should display a progress dialog. If you set it to FALSE you'll have to set up
00137     // your own progress indicator
00138     BOOL bHasProgressDlg;
00139     // Description of the file - this will be displayed in the progress dialog as "Downloading <description>". If empty, the filename 
00140     // will be used instead
00141     String_256 strDescription; 
00142     // Type of file we're downloading - must be set to one of the types enumerated in camnet.h
00143     FileType type;
00144     // Priority of the download - can be either AsynchDownload::PRIORITY_NORMAL or AsynchDownload::PRIORITY_HIGH
00145     AsynchDownload::Priority priority;
00146 
00147 protected:
00148     DownloadOpParam();
00149     static void* pAllocatedMemory;
00150 
00151 public:
00152     void* operator new(size_t stSize, LPCSTR lpszFileName, INT32 nLine)
00153     {
00154         return (pAllocatedMemory = SimpleCCObject::operator new(stSize, lpszFileName, nLine));
00155     }
00156     void* operator new(size_t stSize)
00157     {
00158         return (pAllocatedMemory = SimpleCCObject::operator new(stSize));
00159     }
00160 };
00161                         
00162 
00163 #define OPTOKEN_OPDOWNLOAD _T("DownloadOp") // Optoken for the basic download operation 
00164 
00165 /****************************************************************************
00166 
00167 >   class DownloadOp: public Operation
00168 
00169     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com> 
00170     Created:    7/04/97
00171     Purpose:    File download operation. This class is intended as a base class
00172                     for new Internet-related operations - it has little use on its own.
00173                     The older internet operations used in Webster 1 are derived straight from
00174                     Operation and were a bit difficult to implement
00175     SeeAlso: -
00176 
00177 ****************************************************************************/
00178 
00179 class DownloadOp : public Operation
00180 {         
00181     CC_DECLARE_DYNCREATE(DownloadOp)
00182 
00183 public:
00184     DownloadOpParam* pParam;
00185 
00186     DownloadOp();
00187     virtual ~DownloadOp();
00188     // Standard operation overrides
00189     static  BOOL Init();                        
00190     static  OpState GetState(String_256*, OpDescriptor*);
00191     virtual void    Do(OpDescriptor *);
00192     virtual BOOL OnIdleEvent();
00193     virtual void    DoWithParam(OpDescriptor* pOp, OpParam* pDownloadOpParam);
00194     virtual void End(); 
00195     virtual BOOL OnDeathMsg() { End(); return TRUE;}
00196     virtual void OnDownloadSuccess();       // called in case the download succeeds
00197     virtual void OnDownloadFail();          // called in case the download fails through network or I/O errors
00198     virtual void OnDownloadAbort();         // called in case the download is aborted by the user
00199     virtual void OnDownloadPending();       // called when the download is just doing it's thang
00200 
00201 protected:
00202     DOWNLOAD_HANDLE m_hDownload;
00203     INT32 m_nPercentageCompleted;
00204     virtual void OnDownloadProgress(const INT32 nPercentageCompleted) {}; // called when a new chunk of data arrives 
00205 };
00206 
00207 
00208 
00209 
00210 
00211 // Web fonts install
00213 
00214 class WebFontInstallParam : public DownloadOpParam
00215 {
00216 public:
00217     String_256 strAltDescription;
00218     BOOL bIsTemp;
00219     LibraryGallery* pGallery;
00220         
00221     WebFontInstallParam();
00222     ~WebFontInstallParam();
00223 };
00224 
00225 
00226                   
00227 #define OPTOKEN_OPASYNCHFONTINSTALL _T("AsynchFontInstall") // Optoken for the asynchronous  font install 
00228 
00229 
00230 /****************************************************************************
00231 
00232 >   class OpAsynchFontInstall : public DownloadOp
00233 
00234     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com> 
00235     Created:    3/03/97
00236     Purpose:    This operation will attempt to download and install fonts
00237                     from a web server to the local machine
00238     SeeAlso:    OpAsynchClipartImport
00239 
00240 ****************************************************************************/
00241 
00242 
00243 class OpAsynchFontInstall : public DownloadOp
00244 {         
00245     CC_DECLARE_DYNCREATE(OpAsynchFontInstall)
00246 
00247 public:
00248     OpAsynchFontInstall() {};
00249     virtual ~OpAsynchFontInstall() {};  
00250     static  BOOL Init();                        
00251 
00252 protected:
00253     virtual void OnDownloadSuccess();
00254 };
00255 
00256 
00257 // Asynch bitmap import
00258 // Note that the actual import will be performed only if the bitmap is to be set as document background;
00259 // otherwise the operation will limit itself to downloading the fill file
00261 
00262 class AsynchBitmapImportParam : public DownloadOpParam
00263 {
00264 public:
00265     // The next four params mirror those of BitmapImport.  This allows these
00266     // settings to be copied into a BitmapImport class OnDownloadSuccess().
00267     Document*           pTargetDoc;         // Document the bitmap is going into
00268     FillTypeEnum        FillType;           // The type of fill (ApplyToObject, SetBackground, AddToPage)
00269     UINT32              TagObjectToFill;    // Object to apply the fill to (if fill type == ApplyToObject)
00270     bool                TagObjectValid;     // Use Tag? (if !TagObjectValid && !pObjectValid use selection)
00271     NodeRenderableInk*  pObject;            // Pointer to object to fill
00272     bool                pObjectValid;       // Use pObject? (if !TagObjectValid && !pObjectValid use selection)
00273     Spread*             pSpread;            // Spread (for FillType == SetBackground)
00274     DocCoord            DropPos;            // DropPos (for FillType == AddToPage)
00275 
00276     AsynchBitmapImportParam();
00277     ~AsynchBitmapImportParam() {};
00278 };
00279 
00280 
00281 #define OPTOKEN_ASYNCHBITMAPIMPORT _T("AsynchBitmapImport") // Optoken for asynchronous bitmap import 
00282 
00283 
00284 /****************************************************************************
00285 
00286 >   class OpAsynchBitmapImport : public DownloadOp
00287 
00288     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com> 
00289     Created:    3/06/97
00290     Purpose:    This operation will attempt to download and import a bitmap
00291                     located on a web server
00292     SeeAlso:    DownloadOp
00293 
00294 ****************************************************************************/
00295 
00296 
00297 class OpAsynchBitmapImport : public DownloadOp
00298 {         
00299     CC_DECLARE_DYNCREATE(OpAsynchBitmapImport)
00300 
00301 public:
00302     OpAsynchBitmapImport() {};
00303     virtual ~OpAsynchBitmapImport() {}; 
00304     static  BOOL Init();                        
00305     virtual BOOL OnDocChangingMsg(Document* pChangingDoc, DocChangingMsg::DocState State);
00306 
00307 protected:
00308     virtual void OnDownloadSuccess();
00309 };
00310 
00311 
00312 
00313 
00314 
00315 
00316 // Thumbnail downloading
00318 
00319 class OpThumbDownload;
00320 
00321 class CCAPI ThumbDownloadParam
00322 {
00323 public:
00324     ThumbDownloadParam();
00325     ~ThumbDownloadParam();
00326 
00327 public:
00328     SGLibDisplayItem* pItem;
00329     OpThumbDownload* pOp;
00330     SGLibType type;
00331     BOOL bSuccess;
00332 };
00333                   
00334 #define OPTOKEN_OPTHUMBDOWNLOAD _T("ThumbnailDownload") // Optoken for the thumbnail download 
00335 
00336 
00337 /****************************************************************************
00338 
00339 >   class OpThumbDownload: public Operation
00340 
00341     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com> 
00342     Created:    7/01/97
00343     Purpose:    Thumbnail download operation
00344     SeeAlso: -
00345 
00346 ****************************************************************************/
00347 
00348 
00349 
00350 
00351 class OpThumbDownload : public Operation
00352 {         
00353     CC_DECLARE_DYNCREATE(OpThumbDownload)
00354 
00355 public:
00356     ThumbDownloadParam* pParam;
00357     
00358     OpThumbDownload();  
00359     ~OpThumbDownload(); 
00360 
00361     static  BOOL Init();                        
00362     static  OpState GetState(String_256*, OpDescriptor*);
00363 
00364     virtual void    Do(OpDescriptor *);
00365     virtual BOOL OnIdleEvent();
00366     virtual void    DoWithParam(OpDescriptor* pOp, OpParam* pThumbDownloadParam);
00367     virtual void End(); 
00368     void Abort();
00369     static INT32 GetLastError(SGLibDisplayItem* pItem);
00370     static void ClearErrors();
00371     inline static void Suspend() {m_bIsSuspended = TRUE; InternetManager::Suspend();}
00372     inline static void Resume() {m_bIsSuspended = FALSE; InternetManager::Resume();}
00373 
00374 protected:
00375     DOWNLOAD_HANDLE m_hDownload;
00376     INT32 m_nPercentageCompleted;
00377     static std::list<SGLibDisplayItem*> m_lstFailedItems;
00378     static INT32 ThumbsDownloaded[8];
00379     static INT32 InstanceCount[8];
00380     static INT32 ErrorCount[8];
00381     LibraryGallery* pGallery;
00382     static BOOL m_bIsSuspended;
00383 };
00384 
00385 
00386 
00387 
00388 
00389 // Asynchronous clipart import
00391 
00392 class CCAPI AsynchClipartImportParam
00393 {
00394 public:
00395     AsynchClipartImportParam();
00396     ~AsynchClipartImportParam();
00397 
00398 public:
00399     PathName File;
00400     String_256 strURL;
00401     String_256 strDescription;
00402     BOOL Import;
00403     PageDropInfo DropInfo;
00404     BOOL bDropped;
00405 };
00406                   
00407 #define OPTOKEN_OPASYNCHCLIPARTIMPORT _T("AsynchClipartImport") // Optoken for the asynch clipart import 
00408 
00409 
00410 /****************************************************************************
00411 
00412 >   class OpAsynchClipartImport: public OpClipartImport
00413 
00414     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com> (based on Richard's OpClipartImport)
00415     Created:    7/01/97
00416     Purpose:    This class represents the Undo-able operation to import and
00417                 open clipart files over the Internet
00418     SeeAlso: OpClipartImport
00419 
00420 ****************************************************************************/
00421 
00422 
00423 
00424 
00425 class OpAsynchClipartImport : public OpClipartImport
00426 {         
00427     CC_DECLARE_DYNCREATE( OpAsynchClipartImport )
00428 
00429 public:
00430     AsynchClipartImportParam* pParam;
00431 
00432     OpAsynchClipartImport();    
00433     ~OpAsynchClipartImport();   
00434 
00435     static  BOOL Init();                        
00436     static  OpState GetState(String_256*, OpDescriptor*);
00437 
00438     virtual void    Do(OpDescriptor *);
00439     virtual BOOL OnIdleEvent();
00440     virtual void    DoWithParam(OpDescriptor* pOp, OpParam* pAsynchClipartImportParam);
00441     virtual BOOL OnDocChangingMsg(Document* pChangingDoc, DocChangingMsg::DocState State);
00442     virtual void End(); 
00443 
00444 protected:
00445     DOWNLOAD_HANDLE m_hDownload;
00446     Document* m_pTargetDoc;
00447     Document* m_pCurrentSelDoc;
00448 };
00449 
00450 
00451 // Web clipart folders operations 
00453 
00454 #define FOLDER_UNMODIFIED   0
00455 #define FOLDER_UPDATED  1
00456 #define FOLDER_NEW  2
00457 
00458 class CCAPI AddWebFoldersParam
00459 {
00460 public:
00461     AddWebFoldersParam() { pLibGal = NULL;}
00462 
00463 public:
00464     PathName localFile;
00465     String_256 strURL;
00466     String_256 strFolderName;   
00467     LibraryGallery* pLibGal;
00468     SGLibType type;
00469 };
00470 
00471 
00472 #define OPTOKEN_OPADDWEBFOLDERS _T("AddWebFolders") // Optoken for the asynch web folders insertion into the gallery
00473 
00474 
00475 class OpAddWebFolders: public Operation
00476 {         
00477     CC_DECLARE_DYNCREATE(OpAddWebFolders)
00478 
00479 public:
00480     AddWebFoldersParam* pParam;
00481     // SGLibType-indexed vector indicating the result of the operation for each gallery that may use it 
00482     static BOOL Success[8];
00483 
00484     OpAddWebFolders();  
00485     ~OpAddWebFolders(); 
00486 
00487     static  BOOL Init();                        
00488     static  OpState GetState(String_256*, OpDescriptor*);
00489 
00490     virtual void    Do(OpDescriptor *);
00491     virtual BOOL OnIdleEvent();
00492     virtual void    DoWithParam(OpDescriptor* pOp, OpParam* pAddWebFoldersParam);
00493     virtual BOOL OnDeathMsg(); 
00494 
00495 protected:
00496     DOWNLOAD_HANDLE m_hDownload;    
00497 };
00498 
00499 
00500 
00501 
00502 #define OPTOKEN_OPADDWEBLIBRARY _T("AddWebLibrary") // Optoken for the asynch web folders insertion into the gallery
00503 
00504 
00505 class OpAddWebLibrary: public Operation
00506 {         
00507     CC_DECLARE_DYNCREATE(OpAddWebLibrary);
00508 
00509 public:
00510     AddWebFoldersParam* pParam;
00511 
00512     OpAddWebLibrary();  
00513     ~OpAddWebLibrary(); 
00514 
00515     static  BOOL Init();                        
00516     static  OpState GetState(String_256*, OpDescriptor*);
00517 
00518     virtual void    Do(OpDescriptor *);
00519     virtual BOOL OnIdleEvent();
00520     virtual void    DoWithParam(OpDescriptor* pOp, OpParam* pAddWebFoldersParam);
00521     virtual BOOL OnDeathMsg(); 
00522 
00523 protected:
00524     DOWNLOAD_HANDLE m_hDownload;
00525     static BOOL m_bIsSuspended;
00526     // class-wide list of pending download handles 
00527     static std::list<DOWNLOAD_HANDLE> m_lstPendingDownloads;
00528     // SGLibType-indexed counter vectors
00529     static INT32 InstanceCount[8];
00530     static INT32 FoldersAdded[8];
00531     static INT32 ErrorCount[8];
00532     static INT32 CachedFilesUsed[8];
00533     inline static void Suspend() {m_bIsSuspended = TRUE; InternetManager::Suspend();} 
00534     inline static void Resume() {m_bIsSuspended = FALSE; InternetManager::Resume();} 
00535     friend class OpAddWebFolders;
00536 };
00537 
00538 
00539 
00540 
00541 
00542 
00543 #endif

Generated on Sat Nov 10 03:45:33 2007 for Camelot by  doxygen 1.4.4