|
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 "untrustedcertificatewidget.h" |
|
20 #include "untrustedcertificatedefinitions.h" |
|
21 #include "untrustedcertificateinfobase.h" |
|
22 #include <hblabel.h> |
|
23 #include <hbcheckbox.h> |
|
24 #include <hbgroupbox.h> |
|
25 #include <hbtextedit.h> |
|
26 #include <QGraphicsLinearLayout> |
|
27 |
|
28 const int KUnknownError = -5; // KErrNotSupported |
|
29 |
|
30 |
|
31 // ======== MEMBER FUNCTIONS ======== |
|
32 |
|
33 // ---------------------------------------------------------------------------- |
|
34 // UntrustedCertificateWidget::UntrustedCertificateWidget() |
|
35 // ---------------------------------------------------------------------------- |
|
36 // |
|
37 UntrustedCertificateWidget::UntrustedCertificateWidget(QGraphicsItem *parent, |
|
38 Qt::WindowFlags flags) : HbWidget(parent, flags), |
|
39 mMainLayout(0), mProblemDescription(0), mAcceptPermanently(0), |
|
40 mCertificateDetailsGroupBox(0), mCertificateDetailsText(0), |
|
41 mCertificateInfo(0), mServerName(), mValidationError(0), |
|
42 mIsSavingServerNamePossible(true) |
|
43 { |
|
44 } |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // UntrustedCertificateWidget::~UntrustedCertificateWidget() |
|
48 // ---------------------------------------------------------------------------- |
|
49 // |
|
50 UntrustedCertificateWidget::~UntrustedCertificateWidget() |
|
51 { |
|
52 delete mCertificateInfo; |
|
53 } |
|
54 |
|
55 // ---------------------------------------------------------------------------- |
|
56 // UntrustedCertificateWidget::constructFromParameters() |
|
57 // ---------------------------------------------------------------------------- |
|
58 // |
|
59 void UntrustedCertificateWidget::constructFromParameters( |
|
60 const QVariantMap ¶meters) |
|
61 { |
|
62 processParameters(parameters); |
|
63 |
|
64 Q_ASSERT(mMainLayout == 0); |
|
65 mMainLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
66 |
|
67 Q_ASSERT(mProblemDescription == 0); |
|
68 QString text = descriptionText().arg(mServerName); |
|
69 mProblemDescription = new HbLabel(text); |
|
70 mProblemDescription->setTextWrapping(Hb::TextWordWrap); |
|
71 mMainLayout->addItem(mProblemDescription); |
|
72 |
|
73 if (isPermanentAcceptAllowed()) { |
|
74 Q_ASSERT(mAcceptPermanently == 0); |
|
75 // TODO: localised UI string needed |
|
76 mAcceptPermanently = new HbCheckBox(tr("Accept permanently")); |
|
77 mMainLayout->addItem(mAcceptPermanently); |
|
78 } |
|
79 |
|
80 Q_ASSERT(mCertificateDetailsGroupBox == 0); |
|
81 mCertificateDetailsGroupBox = new HbGroupBox; |
|
82 // TODO: localized UI string needed |
|
83 mCertificateDetailsGroupBox->setHeading(tr("Details")); |
|
84 |
|
85 Q_ASSERT(mCertificateDetailsText == 0); |
|
86 mCertificateDetailsText = new HbTextEdit; |
|
87 QString certificateDetails = mCertificateInfo->certificateDetails(mServerName); |
|
88 mCertificateDetailsText->setPlainText(certificateDetails); |
|
89 mCertificateDetailsText->setReadOnly(true); |
|
90 |
|
91 mCertificateDetailsGroupBox->setContentWidget(mCertificateDetailsText); |
|
92 mCertificateDetailsGroupBox->setCollapsed(true); |
|
93 mMainLayout->addItem(mCertificateDetailsGroupBox); |
|
94 |
|
95 setLayout(mMainLayout); |
|
96 } |
|
97 |
|
98 // ---------------------------------------------------------------------------- |
|
99 // UntrustedCertificateWidget::updateFromParameters() |
|
100 // ---------------------------------------------------------------------------- |
|
101 // |
|
102 void UntrustedCertificateWidget::updateFromParameters( |
|
103 const QVariantMap ¶meters) |
|
104 { |
|
105 processParameters(parameters); |
|
106 } |
|
107 |
|
108 // ---------------------------------------------------------------------------- |
|
109 // UntrustedCertificateWidget::isPermanentAcceptAllowed() |
|
110 // ---------------------------------------------------------------------------- |
|
111 // |
|
112 bool UntrustedCertificateWidget::isPermanentAcceptAllowed() const |
|
113 { |
|
114 return (mCertificateInfo->isDateValid() && (mServerName.length() > 0) && |
|
115 mIsSavingServerNamePossible); |
|
116 } |
|
117 |
|
118 // ---------------------------------------------------------------------------- |
|
119 // UntrustedCertificateWidget::isPermanentAcceptChecked() |
|
120 // ---------------------------------------------------------------------------- |
|
121 // |
|
122 bool UntrustedCertificateWidget::isPermanentAcceptChecked() const |
|
123 { |
|
124 if (mAcceptPermanently) { |
|
125 return (mAcceptPermanently->checkState() == Qt::Checked); |
|
126 } |
|
127 return false; |
|
128 } |
|
129 |
|
130 // ---------------------------------------------------------------------------- |
|
131 // UntrustedCertificateWidget::serverName() |
|
132 // ---------------------------------------------------------------------------- |
|
133 // |
|
134 QString UntrustedCertificateWidget::serverName() const |
|
135 { |
|
136 return mServerName; |
|
137 } |
|
138 |
|
139 // ---------------------------------------------------------------------------- |
|
140 // UntrustedCertificateWidget::processParameters() |
|
141 // ---------------------------------------------------------------------------- |
|
142 // |
|
143 void UntrustedCertificateWidget::processParameters(const QVariantMap ¶meters) |
|
144 { |
|
145 mServerName = parameters.value(KUntrustedCertServerName).toString(); |
|
146 |
|
147 bool ok = false; |
|
148 mValidationError = KUnknownError; |
|
149 int value = parameters.value(KUntrustedCertValidationError).toInt(&ok); |
|
150 if (ok) { |
|
151 mValidationError = value; |
|
152 } |
|
153 |
|
154 QByteArray encodedCert = parameters.value(KUntrustedCertEncodedCertificate).toByteArray(); |
|
155 processEncodedCertificate(encodedCert); |
|
156 |
|
157 if (parameters.contains(KUntrustedCertTrustedSiteStoreFail)) { |
|
158 mIsSavingServerNamePossible = false; |
|
159 } |
|
160 } |
|
161 |