|
1 /* |
|
2 * Copyright (c) 2010 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: Device dialog plugin that shows untrusted certificate |
|
15 * dialog for TLS server authentication failure errors. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "untrustedcertificatedialog.h" |
|
20 #include "untrustedcertificatedefinitions.h" |
|
21 #include "untrustedcertificatewidget.h" |
|
22 #include <hblabel.h> |
|
23 #include <hbaction.h> |
|
24 |
|
25 const int KNoError = 0; // KErrNone |
|
26 const int KParameterError = -6; // KErrArgument |
|
27 |
|
28 |
|
29 // ---------------------------------------------------------------------------- |
|
30 // UntrustedCertificateDialog::UntrustedCertificateDialog() |
|
31 // ---------------------------------------------------------------------------- |
|
32 // |
|
33 UntrustedCertificateDialog::UntrustedCertificateDialog(const QVariantMap ¶meters) : HbDialog(), |
|
34 mLastError(KNoError), mShowEventReceived(false), mContent(0) |
|
35 { |
|
36 constructDialog(parameters); |
|
37 } |
|
38 |
|
39 // ---------------------------------------------------------------------------- |
|
40 // UntrustedCertificateDialog::~UntrustedCertificateDialog() |
|
41 // ---------------------------------------------------------------------------- |
|
42 // |
|
43 UntrustedCertificateDialog::~UntrustedCertificateDialog() |
|
44 { |
|
45 } |
|
46 |
|
47 // ---------------------------------------------------------------------------- |
|
48 // UntrustedCertificateDialog::setDeviceDialogParameters() |
|
49 // ---------------------------------------------------------------------------- |
|
50 // |
|
51 bool UntrustedCertificateDialog::setDeviceDialogParameters(const QVariantMap ¶meters) |
|
52 { |
|
53 return updateFromParameters(parameters); |
|
54 } |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // UntrustedCertificateDialog::deviceDialogError() |
|
58 // ---------------------------------------------------------------------------- |
|
59 // |
|
60 int UntrustedCertificateDialog::deviceDialogError() const |
|
61 { |
|
62 return mLastError; |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------------------------------- |
|
66 // UntrustedCertificateDialog::closeDeviceDialog() |
|
67 // ---------------------------------------------------------------------------- |
|
68 // |
|
69 void UntrustedCertificateDialog::closeDeviceDialog(bool byClient) |
|
70 { |
|
71 Q_UNUSED(byClient); |
|
72 close(); |
|
73 |
|
74 // If show event has been received, close is signalled from hide event. |
|
75 // If not, hide event does not come and close is signalled from here. |
|
76 if (!mShowEventReceived) { |
|
77 emit deviceDialogClosed(); |
|
78 } |
|
79 } |
|
80 |
|
81 // ---------------------------------------------------------------------------- |
|
82 // UntrustedCertificateDialog::deviceDialogWidget() |
|
83 // ---------------------------------------------------------------------------- |
|
84 // |
|
85 HbDialog *UntrustedCertificateDialog::deviceDialogWidget() const |
|
86 { |
|
87 return const_cast<UntrustedCertificateDialog*>(this); |
|
88 } |
|
89 |
|
90 // ---------------------------------------------------------------------------- |
|
91 // UntrustedCertificateDialog::hideEvent() |
|
92 // ---------------------------------------------------------------------------- |
|
93 // |
|
94 void UntrustedCertificateDialog::hideEvent(QHideEvent *event) |
|
95 { |
|
96 HbDialog::hideEvent(event); |
|
97 emit deviceDialogClosed(); |
|
98 } |
|
99 |
|
100 // ---------------------------------------------------------------------------- |
|
101 // UntrustedCertificateDialog::showEvent() |
|
102 // ---------------------------------------------------------------------------- |
|
103 // |
|
104 void UntrustedCertificateDialog::showEvent(QShowEvent *event) |
|
105 { |
|
106 HbDialog::showEvent(event); |
|
107 mShowEventReceived = true; |
|
108 } |
|
109 |
|
110 // ---------------------------------------------------------------------------- |
|
111 // UntrustedCertificateDialog::isParametersValid() |
|
112 // ---------------------------------------------------------------------------- |
|
113 // |
|
114 bool UntrustedCertificateDialog::isParametersValid(const QVariantMap ¶meters) |
|
115 { |
|
116 if (parameters.contains(KUntrustedCertEncodedCertificate) && |
|
117 parameters.contains(KUntrustedCertServerName) && |
|
118 parameters.contains(KUntrustedCertValidationError)) { |
|
119 return true; |
|
120 } |
|
121 mLastError = KParameterError; |
|
122 return false; |
|
123 } |
|
124 |
|
125 // ---------------------------------------------------------------------------- |
|
126 // UntrustedCertificateDialog::constructDialog() |
|
127 // ---------------------------------------------------------------------------- |
|
128 // |
|
129 bool UntrustedCertificateDialog::constructDialog(const QVariantMap ¶meters) |
|
130 { |
|
131 if (!isParametersValid(parameters)) { |
|
132 return false; |
|
133 } |
|
134 |
|
135 setTimeout(HbPopup::NoTimeout); |
|
136 setDismissPolicy(HbPopup::NoDismiss); |
|
137 setModal(true); |
|
138 |
|
139 //: Title text in untrusted certificate dialog. User is opening secure |
|
140 //: connection to site or service, which authenticity cannot be proved, |
|
141 //: or there are other problems in the site certificate. User needs to |
|
142 //: decide if she/he accepts the risk and opens the secure connection |
|
143 //: anyway, or if the connection is rejected. |
|
144 //TODO: localised UI string |
|
145 //QString titleText = hbTrId(""); |
|
146 QString titleText = tr("Untrusted certificate"); |
|
147 setHeadingWidget(new HbLabel(titleText, this)); |
|
148 |
|
149 Q_ASSERT(mContent == 0); |
|
150 mContent = new UntrustedCertificateWidget(this); |
|
151 mContent->constructFromParameters(parameters); |
|
152 setContentWidget(mContent); |
|
153 |
|
154 if (mContent->isCertificateValid()) { |
|
155 HbAction *okAction = new HbAction(qtTrId("txt_common_button_ok"), this); |
|
156 connect(okAction, SIGNAL(triggered()), this, SLOT(handleAccepted())); |
|
157 addAction(okAction); |
|
158 |
|
159 HbAction *cancelAction = new HbAction(qtTrId("txt_common_button_cancel"), this); |
|
160 connect(cancelAction, SIGNAL(triggered()), this, SLOT(handleRejected())); |
|
161 addAction(cancelAction); |
|
162 } else { |
|
163 HbAction *closeAction = new HbAction(qtTrId("txt_common_button_close"), this); |
|
164 connect(closeAction, SIGNAL(triggered()), this, SLOT(handleRejected())); |
|
165 addAction(closeAction); |
|
166 } |
|
167 |
|
168 return true; |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // UntrustedCertificateDialog::updateFromParameters() |
|
173 // ---------------------------------------------------------------------------- |
|
174 // |
|
175 bool UntrustedCertificateDialog::updateFromParameters(const QVariantMap ¶meters) |
|
176 { |
|
177 if (!isParametersValid(parameters)) { |
|
178 return false; |
|
179 } |
|
180 |
|
181 Q_ASSERT(mContent != 0); |
|
182 mContent->updateFromParameters(parameters); |
|
183 return true; |
|
184 } |
|
185 |
|
186 // ---------------------------------------------------------------------------- |
|
187 // UntrustedCertificateDialog::sendResult() |
|
188 // ---------------------------------------------------------------------------- |
|
189 // |
|
190 void UntrustedCertificateDialog::sendResult(int result) |
|
191 { |
|
192 QVariant resultValue(result); |
|
193 mResultMap.insert(KUntrustedCertificateDialogResult, resultValue); |
|
194 emit deviceDialogData(mResultMap); |
|
195 } |
|
196 |
|
197 // ---------------------------------------------------------------------------- |
|
198 // UntrustedCertificateDialog::handleAccepted() |
|
199 // ---------------------------------------------------------------------------- |
|
200 // |
|
201 void UntrustedCertificateDialog::handleAccepted() |
|
202 { |
|
203 if (mContent->isPermanentAcceptChecked()) { |
|
204 sendResult(KDialogAcceptedPermanently); |
|
205 } else { |
|
206 sendResult(KDialogAccepted); |
|
207 } |
|
208 } |
|
209 |
|
210 // ---------------------------------------------------------------------------- |
|
211 // UntrustedCertificateDialog::handleRejected() |
|
212 // ---------------------------------------------------------------------------- |
|
213 // |
|
214 void UntrustedCertificateDialog::handleRejected() |
|
215 { |
|
216 sendResult(KDialogRejected); |
|
217 } |
|
218 |