OpThumbDownload Class Reference

Thumbnail download operation. More...

#include <inetop.h>

Inheritance diagram for OpThumbDownload:

Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

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

virtual void DoWithParam (OpDescriptor *pOp, OpParam *pThumbDownloadParam)
 
  • starts a thumbnail download

virtual void End ()
 Ends the download operation, displaying the thumbnail if successful.
void Abort ()
 Aborts the download operation.

Static Public Member Functions

static BOOL Init ()
 Creates an OpDescriptor for an OpThumbDownload operation.
static OpState GetState (String_256 *, OpDescriptor *)
 Returns the OpState of the OpThumbDownload operation.
static INT32 GetLastError (SGLibDisplayItem *pItem)
 
  • used to decide whether or not we should reattempt a download - if the item got an error no further attempts are made before the error is cleared by the user

static void ClearErrors ()
 
  • resets the error counter and flushes the list of items with download problems, which will allow us to reattempt downloads for these items

static void Suspend ()
static void Resume ()

Public Attributes

ThumbDownloadParampParam

Protected Attributes

DOWNLOAD_HANDLE m_hDownload
INT32 m_nPercentageCompleted
LibraryGallerypGallery

Static Protected Attributes

static std::list< SGLibDisplayItem * > m_lstFailedItems
static INT32 ThumbsDownloaded [8]
static INT32 InstanceCount [8]
static INT32 ErrorCount [8]
static BOOL m_bIsSuspended = FALSE

Detailed Description

Thumbnail download operation.

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

Definition at line 351 of file inetop.h.


Constructor & Destructor Documentation

OpThumbDownload::OpThumbDownload  ) 
 

Definition at line 1696 of file inetop.cpp.

01697 {
01698     pParam = NULL;
01699     m_nPercentageCompleted = 0;
01700     m_hDownload = 0;
01701     pGallery = NULL;
01702     GetApplication()->RegisterIdleProcessor(IDLEPRIORITY_LOW, this);
01703     OpFlags.HasOwnTimeIndicator = TRUE;
01704 }       

OpThumbDownload::~OpThumbDownload  ) 
 

OpThumbDownload destructor.

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

Errors: -

See also:
-

Definition at line 1721 of file inetop.cpp.

01722 {
01723     GetApplication()->RemoveIdleProcessor(IDLEPRIORITY_LOW, this);
01724     if (pParam)
01725     {
01726         InstanceCount[pParam->type]--;
01727         delete pParam;
01728     }
01729 }


Member Function Documentation

void OpThumbDownload::Abort  ) 
 

Aborts the download operation.

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

Errors: -

See also:
Operation::End()

Definition at line 1932 of file inetop.cpp.

01933 {
01934     if (m_hDownload && InternetManager::GetDownloadState(m_hDownload) ==  AsynchDownload::STATE_PENDING)
01935         InternetManager::UnregisterDownload(m_hDownload);
01936     LibraryGallery* pGallery = (LibraryGallery*) pParam->pItem->GetParentGallery();
01937     if (pGallery)
01938     {
01939         pGallery->m_lstPendingThumbs.remove(this);
01940         if (InstanceCount[pParam->type] == 1)
01941             pGallery->SelectionHasChanged();
01942     }
01943     Operation::End();
01944 }   

void OpThumbDownload::ClearErrors  )  [static]
 

  • resets the error counter and flushes the list of items with download problems, which will allow us to reattempt downloads for these items

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

Definition at line 2074 of file inetop.cpp.

02075 {
02076     memset(&ErrorCount, 0x00, sizeof(ErrorCount));
02077     if (!m_lstFailedItems.empty())
02078     {
02079         std::list<SGLibDisplayItem*>::iterator itrBegin = m_lstFailedItems.begin();
02080         std::list<SGLibDisplayItem*>::iterator itrEnd = m_lstFailedItems.end();
02081         m_lstFailedItems.erase(itrBegin, itrEnd); // zapp the entire list
02082         ERROR3IF(!m_lstFailedItems.empty(), "Warning: failed to empty error list");
02083     }
02084 }

void OpThumbDownload::Do OpDescriptor NotUsed  )  [virtual]
 

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

Errors: Always fails - should not be called

See also:
-

Reimplemented from Operation.

Definition at line 1793 of file inetop.cpp.

01794 {
01795     ERROR3("OpThumbDownload does not provide a Do() function - Use DoWithParam");
01796     End();
01797 }

void OpThumbDownload::DoWithParam OpDescriptor pOp,
OpParam pThumbDownloadParam
[virtual]
 

  • starts a thumbnail download

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/01/97
Parameters:
pOp - OpDescriptor as for all Do() functions [INPUTS] pThumbDownloadParam - pointer to ThumbDownloadParam 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 download operation.
Returns:
-

Reimplemented from Operation.

Definition at line 1816 of file inetop.cpp.

01817 {
01818     ThumbDownloadParam* pInfo = (ThumbDownloadParam*) pThumbDownloadParam;
01819 
01820     if (pInfo == NULL || pInfo->pItem == NULL)
01821     {
01822         ERROR3("OpThumbDownload called with NULL info pointer");
01823         End();
01824     }
01825     else
01826     {
01827         String_256 thumbPath;
01828         if (!pInfo->pItem->GetThumbFileName(&thumbPath))
01829         {
01830             ERROR3("Can't get thumbnail file name");
01831             goto FAIL;
01832         }
01833         String_256 thumbNetPath = thumbPath;
01834         Library* pLibrary = pInfo->pItem->GetParentLibrary();
01835         if (!pLibrary)
01836         {
01837             ERROR3("Illegal NULL pointer");
01838             goto FAIL;
01839         }
01840         if (!pLibrary->IsWebLibrary())
01841             goto FAIL;
01842         pLibrary->LocalPath2URL(&thumbNetPath);
01843         // Register the file for download
01844         DOWNLOADINFO downloadInfo;
01845         downloadInfo.strURL = thumbNetPath;
01846         downloadInfo.strLocalFile = thumbPath;
01847         downloadInfo.nFileType = TYPE_THUMBNAIL;
01848         downloadInfo.nPriority = AsynchDownload::PRIORITY_HIGH;
01849         downloadInfo.bHasProgressDlg = FALSE;
01850         downloadInfo.hwndNotifyWindow = 0;
01851         downloadInfo.lNotifyToken = 0;
01852         m_hDownload = InternetManager::RegisterDownload(&downloadInfo);
01853         if (!m_hDownload || m_hDownload == (DOWNLOAD_HANDLE) INVALID_HANDLE_VALUE)
01854         {
01855             InformWarning(_R(IDS_THUMBDOWNLOADFAILED), _R(IDS_OK));
01856             if (pGallery = (LibraryGallery*) pInfo->pItem->GetParentGallery())
01857                 pGallery->bThumbDownloading = FALSE; // turn off thumb downloading so we don't flood the user with error messages 
01858             goto FAIL;
01859         }
01860         pParam = pInfo;
01861         if (pGallery = (LibraryGallery*) pInfo->pItem->GetParentGallery())
01862             pGallery->m_lstPendingThumbs.push_back(this);
01863         pInfo->pOp = this;
01864         pInfo->bSuccess = TRUE;
01865         InstanceCount[pParam->type]++;
01866         // thumb downloads occur in "bursts", so when a new burst begins we must reset the error and download counters
01867         // so that we don't get confused by previous errors
01868         if (InstanceCount[pParam->type] == 1)
01869         {
01870             ErrorCount[pParam->type] = 0;
01871             ThumbsDownloaded[pParam->type] = 0;
01872             pGallery->SelectionHasChanged();
01873         }
01874         return;
01875     }
01876 FAIL:
01877         FailAndExecute(); 
01878         End();
01879 }

void OpThumbDownload::End  )  [virtual]
 

Ends the download operation, displaying the thumbnail if successful.

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

Errors: -

See also:
Operation::End()

Reimplemented from Operation.

Definition at line 1897 of file inetop.cpp.

01898 {
01899     // Abort the download if still pending - this can only happen if the item is being destroyed
01900     if (m_hDownload && InternetManager::GetDownloadState(m_hDownload) ==  AsynchDownload::STATE_PENDING)
01901         InternetManager::UnregisterDownload(m_hDownload);
01902     LibraryGallery* pGallery = (LibraryGallery*) pParam->pItem->GetParentGallery();
01903     if (pGallery)
01904     {
01905         pGallery->m_lstPendingThumbs.remove(this);
01906         if (InstanceCount[pParam->type] == 1)
01907             pGallery->SelectionHasChanged();
01908     }
01909     if (pParam && pParam->pItem) // tell the item that the thumb download is finished
01910         pParam->pItem->OnThumbDownloadComplete();
01911     Operation::End();
01912 }   

INT32 OpThumbDownload::GetLastError SGLibDisplayItem pItem  )  [static]
 

  • used to decide whether or not we should reattempt a download - if the item got an error no further attempts are made before the error is cleared by the user

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/01/97
Parameters:
- pointer to a SGLibDisplayItem [INPUTS]
- [OUTPUTS]
Returns:
- an error code (DOWNLOAD_ERROR) if the item got an error while downloading its thumb, 0 otherwise

Definition at line 2047 of file inetop.cpp.

02048  {
02049     if (m_lstFailedItems.empty())
02050         return 0;
02051     std::list<SGLibDisplayItem*>::iterator listIterator = m_lstFailedItems.begin();
02052     INT32 nListSize = m_lstFailedItems.size();
02053     for (INT32 i = 0; i < nListSize; i++)
02054         if (pItem == *listIterator++)
02055             return DOWNLOAD_ERROR;
02056     return 0;
02057 }

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

Returns the OpState of the OpThumbDownload operation.

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

Definition at line 1769 of file inetop.cpp.

01770 {
01771     OpState OpSt;
01772     return(OpSt);
01773 }

BOOL OpThumbDownload::Init void   )  [static]
 

Creates an OpDescriptor for an OpThumbDownload operation.

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

Reimplemented from SimpleCCObject.

Definition at line 1743 of file inetop.cpp.

01744 {  
01745     return RegisterOpDescriptor(
01746         0,                              // Tool ID
01747         _R(IDS_OPTHUMBDOWNLOAD),                // String resource ID
01748         CC_RUNTIME_CLASS(OpThumbDownload),  // Runtime class
01749         OPTOKEN_OPTHUMBDOWNLOAD,            // Token string
01750         OpThumbDownload::GetState,          // GetState function
01751         0,                              // Help ID
01752         0,                              // Bubble ID
01753         0,                              // Resource ID
01754         0                               // Control ID
01755     );
01756 }   

BOOL OpThumbDownload::OnIdleEvent void   )  [virtual]
 

  • idle time polling loop; continues until either the download completes or the operation is terminated by a call to End(). 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 1964 of file inetop.cpp.

01965 {
01966     ERROR2IF(!pParam, FALSE, "Unexpected NULL pointer");
01967     if (m_bIsSuspended) // if the Op is suspended we don't do anything
01968         return FALSE;
01969     switch (InternetManager::GetDownloadState(m_hDownload))
01970     {
01971         case AsynchDownload::STATE_PENDING:
01972         {
01973             // check the percentage downloaded so far
01974             INT32 nPercentageCompleted = InternetManager::GetPercentageDownloaded(m_hDownload);
01975             ERROR3IF(nPercentageCompleted == -1, "Invalid download handle");
01976             if (nPercentageCompleted != m_nPercentageCompleted) // we made some progress
01977             {
01978                 m_nPercentageCompleted = nPercentageCompleted;
01979                  if (pParam && pParam->pItem) // tell the item to update itself
01980                      pParam->pItem->OnThumbDownloadProgress(nPercentageCompleted);
01981             }
01982             // the download is still pending, so we continue polling
01983             return TRUE;
01984         }
01985         case AsynchDownload::STATE_SUCCEEDED:
01986         {
01987             // We got lucky
01988             ThumbsDownloaded[pParam->type]++;
01989             SucceedAndDiscard();
01990             goto END;
01991         }
01992         case AsynchDownload::STATE_FAILED:
01993         {
01994             ErrorCount[pParam->type]++;
01995             m_lstFailedItems.push_back(pParam->pItem);
01996             goto FAIL;
01997         }
01998         case AsynchDownload::STATE_ABORTED:
01999         {
02000             // user cancel
02001             goto FAIL;
02002         }
02003         default:
02004             ERROR3("Error or unrecognized state");
02005             goto FAIL;
02006     }
02007 
02008 FAIL:
02009     FailAndDiscard();
02010 END:
02011     // Thumb downloads occur in "bursts", so we report errors only once per burst
02012     if (InstanceCount[pParam->type] == 1 && ErrorCount[pParam->type])
02013     {
02014         String_256 strErrorMsg;
02015         if (ThumbsDownloaded[pParam->type]) // partial failure
02016             strErrorMsg.MakeMsg(_R(IDS_THUMBDOWNLOADPARTIALFAIL), (TCHAR*) (String_256) GetStringField((UINT32) pParam->type, _R(IDS_GETX_CAPTIONS)));
02017         else // complete failure...
02018             strErrorMsg.MakeMsg(_R(IDS_THUMBDOWNLOADFAILED), (TCHAR*) (String_256) GetStringField((UINT32) pParam->type, _R(IDS_GETX_CAPTIONS)));
02019 
02020         // As something went wrong (most likely a connection problem) suspend thumb downloading. This means the 
02021         // user can scroll this gallery without more such error popups. Fixes,with LibraryGallery change, #10471
02022         pGallery->bThumbDownloading = FALSE;
02023         
02024         Error::SetError(0, strErrorMsg, 0);
02025         InformError();
02026     }
02027     End();
02028     return FALSE;
02029 }

static void OpThumbDownload::Resume  )  [inline, static]
 

Definition at line 372 of file inetop.h.

static void OpThumbDownload::Suspend  )  [inline, static]
 

Definition at line 371 of file inetop.h.


Member Data Documentation

INT32 OpThumbDownload::ErrorCount [static, protected]
 

Definition at line 380 of file inetop.h.

INT32 OpThumbDownload::InstanceCount [static, protected]
 

Definition at line 379 of file inetop.h.

BOOL OpThumbDownload::m_bIsSuspended = FALSE [static, protected]
 

Definition at line 382 of file inetop.h.

DOWNLOAD_HANDLE OpThumbDownload::m_hDownload [protected]
 

Definition at line 375 of file inetop.h.

std::list< SGLibDisplayItem * > OpThumbDownload::m_lstFailedItems [static, protected]
 

Definition at line 377 of file inetop.h.

INT32 OpThumbDownload::m_nPercentageCompleted [protected]
 

Definition at line 376 of file inetop.h.

LibraryGallery* OpThumbDownload::pGallery [protected]
 

Definition at line 381 of file inetop.h.

ThumbDownloadParam* OpThumbDownload::pParam
 

Definition at line 356 of file inetop.h.

INT32 OpThumbDownload::ThumbsDownloaded [static, protected]
 

Definition at line 378 of file inetop.h.


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