/*! \brief Convert the current data in the record model to an NDEF message. */ QNdefMessage* NfcModelToNdef::convertToNdefMessage() { QNdefMessage* ndefMessage = new QNdefMessage(); NfcTypes::MessageType curMessageType; NfcTypes::RecordContent curRecordContent; int curRecordIndex = 0; if (m_nfcStats) { m_nfcStats->resetComposedMsgCount(); } //qDebug() << "NfcModelToNdef::convertToNdefMessage() Record item array size: " << recordItems.size(); // Go through array and convert the data to Ndef Records while(curRecordIndex < m_recordItems.size()) { NfcRecordItem* curItem = m_recordItems[curRecordIndex]; curRecordContent = curItem->recordContent(); curMessageType = curItem->messageType(); // If we find a new record header, check the message type // and convert this to a QNdefRecord, which is appended to the // ndefMessage. if (curRecordContent == NfcTypes::RecordHeader) { // Starting a new Ndef Record int parseEndIndex = -1; curMessageType = curItem->messageType(); if (m_nfcStats) { m_nfcStats->incComposedMsgCount(curMessageType); } switch (curMessageType) { case NfcTypes::MsgSmartPoster: ndefMessage->append(*convertSpFromModel(curRecordIndex, parseEndIndex)); break; case NfcTypes::MsgUri: ndefMessage->append(*convertUriFromModel(curRecordIndex, parseEndIndex, true)); break; case NfcTypes::MsgText: ndefMessage->append(*convertTextFromModel(curRecordIndex, parseEndIndex, true)); break; case NfcTypes::MsgSms: ndefMessage->append(*convertSmsFromModel(curRecordIndex, parseEndIndex)); break; case NfcTypes::MsgBusinessCard: ndefMessage->append(*convertBusinessCardFromModel(curRecordIndex, parseEndIndex)); break; case NfcTypes::MsgSocialNetwork: ndefMessage->append(*convertSocialNetworkFromModel(curRecordIndex, parseEndIndex)); break; case NfcTypes::MsgGeo: ndefMessage->append(*convertGeoFromModel(curRecordIndex, parseEndIndex)); break; case NfcTypes::MsgStore: ndefMessage->append(*convertStoreFromModel(curRecordIndex, parseEndIndex)); break; case NfcTypes::MsgImage: ndefMessage->append(*convertImageFromModel(curRecordIndex, parseEndIndex, true)); break; case NfcTypes::MsgCustom: ndefMessage->append(*convertCustomFromModel(curRecordIndex, parseEndIndex)); break; case NfcTypes::MsgLaunchApp: ndefMessage->append(*convertLaunchAppFromModel(curRecordIndex, parseEndIndex)); break; case NfcTypes::MsgAndroidAppRecord: ndefMessage->append(*convertAndroidAppRecordFromModel(curRecordIndex, parseEndIndex)); break; default: // MsgAnnotatedUrl, MsgCombination and a few others // are just templates to add multiple records // at once and don't exist as a type in the final model. qDebug() << "Warning: don't know how to handle this message type in NfcModelToNdef::convertToNdefMessage()."; break; } if (parseEndIndex == curRecordIndex || parseEndIndex == -1) { // Record wasn't parsed // Skip it qDebug() << "Warning: unable to parse record " << curRecordIndex; curRecordIndex++; } else { // Parse end index is set - jump over the already parsed items. // parseEndIndex is the index of the next item to be looked at, // so no need to increment here. curRecordIndex = parseEndIndex; } } else { // It shouldn't be possible to have a different record type without // having a header item before, so this would be an error in the UI qDebug() << "Error in model: new message type without header item at index " << curRecordIndex << " (can be the case while deleting a record)"; curRecordIndex++; } } return ndefMessage; }