Ejemplo n.º 1
0
bool
XWindowsClipboard::addSimpleRequest(Window requestor,
				Atom target, ::Time time, Atom property)
{
	// obsolete requestors may supply a None property.  in
	// that case we use the target as the property to store
	// the conversion.
	if (property == None) {
		property = target;
	}

	// handle targets
	String data;
	Atom type  = None;
	int format = 0;
	if (target == m_atomTargets) {
		type = getTargetsData(data, &format);
	}
	else if (target == m_atomTimestamp) {
		type = getTimestampData(data, &format);
	}
	else {
		IXWindowsClipboardConverter* converter = getConverter(target);
		if (converter != NULL) {
			IClipboard::EFormat clipboardFormat = converter->getFormat();
			if (m_added[clipboardFormat]) {
				try {
					data   = converter->fromIClipboard(m_data[clipboardFormat]);
					format = converter->getDataSize();
					type   = converter->getAtom();
				}
				catch (...) {
					// ignore -- cannot convert
				}
			}
		}
	}

	if (type != None) {
		// success
		LOG((CLOG_DEBUG1 "success"));
		insertReply(new Reply(requestor, target, time,
								property, data, type, format));
		return true;
	}
	else {
		// failure
		LOG((CLOG_DEBUG1 "failed"));
		insertReply(new Reply(requestor, target, time));
		return false;
	}
}
Ejemplo n.º 2
0
bool Acl::insertB(QString calendarId, AclRule &rule)
{
    _insert->setAccessToken(_accessToken);
    _insert->setParameters(calendarId, rule);
    if(_insert->perform(RequestOperation::PerformModeBlocking, _operationTimeout)) {
        return insertReply(_insert->networkReply(), rule);
    }
    return false;
}
Ejemplo n.º 3
0
// APIRequestDelegate
void Acl::handleReplyNonBlocking(RequestOperation *request,
                      QNetworkReply *networkReply)
{
    // Schedule network reply for deletion
    networkReply->deleteLater();

    if(request == _delete) {
        bool success;
        if(deleteReply(networkReply)) {
            emit deleteFinished();
        } else {
            emit deleteFailed(errorString());
        }
    } else
    if(request == _get) {
        AclRule rule;
        if(getReply(networkReply, rule)) {
            emit getFinished(rule);
        } else {
            emit getFailed(errorString());
        }
    } else
    if(request == _insert) {
        AclRule rule;
        if(insertReply(networkReply, rule)) {
            emit insertFinished(rule);
        } else {
            emit insertFailed(errorString());
        }
    } else
    if(request == _list) {
        // TODO: Implement.
    } else
    if(request == _patch) {
        AclRule rule;
        if(patchReply(networkReply, rule)) {
            emit patchFinished(rule);
        } else {
            emit patchFailed(errorString());
        }
    } else
    if(request == _update) {
        AclRule rule;
        if(updateReply(networkReply, rule)) {
            emit updateFinished(rule);
        } else {
            emit updateFailed(errorString());
        }
    } else
    if(request == _watch) {
        // TODO: Implement.
    } else {
        qDebug() << "Warning: Received response for unknown request.";
    }
}
Ejemplo n.º 4
0
bool
CXWindowsClipboard::insertMultipleReply(Window requestor,
				::Time time, Atom property)
{
	// get the requested targets
	Atom target;
	SInt32 format;
	CString data;
	if (!CXWindowsUtil::getWindowProperty(m_display, requestor,
								property, &data, &target, &format, False)) {
		// can't get the requested targets
		return false;
	}

	// fail if the requested targets isn't of the correct form
	if (format != 32 ||
		target != m_atomAtomPair) {
		return false;
	}

	// data is a list of atom pairs:  target, property
	const Atom* targets = reinterpret_cast<const Atom*>(data.data());
	const UInt32 numTargets = data.size() / sizeof(Atom);

	// add replies for each target
	bool changed = false;
	for (UInt32 i = 0; i < numTargets; i += 2) {
		const Atom target   = targets[i + 0];
		const Atom property = targets[i + 1];
		if (!addSimpleRequest(requestor, target, time, property)) {
			// note that we can't perform the requested conversion
			static const Atom none = None;
			data.replace(i * sizeof(Atom), sizeof(Atom),
								reinterpret_cast<const char*>(&none),
								sizeof(Atom));
			changed = true;
		}
	}

	// update the targets property if we changed it
	if (changed) {
		CXWindowsUtil::setWindowProperty(m_display, requestor,
								property, data.data(), data.size(),
								target, format);
	}

	// add reply for MULTIPLE request
	insertReply(new CReply(requestor, m_atomMultiple,
								time, property, CString(), None, 32));

	return true;
}
Ejemplo n.º 5
0
void
XWindowsClipboard::addRequest(Window owner, Window requestor,
				Atom target, ::Time time, Atom property)
{
	// must be for our window and we must have owned the selection
	// at the given time.
	bool success = false;
	if (owner == m_window) {
		LOG((CLOG_DEBUG1 "request for clipboard %d, target %s by 0x%08x (property=%s)", m_selection, XWindowsUtil::atomToString(m_display, target).c_str(), requestor, XWindowsUtil::atomToString(m_display, property).c_str()));
		if (wasOwnedAtTime(time)) {
			if (target == m_atomMultiple) {
				// add a multiple request.  property may not be None
				// according to ICCCM.
				if (property != None) {
					success = insertMultipleReply(requestor, time, property);
				}
			}
			else {
				addSimpleRequest(requestor, target, time, property);

				// addSimpleRequest() will have already handled failure
				success = true;
			}
		}
		else {
			LOG((CLOG_DEBUG1 "failed, not owned at time %d", time));
		}
	}

	if (!success) {
		// send failure
		LOG((CLOG_DEBUG1 "failed"));
		insertReply(new Reply(requestor, target, time));
	}

	// send notifications that are pending
	pushReplies();
}