43 #include "cntsymbiansimengine.h" |
43 #include "cntsymbiansimengine.h" |
44 #include "cntsimstore.h" |
44 #include "cntsimstore.h" |
45 #include <qcontactfetchrequest.h> |
45 #include <qcontactfetchrequest.h> |
46 |
46 |
47 CntSimContactLocalIdFetchRequest::CntSimContactLocalIdFetchRequest(CntSymbianSimEngine *engine, QContactLocalIdFetchRequest *req) |
47 CntSimContactLocalIdFetchRequest::CntSimContactLocalIdFetchRequest(CntSymbianSimEngine *engine, QContactLocalIdFetchRequest *req) |
48 :CntAbstractSimRequest(engine), |
48 :CntAbstractSimRequest(engine, req) |
49 m_req(req) |
|
50 { |
49 { |
51 connect( simStore(), SIGNAL(readComplete(QList<QContact>, QContactManager::Error)), |
50 connect( simStore(), SIGNAL(readComplete(QList<QContact>, QContactManager::Error)), |
52 this, SLOT(readComplete(QList<QContact>, QContactManager::Error)), Qt::QueuedConnection ); |
51 this, SLOT(readComplete(QList<QContact>, QContactManager::Error)), Qt::QueuedConnection ); |
53 } |
52 } |
54 |
53 |
55 CntSimContactLocalIdFetchRequest::~CntSimContactLocalIdFetchRequest() |
54 CntSimContactLocalIdFetchRequest::~CntSimContactLocalIdFetchRequest() |
56 { |
55 { |
57 cancel(); |
56 cancel(); |
58 } |
57 } |
59 |
58 |
60 bool CntSimContactLocalIdFetchRequest::start() |
59 void CntSimContactLocalIdFetchRequest::run() |
61 { |
60 { |
|
61 QContactLocalIdFetchRequest *r = req<QContactLocalIdFetchRequest>(); |
|
62 |
|
63 if (!r->isActive()) |
|
64 return; |
|
65 |
62 // Contacts are fetched starting from index 1, all slots are read |
66 // Contacts are fetched starting from index 1, all slots are read |
63 // since slots may be not filled in a sequence. |
67 // since slots may be not filled in a sequence. |
|
68 int index = 1; |
64 int numSlots = simStore()->storeInfo().iTotalEntries; |
69 int numSlots = simStore()->storeInfo().iTotalEntries; |
65 QContactManager::Error error = simStore()->read(1, numSlots); |
70 |
66 if (error == QContactManager::NoError) |
71 QContactManager::Error error = QContactManager::NoError; |
67 QContactManagerEngine::updateRequestState(m_req, QContactAbstractRequest::ActiveState); |
72 if (!simStore()->read(index, numSlots, &error)) { |
68 return (error == QContactManager::NoError); |
73 QContactManagerEngine::updateContactLocalIdFetchRequest(r, QList<QContactLocalId>(), error, QContactAbstractRequest::FinishedState); |
69 } |
|
70 |
|
71 bool CntSimContactLocalIdFetchRequest::cancel() |
|
72 { |
|
73 if (m_req->isActive()) { |
|
74 simStore()->cancel(); |
|
75 QContactManagerEngine::updateRequestState(m_req, QContactAbstractRequest::CanceledState); |
|
76 return true; |
|
77 } |
74 } |
78 return false; |
|
79 } |
75 } |
80 |
76 |
81 void CntSimContactLocalIdFetchRequest::readComplete(QList<QContact> contacts, QContactManager::Error error) |
77 void CntSimContactLocalIdFetchRequest::readComplete(QList<QContact> contacts, QContactManager::Error error) |
82 { |
78 { |
83 if (!m_req->isActive()) |
79 QContactLocalIdFetchRequest *r = req<QContactLocalIdFetchRequest>(); |
|
80 |
|
81 if (!r->isActive()) |
84 return; |
82 return; |
|
83 |
|
84 // Sometimes the sim store will return server busy error. All we can do is |
|
85 // wait and try again. The error seems to occur if we try to read from the |
|
86 // store right after writing some contacts to it. |
|
87 // This was observed with S60 5.0 HW (Tube). |
|
88 if (error == QContactManager::UnspecifiedError && |
|
89 simStore()->lastAsyncError() == KErrServerBusy) |
|
90 { |
|
91 if (waitAndRetry()) |
|
92 return; |
|
93 } |
85 |
94 |
86 // Filter & sort results |
95 // Filter & sort results |
87 QList<QContact> filteredAndSorted; |
96 QList<QContact> filteredAndSorted; |
88 for (int i=0; i<contacts.count(); i++) { |
97 for (int i=0; i<contacts.count(); i++) { |
89 if (QContactManagerEngine::testFilter(m_req->filter(), contacts.at(i))) |
98 if (QContactManagerEngine::testFilter(r->filter(), contacts.at(i))) |
90 QContactManagerEngine::addSorted(&filteredAndSorted, contacts.at(i), m_req->sorting()); |
99 QContactManagerEngine::addSorted(&filteredAndSorted, contacts.at(i), r->sorting()); |
91 } |
100 } |
92 |
101 |
93 // Convert to QContactLocalId-list |
102 // Convert to QContactLocalId-list |
94 QList<QContactLocalId> filteredAndSortedIds; |
103 QList<QContactLocalId> filteredAndSortedIds; |
95 for (int i=0; i<filteredAndSorted.count(); i++) { |
104 for (int i=0; i<filteredAndSorted.count(); i++) { |
96 filteredAndSortedIds << filteredAndSorted.at(i).localId(); |
105 filteredAndSortedIds << filteredAndSorted.at(i).localId(); |
97 } |
106 } |
98 |
107 |
99 // Complete the request |
108 // Complete the request |
100 QContactManagerEngine::updateRequestState(m_req, QContactAbstractRequest::FinishedState); |
109 QContactManagerEngine::updateContactLocalIdFetchRequest(r, filteredAndSortedIds, error, QContactAbstractRequest::FinishedState); |
101 QContactManagerEngine::updateContactLocalIdFetchRequest(m_req, filteredAndSortedIds, error); |
|
102 } |
110 } |