OpAsynchClipartImport Class Reference

This class represents the Undo-able operation to import and open clipart files over the Internet. More...

#include <inetop.h>

Inheritance diagram for OpAsynchClipartImport:

OpClipartImport SelOperation UndoableOperation Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 OpAsynchClipartImport ()
 ~OpAsynchClipartImport ()
 OpAsynchClipartImport destructor.
virtual void Do (OpDescriptor *)
virtual BOOL OnIdleEvent ()
 
  • idle time polling loop; continues until either the download completes or the operation is terminated on receiving a death message. Different actions are taken according to the state of the download on completion (succeeded/aborted/failed)

virtual void DoWithParam (OpDescriptor *pOp, OpParam *pAsynchClipartImportParam)
 Performs an asynch clipart import / open depending on the parameters Notes: In case the downloads succeeds, the actual clipart import will be done on the idle loop in order to avoid reentering the import code (potentially messy) in case of multiple symultaneous downloads.
virtual BOOL OnDocChangingMsg (Document *pChangingDoc, DocChangingMsg::DocState State)
 Notifies us if the document we intend to import into is about to be destroyed, in which case we should abort the operation.
virtual void End ()
 overwrites Operation::End() to avoid having an ERROR2 (caused by Document::GetSelectedSpread() returning NULL) go off when Webster exits while an asynch clipart import is still in progress

Static Public Member Functions

static BOOL Init ()
 Creates an OpDescriptor for an AsynchClipartImport operation.
static OpState GetState (String_256 *, OpDescriptor *)
 Returns the OpState of the OpAsynchClipartImport operation.

Public Attributes

AsynchClipartImportParampParam

Protected Attributes

DOWNLOAD_HANDLE m_hDownload
Documentm_pTargetDoc
Documentm_pCurrentSelDoc

Detailed Description

This class represents the Undo-able operation to import and open clipart files over the Internet.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com> (based on Richard's OpClipartImport)
Date:
7/01/97
See also:
OpClipartImport

Definition at line 425 of file inetop.h.


Constructor & Destructor Documentation

OpAsynchClipartImport::OpAsynchClipartImport  ) 
 

Definition at line 536 of file inetop.cpp.

00537 {
00538     pParam = NULL;
00539     m_hDownload = 0;
00540     m_pTargetDoc = NULL;
00541     m_pCurrentSelDoc = NULL;
00542     GetApplication()->RegisterIdleProcessor(IDLEPRIORITY_LOW, this);
00543 }       

OpAsynchClipartImport::~OpAsynchClipartImport  ) 
 

OpAsynchClipartImport destructor.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/12/96
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 560 of file inetop.cpp.

00561 {
00562     GetApplication()->RemoveIdleProcessor(IDLEPRIORITY_LOW, this);
00563     if (pParam)
00564         delete pParam;
00565 }


Member Function Documentation

void OpAsynchClipartImport::Do OpDescriptor NotUsed  )  [virtual]
 

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/1/97
Parameters:
OpClipartImport (unused) [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: Always fails - should not be called

See also:
-

Reimplemented from OpClipartImport.

Definition at line 653 of file inetop.cpp.

00654 {
00655     ERROR3("OpAsynchClipartImport does not provide a Do() function - Use DoWithParam");
00656     End();
00657 }

void OpAsynchClipartImport::DoWithParam OpDescriptor pOp,
OpParam pClipartImportParam
[virtual]
 

Performs an asynch clipart import / open depending on the parameters Notes: In case the downloads succeeds, the actual clipart import will be done on the idle loop in order to avoid reentering the import code (potentially messy) in case of multiple symultaneous downloads.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/01/97
Parameters:
pOp - OpDescriptor as for all Do() functions [INPUTS] pClipartImportParam - pointer to AsynchClipartImport structure . This structure must be created on the heap as it should not be destroyed when it goes out of scope.
- none [OUTPUTS] Note that this function returns immediately after starting the download, so its success is not relevant to the outcome of the actual clipart import operation, which will be done on the idle loop if the download eventually succeeds. In case of failure, however, the user will be informed that the download - and clipart import - cannot be started.
Returns:
-
See also:
OpClipartImport, OpAsynchClipartImport::OnIdleEvent()

Reimplemented from OpClipartImport.

Definition at line 682 of file inetop.cpp.

00683 {
00684     AsynchClipartImportParam *pInfo = (AsynchClipartImportParam*) pClipartImportParam;
00685 
00686     if(pInfo == NULL)
00687     {
00688         ERROR3("OpAsynchClipartImport called with NULL info pointer");
00689         goto FAIL;
00690     }
00691     else
00692     {
00693         if (!pInfo->File.IsValid() || pInfo->strURL.IsEmpty())
00694         {
00695             ERROR3("Invalid file path or URL");
00696             goto FAIL;
00697         }
00698         // Remember the document pointer
00699         m_pTargetDoc = Document::GetSelected();
00700         m_pCurrentSelDoc = Document::GetSelected(); // target and selected are the same at this stage
00701         // Register the file for download
00702         DOWNLOADINFO downloadInfo;
00703         downloadInfo.strURL = pInfo->strURL;
00704         downloadInfo.strLocalFile = (String_256) pInfo->File.GetPath();
00705         downloadInfo.nFileType = TYPE_CLIPART;
00706         downloadInfo.nPriority = AsynchDownload::PRIORITY_HIGH;
00707         downloadInfo.strDescription = pInfo->strDescription;
00708         downloadInfo.bHasProgressDlg = TRUE;
00709         downloadInfo.hwndNotifyWindow = 0;
00710         downloadInfo.lNotifyToken = 0;
00711         m_hDownload = InternetManager::RegisterDownload(&downloadInfo);
00712         if (!m_hDownload || m_hDownload == (DOWNLOAD_HANDLE) INVALID_HANDLE_VALUE)
00713         {
00714             ERROR3("Failed to register download");
00715             goto FAIL;
00716         }
00717         pParam = pInfo;
00718     }
00719     return;
00720 
00721 FAIL:
00722         FailAndExecute(); 
00723         End();
00724 }

void OpAsynchClipartImport::End  )  [virtual]
 

overwrites Operation::End() to avoid having an ERROR2 (caused by Document::GetSelectedSpread() returning NULL) go off when Webster exits while an asynch clipart import is still in progress

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
21/01/97
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
Operation::End()

Reimplemented from SelOperation.

Definition at line 744 of file inetop.cpp.

00745 {
00746     if (Document::GetSelectedSpread())
00747         Operation::End();
00748     else
00749         EndOp();
00750 }   

OpState OpAsynchClipartImport::GetState String_256 pString,
OpDescriptor pOpDesc
[static]
 

Returns the OpState of the OpAsynchClipartImport operation.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/3/95
See also:

Reimplemented from OpClipartImport.

Definition at line 606 of file inetop.cpp.

00607 {
00608     OpState OpSt;
00609     return(OpSt);
00610 }

BOOL OpAsynchClipartImport::Init void   )  [static]
 

Creates an OpDescriptor for an AsynchClipartImport operation.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/01/97
Returns:
FALSE if it fails (due to lack of memory)
See also:

Reimplemented from OpClipartImport.

Definition at line 580 of file inetop.cpp.

00581 {  
00582     return RegisterOpDescriptor(
00583         0,                              // Tool ID
00584         _R(IDS_OPASYNCHCLIPARTIMPORT),              // String resource ID
00585         CC_RUNTIME_CLASS(OpAsynchClipartImport),    // Runtime class
00586         OPTOKEN_OPASYNCHCLIPARTIMPORT,          // Token string
00587         OpAsynchClipartImport::GetState,            // GetState function
00588         0,                              // Help ID
00589         0,                              // Bubble ID
00590         0,                              // Resource ID
00591         0                               // Control ID
00592     );
00593 }   

BOOL OpAsynchClipartImport::OnDocChangingMsg Document pChangingDoc,
DocChangingMsg::DocState  State
[virtual]
 

Notifies us if the document we intend to import into is about to be destroyed, in which case we should abort the operation.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/01/97
Returns:
-
See also:
MessageHandler::OnDocChangingMsg()

Reimplemented from MessageHandler.

Definition at line 626 of file inetop.cpp.

00627 {
00628     if (pChangingDoc == m_pTargetDoc && State == DocChangingMsg::ABOUTTODIE)
00629     {
00630         // We end the operation, but don't abort the clipart download - it's up to the user to do that
00631         FailAndExecute(); 
00632         End();
00633     }
00634     return TRUE;
00635 }

BOOL OpAsynchClipartImport::OnIdleEvent void   )  [virtual]
 

  • idle time polling loop; continues until either the download completes or the operation is terminated on receiving a death message. Different actions are taken according to the state of the download on completion (succeeded/aborted/failed)

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/01/97
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
- TRUE if we want to continue polling, FALSE otherwise

Reimplemented from Operation.

Definition at line 771 of file inetop.cpp.

00772 {
00773     ERROR2IF(!pParam, FALSE, "Unexpected NULL pointer");
00774     switch (InternetManager::GetDownloadState(m_hDownload))
00775     {
00776         case AsynchDownload::STATE_PENDING:
00777             // download pending, so we continue polling
00778             return TRUE;
00779 
00780         case AsynchDownload::STATE_SUCCEEDED:
00781         {
00782             // file has transferred successfully, so we can proceed with a synchronous import/open operation
00783             if (pParam->Import)
00784             {
00785                 if (m_pTargetDoc != Document::GetSelected())
00786                 {
00787                     m_pCurrentSelDoc = Document::GetSelected();
00788                     Document::SetSelectedViewAndSpread(m_pTargetDoc);
00789                     // If the target document is not selected yet we keep on polling until it is  
00790                     if (m_pTargetDoc != Document::GetSelected()) 
00791                         return TRUE;
00792                 }
00793                 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpClipartImport));
00794                 if (pOpDesc != NULL)
00795                 {
00796                     ClipartImportParam Param;
00797                     // Set up the parameters which we require to import the clipart
00798                     Param.File = &(pParam->File);
00799                     Param.Import = pParam->Import;
00800                     Param.Result = TRUE;
00801                     if (pParam->bDropped) // if the file has been dropped on the page, get positioning informatiom
00802                         Param.DropInfo =  &(pParam->DropInfo);
00803                     pOpDesc->Invoke((OpParam*) &Param);
00804                     BOOL ok = Param.Result;
00805                     if (!ok)
00806                     {
00807                         ERROR3("LibClipartSGallery::ImportClipart - Problem importing file");
00808                     }
00809                 }
00810                 if (m_pCurrentSelDoc != m_pTargetDoc)
00811                     Document::SetSelectedViewAndSpread(m_pCurrentSelDoc);
00812             }
00813             else // open the file as new document
00814             {
00815                 CWinApp* pApp = AfxGetApp();
00816                 BaseFileDialog::SelectedFilter = 0;
00817                 // Open a document
00818                 CCamDoc* pDoc = (CCamDoc*) pApp->OpenDocumentFile((TCHAR*) String_256(pParam->File.GetPath()));
00819                 // And redraw the imported document
00820                 if(pDoc) pDoc->GetKernelDoc()->ForceRedraw();
00821             }
00822             if (LibFillsSGallery::ThisGallery)
00823                 LibFillsSGallery::ThisGallery->SelectionHasChanged();
00824             SucceedAndDiscard();
00825             End();
00826             return FALSE;
00827         }
00828 
00829         case AsynchDownload::STATE_FAILED:
00830         {
00831             String_256 strTemp;
00832             strTemp.MakeMsg(_R(IDS_DOWNLOADFAILED), (TCHAR*) (String_256) GetStringField((UINT32) SGLib_ClipArt, _R(IDS_GALLERY_DESCRIPTIONS)), (TCHAR*) pParam->strDescription);
00833             Error::SetError(0, strTemp, 0);
00834             InformError();
00835             goto FAIL;
00836         }
00837 
00838         case AsynchDownload::STATE_ABORTED:
00839         {
00840             // no errror message as this state is the result of a user cancel
00841             goto FAIL;
00842         }
00843 
00844         default:
00845             ERROR3("Error or unrecognized state");
00846             goto FAIL;
00847     }
00848 
00849 FAIL:
00850     FailAndDiscard();
00851     End();
00852     return FALSE;
00853 }


Member Data Documentation

DOWNLOAD_HANDLE OpAsynchClipartImport::m_hDownload [protected]
 

Definition at line 445 of file inetop.h.

Document* OpAsynchClipartImport::m_pCurrentSelDoc [protected]
 

Definition at line 447 of file inetop.h.

Document* OpAsynchClipartImport::m_pTargetDoc [protected]
 

Definition at line 446 of file inetop.h.

AsynchClipartImportParam* OpAsynchClipartImport::pParam
 

Definition at line 430 of file inetop.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:57:29 2007 for Camelot by  doxygen 1.4.4