summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-05-14 13:28:39 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-14 18:42:27 +0200
commit800214f0b9cbbbc7b77a12180ce59033dd3cca64 (patch)
treef460ccddadf133cb20f4db7d6c987f8fee540891 /src
parent1a8788d966da9698b05c1e0bd271d83c5bca9992 (diff)
Windows: Improve checking of options to the QPA plugin.
Change-Id: I59129132c7caa13d5c9d8f1e6211da68505dd838 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/windows/qwindowsintegration.cpp36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp
index aed7ad9c46..fc59302bf3 100644
--- a/src/plugins/platforms/windows/qwindowsintegration.cpp
+++ b/src/plugins/platforms/windows/qwindowsintegration.cpp
@@ -89,6 +89,8 @@
#include <QtCore/QDebug>
#include <QtCore/QVariant>
+#include <limits.h>
+
QT_BEGIN_NAMESPACE
/*!
@@ -166,6 +168,29 @@ struct QWindowsIntegrationPrivate
QWindowsServices m_services;
};
+template <typename IntType>
+bool parseIntOption(const QString &parameter,const QLatin1String &option,
+ IntType minimumValue, IntType maximumValue, IntType *target)
+{
+ const int valueLength = parameter.size() - option.size() - 1;
+ if (valueLength < 1 || !parameter.startsWith(option) || parameter.at(option.size()) != QLatin1Char('='))
+ return false;
+ bool ok;
+ const QStringRef valueRef = parameter.rightRef(valueLength);
+ const int value = valueRef.toInt(&ok);
+ if (ok) {
+ if (value >= minimumValue && value <= maximumValue)
+ *target = static_cast<IntType>(value);
+ else {
+ qWarning() << "Value" << value << "for option" << option << "out of range"
+ << minimumValue << ".." << maximumValue;
+ }
+ } else {
+ qWarning() << "Invalid value" << valueRef << "for option" << option;
+ }
+ return true;
+}
+
static inline unsigned parseOptions(const QStringList &paramList,
int *tabletAbsoluteRange,
QtWindows::ProcessDpiAwareness *dpiAwareness)
@@ -188,12 +213,11 @@ static inline unsigned parseOptions(const QStringList &paramList,
options |= QWindowsIntegration::DisableArb;
} else if (param == QLatin1String("nomousefromtouch")) {
options |= QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch;
- } else if (param.startsWith(QLatin1String("verbose="))) {
- QWindowsContext::verbose = param.right(param.size() - 8).toInt();
- } else if (param.startsWith(QLatin1String("tabletabsoluterange="))) {
- *tabletAbsoluteRange = param.rightRef(param.size() - 20).toInt();
- } else if (param.startsWith(QLatin1String("dpiawareness="))) {
- *dpiAwareness = static_cast<QtWindows::ProcessDpiAwareness>(param.rightRef(param.size() - 13).toInt());
+ } else if (parseIntOption(param, QLatin1String("verbose"), 0, INT_MAX, &QWindowsContext::verbose)
+ || parseIntOption(param, QLatin1String("tabletabsoluterange"), 0, INT_MAX, tabletAbsoluteRange)
+ || parseIntOption(param, QLatin1String("dpiawareness"), QtWindows::ProcessDpiUnaware, QtWindows::ProcessPerMonitorDpiAware, dpiAwareness)) {
+ } else {
+ qWarning() << "Unknown option" << param;
}
}
return options;