92
|
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 |
// conversion
|
|
19 |
#include <XQConversions>
|
|
20 |
// apparc
|
|
21 |
#include <apparc.h>
|
94
|
22 |
#include <apgcli.h>
|
|
23 |
#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
|
|
24 |
#include <apaidpartner.h>
|
|
25 |
#else
|
|
26 |
#include <apaid.h>
|
|
27 |
#endif
|
92
|
28 |
// cfbsbitmap
|
94
|
29 |
#include <apgicnfl.h>
|
92
|
30 |
|
119
|
31 |
#include <rsatsession.h>
|
|
32 |
#include <tsaticoninfo.h>
|
|
33 |
#include <rsatservice.h>// MCL
|
|
34 |
|
|
35 |
#include <e32property.h>
|
|
36 |
#include <bitdev.h>
|
|
37 |
|
|
38 |
#include <AknIconUtils.h>
|
|
39 |
|
|
40 |
|
92
|
41 |
#include <HbIcon>
|
112
|
42 |
|
119
|
43 |
#include "ca2internalCRkeys.h"
|
92
|
44 |
#include "camenuiconutility.h"
|
|
45 |
#include "caentry.h"
|
|
46 |
#include "caquery.h"
|
|
47 |
#include "caservice.h"
|
|
48 |
#include "cadef.h"
|
|
49 |
|
112
|
50 |
const char appUidAttributeName[] = "application:uid";
|
92
|
51 |
|
119
|
52 |
LOCAL_C void getIconFromFile(HbIcon& icon, const QSizeF &size)
|
|
53 |
{
|
|
54 |
if ((icon.iconName().contains(QChar('.')) ||
|
|
55 |
(icon.iconName().contains(QChar('/'))) ||
|
|
56 |
(icon.iconName().contains(QChar('\\'))) )
|
|
57 |
&& !icon.isNull() && icon.size().isValid()) {
|
|
58 |
icon.setSize(size);
|
|
59 |
icon = HbIcon(QIcon(icon.pixmap()));
|
|
60 |
}
|
|
61 |
}
|
|
62 |
|
|
63 |
/*!
|
|
64 |
Convert from bitmap and mask to qpixmap
|
|
65 |
\param input bitmap.
|
|
66 |
\param pixmap to prepare.
|
|
67 |
\retval void.
|
|
68 |
*/
|
|
69 |
LOCAL_C void fromBitmapAndMaskToPixmap(CFbsBitmap* fbsBitmap,
|
|
70 |
CFbsBitmap* fbsMask, QPixmap& pixmap)
|
|
71 |
{
|
|
72 |
pixmap = pixmap.fromSymbianCFbsBitmap(fbsBitmap);
|
|
73 |
QPixmap mask;
|
|
74 |
mask = mask.fromSymbianCFbsBitmap(fbsMask);
|
|
75 |
pixmap.setAlphaChannel(mask);
|
|
76 |
}
|
|
77 |
|
92
|
78 |
/*!
|
|
79 |
Get icon from entry.
|
|
80 |
\param entry const reference to CaEntry.
|
|
81 |
\retval icon.
|
|
82 |
*/
|
112
|
83 |
LOCAL_C HbIcon getIconFromEntry(const CaEntry& entry, const QSizeF &size)
|
92
|
84 |
{
|
|
85 |
HbIcon icon;
|
|
86 |
QString skinId(entry.iconDescription().skinId());
|
|
87 |
if (!skinId.isEmpty()) {
|
|
88 |
icon = HbIcon(skinId);
|
119
|
89 |
getIconFromFile(icon, size);
|
92
|
90 |
}
|
|
91 |
|
|
92 |
if (icon.isNull() || !(icon.size().isValid())) {
|
|
93 |
QString fileName(entry.iconDescription().filename());
|
|
94 |
if (!fileName.isEmpty()) {
|
98
|
95 |
icon = HbIcon(fileName);
|
119
|
96 |
getIconFromFile(icon, size);
|
92
|
97 |
}
|
|
98 |
}
|
|
99 |
return icon;
|
|
100 |
}
|
|
101 |
|
|
102 |
/*!
|
|
103 |
Get icon from apparc.
|
|
104 |
\param entry const reference to CaEntry.
|
|
105 |
\param sie const reference to icon size.
|
|
106 |
\retval icon.
|
|
107 |
*/
|
112
|
108 |
LOCAL_C HbIcon getIconFromApparcL(int uidValue, const QSizeF &size)
|
92
|
109 |
{
|
|
110 |
HbIcon icon;
|
|
111 |
|
|
112 |
RApaLsSession apaLsSession;
|
|
113 |
CleanupClosePushL(apaLsSession);
|
|
114 |
User::LeaveIfError(apaLsSession.Connect());
|
|
115 |
|
106
|
116 |
TUid uid = uid.Uid(uidValue);
|
92
|
117 |
CApaAppServiceInfoArray* skinArray(NULL);
|
106
|
118 |
TRAPD( err, skinArray =
|
|
119 |
apaLsSession.GetAppServiceOpaqueDataLC(uid, TUid::Uid(0x2002DCF3));
|
|
120 |
if (err == KErrNone && skinArray ) {
|
|
121 |
TArray<TApaAppServiceInfo> tmpArray( skinArray->Array() );
|
|
122 |
if ( tmpArray.Count() ) {
|
|
123 |
TPtrC8 opaque(tmpArray[0].OpaqueData());
|
|
124 |
const TPtrC16 iconName((TText16*) opaque.Ptr(),(opaque.Length()+1)>>1);
|
|
125 |
icon = HbIcon( XQConversions:: s60DescToQString( iconName ) );
|
|
126 |
}
|
|
127 |
}
|
|
128 |
CleanupStack::PopAndDestroy(skinArray);
|
|
129 |
);
|
92
|
130 |
|
|
131 |
if (icon.isNull() || !(icon.size().isValid())) {
|
|
132 |
TSize iconSize(size.width(), size.height());
|
|
133 |
CApaMaskedBitmap* apaMaskedBitmap = CApaMaskedBitmap::NewLC();
|
|
134 |
TInt err = apaLsSession.GetAppIcon(uid,iconSize,*apaMaskedBitmap);
|
|
135 |
|
|
136 |
TInt iconsCount(0);
|
|
137 |
apaLsSession.NumberOfOwnDefinedIcons(uid, iconsCount);
|
|
138 |
|
|
139 |
QPixmap pixmap;
|
|
140 |
if ((err == KErrNone) && (iconsCount > 0)) {
|
119
|
141 |
fromBitmapAndMaskToPixmap(apaMaskedBitmap,
|
92
|
142 |
apaMaskedBitmap->Mask(), pixmap);
|
|
143 |
|
112
|
144 |
pixmap = pixmap.scaled(size.toSize(),
|
|
145 |
Qt::KeepAspectRatioByExpanding);
|
92
|
146 |
icon = HbIcon(QIcon(pixmap));
|
|
147 |
} else {
|
99
|
148 |
HBufC* fileNameFromApparc = NULL;
|
92
|
149 |
TInt err2 = apaLsSession.GetAppIcon(uid,fileNameFromApparc);
|
|
150 |
CleanupStack::PushL(fileNameFromApparc);
|
|
151 |
if (err2 == KErrNone) {
|
|
152 |
QString fileName = XQConversions::s60DescToQString(
|
|
153 |
fileNameFromApparc->Des());
|
112
|
154 |
if (fileName.endsWith(QLatin1String(".mif"),
|
|
155 |
Qt::CaseInsensitive) ||
|
|
156 |
fileName.endsWith(QLatin1String(".mbm"),
|
|
157 |
Qt::CaseInsensitive)) {
|
|
158 |
icon = HbIcon(QIcon(fileName));
|
|
159 |
// Icon should be valid.
|
|
160 |
icon.setSize(QSizeF(0.0, 0.0));
|
93
|
161 |
} else {
|
|
162 |
icon = HbIcon(fileName);
|
92
|
163 |
}
|
|
164 |
}
|
99
|
165 |
CleanupStack::PopAndDestroy(fileNameFromApparc);
|
92
|
166 |
}
|
|
167 |
CleanupStack::PopAndDestroy(apaMaskedBitmap);
|
|
168 |
}
|
|
169 |
CleanupStack::PopAndDestroy(&apaLsSession);
|
|
170 |
return icon;
|
|
171 |
}
|
|
172 |
|
|
173 |
/*!
|
|
174 |
Get default icon from theme.
|
|
175 |
\param entry const reference to CaEntry.
|
|
176 |
\retval icon.
|
|
177 |
*/
|
|
178 |
LOCAL_C HbIcon getDefaultIcon(const CaEntry& entry)
|
|
179 |
{
|
|
180 |
HbIcon icon;
|
|
181 |
|
|
182 |
if (entry.entryTypeName() ==
|
|
183 |
XQConversions::s60DescToQString(KCaTypeApp)) {
|
|
184 |
icon = HbIcon("qtg_large_application");
|
|
185 |
} else if (entry.entryTypeName() ==
|
|
186 |
XQConversions::s60DescToQString(KCaTypeFolder) ||
|
|
187 |
entry.entryTypeName() ==
|
|
188 |
XQConversions::s60DescToQString(KCaTypeCollection) ||
|
|
189 |
entry.entryTypeName() ==
|
|
190 |
XQConversions::s60DescToQString(KCaTypeCollectionDownload)) {
|
107
|
191 |
icon = HbIcon("qtg_large_applications_user");
|
92
|
192 |
} else if (entry.entryTypeName() ==
|
|
193 |
XQConversions::s60DescToQString(KCaTypeUrl)) {
|
|
194 |
icon = HbIcon("qtg_large_application");
|
|
195 |
} else if (entry.entryTypeName() ==
|
|
196 |
XQConversions::s60DescToQString(KCaTypeWidget)) {
|
|
197 |
icon = HbIcon("qtg_large_application");
|
|
198 |
} else if (entry.entryTypeName() ==
|
|
199 |
XQConversions::s60DescToQString(KCaTypeTemplatedApp)) {
|
|
200 |
icon = HbIcon("qtg_large_application");
|
|
201 |
} else if (entry.entryTypeName() ==
|
|
202 |
XQConversions::s60DescToQString(KCaTypePackage)) {
|
116
|
203 |
QString type = entry.attribute(XQConversions::s60DescToQString(KCaAttrAppType));
|
|
204 |
if (type ==
|
|
205 |
XQConversions::s60DescToQString(KCaAttrAppTypeValueJava)) {
|
|
206 |
icon = HbIcon("qtg_large_java");
|
|
207 |
} else if (type ==
|
|
208 |
XQConversions::s60DescToQString(KCaAttrAppTypeValueCWRT)) {
|
|
209 |
icon = HbIcon("qtg_large_widget");
|
|
210 |
} else {
|
|
211 |
icon = HbIcon("qtg_large_sisx");
|
|
212 |
}
|
92
|
213 |
}
|
|
214 |
|
|
215 |
return icon;
|
|
216 |
}
|
|
217 |
|
|
218 |
/*!
|
|
219 |
Get entry by uid.
|
|
220 |
\param uid application uid.
|
|
221 |
\retval entry.
|
|
222 |
*/
|
|
223 |
LOCAL_C CaEntry getEntryByUid(int uid)
|
|
224 |
{
|
|
225 |
CaEntry entry;
|
|
226 |
CaQuery query;
|
|
227 |
query.setAttribute(QString("application:uid"), QString::number(uid));
|
|
228 |
QList< QSharedPointer<CaEntry> > entries = CaService::instance()->getEntries(query);
|
|
229 |
if (!entries.isEmpty()) {
|
|
230 |
entry = *(entries.first());
|
|
231 |
}
|
|
232 |
return entry;
|
|
233 |
}
|
|
234 |
|
|
235 |
/*!
|
|
236 |
Get icon when uid is defined.
|
|
237 |
\param entry const reference to CaEntry.
|
|
238 |
\param sie const reference to icon size.
|
|
239 |
\retval icon.
|
|
240 |
*/
|
|
241 |
HbIcon CaMenuIconUtility::getApplicationIcon(int uid,
|
112
|
242 |
const QSizeF &size)
|
92
|
243 |
{
|
|
244 |
HbIcon icon;
|
|
245 |
CaEntry entry;
|
|
246 |
entry = getEntryByUid(uid);
|
|
247 |
icon = getEntryIcon(entry, size);
|
|
248 |
return icon;
|
|
249 |
}
|
|
250 |
|
119
|
251 |
|
|
252 |
#ifdef COVERAGE_MEASUREMENT
|
|
253 |
#pragma CTC SKIP
|
|
254 |
#endif //COVERAGE_MEASUREMENT (Icon can be created only from SIM)
|
|
255 |
/*!
|
|
256 |
Get bitmap.
|
|
257 |
\param aIconEF icon information array
|
|
258 |
\retval bitmap.
|
|
259 |
*/
|
|
260 |
LOCAL_C CFbsBitmap* getSatBitmapL()
|
|
261 |
{
|
|
262 |
RSatSession satSession;
|
|
263 |
CleanupClosePushL(satSession);
|
|
264 |
RSatService satIcon;
|
|
265 |
CleanupClosePushL(satIcon);
|
|
266 |
|
|
267 |
satSession.ConnectL();
|
|
268 |
satIcon.OpenL(satSession);
|
|
269 |
|
|
270 |
|
|
271 |
TInt iconId(KErrNone);
|
|
272 |
RProperty::Get(KCRUidCa, KCaSatUIIconId, iconId);
|
|
273 |
|
|
274 |
CFbsBitmap* bitmap(NULL);
|
|
275 |
|
|
276 |
if (iconId != KErrNone) {
|
|
277 |
RIconEf iconEf;
|
|
278 |
satIcon.GetIconInfoL(TUint8(iconId), iconEf);
|
|
279 |
CleanupClosePushL(iconEf);
|
|
280 |
|
|
281 |
TInt selectedIconIndex(KErrNotFound);
|
|
282 |
TSize selectedIconSize(0, 0);
|
|
283 |
|
|
284 |
for (TInt i = 0; i < iconEf.Count(); ++i) {
|
|
285 |
if ((iconEf[i].IconSize().iHeight * iconEf[i].IconSize().iWidth)
|
|
286 |
>= (selectedIconSize.iHeight * selectedIconSize.iWidth))
|
|
287 |
if (bitmap) {
|
|
288 |
delete bitmap;
|
|
289 |
bitmap = NULL;
|
|
290 |
}
|
|
291 |
// test and select index of icon which is not too big
|
|
292 |
bitmap = satIcon.GetIconL( iconEf[ i ] );
|
|
293 |
if (bitmap) //!bitmap if iIcon is too big
|
|
294 |
{
|
|
295 |
selectedIconSize = iconEf[i].IconSize();
|
|
296 |
selectedIconIndex = i;
|
|
297 |
}
|
|
298 |
}
|
|
299 |
if (selectedIconIndex != KErrNotFound) {
|
|
300 |
if (bitmap) {
|
|
301 |
delete bitmap;
|
|
302 |
bitmap = NULL;
|
|
303 |
}
|
|
304 |
bitmap = satIcon.GetIconL( iconEf[ selectedIconIndex ] );
|
|
305 |
}
|
|
306 |
CleanupStack::PopAndDestroy(&iconEf);
|
|
307 |
}
|
|
308 |
|
|
309 |
CleanupStack::PopAndDestroy(&satIcon);
|
|
310 |
CleanupStack::PopAndDestroy(&satSession);
|
|
311 |
|
|
312 |
return bitmap;
|
|
313 |
}
|
|
314 |
#ifdef COVERAGE_MEASUREMENT
|
|
315 |
#pragma CTC ENDSKIP
|
|
316 |
#endif //COVERAGE_MEASUREMENT
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
#ifdef COVERAGE_MEASUREMENT
|
|
321 |
#pragma CTC SKIP
|
|
322 |
#endif //COVERAGE_MEASUREMENT (Icon can be created only from SIM)
|
|
323 |
/*!
|
|
324 |
Get bitmap.
|
|
325 |
\param aIconEF icon information array
|
|
326 |
\retval bitmap.
|
|
327 |
*/
|
|
328 |
LOCAL_C CFbsBitmap* getSatMaskL(CFbsBitmap* aBitmap)
|
|
329 |
{
|
|
330 |
CFbsBitmap* mask(new (ELeave) CFbsBitmap);
|
|
331 |
CleanupStack::PushL(mask);
|
|
332 |
|
|
333 |
User::LeaveIfError(mask->Create(aBitmap->SizeInPixels(), EGray256));
|
|
334 |
|
|
335 |
CFbsBitmapDevice* maskDevice = CFbsBitmapDevice::NewL(mask);
|
|
336 |
CleanupStack::PushL(maskDevice);
|
|
337 |
CFbsBitGc* maskGc;
|
|
338 |
User::LeaveIfError(maskDevice->CreateContext(maskGc));
|
|
339 |
CleanupStack::PushL(maskGc);
|
|
340 |
maskGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
|
|
341 |
maskGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
|
|
342 |
maskGc->SetBrushColor(KRgbBlack);
|
|
343 |
maskGc->Clear();
|
|
344 |
maskGc->SetBrushColor(KRgbWhite);
|
|
345 |
maskGc->DrawRect(TRect(TPoint(), aBitmap->SizeInPixels()));
|
|
346 |
CleanupStack::PopAndDestroy(maskGc);
|
|
347 |
CleanupStack::PopAndDestroy(maskDevice);
|
|
348 |
CleanupStack::Pop(mask);
|
|
349 |
return mask;
|
|
350 |
}
|
|
351 |
#ifdef COVERAGE_MEASUREMENT
|
|
352 |
#pragma CTC ENDSKIP
|
|
353 |
#endif //COVERAGE_MEASUREMENT
|
|
354 |
|
|
355 |
|
|
356 |
#ifdef COVERAGE_MEASUREMENT
|
|
357 |
#pragma CTC SKIP
|
|
358 |
#endif //COVERAGE_MEASUREMENT (Icon can be created only from SIM)
|
|
359 |
/*!
|
|
360 |
Get icon from entry.
|
|
361 |
\param entry const reference to CaEntry.
|
|
362 |
\retval icon.
|
|
363 |
*/
|
|
364 |
LOCAL_C HbIcon getSatIconL()
|
|
365 |
{
|
|
366 |
HbIcon icon;
|
|
367 |
QPixmap pixmap;
|
|
368 |
CFbsBitmap* bitmap(NULL);
|
|
369 |
CFbsBitmap* mask(NULL);
|
|
370 |
bitmap = getSatBitmapL();
|
|
371 |
if(bitmap)
|
|
372 |
{
|
|
373 |
mask = getSatMaskL(bitmap);
|
|
374 |
fromBitmapAndMaskToPixmap(bitmap, mask, pixmap);
|
|
375 |
icon = HbIcon(QIcon(pixmap));
|
|
376 |
}
|
|
377 |
|
|
378 |
|
|
379 |
delete mask;
|
|
380 |
delete bitmap;
|
|
381 |
return icon;
|
|
382 |
|
|
383 |
}
|
|
384 |
#ifdef COVERAGE_MEASUREMENT
|
|
385 |
#pragma CTC ENDSKIP
|
|
386 |
#endif //COVERAGE_MEASUREMENT
|
|
387 |
|
|
388 |
|
92
|
389 |
/*!
|
|
390 |
Get icon.
|
|
391 |
\param entry const reference to CaEntry.
|
|
392 |
\param sie const reference to icon size.
|
|
393 |
\retval icon.
|
|
394 |
*/
|
119
|
395 |
HbIcon CaMenuIconUtility::getEntryIcon(const CaEntry& entry, const QSizeF &size)
|
92
|
396 |
{
|
|
397 |
HbIcon icon;
|
119
|
398 |
|
112
|
399 |
icon = getIconFromEntry(entry, size);
|
119
|
400 |
|
|
401 |
if ((icon.isNull() || !(icon.size().isValid())) &&
|
|
402 |
entry.attribute(appUidAttributeName).toInt() == KSatUid.iUid) {
|
|
403 |
TRAP_IGNORE(icon = getSatIconL());
|
|
404 |
}
|
|
405 |
|
92
|
406 |
if (icon.isNull() || !(icon.size().isValid())) {
|
106
|
407 |
QString uidString(entry.attribute(appUidAttributeName));
|
|
408 |
bool uidOk(false);
|
|
409 |
int uidValue = uidString.toInt(&uidOk);
|
|
410 |
if (!uidOk) {
|
|
411 |
uidString = entry.iconDescription().applicationId();
|
|
412 |
uidValue = uidString.toInt(&uidOk);
|
|
413 |
}
|
|
414 |
if (uidOk) {
|
|
415 |
TRAP_IGNORE(icon = getIconFromApparcL(uidValue, size));
|
|
416 |
}
|
92
|
417 |
}
|
119
|
418 |
|
92
|
419 |
if (icon.isNull() || !(icon.size().isValid())) {
|
|
420 |
icon = getDefaultIcon(entry);
|
|
421 |
}
|
119
|
422 |
|
94
|
423 |
if (entry.entryTypeName() == XQConversions::s60DescToQString(
|
119
|
424 |
KCaTypeWidget)) {
|
106
|
425 |
icon.addProportionalBadge(Qt::AlignBottom | Qt::AlignRight,
|
119
|
426 |
HbIcon("qtg_small_homescreen"), QSizeF(0.5, 0.5));
|
94
|
427 |
}
|
92
|
428 |
return icon;
|
|
429 |
}
|
112
|
430 |
|
119
|
431 |
|
|
432 |
|