WebpagePrinterTool 2.0
Print a web page skip the browser's print preview
载入中...
搜索中...
未找到
WebInterface.h
浏览该文件的文档.
1#pragma once
10#include "ModelsJson.h"
11#include "PrintedPage.h"
12#include "PrinterConfig.h"
13#include <QJsonObject>
14#include <QPrinterInfo>
15#include <deque>
16#include <optional>
17#include <qjsonarray.h>
18#include <qjsonobject.h>
19#include <string_view>
24struct RespBase {
25 RespBase() = delete;
30 bool is_success = false;
36 std::optional<int> uid;
37};
38
48 QString msg{""};
49 static QJsonObject toJsonObject(std::optional<int> uid, const QString& msg) {
50 QJsonObject obj;
51 obj["is_success"] = false;
52 if (uid.has_value()) {
53 obj["uid"] = uid.value();
54 }
55 obj["msg"] = msg;
56 return obj;
57 }
58};
59
64 static constexpr inline std::string_view method{"add_config"};
65 std::optional<int> uid;
67};
68
77 int config_id{-1};
78
79 static QJsonObject toJsonObject(std::optional<int> uid, int config_id) {
80
81 QJsonObject obj;
82 obj["is_success"] = true;
83 if (uid.has_value()) {
84 obj["uid"] = uid.value();
85 }
86 obj["config_id"] = config_id;
87 return obj;
88 }
89};
90
95 static constexpr inline std::string_view method{"update_config"};
96 std::optional<int> uid;
98};
99
104
105 static QJsonObject toJsonObject(std::optional<int> uid) {
106 QJsonObject obj;
107 obj["is_success"] = true;
108 if (uid.has_value()) {
109 obj["uid"] = uid.value();
110 }
111 return obj;
112 }
113};
114
119 static constexpr inline std::string_view method{"del_config"};
120 std::optional<int> uid;
125 int data{};
126};
127
132 static QJsonObject toJsonObject(std::optional<int> uid) {
133 QJsonObject obj;
134 obj["is_success"] = true;
135 if (uid.has_value()) {
136 obj["uid"] = uid.value();
137 }
138 return obj;
139 }
140};
141
146 static constexpr inline std::string_view method{"get_all_configs"};
147 std::optional<int> uid;
148};
149
154 std::deque<PrinterConfig> data{};
155 static QJsonObject toJsonObject(std::optional<int> uid,
156 const std::deque<PrinterConfig>& configs) {
157 QJsonObject obj;
158 obj["is_success"] = true;
159 if (uid.has_value()) {
160 obj["uid"] = uid.value();
161 }
162 QJsonArray arr;
163 for (auto& config : configs) {
164 arr.append(toPrinterConfigJson(config));
165 }
166 obj["data"] = arr;
167 return obj;
168 }
169};
170
175 static constexpr inline std::string_view method{"get_pages_desc"};
176 std::optional<int> uid;
178 int page_size{10};
179};
180
185 std::deque<PrinterConfig> data{};
186
191 int count{0};
192 static QJsonObject toJsonObject(std::optional<int> uid,
193 const std::deque<PrintedPage>& configs,int count) {
194 QJsonObject obj;
195 obj["is_success"] = true;
196 if (uid.has_value()) {
197 obj["uid"] = uid.value();
198 }
199 QJsonArray arr;
200 for (auto& config : configs) {
201 arr.append(toPrintedPageJson(config));
202 }
203 obj["data"] = arr;
204 obj["count"] = count;
205 return obj;
206 }
207};
208
213 static constexpr inline std::string_view method{"get_websocket_server_port"};
214 std::optional<int> uid;
215};
216
225 QString data{""};
226 static QJsonObject toJsonObject(std::optional<int> uid, const QString& port) {
227 QJsonObject obj;
228 obj["is_success"] = true;
229 if (uid.has_value()) {
230 obj["uid"] = uid.value();
231 }
232 obj["data"] = port;
233 return obj;
234 }
235};
236
241 static constexpr inline std::string_view method{"get_printers_info"};
242 std::optional<int> uid;
243};
245 QString printer_name{""};
246 QList<QString> supported_paper_names{};
247};
248
253
254 QList<PrinterInfo> data{};
255
256 static QJsonObject toJsonObject(std::optional<int> uid, const QList<QPrinterInfo>& printers) {
257 QJsonObject obj;
258 obj["is_success"] = true;
259 if (uid.has_value()) {
260 obj["uid"] = uid.value();
261 }
262 QJsonArray arr;
263 for (auto& printer : printers) {
264 QJsonObject printer_obj;
265 printer_obj["printer_name"] = printer.printerName();
266 QJsonArray paper_names_arr;
267 for (auto& paper_name : printer.supportedPageSizes()) {
268 paper_names_arr.append(paper_name.name());
269 }
270 printer_obj["supported_paper_names"] = paper_names_arr;
271 arr.append(printer_obj);
272 }
273 obj["data"] = arr;
274 return obj;
275 }
276};
277
283 static constexpr inline std::string_view method{"print_page"};
284 std::optional<int> uid;
286};
287
296 QString file_path{""};
301 int page_id{0};
302
303 static QJsonObject toJsonObject(std::optional<int> uid, const QString& file_path, int page_id) {
304 QJsonObject obj;
305 obj["is_success"] = true;
306 if (uid.has_value()) {
307 obj["uid"] = uid.value();
308 }
309 obj["file_path"] = file_path;
310 obj["page_id"] = page_id;
311 return obj;
312 }
313};
QJsonObject toPrinterConfigJson(const PrinterConfig &config)
定义 ModelsJson.cpp:88
QJsonObject toPrintedPageJson(const PrintedPage &page)
定义 ModelsJson.cpp:6
定义 PrintedPage.h:5
定义 PrinterConfig.h:5
定义 WebInterface.h:244
QList< QString > supported_paper_names
定义 WebInterface.h:246
QString printer_name
定义 WebInterface.h:245
添加打印配置 request
定义 WebInterface.h:63
PrinterConfig data
定义 WebInterface.h:66
std::optional< int > uid
定义 WebInterface.h:65
static constexpr std::string_view method
定义 WebInterface.h:64
删除打印配置 request
定义 WebInterface.h:118
std::optional< int > uid
定义 WebInterface.h:120
static constexpr std::string_view method
定义 WebInterface.h:119
int data
打印配置id
定义 WebInterface.h:125
获取所有打印配置 request
定义 WebInterface.h:145
std::optional< int > uid
定义 WebInterface.h:147
static constexpr std::string_view method
定义 WebInterface.h:146
倒序打印页面获取 request
定义 WebInterface.h:174
int page_size
定义 WebInterface.h:178
std::optional< int > uid
定义 WebInterface.h:176
int page_index
定义 WebInterface.h:177
static constexpr std::string_view method
定义 WebInterface.h:175
获取打印机信息 request
定义 WebInterface.h:240
static constexpr std::string_view method
定义 WebInterface.h:241
std::optional< int > uid
定义 WebInterface.h:242
获取 websocket 服务器端口号 request
定义 WebInterface.h:212
std::optional< int > uid
定义 WebInterface.h:214
static constexpr std::string_view method
定义 WebInterface.h:213
打印页面 request
定义 WebInterface.h:282
static constexpr std::string_view method
定义 WebInterface.h:283
std::optional< int > uid
定义 WebInterface.h:284
PrintedPage data
定义 WebInterface.h:285
更新打印配置 request
定义 WebInterface.h:94
std::optional< int > uid
定义 WebInterface.h:96
static constexpr std::string_view method
定义 WebInterface.h:95
PrinterConfig data
定义 WebInterface.h:97
添加打印配置 response
定义 WebInterface.h:72
static QJsonObject toJsonObject(std::optional< int > uid, int config_id)
定义 WebInterface.h:79
int config_id
打印配置id,由sqlite 生成
定义 WebInterface.h:77
bool is_success
是否成功
定义 WebInterface.h:30
RespBase()=delete
std::optional< int > uid
uid,websocket 的消息request 和 resp 不限制对应关系,uid 保证了他们的联系, 也就是 uid 相同 的 request 和 response 对应 由request端生成
定义 WebInterface.h:36
删除打印配置 response
定义 WebInterface.h:131
static QJsonObject toJsonObject(std::optional< int > uid)
定义 WebInterface.h:132
所有接口的错误返回
定义 WebInterface.h:43
static QJsonObject toJsonObject(std::optional< int > uid, const QString &msg)
定义 WebInterface.h:49
QString msg
错误信息
定义 WebInterface.h:48
获取所有打印配置 response
定义 WebInterface.h:153
std::deque< PrinterConfig > data
定义 WebInterface.h:154
static QJsonObject toJsonObject(std::optional< int > uid, const std::deque< PrinterConfig > &configs)
定义 WebInterface.h:155
倒序打印页面获取 response
定义 WebInterface.h:184
std::deque< PrinterConfig > data
定义 WebInterface.h:185
int count
总数目
定义 WebInterface.h:191
static QJsonObject toJsonObject(std::optional< int > uid, const std::deque< PrintedPage > &configs, int count)
定义 WebInterface.h:192
获取打印机信息 response
定义 WebInterface.h:252
QList< PrinterInfo > data
定义 WebInterface.h:254
static QJsonObject toJsonObject(std::optional< int > uid, const QList< QPrinterInfo > &printers)
定义 WebInterface.h:256
获取 websocket 服务器端口号 response
定义 WebInterface.h:220
QString data
websocket 端口号
定义 WebInterface.h:225
static QJsonObject toJsonObject(std::optional< int > uid, const QString &port)
定义 WebInterface.h:226
打印页面 response
定义 WebInterface.h:291
QString file_path
输出的文件路径,不包含后缀,(.pdf 或.png)
定义 WebInterface.h:296
int page_id
sqlite中存储的对应数据的id
定义 WebInterface.h:301
static QJsonObject toJsonObject(std::optional< int > uid, const QString &file_path, int page_id)
定义 WebInterface.h:303
更新打印配置 response
定义 WebInterface.h:103
static QJsonObject toJsonObject(std::optional< int > uid)
定义 WebInterface.h:105