bool deserializeData(QAbstractItemModel *model, QDataStream *stream) { qint32 length; *stream >> length; if ( stream->status() != QDataStream::Ok ) return false; if (length < 0) { stream->setStatus(QDataStream::ReadCorruptData); return false; } // Limit the loaded number of items to model's maximum. const QVariant maxItems = model->property("maxItems"); Q_ASSERT( maxItems.isValid() ); Q_ASSERT( maxItems.toInt() > 0 ); length = qMin( length, maxItems.toInt() ) - model->rowCount(); if ( !model->insertRows(0, length) ) return false; for(qint32 i = 0; i < length && stream->status() == QDataStream::Ok; ++i) { QVariantMap data; deserializeData(stream, &data); model->setData( model->index(i, 0), data, contentType::data ); } return stream->status() == QDataStream::Ok; }
Result dispatch(JSContext *cx, JSObject *thisobj, const char *dataPropName, const char *methodName, Result noHandler) { if (!data) return fail; JSBool found; if (!JS_HasProperty(cx, thisobj, methodName, &found)) return fail; if (!found) return noHandler; // Create event object. jsval v; if (!deserializeData(cx, &v)) return fail; JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL); if (!obj || !JS_DefineProperty(cx, obj, dataPropName, v, NULL, NULL, 0)) return fail; // Call event handler. jsval argv[1] = { OBJECT_TO_JSVAL(obj) }; jsval rval = JSVAL_VOID; return Result(JS_CallFunctionName(cx, thisobj, methodName, 1, argv, &rval)); }
void MapBrowserWidget::setValueInternal(const QVariant& add, bool removeOld) { Q_UNUSED(add); Q_UNUSED(removeOld); m_slotMapChanged_enabled = false; //kDebug() << "add:" << add; //kDebug() << "originalValue():" << originalValue(); deserializeData(originalValue()); m_slotMapChanged_enabled = true; }
void XBeeNodeImpl::handleZigBeePacketReceived(const XBeeFrame& frame) { ZigBeeReceivePacket receivePacket; Poco::MemoryInputStream mistr(frame.data(), frame.dataSize()); Poco::BinaryReader reader(mistr, Poco::BinaryReader::NETWORK_BYTE_ORDER); deserializeDeviceAddress(reader, receivePacket.deviceAddress); deserializeNetworkAddress(reader, receivePacket.networkAddress); reader >> receivePacket.options; deserializeData(reader, reader.available(), receivePacket.payload); zigBeePacketReceived(receivePacket); }
void ActionHandler::addItem(const QByteArray &data, const QString &format, const QModelIndex &index) { ClipboardBrowser *c = m_wnd->browserForItem(index); if (c == NULL) return; QVariantMap dataMap; if (format == mimeItems) deserializeData(&dataMap, data); else dataMap.insert(format, data); c->model()->setData(index, dataMap, contentType::updateData); }
void MapBrowserWidget::setValueInternal(const QVariant& add, bool removeOld ) { Q_UNUSED(removeOld); //if(isReadOnly()) // return; m_slotMapChanged_enabled = false; //disable change editing //if(removeOld); kDebug() << "add:" << add; kDebug() << "originalValue():" << originalValue(); //deserializeData((removeOld ? QVariant() : originalValue())); deserializeData(originalValue()); m_slotMapChanged_enabled = true; }
void XBeeNodeImpl::handleCommandResponse(const XBeeFrame& frame) { ATCommandResponse commandResponse; Poco::MemoryInputStream mistr(frame.data(), frame.dataSize()); Poco::BinaryReader reader(mistr, Poco::BinaryReader::NETWORK_BYTE_ORDER); reader >> commandResponse.frameID; char command[2]; reader >> command[0] >> command[1]; commandResponse.command.assign(command, 2); reader >> commandResponse.status; deserializeData(reader, frame.dataSize() - 4, commandResponse.data); commandResponseReceived(commandResponse); }
void XBeeNodeImpl::handleExplicitAddressingZigBeePacketReceived(const XBeeFrame& frame) { ExplicitAddressingZigBeeReceivePacket receivePacket; Poco::MemoryInputStream mistr(frame.data(), frame.dataSize()); Poco::BinaryReader reader(mistr, Poco::BinaryReader::NETWORK_BYTE_ORDER); deserializeDeviceAddress(reader, receivePacket.deviceAddress); deserializeNetworkAddress(reader, receivePacket.networkAddress); reader >> receivePacket.sourceEndpoint >> receivePacket.destinationEndpoint >> receivePacket.clusterID >> receivePacket.profileID >> receivePacket.options; deserializeData(reader, reader.available(), receivePacket.payload); explicitAddressingZigBeePacketReceived(receivePacket); }
void ActionHandler::closeAction(Action *action) { QString msg; QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information; if ( action->actionFailed() || action->exitStatus() != QProcess::NormalExit ) { msg += tr("Error: %1\n").arg(action->errorString()) + action->errorOutput(); icon = QSystemTrayIcon::Critical; } else if ( action->exitCode() != 0 ) { msg += tr("Exit code: %1\n").arg(action->exitCode()) + action->errorOutput(); icon = QSystemTrayIcon::Warning; } else if ( !action->inputFormats().isEmpty() ) { QModelIndex index = action->index(); ClipboardBrowser *c = m_wnd->browserForItem(index); if (c) { QStringList removeFormats; if ( action->inputFormats().size() > 1 ) { QVariantMap data; deserializeData( &data, action->input() ); removeFormats = data.keys(); } else { removeFormats.append( action->inputFormats()[0] ); } removeFormats.removeAll( action->outputFormat() ); if ( !removeFormats.isEmpty() ) c->model()->setData(index, removeFormats, contentType::removeFormats); } } if ( !msg.isEmpty() ) m_wnd->showMessage( tr("Command %1").arg(quoteString(action->command())), msg, icon ); m_activeActionDialog->actionFinished(action); m_actionData.remove( action->property("COPYQ_ACTION_ID").toByteArray() ); action->deleteLater(); if (!hasRunningAction()) emit hasRunningActionChanged(); }
void XBeeNodeImpl::handleIODataReceived(const XBeeFrame& frame) { ReceivePacket receivePacket; Poco::MemoryInputStream mistr(frame.data(), frame.dataSize()); Poco::BinaryReader reader(mistr, Poco::BinaryReader::NETWORK_BYTE_ORDER); if (frame.type() == XBeeFrame::XBEE_FRAME_RECEIVE_PACKET_64BIT_ADDRESS_IO) { deserializeDeviceAddress(reader, receivePacket.deviceOrNetworkAddress); } else { deserializeNetworkAddress(reader, receivePacket.deviceOrNetworkAddress); } reader >> receivePacket.rssi >> receivePacket.options; deserializeData(reader, reader.available(), receivePacket.payload); ioDataReceived(receivePacket); }
bool deserializeData(QAbstractItemModel *model, QFile *file) { QDataStream stream(file); return deserializeData(model, &stream); }
bool deserializeData(QVariantMap *data, const QByteArray &bytes) { QDataStream out(bytes); deserializeData(&out, data); return out.status() == QDataStream::Ok; }