-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.cpp
More file actions
72 lines (58 loc) · 1.74 KB
/
controller.cpp
File metadata and controls
72 lines (58 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "controller.h"
#include "captureworker.h"
Controller::Controller()
{
connect(&m_workerThread, &QThread::started, this, &Controller::onStarted);
connect(&m_workerThread, &QThread::finished, this, &Controller::onFinished);
connect(&m_dataBase, &DataBase::Error, this, &Controller::onDataBaseError);
m_dataBase.Connect();
}
Controller::~Controller()
{
m_workerThread.quit();
m_workerThread.wait();
}
void Controller::StartStopCapturing(bool bStart)
{
if(bStart == CapturingState())
return;
if(bStart)
{
auto worker = new CaptureWorker(m_dataBase.GetLastCapturedImage());
connect( worker, &CaptureWorker::Error, this, &Controller::onCaptureWorkerError);
connect( worker, &CaptureWorker::NewScreenshotCaptured, this, &Controller::onNewScreenshotCaptured);
connect( &m_workerThread, &QThread::started, worker, &CaptureWorker::Start);
connect( &m_workerThread, &QThread::finished, worker, &CaptureWorker::deleteLater);
worker->moveToThread(&m_workerThread);
m_workerThread.start();
}
else
{
m_workerThread.quit();
}
}
bool Controller::CapturingState() const
{
return m_workerThread.isRunning();
}
void Controller::onStarted()
{
emit CapturingStateChanged(true);
}
void Controller::onFinished()
{
emit CapturingStateChanged(false);
}
void Controller::onCaptureWorkerError(QString err)
{
emit Error("CaptureWorker error: " + err);
}
void Controller::onNewScreenshotCaptured(const ScreenShot& shot)
{
m_dataBase.AddScreenShot(shot);
emit DataBaseUpdated();
}
void Controller::onDataBaseError(QString err)
{
emit Error("DataBase error: " + err);
}