Changeset View
Changeset View
Standalone View
Standalone View
resources/contacts/contactsresource.cpp
Show First 20 Lines • Show All 247 Lines • ▼ Show 20 Line(s) | 245 | } else if (item.hasPayload<KContacts::ContactGroup>()) { | |||
---|---|---|---|---|---|
248 | const QString fileName = directoryPath + QDir::separator() + group.id() + QLatin1String(".ctg"); | 248 | const QString fileName = directoryPath + QDir::separator() + group.id() + QLatin1String(".ctg"); | ||
249 | 249 | | |||
250 | QFile file(fileName); | 250 | QFile file(fileName); | ||
251 | if (!file.open(QIODevice::WriteOnly)) { | 251 | if (!file.open(QIODevice::WriteOnly)) { | ||
252 | cancelTask(i18n("Unable to write to file '%1': %2", fileName, file.errorString())); | 252 | cancelTask(i18n("Unable to write to file '%1': %2", fileName, file.errorString())); | ||
253 | return; | 253 | return; | ||
254 | } | 254 | } | ||
255 | 255 | | |||
256 | KContacts::ContactGroupTool::convertToXml(group, &file); | 256 | QString *errorMessage = new QString(); | ||
dvratil: Don't allocate QString on heap or use QScopedPointer/std::unqiue_ptr. Preferably just allocate… | |||||
257 | if (!KContacts::ContactGroupTool::convertToXml(group, &file, errorMessage)) { | ||||
258 | cancelTask(i18n("Unable to write to file '%1': %2", fileName, *errorMessage)); | ||||
259 | } | ||||
260 | delete errorMessage; | ||||
257 | 261 | | |||
258 | file.close(); | 262 | file.close(); | ||
259 | 263 | | |||
260 | newItem.setRemoteId(group.id() + QLatin1String(".ctg")); | 264 | newItem.setRemoteId(group.id() + QLatin1String(".ctg")); | ||
261 | } else { | 265 | } else { | ||
262 | qCWarning(CONTACTSRESOURCES_LOG) << "got item without (usable) payload, ignoring it"; | 266 | qCWarning(CONTACTSRESOURCES_LOG) << "got item without (usable) payload, ignoring it"; | ||
263 | } | 267 | } | ||
264 | 268 | | |||
Show All 30 Lines | 298 | } else if (item.hasPayload<KContacts::ContactGroup>()) { | |||
295 | const KContacts::ContactGroup group = item.payload<KContacts::ContactGroup>(); | 299 | const KContacts::ContactGroup group = item.payload<KContacts::ContactGroup>(); | ||
296 | 300 | | |||
297 | QFile file(fileName); | 301 | QFile file(fileName); | ||
298 | if (!file.open(QIODevice::WriteOnly)) { | 302 | if (!file.open(QIODevice::WriteOnly)) { | ||
299 | cancelTask(i18n("Unable to write to file '%1': %2", fileName, file.errorString())); | 303 | cancelTask(i18n("Unable to write to file '%1': %2", fileName, file.errorString())); | ||
300 | return; | 304 | return; | ||
301 | } | 305 | } | ||
302 | 306 | | |||
303 | KContacts::ContactGroupTool::convertToXml(group, &file); | 307 | QString *errorMessage = new QString(); | ||
dvratil: Same as above. | |||||
308 | if (!KContacts::ContactGroupTool::convertToXml(group, &file, errorMessage)) { | ||||
309 | cancelTask(i18n("Unable to write to file '%1': %2", fileName, *errorMessage)); | ||||
310 | } | ||||
311 | delete errorMessage; | ||||
304 | 312 | | |||
305 | file.close(); | 313 | file.close(); | ||
306 | 314 | | |||
307 | newItem.setRemoteId(item.remoteId()); | 315 | newItem.setRemoteId(item.remoteId()); | ||
308 | } else { | 316 | } else { | ||
309 | cancelTask(i18n("Received item with unknown payload %1", item.mimeType())); | 317 | cancelTask(i18n("Received item with unknown payload %1", item.mimeType())); | ||
310 | return; | 318 | return; | ||
311 | } | 319 | } | ||
▲ Show 20 Lines • Show All 196 Lines • Show Last 20 Lines |
Don't allocate QString on heap or use QScopedPointer/std::unqiue_ptr. Preferably just allocate it on stack and just pass a pointer to it to the function.