add thread linker extension

This commit is contained in:
Akash Mozumdar 2018-11-04 16:37:23 -05:00
parent 3cb65dba63
commit a48815e9f4
7 changed files with 230 additions and 36 deletions

View File

@ -17,22 +17,24 @@
<string>Extensions</string>
</property>
<property name="styleSheet">
<string notr="true">QObject
{
<string notr="true">
QObject
{
font: 10pt &quot;MS Shell Dlg 2&quot;;
}
#textOutput
{
font: 13pt &quot;MS Shell Dlg 2&quot;;;
}
QPushButton, QComboBox
{
}
#textOutput
{
font: 13pt &quot;MS Shell Dlg 2&quot;;
}
QPushButton, QComboBox
{
padding-top: 3px;
padding-bottom: 3px;
padding-right: 5px;
padding-left: 5px;
text-align: left;
}</string>
}
</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout">

View File

@ -14,22 +14,24 @@
<string>Textractor</string>
</property>
<property name="styleSheet">
<string notr="true">QObject
{
<string notr="true">
QObject
{
font: 10pt &quot;MS Shell Dlg 2&quot;;
}
#textOutput
{
}
#textOutput
{
font: 13pt &quot;MS Shell Dlg 2&quot;;
}
QPushButton, QComboBox
{
}
QPushButton, QComboBox
{
padding-top: 3px;
padding-bottom: 3px;
padding-right: 5px;
padding-left: 5px;
text-align: left;
}</string>
}
</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout">

View File

@ -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(Regex\ Filter SHARED regexfilter/regexfilter.cpp regexfilter/window.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(Google\ Translate winhttp Qt5::Widgets)
target_link_libraries(Regex\ Filter Qt5::Widgets)
target_link_libraries(Thread\ Linker Qt5::Widgets)

View 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;
}

View 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));
}

View 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

View 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 &quot;MS Shell Dlg 2&quot;;
}
#textOutput
{
font: 13pt &quot;MS Shell Dlg 2&quot;;
}
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>