csxhelp/HelpEngine/src/CSXHHelpDataBase.cpp
branchRCL_3
changeset 18 cbffe13eac63
equal deleted inserted replaced
17:12f60d9a73b3 18:cbffe13eac63
       
     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:  CCSXHHelpDataBase class definition
       
    15 *
       
    16 */
       
    17 
       
    18 #include "CSXHHelpDataBase.h"
       
    19 #include "CSXHHTMLContentParser.h"
       
    20 #include "CSXHLegacyContentParser.h"
       
    21 #include "CSXHViewIDs.h"
       
    22 #include "CSXHGenericTOC2.h"
       
    23 #include "CSXHKywdTOC1.h"
       
    24 #include "CSXHMainTopics.h"
       
    25 #include "CSXHKywdTopics.h"
       
    26 #include "CsHelpCmdLineParser.h"
       
    27 #include "CSXHContextTopic.h"
       
    28 #include "coehelp.h" 
       
    29 
       
    30 #include <eikprogi.h>
       
    31 #include <utf.h>
       
    32 #include <bautils.h>
       
    33 #include <data_caging_path_literals.hrh>
       
    34 #include <eikenv.h> 
       
    35 #include <eikprogi.h>
       
    36 
       
    37 
       
    38 #include <AknProgressDialog.h>
       
    39 
       
    40 EXPORT_C CCSXHHelpDataBase* CCSXHHelpDataBase::NewL(CCoeEnv* aCoeEnv,
       
    41 	const TApaAppCaption& aAppCaption, const TApaAppCaption& aAppHelpTopic)
       
    42     {
       
    43     CCSXHHelpDataBase* self = CCSXHHelpDataBase::NewLC(aCoeEnv,aAppCaption, aAppHelpTopic);
       
    44     CleanupStack::Pop(self);
       
    45     return self;    
       
    46     }
       
    47 
       
    48 CCSXHHelpDataBase* CCSXHHelpDataBase::NewLC(CCoeEnv* aCoeEnv, const TApaAppCaption& aAppCaption, const TApaAppCaption& aAppHelpTopic)
       
    49     {
       
    50     CCSXHHelpDataBase *self = NULL;
       
    51     //Add stuff into TLS
       
    52     if(Dll::Tls() == NULL )
       
    53         {
       
    54         // TLS is still null, which means that no Singleton has
       
    55         // been instantiated yet. Do so now, and return that
       
    56         // instance:
       
    57         // Store a pointer to the new instance in thread local storage:
       
    58         self = new(ELeave) CCSXHHelpDataBase(aCoeEnv,aAppCaption, aAppHelpTopic);
       
    59         CleanupStack::PushL(self);
       
    60         self->ConstructL();
       
    61      
       
    62         TInt err = Dll::SetTls(self);
       
    63         if (err != KErrNone)
       
    64             {
       
    65             CleanupStack::Pop(self);            
       
    66             delete self;
       
    67             self = NULL;
       
    68             User::Leave(err);
       
    69             }
       
    70         }
       
    71      else
       
    72         {
       
    73         self = GetInstance();
       
    74         }
       
    75 
       
    76     return self;
       
    77     }
       
    78     
       
    79 CCSXHHelpDataBase* CCSXHHelpDataBase::GetInstance()
       
    80     {
       
    81     // Singleton has been instantiated once already, so return
       
    82     // that instance:
       
    83     return static_cast<CCSXHHelpDataBase*>(Dll::Tls());
       
    84     }
       
    85 
       
    86 CCSXHHelpDataBase::CCSXHHelpDataBase(CCoeEnv* aCoeEnv, const TApaAppCaption& aAppCaption, const TApaAppCaption& aAppHelpTopic)
       
    87              : iCoeEnv(aCoeEnv), iAppCaption(aAppCaption), iAppHelpTopic(aAppHelpTopic), iKeywordSearchCount(0)
       
    88              
       
    89     {
       
    90     }
       
    91 
       
    92 CCSXHHelpDataBase::~CCSXHHelpDataBase()
       
    93     {
       
    94     delete iMainTOC1;
       
    95     delete iKywdTOC1;
       
    96     delete iLastContextTopic;   
       
    97     delete iHTMLContentParser;
       
    98     delete iLegacyContentParser;
       
    99     Dll::SetTls( NULL );
       
   100     }
       
   101 
       
   102 void CCSXHHelpDataBase::ConstructL()
       
   103     {
       
   104     iHTMLContentParser = CCSXHHTMLContentParser::NewL(iCoeEnv);
       
   105     iLegacyContentParser = CCSXHLegacyContentParser::NewL(this);
       
   106     
       
   107     iMainTOC1 = CCSXHMainTopics::NewL(KCSXHToc1ViewID,iAppCaption);
       
   108     iKywdTOC1 = CCSXHKywdTopics::NewL(iAppCaption);
       
   109     
       
   110     //No need to delete iAppHelpsToc in destruct,
       
   111     //because it will be deleted when deleting iMainTOC1.
       
   112     //All third-party helps will be put to this topic
       
   113     TInt appHelpPriority = 20001;
       
   114     iAppHelpsToc = CCSXHMainTopics::NewL( KCSXHToc1AppHelpsViewID, iAppHelpTopic, appHelpPriority );
       
   115         
       
   116     //Build the TOC1 list here
       
   117     iMainTOC1->InsertChildWithPriority(iAppHelpsToc, EFalse);
       
   118     iHTMLContentParser->GenerateTOC1ListL(this);
       
   119     iLegacyContentParser->GenerateTOC1ListL(this);
       
   120     }
       
   121     
       
   122 CCoeEnv* CCSXHHelpDataBase::GetCoeEnv()
       
   123     {
       
   124     return iCoeEnv;
       
   125     }
       
   126 
       
   127 EXPORT_C CCSXHGenericTOC1* CCSXHHelpDataBase::GetMainTopics()
       
   128     {
       
   129     return iMainTOC1;   
       
   130     }
       
   131 EXPORT_C CCSXHGenericTOC1* CCSXHHelpDataBase::GetKywdTopics()
       
   132     {
       
   133     return iKywdTOC1;
       
   134     }
       
   135 
       
   136 EXPORT_C CCSXHGenericTOC1* CCSXHHelpDataBase::GetAppHelpsTopics()
       
   137     {
       
   138     return iAppHelpsToc;   
       
   139     }
       
   140 
       
   141 EXPORT_C CCSXHHelpContentBase* CCSXHHelpDataBase::GetContextTopic(const TDesC8& aContextMessage)
       
   142     {
       
   143     TRAP_IGNORE(GetContextTopicL(aContextMessage));
       
   144     return iLastContextTopic;
       
   145     
       
   146     }
       
   147 CCSXHHelpContentBase* CCSXHHelpDataBase::GetContextTopicL(const TDesC8& aContextMessage)
       
   148     {
       
   149     if(iLastContextTopic)
       
   150         {
       
   151         delete iLastContextTopic;
       
   152         iLastContextTopic = NULL;
       
   153         }
       
   154     //TSW Error Correction:Help: Application crashes 
       
   155     //after trying to re-open context-dependent help from application
       
   156     //Clear childlist of all (TOC1)parents.    
       
   157 	ClearAllTOC1Contents();    
       
   158 	
       
   159     CArrayFix<TCoeHelpContext>* contextList;
       
   160     CCsHlpCmdLineParser* parser = new(ELeave) CCsHlpCmdLineParser;
       
   161     CleanupStack::PushL(parser);
       
   162     parser->ConstructL(aContextMessage);
       
   163     contextList = parser->ContextListL();
       
   164     CleanupStack::PopAndDestroy(parser); // parser
       
   165     CleanupStack::PushL(contextList);
       
   166     CCSXHHelpContentBase* contextTopic;
       
   167     TInt numberOfContextList = contextList->Count();
       
   168     TCoeHelpContext* context;
       
   169     for (TInt i(0); i < numberOfContextList; i++)
       
   170         {
       
   171         context = &(contextList->At(i));
       
   172         
       
   173         contextTopic = iHTMLContentParser->GetContextTopicL(this, context->iMajor,context->iContext);
       
   174         if(contextTopic)
       
   175             {
       
   176             CleanupStack::PopAndDestroy(contextList);
       
   177             iLastContextTopic = CCSXHContextTopic::NewL(contextTopic);
       
   178             return iLastContextTopic;
       
   179             }
       
   180         }
       
   181 
       
   182     for (TInt i(0); i < numberOfContextList; i++)
       
   183         {
       
   184         context = &(contextList->At(i));
       
   185         
       
   186         contextTopic = iLegacyContentParser->GetContextTopic(*context);
       
   187         if(contextTopic)
       
   188             {
       
   189             CleanupStack::PopAndDestroy(contextList);
       
   190             iLastContextTopic = CCSXHContextTopic::NewL(contextTopic);
       
   191             return iLastContextTopic;
       
   192             }
       
   193         }
       
   194         
       
   195         
       
   196     CleanupStack::PopAndDestroy(contextList);    
       
   197     return NULL;
       
   198     }
       
   199 
       
   200 EXPORT_C void CCSXHHelpDataBase::ClearAllTOC1Contents()
       
   201     {
       
   202     iMainTOC1->ResetChildList();
       
   203     iKywdTOC1->ResetChildList();
       
   204     }
       
   205 
       
   206 CCSXHLegacyContentParser* CCSXHHelpDataBase::GetLegacyParser() 
       
   207     {
       
   208     return iLegacyContentParser;        
       
   209     }
       
   210     
       
   211 CCSXHHTMLContentParser* CCSXHHelpDataBase::GetHtmlParser() 
       
   212     {
       
   213     return iHTMLContentParser;      
       
   214     }
       
   215 
       
   216 void CCSXHHelpDataBase::InsertKeywordL(const TDesC& aKywdName, 
       
   217 	TInt aLegacyKywdIndex, const TUid& aCatUid)
       
   218     {
       
   219     if(!iHTMLContentParser->IsUidCategoryPresent(aCatUid))
       
   220         iKwydBuilder->InsertKeywordL(iKywdTOC1,aKywdName,aLegacyKywdIndex);
       
   221     }
       
   222     
       
   223 void CCSXHHelpDataBase::InsertKeywordL(const TDesC& aKywdName, CCSXHHtmlTOC1* aToc1)
       
   224     {
       
   225     iKwydBuilder->InsertKeywordL(iKywdTOC1,aKywdName,aToc1);
       
   226     }
       
   227 
       
   228 CCSXHKywdTOC1* CCSXHHelpDataBase::InsertKeywordTopicL(CCSXHGenericTOC2* aToc2)
       
   229     {
       
   230     CCSXHKywdTOC1* toc1 = iKywdTOC1->GetSelectedTopic();
       
   231     InsertKeywordTopic(toc1,aToc2);
       
   232     return toc1;
       
   233     }
       
   234     
       
   235 void CCSXHHelpDataBase::InsertKeywordTopic(CCSXHKywdTOC1* aToc1, CCSXHGenericTOC2* aToc2)
       
   236     {
       
   237     aToc1->InsertChild(aToc2);
       
   238     }
       
   239 
       
   240 EXPORT_C TInt CCSXHHelpDataBase::InitGenerateKeywordTOC2ListL(CCSXHKywdTOC1* aTopic)
       
   241     {
       
   242     iKeywordSearchCount = 0;
       
   243     RPointerArray<CCSXHHtmlTOC1>* TOC1HtmlList = aTopic->GetHtmlTOC1List();
       
   244     TInt htmlCount = TOC1HtmlList ? TOC1HtmlList->Count() : 0;
       
   245     TInt legacyCount = iLegacyContentParser->InitGenerateTOC2ListForKeywordSearchL(aTopic);
       
   246     return (htmlCount + legacyCount);
       
   247     }
       
   248     
       
   249 void CCSXHHelpDataBase::GenerateKeywordTOC2ListL(CCSXHKywdTOC1* aTopic)
       
   250     {
       
   251     iHTMLContentParser->GenerateTOC2ListForKeywordSearchL(this,aTopic);
       
   252  	iLegacyContentParser->GenerateTOC2ListForKeywordSearchL(aTopic);
       
   253     }
       
   254     
       
   255 EXPORT_C CCSXHHelpContentBase* CCSXHHelpDataBase::GetHtmlTopicForUrlL(const TDesC& url)
       
   256     {
       
   257     return iHTMLContentParser->GetHtmlTopicForUrlL(url);
       
   258     }
       
   259 void CCSXHHelpDataBase::FillKeywordTopicsL(MCSXHKywdBuilder* aBuilder)
       
   260     {
       
   261     iKwydBuilder = aBuilder;
       
   262     iHTMLContentParser->GenerateKywdTOC1ListL(this);
       
   263     iLegacyContentParser->GenerateKywdTOC1ListL(this);
       
   264     }
       
   265     
       
   266 
       
   267 void CCSXHHelpDataBase::IncrementKeywordSearchCount(TInt aUnits)
       
   268 	{
       
   269 	iKeywordSearchCount += aUnits;
       
   270 	}
       
   271 
       
   272 EXPORT_C TInt CCSXHHelpDataBase::GetKeywordSearchCount()
       
   273 	{
       
   274 	return iKeywordSearchCount;
       
   275 	}
       
   276