Example #1
0
bool MCOPDCOPObject::processDynamic(const TQCString &fun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData)
{
	TQMap<TQCString, MCOPEntryInfo *>::iterator it;
	for(it = d->dynamicFunctions.begin(); it != d->dynamicFunctions.end(); ++it)
	{
		MCOPEntryInfo *entry = it.data();

		if((entry->functionName() + entry->signature()) == fun)
		{
			TQCString type = entry->functionType();

			if(type == "void")
			{
				replyType = type;

				Arts::Buffer *result = callFunction(entry, objId(), data);
				
				if(result != 0)
					delete result;
			}
			else if(type == "string")
			{
				replyType = "TQCString";
				
				TQDataStream reply(replyData, IO_WriteOnly);
				reply << "fooo!";
			}
			else if(type == "long")
			{
				replyType = type;

				long returnCode = -1;
				
				Arts::Buffer *result = callFunction(entry, objId(), data);
			
				if(result != 0)
				{
					returnCode = result->readLong();
					delete result;
				}
				
				TQDataStream reply(replyData, IO_WriteOnly);
				reply << returnCode;
			}
			
			return true;
		}
	}

	return false;
}
void PropertyPanel::rereadPortProperties()
{
	//kdDebug() << QString("PropertyPanel::rereadPortProperties") << endl;
	if(!port) return; // sanity check

	std::string dataType = port->PortDesc.type().dataType;
	if(isEnum(dataType))
	{
		constantValueEdit->hide();
		constantValueComboBox->show();

		fillEnumChoices(dataType);
	}
	else
	{
		constantValueEdit->show();
		constantValueComboBox->hide();
	}

	if( port->PortDesc.hasValue() )
	{
		pvConstantButton->setChecked( true );

		QString constValue;

		Arts::Any value = port->PortDesc.value();
		Arts::Buffer b;
		b.write(value.value);

		if(isEnum(value.type))
		{
			long v = b.readLong();
			constantValueComboBox->setCurrentItem(findEnumIndex(value.type,v));
		}
		else
		{
			if(value.type == "float")
				constValue.sprintf("%2.4f", b.readFloat());
			else if(value.type == "long")
				constValue.sprintf("%ld", b.readLong());
			else if(value.type == "string")
			{
				std::string s;
				b.readString(s);
				constValue = s.c_str();
			}
			else if(value.type == "boolean")
			{
				if(b.readBool())
					constValue = "true";
				else
					constValue = "false";
			}
			else constValue = ("*unknown type* " + value.type).c_str();

			constantValueEdit->setText( constValue );
		}
	}
	else if( port->PortDesc.isConnected() )
		pvConnectionButton->setChecked( true );
	else
	{
		pvNotSetButton->setChecked( true );
		constantValueEdit->clear();
	}

	pvConnectionButton->setEnabled( port->PortDesc.isConnected() );
}
void PropertyPanel::writePortProperties( bool reread )
{
	//kdDebug() << QString("PropertyPanel::writePortProperties") << endl;
	if(!port) return; // sanity check

	bool dirty = false;

	if(!pvConnectionButton->isChecked())
	{
		if(port->PortDesc.isConnected())
		{
			port->PortDesc.disconnectAll();
			dirty = true;
		}
	}

	if(pvNotSetButton->isChecked() &&
		(port->PortDesc.isConnected() || port->PortDesc.hasValue()))
	{
		port->PortDesc.hasValue(false);
		dirty = true;
	}

	if(pvConstantButton->isChecked())
	{
		std::string type = port->PortDesc.type().dataType;
		QString newvalue = constantValueEdit->text();

		Arts::Any a;
		a.type = type;
		Arts::Buffer b;
		if(type == "float")
			b.writeFloat(newvalue.toFloat());
		else if(type == "long")
			b.writeLong(newvalue.toLong());
		else if(type == "string")
			b.writeString(newvalue.local8Bit().data());
		else if(type == "boolean")
		{
			b.writeBool(newvalue.upper() == "TRUE" || newvalue.upper() == "T"
						|| newvalue == "1");
		}
		else if(isEnum(type))
		{
			b.writeLong(selectedEnumValue(type));
		}

		if(b.size() > 0)
		{
			b.read(a.value, b.size());
			port->PortDesc.value(a);
			dirty = true;
		}
	}

	if( dirty )
		emit portPropertiesChanged( port );

	if( reread )
		rereadPortProperties();
}