|
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: Grant capabilities dialog in SifUi |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <sifuidialoggrantcapabilitiescontent.h> // SifUiDialogGrantCapabilitiesContent |
|
19 #include <QGraphicsLinearLayout> |
|
20 #include <HbLabel> |
|
21 #include <HbPushButton> |
|
22 #include <HbScrollArea> |
|
23 #include <HbAction> |
|
24 #include <HbDialog> |
|
25 #ifdef Q_OS_SYMBIAN |
|
26 #include <s32mem.h> // TMemBuf |
|
27 #endif // Q_OS_SYMBIAN |
|
28 |
|
29 const QString KDetailsTextHtmlBeginList = "<html>%1<ul>"; |
|
30 const QString KDetailsTextHtmlListItem = "<li>%1</li>"; |
|
31 const QString KDetailsTextHtmlEndList = "</ul></html>"; |
|
32 |
|
33 |
|
34 // ---------------------------------------------------------------------------- |
|
35 // SifUiDialogGrantCapabilitiesContent::~SifUiDialogGrantCapabilitiesContent() |
|
36 // ---------------------------------------------------------------------------- |
|
37 // |
|
38 SifUiDialogGrantCapabilitiesContent::SifUiDialogGrantCapabilitiesContent( |
|
39 const QString& applicationName, const QVariant &capabilities, QGraphicsItem *parent) |
|
40 : HbWidget(parent), mCapabilities(), mIsCapabilitiesValid(false) |
|
41 { |
|
42 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical); |
|
43 |
|
44 HbLabel *label = new HbLabel(); |
|
45 //TODO: localized UI string needed |
|
46 //label->setPlainText(hbTrId("txt_").arg(applicationName)); |
|
47 label->setPlainText(tr("Application \"%1\" uses capabilities it is not signed for.") |
|
48 .arg(applicationName)); |
|
49 label->setTextWrapping(Hb::TextWordWrap); |
|
50 layout->addItem(label); |
|
51 layout->addStretch(); |
|
52 |
|
53 //TODO: localized UI string needed |
|
54 //HbPushButton *details = new HbPushButton(hbTrId("txt_")); |
|
55 HbPushButton *details = new HbPushButton(tr("View details")); |
|
56 connect(details, SIGNAL(clicked()), this, SLOT(viewDetails())); |
|
57 layout->addItem(details); |
|
58 layout->addStretch(); |
|
59 |
|
60 HbPushButton *accept = new HbPushButton; |
|
61 //TODO: localized UI string needed |
|
62 //accept->setText(hbTrId("txt_")); |
|
63 accept->setText(tr("I trust the app")); |
|
64 //TODO: localized UI string needed |
|
65 //accept->setAdditionalText(hbTrId("txt_")); |
|
66 accept->setAdditionalText(tr("Grant all permissions")); |
|
67 connect(accept, SIGNAL(clicked()), this, SIGNAL(accepted())); |
|
68 layout->addItem(accept); |
|
69 |
|
70 HbPushButton *deny = new HbPushButton; |
|
71 //TODO: localized UI string needed |
|
72 //deny->setText(hbTrId("txt_")); |
|
73 deny->setText(tr("I do not trust")); |
|
74 //TODO: localized UI string needed |
|
75 //deny->setAdditionalText(hbTrId("txt_")); |
|
76 deny->setAdditionalText(tr("Cancel installation")); |
|
77 connect(deny, SIGNAL(clicked()), this, SIGNAL(rejected())); |
|
78 layout->addItem(deny); |
|
79 |
|
80 setLayout(layout); |
|
81 setCapabilities(capabilities); |
|
82 } |
|
83 |
|
84 // ---------------------------------------------------------------------------- |
|
85 // SifUiDialogGrantCapabilitiesContent::~SifUiDialogGrantCapabilitiesContent() |
|
86 // ---------------------------------------------------------------------------- |
|
87 // |
|
88 SifUiDialogGrantCapabilitiesContent::~SifUiDialogGrantCapabilitiesContent() |
|
89 { |
|
90 } |
|
91 |
|
92 // ---------------------------------------------------------------------------- |
|
93 // SifUiDialogGrantCapabilitiesContent::viewDetails() |
|
94 // ---------------------------------------------------------------------------- |
|
95 // |
|
96 void SifUiDialogGrantCapabilitiesContent::viewDetails() |
|
97 { |
|
98 HbDialog *detailsDialog= new HbDialog(); |
|
99 detailsDialog->setAttribute(Qt::WA_DeleteOnClose, true); |
|
100 detailsDialog->setTimeout(HbPopup::NoTimeout); |
|
101 detailsDialog->setDismissPolicy(HbDialog::NoDismiss); |
|
102 detailsDialog->setModal(true); |
|
103 |
|
104 // TODO: localised UI string needed |
|
105 QString detailsTitle = tr("Permission details"); |
|
106 detailsDialog->setHeadingWidget(new HbLabel(detailsTitle)); |
|
107 |
|
108 HbScrollArea *scrollArea = new HbScrollArea(this); |
|
109 |
|
110 // TODO: localized UI string needed |
|
111 QString detailsText = KDetailsTextHtmlBeginList.arg("The application has requested permissions to:"); |
|
112 QStringListIterator capaIter(mCapabilities); |
|
113 while (capaIter.hasNext()) { |
|
114 detailsText.append(KDetailsTextHtmlListItem.arg(capaIter.next())); |
|
115 } |
|
116 detailsText.append(KDetailsTextHtmlEndList); |
|
117 |
|
118 HbLabel *detailsTextLabel = new HbLabel; |
|
119 detailsTextLabel->setHtml(detailsText); |
|
120 detailsTextLabel->setTextWrapping(Hb::TextWordWrap); |
|
121 |
|
122 scrollArea->setContentWidget(detailsTextLabel); |
|
123 scrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded); |
|
124 detailsDialog->setContentWidget(scrollArea); |
|
125 |
|
126 HbAction *closeAction = new HbAction(hbTrId("txt_common_button_ok")); |
|
127 detailsDialog->addAction(closeAction); |
|
128 |
|
129 detailsDialog->show(); |
|
130 } |
|
131 |
|
132 // ---------------------------------------------------------------------------- |
|
133 // SifUiDialogGrantCapabilitiesContent::setCapabilities() |
|
134 // ---------------------------------------------------------------------------- |
|
135 // |
|
136 void SifUiDialogGrantCapabilitiesContent::setCapabilities(const QVariant &capabilities) |
|
137 { |
|
138 #ifdef Q_OS_SYMBIAN |
|
139 QByteArray byteArray = capabilities.toByteArray(); |
|
140 const TPtrC8 ptr(reinterpret_cast<const TText8*>(byteArray.constData()), byteArray.length()); |
|
141 QT_TRAP_THROWING(setCapabilitiesSymbianL(ptr)); |
|
142 #endif // Q_OS_SYMBIAN |
|
143 |
|
144 if (!mIsCapabilitiesValid) { |
|
145 emit rejected(); |
|
146 } |
|
147 } |
|
148 |
|
149 #ifdef Q_OS_SYMBIAN |
|
150 // ---------------------------------------------------------------------------- |
|
151 // SifUiDialogGrantCapabilitiesContent::setCapabilitiesSymbianL() |
|
152 // ---------------------------------------------------------------------------- |
|
153 // |
|
154 void SifUiDialogGrantCapabilitiesContent::setCapabilitiesSymbianL( const TDesC8& aBuf ) |
|
155 { |
|
156 TMemBuf buf; |
|
157 TUint8* ptr = const_cast<TUint8*>(aBuf.Ptr()); |
|
158 buf.Set(ptr, ptr + aBuf.Size(), MStreamBuf::ERead); |
|
159 RReadStream readStream(&buf); |
|
160 CleanupClosePushL(readStream); |
|
161 TCapabilitySet capabilitySet; |
|
162 TPckg<TCapabilitySet> capabilitySetPackage( capabilitySet ); |
|
163 readStream.ReadL(capabilitySetPackage); |
|
164 CleanupStack::PopAndDestroy(&readStream); |
|
165 |
|
166 mIsCapabilitiesValid = true; |
|
167 for( TInt i = 0; i < ECapability_HardLimit && mIsCapabilitiesValid; i++ ) { |
|
168 const TCapability capability( static_cast<TCapability>(i) ); |
|
169 if( capabilitySet.HasCapability(capability) ) { |
|
170 QT_TRYCATCH_LEAVING( mCapabilities.append(capabilityName(capability)) ); |
|
171 } |
|
172 } |
|
173 } |
|
174 |
|
175 // ---------------------------------------------------------------------------- |
|
176 // SifUiDialogGrantCapabilitiesContent::capabilityName() |
|
177 // ---------------------------------------------------------------------------- |
|
178 // |
|
179 QString SifUiDialogGrantCapabilitiesContent::capabilityName( const TCapability aCapability ) |
|
180 { |
|
181 QString name; |
|
182 |
|
183 switch( aCapability ) { |
|
184 case ECapabilityPowerMgmt: |
|
185 // TODO: is this user-grantable? |
|
186 name = tr("ECapabilityPowerMgmt"); |
|
187 break; |
|
188 case ECapabilityReadDeviceData: |
|
189 // TODO: is this user-grantable? |
|
190 name = tr("ECapabilityReadDeviceData"); |
|
191 break; |
|
192 case ECapabilityWriteDeviceData: |
|
193 // TODO: is this user-grantable? |
|
194 name = tr("ECapabilityWriteDeviceData"); |
|
195 break; |
|
196 case ECapabilityTrustedUI: |
|
197 // TODO: is this user-grantable? |
|
198 name = tr("ECapabilityTrustedUI"); |
|
199 break; |
|
200 case ECapabilityProtServ: |
|
201 // TODO: is this user-grantable? |
|
202 name = tr("ECapabilityProtServ"); |
|
203 break; |
|
204 case ECapabilitySwEvent: |
|
205 // TODO: is this user-grantable? |
|
206 name = tr("ECapabilitySwEvent"); |
|
207 break; |
|
208 case ECapabilityNetworkServices: |
|
209 // TODO: localized UI string needed |
|
210 name = tr("Make network connections or phone calls"); |
|
211 break; |
|
212 case ECapabilityLocalServices: |
|
213 // TODO: localized UI string needed |
|
214 name = tr("Connect using local connectivity"); |
|
215 break; |
|
216 case ECapabilityReadUserData: |
|
217 // TODO: localized UI string needed |
|
218 name = tr("Read user's personal data"); |
|
219 break; |
|
220 case ECapabilityWriteUserData: |
|
221 // TODO: localized UI string needed |
|
222 name = tr("Modify user's personal data"); |
|
223 break; |
|
224 case ECapabilityLocation: |
|
225 // TODO: localized UI string needed |
|
226 name = tr("Access the location information"); |
|
227 break; |
|
228 case ECapabilitySurroundingsDD: |
|
229 // TODO: is this user-grantable? |
|
230 name = tr("ECapabilitySurroundingsDD"); |
|
231 break; |
|
232 case ECapabilityUserEnvironment: |
|
233 // TODO: localized UI string needed |
|
234 name = tr("Access user environment"); |
|
235 break; |
|
236 |
|
237 // Other capabilities are not user-grantable |
|
238 default: |
|
239 mIsCapabilitiesValid = false; |
|
240 break; |
|
241 } |
|
242 |
|
243 return name; |
|
244 } |
|
245 #endif // Q_OS_SYMBIAN |
|
246 |