-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmodels.cpp
67 lines (63 loc) · 1.75 KB
/
models.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
#include "models.h"
CopyPaste::CopyPaste(const Direction &direction, const QDateTime ×tamp, const QString &text)
: direction(direction)
, timestamp(timestamp)
, mimeType(TextType)
, text(text)
{
}
CopyPaste::CopyPaste()
: direction(Incoming)
{
}
QVariantMap CopyPaste::saveState()
{
QVariantMap state;
// if (type == CopyPasteType::Incoming) {
// state.insert("type", 1);
// } else {
// state.insert("type", 2);
// }
state.insert("timestamp", timestamp);
state.insert("mime_type", mimeType);
if (mimeType == TextType) {
state.insert("text", text);
} else if (mimeType == ImageType) {
state.insert("image", image);
} else if (mimeType == BinaryType) {
state.insert("files", files);
} else {
}
return state;
}
bool CopyPaste::restoreState(const QVariantMap &state)
{
// bool ok;
// if (state.value("type").toInt(&ok) == 1) {
// type = Incoming;
// } else if (state.value("type").toInt(&ok) == 2) {
// type = Outgoing;
// } else {
// return false;
// }
// if (!ok) {
// return false;
// }
timestamp = state.value("timestamp").toDateTime();
mimeType = state.value("mime_type").toString();
text = state.value("text").toString();
image = state.value("image").toByteArray();
files = state.value("files").toStringList();
if (!timestamp.isValid() || mimeType.isEmpty()) {
return false;
}
if (mimeType == TextType) {
return !text.isEmpty();
} else if (mimeType == ImageType) {
return !image.isEmpty();
} else if (mimeType == BinaryType) {
return !files.isEmpty();
} else {
return false;
}
}