From 66d02a7bf07e303c15d30298409c13367fc3d9de Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sat, 3 Nov 2018 23:58:52 -0400 Subject: [PATCH] add regex filter --- deploy.ps1 | 2 ++ extensions/CMakeLists.txt | 4 ++++ extensions/regexfilter/regexfilter.cpp | 31 ++++++++++++++++++++++++++ extensions/regexfilter/window.cpp | 21 +++++++++++++++++ extensions/regexfilter/window.h | 30 +++++++++++++++++++++++++ extensions/regexfilter/window.ui | 26 +++++++++++++++++++++ 6 files changed, 114 insertions(+) create mode 100644 extensions/regexfilter/regexfilter.cpp create mode 100644 extensions/regexfilter/window.cpp create mode 100644 extensions/regexfilter/window.h create mode 100644 extensions/regexfilter/window.ui diff --git a/deploy.ps1 b/deploy.ps1 index 6a1edef..f7b662a 100644 --- a/deploy.ps1 +++ b/deploy.ps1 @@ -11,6 +11,7 @@ Compress-Archive -Force -DestinationPath Textractor -Path @( "Copy to Clipboard.dll", "Extra Newlines.dll", "Google Translate.dll", + "Regex Filter.dll", "Remove Repetition.dll", "Extensions.txt" ) @@ -28,6 +29,7 @@ Compress-Archive -Force -DestinationPath Textractor -Path @( "Copy to Clipboard.dll", "Extra Newlines.dll", "Google Translate.dll", + "Regex Filter.dll", "Remove Repetition.dll", "Extensions.txt" ) \ No newline at end of file diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index b9aed40..8a301dc 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -7,6 +7,10 @@ cmake_policy(SET CMP0037 OLD) add_library(Bing\ Translate SHARED bingtranslate/bingtranslate.cpp extensionimpl.cpp) add_library(Copy\ to\ Clipboard SHARED copyclipboard/copyclipboard.cpp extensionimpl.cpp) add_library(Extra\ Newlines SHARED extranewlines/extranewlines.cpp extensionimpl.cpp) +add_library(Google\ Translate SHARED googletranslate/googletranslate.cpp extensionimpl.cpp) +add_library(Regex\ Filter SHARED regexfilter/regexfilter.cpp regexfilter/window.cpp extensionimpl.cpp) add_library(Remove\ Repetition SHARED removerepeat/removerepeat.cpp extensionimpl.cpp) target_link_libraries(Bing\ Translate winhttp Qt5::Widgets) +target_link_libraries(Google\ Translate winhttp Qt5::Widgets) +target_link_libraries(Regex\ Filter Qt5::Widgets) diff --git a/extensions/regexfilter/regexfilter.cpp b/extensions/regexfilter/regexfilter.cpp new file mode 100644 index 0000000..ac79e03 --- /dev/null +++ b/extensions/regexfilter/regexfilter.cpp @@ -0,0 +1,31 @@ +#include "../extension.h" +#include "window.h" +#include + +Window* w = nullptr; + +BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + { + QTimer::singleShot(0, [] { (w = new Window)->show(); }); + } + break; + case DLL_PROCESS_DETACH: + { + delete w; + } + break; + } + return TRUE; +} + +bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) +{ + if (w == nullptr) return false; + std::lock_guard l(w->locker); + sentence = std::regex_replace(sentence, w->regex, L""); + return true; +} \ No newline at end of file diff --git a/extensions/regexfilter/window.cpp b/extensions/regexfilter/window.cpp new file mode 100644 index 0000000..105dc02 --- /dev/null +++ b/extensions/regexfilter/window.cpp @@ -0,0 +1,21 @@ +#include "window.h" +#include "ui_window.h" + +Window::Window(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::Window) +{ + ui->setupUi(this); +} + +Window::~Window() +{ + delete ui; +} + +void Window::on_regexInput_textEdited(const QString& newRegex) +{ + std::lock_guard lock(locker); + try { regex = newRegex.toStdWString(); } + catch (...) {} +} diff --git a/extensions/regexfilter/window.h b/extensions/regexfilter/window.h new file mode 100644 index 0000000..274bb1e --- /dev/null +++ b/extensions/regexfilter/window.h @@ -0,0 +1,30 @@ +#ifndef WINDOW_H +#define WINDOW_H + +#include +#include +#include +#include + +namespace Ui +{ + class Window; +} + +class Window : public QMainWindow +{ + Q_OBJECT + +public: + explicit Window(QWidget *parent = nullptr); + ~Window(); + + Ui::Window* ui; + std::mutex locker; + std::wregex regex; + +private slots: + void on_regexInput_textEdited(const QString& regex); +}; + +#endif // WINDOW_H diff --git a/extensions/regexfilter/window.ui b/extensions/regexfilter/window.ui new file mode 100644 index 0000000..c52e297 --- /dev/null +++ b/extensions/regexfilter/window.ui @@ -0,0 +1,26 @@ + + + Window + + + + 0 + 0 + 350 + 80 + + + + Regex Filter + + + + + + + + + + + +