87
|
1 |
/*
|
|
2 |
* Copyright (c)2008 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: ?Description
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QCoreApplication>
|
|
19 |
#include "caiconcache.h"
|
|
20 |
#include "caservice.h"
|
|
21 |
#include "caentry.h"
|
|
22 |
#include "caobjectadapter.h"
|
|
23 |
#include "caclienttest_global.h"
|
|
24 |
|
|
25 |
// Constants
|
|
26 |
static const int maxCost = 250;
|
|
27 |
static const QChar separator = '*';
|
|
28 |
|
|
29 |
QSharedPointer<CaIconCache> CaIconCache::mInstance(0);
|
|
30 |
|
|
31 |
/*!
|
93
|
32 |
\class CaIconCache
|
|
33 |
\brief This class provides icon caching mechanism
|
|
34 |
Class implements singleton design patern. Use cache() method
|
|
35 |
to get an instance of CaIconCache
|
|
36 |
*/
|
|
37 |
|
|
38 |
/*!
|
|
39 |
\var CaIconCache::mCache
|
|
40 |
Own.
|
|
41 |
*/
|
|
42 |
|
|
43 |
/*!
|
|
44 |
\var CaIconCache::mService
|
|
45 |
Not own.
|
|
46 |
*/
|
|
47 |
|
|
48 |
/*!
|
|
49 |
\var CaIconCache::mNotifier
|
|
50 |
Own.
|
87
|
51 |
*/
|
|
52 |
|
|
53 |
/*!
|
|
54 |
Returns an instance of CaIconCache
|
|
55 |
\retval CaIconCache instance
|
|
56 |
|
|
57 |
*/
|
|
58 |
CaIconCache *CaIconCache::cache()
|
|
59 |
{
|
|
60 |
if (!mInstance.data()) {
|
|
61 |
mInstance = QSharedPointer<CaIconCache>(new CaIconCache());
|
|
62 |
mInstance->setParent(QCoreApplication::instance());
|
|
63 |
}
|
|
64 |
return mInstance.data();
|
|
65 |
}
|
|
66 |
|
|
67 |
/*!
|
|
68 |
Destructor
|
|
69 |
*/
|
|
70 |
CaIconCache::~CaIconCache()
|
|
71 |
{
|
|
72 |
CACLIENTTEST_FUNC_ENTRY("CaIconCache::~CaIconCache");
|
|
73 |
mCache.clear();
|
|
74 |
delete mNotifier;
|
|
75 |
CACLIENTTEST_FUNC_EXIT("CaIconCache::~CaIconCache");
|
|
76 |
}
|
|
77 |
|
|
78 |
/*!
|
|
79 |
Constructor
|
|
80 |
*/
|
|
81 |
CaIconCache::CaIconCache(QObject *parent): QObject(parent),
|
|
82 |
mCache(), mService(CaService::instance()), mNotifier(0)
|
|
83 |
{
|
|
84 |
mCache.setMaxCost(maxCost);
|
|
85 |
CaNotifierFilter filter;
|
|
86 |
mNotifier = mService->createNotifier(filter);
|
|
87 |
connect(mNotifier, SIGNAL(entryChanged(const CaEntry &,ChangeType)),
|
|
88 |
this, SLOT(remove(const CaEntry &,ChangeType)));
|
|
89 |
|
|
90 |
}
|
|
91 |
|
|
92 |
/*!
|
|
93 |
Checks if icon is already cached
|
|
94 |
\param entry an entry
|
|
95 |
\param size size of an icon
|
|
96 |
\retval true if icon exist in cache
|
|
97 |
|
|
98 |
*/
|
|
99 |
bool CaIconCache::exist(const CaEntry &entry, const QSize &size)
|
|
100 |
{
|
|
101 |
CACLIENTTEST_FUNC_ENTRY("CaIconCache::exist");
|
|
102 |
bool result(false);
|
|
103 |
result = mCache.contains(key(entry,size));
|
|
104 |
CACLIENTTEST_FUNC_EXIT("CaIconCache::exist");
|
|
105 |
return result;
|
|
106 |
}
|
|
107 |
|
|
108 |
/*!
|
|
109 |
Returns an icon from a cache
|
|
110 |
\param entry an entry
|
|
111 |
\param size size of an icon
|
|
112 |
\retval icon
|
|
113 |
|
|
114 |
*/
|
|
115 |
|
|
116 |
HbIcon CaIconCache::icon(const CaEntry &entry, const QSize &size)
|
|
117 |
{
|
|
118 |
CACLIENTTEST_FUNC_ENTRY("CaIconCache::icon");
|
107
|
119 |
HbIcon result;
|
|
120 |
if (HbIcon* tmp = mCache.object(key(entry,size))) {
|
|
121 |
result = *tmp;
|
|
122 |
}
|
87
|
123 |
CACLIENTTEST_FUNC_EXIT("CaIconCache::icon");
|
107
|
124 |
return result;
|
87
|
125 |
}
|
|
126 |
|
|
127 |
/*!
|
|
128 |
Insert an icon to a cache
|
|
129 |
\param entry an entry
|
|
130 |
\param size size of an icon
|
|
131 |
\param icon icon to be cached
|
|
132 |
|
|
133 |
*/
|
|
134 |
void CaIconCache::insert(const CaEntry &entry, const QSize &size,
|
|
135 |
const HbIcon &icon)
|
|
136 |
{
|
|
137 |
CACLIENTTEST_FUNC_ENTRY("CaIconCache::insert");
|
|
138 |
mCache.insert(key(entry,size),new HbIcon(icon));
|
|
139 |
CACLIENTTEST_FUNC_EXIT("CaIconCache::insert");
|
|
140 |
}
|
|
141 |
|
|
142 |
/*!
|
|
143 |
Removes icon from a cache
|
|
144 |
\param entry an entry
|
|
145 |
\param changeTypa indicates if entry was updated, removed or added
|
|
146 |
*/
|
|
147 |
void CaIconCache::remove(const CaEntry &entry, ChangeType changeType)
|
|
148 |
{
|
|
149 |
CACLIENTTEST_FUNC_ENTRY("CaIconCache::remove");
|
98
|
150 |
if (changeType != AddChangeType && !(entry.flags() & UninstallEntryFlag)) {
|
87
|
151 |
QString entryKey = key(entry);
|
|
152 |
entryKey.append(separator);
|
|
153 |
QList<QString> keys = mCache.keys();
|
|
154 |
foreach(QString cacheKey,keys) {
|
|
155 |
if (cacheKey.contains(entryKey)) {
|
|
156 |
mCache.remove(cacheKey);
|
|
157 |
}
|
|
158 |
}
|
|
159 |
}
|
|
160 |
CACLIENTTEST_FUNC_EXIT("CaIconCache::remove");
|
|
161 |
}
|
|
162 |
|
|
163 |
/*!
|
|
164 |
Generates a key
|
|
165 |
\param entry an entry
|
|
166 |
\return key
|
|
167 |
*/
|
|
168 |
|
|
169 |
QString CaIconCache::key(const CaEntry &entry, const QSize &size)
|
|
170 |
{
|
|
171 |
QString key;
|
|
172 |
if (!entry.iconDescription().filename().isEmpty()) {
|
|
173 |
key.append(entry.iconDescription().filename());
|
99
|
174 |
key.append(separator);
|
|
175 |
key.append(entry.entryTypeName());
|
87
|
176 |
} else {
|
|
177 |
key.append(separator);
|
|
178 |
key.append(entry.id());
|
|
179 |
}
|
|
180 |
if (size.isValid()) {
|
|
181 |
key.append(separator);
|
|
182 |
key.append(size.height());
|
|
183 |
key.append(separator);
|
|
184 |
key.append(size.width());
|
|
185 |
}
|
|
186 |
return key;
|
|
187 |
}
|