Exemplo n.º 1
0
void Flow::commit() {

	// Lost informations!
	UInt32 size = 0;
	list<UInt64> lost;
	UInt64 current=stage;
	UInt32 count=0;
	map<UInt64,Fragment*>::const_iterator it=_fragments.begin();
	while(it!=_fragments.end()) {
		current = it->first-current-2;
		size += Util::Get7BitValueSize(current);
		lost.push_back(current);
		current = it->first;
		while(++it!=_fragments.end() && it->first==(++current))
			++count;
		size += Util::Get7BitValueSize(count);
		lost.push_back(count);
		--current;
		count=0;
	}

	UInt32 bufferSize = _pPacket ? ((_pPacket->fragments>0x3F00) ? 0 : (0x3F00-_pPacket->fragments)) : 0x7F;
	if(writer.signature.empty())
		bufferSize=0;

	PacketWriter& ack = _band.writeMessage(0x51,Util::Get7BitValueSize(id)+Util::Get7BitValueSize(bufferSize)+Util::Get7BitValueSize(stage)+size);
	UInt32 pos = ack.position();
	ack.write7BitLongValue(id);
	ack.write7BitValue(bufferSize);
	ack.write7BitLongValue(stage);

	list<UInt64>::const_iterator it2;
	for(it2=lost.begin();it2!=lost.end();++it2)
		ack.write7BitLongValue(*it2);

	commitHandler();
	writer.flush();
}
Exemplo n.º 2
0
void GraphicalBoardFrame::keyPressEvent(QKeyEvent *event)
{
    enum { Backspace = 0, Delete, Submit, Commit, Append } mode;

    switch (event->key())
    {
    case Qt::Key_Backspace:
        mode = Backspace;
        break;

    case Qt::Key_Delete:
        mode = Delete;
        break;

    case Qt::Key_Return:
    case Qt::Key_Enter:
        mode = event->modifiers() & Qt::ShiftModifier || event->modifiers() & Qt::ControlModifier || event->modifiers() & Qt::MetaModifier? Commit : Submit;
        break;

    default:
        mode = Append;
        break;
    }

    if (!hasCandidate())
    {
        event->ignore();
        return;
    }

    switch (mode)
    {

    // these modes need a candidate
    case Submit:
        submitHandler();
        break;
    
    case Commit:
        commitHandler();
        break;
    
    default:
        if (!hasArrow())
        {
            event->ignore();
            return;
        }

        switch (mode)
        {

        // these modes need an arrow
        case Delete:
            deleteHandler();
            break;
        
        case Backspace:
            backspaceHandler();
            break;
        
        case Append:
			if (event->text().isEmpty() ||
				(event->text().at(0) >= 0xa8 && event->text().at(0) <= 0xb8) || // combining character
				(event->text().at(0) >= 0x2b9 && event->text().at(0) <= 0x2ff)) // combining character
				break; // let AltGr (Ctrl+Alt) and other composite keyboard events slip through
            else if (event->modifiers() & Qt::AltModifier || event->modifiers() & Qt::ControlModifier)
            {
				if (!event->text().isEmpty() &&
					((event->text().at(0) >= 'a' && event->text().at(0) <= 'z') ||
					 (event->text().at(0) >= 'A' && event->text().at(0) <= 'Z')))
				{
					event->ignore();
					return;
				}
            }
    
            appendHandler(event->text(), event->modifiers() & Qt::ShiftModifier);
            break;

        case Commit:
        case Submit:
            break;
        }
        break;
    }

    prepare();

    event->accept();
}