csxhelp/HelpEngine/src/CSXHLegacyContentParser.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:  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::NewL(appName);
       
   113         if(aDataBase->GetMainTopics()->InsertChild(CategoryObj))
       
   114                 iLegacyTOC1List.Append(CategoryObj);//Keep a local copy*/       
       
   115         }
       
   116     CleanupStack::Pop(categoryList);            
       
   117     delete categoryList;
       
   118     }
       
   119 // --------------------------------------------------------------------------
       
   120 // Gets the available TOC2 objects for the TOC1 object
       
   121 // --------------------------------------------------------------------------    
       
   122 void CCSXHLegacyContentParser::GenerateTOC2ListL(CCSXHGenericTOC1& aGenericTOC1Object,
       
   123                                  RPointerArray<CCSXHHelpContentBase>* GenericTOC2List)
       
   124     {
       
   125     iModel->SearchL(ETopicListForCategory, aGenericTOC1Object.GetName());
       
   126     if(iHlpList)
       
   127         {
       
   128         delete iHlpList;
       
   129         //Next line is Needed for code scanner
       
   130         iHlpList = NULL;
       
   131         }
       
   132     iHlpList = CHlpList::NewL();
       
   133     iModel->LoadListL(iHlpList);
       
   134     
       
   135     TInt count(iHlpList->MdcaCount());
       
   136     CCSXHGenericTOC2* PLegacyTOC2;
       
   137     TLinearOrder<CCSXHHelpContentBase> anOrder(Orderer<CCSXHHelpContentBase>); 
       
   138     for (TInt i(0); i < count; i++)
       
   139         {    
       
   140         PLegacyTOC2 = CCSXHLegacyTOC2::NewL(&aGenericTOC1Object,iHlpList->MdcaPoint(i));
       
   141         if (KErrNone != GenericTOC2List->InsertInOrder(PLegacyTOC2,anOrder))
       
   142             delete PLegacyTOC2;
       
   143         }        
       
   144     }       
       
   145 // --------------------------------------------------------------------------
       
   146 // Gets the RTF content for the given topic
       
   147 // --------------------------------------------------------------------------    
       
   148 TAny* CCSXHLegacyContentParser::GetTopicContentL(CCSXHGenericTOC2* aTopic)
       
   149     {
       
   150     TInt nCount(iHlpList->MdcaCount());
       
   151     TInt nIndex(0);
       
   152     for(nIndex=0;nIndex < nCount; nIndex++)
       
   153         {
       
   154         TBuf<KMaxFileName> appName; 
       
   155         appName.Append(iHlpList->MdcaPoint(nIndex));
       
   156         if(appName.Compare(aTopic->GetName())==0)
       
   157             break;
       
   158         }
       
   159     if(iTopic)
       
   160         {
       
   161         delete iTopic;
       
   162         //Next line is Needed for code scanner
       
   163         iTopic = NULL;
       
   164         }
       
   165     iTopic = CHlpTopic::NewL();
       
   166     CHlpItem* item = iHlpList->Item(nIndex); 
       
   167     iModel->TopicSearchL(*item);    
       
   168     iModel->LoadTopicL(iTopic);    
       
   169     return iTopic->TopicText();    
       
   170     }
       
   171 
       
   172 void CCSXHLegacyContentParser::HandleModelEventL(TInt aEvent)
       
   173     {
       
   174     iStatus = aEvent;   
       
   175     }
       
   176 
       
   177 // --------------------------------------------------------------------------
       
   178 // Gets the number of kywd subtopics for the given kywd
       
   179 // --------------------------------------------------------------------------    
       
   180 TInt CCSXHLegacyContentParser::InitGenerateTOC2ListForKeywordSearchL(CCSXHKywdTOC1* aKywdTOC1Object)
       
   181     {
       
   182     if(aKywdTOC1Object->LegacyIndex() == -1 || (!iLegacyTOC1List.Count()))      
       
   183         return 0;
       
   184     CHlpList* SearchList; 
       
   185     
       
   186     if(iHlpList)
       
   187         {
       
   188         delete iHlpList;
       
   189         //Next line is Needed for code scanner
       
   190         iHlpList = NULL;
       
   191         }
       
   192     iHlpList = CHlpList::NewL();
       
   193     SearchList = CHlpList::NewLC();
       
   194     iModel->SearchL(EIndexList);
       
   195     iModel->LoadListL(SearchList);  
       
   196     //Search Panel    
       
   197     CHlpItem* item = SearchList->Item(aKywdTOC1Object->LegacyIndex());
       
   198     iModel->IndexSearchL(*item);    
       
   199     iModel->LoadListL(iHlpList);        
       
   200     
       
   201     CleanupStack::PopAndDestroy(SearchList);
       
   202     return iHlpList->MdcaCount();
       
   203     }
       
   204     
       
   205     
       
   206 // --------------------------------------------------------------------------
       
   207 // Gets the available kywd subtopics for the given kywd
       
   208 // --------------------------------------------------------------------------    
       
   209 void CCSXHLegacyContentParser::GenerateTOC2ListForKeywordSearchL(CCSXHKywdTOC1* aKywdTOC1Object)
       
   210     {
       
   211     if(aKywdTOC1Object->LegacyIndex() == -1 || (!iLegacyTOC1List.Count()))      
       
   212         return;
       
   213     
       
   214     TInt nCount(iHlpList->MdcaCount());
       
   215     CCSXHGenericTOC2* PLegacyTOC2;
       
   216     TLinearOrder<CCSXHGenericTOC2> anOrder(Orderer<CCSXHGenericTOC2>); 
       
   217     for (TInt i(0); i < nCount; i++)
       
   218         {   
       
   219         PLegacyTOC2 = CCSXHLegacyTOC2::NewL(aKywdTOC1Object,iHlpList->MdcaPoint(i),ETrue);
       
   220         iDataBase->InsertKeywordTopic(aKywdTOC1Object,PLegacyTOC2);
       
   221         iDataBase->IncrementKeywordSearchCount();
       
   222         }    
       
   223   
       
   224     }
       
   225    
       
   226 CCSXHLegacyTOC1* CCSXHLegacyContentParser::GetTOC1ForTOC2(CCSXHLegacyTOC2*)
       
   227     {
       
   228     TInt count = iLegacyTOC1List.Count();
       
   229     CCSXHLegacyTOC1* toc1; 
       
   230     for(TInt i = 0; i<count ; ++i)
       
   231         {
       
   232         toc1 = iLegacyTOC1List[i];
       
   233         if(iTopic->Category().Compare(toc1->GetName())==0)
       
   234             return toc1;
       
   235         }
       
   236     return NULL;    
       
   237     }
       
   238     
       
   239 CCSXHHelpContentBase* CCSXHLegacyContentParser::GetContextTopic(TCoeHelpContext& aContext)
       
   240     {
       
   241         TRAPD(err,LoadContextTopicL(aContext));
       
   242         if(err != KErrNone || NULL == iTopic)
       
   243             return NULL;
       
   244         
       
   245         TInt count = iLegacyTOC1List.Count();
       
   246         CCSXHLegacyTOC1* toc1; 
       
   247         for(TInt i = 0; i<count ; ++i)
       
   248             {
       
   249             toc1 = iLegacyTOC1List[i];
       
   250             if(iTopic->Category().Compare(toc1->GetName())==0)
       
   251                 {
       
   252                 return toc1->GetContextTopic(iTopic->TopicTitle());
       
   253                 }
       
   254             }
       
   255         return NULL;
       
   256     }
       
   257 
       
   258 void CCSXHLegacyContentParser::LoadContextTopicL(TCoeHelpContext& aContext)
       
   259     {
       
   260     if(iTopic)
       
   261         {
       
   262         delete iTopic;
       
   263         //Next line is Needed for code scanner
       
   264         iTopic = NULL;
       
   265         }
       
   266     
       
   267     iModel->ContextSearchL(aContext);
       
   268     if(ETopicAvailable == iStatus )
       
   269         {
       
   270         iTopic = CHlpTopic::NewL();
       
   271         iModel->LoadTopicL(iTopic);     
       
   272         }
       
   273     }