userguide/src/HelpContentsView.cpp
branchRCL_3
changeset 45 cbffe13eac63
parent 44 12f60d9a73b3
child 49 a7ccb69868af
equal deleted inserted replaced
44:12f60d9a73b3 45:cbffe13eac63
     1 /*
       
     2 * Copyright (c) 2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QUrl>
       
    19 #include <QProcess>
       
    20 #include <QLatin1String>
       
    21 #include <QDebug>
       
    22 
       
    23 #include <hbaction.h>
       
    24 #include <hbmainwindow.h>
       
    25 #include <hbmenu.h>
       
    26 
       
    27 #include "BrowserWrapper.h"
       
    28 #include "HelpDataProvider.h"
       
    29 #include "HelpUtils.h"
       
    30 #include "HelpContentsView.h"
       
    31 
       
    32 HelpContentsView::HelpContentsView() : mBrowser(NULL)
       
    33 {
       
    34 }
       
    35 
       
    36 HelpContentsView::~HelpContentsView()
       
    37 {
       
    38 }
       
    39 
       
    40 void HelpContentsView::init()
       
    41 {
       
    42 	initDocMl();
       
    43     initBackAction();
       
    44     mBrowser = mBuilder.findWidget<BrowserWrapper*>(DOCML_BROWSER_CONTENTS);
       
    45     mBrowser->init();
       
    46 
       
    47     connect(mBrowser, SIGNAL(linkClicked(const QUrl&)), this, SLOT(onLinkClicked(const QUrl&)));
       
    48     connect(mBrowser, SIGNAL(urlChanged(const QUrl&)), this, SLOT(onUrlChanged(const QUrl&)));
       
    49     connect(mainWindow(), SIGNAL(viewReady()), this, SLOT(onViewReady()));
       
    50 }
       
    51 
       
    52 void HelpContentsView::initDocMl()
       
    53 {
       
    54 	initBaseDocMl();
       
    55     mBuilder.load(QRC_DOCML_CONTENTS);
       
    56 }
       
    57 
       
    58 void HelpContentsView::initBackAction()
       
    59 {
       
    60     mSoftKeyAction = new HbAction(Hb::BackNaviAction  );
       
    61     connect(mSoftKeyAction, SIGNAL(triggered()), this, SLOT(onBackAction()));
       
    62 }
       
    63 
       
    64 ///////////////////////////////////////////////////////////////////////////////////////
       
    65 
       
    66 bool HelpContentsView::openApplication(const QUrl& url)
       
    67 {
       
    68 	QString str = url.toString();
       
    69 	if(str.startsWith(URL_HEADER_APP))
       
    70 	{
       
    71         //app://cmd@localhost/APP_NAME/APP_UID
       
    72         QString appUid = str.section(BACKSLASH, -1,-1);
       
    73         if(appUid.contains("0x", Qt::CaseInsensitive))
       
    74         {
       
    75             appUid.remove(0,2);
       
    76         }
       
    77         int error = HelpUtils::launchApplication(appUid);
       
    78         if(error != 0)
       
    79         {
       
    80             qDebug() << "AIW-ERROR: AppMgrClient:test: Send failed" << error;
       
    81         }
       
    82         return true;
       
    83 	}
       
    84 	
       
    85 	return false;
       
    86 }
       
    87 
       
    88 bool HelpContentsView::openExternalLink(const QUrl& url)
       
    89 {
       
    90 	QString str = url.toString();
       
    91 	if(str.startsWith(URL_HEADER_HTTP) || 
       
    92 	   str.startsWith(URL_HEADER_HTTPS) || 
       
    93 	   str.startsWith(URL_HEADER_FTP))
       
    94 	{
       
    95 		return true;
       
    96 	}
       
    97 	
       
    98     return false;
       
    99 }
       
   100 
       
   101 void HelpContentsView::openHelpContent(const QUrl& url)
       
   102 {
       
   103     QString html;
       
   104     QString urlStr = url.toString();
       
   105     HelpDataProvider::instance()->getHelpContentData(html, urlStr);
       
   106 	mBrowser->setHtml(html, urlStr);
       
   107 }
       
   108 
       
   109 ////////////////////////////////////////////////////////////////////////////////////////////
       
   110 
       
   111 void HelpContentsView::onViewReady()
       
   112 {
       
   113     if(isVisible())
       
   114     {
       
   115         setNavigationAction(mSoftKeyAction);
       
   116         openHelpContent();
       
   117     }
       
   118     else
       
   119     {
       
   120         mBrowser->clearHistory();
       
   121     }    
       
   122 }
       
   123 
       
   124 ///////////////////////////////////////////////////////////////////////////////////////
       
   125 
       
   126 void HelpContentsView::onBackAction()
       
   127 {
       
   128 	if(mBrowser->canGoBack())
       
   129 	{
       
   130 		mBrowser->back();
       
   131 	}
       
   132 	else
       
   133 	{
       
   134 		emit activateView(PreviousView);
       
   135 	}
       
   136 }
       
   137 
       
   138 ///////////////////////////////////////////////////////////////////////////////////////
       
   139 
       
   140 void HelpContentsView::onLinkClicked(const QUrl& url)
       
   141 {
       
   142     // try to open as application
       
   143     if(openApplication(url))
       
   144     {
       
   145         return;
       
   146     }
       
   147 
       
   148     // try to open as remote link
       
   149     if(openExternalLink(url))
       
   150     {
       
   151         return;
       
   152     }
       
   153 
       
   154     // try to open as local link
       
   155     {
       
   156         openHelpContent(url);
       
   157         return;
       
   158     }
       
   159 }
       
   160 
       
   161 void HelpContentsView::onUrlChanged(const QUrl& url)
       
   162 {
       
   163     openHelpContent(url);
       
   164 }
       
   165 
       
   166 
       
   167 // end of file