diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index f808fca..f285619 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -83,6 +83,7 @@ MainWindow::~MainWindow() settings.open(QIODevice::ReadWrite | QIODevice::Truncate); QDataStream writer(&settings); writer << this->geometry(); + Host::Close(); delete ui; } diff --git a/host/host.cc b/host/host.cc index 7807c9d..f5cb907 100644 --- a/host/host.cc +++ b/host/host.cc @@ -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; diff --git a/host/textthread.cc b/host/textthread.cc index 2146ebf..0744b54 100644 --- a/host/textthread.cc +++ b/host/textthread.cc @@ -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(); } diff --git a/host/textthread.h b/host/textthread.h index 0f4d6b6..059bc0e 100644 --- a/host/textthread.h +++ b/host/textthread.h @@ -45,9 +45,9 @@ public: void AddSentence(std::wstring sentence); private: - bool FlushSentenceBuffer(); + bool Flush(); - std::vector sentenceBuffer; + std::vector buffer; std::wstring storage; std::recursive_mutex ttMutex; HANDLE deletionEvent;