|
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 "HelpDocumentLoader.h" |
|
29 #include "HelpDataProvider.h" |
|
30 #include "HelpUtils.h" |
|
31 #include "HelpContentsView.h" |
|
32 |
|
33 HelpContentsView::HelpContentsView() : mBrowser(NULL) |
|
34 { |
|
35 } |
|
36 |
|
37 HelpContentsView::~HelpContentsView() |
|
38 { |
|
39 } |
|
40 |
|
41 void HelpContentsView::init() |
|
42 { |
|
43 initBackAction(); |
|
44 mBrowser = HelpUIBuilder::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(currentViewChanged(HbView*)), this, SLOT(onCurrentViewChanged(HbView*))); |
|
50 } |
|
51 |
|
52 void HelpContentsView::initBackAction() |
|
53 { |
|
54 mSoftKeyAction = new HbAction(Hb::BackAction); |
|
55 connect(mSoftKeyAction, SIGNAL(triggered()), this, SLOT(onBackAction())); |
|
56 } |
|
57 |
|
58 /////////////////////////////////////////////////////////////////////////////////////// |
|
59 |
|
60 bool HelpContentsView::openApplication(const QUrl& url) |
|
61 { |
|
62 QString str = url.toString(); |
|
63 if(str.startsWith(URL_HEADER_APP)) |
|
64 { |
|
65 //app://cmd@localhost/APP_NAME/APP_UID |
|
66 QString appUid = str.section(BACKSLASH, -1,-1); |
|
67 if(appUid.contains("0x", Qt::CaseInsensitive)) |
|
68 { |
|
69 appUid.remove(0,2); |
|
70 } |
|
71 int error = HelpUtils::launchApplication(appUid); |
|
72 if(error != 0) |
|
73 { |
|
74 qDebug() << "AIW-ERROR: AppMgrClient:test: Send failed" << error; |
|
75 } |
|
76 return true; |
|
77 } |
|
78 |
|
79 return false; |
|
80 } |
|
81 |
|
82 bool HelpContentsView::openExternalLink(const QUrl& url) |
|
83 { |
|
84 QString str = url.toString(); |
|
85 if(str.startsWith(URL_HEADER_HTTP) || |
|
86 str.startsWith(URL_HEADER_HTTPS) || |
|
87 str.startsWith(URL_HEADER_FTP)) |
|
88 { |
|
89 return true; |
|
90 } |
|
91 |
|
92 return false; |
|
93 } |
|
94 |
|
95 void HelpContentsView::openHelpContent(const QUrl& url) |
|
96 { |
|
97 QString html; |
|
98 QString baseUrl = url.toString(); |
|
99 HelpDataProvider::instance()->getHelpContentData(html, baseUrl); |
|
100 mBrowser->setHtml(html, baseUrl); |
|
101 } |
|
102 |
|
103 //////////////////////////////////////////////////////////////////////////////////////////// |
|
104 |
|
105 void HelpContentsView::onCurrentViewChanged(HbView *view) |
|
106 { |
|
107 if(this == view) |
|
108 { |
|
109 setNavigationAction(mSoftKeyAction); |
|
110 openHelpContent(); |
|
111 } |
|
112 else |
|
113 { |
|
114 mBrowser->clearHistory(); |
|
115 } |
|
116 } |
|
117 |
|
118 /////////////////////////////////////////////////////////////////////////////////////// |
|
119 |
|
120 void HelpContentsView::onBackAction() |
|
121 { |
|
122 if(this == mainWindow()->currentView()) |
|
123 { |
|
124 if(mBrowser->canGoBack()) |
|
125 { |
|
126 mBrowser->back(); |
|
127 } |
|
128 else |
|
129 { |
|
130 emit activateView(HelpViewCategory); |
|
131 } |
|
132 } |
|
133 } |
|
134 |
|
135 /////////////////////////////////////////////////////////////////////////////////////// |
|
136 |
|
137 void HelpContentsView::onLinkClicked(const QUrl& url) |
|
138 { |
|
139 // try to open as application |
|
140 if(openApplication(url)) |
|
141 { |
|
142 return; |
|
143 } |
|
144 |
|
145 // try to open as remote link |
|
146 if(openExternalLink(url)) |
|
147 { |
|
148 return; |
|
149 } |
|
150 |
|
151 // try to open as local link |
|
152 { |
|
153 openHelpContent(url); |
|
154 return; |
|
155 } |
|
156 } |
|
157 |
|
158 void HelpContentsView::onUrlChanged(const QUrl& url) |
|
159 { |
|
160 openHelpContent(url); |
|
161 } |
|
162 |
|
163 |
|
164 // end of file |