csxhelp/HelpEngine/src/CSXHHelpDataBase.cpp
changeset 0 1f04cf54edd8
child 5 d06b1526f62c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/csxhelp/HelpEngine/src/CSXHHelpDataBase.cpp	Tue Jan 26 15:15:23 2010 +0200
@@ -0,0 +1,264 @@
+/*
+* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  CCSXHHelpDataBase class definition
+*
+*/
+
+#include "CSXHHelpDataBase.h"
+#include "CSXHHTMLContentParser.h"
+#include "CSXHLegacyContentParser.h"
+#include "CSXHViewIDs.h"
+#include "CSXHGenericTOC2.h"
+#include "CSXHKywdTOC1.h"
+#include "CSXHMainTopics.h"
+#include "CSXHKywdTopics.h"
+#include "CsHelpCmdLineParser.h"
+#include "CSXHContextTopic.h"
+#include "coehelp.h" 
+
+#include <eikprogi.h>
+#include <utf.h>
+#include <bautils.h>
+#include <data_caging_path_literals.hrh>
+#include <eikenv.h> 
+#include <eikprogi.h>
+
+
+#include <AknProgressDialog.h>
+
+EXPORT_C CCSXHHelpDataBase* CCSXHHelpDataBase::NewL(CCoeEnv* aCoeEnv,
+	const TApaAppCaption& aAppCaption)
+    {
+    CCSXHHelpDataBase* self = CCSXHHelpDataBase::NewLC(aCoeEnv,aAppCaption);
+    CleanupStack::Pop(self);
+    return self;    
+    }
+
+CCSXHHelpDataBase* CCSXHHelpDataBase::NewLC(CCoeEnv* aCoeEnv,const TApaAppCaption& aAppCaption)
+    {
+    //Add stuff into TLS
+    if(Dll::Tls() == NULL )
+        {
+        // TLS is still null, which means that no Singleton has
+        // been instantiated yet. Do so now, and return that
+        // instance:
+        // Store a pointer to the new instance in thread local storage:
+        CCSXHHelpDataBase* self = new(ELeave) CCSXHHelpDataBase(aCoeEnv,aAppCaption);
+        CleanupStack::PushL(self);
+        self->ConstructL();
+     
+        TInt err = Dll::SetTls(self);
+        if(err == KErrNone )
+            {
+            return self;
+            }
+        else
+            {
+            delete self;
+            User::Leave( err );
+            return NULL;
+            }
+        }
+     else
+        {
+            return GetInstance();
+        }   
+    }
+    
+CCSXHHelpDataBase* CCSXHHelpDataBase::GetInstance()
+    {
+    // Singleton has been instantiated once already, so return
+    // that instance:
+    return static_cast<CCSXHHelpDataBase*>(Dll::Tls());
+    }
+
+CCSXHHelpDataBase::CCSXHHelpDataBase(CCoeEnv* aCoeEnv,const TApaAppCaption& aAppCaption)
+             : iCoeEnv(aCoeEnv),iAppCaption(aAppCaption),iKeywordSearchCount(0)
+             
+    {
+    }
+
+CCSXHHelpDataBase::~CCSXHHelpDataBase()
+    {
+    delete iMainTOC1;
+    delete iKywdTOC1;
+    delete iLastContextTopic;   
+    delete iHTMLContentParser;
+    delete iLegacyContentParser;
+    Dll::SetTls( NULL );
+    }
+
+void CCSXHHelpDataBase::ConstructL()
+    {
+    iHTMLContentParser = CCSXHHTMLContentParser::NewL(iCoeEnv);
+    iLegacyContentParser = CCSXHLegacyContentParser::NewL(this);
+    
+    iMainTOC1 = CCSXHMainTopics::NewL(KCSXHToc1ViewID,iAppCaption);
+    iKywdTOC1 = CCSXHKywdTopics::NewL(iAppCaption);
+        
+    //Build the TOC1 list here
+    iHTMLContentParser->GenerateTOC1ListL(this);
+    iLegacyContentParser->GenerateTOC1ListL(this);
+    }
+    
+CCoeEnv* CCSXHHelpDataBase::GetCoeEnv()
+    {
+    return iCoeEnv;
+    }
+
+EXPORT_C CCSXHGenericTOC1* CCSXHHelpDataBase::GetMainTopics()
+    {
+    return iMainTOC1;   
+    }
+EXPORT_C CCSXHGenericTOC1* CCSXHHelpDataBase::GetKywdTopics()
+    {
+    return iKywdTOC1;
+    }
+
+EXPORT_C CCSXHHelpContentBase* CCSXHHelpDataBase::GetContextTopic(const TDesC8& aContextMessage)
+    {
+    TRAP_IGNORE(GetContextTopicL(aContextMessage));
+    return iLastContextTopic;
+    
+    }
+CCSXHHelpContentBase* CCSXHHelpDataBase::GetContextTopicL(const TDesC8& aContextMessage)
+    {
+    if(iLastContextTopic)
+        {
+        delete iLastContextTopic;
+        iLastContextTopic = NULL;
+        }
+    //TSW Error Correction:Help: Application crashes 
+    //after trying to re-open context-dependent help from application
+    //Clear childlist of all (TOC1)parents.    
+	ClearAllTOC1Contents();    
+	
+    CArrayFix<TCoeHelpContext>* contextList;
+    CCsHlpCmdLineParser* parser = new(ELeave) CCsHlpCmdLineParser;
+    CleanupStack::PushL(parser);
+    parser->ConstructL(aContextMessage);
+    contextList = parser->ContextListL();
+    CleanupStack::PopAndDestroy(parser); // parser
+    CleanupStack::PushL(contextList);
+    CCSXHHelpContentBase* contextTopic;
+    TInt numberOfContextList = contextList->Count();
+    TCoeHelpContext* context;
+    for (TInt i(0); i < numberOfContextList; i++)
+        {
+        context = &(contextList->At(i));
+        
+        contextTopic = iHTMLContentParser->GetContextTopic(context->iMajor,context->iContext);
+        if(contextTopic)
+            {
+            CleanupStack::PopAndDestroy(contextList);
+            iLastContextTopic = CCSXHContextTopic::NewL(contextTopic);
+            return iLastContextTopic;
+            }
+        }
+
+    for (TInt i(0); i < numberOfContextList; i++)
+        {
+        context = &(contextList->At(i));
+        
+        contextTopic = iLegacyContentParser->GetContextTopic(*context);
+        if(contextTopic)
+            {
+            CleanupStack::PopAndDestroy(contextList);
+            iLastContextTopic = CCSXHContextTopic::NewL(contextTopic);
+            return iLastContextTopic;
+            }
+        }
+        
+        
+    CleanupStack::PopAndDestroy(contextList);    
+    return NULL;
+    }
+
+EXPORT_C void CCSXHHelpDataBase::ClearAllTOC1Contents()
+    {
+    iMainTOC1->ResetChildList();
+    iKywdTOC1->ResetChildList();
+    }
+
+CCSXHLegacyContentParser* CCSXHHelpDataBase::GetLegacyParser() 
+    {
+    return iLegacyContentParser;        
+    }
+    
+CCSXHHTMLContentParser* CCSXHHelpDataBase::GetHtmlParser() 
+    {
+    return iHTMLContentParser;      
+    }
+
+void CCSXHHelpDataBase::InsertKeywordL(const TDesC& aKywdName, 
+	TInt aLegacyKywdIndex, const TUid& aCatUid)
+    {
+    if(!iHTMLContentParser->IsUidCategoryPresent(aCatUid))
+        iKwydBuilder->InsertKeywordL(iKywdTOC1,aKywdName,aLegacyKywdIndex);
+    }
+    
+void CCSXHHelpDataBase::InsertKeywordL(const TDesC& aKywdName, CCSXHHtmlTOC1* aToc1)
+    {
+    iKwydBuilder->InsertKeywordL(iKywdTOC1,aKywdName,aToc1);
+    }
+
+CCSXHKywdTOC1* CCSXHHelpDataBase::InsertKeywordTopicL(CCSXHGenericTOC2* aToc2)
+    {
+    CCSXHKywdTOC1* toc1 = iKywdTOC1->GetSelectedTopic();
+    InsertKeywordTopic(toc1,aToc2);
+    return toc1;
+    }
+    
+void CCSXHHelpDataBase::InsertKeywordTopic(CCSXHKywdTOC1* aToc1, CCSXHGenericTOC2* aToc2)
+    {
+    aToc1->InsertChild(aToc2);
+    }
+
+EXPORT_C TInt CCSXHHelpDataBase::InitGenerateKeywordTOC2ListL(CCSXHKywdTOC1* aTopic)
+    {
+    iKeywordSearchCount = 0;
+    RPointerArray<CCSXHHtmlTOC1>* TOC1HtmlList = aTopic->GetHtmlTOC1List();
+    TInt htmlCount = TOC1HtmlList ? TOC1HtmlList->Count() : 0;
+    TInt legacyCount = iLegacyContentParser->InitGenerateTOC2ListForKeywordSearchL(aTopic);
+    return (htmlCount + legacyCount);
+    }
+    
+void CCSXHHelpDataBase::GenerateKeywordTOC2ListL(CCSXHKywdTOC1* aTopic)
+    {
+    iHTMLContentParser->GenerateTOC2ListForKeywordSearchL(this,aTopic);
+ 	iLegacyContentParser->GenerateTOC2ListForKeywordSearchL(aTopic);
+    }
+    
+EXPORT_C CCSXHHelpContentBase* CCSXHHelpDataBase::GetHtmlTopicForUrlL(const TDesC& url)
+    {
+    return iHTMLContentParser->GetHtmlTopicForUrlL(url);
+    }
+void CCSXHHelpDataBase::FillKeywordTopicsL(MCSXHKywdBuilder* aBuilder)
+    {
+    iKwydBuilder = aBuilder;
+    iHTMLContentParser->GenerateKywdTOC1ListL(this);
+    iLegacyContentParser->GenerateKywdTOC1ListL(this);
+    }
+    
+
+void CCSXHHelpDataBase::IncrementKeywordSearchCount(TInt aUnits)
+	{
+	iKeywordSearchCount += aUnits;
+	}
+
+EXPORT_C TInt CCSXHHelpDataBase::GetKeywordSearchCount()
+	{
+	return iKeywordSearchCount;
+	}
+