This repository has been archived by the owner on Feb 5, 2021. It is now read-only.
/
extension.cpp
240 lines (201 loc) · 5.31 KB
/
extension.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#include "stdafx.h"
#include "extension.h"
Extension::Extension(const Extension &e)
{
m_title = e.m_title;
m_author = e.m_author;
m_comment = e.m_comment;
m_shortcut = e.m_shortcut;
m_field = e.m_field;
m_method = e.m_method;
m_content = e.m_content;
m_createdAt = e.m_createdAt;
m_lastModifiedAt = e.m_lastModifiedAt;
m_uuid = e.m_uuid;
m_from = e.m_from;
m_category = e.m_category;
m_path = e.m_path;
}
Extension &Extension::operator=(const Extension &e)
{
m_title = e.m_title;
m_author = e.m_author;
m_comment = e.m_comment;
m_shortcut = e.m_shortcut;
m_field = e.m_field;
m_method = e.m_method;
m_content = e.m_content;
m_createdAt = e.m_createdAt;
m_lastModifiedAt = e.m_lastModifiedAt;
m_uuid = e.m_uuid;
m_from = e.m_from;
m_category = e.m_category;
m_path = e.m_path;
return *this;
}
bool Extension::load(const QString &path)
{
QDomDocument doc;
QFile file(path);
if (!file.open(QIODevice::ReadOnly))
return false;
if (!doc.setContent(&file))
{
file.close();
return false;
}
file.close();
QDomElement docElem = doc.documentElement();
setUuid(docElem.attribute("uuid"));
setField(docElem.attribute("field"));
setAuthor(docElem.attribute("author"));
setTitle(docElem.attribute("title"));
setComment(docElem.attribute("comment"));
setShortcut(docElem.attribute("shortcut"));
setMethod(docElem.attribute("method"));
setCreatedAt(docElem.attribute("createAt"));
setLastModifiedAt(docElem.attribute("lastModifiedAt"));
setCategory(docElem.attribute("category"));
QDomElement contentElem = docElem.firstChildElement("content");
if (!contentElem.isNull())
setContent(contentElem.text());
m_path = path;
return true;
}
bool Extension::save()
{
QDomDocument doc;
QDomElement root = doc.createElement("extension");
doc.appendChild(root);
root.setAttribute("uuid", m_uuid);
root.setAttribute("field", m_field);
root.setAttribute("author", m_author);
root.setAttribute("title", m_title);
root.setAttribute("comment", m_comment);
root.setAttribute("shortcut", m_shortcut);
root.setAttribute("method", m_method);
root.setAttribute("createAt", m_createdAt);
root.setAttribute("lastModifiedAt", m_lastModifiedAt);
root.setAttribute("category", m_category);
QDomElement contentElem = doc.createElement("content");
QDomCDATASection contentCData = doc.createCDATASection(m_content);
contentElem.appendChild(contentCData);
root.appendChild(contentElem);
QFile file(m_path);
if (!file.open(QIODevice::WriteOnly))
return false;
QTextStream out(&file);
const int IndentSize = 4;
doc.save(out, IndentSize);
file.close();
return true;
}
void Extension::destroy()
{
QFile file(m_path);
file.remove();
}
const QString &Extension::title() const
{
return m_title;
}
void Extension::setTitle(const QString &title)
{
m_title = title;
}
const QString &Extension::author() const
{
return m_author;
}
void Extension::setAuthor(const QString &author)
{
m_author = author;
}
const QString &Extension::field() const
{
return m_field;
}
void Extension::setField(const QString &field)
{
m_field = field;
}
const QString &Extension::method() const
{
return m_method;
}
void Extension::setMethod(const QString &method)
{
m_method = method;
}
const QString &Extension::content() const
{
return m_content;
}
void Extension::setContent(const QString &content)
{
m_content = content;
}
const QString &Extension::createdAt() const
{
return m_createdAt;
}
void Extension::setCreatedAt(const QString &createdAt)
{
m_createdAt = createdAt;
}
const QString &Extension::lastModifiedAt() const
{
return m_lastModifiedAt;
}
void Extension::setLastModifiedAt(const QString &lastModifiedAt)
{
m_lastModifiedAt = lastModifiedAt;
}
const QString &Extension::uuid() const
{
return m_uuid;
}
void Extension::setUuid(const QString &uuid)
{
m_uuid = uuid;
}
const QString &Extension::from() const
{
return m_from;
}
void Extension::setFrom(const QString &from)
{
m_from = from;
}
const QString &Extension::shortcut() const
{
return m_shortcut;
}
void Extension::setShortcut(const QString &shortcut)
{
m_shortcut = shortcut;
}
const QString &Extension::comment() const
{
return m_comment;
}
void Extension::setComment(const QString &comment)
{
m_comment = comment;
}
void Extension::changePathToCustomExtensionDirectory()
{
m_path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) % "/extensions";
QDir dir(m_path);
if (!dir.exists())
dir.mkpath(m_path);
m_path.append("/" % m_uuid % ".xml");
}
const QString &Extension::category() const
{
return m_category;
}
void Extension::setCategory(const QString &category)
{
m_category = category;
}