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); settings.open(QIODevice::ReadWrite | QIODevice::Truncate);
QDataStream writer(&settings); QDataStream writer(&settings);
writer << this->geometry(); writer << this->geometry();
Host::Close();
delete ui; delete ui;
} }

View File

@ -147,7 +147,6 @@ namespace Host
void DispatchText(ThreadParameter tp, const BYTE* text, int len) 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; if (!text || len <= 0) return;
HOST_LOCK; HOST_LOCK;
TextThread *it; TextThread *it;

View File

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

View File

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