mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-23 08:54:12 +08:00
toggleable repetition filter
This commit is contained in:
parent
e6805a2be3
commit
4b7452bef2
@ -42,7 +42,7 @@ void TextThread::Push(const BYTE* data, int len)
|
||||
lastPushTime = GetTickCount();
|
||||
|
||||
if (std::all_of(buffer.begin(), buffer.end(), [&](wchar_t c) { return repeatingChars.count(c) > 0; })) buffer.clear();
|
||||
if (Util::RemoveRepetition(buffer)) // sentence repetition detected, which means the entire sentence has already been received
|
||||
if (filterRepetition && Util::RemoveRepetition(buffer)) // sentence repetition detected, which means the entire sentence has already been received
|
||||
{
|
||||
repeatingChars = std::unordered_set(buffer.begin(), buffer.end());
|
||||
AddSentence(buffer);
|
||||
|
@ -9,6 +9,7 @@ public:
|
||||
using OutputCallback = std::function<bool(TextThread&, std::wstring&)>;
|
||||
inline static OutputCallback Output;
|
||||
|
||||
inline static bool filterRepetition = true;
|
||||
inline static int flushDelay = 400; // flush every 400ms by default
|
||||
inline static int maxBufferSize = 1000;
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <winhttp.h>
|
||||
#include <QFormLayout>
|
||||
#include <QPushButton>
|
||||
#include <QCheckBox>
|
||||
#include <QSpinBox>
|
||||
#include <QMessageBox>
|
||||
#include <QInputDialog>
|
||||
@ -42,6 +43,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
|
||||
QSettings settings(CONFIG_FILE, QSettings::IniFormat);
|
||||
if (settings.contains(WINDOW)) setGeometry(settings.value(WINDOW).toRect());
|
||||
TextThread::filterRepetition = settings.value(FILTER_REPETITION, TextThread::filterRepetition).toBool();
|
||||
TextThread::flushDelay = settings.value(FLUSH_DELAY, TextThread::flushDelay).toInt();
|
||||
TextThread::maxBufferSize = settings.value(MAX_BUFFER_SIZE, TextThread::maxBufferSize).toInt();
|
||||
Host::defaultCodepage = settings.value(DEFAULT_CODEPAGE, Host::defaultCodepage).toInt();
|
||||
@ -311,6 +313,15 @@ void MainWindow::Settings()
|
||||
layout->insertRow(0, label, spinBox);
|
||||
connect(save, &QPushButton::clicked, [=, &value] { settings->setValue(label, value = spinBox->value()); });
|
||||
}
|
||||
for (auto[value, label] : Array<std::tuple<bool&, const char*>>{
|
||||
{ TextThread::filterRepetition, FILTER_REPETITION },
|
||||
})
|
||||
{
|
||||
auto checkBox = new QCheckBox(this);
|
||||
checkBox->setChecked(value);
|
||||
layout->insertRow(0, label, checkBox);
|
||||
connect(save, &QPushButton::clicked, [=, &value] { settings->setValue(label, value = checkBox->isChecked()); });
|
||||
}
|
||||
connect(save, &QPushButton::clicked, this, &QDialog::accept);
|
||||
setWindowTitle(SETTINGS);
|
||||
exec();
|
||||
|
@ -18,6 +18,7 @@ extern const char* SAVE_SETTINGS;
|
||||
extern const char* EXTEN_WINDOW_INSTRUCTIONS;
|
||||
extern const char* WINDOW;
|
||||
extern const char* USE_JP_LOCALE;
|
||||
extern const char* FILTER_REPETITION;
|
||||
extern const char* DEFAULT_CODEPAGE;
|
||||
extern const char* FLUSH_DELAY;
|
||||
extern const char* MAX_BUFFER_SIZE;
|
||||
|
1
text.cpp
1
text.cpp
@ -39,6 +39,7 @@ Drag and drop within the list to reorder
|
||||
Press delete with an extension selected to remove it)";
|
||||
const char* WINDOW = u8"Window";
|
||||
const char* USE_JP_LOCALE = u8"Emulate japanese locale?";
|
||||
const char* FILTER_REPETITION = u8"Repetition Filter";
|
||||
const char* DEFAULT_CODEPAGE = u8"Default Codepage";
|
||||
const char* FLUSH_DELAY = u8"Flush Delay";
|
||||
const char* MAX_BUFFER_SIZE = u8"Max Buffer Size";
|
||||
|
Loading…
x
Reference in New Issue
Block a user