Commit 76cfa94b authored by Vlad Zahorodnii's avatar Vlad Zahorodnii

Check for protocol errors before converting dnd actions

It kind of makes more sense to check for errors and then start doing
the actual work.
parent faab823d
......@@ -82,21 +82,14 @@ void DataOfferInterfacePrivate::data_offer_finish(Resource *resource)
void DataOfferInterfacePrivate::data_offer_set_actions(Resource *resource, uint32_t dnd_actions, uint32_t preferred_action)
{
// TODO: check it's drag and drop, otherwise send error
DataDeviceManagerInterface::DnDActions supportedActions;
if (dnd_actions & QtWaylandServer::wl_data_device_manager::dnd_action_copy) {
supportedActions |= DataDeviceManagerInterface::DnDAction::Copy;
}
if (dnd_actions & QtWaylandServer::wl_data_device_manager::dnd_action_move) {
supportedActions |= DataDeviceManagerInterface::DnDAction::Move;
}
if (dnd_actions & QtWaylandServer::wl_data_device_manager::dnd_action_ask) {
supportedActions |= DataDeviceManagerInterface::DnDAction::Ask;
}
// verify that the no other actions are sent
if (dnd_actions & ~(QtWaylandServer::wl_data_device_manager::dnd_action_copy | QtWaylandServer::wl_data_device_manager::dnd_action_move | QtWaylandServer::wl_data_device_manager::dnd_action_ask)) {
if (dnd_actions & ~(QtWaylandServer::wl_data_device_manager::dnd_action_copy |
QtWaylandServer::wl_data_device_manager::dnd_action_move |
QtWaylandServer::wl_data_device_manager::dnd_action_ask)) {
wl_resource_post_error(resource->handle, error_invalid_action_mask, "Invalid action mask");
return;
}
if (preferred_action != QtWaylandServer::wl_data_device_manager::dnd_action_copy &&
preferred_action != QtWaylandServer::wl_data_device_manager::dnd_action_move &&
preferred_action != QtWaylandServer::wl_data_device_manager::dnd_action_ask &&
......@@ -105,6 +98,17 @@ void DataOfferInterfacePrivate::data_offer_set_actions(Resource *resource, uint3
return;
}
DataDeviceManagerInterface::DnDActions supportedActions;
if (dnd_actions & QtWaylandServer::wl_data_device_manager::dnd_action_copy) {
supportedActions |= DataDeviceManagerInterface::DnDAction::Copy;
}
if (dnd_actions & QtWaylandServer::wl_data_device_manager::dnd_action_move) {
supportedActions |= DataDeviceManagerInterface::DnDAction::Move;
}
if (dnd_actions & QtWaylandServer::wl_data_device_manager::dnd_action_ask) {
supportedActions |= DataDeviceManagerInterface::DnDAction::Ask;
}
DataDeviceManagerInterface::DnDAction preferredAction = DataDeviceManagerInterface::DnDAction::None;
if (preferred_action == QtWaylandServer::wl_data_device_manager::dnd_action_copy) {
preferredAction = DataDeviceManagerInterface::DnDAction::Copy;
......
......@@ -70,6 +70,13 @@ void DataSourceInterfacePrivate::offer(const QString &mimeType)
void DataSourceInterfacePrivate::data_source_set_actions(Resource *resource, uint32_t dnd_actions)
{
// verify that the no other actions are sent
if (dnd_actions & ~(QtWaylandServer::wl_data_device_manager::dnd_action_copy |
QtWaylandServer::wl_data_device_manager::dnd_action_move |
QtWaylandServer::wl_data_device_manager::dnd_action_ask)) {
wl_resource_post_error(resource->handle, error_invalid_action_mask, "Invalid action mask");
return;
}
DataDeviceManagerInterface::DnDActions supportedActions;
if (dnd_actions & QtWaylandServer::wl_data_device_manager::dnd_action_copy) {
supportedActions |= DataDeviceManagerInterface::DnDAction::Copy;
......@@ -80,11 +87,6 @@ void DataSourceInterfacePrivate::data_source_set_actions(Resource *resource, uin
if (dnd_actions & QtWaylandServer::wl_data_device_manager::dnd_action_ask) {
supportedActions |= DataDeviceManagerInterface::DnDAction::Ask;
}
// verify that the no other actions are sent
if (dnd_actions & ~(QtWaylandServer::wl_data_device_manager::dnd_action_copy | QtWaylandServer::wl_data_device_manager::dnd_action_move | QtWaylandServer::wl_data_device_manager::dnd_action_ask)) {
wl_resource_post_error(resource->handle, QtWaylandServer::wl_data_source::error_invalid_action_mask, "Invalid action mask");
return;
}
if (supportedDnDActions!= supportedActions) {
supportedDnDActions = supportedActions;
emit q->supportedDragAndDropActionsChanged();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment