csxhelp/HelpEngine/src/CSXHLegacyContentParser.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:  CCSXHLegacyContentParser class definition
       
    15 *
       
    16 */
       
    17 
       
    18 #include "CSXHLegacyContentParser.h"
       
    19 #include "CSXHLegacyTOC1.h"
       
    20 #include "CSXHLegacyTOC2.h"
       
    21 #include "CSXHKywdTOC1.h"
       
    22 #include "CSXHHelpDataBase.h"
       
    23 
       
    24 #include <coehelp.h>
       
    25 #include <coemain.h>
       
    26 #include <f32file.h> 
       
    27 #include <badesca.h>
       
    28 #include <txtrich.h>
       
    29 
       
    30 CCSXHLegacyContentParser* CCSXHLegacyContentParser::NewL(CCSXHHelpDataBase
       
    31 *aDataBase)
       
    32     {
       
    33     CCSXHLegacyContentParser* self = CCSXHLegacyContentParser::NewLC(aDataBase);
       
    34     CleanupStack::Pop(self);
       
    35     return self;
       
    36     }
       
    37     
       
    38 CCSXHLegacyContentParser* CCSXHLegacyContentParser::NewLC(CCSXHHelpDataBase
       
    39 *aDataBase)
       
    40     {
       
    41     CCSXHLegacyContentParser* self = new (ELeave) CCSXHLegacyContentParser(aDataBase);
       
    42     CleanupStack::PushL(self);
       
    43     self->ConstructL();
       
    44     return self;
       
    45     }
       
    46     
       
    47 void CCSXHLegacyContentParser::ConstructL()
       
    48     {
       
    49     iModel = CHlpModel::NewL(CCoeEnv::Static()->FsSession(), this);     
       
    50     iModel->OpenL();
       
    51     }
       
    52     
       
    53 CCSXHLegacyContentParser::CCSXHLegacyContentParser(CCSXHHelpDataBase* aDataBase)
       
    54                         :iTopic(NULL)
       
    55     {
       
    56     iDataBase = aDataBase;
       
    57     iHlpList = NULL;
       
    58     }
       
    59     
       
    60 CCSXHLegacyContentParser::~CCSXHLegacyContentParser()
       
    61     {
       
    62     if(iTopic)
       
    63         delete iTopic;
       
    64     if(iHlpList)
       
    65         delete iHlpList;
       
    66     
       
    67     //No need to delete the entries here, it will be done by the database
       
    68     iLegacyTOC1List.Close();    
       
    69     
       
    70     if(iModel)  
       
    71         {
       
    72         TRAP_IGNORE(iModel->CloseL());
       
    73         delete iModel;  
       
    74         }
       
    75     }
       
    76 // --------------------------------------------------------------------------
       
    77 // Gets the available kywds from the legacy content and sends them to the
       
    78 // database
       
    79 // --------------------------------------------------------------------------    
       
    80 void CCSXHLegacyContentParser::GenerateKywdTOC1ListL(CCSXHHelpDataBase* aDataBase)
       
    81     {
       
    82     CHlpList* HlpList; 
       
    83     HlpList = CHlpList::NewL();
       
    84     iModel->SearchL(EIndexList);
       
    85     iModel->LoadListL(HlpList); 
       
    86     
       
    87     TInt nCount(HlpList->MdcaCount());
       
    88     for (TInt i(0); i < nCount; i++)
       
    89         {           
       
    90         TBuf<KMaxFileName> appName;
       
    91         appName = HlpList->MdcaPoint(i);
       
    92         TRAP_IGNORE(aDataBase->InsertKeywordL(appName,i,HlpList->Item(i)->HelpFileUid()));
       
    93         }   
       
    94     delete HlpList;
       
    95     }
       
    96 // --------------------------------------------------------------------------
       
    97 // Gets the available TOC1 from the legacy content and sends them to the
       
    98 // database. Local copy of the TOC1 objects is maintained for generating TOC2
       
    99 // --------------------------------------------------------------------------    
       
   100 void CCSXHLegacyContentParser::GenerateTOC1ListL(CCSXHHelpDataBase* aDataBase)
       
   101     {    
       
   102     const TInt twoColumnFlatArray = 2;
       
   103     CDesCArray* categoryList = new(ELeave) CDesCArrayFlat(twoColumnFlatArray);
       
   104     CleanupStack::PushL(categoryList);
       
   105     iModel->CategoryListL(categoryList);
       
   106     CCSXHLegacyTOC1* categoryObj;
       
   107     TBuf<KMaxFileName> appName;
       
   108     TLinearOrder<CCSXHHelpContentBase> anOrder(Orderer<CCSXHHelpContentBase>);          
       
   109     for (TInt i(0); i < categoryList->Count(); i++)
       
   110         {           
       
   111         appName = categoryList->MdcaPoint(i);                           
       
   112         categoryObj = CCSXHLegacyTOC1::NewLC(appName);
       
   113         if ( aDataBase->GetAppHelpsTopics()->InsertChild(categoryObj) )
       
   114             {
       
   115             iLegacyTOC1List.AppendL(categoryObj);//Keep a local copy*/
       
   116             }
       
   117         CleanupStack::Pop(categoryObj);
       
   118         }
       
   119     CleanupStack::Pop(categoryList);            
       
   120     delete categoryList;
       
   121     }
       
   122 // --------------------------------------------------------------------------
       
   123 // Gets the available TOC2 objects for the TOC1 object
       
   124 // --------------------------------------------------------------------------    
       
   125 void CCSXHLegacyContentParser::GenerateTOC2ListL(CCSXHGenericTOC1& aGenericTOC1Object,
       
   126                                  RPointerArray<CCSXHHelpContentBase>* GenericTOC2List)
       
   127     {
       
   128     iModel->SearchL(ETopicListForCategory, aGenericTOC1Object.GetName());
       
   129     if(iHlpList)
       
   130         {
       
   131         delete iHlpList;
       
   132         //Next line is Needed for code scanner
       
   133         iHlpList = NULL;
       
   134         }
       
   135     iHlpList = CHlpList::NewL();
       
   136     iModel->LoadListL(iHlpList);
       
   137     
       
   138     TInt count(iHlpList->MdcaCount());
       
   139     CCSXHGenericTOC2* PLegacyTOC2;
       
   140     TLinearOrder<CCSXHHelpContentBase> anOrder(Orderer<CCSXHHelpContentBase>); 
       
   141     for (TInt i(0); i < count; i++)
       
   142         {    
       
   143         PLegacyTOC2 = CCSXHLegacyTOC2::NewL(&aGenericTOC1Object,iHlpList->MdcaPoint(i));
       
   144         if (KErrNone != GenericTOC2List->InsertInOrder(PLegacyTOC2,anOrder))
       
   145             delete PLegacyTOC2;
       
   146         }        
       
   147     }       
       
   148 // --------------------------------------------------------------------------
       
   149 // Gets the RTF content for the given topic
       
   150 // --------------------------------------------------------------------------    
       
   151 TAny* CCSXHLegacyContentParser::GetTopicContentL(CCSXHGenericTOC2* aTopic)
       
   152     {
       
   153     TInt nCount(iHlpList->MdcaCount());
       
   154     TInt nIndex(0);
       
   155     for(nIndex=0;nIndex < nCount; nIndex++)
       
   156         {
       
   157         TBuf<KMaxFileName> appName; 
       
   158         appName.Append(iHlpList->MdcaPoint(nIndex));
       
   159         if(appName.Compare(aTopic->GetName())==0)
       
   160             break;
       
   161         }
       
   162     if( nIndex == nCount )
       
   163         {
       
   164         return NULL;
       
   165         }
       
   166     if(iTopic)
       
   167         {
       
   168         delete iTopic;
       
   169         //Next line is Needed for code scanner
       
   170         iTopic = NULL;
       
   171         }
       
   172     iTopic = CHlpTopic::NewL();
       
   173     CHlpItem* item = iHlpList->Item(nIndex); 
       
   174     iModel->TopicSearchL(*item);    
       
   175     iModel->LoadTopicL(iTopic);    
       
   176     return iTopic->TopicText();    
       
   177     }
       
   178 
       
   179 void CCSXHLegacyContentParser::HandleModelEventL(TInt aEvent)
       
   180     {
       
   181     iStatus = aEvent;   
       
   182     }
       
   183 
       
   184 // --------------------------------------------------------------------------
       
   185 // Gets the number of kywd subtopics for the given kywd
       
   186 // --------------------------------------------------------------------------    
       
   187 TInt CCSXHLegacyContentParser::InitGenerateTOC2ListForKeywordSearchL(CCSXHKywdTOC1* aKywdTOC1Object)
       
   188     {
       
   189     if(aKywdTOC1Object->LegacyIndex() == -1 || (!iLegacyTOC1List.Count()))      
       
   190         return 0;
       
   191     CHlpList* SearchList; 
       
   192     
       
   193     if(iHlpList)
       
   194         {
       
   195         delete iHlpList;
       
   196         //Next line is Needed for code scanner
       
   197         iHlpList = NULL;
       
   198         }
       
   199     iHlpList = CHlpList::NewL();
       
   200     SearchList = CHlpList::NewLC();
       
   201     iModel->SearchL(EIndexList);
       
   202     iModel->LoadListL(SearchList);  
       
   203     //Search Panel    
       
   204     CHlpItem* item = SearchList->Item(aKywdTOC1Object->LegacyIndex());
       
   205     iModel->IndexSearchL(*item);    
       
   206     iModel->LoadListL(iHlpList);        
       
   207     
       
   208     CleanupStack::PopAndDestroy(SearchList);
       
   209     return iHlpList->MdcaCount();
       
   210     }
       
   211     
       
   212     
       
   213 // --------------------------------------------------------------------------
       
   214 // Gets the available kywd subtopics for the given kywd
       
   215 // --------------------------------------------------------------------------    
       
   216 void CCSXHLegacyContentParser::GenerateTOC2ListForKeywordSearchL(CCSXHKywdTOC1* aKywdTOC1Object)
       
   217     {
       
   218     if(aKywdTOC1Object->LegacyIndex() == -1 || (!iLegacyTOC1List.Count()))      
       
   219         return;
       
   220     
       
   221     TInt nCount(iHlpList->MdcaCount());
       
   222     CCSXHGenericTOC2* PLegacyTOC2;
       
   223     TLinearOrder<CCSXHGenericTOC2> anOrder(Orderer<CCSXHGenericTOC2>); 
       
   224     for (TInt i(0); i < nCount; i++)
       
   225         {   
       
   226         PLegacyTOC2 = CCSXHLegacyTOC2::NewL(aKywdTOC1Object,iHlpList->MdcaPoint(i),ETrue);
       
   227         iDataBase->InsertKeywordTopic(aKywdTOC1Object,PLegacyTOC2);
       
   228         iDataBase->IncrementKeywordSearchCount();
       
   229         }    
       
   230   
       
   231     }
       
   232    
       
   233 CCSXHLegacyTOC1* CCSXHLegacyContentParser::GetTOC1ForTOC2(CCSXHLegacyTOC2*)
       
   234     {
       
   235     TInt count = iLegacyTOC1List.Count();
       
   236     CCSXHLegacyTOC1* toc1; 
       
   237     for(TInt i = 0; i<count ; ++i)
       
   238         {
       
   239         toc1 = iLegacyTOC1List[i];
       
   240         if(iTopic->Category().Compare(toc1->GetName())==0)
       
   241             return toc1;
       
   242         }
       
   243     return NULL;    
       
   244     }
       
   245     
       
   246 CCSXHHelpContentBase* CCSXHLegacyContentParser::GetContextTopic(TCoeHelpContext& aContext)
       
   247     {
       
   248         TRAPD(err,LoadContextTopicL(aContext));
       
   249         if(err != KErrNone || NULL == iTopic)
       
   250             return NULL;
       
   251         
       
   252         TInt count = iLegacyTOC1List.Count();
       
   253         CCSXHLegacyTOC1* toc1; 
       
   254         for(TInt i = 0; i<count ; ++i)
       
   255             {
       
   256             toc1 = iLegacyTOC1List[i];
       
   257             if(iTopic->Category().Compare(toc1->GetName())==0)
       
   258                 {
       
   259                 return toc1->GetContextTopic(iTopic->TopicTitle());
       
   260                 }
       
   261             }
       
   262         return NULL;
       
   263     }
       
   264 
       
   265 void CCSXHLegacyContentParser::LoadContextTopicL(TCoeHelpContext& aContext)
       
   266     {
       
   267     if(iTopic)
       
   268         {
       
   269         delete iTopic;
       
   270         //Next line is Needed for code scanner
       
   271         iTopic = NULL;
       
   272         }
       
   273     
       
   274     iModel->ContextSearchL(aContext);
       
   275     if(ETopicAvailable == iStatus )
       
   276         {
       
   277         iTopic = CHlpTopic::NewL();
       
   278         iModel->LoadTopicL(iTopic);     
       
   279         }
       
   280     }