Ejemplo n.º 1
0
QScriptValue scriptRequestInfo(QScriptContext *context, QScriptEngine *engine)
{
	if (context->argumentCount() < 2)
		return context->throwError("qutim.requestInfo() takes at least 2 arguments");
	QObject *object = context->argument(0).toQObject();
	if (!object)
		return context->throwError("First argument must be QObject");
	QScriptValue func = context->argument(1);
	if (!func.isFunction())
		return context->throwError("Second argument must be callback");
	InfoRequestFactory *factory = InfoRequestFactory::factory(object);
	QScriptValue errorFunc = context->argument(2);
	if (!factory || factory->supportLevel(object) <= InfoRequestFactory::Unavailable) {
		if (errorFunc.isFunction()) {
			qDebug() << Q_FUNC_INFO;
			QScriptValue error = engine->newObject();
			error.setProperty(QLatin1String("name"), QLatin1String("NotSupported"));
			error.setProperty(QLatin1String("text"), QLatin1String("Unit does not support information request"));
			QList<QScriptValue> args;
			args << error;
			errorFunc.call(errorFunc, args);
		}
		return engine->undefinedValue();
	}
	InfoRequest *request = factory->createrDataFormRequest(object);
	new ScriptInfoRequest(func, errorFunc, request);
	return engine->undefinedValue();
}
Ejemplo n.º 2
0
void QuickContactInfo::show(QObject *object)
{
	InfoRequestFactory *factory = InfoRequestFactory::factory(object);
    SupportLevel type = factory ? factory->supportLevel(object) : InfoRequestFactory::Unavailable;
    if (type <= InfoRequestFactory::Unavailable)
        object = 0;
    
    if (m_object != object) {
        m_object = object;
        emit objectChanged(object);
    }
    if (!object) {
        m_item = DataItem("No data");
        emit itemChanged(m_item);
        delete m_request;
        m_request = 0;
        return;
    }
	bool readWrite = (type == InfoRequestFactory::ReadWrite);
    if (m_readWrite != readWrite) {
        m_readWrite = readWrite;
        emit readOnlyChanged(!readWrite);
    }
    delete m_request;
	m_request = InfoRequestFactory::dataFormRequest(object);

	if (m_request) {
		connect(m_request, SIGNAL(stateChanged(qutim_sdk_0_3::InfoRequest::State)),
				SLOT(onRequestStateChanged(qutim_sdk_0_3::InfoRequest::State)));
		m_request->requestData();
	}

	QString title;
	QString avatar;
	if (Buddy *buddy = qobject_cast<Buddy*>(m_object)) {
		title = QApplication::translate("ContactInfo", "About contact %1 <%2>")
					.arg(buddy->name())
					.arg(buddy->id());
	} else {
		if (Account *account = qobject_cast<Account*>(m_object)) {
			title = QApplication::translate("ContactInfo", "About account %1")
						.arg(account->name());
		} else {
			title = QApplication::translate("ContactInfo", "About %1 <%2>")
						.arg(m_object->property("name").toString())
						.arg(m_object->property("id").toString());
		}
	}
	if (m_request)
		onRequestStateChanged(m_request->state());
    emit showRequest();
}
Ejemplo n.º 3
0
QScriptValue createInfoRequest(QScriptContext *context, QScriptEngine *engine)
{
	if (context->argumentCount() != 1)
		return context->throwError("InfoRequest() takes exactly one argument");
	QObject *object = context->argument(0).toQObject();
	InfoRequestFactory *factory = InfoRequestFactory::factory(object);
	if (!factory || factory->supportLevel(object) <= InfoRequestFactory::Unavailable)
		return engine->undefinedValue();
	InfoRequest *request = factory->createrDataFormRequest(object);
	if (!request)
		return engine->nullValue();
	return engine->newQObject(request, QScriptEngine::ScriptOwnership);
}