From 92812d0b0b1a78febc34d3e5fbb551e50ad77eb9 Mon Sep 17 00:00:00 2001 From: Techjar Date: Thu, 16 Jul 2020 18:47:51 -0400 Subject: [PATCH] QtUtils: Add UTF8CodePointCountValidator --- Source/Core/DolphinQt/CMakeLists.txt | 6 ++++-- Source/Core/DolphinQt/DolphinQt.vcxproj | 5 ++++- .../QtUtils/UTF8CodePointCountValidator.cpp | 20 +++++++++++++++++++ .../QtUtils/UTF8CodePointCountValidator.h | 19 ++++++++++++++++++ 4 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 Source/Core/DolphinQt/QtUtils/UTF8CodePointCountValidator.cpp create mode 100644 Source/Core/DolphinQt/QtUtils/UTF8CodePointCountValidator.h diff --git a/Source/Core/DolphinQt/CMakeLists.txt b/Source/Core/DolphinQt/CMakeLists.txt index 3ef723300d..269083c4dc 100644 --- a/Source/Core/DolphinQt/CMakeLists.txt +++ b/Source/Core/DolphinQt/CMakeLists.txt @@ -235,6 +235,8 @@ add_executable(dolphin-emu QtUtils/ParallelProgressDialog.h QtUtils/ImageConverter.cpp QtUtils/ImageConverter.h + QtUtils/UTF8CodePointCountValidator.cpp + QtUtils/UTF8CodePointCountValidator.h QtUtils/WindowActivationEventFilter.cpp QtUtils/WindowActivationEventFilter.h QtUtils/WinIconHelper.cpp @@ -459,8 +461,8 @@ if(APPLE) include(DolphinPostprocessBundle) dolphin_postprocess_bundle(dolphin-emu) # Fix rpath - add_custom_command(TARGET dolphin-emu - POST_BUILD COMMAND + add_custom_command(TARGET dolphin-emu + POST_BUILD COMMAND ${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@executable_path/../Frameworks/" $) else() diff --git a/Source/Core/DolphinQt/DolphinQt.vcxproj b/Source/Core/DolphinQt/DolphinQt.vcxproj index 0fdfc53118..1e4fd3b0b2 100644 --- a/Source/Core/DolphinQt/DolphinQt.vcxproj +++ b/Source/Core/DolphinQt/DolphinQt.vcxproj @@ -186,6 +186,7 @@ + @@ -291,6 +292,7 @@ + @@ -433,6 +435,7 @@ + @@ -555,4 +558,4 @@ - \ No newline at end of file + diff --git a/Source/Core/DolphinQt/QtUtils/UTF8CodePointCountValidator.cpp b/Source/Core/DolphinQt/QtUtils/UTF8CodePointCountValidator.cpp new file mode 100644 index 0000000000..d5020ea8dd --- /dev/null +++ b/Source/Core/DolphinQt/QtUtils/UTF8CodePointCountValidator.cpp @@ -0,0 +1,20 @@ +// Copyright 2020 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "DolphinQt/QtUtils/UTF8CodePointCountValidator.h" + +#include "Common/StringUtil.h" + +UTF8CodePointCountValidator::UTF8CodePointCountValidator(int max_count, QObject* parent) + : QValidator(parent), m_max_count(max_count) +{ +} + +QValidator::State UTF8CodePointCountValidator::validate(QString& input, int& pos) const +{ + if (StringUTF8CodePointCount(input.toStdString()) > m_max_count) + return QValidator::Invalid; + + return QValidator::Acceptable; +} diff --git a/Source/Core/DolphinQt/QtUtils/UTF8CodePointCountValidator.h b/Source/Core/DolphinQt/QtUtils/UTF8CodePointCountValidator.h new file mode 100644 index 0000000000..89a8bc8e1d --- /dev/null +++ b/Source/Core/DolphinQt/QtUtils/UTF8CodePointCountValidator.h @@ -0,0 +1,19 @@ +// Copyright 2020 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include + +class UTF8CodePointCountValidator : public QValidator +{ + Q_OBJECT +public: + explicit UTF8CodePointCountValidator(int max_count, QObject* parent = nullptr); + + QValidator::State validate(QString& input, int& pos) const override; + + int m_max_count; +};