|
1 /* |
|
2 * Copyright (c) 2007-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: mailbox branding object |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "emailmailboxinfo_p.h" |
|
19 #include "nmutilitiescommonheaders.h" |
|
20 #include "nmcenrepkeys.h" |
|
21 #include <QRegExp> |
|
22 #include <QStringList> |
|
23 |
|
24 const unsigned long int partialKey = 0x0; |
|
25 const unsigned long int bitMask = 0x0F000000; |
|
26 |
|
27 EmailMailboxInfoPrivate* EmailMailboxInfoPrivate::mSelf = NULL; |
|
28 qint32 EmailMailboxInfoPrivate::mReferenceCount = 0; |
|
29 |
|
30 const QString KBrandNameGmail("Gmail"); |
|
31 const QString KBrandNameGoogleMail("Google Mail"); |
|
32 |
|
33 const QString KMCCGermany("262"); |
|
34 const QString KMCCUK1("234"); |
|
35 const QString KMCCUK2("235"); |
|
36 |
|
37 const quint8 KGermanyTzId = 36; |
|
38 const quint8 KUKTzId = 104; |
|
39 |
|
40 using namespace NmBrandingApi; |
|
41 using namespace QtMobility; |
|
42 |
|
43 /*! |
|
44 private constructor |
|
45 */ |
|
46 EmailMailboxInfoPrivate::EmailMailboxInfoPrivate() : |
|
47 QObject(NULL), |
|
48 mIsResourceLoaded(false) |
|
49 { |
|
50 XQSettingsManager manager; |
|
51 XQCentralRepositorySettingsKey rccKey(EMAIL_CENREP, RCC_PATH); |
|
52 |
|
53 XQCentralRepositorySettingsKey wlbKey(EMAIL_CENREP, WLB_BRAND_NAME); |
|
54 |
|
55 mWlbDomainName = manager.readItemValue(wlbKey, XQSettingsManager::TypeString).value<QString> (); |
|
56 |
|
57 QString pathToRcc = |
|
58 manager.readItemValue(rccKey, XQSettingsManager::TypeString).value<QString> (); |
|
59 if (!mIsResourceLoaded) { |
|
60 mIsResourceLoaded = QResource::registerResource(pathToRcc); |
|
61 } |
|
62 } |
|
63 /*! |
|
64 private destructor |
|
65 */ |
|
66 EmailMailboxInfoPrivate::~EmailMailboxInfoPrivate() |
|
67 { |
|
68 |
|
69 } |
|
70 |
|
71 /*! |
|
72 gets instance of EmailMailboxInfoPrivate |
|
73 \return instance of EmailMailboxInfoPrivate |
|
74 */ |
|
75 EmailMailboxInfoPrivate* EmailMailboxInfoPrivate::getInstance() |
|
76 { |
|
77 if (!mSelf) { |
|
78 mSelf = new EmailMailboxInfoPrivate(); |
|
79 } |
|
80 mReferenceCount++; |
|
81 return mSelf; |
|
82 } |
|
83 |
|
84 /*! |
|
85 releases pointer to instance of EmailMailboxInfoPrivate |
|
86 \param pointer to instance of EmailMailboxInfoPrivate object |
|
87 */ |
|
88 void EmailMailboxInfoPrivate::releaseInstance(EmailMailboxInfoPrivate *&instance) |
|
89 { |
|
90 if (instance) { |
|
91 mReferenceCount--; |
|
92 instance = NULL; |
|
93 } |
|
94 if (mReferenceCount < 1) { |
|
95 delete mSelf; |
|
96 mSelf = NULL; |
|
97 } |
|
98 } |
|
99 |
|
100 /*! |
|
101 returns branding name of given domain |
|
102 \param branding identifier |
|
103 \return branding name |
|
104 */ |
|
105 QString EmailMailboxInfoPrivate::name(const QVariant &identifier) |
|
106 { |
|
107 QString returnValue = ""; |
|
108 QString domainName = ""; |
|
109 if (identifier.canConvert<QString> ()) { |
|
110 domainName = identifier.value<QString> (); |
|
111 } |
|
112 |
|
113 if (domainName.length() > 0) { |
|
114 processCenRepRecords(domainName); |
|
115 returnValue = mTempName; |
|
116 } |
|
117 |
|
118 verifyMailAccountName(returnValue); |
|
119 |
|
120 return returnValue; |
|
121 } |
|
122 |
|
123 /*! |
|
124 returns branding icon of given domain |
|
125 \param branding identifier |
|
126 \return branding icon |
|
127 */ |
|
128 QString EmailMailboxInfoPrivate::icon(const QVariant &identifier) |
|
129 { |
|
130 QString returnValue = ""; |
|
131 QString domainName = ""; |
|
132 if (identifier.canConvert<QString> ()) { |
|
133 domainName = identifier.value<QString> (); |
|
134 } |
|
135 |
|
136 if (domainName.length() > 0){ |
|
137 processCenRepRecords(domainName); |
|
138 returnValue = mTempIcon; |
|
139 } |
|
140 |
|
141 return returnValue; |
|
142 } |
|
143 |
|
144 /*! |
|
145 goes through cenrep to find matching branding details |
|
146 \param brandingId (i.e. domain name) |
|
147 */ |
|
148 void EmailMailboxInfoPrivate::processCenRepRecords(const QString &brandingId) |
|
149 { |
|
150 bool found = false; |
|
151 QString name; |
|
152 QString icon; |
|
153 |
|
154 XQSettingsManager cenRepManager; |
|
155 |
|
156 if (brandingId == mWlbDomainName) { |
|
157 found = true; |
|
158 XQCentralRepositorySettingsKey wlbNameKey(EMAIL_CENREP, WLB_MAILBOX_NAME); |
|
159 XQCentralRepositorySettingsKey wlbIconKey(EMAIL_CENREP, WLB_ICON_PATH); |
|
160 |
|
161 icon = cenRepManager.readItemValue(wlbIconKey, XQSettingsManager::TypeString).value<QString> (); |
|
162 name = cenRepManager.readItemValue(wlbNameKey, XQSettingsManager::TypeString).value<QString> (); |
|
163 } |
|
164 else { |
|
165 XQCentralRepositorySearchCriteria sCriteria(EMAIL_CENREP, partialKey, bitMask); |
|
166 XQCentralRepositoryUtils cenrepUtils(cenRepManager); |
|
167 QList<XQCentralRepositorySettingsKey> foundKeys = cenrepUtils.findKeys(sCriteria); |
|
168 |
|
169 foreach(XQCentralRepositorySettingsKey key, foundKeys) |
|
170 { |
|
171 QString dataRow = ""; |
|
172 if (mBrandingDataMap.contains(key.key())) { |
|
173 dataRow = mBrandingDataMap.value(key.key()); |
|
174 } |
|
175 //first we put every spotted data row to map |
|
176 else { |
|
177 QVariant brandingDataRaw = cenRepManager.readItemValue(key, |
|
178 XQSettingsManager::TypeString); |
|
179 if (brandingDataRaw.canConvert<QString>()) { |
|
180 dataRow = brandingDataRaw.value<QString>(); |
|
181 mBrandingDataMap.insert(key.key(), dataRow); |
|
182 } |
|
183 } |
|
184 |
|
185 // then we check if this row contains matching data |
|
186 QStringList cenRepRecord = dataRow.split(";"); |
|
187 |
|
188 if (cenRepRecord.size() < 4) { |
|
189 continue; |
|
190 } |
|
191 |
|
192 if (!brandingId.contains(cenRepRecord.at(0), Qt::CaseInsensitive)) { |
|
193 continue; |
|
194 } |
|
195 |
|
196 QRegExp regExp(cenRepRecord.at(1)); |
|
197 regExp.setCaseSensitivity(Qt::CaseInsensitive); |
|
198 |
|
199 if (regExp.exactMatch(brandingId)) { //match |
|
200 found = true; |
|
201 icon = ":/" + cenRepRecord.at(3); |
|
202 name = cenRepRecord.at(2); |
|
203 break; |
|
204 } |
|
205 } |
|
206 } |
|
207 if (!found || !mIsResourceLoaded) { |
|
208 //get default icon and name |
|
209 icon = "qtg_large_email"; |
|
210 QStringList domain = brandingId.split("."); |
|
211 if (domain.size() > 0) { |
|
212 name = domain.at(0); |
|
213 } |
|
214 } |
|
215 mTempIcon = icon; |
|
216 mTempName = name; |
|
217 } |
|
218 |
|
219 /*! |
|
220 gets current country code |
|
221 \return current country id |
|
222 */ |
|
223 quint8 EmailMailboxInfoPrivate::getCurrentCountryL() const |
|
224 { |
|
225 CTzLocalizer* localizer = CTzLocalizer::NewLC(); |
|
226 |
|
227 CTzLocalizedCity* city = localizer->GetFrequentlyUsedZoneCityL( |
|
228 CTzLocalizedTimeZone::ECurrentZone); |
|
229 CleanupStack::PushL(city); |
|
230 |
|
231 CTzLocalizedCityGroup* cityGroup = localizer->GetCityGroupL(city->GroupId()); |
|
232 |
|
233 TUint8 countryId = cityGroup->Id(); |
|
234 |
|
235 delete cityGroup; |
|
236 cityGroup = NULL; |
|
237 |
|
238 CleanupStack::PopAndDestroy(2, localizer); |
|
239 |
|
240 return countryId; |
|
241 } |
|
242 |
|
243 /*! |
|
244 verifies if timezone is set for Germany or UK |
|
245 \return true if timezone is UK or Germany, false otherwise |
|
246 */ |
|
247 bool EmailMailboxInfoPrivate::verifyTimeZone() const |
|
248 { |
|
249 quint8 timeZone = 0; |
|
250 bool retVal = false; |
|
251 TRAPD(err, timeZone = getCurrentCountryL()); |
|
252 |
|
253 if (err == KErrNone && (timeZone == KGermanyTzId || timeZone == KUKTzId)) { |
|
254 retVal = true; |
|
255 } |
|
256 return retVal; |
|
257 } |
|
258 |
|
259 /*! |
|
260 modifies branding name "Gmail" according to UK and Germany law rules |
|
261 \param brandingName name of branding |
|
262 */ |
|
263 void EmailMailboxInfoPrivate::verifyMailAccountName(QString &brandingName) const |
|
264 { |
|
265 QSystemNetworkInfo *networkInfo = new QSystemNetworkInfo(); |
|
266 QString currentMCC = networkInfo->currentMobileCountryCode(); |
|
267 |
|
268 if (brandingName == KBrandNameGmail) { |
|
269 if (currentMCC.size() > 0) { |
|
270 if ((currentMCC == KMCCGermany) || (currentMCC == KMCCUK1) || (currentMCC == KMCCUK2)) { |
|
271 brandingName = KBrandNameGoogleMail; |
|
272 } |
|
273 } |
|
274 else { //if there is information (no sim) |
|
275 if (verifyTimeZone()) { |
|
276 brandingName = KBrandNameGoogleMail; |
|
277 } |
|
278 } |
|
279 } |
|
280 } |
|
281 |