This commit is contained in:
Akash Mozumdar 2018-08-22 01:22:34 -04:00
parent 51dc229edc
commit e35e26c2eb
4 changed files with 11 additions and 17 deletions

View File

@ -83,6 +83,7 @@ MainWindow::~MainWindow()
settings.open(QIODevice::ReadWrite | QIODevice::Truncate);
QDataStream writer(&settings);
writer << this->geometry();
Host::Close();
delete ui;
}

View File

@ -147,7 +147,6 @@ namespace Host
void DispatchText(ThreadParameter tp, const BYTE* text, int len)
{
// jichi 2/27/2013: When PID is zero, the text comes from console, which I don't need
if (!text || len <= 0) return;
HOST_LOCK;
TextThread *it;

View File

@ -14,7 +14,7 @@
TextThread::TextThread(ThreadParameter tp, DWORD status) :
deletionEvent(CreateEventW(nullptr, FALSE, FALSE, NULL)),
flushThread([&]() { while (WaitForSingleObject(deletionEvent, 100), FlushSentenceBuffer()); }),
flushThread([&]() { while (WaitForSingleObject(deletionEvent, 100), Flush()); }),
timestamp(GetTickCount()),
Output(nullptr),
tp(tp),
@ -35,30 +35,24 @@ std::wstring TextThread::GetStore()
return storage;
}
bool TextThread::FlushSentenceBuffer()
bool TextThread::Flush()
{
TT_LOCK;
if (status == -1UL) return false;
if (timestamp - GetTickCount() < 250 || sentenceBuffer.size() == 0) return true; // TODO: let user change delay before sentence is flushed
if (timestamp - GetTickCount() < 250 || buffer.size() == 0) return true; // TODO: let user change delay before sentence is flushed
std::wstring sentence;
if (status & USING_UNICODE)
{
sentence = std::wstring((wchar_t*)sentenceBuffer.data(), sentenceBuffer.size() / 2);
}
else if (status & USING_UTF8)
{
wchar_t* converted = new wchar_t[sentenceBuffer.size()];
sentence = std::wstring(converted, MultiByteToWideChar(CP_UTF8, 0, sentenceBuffer.data(), sentenceBuffer.size(), converted, sentenceBuffer.size()));
delete[] converted;
sentence = std::wstring((wchar_t*)buffer.data(), buffer.size() / 2);
}
else
{
wchar_t* converted = new wchar_t[sentenceBuffer.size()];
sentence = std::wstring(converted, MultiByteToWideChar(932, 0, sentenceBuffer.data(), sentenceBuffer.size(), converted, sentenceBuffer.size()));
wchar_t* converted = new wchar_t[buffer.size()];
sentence = std::wstring(converted, MultiByteToWideChar(status & USING_UTF8 ? CP_UTF8 : 932, 0, buffer.data(), buffer.size(), converted, buffer.size()));
delete[] converted;
}
AddSentence(sentence);
sentenceBuffer.clear();
buffer.clear();
return true;
}
@ -72,7 +66,7 @@ void TextThread::AddSentence(std::wstring sentence)
void TextThread::AddText(const BYTE *con, int len)
{
TT_LOCK;
sentenceBuffer.insert(sentenceBuffer.end(), con, con + len);
buffer.insert(buffer.end(), con, con + len);
timestamp = GetTickCount();
}

View File

@ -45,9 +45,9 @@ public:
void AddSentence(std::wstring sentence);
private:
bool FlushSentenceBuffer();
bool Flush();
std::vector<char> sentenceBuffer;
std::vector<char> buffer;
std::wstring storage;
std::recursive_mutex ttMutex;
HANDLE deletionEvent;