From 2a87543d82a2652151d0aac29dddcd9b02b6a1fc Mon Sep 17 00:00:00 2001 From: "Peter \"Marenthyu\" Fredebold" Date: Wed, 24 Feb 2021 21:37:18 +0100 Subject: [PATCH] UI: Add css on Drag and Drop Adds parsing for the "layer-css" query param of URLs dragged into the main window, similarly to the other layer-* parameters already used. --- UI/window-basic-main-dropfiles.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/UI/window-basic-main-dropfiles.cpp b/UI/window-basic-main-dropfiles.cpp index 6c2d7defd..25e402ff3 100644 --- a/UI/window-basic-main-dropfiles.cpp +++ b/UI/window-basic-main-dropfiles.cpp @@ -72,6 +72,20 @@ void OBSBasic::AddDropURL(const char *url, QString &name, obs_data_t *settings, cx = query.queryItemValue("layer-width").toInt(); if (query.hasQueryItem("layer-height")) cy = query.queryItemValue("layer-height").toInt(); + if (query.hasQueryItem("layer-css")) { + // QUrl::FullyDecoded does NOT properly decode a + // application/x-www-form-urlencoded space represented as '+' + // Thus, this is manually filtered out before QUrl's + // decoding kicks in again. This is to allow JavaScript's + // default searchParams.append function to simply append css + // to the query parameters, which is the intended usecase for this. + QString fullyEncoded = + query.queryItemValue("layer-css", QUrl::FullyEncoded); + fullyEncoded = fullyEncoded.replace("+", "%20"); + QString decoded = QUrl::fromPercentEncoding( + QByteArray::fromStdString(QT_TO_UTF8(fullyEncoded))); + obs_data_set_string(settings, "css", QT_TO_UTF8(decoded)); + } obs_data_set_int(settings, "width", cx); obs_data_set_int(settings, "height", cy); @@ -83,6 +97,7 @@ void OBSBasic::AddDropURL(const char *url, QString &name, obs_data_t *settings, query.removeQueryItem("layer-width"); query.removeQueryItem("layer-height"); query.removeQueryItem("layer-name"); + query.removeQueryItem("layer-css"); path.setQuery(query); obs_data_set_string(settings, "url", QT_TO_UTF8(path.url()));