82 bool ok = file.open(QIODevice::ReadOnly); |
81 bool ok = file.open(QIODevice::ReadOnly); |
83 if (ok) { |
82 if (ok) { |
84 reader.setDevice(&file); |
83 reader.setDevice(&file); |
85 if (reader.startReading() && reader.waitForFinished()) { |
84 if (reader.startReading() && reader.waitForFinished()) { |
86 QVersitContactImporter importer; |
85 QVersitContactImporter importer; |
87 QList<QContact> contacts = importer.importContacts(reader.results()); |
86 importer.importDocuments(reader.results()); |
88 QMap<int, QContactManager::Error> errors; |
87 QList<QContact> contacts = importer.contacts(); |
89 manager->saveContacts(&contacts, &errors); |
88 manager->saveContacts(&contacts, 0); |
90 } |
89 } |
91 } |
90 } |
92 |
|
93 |
|
94 } |
91 } |
95 |
92 |
96 void QMLContactManagerAsync::setManager(QString manager) |
93 void QMLContactManagerAsync::setManager(QString manager) |
97 { |
94 { |
98 delete qc; |
95 delete qc; |
99 qc = new QContactManager(manager); |
96 qc = new QContactManager(manager); |
100 if(!qc) |
|
101 qc = new QContactManager(); |
|
102 connect(qc, SIGNAL(contactsAdded(QList<QContactLocalId>)), this, SIGNAL(contactsAdded(QList<QContactLocalId>))); |
97 connect(qc, SIGNAL(contactsAdded(QList<QContactLocalId>)), this, SIGNAL(contactsAdded(QList<QContactLocalId>))); |
103 connect(qc, SIGNAL(contactsChanged(QList<QContactLocalId>)), this, SIGNAL(contactsChanged(QList<QContactLocalId>))); |
98 connect(qc, SIGNAL(contactsChanged(QList<QContactLocalId>)), this, SIGNAL(contactsChanged(QList<QContactLocalId>))); |
104 connect(qc, SIGNAL(contactsRemoved(QList<QContactLocalId>)), this, SIGNAL(contactsRemoved(QList<QContactLocalId>))); |
99 connect(qc, SIGNAL(contactsRemoved(QList<QContactLocalId>)), this, SIGNAL(contactsRemoved(QList<QContactLocalId>))); |
105 connect(qc, SIGNAL(relationshipsAdded(QList<QContactLocalId>)), this, SIGNAL(relationshipsAdded(QList<QContactLocalId>))); |
100 connect(qc, SIGNAL(relationshipsAdded(QList<QContactLocalId>)), this, SIGNAL(relationshipsAdded(QList<QContactLocalId>))); |
106 connect(qc, SIGNAL(relationshipsRemoved(QList<QContactLocalId>)), this, SIGNAL(relationshipsRemoved(QList<QContactLocalId>))); |
101 connect(qc, SIGNAL(relationshipsRemoved(QList<QContactLocalId>)), this, SIGNAL(relationshipsRemoved(QList<QContactLocalId>))); |
114 |
109 |
115 |
110 |
116 QString QMLContactManagerAsync::contactListToQString(const QList<QContactLocalId>& contactIds) const |
111 QString QMLContactManagerAsync::contactListToQString(const QList<QContactLocalId>& contactIds) const |
117 { |
112 { |
118 QString list; |
113 QString list; |
119 int i; |
|
120 |
114 |
121 for (i = 0; i < contactIds.count(); i++) { |
115 for (int i = 0; i < contactIds.count(); i++) { |
122 list += QString::number(contactIds.at(i)) + " "; |
116 list += QString::number(contactIds.at(i)) + ' '; |
123 } |
117 } |
124 |
118 |
125 return list; |
119 return list; |
126 } |
120 } |
127 |
121 |
128 QStringList QMLContactManagerAsync::contactListToQString(const QList<QContact>& contact) const |
122 QStringList QMLContactManagerAsync::contactListToQString(const QList<QContact>& contact) const |
129 { |
123 { |
130 QStringList list; |
124 QStringList list; |
131 int i; |
|
132 |
125 |
133 for (i = 0; i < contact.count(); i++) { |
126 for (int i = 0; i < contact.count(); i++) { |
134 list += qc->synthesizedDisplayLabel(contact.at(i)); |
127 list += qc->synthesizedDisplayLabel(contact.at(i)); |
135 } |
128 } |
136 |
129 |
137 return list; |
130 return list; |
138 } |
131 } |
139 |
132 |
140 int QMLContactManagerAsync::numContacts() |
133 int QMLContactManagerAsync::numContacts() |
141 { |
134 { |
142 QList<QContactLocalId> qlid; |
135 return qc->contactIds().count(); |
143 |
|
144 qlid = qc->contactIds(); |
|
145 |
|
146 return qlid.count(); |
|
147 } |
136 } |
148 |
137 |
149 void QMLContactManagerAsync::contacts() |
138 void QMLContactManagerAsync::contacts() |
150 { |
139 { |
151 m_contactIds.clear(); |
140 m_contactIds.clear(); |
168 request->deleteLater(); |
157 request->deleteLater(); |
169 return; // ignore these results. |
158 return; // ignore these results. |
170 } |
159 } |
171 |
160 |
172 if(request->contacts().count() > 0) { |
161 if(request->contacts().count() > 0) { |
173 QContact c; |
162 foreach(const QContact& c, request->contacts()) { |
174 foreach(c, request->contacts()) { |
|
175 QmlContact qmlc(c); |
163 QmlContact qmlc(c); |
176 emit contactsLoaded(&qmlc); |
164 emit contactsLoaded(&qmlc); |
177 } |
165 } |
178 } |
166 } |
179 |
167 |
180 // check to see if the request status is "finished" - clean up. |
168 // check to see if the request status is "finished" - clean up. |
181 if (newState == QContactAbstractRequest::FinishedState) { |
169 if (newState == QContactAbstractRequest::FinishedState) { |
182 request->deleteLater(); |
170 request->deleteLater(); |
183 emit contactsLoadedDone(); |
171 emit contactsLoadedDone(); |
184 } |
172 } |
185 |
|
186 } |
173 } |
187 |
174 |
188 QString QMLContactManagerAsync::idToName(QString name) |
175 QString QMLContactManagerAsync::idToName(QString name) |
189 { |
176 { |
190 QContact c = qc->contact(name.toInt()); |
177 QContact c = qc->contact(name.toInt()); |