bool QOrganizerSimulatorEngine::saveItem(QOrganizerItem* theOrganizerItem, QOrganizerItemChangeSet& changeSet, QOrganizerManager::Error* error) { Connection *con = Connection::instance(); if (!con->mNotifySimulator) return QOrganizerItemMemoryEngine::saveItem(theOrganizerItem, changeSet, error); // translate local id -> remote id QOrganizerItem item = *theOrganizerItem; con->translateItemIds(&item, con->mLocalToRemote); bool newItem = item.id().isNull(); // save remotely QLocalSocket *sendSocket = con->sendSocket(); Simulator::SaveOrganizerItemReply reply = RemoteMetacall<Simulator::SaveOrganizerItemReply>::call( sendSocket, TimeoutSync, "requestSaveOrganizerItem", item); *error = reply.error; // if it failed, stop if (reply.error != QOrganizerManager::NoError) return false; // save locally if (!QOrganizerItemMemoryEngine::saveItem(theOrganizerItem, changeSet, error)) return false; // it's already saved remotely - revert? if (newItem) { con->mRemoteToLocal.items.insert(reply.savedItem.id(), theOrganizerItem->id()); con->mLocalToRemote.items.insert(theOrganizerItem->id(), reply.savedItem.id()); } return true; }
// test saving of a detail with an empty field. QOrganizerItemLocation four; four.setLabel(""); oi.saveDetail(&four); QVERIFY(oi.details(QOrganizerItemLocation::DefinitionName).count() == 2); QVERIFY(!four.variantValues().isEmpty()); // an empty qstring is not invalid; make sure it exists in the detail. // ensure that clearing a contact's details works correctly QOrganizerItemPriority priorityDetail; priorityDetail.setPriority(QOrganizerItemPriority::VeryHighPriority); oi.saveDetail(&priorityDetail); QCOMPARE(oi.detail(QOrganizerItemPriority::DefinitionName).value(QOrganizerItemPriority::FieldPriority).toInt(), static_cast<int>(QOrganizerItemPriority::VeryHighPriority)); QVERIFY(oi.details().size() > 0); QVERIFY(!oi.isEmpty()); QOrganizerItemId oldId = oi.id(); oi.clearDetails(); QCOMPARE(oi.details().size(), 1); // always has an item type. QCOMPARE(oi.detail(QOrganizerItemPriority::DefinitionName).value(QOrganizerItemPriority::FieldPriority), QString()); QVERIFY(oi.isEmpty()); QCOMPARE(oi.id(), oldId); // id shouldn't change. } void tst_QOrganizerItem::displayLabel() { QOrganizerItem oi; QString label = oi.displayLabel(); QVERIFY(label.isEmpty()); oi.setDisplayLabel("Test Event Display Label"); QVERIFY(oi.displayLabel() == QString("Test Event Display Label"));