-
Notifications
You must be signed in to change notification settings - Fork 0
/
Screenshot.cpp
70 lines (56 loc) · 1.51 KB
/
Screenshot.cpp
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
#include "Screenshot.h"
#include <ctime>
#include <sstream>
#include <iomanip>
#include "BufferSaver.h"
Screenshot::Screenshot(std::string savePath) : path(savePath)
{
}
Screenshot::~Screenshot()
{
}
bool Screenshot::takeAndSaveScreenshot(std::string name)
{
if (!takeScreenshot())
return false;
saveScreenshot(name);
return true;
}
void Screenshot::saveScreenshot(std::string name)
{
if (name == "")
name = getScreenshotNameFromDate();
//передай сохранение BufferSaver с именем файла и пути
if (saver)
saver->saveScreenshot(path, name);
}
std::string Screenshot::getPath() const
{
return path;
}
void Screenshot::setPath(const std::string &value)
{
path = value;
}
std::shared_ptr<BufferSaver> Screenshot::getSaver() const
{
return saver;
}
void Screenshot::setSaver(const std::shared_ptr<BufferSaver> &value)
{
saver = value;
}
//Генерирует строку в формате YYYY-MM-DD HH MM SS
std::string Screenshot::getScreenshotNameFromDate()
{
std::string name;
std::time_t t = std::time(nullptr);
std::tm * curDate = std::localtime(&t);
std::stringstream ss;
ss << std::setfill('0');
ss << (curDate->tm_year + 1900) << '-' << std::setw(2) << (curDate->tm_mon + 1) << '-'
<< std::setw(2) << curDate->tm_mday << " " << std::setw(2) << curDate->tm_hour
<< ' ' << std::setw(2) << curDate->tm_min << ' ' << std::setw(2) << curDate->tm_sec;
name = ss.str();
return name;
}