csxhelp/HelpEngine/src/CSXHHelpDataBase.cpp
changeset 0 1f04cf54edd8
child 5 d06b1526f62c
equal deleted inserted replaced
-1:000000000000 0:1f04cf54edd8
       
     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)
       
    42     {
       
    43     CCSXHHelpDataBase* self = CCSXHHelpDataBase::NewLC(aCoeEnv,aAppCaption);
       
    44     CleanupStack::Pop(self);
       
    45     return self;    
       
    46     }
       
    47 
       
    48 CCSXHHelpDataBase* CCSXHHelpDataBase::NewLC(CCoeEnv* aCoeEnv,const TApaAppCaption& aAppCaption)
       
    49     {
       
    50     //Add stuff into TLS
       
    51     if(Dll::Tls() == NULL )
       
    52         {
       
    53         // TLS is still null, which means that no Singleton has
       
    54         // been instantiated yet. Do so now, and return that
       
    55         // instance:
       
    56         // Store a pointer to the new instance in thread local storage:
       
    57         CCSXHHelpDataBase* self = new(ELeave) CCSXHHelpDataBase(aCoeEnv,aAppCaption);
       
    58         CleanupStack::PushL(self);
       
    59         self->ConstructL();
       
    60      
       
    61         TInt err = Dll::SetTls(self);
       
    62         if(err == KErrNone )
       
    63             {
       
    64             return self;
       
    65             }
       
    66         else
       
    67             {
       
    68             delete self;
       
    69             User::Leave( err );
       
    70             return NULL;
       
    71             }
       
    72         }
       
    73      else
       
    74         {
       
    75             return GetInstance();
       
    76         }   
       
    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)
       
    87              : iCoeEnv(aCoeEnv),iAppCaption(aAppCaption),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     //Build the TOC1 list here
       
   111     iHTMLContentParser->GenerateTOC1ListL(this);
       
   112     iLegacyContentParser->GenerateTOC1ListL(this);
       
   113     }
       
   114     
       
   115 CCoeEnv* CCSXHHelpDataBase::GetCoeEnv()
       
   116     {
       
   117     return iCoeEnv;
       
   118     }
       
   119 
       
   120 EXPORT_C CCSXHGenericTOC1* CCSXHHelpDataBase::GetMainTopics()
       
   121     {
       
   122     return iMainTOC1;   
       
   123     }
       
   124 EXPORT_C CCSXHGenericTOC1* CCSXHHelpDataBase::GetKywdTopics()
       
   125     {
       
   126     return iKywdTOC1;
       
   127     }
       
   128 
       
   129 EXPORT_C CCSXHHelpContentBase* CCSXHHelpDataBase::GetContextTopic(const TDesC8& aContextMessage)
       
   130     {
       
   131     TRAP_IGNORE(GetContextTopicL(aContextMessage));
       
   132     return iLastContextTopic;
       
   133     
       
   134     }
       
   135 CCSXHHelpContentBase* CCSXHHelpDataBase::GetContextTopicL(const TDesC8& aContextMessage)
       
   136     {
       
   137     if(iLastContextTopic)
       
   138         {
       
   139         delete iLastContextTopic;
       
   140         iLastContextTopic = NULL;
       
   141         }
       
   142     //TSW Error Correction:Help: Application crashes 
       
   143     //after trying to re-open context-dependent help from application
       
   144     //Clear childlist of all (TOC1)parents.    
       
   145 	ClearAllTOC1Contents();    
       
   146 	
       
   147     CArrayFix<TCoeHelpContext>* contextList;
       
   148     CCsHlpCmdLineParser* parser = new(ELeave) CCsHlpCmdLineParser;
       
   149     CleanupStack::PushL(parser);
       
   150     parser->ConstructL(aContextMessage);
       
   151     contextList = parser->ContextListL();
       
   152     CleanupStack::PopAndDestroy(parser); // parser
       
   153     CleanupStack::PushL(contextList);
       
   154     CCSXHHelpContentBase* contextTopic;
       
   155     TInt numberOfContextList = contextList->Count();
       
   156     TCoeHelpContext* context;
       
   157     for (TInt i(0); i < numberOfContextList; i++)
       
   158         {
       
   159         context = &(contextList->At(i));
       
   160         
       
   161         contextTopic = iHTMLContentParser->GetContextTopic(context->iMajor,context->iContext);
       
   162         if(contextTopic)
       
   163             {
       
   164             CleanupStack::PopAndDestroy(contextList);
       
   165             iLastContextTopic = CCSXHContextTopic::NewL(contextTopic);
       
   166             return iLastContextTopic;
       
   167             }
       
   168         }
       
   169 
       
   170     for (TInt i(0); i < numberOfContextList; i++)
       
   171         {
       
   172         context = &(contextList->At(i));
       
   173         
       
   174         contextTopic = iLegacyContentParser->GetContextTopic(*context);
       
   175         if(contextTopic)
       
   176             {
       
   177             CleanupStack::PopAndDestroy(contextList);
       
   178             iLastContextTopic = CCSXHContextTopic::NewL(contextTopic);
       
   179             return iLastContextTopic;
       
   180             }
       
   181         }
       
   182         
       
   183         
       
   184     CleanupStack::PopAndDestroy(contextList);    
       
   185     return NULL;
       
   186     }
       
   187 
       
   188 EXPORT_C void CCSXHHelpDataBase::ClearAllTOC1Contents()
       
   189     {
       
   190     iMainTOC1->ResetChildList();
       
   191     iKywdTOC1->ResetChildList();
       
   192     }
       
   193 
       
   194 CCSXHLegacyContentParser* CCSXHHelpDataBase::GetLegacyParser() 
       
   195     {
       
   196     return iLegacyContentParser;        
       
   197     }
       
   198     
       
   199 CCSXHHTMLContentParser* CCSXHHelpDataBase::GetHtmlParser() 
       
   200     {
       
   201     return iHTMLContentParser;      
       
   202     }
       
   203 
       
   204 void CCSXHHelpDataBase::InsertKeywordL(const TDesC& aKywdName, 
       
   205 	TInt aLegacyKywdIndex, const TUid& aCatUid)
       
   206     {
       
   207     if(!iHTMLContentParser->IsUidCategoryPresent(aCatUid))
       
   208         iKwydBuilder->InsertKeywordL(iKywdTOC1,aKywdName,aLegacyKywdIndex);
       
   209     }
       
   210     
       
   211 void CCSXHHelpDataBase::InsertKeywordL(const TDesC& aKywdName, CCSXHHtmlTOC1* aToc1)
       
   212     {
       
   213     iKwydBuilder->InsertKeywordL(iKywdTOC1,aKywdName,aToc1);
       
   214     }
       
   215 
       
   216 CCSXHKywdTOC1* CCSXHHelpDataBase::InsertKeywordTopicL(CCSXHGenericTOC2* aToc2)
       
   217     {
       
   218     CCSXHKywdTOC1* toc1 = iKywdTOC1->GetSelectedTopic();
       
   219     InsertKeywordTopic(toc1,aToc2);
       
   220     return toc1;
       
   221     }
       
   222     
       
   223 void CCSXHHelpDataBase::InsertKeywordTopic(CCSXHKywdTOC1* aToc1, CCSXHGenericTOC2* aToc2)
       
   224     {
       
   225     aToc1->InsertChild(aToc2);
       
   226     }
       
   227 
       
   228 EXPORT_C TInt CCSXHHelpDataBase::InitGenerateKeywordTOC2ListL(CCSXHKywdTOC1* aTopic)
       
   229     {
       
   230     iKeywordSearchCount = 0;
       
   231     RPointerArray<CCSXHHtmlTOC1>* TOC1HtmlList = aTopic->GetHtmlTOC1List();
       
   232     TInt htmlCount = TOC1HtmlList ? TOC1HtmlList->Count() : 0;
       
   233     TInt legacyCount = iLegacyContentParser->InitGenerateTOC2ListForKeywordSearchL(aTopic);
       
   234     return (htmlCount + legacyCount);
       
   235     }
       
   236     
       
   237 void CCSXHHelpDataBase::GenerateKeywordTOC2ListL(CCSXHKywdTOC1* aTopic)
       
   238     {
       
   239     iHTMLContentParser->GenerateTOC2ListForKeywordSearchL(this,aTopic);
       
   240  	iLegacyContentParser->GenerateTOC2ListForKeywordSearchL(aTopic);
       
   241     }
       
   242     
       
   243 EXPORT_C CCSXHHelpContentBase* CCSXHHelpDataBase::GetHtmlTopicForUrlL(const TDesC& url)
       
   244     {
       
   245     return iHTMLContentParser->GetHtmlTopicForUrlL(url);
       
   246     }
       
   247 void CCSXHHelpDataBase::FillKeywordTopicsL(MCSXHKywdBuilder* aBuilder)
       
   248     {
       
   249     iKwydBuilder = aBuilder;
       
   250     iHTMLContentParser->GenerateKywdTOC1ListL(this);
       
   251     iLegacyContentParser->GenerateKywdTOC1ListL(this);
       
   252     }
       
   253     
       
   254 
       
   255 void CCSXHHelpDataBase::IncrementKeywordSearchCount(TInt aUnits)
       
   256 	{
       
   257 	iKeywordSearchCount += aUnits;
       
   258 	}
       
   259 
       
   260 EXPORT_C TInt CCSXHHelpDataBase::GetKeywordSearchCount()
       
   261 	{
       
   262 	return iKeywordSearchCount;
       
   263 	}
       
   264