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