csxhelp/src/CSXHDocument.cpp
branchRCL_3
changeset 44 12f60d9a73b3
parent 40 0d1adf67ec1b
child 45 cbffe13eac63
equal deleted inserted replaced
40:0d1adf67ec1b 44:12f60d9a73b3
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CCSXHDocument class definition
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CSXHDocument.h"
       
    20 #include "CSXHAppUi.h"
       
    21 
       
    22 #include "CSXHHelpDataBase.h"
       
    23 #include "CSXHKywdTOC1.h"
       
    24 #include "CSXHViewIDs.h"
       
    25 #include <eikprogi.h>
       
    26 
       
    27 #include <cshelp.rsg>
       
    28 #include <AknProgressDialog.h>
       
    29 
       
    30 
       
    31 // Standard Symbian OS construction sequence
       
    32 CCSXHDocument* CCSXHDocument::NewL(CEikApplication& aApp)
       
    33     {
       
    34     CCSXHDocument* self = NewLC(aApp);
       
    35     CleanupStack::Pop(self);
       
    36     return self;
       
    37     }
       
    38 
       
    39 CCSXHDocument* CCSXHDocument::NewLC(CEikApplication& aApp)
       
    40     {
       
    41     CCSXHDocument* self = new (ELeave) CCSXHDocument(aApp);
       
    42     CleanupStack::PushL(self);
       
    43     return self;
       
    44     }
       
    45 
       
    46 CCSXHDocument::CCSXHDocument(CEikApplication& aApp) : CAknDocument(aApp)
       
    47     {// no implementation required
       
    48     }
       
    49 
       
    50 CCSXHDocument::~CCSXHDocument()
       
    51     {
       
    52 	delete iHelpDataBase;
       
    53     }
       
    54 
       
    55 CEikAppUi* CCSXHDocument::CreateAppUiL()
       
    56     {
       
    57     // Create the application user interface, and return a pointer to it,
       
    58     // the framework takes ownership of this object. ConstructL of the AppUi
       
    59     // object will be called by the Application Framework
       
    60     iHelpAppUi = new (ELeave) CCSXHAppUi;
       
    61     
       
    62     HBufC* appToc = CCSXHAppUi::GetCoeEnv()->AllocReadResourceLC( R_CSHELP_TOC_APP_HELPS );
       
    63     iHelpDataBase = CCSXHHelpDataBase::NewL(CCSXHAppUi::GetCoeEnv(),AppCaption(), *appToc);
       
    64     CleanupStack::PopAndDestroy( appToc );
       
    65 	
       
    66 	iDisplayTopic = iHelpDataBase->GetMainTopics();
       
    67 	iPrevTopic = NULL;
       
    68 	
       
    69 	iProgressDialog = NULL;
       
    70     
       
    71     return iHelpAppUi;
       
    72     }
       
    73 // --------------------------------------------------------------------------
       
    74 // Sets the topic to be displayed next
       
    75 // --------------------------------------------------------------------------
       
    76 void CCSXHDocument::SetDisplayTopic(CCSXHHelpContentBase* aDisplayTopic)
       
    77 	{
       
    78 	iDisplayTopic = aDisplayTopic;
       
    79 	iPrevTopic = NULL;
       
    80 	
       
    81 	if(iDisplayTopic == NULL)
       
    82 		iDisplayTopic = iHelpDataBase->GetMainTopics();
       
    83 	}
       
    84 // --------------------------------------------------------------------------
       
    85 // Sets the topic to be displayed next and the previous topic
       
    86 // The previous topic is needed to highlight the correct item in the listbox
       
    87 // --------------------------------------------------------------------------
       
    88 void CCSXHDocument::SetDisplayAndPrevTopic(CCSXHHelpContentBase* aDisplayTopic)
       
    89 	{
       
    90 	iPrevTopic = iDisplayTopic;
       
    91 	iDisplayTopic = aDisplayTopic;
       
    92 	
       
    93 	if(iDisplayTopic == NULL)
       
    94 		iDisplayTopic = iHelpDataBase->GetMainTopics();
       
    95 	
       
    96 	}
       
    97 	
       
    98 void CCSXHDocument::SendMessageToAppUiL(TInt aCommand)
       
    99 	{
       
   100 	iHelpAppUi->ProcessCommandL(aCommand);
       
   101 	}
       
   102 
       
   103 // --------------------------------------------------------------------------
       
   104 // Sets the context topic as the next topic to be displayed
       
   105 // --------------------------------------------------------------------------
       
   106 TBool CCSXHDocument::SetContextTopicAsDisplayTopicL(const TDesC8& aContextMessage)
       
   107 	{
       
   108 	CCSXHHelpContentBase* topic = iHelpDataBase->GetContextTopic(aContextMessage);
       
   109 	if(topic)
       
   110 		{
       
   111 		SetDisplayTopic(topic);	
       
   112 		return ETrue;
       
   113 		}
       
   114 	return EFalse;
       
   115 	}
       
   116 CCSXHHelpContentBase* CCSXHDocument::GetHtmlTopicForUrlL(const TDesC& url)
       
   117 	{
       
   118 	return iHelpDataBase->GetHtmlTopicForUrlL(url);
       
   119 	}
       
   120 
       
   121 void CCSXHDocument::InitProgressBarL()
       
   122 	{
       
   123 
       
   124     iProgressDialog = new(ELeave)CAknProgressDialog(
       
   125                            REINTERPRET_CAST(CEikDialog**,&iProgressDialog));
       
   126     iProgressDialog->PrepareLC(R_CSHELP_SEARCH_PROGRESS_NOTE);
       
   127     
       
   128     CEikProgressInfo* pBar = iProgressDialog->GetProgressInfoL();
       
   129     iTotalKeywordsInResultView = iHelpDataBase->InitGenerateKeywordTOC2ListL(
       
   130     									STATIC_CAST(CCSXHKywdTOC1*,iDisplayTopic));
       
   131     pBar->SetFinalValue(iTotalKeywordsInResultView);
       
   132  	iIdle = CIdle::NewL(CActive::EPriorityLow);
       
   133     TCallBack callback(CallBack, this);
       
   134     iIdle->Start(callback);
       
   135     iProgressDialog->RunDlgLD(CAknNoteDialog::ENoTone);  
       
   136 	}
       
   137 	 	
       
   138 void CCSXHDocument::FreeProgressBarL()
       
   139 	{
       
   140 	delete iIdle;
       
   141     iIdle = NULL;
       
   142     if(iProgressDialog)
       
   143     	{
       
   144     	iProgressDialog->ProcessFinishedL();
       
   145 		iProgressDialog = NULL;
       
   146     	}
       
   147 	}
       
   148 		
       
   149 TInt CCSXHDocument::CallBack(TAny* aThis)
       
   150     {
       
   151     TInt err(KErrNone);
       
   152     TBool res(EFalse);
       
   153     CCSXHDocument* self = STATIC_CAST(CCSXHDocument*, aThis);
       
   154     TRAP( err, res = self->DoCallBackL() );
       
   155     if(err != KErrNone )
       
   156     	{
       
   157     	TRAP_IGNORE(self->FreeProgressBarL());
       
   158     	}
       
   159     return res;
       
   160     }
       
   161 TBool CCSXHDocument::DoCallBackL()
       
   162     {
       
   163     if(!iProgressDialog)
       
   164         {
       
   165         delete iIdle;
       
   166         iIdle = NULL;
       
   167         return EFalse;
       
   168         }
       
   169         
       
   170     CEikProgressInfo* pBar= iProgressDialog->GetProgressInfoL();
       
   171     pBar->SetAndDraw(iHelpDataBase->GetKeywordSearchCount());
       
   172     
       
   173     if(iHelpDataBase->GetKeywordSearchCount() >= iTotalKeywordsInResultView)
       
   174     	{
       
   175     	FreeProgressBarL();
       
   176     	return EFalse;
       
   177     	}
       
   178     
       
   179     return ETrue;    
       
   180     }    
       
   181