72
|
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 |
#include <QString.h>
|
|
19 |
|
|
20 |
#include "cntglobal.h"
|
|
21 |
#include "CntSimEngine.h"
|
|
22 |
#include "cntimportviewcallback.h"
|
|
23 |
#include "cntdebug.h"
|
|
24 |
|
|
25 |
#include <hbview.h>
|
|
26 |
#include <QCoreApplication>
|
|
27 |
#include <QStandardItemModel>
|
|
28 |
#include <hbextendedlocale.h>
|
|
29 |
#include <hbstringutil.h>
|
|
30 |
#include <hbparameterlengthlimiter.h>
|
|
31 |
#include <hbdialog.h>
|
|
32 |
#include <hbnotificationdialog.h>
|
|
33 |
#include <hbdevicenotificationdialog.h>
|
|
34 |
|
|
35 |
const int KTimerValue = 1; // used as 1 msec timer for saving ADN contacts from SIM
|
|
36 |
|
|
37 |
CntSimEngine::CntSimEngine(CntImportViewCallback& aImportViewCallback, HbView& aView)
|
|
38 |
: mImportViewCallback(aImportViewCallback),
|
|
39 |
mView(aView),
|
|
40 |
mAdnSimUtility(0),
|
|
41 |
mSdnSimUtility(0),
|
|
42 |
mContactSimManagerADN(0),
|
|
43 |
mContactSimManagerSDN(0),
|
|
44 |
mFetchRequestADN(0),
|
|
45 |
mFetchRequestSDN(0),
|
|
46 |
mTimer(0),
|
|
47 |
mAbsEngine(0),
|
|
48 |
mTimerId(0),
|
|
49 |
mSaveCount(0),
|
|
50 |
mAdnStoreEntries(0),
|
|
51 |
mSdnStoreEntries(0),
|
|
52 |
mAdnEntriesPresent(false),
|
|
53 |
mFetchIsDone(false),
|
|
54 |
mAdnStorePresent(false),
|
|
55 |
mSdnStorePresent(false),
|
|
56 |
mSimPresent(false),
|
|
57 |
mSimError(false),
|
|
58 |
mWaitingForAdnCache(false),
|
|
59 |
mImportInProgress(false)
|
|
60 |
{
|
|
61 |
|
|
62 |
}
|
|
63 |
|
|
64 |
CntSimEngine::~CntSimEngine()
|
|
65 |
{
|
|
66 |
CNT_ENTRY
|
|
67 |
delete mFetchRequestADN;
|
|
68 |
delete mFetchRequestSDN;
|
|
69 |
delete mAdnSimUtility;
|
|
70 |
delete mSdnSimUtility;
|
|
71 |
CNT_EXIT
|
|
72 |
}
|
|
73 |
|
|
74 |
void CntSimEngine::init(CntAbstractEngine& aAbsEngine)
|
|
75 |
{
|
|
76 |
CNT_ENTRY
|
|
77 |
mAbsEngine = &aAbsEngine;
|
|
78 |
mContactSymbianManager = &mAbsEngine->contactManager(SYMBIAN_BACKEND);
|
|
79 |
|
|
80 |
// Sim Utility info fetch
|
|
81 |
int getSimInfoError(0);
|
|
82 |
int storesError(0);
|
|
83 |
int getSdnSimInfoError(0);
|
|
84 |
|
|
85 |
|
|
86 |
//ADN store
|
|
87 |
int error = -1;
|
|
88 |
mAdnSimUtility = new CntSimUtility(CntSimUtility::AdnStore, error);
|
|
89 |
|
|
90 |
if (error != 0)
|
|
91 |
{
|
|
92 |
delete mAdnSimUtility;
|
|
93 |
mAdnSimUtility = 0;
|
|
94 |
mSimError = true;
|
|
95 |
//mSimError = true;
|
|
96 |
}
|
|
97 |
else
|
|
98 |
{
|
|
99 |
// check what stores are there
|
|
100 |
CntSimUtility::AvailableStores stores = mAdnSimUtility->getAvailableStores(storesError);
|
|
101 |
if(!storesError)
|
|
102 |
{
|
|
103 |
mSimPresent = stores.SimPresent;
|
|
104 |
mAdnStorePresent = stores.AdnStorePresent;
|
|
105 |
mSdnStorePresent = stores.SdnStorePresent;
|
|
106 |
}
|
|
107 |
|
|
108 |
//check there are ADN contacts
|
|
109 |
if (mAdnStorePresent)
|
|
110 |
{
|
|
111 |
CntSimUtility::SimInfo simInfo = mAdnSimUtility->getSimInfo(getSimInfoError);
|
|
112 |
if (getSimInfoError == KErrNone)
|
|
113 |
{
|
|
114 |
// sim entries are present
|
|
115 |
mAdnStoreEntries = simInfo.usedEntries;
|
|
116 |
if (mAdnStoreEntries > 0)
|
|
117 |
{
|
|
118 |
mAdnEntriesPresent = true;
|
|
119 |
}
|
|
120 |
}
|
|
121 |
else
|
|
122 |
{
|
|
123 |
if (getSimInfoError == KErrNotReady)
|
|
124 |
{
|
|
125 |
//ADN store is not accessible, e.g. because of active FDN
|
|
126 |
//Or ADN cache is not ready yet, so wait for this
|
|
127 |
|
|
128 |
mAdnStorePresent = true;
|
|
129 |
mAdnEntriesPresent = true;
|
|
130 |
mWaitingForAdnCache = true;
|
81
|
131 |
connect(mAdnSimUtility, SIGNAL(adnCacheStatusReady(CntSimUtility::CacheStatus&, int)), this, SLOT(getSimInfoAndUpdateUI(CntSimUtility::CacheStatus&, int)));
|
72
|
132 |
if (!mAdnSimUtility->notifyAdnCacheStatus()) {
|
|
133 |
mAdnStorePresent = false;
|
|
134 |
mAdnEntriesPresent = false;
|
|
135 |
mWaitingForAdnCache = false;
|
|
136 |
}
|
|
137 |
}
|
|
138 |
else
|
|
139 |
{
|
|
140 |
simInfoErrorMessage(getSimInfoError);
|
|
141 |
}
|
|
142 |
}
|
|
143 |
}
|
|
144 |
}
|
|
145 |
|
|
146 |
//SDN store
|
|
147 |
if (mSdnStorePresent && !mWaitingForAdnCache)
|
|
148 |
{
|
|
149 |
int sdnError = -1;
|
|
150 |
mSdnStorePresent = false;
|
|
151 |
if (!mSdnSimUtility)
|
|
152 |
{
|
|
153 |
mSdnSimUtility = new CntSimUtility(CntSimUtility::SdnStore, sdnError);
|
|
154 |
if (sdnError != 0)
|
|
155 |
{
|
|
156 |
delete mSdnSimUtility;
|
|
157 |
mSdnSimUtility = 0;
|
|
158 |
}
|
|
159 |
}
|
|
160 |
if (mSdnSimUtility)
|
|
161 |
{
|
|
162 |
//get number of SDN contacts
|
|
163 |
CntSimUtility::SimInfo sdnSimInfo = mSdnSimUtility->getSimInfo(getSdnSimInfoError);
|
|
164 |
if (!getSdnSimInfoError)
|
|
165 |
{
|
|
166 |
// sim entries are present
|
|
167 |
mSdnStoreEntries = sdnSimInfo.usedEntries;
|
|
168 |
if (mSdnStoreEntries > 0)
|
|
169 |
{
|
|
170 |
mSdnStorePresent = true;
|
|
171 |
}
|
|
172 |
}
|
|
173 |
}
|
|
174 |
}
|
|
175 |
CNT_EXIT
|
|
176 |
// end SDN store
|
|
177 |
}
|
|
178 |
|
|
179 |
void CntSimEngine::checkEntries(QStringList& simList, QStandardItem& importSimItem)
|
|
180 |
{
|
|
181 |
CNT_ENTRY
|
|
182 |
QString simImport(hbTrId("txt_phob_dblist_import_from_sim"));
|
|
183 |
QString simNoContacts(hbTrId("txt_phob_dblist_import_from_1_val_no_sim_contacts"));
|
|
184 |
QString simNoCard(hbTrId("txt_phob_dblist_import_from_ovi_val_no_sim_card"));
|
|
185 |
|
|
186 |
// check if SIM card is NOT there
|
|
187 |
if (mSimError)
|
|
188 |
{
|
|
189 |
simList << simImport;
|
|
190 |
importSimItem.setEnabled(false);
|
|
191 |
}
|
|
192 |
else if (!(mAdnStorePresent || mSdnStorePresent))
|
|
193 |
{
|
|
194 |
// Both stores are not present
|
|
195 |
// disable the QStandardItem
|
|
196 |
if (!mSimPresent)
|
|
197 |
{
|
|
198 |
simList << simImport << simNoCard;
|
|
199 |
}
|
|
200 |
else
|
|
201 |
{
|
|
202 |
simList << simImport << simNoContacts;
|
|
203 |
}
|
|
204 |
importSimItem.setEnabled(false);
|
|
205 |
}
|
|
206 |
else if (!(mAdnEntriesPresent || mSdnStorePresent))
|
|
207 |
{
|
|
208 |
// Sim card is present
|
|
209 |
// No ADN entries are there
|
|
210 |
// no SDN entries are there
|
|
211 |
simList << simImport << simNoContacts;
|
|
212 |
importSimItem.setEnabled(false);
|
|
213 |
}
|
|
214 |
else
|
|
215 |
{
|
|
216 |
// SIM card is present
|
|
217 |
//ADN entries or SDN entries are there
|
|
218 |
simList << simImport;
|
|
219 |
int error = 0;
|
|
220 |
QDateTime date = mAdnSimUtility->getLastImportTime(error);
|
|
221 |
if (error == 0) {
|
|
222 |
HbExtendedLocale locale = HbExtendedLocale::system();
|
|
223 |
QString dateStr = locale.format(date.date(), r_qtn_date_usual);
|
|
224 |
QString dateStrLocaleDigits = HbStringUtil::convertDigits(dateStr);
|
|
225 |
QString dateStrFull =
|
81
|
226 |
HbParameterLengthLimiter("txt_phob_dblist_import_from_1_val_updated_1").arg(dateStrLocaleDigits);
|
72
|
227 |
simList << dateStrFull;
|
|
228 |
}
|
|
229 |
}
|
|
230 |
CNT_EXIT
|
|
231 |
}
|
|
232 |
|
|
233 |
bool CntSimEngine::startSimImport()
|
|
234 |
{
|
|
235 |
CNT_ENTRY
|
|
236 |
bool started = false;
|
|
237 |
mImportInProgress = true;
|
|
238 |
mSaveCount = 0;
|
|
239 |
|
|
240 |
delete mFetchRequestADN;
|
|
241 |
mContactSimManagerADN = &mAbsEngine->contactManager(SIM_BACKEND_ADN);
|
|
242 |
mFetchRequestADN = new QContactFetchRequest;
|
|
243 |
mFetchRequestADN->setManager(mContactSimManagerADN);
|
|
244 |
|
|
245 |
delete mFetchRequestSDN;
|
|
246 |
mContactSimManagerSDN = &mAbsEngine->contactManager(SIM_BACKEND_SDN);
|
|
247 |
mFetchRequestSDN = new QContactFetchRequest;
|
|
248 |
mFetchRequestSDN->setManager(mContactSimManagerSDN);
|
|
249 |
|
|
250 |
if (mWaitingForAdnCache)
|
|
251 |
{
|
|
252 |
//show progress dialog and wait when ADN cache is ready
|
|
253 |
started = true;
|
|
254 |
}
|
|
255 |
else
|
|
256 |
{
|
|
257 |
if(mAdnStorePresent)
|
|
258 |
{
|
|
259 |
connect(mFetchRequestADN, SIGNAL(resultsAvailable()), this, SLOT(importADNFetchResults()));
|
|
260 |
}
|
|
261 |
|
|
262 |
if(mSdnStorePresent)
|
|
263 |
{
|
|
264 |
connect(mFetchRequestSDN, SIGNAL(resultsAvailable()), this, SLOT(importSDNFetchResults()));
|
|
265 |
}
|
|
266 |
|
|
267 |
if(mAdnEntriesPresent > 0 && mContactSimManagerADN->error() == QContactManager::NoError)
|
|
268 |
{
|
|
269 |
// ADN contacts are there, start fetch
|
|
270 |
mFetchRequestADN->start();
|
|
271 |
started = true;
|
|
272 |
}
|
|
273 |
else if (mSdnStorePresent && mContactSimManagerSDN->error() == QContactManager::NoError)
|
|
274 |
{
|
|
275 |
//start fetch of SDN contacts since ADN contacts are not there
|
|
276 |
mFetchRequestSDN->start();
|
|
277 |
started = true;
|
|
278 |
}
|
|
279 |
}
|
|
280 |
CNT_EXIT
|
|
281 |
return started;
|
|
282 |
}
|
|
283 |
|
|
284 |
|
|
285 |
void CntSimEngine::stopSimImport()
|
|
286 |
{
|
|
287 |
CNT_ENTRY
|
|
288 |
if(mImportInProgress)
|
|
289 |
{
|
|
290 |
emit closePopup();
|
|
291 |
mImportInProgress = false;
|
|
292 |
if (mFetchIsDone)
|
|
293 |
{
|
|
294 |
// indicates that timer has been started
|
|
295 |
killTimer(mTimerId);
|
|
296 |
}
|
|
297 |
mSaveSimContactsList.clear();
|
|
298 |
mSaveSimContactsListSDN.clear();
|
|
299 |
|
|
300 |
showSimImportResults();
|
|
301 |
|
|
302 |
if (mFetchRequestADN != NULL)
|
|
303 |
{
|
|
304 |
mFetchRequestADN->cancel();
|
|
305 |
}
|
|
306 |
if (mFetchRequestSDN != NULL)
|
|
307 |
{
|
|
308 |
mFetchRequestSDN->cancel();
|
|
309 |
}
|
|
310 |
|
|
311 |
// save import time
|
|
312 |
int error = 0;
|
|
313 |
mAdnSimUtility->setLastImportTime(error);
|
|
314 |
|
|
315 |
//update sim import row with last import time
|
|
316 |
if (error == 0)
|
|
317 |
{
|
|
318 |
QDateTime date = mAdnSimUtility->getLastImportTime(error);
|
|
319 |
if (error == 0)
|
|
320 |
{
|
|
321 |
QString simImport(hbTrId("txt_phob_dblist_import_from_sim"));
|
|
322 |
|
|
323 |
HbExtendedLocale locale = HbExtendedLocale::system();
|
|
324 |
QString dateStr = locale.format(date.date(), r_qtn_date_usual);
|
|
325 |
QString dateStrLocaleDigits = HbStringUtil::convertDigits(dateStr);
|
|
326 |
QString dateStrFull =
|
81
|
327 |
HbParameterLengthLimiter("txt_phob_dblist_import_from_1_val_updated_1").arg(dateStrLocaleDigits);
|
72
|
328 |
//simList << dateStrFull;
|
|
329 |
|
|
330 |
mImportViewCallback.setListBoxItemText(simImport, dateStrFull);
|
|
331 |
}
|
|
332 |
}
|
81
|
333 |
|
|
334 |
emit showNamesView();
|
72
|
335 |
}
|
|
336 |
|
|
337 |
CNT_EXIT
|
|
338 |
}
|
|
339 |
|
|
340 |
void CntSimEngine::timerEvent(QTimerEvent *event)
|
|
341 |
{
|
|
342 |
CNT_ENTRY
|
|
343 |
Q_UNUSED(event);
|
|
344 |
if (!(mSaveCount >= mSaveSimContactsList.count())) // while mSaveCount is less than or equal to mSaveSimContactsList.count()
|
|
345 |
{
|
|
346 |
QContact unSavedContact = mSaveSimContactsList.at(mSaveCount);
|
|
347 |
mContactSymbianManager->saveContact(&unSavedContact);
|
|
348 |
mSaveCount++;
|
|
349 |
//use another counter to check number of actual saved if saveContact() fails
|
|
350 |
}
|
|
351 |
else
|
|
352 |
{
|
|
353 |
// saving complete
|
|
354 |
killTimer(mTimerId);
|
|
355 |
mSaveSimContactsList.clear();
|
|
356 |
|
|
357 |
// ADN contacts fetching and saving is done
|
|
358 |
// Now start SDN fetching and save
|
|
359 |
fetchSDNContacts();
|
|
360 |
}
|
|
361 |
CNT_EXIT
|
|
362 |
}
|
|
363 |
|
|
364 |
|
|
365 |
void CntSimEngine::importADNFetchResults()
|
|
366 |
{
|
|
367 |
CNT_ENTRY
|
|
368 |
//save import time
|
|
369 |
int error = 0;
|
|
370 |
mAdnSimUtility->setLastImportTime(error);
|
|
371 |
|
|
372 |
QList<QContact> simContactsList = mFetchRequestADN->contacts();
|
|
373 |
if (simContactsList.isEmpty())
|
|
374 |
{
|
|
375 |
// No sim contacts, jump to fetching SDN contacts
|
|
376 |
fetchSDNContacts();
|
|
377 |
}
|
|
378 |
else
|
|
379 |
{
|
|
380 |
// save ADN contacts
|
|
381 |
|
|
382 |
int count = simContactsList.count();
|
|
383 |
foreach(QContact contact, simContactsList)
|
|
384 |
{
|
|
385 |
if (contact.localId() > 0)
|
|
386 |
{
|
|
387 |
//delete local id before saving to different storage
|
|
388 |
QScopedPointer<QContactId> contactId(new QContactId());
|
|
389 |
contactId->setLocalId(0);
|
|
390 |
contactId->setManagerUri(QString());
|
|
391 |
contact.setId(*contactId);
|
|
392 |
|
|
393 |
// custom label contains name information, save it to the first name
|
|
394 |
QList<QContactDetail> names = contact.details(QContactName::DefinitionName);
|
|
395 |
if (names.count() > 0)
|
|
396 |
{
|
|
397 |
QContactName name = static_cast<QContactName>(names.at(0));
|
|
398 |
name.setFirstName(name.customLabel());
|
|
399 |
name.setCustomLabel(QString());
|
|
400 |
contact.saveDetail(&name);
|
|
401 |
}
|
|
402 |
|
|
403 |
//update phone numbers to contain default subtype
|
|
404 |
QList<QContactDetail> numbers = contact.details(QContactPhoneNumber::DefinitionName);
|
|
405 |
for (int i = 0; i < numbers.count(); i++)
|
|
406 |
{
|
|
407 |
QContactPhoneNumber number = static_cast<QContactPhoneNumber>(numbers.at(i));
|
|
408 |
number.setSubTypes(QContactPhoneNumber::SubTypeMobile);
|
|
409 |
contact.saveDetail(&number);
|
|
410 |
}
|
|
411 |
|
|
412 |
//remove sync target details, it's read-only.
|
|
413 |
QList<QContactDetail> syncTargets = contact.details(QContactSyncTarget::DefinitionName);
|
|
414 |
for (int j = 0; j < syncTargets.count(); j++)
|
|
415 |
{
|
|
416 |
QContactSyncTarget syncTarget = static_cast<QContactSyncTarget>(syncTargets.at(j));
|
|
417 |
contact.removeDetail(&syncTarget);
|
|
418 |
}
|
|
419 |
|
|
420 |
contact.setType(QContactType::TypeContact);
|
|
421 |
setPreferredDetails(contact);
|
|
422 |
mSaveSimContactsList.append(contact);
|
|
423 |
|
|
424 |
}
|
|
425 |
}
|
|
426 |
// save the list synchronously because async cancelling of save request is
|
|
427 |
// not supported in symbian backend at the time of this implementation
|
|
428 |
|
|
429 |
if (!(mSaveSimContactsList.isEmpty()))
|
|
430 |
{
|
|
431 |
// indicates that there is one or more sim contact that has been fetched
|
|
432 |
// create a timer and start saving synchronously one by one
|
|
433 |
// when cancel is pressed, kill the timer
|
|
434 |
|
|
435 |
mTimerId = startTimer(KTimerValue); // starting a 1 msec timer
|
|
436 |
mFetchIsDone = true;
|
|
437 |
mSaveCount = 0;
|
|
438 |
}
|
|
439 |
}
|
|
440 |
CNT_EXIT
|
|
441 |
}
|
|
442 |
|
|
443 |
void CntSimEngine::importSDNFetchResults()
|
|
444 |
{
|
|
445 |
CNT_ENTRY
|
|
446 |
//save import time
|
|
447 |
int error = 0;
|
|
448 |
mAdnSimUtility->setLastImportTime(error);
|
|
449 |
|
|
450 |
QList<QContact> simContactsListSDN = mFetchRequestSDN->contacts();
|
|
451 |
if (simContactsListSDN.isEmpty())
|
|
452 |
{
|
|
453 |
//No sdn contacts present
|
|
454 |
showSimImportResults();
|
|
455 |
mSaveSimContactsListSDN.clear();
|
|
456 |
emit closePopup();
|
|
457 |
mImportInProgress = false;
|
|
458 |
// Importing finished, go back to NamesView
|
|
459 |
emit showNamesView();
|
|
460 |
//showPreviousView();
|
|
461 |
}
|
|
462 |
else
|
|
463 |
{
|
|
464 |
// SAVE SDN CONTACTS
|
|
465 |
int count = simContactsListSDN.count();
|
|
466 |
foreach(QContact contact, simContactsListSDN)
|
|
467 |
{
|
|
468 |
if (contact.localId() > 0)
|
|
469 |
{
|
|
470 |
//delete local id before saving to different storage
|
|
471 |
QScopedPointer<QContactId> contactId(new QContactId());
|
|
472 |
contactId->setLocalId(0);
|
|
473 |
contactId->setManagerUri(QString());
|
|
474 |
contact.setId(*contactId);
|
|
475 |
|
|
476 |
//custom label contains name information, save it to the first name
|
|
477 |
QList<QContactDetail> names = contact.details(QContactName::DefinitionName);
|
|
478 |
if (names.count() > 0)
|
|
479 |
{
|
|
480 |
QContactName name = static_cast<QContactName>(names.at(0));
|
|
481 |
name.setFirstName(name.customLabel());
|
|
482 |
name.setCustomLabel(QString());
|
|
483 |
contact.saveDetail(&name);
|
|
484 |
}
|
|
485 |
|
|
486 |
//update phone numbers to contain default subtype
|
|
487 |
QList<QContactDetail> numbers = contact.details(QContactPhoneNumber::DefinitionName);
|
|
488 |
for (int i = 0; i < numbers.count(); i++)
|
|
489 |
{
|
|
490 |
QContactPhoneNumber number = static_cast<QContactPhoneNumber>(numbers.at(i));
|
|
491 |
number.setSubTypes(QContactPhoneNumber::SubTypeMobile);
|
|
492 |
contact.saveDetail(&number);
|
|
493 |
}
|
|
494 |
|
|
495 |
//remove sync target details, it's read-only.
|
|
496 |
QList<QContactDetail> syncTargets = contact.details(QContactSyncTarget::DefinitionName);
|
|
497 |
for (int j = 0; j < syncTargets.count(); j++)
|
|
498 |
{
|
|
499 |
QContactSyncTarget syncTarget = static_cast<QContactSyncTarget>(syncTargets.at(j));
|
|
500 |
contact.removeDetail(&syncTarget);
|
|
501 |
}
|
|
502 |
|
|
503 |
contact.setType(QContactType::TypeContact);
|
|
504 |
setPreferredDetails(contact);
|
|
505 |
mSaveSimContactsListSDN.append(contact);
|
|
506 |
|
|
507 |
}
|
|
508 |
}
|
|
509 |
// save the list synchronously because async cancelling of save request is
|
|
510 |
// not supported in symbian backend at the time of this implementation
|
|
511 |
|
|
512 |
if (!(mSaveSimContactsListSDN.isEmpty()))
|
|
513 |
{
|
|
514 |
// indicates that there is one or more SDN sim contact that has been fetched
|
|
515 |
QMap<int, QContactManager::Error> errorMap;
|
|
516 |
mContactSymbianManager->saveContacts(&mSaveSimContactsListSDN,&errorMap);
|
|
517 |
// check number of contacts really saved
|
|
518 |
mSaveCount = mSaveCount + mSaveSimContactsListSDN.count();
|
|
519 |
}
|
|
520 |
|
|
521 |
// no more SDN contacts to fetch
|
|
522 |
showSimImportResults();
|
|
523 |
mSaveSimContactsListSDN.clear();
|
|
524 |
emit closePopup();
|
|
525 |
mImportInProgress = false;
|
|
526 |
// Importing finished, go back to NamesView
|
|
527 |
emit showNamesView();
|
|
528 |
//showPreviousView();
|
|
529 |
}
|
|
530 |
CNT_EXIT
|
|
531 |
}
|
|
532 |
|
|
533 |
void CntSimEngine::setPreferredDetails(QContact& aContact )
|
|
534 |
{
|
|
535 |
CNT_ENTRY
|
|
536 |
QList<QContactPhoneNumber> numberList( aContact.details<QContactPhoneNumber>() );
|
|
537 |
//set preferred number for call if there is only one phone number
|
|
538 |
if ( aContact.preferredDetail("call").isEmpty() && numberList.count() == 1 )
|
|
539 |
{
|
|
540 |
aContact.setPreferredDetail( "call", numberList.first() );
|
|
541 |
}
|
|
542 |
//set preferred number for message if there is only one mobile phone number
|
|
543 |
if ( aContact.preferredDetail("message").isEmpty() && numberList.count() == 1 )
|
|
544 |
{
|
|
545 |
aContact.setPreferredDetail( "message", numberList.first() );
|
|
546 |
}
|
|
547 |
//set preferred number for message if there is only one email address
|
|
548 |
QList<QContactEmailAddress> emailList( aContact.details<QContactEmailAddress>() );
|
|
549 |
if ( aContact.preferredDetail("email").isEmpty() && emailList.count() == 1 )
|
|
550 |
{
|
|
551 |
aContact.setPreferredDetail( "email", emailList.first() );
|
|
552 |
}
|
|
553 |
CNT_EXIT
|
|
554 |
}
|
|
555 |
|
|
556 |
void CntSimEngine::showSimImportResults() const
|
|
557 |
{
|
|
558 |
CNT_ENTRY
|
|
559 |
QString results = hbTrId("txt_phob_dpophead_ln_contacts_imported").arg(mSaveCount).arg(mAdnStoreEntries + mSdnStoreEntries);
|
|
560 |
HbNotificationDialog::launchDialog(results);
|
|
561 |
CNT_EXIT
|
|
562 |
}
|
|
563 |
|
|
564 |
void CntSimEngine::fetchSDNContacts()
|
|
565 |
{
|
|
566 |
CNT_ENTRY
|
|
567 |
if (mSdnStorePresent && mContactSimManagerSDN->error() == QContactManager::NoError)
|
|
568 |
{
|
|
569 |
mFetchRequestSDN->start();
|
|
570 |
}
|
|
571 |
else
|
|
572 |
{
|
|
573 |
// no SDN contacts to fetch
|
|
574 |
showSimImportResults();
|
|
575 |
emit closePopup();
|
|
576 |
mImportInProgress = false;
|
|
577 |
// Importing finished, go back to NamesView
|
|
578 |
|
|
579 |
//showPreviousView();
|
|
580 |
emit showNamesView();
|
|
581 |
}
|
|
582 |
CNT_EXIT
|
|
583 |
}
|
|
584 |
|
|
585 |
|
|
586 |
void CntSimEngine::getSimInfoAndUpdateUI(CntSimUtility::CacheStatus& cacheStatus, int error)
|
|
587 |
{
|
|
588 |
CNT_ENTRY
|
|
589 |
mWaitingForAdnCache = false;
|
|
590 |
//update ADN store info...
|
|
591 |
if (error != KErrNone || cacheStatus == CntSimUtility::ECacheFailed)
|
|
592 |
{
|
|
593 |
mAdnStorePresent = false;
|
|
594 |
mAdnEntriesPresent = false;
|
|
595 |
mSdnStorePresent = false;
|
|
596 |
}
|
|
597 |
else
|
|
598 |
{
|
|
599 |
//check if there are ADN contacts
|
|
600 |
mAdnStorePresent = true;
|
|
601 |
mAdnEntriesPresent = false;
|
|
602 |
int getSimInfoError = -1;
|
|
603 |
CntSimUtility::SimInfo simInfo = mAdnSimUtility->getSimInfo(getSimInfoError);
|
|
604 |
if (!getSimInfoError)
|
|
605 |
{
|
|
606 |
// sim entries are present
|
|
607 |
mAdnStoreEntries = simInfo.usedEntries;
|
|
608 |
if (mAdnStoreEntries > 0)
|
|
609 |
{
|
|
610 |
mAdnEntriesPresent = true;
|
|
611 |
}
|
|
612 |
}
|
|
613 |
|
|
614 |
//get number of SDN contacts
|
|
615 |
int sdnError = -1;
|
|
616 |
mSdnStorePresent = false;
|
|
617 |
if (!mSdnSimUtility)
|
|
618 |
{
|
|
619 |
mSdnSimUtility = new CntSimUtility(CntSimUtility::SdnStore, sdnError);
|
|
620 |
if (sdnError != 0)
|
|
621 |
{
|
|
622 |
delete mSdnSimUtility;
|
|
623 |
mSdnSimUtility = 0;
|
|
624 |
}
|
|
625 |
}
|
|
626 |
if (mSdnSimUtility)
|
|
627 |
{
|
|
628 |
int getSdnSimInfoError = 0;
|
|
629 |
CntSimUtility::SimInfo sdnSimInfo = mSdnSimUtility->getSimInfo(getSdnSimInfoError);
|
|
630 |
if (!getSdnSimInfoError)
|
|
631 |
{
|
|
632 |
mSdnStoreEntries = sdnSimInfo.usedEntries;
|
|
633 |
if (mSdnStoreEntries > 0)
|
|
634 |
{
|
|
635 |
mSdnStorePresent = true;
|
|
636 |
}
|
|
637 |
}
|
|
638 |
}
|
|
639 |
}
|
|
640 |
|
|
641 |
//dismiss progress dialog, if there are no SIM contacts
|
|
642 |
if(!mAdnEntriesPresent && !mSdnStorePresent)
|
|
643 |
{
|
|
644 |
emit closePopup();
|
|
645 |
showSimImportResults();
|
|
646 |
}
|
|
647 |
|
|
648 |
//disable sim import item, if there are no SIM contacts
|
|
649 |
if(!mAdnEntriesPresent && !mSdnStorePresent)
|
|
650 |
{
|
|
651 |
QString simImport(hbTrId("txt_phob_dblist_import_from_sim"));
|
|
652 |
QString simNoContacts(hbTrId("txt_phob_dblist_import_from_1_val_no_sim_contacts"));
|
|
653 |
|
|
654 |
mImportViewCallback.setListBoxItemText(simImport, simNoContacts);
|
|
655 |
mImportViewCallback.setListBoxItemEnabled(false);
|
|
656 |
}
|
|
657 |
|
|
658 |
//start SIM contacts import, if user tapped "SIM import"
|
|
659 |
// if(mImportSimPopup != NULL && mImportSimPopup->isActive())
|
|
660 |
// {
|
|
661 |
if (!startSimImport())
|
|
662 |
{
|
|
663 |
//dismiss wait note
|
|
664 |
emit closePopup();
|
|
665 |
mImportInProgress = false;
|
|
666 |
//and show error note
|
|
667 |
simInfoErrorMessage(KErrAccessDenied);
|
|
668 |
}
|
|
669 |
// }
|
|
670 |
CNT_EXIT
|
|
671 |
}
|
|
672 |
|
|
673 |
void CntSimEngine::simInfoErrorMessage(int infoError)
|
|
674 |
{
|
|
675 |
CNT_ENTRY
|
|
676 |
Q_UNUSED(infoError);
|
|
677 |
QString errorMessage;
|
|
678 |
errorMessage.append(hbTrId("txt_phob_info_sim_card_error"));
|
|
679 |
HbNotificationDialog::launchDialog(errorMessage);
|
|
680 |
mSimError = true;
|
|
681 |
CNT_EXIT
|
|
682 |
}
|
|
683 |
|
|
684 |
bool CntSimEngine::userCancelsImport(QString& aResults)
|
|
685 |
{
|
|
686 |
CNT_ENTRY
|
|
687 |
aResults = "";
|
|
688 |
|
|
689 |
bool boolResult = mImportInProgress && !mSimError;
|
|
690 |
|
|
691 |
if(boolResult)
|
|
692 |
{
|
|
693 |
aResults = hbTrId("txt_phob_dpophead_ln_contacts_imported").arg(mSaveCount).arg(mAdnStoreEntries + mSdnStoreEntries);
|
|
694 |
}
|
|
695 |
mImportInProgress = false;
|
|
696 |
CNT_EXIT
|
|
697 |
return boolResult;
|
|
698 |
}
|
|
699 |
|
|
700 |
|
|
701 |
|
|
702 |
|