mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-23 17:04:12 +08:00
add thread linker extension
This commit is contained in:
parent
3cb65dba63
commit
a48815e9f4
@ -16,24 +16,26 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Extensions</string>
|
<string>Extensions</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">QObject
|
<string notr="true">
|
||||||
{
|
QObject
|
||||||
font: 10pt "MS Shell Dlg 2";
|
{
|
||||||
}
|
font: 10pt "MS Shell Dlg 2";
|
||||||
#textOutput
|
}
|
||||||
{
|
#textOutput
|
||||||
font: 13pt "MS Shell Dlg 2";;
|
{
|
||||||
}
|
font: 13pt "MS Shell Dlg 2";
|
||||||
QPushButton, QComboBox
|
}
|
||||||
{
|
QPushButton, QComboBox
|
||||||
padding-top: 3px;
|
{
|
||||||
padding-bottom: 3px;
|
padding-top: 3px;
|
||||||
padding-right: 5px;
|
padding-bottom: 3px;
|
||||||
padding-left: 5px;
|
padding-right: 5px;
|
||||||
text-align: left;
|
padding-left: 5px;
|
||||||
}</string>
|
text-align: left;
|
||||||
</property>
|
}
|
||||||
|
</string>
|
||||||
|
</property>
|
||||||
<widget class="QWidget" name="centralWidget">
|
<widget class="QWidget" name="centralWidget">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
|
@ -13,24 +13,26 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Textractor</string>
|
<string>Textractor</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">QObject
|
<string notr="true">
|
||||||
{
|
QObject
|
||||||
font: 10pt "MS Shell Dlg 2";
|
{
|
||||||
}
|
font: 10pt "MS Shell Dlg 2";
|
||||||
#textOutput
|
}
|
||||||
{
|
#textOutput
|
||||||
font: 13pt "MS Shell Dlg 2";
|
{
|
||||||
}
|
font: 13pt "MS Shell Dlg 2";
|
||||||
QPushButton, QComboBox
|
}
|
||||||
{
|
QPushButton, QComboBox
|
||||||
padding-top: 3px;
|
{
|
||||||
padding-bottom: 3px;
|
padding-top: 3px;
|
||||||
padding-right: 5px;
|
padding-bottom: 3px;
|
||||||
padding-left: 5px;
|
padding-right: 5px;
|
||||||
text-align: left;
|
padding-left: 5px;
|
||||||
}</string>
|
text-align: left;
|
||||||
</property>
|
}
|
||||||
|
</string>
|
||||||
|
</property>
|
||||||
<widget class="QWidget" name="centralWidget">
|
<widget class="QWidget" name="centralWidget">
|
||||||
<layout class="QHBoxLayout">
|
<layout class="QHBoxLayout">
|
||||||
<item>
|
<item>
|
||||||
|
@ -10,7 +10,9 @@ add_library(Extra\ Newlines SHARED extranewlines/extranewlines.cpp extensionimpl
|
|||||||
add_library(Google\ Translate SHARED googletranslate/googletranslate.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(Regex\ Filter SHARED regexfilter/regexfilter.cpp regexfilter/window.cpp extensionimpl.cpp)
|
||||||
add_library(Remove\ Repetition SHARED removerepeat/removerepeat.cpp extensionimpl.cpp)
|
add_library(Remove\ Repetition SHARED removerepeat/removerepeat.cpp extensionimpl.cpp)
|
||||||
|
add_library(Thread\ Linker SHARED threadlinker/threadlinker.cpp threadlinker/window.cpp extensionimpl.cpp)
|
||||||
|
|
||||||
target_link_libraries(Bing\ Translate winhttp Qt5::Widgets)
|
target_link_libraries(Bing\ Translate winhttp Qt5::Widgets)
|
||||||
target_link_libraries(Google\ Translate winhttp Qt5::Widgets)
|
target_link_libraries(Google\ Translate winhttp Qt5::Widgets)
|
||||||
target_link_libraries(Regex\ Filter Qt5::Widgets)
|
target_link_libraries(Regex\ Filter Qt5::Widgets)
|
||||||
|
target_link_libraries(Thread\ Linker Qt5::Widgets)
|
||||||
|
37
extensions/threadlinker/threadlinker.cpp
Normal file
37
extensions/threadlinker/threadlinker.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include "../extension.h"
|
||||||
|
#include "window.h"
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
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->m);
|
||||||
|
|
||||||
|
static std::unordered_map<int64_t, std::wstring> queuedWritesByHandle;
|
||||||
|
int64_t textHandle = sentenceInfo["text handle"];
|
||||||
|
for (auto linkedHandle : w->linkedTextHandles[textHandle]) queuedWritesByHandle[linkedHandle] += L"\r\n" + sentence;
|
||||||
|
if (queuedWritesByHandle[textHandle].empty()) return false;
|
||||||
|
sentence += queuedWritesByHandle[textHandle];
|
||||||
|
queuedWritesByHandle[textHandle].clear();
|
||||||
|
return true;
|
||||||
|
}
|
37
extensions/threadlinker/window.cpp
Normal file
37
extensions/threadlinker/window.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include "window.h"
|
||||||
|
#include "ui_window.h"
|
||||||
|
#include <QInputDialog>
|
||||||
|
|
||||||
|
Window::Window(QWidget *parent) :
|
||||||
|
QMainWindow(parent),
|
||||||
|
ui(new Ui::Window)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
threadLinkList = findChild<QListWidget*>("threadLinkList");
|
||||||
|
}
|
||||||
|
|
||||||
|
Window::~Window()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::on_linkButton_clicked()
|
||||||
|
{
|
||||||
|
bool ok1, ok2, ok3, ok4;
|
||||||
|
int from = QInputDialog::getText(this, "Link From", "Thread number to link from?", QLineEdit::Normal, "", &ok1, Qt::WindowCloseButtonHint).toInt(&ok2, 16);
|
||||||
|
int to = QInputDialog::getText(this, "Link To", "Thread number to link to?", QLineEdit::Normal, "", &ok3, Qt::WindowCloseButtonHint).toInt(&ok4, 16);
|
||||||
|
if (ok1 && ok2 && ok3 && ok4)
|
||||||
|
{
|
||||||
|
std::lock_guard l(m);
|
||||||
|
linkedTextHandles[from].insert(to);
|
||||||
|
threadLinkList->addItem(QString::number(from, 16) + "->" + QString::number(to, 16));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::on_unlinkButton_clicked()
|
||||||
|
{
|
||||||
|
std::lock_guard l(m);
|
||||||
|
QStringList link = threadLinkList->currentItem()->text().split("->");
|
||||||
|
threadLinkList->takeItem(threadLinkList->currentRow());
|
||||||
|
linkedTextHandles[link[0].toInt(nullptr, 16)].erase(link[1].toInt(nullptr, 16));
|
||||||
|
}
|
35
extensions/threadlinker/window.h
Normal file
35
extensions/threadlinker/window.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef WINDOW_H
|
||||||
|
#define WINDOW_H
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <mutex>
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QListWidget>
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class Window;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Window : public QMainWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Window(QWidget *parent = nullptr);
|
||||||
|
~Window();
|
||||||
|
|
||||||
|
Ui::Window* ui;
|
||||||
|
std::mutex m;
|
||||||
|
std::unordered_map<int64_t, std::unordered_multiset<int64_t>> linkedTextHandles;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_linkButton_clicked();
|
||||||
|
void on_unlinkButton_clicked();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QListWidget* threadLinkList;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WINDOW_H
|
79
extensions/threadlinker/window.ui
Normal file
79
extensions/threadlinker/window.ui
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Window</class>
|
||||||
|
<widget class="QMainWindow" name="Window">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Thread Linker</string>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">
|
||||||
|
QObject
|
||||||
|
{
|
||||||
|
font: 10pt "MS Shell Dlg 2";
|
||||||
|
}
|
||||||
|
#textOutput
|
||||||
|
{
|
||||||
|
font: 13pt "MS Shell Dlg 2";
|
||||||
|
}
|
||||||
|
QPushButton, QComboBox
|
||||||
|
{
|
||||||
|
padding-top: 3px;
|
||||||
|
padding-bottom: 3px;
|
||||||
|
padding-right: 5px;
|
||||||
|
padding-left: 5px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralWidget">
|
||||||
|
<layout class="QHBoxLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QListWidget" name="threadLinkList">
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout">
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="linkButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Link</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="unlinkButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Unlink</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
x
Reference in New Issue
Block a user