|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "cntsimcontactsaverequest.h" |
|
43 #include "cntsymbiansimengine.h" |
|
44 #include "cntsimstore.h" |
|
45 #include <qcontactsaverequest.h> |
|
46 #include <QTimer> |
|
47 |
|
48 CntSimContactSaveRequest::CntSimContactSaveRequest(CntSymbianSimEngine *engine, QContactSaveRequest *req) |
|
49 :CntAbstractSimRequest(engine), |
|
50 m_req(req) |
|
51 { |
|
52 connect( simStore(), SIGNAL(writeComplete(QContact, QContactManager::Error)), |
|
53 this, SLOT(writeComplete(QContact, QContactManager::Error)), Qt::QueuedConnection ); |
|
54 } |
|
55 |
|
56 CntSimContactSaveRequest::~CntSimContactSaveRequest() |
|
57 { |
|
58 cancel(); |
|
59 } |
|
60 |
|
61 bool CntSimContactSaveRequest::start() |
|
62 { |
|
63 if (simStore()->isBusy()) |
|
64 return false; |
|
65 |
|
66 m_contacts = m_req->contacts(); |
|
67 m_errorMap.clear(); |
|
68 m_index = 0; |
|
69 singleShotTimer(0, this, SLOT(writeNext())); |
|
70 QContactManagerEngine::updateRequestState(m_req, QContactAbstractRequest::ActiveState); |
|
71 return true; |
|
72 } |
|
73 |
|
74 bool CntSimContactSaveRequest::cancel() |
|
75 { |
|
76 if (m_req->isActive()) { |
|
77 cancelTimer(); |
|
78 simStore()->cancel(); |
|
79 QContactManagerEngine::updateRequestState(m_req, QContactAbstractRequest::CanceledState); |
|
80 return true; |
|
81 } |
|
82 return false; |
|
83 } |
|
84 |
|
85 void CntSimContactSaveRequest::writeComplete(QContact contact, QContactManager::Error error) |
|
86 { |
|
87 if (error) |
|
88 m_errorMap.insert(m_index, error); |
|
89 engine()->updateDisplayLabel(contact); |
|
90 m_contacts[m_index] = contact; |
|
91 m_index++; |
|
92 writeNext(); |
|
93 } |
|
94 |
|
95 void CntSimContactSaveRequest::writeNext() |
|
96 { |
|
97 if (m_req->isCanceled()) |
|
98 return; |
|
99 |
|
100 // All contacts written? |
|
101 if (m_index >= m_contacts.count()) |
|
102 { |
|
103 // Take first error from errormap (if any) |
|
104 QContactManager::Error error = QContactManager::NoError; |
|
105 if (m_errorMap.count()) |
|
106 error = m_errorMap.begin().value(); |
|
107 |
|
108 QContactManagerEngine::updateRequestState(m_req, QContactAbstractRequest::FinishedState); |
|
109 QContactManagerEngine::updateContactSaveRequest(m_req, m_contacts, error, m_errorMap); |
|
110 return; |
|
111 } |
|
112 |
|
113 // Get next contact |
|
114 QContact contact = m_contacts.at(m_index); |
|
115 |
|
116 // Validate & write contact |
|
117 QContactManager::Error error; |
|
118 if (engine()->validateContact(contact, error)) |
|
119 error = simStore()->write(contact); |
|
120 |
|
121 if (error) { |
|
122 m_errorMap.insert(m_index, error); |
|
123 m_index++; |
|
124 singleShotTimer(0, this, SLOT(writeNext())); |
|
125 } |
|
126 } |