Debian Codegraph @

application/logexportwidget.cpp

raw
1 // SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 //#include "logexportwidget.h"
6 //#include <QDebug>
7 //#include <QFile>
8 //#include <QTextCodec>
9 //#include <QTextStream>
10
11 //#include "document.h"
12 //#include "table.h"
13 //#include "xlsxdocument.h"
14
15 //#include <DApplication>
16 //#include <QTextDocument>
17 //#include <QTextDocumentWriter>
18
19 //DWIDGET_USE_NAMESPACE
20
21 //LogExportWidget::LogExportWidget(QWidget *parent)
22 // : DWidget(parent)
23 //{
24 //}
25
26 //bool LogExportWidget::exportToTxt(QString fileName, QStandardItemModel *pModel, LOG_FLAG flag)
27 //{
28 // QFile fi(fileName);
29 // if (!fi.open(QIODevice::WriteOnly))
30 // return false;
31
32 // QTextStream out(&fi);
33 // if (flag == APP) {
34 // for (int row = 0; row < pModel->rowCount(); ++row) {
35 // out << pModel->horizontalHeaderItem(0)->text() << ": "
36 // << pModel->item(row, 0)->data(Qt::UserRole + 6).toString() << " ";
37 // for (int col = 1; col < pModel->columnCount(); ++col) {
38 // out << pModel->horizontalHeaderItem(col)->text() << ": "
39 // << pModel->item(row, col)->text() << " ";
40 // }
41 // out << "\n";
42 // }
43 // } else {
44 // for (int row = 0; row < pModel->rowCount(); row++) {
45 // for (int col = 0; col < pModel->columnCount(); col++) {
46 // out << pModel->horizontalHeaderItem(col)->text() << ": "
47 // << pModel->item(row, col)->text() << " ";
48 // }
49 // out << "\n";
50 // }
51 // }
52 // fi.close();
53 // return true;
54 //}
55
56 //bool LogExportWidget::exportToTxt(QString fileName, QList<LOG_MSG_JOURNAL> jList)
57 //{
58 // QFile fi(fileName);
59 // if (!fi.open(QIODevice::WriteOnly)) {
60 // return false;
61 // }
62 // QTextStream out(&fi);
63 // out.setCodec(QTextCodec::codecForName("utf-8"));
64 // for (int i = 0; i < jList.count(); i++) {
65 // LOG_MSG_JOURNAL jMsg = jList.at(i);
66 // // out << QString(DApplication::translate("Table", "Date and Time:")) <<
67 // // jMsg.dateTime << " "; out << QString(DApplication::translate("Table", "User:")) <<
68 // // jMsg.hostName << " "; out << QString(DApplication::translate("Table", "Daemon:"))
69 // // << jMsg.daemonName << " "; out << QString(DApplication::translate("Table",
70 // // "PID:")) << jMsg.daemonId << " "; out << QString(DApplication::translate("Table",
71 // // "Level:")) << jMsg.level << " "; out << QString(DApplication::translate("Table",
72 // // "Info:")) << jMsg.msg << " "; //delete bug
73 // out << QString(DApplication::translate("Table", "Level:")) << jMsg.level << " ";
74 // out << QString(DApplication::translate("Table", "Process:")) << jMsg.daemonName << " ";
75 // out << QString(DApplication::translate("Table", "Date and Time:")) << jMsg.dateTime << " ";
76 // if (jMsg.msg.isEmpty()) {
77 // out << QString(DApplication::translate("Table", "Info:"))
78 // << QString(DApplication::translate("Table", "Null")) << " "; // modify for bug
79 // } else {
80 // out << QString(DApplication::translate("Table", "Info:")) << jMsg.msg << " ";
81 // }
82 // out << QString(DApplication::translate("Table", "User:")) << jMsg.hostName << " ";
83 // out << QString(DApplication::translate("Table", "PID:")) << jMsg.daemonId << " ";
84 // out << "\n";
85 // }
86 // fi.close();
87 // return true;
88 //}
89
90 //bool LogExportWidget::exportToTxt(QString fileName, QList<LOG_MSG_JOURNAL> jList, QStringList labels)
91 //{
92 // QFile fi(fileName);
93 // if (!fi.open(QIODevice::WriteOnly)) {
94 // return false;
95 // }
96 // QTextStream out(&fi);
97 // out.setCodec(QTextCodec::codecForName("utf-8"));
98 // for (int i = 0; i < jList.count(); i++) {
99 // int col = 0;
100 // LOG_MSG_JOURNAL jMsg = jList.at(i);
101 // out << labels.value(col++, "") << ":" << jMsg.dateTime << " ";
102 // out << labels.value(col++, "") << ":" << jMsg.hostName << " ";
103 // out << labels.value(col++, "") << ":" << jMsg.daemonName << " ";
104 // out << labels.value(col++, "") << ":" << jMsg.msg << " ";
105 // out << "\n";
106 // }
107 // fi.close();
108 // return true;
109 //}
110
111 //bool LogExportWidget::exportToTxt(QString fileName, QList<LOG_MSG_APPLICATOIN> jList, QStringList labels)
112 //{
113 // QFile fi(fileName);
114 // if (!fi.open(QIODevice::WriteOnly)) {
115 // return false;
116 // }
117 // qDebug() << "labels" << labels;
118 // QTextStream out(&fi);
119
120 // out.setCodec(QTextCodec::codecForName("utf-8"));
121 // for (int i = 0; i < jList.count(); i++) {
122 // int col = 0;
123 // LOG_MSG_APPLICATOIN jMsg = jList.at(i);
124 // out << labels.value(col++, "") << ":" << jMsg.level << " ";
125 // out << labels.value(col++, "") << ":" << jMsg.dateTime << " ";
126 // out << labels.value(col++, "") << ":" << jMsg.src << " ";
127 // out << labels.value(col++, "") << ":" << jMsg.msg << " ";
128 // out << "\n";
129 // }
130 // fi.close();
131 // return true;
132 //}
133
134 //bool LogExportWidget::exportToTxt(QString fileName, QList<LOG_MSG_DPKG> jList, QStringList labels)
135 //{
136 // QFile fi(fileName);
137 // if (!fi.open(QIODevice::WriteOnly)) {
138 // return false;
139 // }
140
141 // QTextStream out(&fi);
142 // out.setCodec(QTextCodec::codecForName("utf-8"));
143 // for (int i = 0; i < jList.count(); i++) {
144 // int col = 0;
145 // LOG_MSG_DPKG jMsg = jList.at(i);
146 // out << labels.value(col++, "") << ":" << jMsg.dateTime << " ";
147 // out << labels.value(col++, "") << ":" << jMsg.msg << " ";
148 // out << labels.value(col++, "") << ":" << jMsg.action << " ";
149 // out << "\n";
150 // }
151 // fi.close();
152 // return true;
153 //}
154
155 //bool LogExportWidget::exportToTxt(QString fileName, QList<LOG_MSG_BOOT> jList, QStringList labels)
156 //{
157 // QFile fi(fileName);
158 // if (!fi.open(QIODevice::WriteOnly)) {
159 // return false;
160 // }
161 // QTextStream out(&fi);
162 // out.setCodec(QTextCodec::codecForName("utf-8"));
163 // for (int i = 0; i < jList.count(); i++) {
164 // LOG_MSG_BOOT jMsg = jList.at(i);
165 // int col = 0;
166 // out << labels.value(col++, "") << ":" << jMsg.status << " ";
167 // out << labels.value(col++, "") << ":" << jMsg.msg << " ";
168 // out << "\n";
169 // }
170 // fi.close();
171 // return true;
172 //}
173
174 //bool LogExportWidget::exportToTxt(QString fileName, QList<LOG_MSG_XORG> jList, QStringList labels)
175 //{
176 // QFile fi(fileName);
177 // if (!fi.open(QIODevice::WriteOnly)) {
178 // return false;
179 // }
180 // QTextStream out(&fi);
181 // out.setCodec(QTextCodec::codecForName("utf-8"));
182 // for (int i = 0; i < jList.count(); i++) {
183 // LOG_MSG_XORG jMsg = jList.at(i);
184 // int col = 0;
185 // out << labels.value(col++, "") << ":" << jMsg.dateTime << " ";
186 // out << labels.value(col++, "") << ":" << jMsg.msg << " ";
187 // out << "\n";
188 // }
189 // fi.close();
190 // return true;
191 //}
192
193 //bool LogExportWidget::exportToTxt(QString fileName, QList<LOG_MSG_NORMAL> jList, QStringList labels)
194 //{
195 // QFile fi(fileName);
196 // if (!fi.open(QIODevice::WriteOnly)) {
197 // return false;
198 // }
199 // QTextStream out(&fi);
200 // out.setCodec(QTextCodec::codecForName("utf-8"));
201 // for (int i = 0; i < jList.count(); i++) {
202 // LOG_MSG_NORMAL jMsg = jList.at(i);
203 // int col = 0;
204 // out << labels.value(col++, "") << ":" << jMsg.eventType << " ";
205 // out << labels.value(col++, "") << ":" << jMsg.userName << " ";
206 // out << labels.value(col++, "") << ":" << jMsg.dateTime << " ";
207 // out << labels.value(col++, "") << ":" << jMsg.msg << " ";
208 // out << "\n";
209 // }
210 // fi.close();
211 // return true;
212 //}
213
214 //bool LogExportWidget::exportToDoc(QString fileName, QStandardItemModel *pModel, LOG_FLAG flag)
215 //{
216 //#if 1
217 // Docx::Document doc(DOCTEMPLATE);
218 // Docx::Table *tab = doc.addTable(pModel->rowCount() + 1, pModel->columnCount());
219 // tab->setAlignment(Docx::WD_TABLE_ALIGNMENT::LEFT);
220
221 // for (int col = 0; col < pModel->columnCount(); ++col) {
222 // auto item = pModel->horizontalHeaderItem(col);
223 // auto cel = tab->cell(0, col);
224 // if (item) {
225 // cel->addText(pModel->horizontalHeaderItem(col)->text());
226 // }
227 // }
228 // if (flag == APP) {
229 // for (int row = 0; row < pModel->rowCount(); ++row) {
230 // auto cel = tab->cell(row + 1, 0);
231 // cel->addText(pModel->item(row, 0)->data(Qt::UserRole + 6).toString());
232 // for (int col = 1; col < pModel->columnCount(); ++col) {
233 // auto cel = tab->cell(row + 1, col);
234 // cel->addText(pModel->item(row, col)->text());
235 // }
236 // }
237 // } else {
238 // for (int row = 0; row < pModel->rowCount(); ++row) {
239 // for (int col = 0; col < pModel->columnCount(); ++col) {
240 // auto cel = tab->cell(row + 1, col);
241 // cel->addText(pModel->item(row, col)->text());
242 // }
243 // }
244 // }
245 // doc.save(fileName);
246 //#else
247 // QTextDocumentWriter writer(fileName);
248 // writer.setFormat("odf");
249 // QTextDocument *doc = new QTextDocument;
250 // QString html;
251 // html.append("<!DOCTYPE html>\n");
252 // html.append("<html>\n");
253 // html.append("<body>\n");
254 // html.append("<table border=\"1\">\n");
255 // // write title
256 // html.append("<tr>");
257 // for (int i = 0; i < pModel->columnCount(); ++i) {
258 // QString labelInfo = QString("<td>%1</td>").arg(pModel->horizontalHeaderItem(i)->text());
259 // html.append(labelInfo.toUtf8().data());
260 // }
261 // html.append("</tr>");
262 // // write contents
263 // for (int row = 0; row < pModel->rowCount(); ++row) {
264 // html.append("<tr>");
265 // for (int col = 0; col < pModel->columnCount(); ++col) {
266 // QString info = QString("<td>%1</td>").arg(pModel->item(row, col)->text());
267 // html.append(info.toUtf8().data());
268 // }
269 // html.append("</tr>");
270 // }
271 // html.append("</table>\n");
272 // html.append("</body>\n");
273 // html.append("</html>\n");
274 // doc->setHtml(html);
275 // writer.write(doc);
276 //#endif
277 // return true;
278 //}
279
280 //bool LogExportWidget::exportToDoc(QString fileName, QList<LOG_MSG_JOURNAL> jList,
281 // QStringList labels, LOG_FLAG iFlag)
282 //{
283 //#if 1
284 // Docx::Document doc(DOCTEMPLATE);
285 // Docx::Table *tab = doc.addTable(jList.count() + 1, 6);
286 // tab->setAlignment(Docx::WD_TABLE_ALIGNMENT::LEFT);
287
288 // for (int col = 0; col < labels.count(); ++col) {
289 // auto cel = tab->cell(0, col);
290 // cel->addText(labels.at(col));
291 // }
292
293 // for (int row = 0; row < jList.count(); ++row) {
294 // LOG_MSG_JOURNAL message = jList.at(row);
295 // int col = 0;
296 // if (iFlag == JOURNAL || iFlag == BOOT_KLU) {
297 // tab->cell(row + 1, col++)->addText(message.level);
298 // tab->cell(row + 1, col++)->addText(message.daemonName);
299 // tab->cell(row + 1, col++)->addText(message.dateTime);
300 // tab->cell(row + 1, col++)->addText(message.msg);
301 // tab->cell(row + 1, col++)->addText(message.hostName);
302 // tab->cell(row + 1, col++)->addText(message.daemonId);
303 // } else if (iFlag == KERN) {
304 // tab->cell(row + 1, col++)->addText(message.dateTime);
305 // tab->cell(row + 1, col++)->addText(message.hostName);
306 // tab->cell(row + 1, col++)->addText(message.daemonName);
307 // tab->cell(row + 1, col++)->addText(message.msg);
308 // }
309 // }
310 // doc.save(fileName);
311 //#else
312 // QTextDocumentWriter writer(fileName);
313 // writer.setFormat("odf");
314 // QTextDocument *doc = new QTextDocument;
315 // QString html;
316 // html.append("<!DOCTYPE html>\n");
317 // html.append("<html>\n");
318 // html.append("<body>\n");
319 // html.append("<table border=\"1\">\n");
320 // QString title = QString(
321 // "<tr><td>时间</td><td>主机名</td><td>守护进程</td><td>进程ID</td><td>级别</td><td>消息</"
322 // "td></tr>");
323 // html.append(title.toUtf8().data());
324 // for (int i = 0; i < jList.count(); i++) {
325 // LOG_MSG_JOURNAL jMsg = jList.at(i);
326 // QString info =
327 // QString("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr>")
328 // .arg(jMsg.dateTime)
329 // .arg(jMsg.hostName)
330 // .arg(jMsg.daemonName)
331 // .arg(jMsg.daemonId)
332 // .arg(jMsg.level)
333 // .arg(jMsg.msg);
334 // html.append(info.toUtf8().data());
335 // }
336
337 // html.append("</table>\n");
338 // html.append("</body>\n");
339 // html.append("</html>\n");
340 // doc->setHtml(html);
341 // writer.write(doc);
342 //#endif
343 // return true;
344 //}
345
346 //bool LogExportWidget::exportToDoc(QString fileName, QList<LOG_MSG_APPLICATOIN> jList, QStringList labels)
347 //{
348 // Docx::Document doc(DOCTEMPLATE);
349 // Docx::Table *tab = doc.addTable(jList.count() + 1, 6);
350 // tab->setAlignment(Docx::WD_TABLE_ALIGNMENT::LEFT);
351
352 // for (int col = 0; col < labels.count(); ++col) {
353 // auto cel = tab->cell(0, col);
354 // cel->addText(labels.at(col));
355 // }
356
357 // for (int row = 0; row < jList.count(); ++row) {
358 // LOG_MSG_APPLICATOIN message = jList.at(row);
359 // int col = 0;
360 // tab->cell(row + 1, col++)->addText(message.level);
361 // tab->cell(row + 1, col++)->addText(message.dateTime);
362 // tab->cell(row + 1, col++)->addText(message.src);
363 // tab->cell(row + 1, col++)->addText(message.msg);
364 // }
365 // doc.save(fileName);
366 // return true;
367 //}
368
369 //bool LogExportWidget::exportToDoc(QString fileName, QList<LOG_MSG_DPKG> jList, QStringList labels)
370 //{
371 // Docx::Document doc(DOCTEMPLATE);
372 // Docx::Table *tab = doc.addTable(jList.count() + 1, 6);
373 // tab->setAlignment(Docx::WD_TABLE_ALIGNMENT::LEFT);
374
375 // for (int col = 0; col < labels.count(); ++col) {
376 // auto cel = tab->cell(0, col);
377 // cel->addText(labels.at(col));
378 // }
379
380 // for (int row = 0; row < jList.count(); ++row) {
381 // LOG_MSG_DPKG message = jList.at(row);
382 // int col = 0;
383 // tab->cell(row + 1, col++)->addText(message.dateTime);
384 // tab->cell(row + 1, col++)->addText(message.msg);
385 // tab->cell(row + 1, col++)->addText(message.action);
386
387 // }
388 // doc.save(fileName);
389 // return true;
390 //}
391
392 //bool LogExportWidget::exportToDoc(QString fileName, QList<LOG_MSG_BOOT> jList, QStringList labels)
393 //{
394 // Docx::Document doc(DOCTEMPLATE);
395 // Docx::Table *tab = doc.addTable(jList.count() + 1, 6);
396 // tab->setAlignment(Docx::WD_TABLE_ALIGNMENT::LEFT);
397
398 // for (int col = 0; col < labels.count(); ++col) {
399 // auto cel = tab->cell(0, col);
400 // cel->addText(labels.at(col));
401 // }
402
403 // for (int row = 0; row < jList.count(); ++row) {
404 // LOG_MSG_BOOT message = jList.at(row);
405 // int col = 0;
406 // tab->cell(row + 1, col++)->addText(message.status);
407 // tab->cell(row + 1, col++)->addText(message.msg);
408 // }
409 // doc.save(fileName);
410 // return true;
411 //}
412
413 //bool LogExportWidget::exportToDoc(QString fileName, QList<LOG_MSG_XORG> jList, QStringList labels)
414 //{
415 // Docx::Document doc(DOCTEMPLATE);
416 // Docx::Table *tab = doc.addTable(jList.count() + 1, 6);
417 // tab->setAlignment(Docx::WD_TABLE_ALIGNMENT::LEFT);
418
419 // for (int col = 0; col < labels.count(); ++col) {
420 // auto cel = tab->cell(0, col);
421 // cel->addText(labels.at(col));
422 // }
423
424 // for (int row = 0; row < jList.count(); ++row) {
425 // LOG_MSG_XORG message = jList.at(row);
426 // int col = 0;
427 // tab->cell(row + 1, col++)->addText(message.dateTime);
428 // tab->cell(row + 1, col++)->addText(message.msg);
429 // }
430 // doc.save(fileName);
431 // return true;
432 //}
433
434 //bool LogExportWidget::exportToDoc(QString fileName, QList<LOG_MSG_NORMAL> jList, QStringList labels)
435 //{
436 // Docx::Document doc(DOCTEMPLATE);
437 // Docx::Table *tab = doc.addTable(jList.count() + 1, 6);
438 // tab->setAlignment(Docx::WD_TABLE_ALIGNMENT::LEFT);
439 // for (int col = 0; col < labels.count(); ++col) {
440 // auto cel = tab->cell(0, col);
441 // cel->addText(labels.at(col));
442 // }
443 // for (int row = 0; row < jList.count(); ++row) {
444 // LOG_MSG_NORMAL message = jList.at(row);
445 // int col = 0;
446 // tab->cell(row + 1, col++)->addText(message.eventType);
447 // tab->cell(row + 1, col++)->addText(message.userName);
448 // tab->cell(row + 1, col++)->addText(message.dateTime);
449 // tab->cell(row + 1, col++)->addText(message.msg);
450 // }
451 // doc.save(fileName);
452 // return true;
453 //}
454
455 //bool LogExportWidget::exportToHtml(QString fileName, QStandardItemModel *pModel, LOG_FLAG flag)
456 //{
457 // QFile html(fileName);
458 // if (!html.open(QIODevice::WriteOnly))
459 // return false;
460 // html.write("<!DOCTYPE html>\n");
461 // html.write("<html>\n");
462 // html.write("<body>\n");
463 // html.write("<table border=\"1\">\n");
464 // // write title
465 // html.write("<tr>");
466 // for (int i = 0; i < pModel->columnCount(); ++i) {
467 // QString labelInfo = QString("<td>%1</td>").arg(pModel->horizontalHeaderItem(i)->text());
468 // html.write(labelInfo.toUtf8().data());
469 // }
470 // html.write("</tr>");
471 // // write contents
472 // if (flag == APP) {
473 // for (int row = 0; row < pModel->rowCount(); ++row) {
474 // html.write("<tr>");
475
476 // QString info =
477 // QString("<td>%1</td>").arg(pModel->item(row, 0)->data(Qt::UserRole + 6).toString());
478 // html.write(info.toUtf8().data());
479
480 // for (int col = 1; col < pModel->columnCount(); ++col) {
481 // QString info = QString("<td>%1</td>").arg(pModel->item(row, col)->text());
482 // html.write(info.toUtf8().data());
483 // }
484 // html.write("</tr>");
485 // }
486 // } else {
487 // for (int row = 0; row < pModel->rowCount(); ++row) {
488 // html.write("<tr>");
489 // for (int col = 0; col < pModel->columnCount(); ++col) {
490 // QString info = QString("<td>%1</td>").arg(pModel->item(row, col)->text());
491 // html.write(info.toUtf8().data());
492 // }
493 // html.write("</tr>");
494 // }
495 // }
496 // html.write("</table>\n");
497 // html.write("</body>\n");
498 // html.write("</html>\n");
499 // html.close();
500 // return true;
501 //}
502
503 //bool LogExportWidget::exportToHtml(QString fileName, QList<LOG_MSG_JOURNAL> jList)
504 //{
505 // QFile html(fileName);
506 // if (!html.open(QIODevice::WriteOnly)) {
507 // return false;
508 // }
509
510 // html.write("<!DOCTYPE html>\n");
511 // html.write("<html>\n");
512 // html.write("<body>\n");
513 // html.write("<table border=\"1\">\n");
514 // // QString title = QString(
515 // // "<tr><td>时间</td><td>主机名</td><td>守护进程</td><td>进程ID</td><td>级别</td><td>消息</"
516 // // "td></tr>");
517 // // QString title = QString("<tr><td>") +
518 // // QString(DApplication::translate("Table", "Date and Time")) +
519 // // QString("</td><td>") + QString(DApplication::translate("Table", "User")) +
520 // // QString("</td><td>") + QString(DApplication::translate("Table", "Daemon"))
521 // // + QString("</td><td>") + QString(DApplication::translate("Table", "PID"))
522 // // + QString("</td><td>") + QString(DApplication::translate("Table",
523 // // "Level")) + QString("</td><td>") +
524 // // QString(DApplication::translate("Table", "Info")) + QString("</td></tr>");
525 // // //delete for bug
526 // QString title = QString("<tr><td>") + QString(DApplication::translate("Table", "Level")) +
527 // QString("</td><td>") + QString(DApplication::translate("Table", "Process")) +
528 // QString("</td><td>") +
529 // QString(DApplication::translate("Table", "Date and Time")) +
530 // QString("</td><td>") + QString(DApplication::translate("Table", "Info")) +
531 // QString("</td><td>") + QString(DApplication::translate("Table", "User")) +
532 // QString("</td><td>") + QString(DApplication::translate("Table", "PID")) +
533 // QString("</td></tr>");
534 // html.write(title.toUtf8().data());
535 // for (int i = 0; i < jList.count(); i++) {
536 // LOG_MSG_JOURNAL jMsg = jList.at(i);
537 // // QString info =
538 // // QString("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr>")
539 // // .arg(jMsg.dateTime)
540 // // .arg(jMsg.hostName)
541 // // .arg(jMsg.daemonName)
542 // // .arg(jMsg.daemonId)
543 // // .arg(jMsg.level)
544 // // .arg(jMsg.msg); //delete for bug
545 // QString info =
546 // QString("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr>")
547 // .arg(jMsg.level)
548 // .arg(jMsg.daemonName)
549 // .arg(jMsg.dateTime)
550 // .arg(jMsg.msg)
551 // .arg(jMsg.hostName)
552 // .arg(jMsg.daemonId);
553 // html.write(info.toUtf8().data());
554 // }
555
556 // html.write("</table>\n");
557 // html.write("</body>\n");
558 // html.write("</html>\n");
559 // html.close();
560 // return true;
561 //}
562
563 //bool LogExportWidget::exportToHtml(QString fileName, QList<LOG_MSG_JOURNAL> jList, QStringList labels)
564 //{
565 // QFile html(fileName);
566 // if (!html.open(QIODevice::WriteOnly))
567 // return false;
568 // html.write("<!DOCTYPE html>\n");
569 // html.write("<html>\n");
570 // html.write("<body>\n");
571 // html.write("<table border=\"1\">\n");
572 // // write title
573 // html.write("<tr>");
574 // for (int i = 0; i < labels.count(); ++i) {
575 // QString labelInfo = QString("<td>%1</td>").arg(labels.value(i));
576 // html.write(labelInfo.toUtf8().data());
577 // }
578 // html.write("</tr>");
579 // // write contentselse
580 // for (int row = 0; row < jList.count(); ++row) {
581 // LOG_MSG_JOURNAL jMsg = jList.at(row);
582 // QString info =
583 // QString("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td></tr>")
584 // .arg(jMsg.dateTime)
585 // .arg(jMsg.hostName)
586 // .arg(jMsg.daemonName)
587 // .arg(jMsg.msg);
588 // html.write(info.toUtf8().data());
589 // }
590 // html.write("</table>\n");
591 // html.write("</body>\n");
592 // html.write("</html>\n");
593 // html.close();
594 // return true;
595 //}
596
597 //bool LogExportWidget::exportToHtml(QString fileName, QList<LOG_MSG_APPLICATOIN> jList, QStringList labels)
598 //{
599 // QFile html(fileName);
600 // if (!html.open(QIODevice::WriteOnly))
601 // return false;
602 // html.write("<!DOCTYPE html>\n");
603 // html.write("<html>\n");
604 // html.write("<body>\n");
605 // html.write("<table border=\"1\">\n");
606 // // write title
607 // html.write("<tr>");
608 // for (int i = 0; i < labels.count(); ++i) {
609 // QString labelInfo = QString("<td>%1</td>").arg(labels.value(i));
610 // html.write(labelInfo.toUtf8().data());
611 // }
612 // html.write("</tr>");
613 // // write contentselse
614 // for (int row = 0; row < jList.count(); ++row) {
615 // LOG_MSG_APPLICATOIN jMsg = jList.at(row);
616 // QString info =
617 // QString("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td></tr>")
618 // .arg(jMsg.level)
619 // .arg(jMsg.dateTime)
620 // .arg(jMsg.src)
621 // .arg(jMsg.msg);
622 // html.write(info.toUtf8().data());
623 // }
624 // html.write("</table>\n");
625 // html.write("</body>\n");
626 // html.write("</html>\n");
627 // html.close();
628 // return true;
629 //}
630
631 //bool LogExportWidget::exportToHtml(QString fileName, QList<LOG_MSG_DPKG> jList, QStringList labels)
632 //{
633 // QFile html(fileName);
634 // if (!html.open(QIODevice::WriteOnly))
635 // return false;
636 // html.write("<!DOCTYPE html>\n");
637 // html.write("<html>\n");
638 // html.write("<body>\n");
639 // html.write("<table border=\"1\">\n");
640 // // write title
641 // html.write("<tr>");
642 // for (int i = 0; i < labels.count(); ++i) {
643 // QString labelInfo = QString("<td>%1</td>").arg(labels.value(i));
644 // html.write(labelInfo.toUtf8().data());
645 // }
646 // html.write("</tr>");
647 // // write contentselse
648 // for (int row = 0; row < jList.count(); ++row) {
649 // LOG_MSG_DPKG jMsg = jList.at(row);
650 // QString info =
651 // QString("<tr><td>%1</td><td>%2</td><td>%3</td></tr>")
652 // .arg(jMsg.dateTime)
653 // .arg(jMsg.msg)
654 // .arg(jMsg.action);
655 // html.write(info.toUtf8().data());
656 // }
657 // html.write("</table>\n");
658 // html.write("</body>\n");
659 // html.write("</html>\n");
660 // html.close();
661 // return true;
662 //}
663
664 //bool LogExportWidget::exportToHtml(QString fileName, QList<LOG_MSG_BOOT> jList, QStringList labels)
665 //{
666 // QFile html(fileName);
667 // if (!html.open(QIODevice::WriteOnly))
668 // return false;
669 // html.write("<!DOCTYPE html>\n");
670 // html.write("<html>\n");
671 // html.write("<body>\n");
672 // html.write("<table border=\"1\">\n");
673 // // write title
674 // html.write("<tr>");
675 // for (int i = 0; i < labels.count(); ++i) {
676 // QString labelInfo = QString("<td>%1</td>").arg(labels.value(i));
677 // html.write(labelInfo.toUtf8().data());
678 // }
679 // html.write("</tr>");
680 // // write contentselse
681 // for (int row = 0; row < jList.count(); ++row) {
682 // LOG_MSG_BOOT jMsg = jList.at(row);
683 // QString info =
684 // QString("<tr><td>%1</td><td>%2</td></tr>")
685 // .arg(jMsg.status)
686 // .arg(jMsg.msg);
687 // html.write(info.toUtf8().data());
688 // }
689 // html.write("</table>\n");
690 // html.write("</body>\n");
691 // html.write("</html>\n");
692 // html.close();
693 // return true;
694 //}
695
696 //bool LogExportWidget::exportToHtml(QString fileName, QList<LOG_MSG_XORG> jList, QStringList labels)
697 //{
698 // QFile html(fileName);
699 // if (!html.open(QIODevice::WriteOnly))
700 // return false;
701 // html.write("<!DOCTYPE html>\n");
702 // html.write("<html>\n");
703 // html.write("<body>\n");
704 // html.write("<table border=\"1\">\n");
705 // // write title
706 // html.write("<tr>");
707 // for (int i = 0; i < labels.count(); ++i) {
708 // QString labelInfo = QString("<td>%1</td>").arg(labels.value(i));
709 // html.write(labelInfo.toUtf8().data());
710 // }
711 // html.write("</tr>");
712 // // write contentselse
713 // for (int row = 0; row < jList.count(); ++row) {
714 // LOG_MSG_XORG jMsg = jList.at(row);
715 // QString info =
716 // QString("<tr><td>%1</td><td>%2</td></tr>")
717 // .arg(jMsg.dateTime)
718 // .arg(jMsg.msg);
719 // html.write(info.toUtf8().data());
720 // }
721 // html.write("</table>\n");
722 // html.write("</body>\n");
723 // html.write("</html>\n");
724 // html.close();
725 // return true;
726 //}
727
728 //bool LogExportWidget::exportToHtml(QString fileName, QList<LOG_MSG_NORMAL> jList, QStringList labels)
729 //{
730 // QFile html(fileName);
731 // if (!html.open(QIODevice::WriteOnly))
732 // return false;
733 // html.write("<!DOCTYPE html>\n");
734 // html.write("<html>\n");
735 // html.write("<body>\n");
736 // html.write("<table border=\"1\">\n");
737 // // write title
738 // html.write("<tr>");
739 // for (int i = 0; i < labels.count(); ++i) {
740 // QString labelInfo = QString("<td>%1</td>").arg(labels.value(i));
741 // html.write(labelInfo.toUtf8().data());
742 // }
743 // html.write("</tr>");
744 // // write contentselse
745 // for (int row = 0; row < jList.count(); ++row) {
746 // LOG_MSG_NORMAL jMsg = jList.at(row);
747 // QString info =
748 // QString("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td></tr>")
749 // .arg(jMsg.eventType)
750 // .arg(jMsg.userName)
751 // .arg(jMsg.dateTime)
752 // .arg(jMsg.msg);
753 // html.write(info.toUtf8().data());
754 // }
755 // html.write("</table>\n");
756 // html.write("</body>\n");
757 // html.write("</html>\n");
758 // html.close();
759 // return true;
760 //}
761
762 //bool LogExportWidget::exportToXls(QString fileName, QStandardItemModel *pModel, LOG_FLAG flag)
763 //{
764 // auto currentXlsRow = 1;
765 // QXlsx::Document xlsx;
766
767 // for (int col = 0; col < pModel->columnCount(); ++col) {
768 // auto item = pModel->horizontalHeaderItem(col);
769 // if (item) {
770 // QXlsx::Format boldFont;
771 // boldFont.setFontBold(true);
772 // xlsx.write(currentXlsRow, col + 1, item->text(), boldFont);
773 // }
774 // }
775 // ++currentXlsRow;
776
777 // if (flag == APP) {
778 // for (int row = 0; row < pModel->rowCount(); ++row) {
779 // xlsx.write(currentXlsRow, 0 + 1,
780 // pModel->item(row, 0)->data(Qt::UserRole + 6).toString());
781 // for (int col = 1; col < pModel->columnCount(); ++col) {
782 // xlsx.write(currentXlsRow, col + 1, pModel->item(row, col)->text());
783 // }
784 // ++currentXlsRow;
785 // }
786 // } else {
787 // for (int row = 0; row < pModel->rowCount(); ++row) {
788 // for (int col = 0; col < pModel->columnCount(); ++col) {
789 // xlsx.write(currentXlsRow, col + 1, pModel->item(row, col)->text());
790 // }
791 // ++currentXlsRow;
792 // }
793 // }
794
795 // ++currentXlsRow;
796
797 // xlsx.saveAs(fileName);
798
799 // return true;
800 //}
801
802 //bool LogExportWidget::exportToXls(QString fileName, QList<LOG_MSG_JOURNAL> jList,
803 // QStringList labels, LOG_FLAG iFlag)
804 //{
805 // auto currentXlsRow = 1;
806 // QXlsx::Document xlsx;
807 // for (int col = 0; col < labels.count(); ++col) {
808 // QXlsx::Format boldFont;
809 // boldFont.setFontBold(true);
810 // xlsx.write(currentXlsRow, col + 1, labels.at(col), boldFont);
811 // }
812 // ++currentXlsRow;
813 // for (int row = 0; row < jList.count(); ++row) {
814 // LOG_MSG_JOURNAL message = jList.at(row);
815 // int col = 1;
816
817 // if (iFlag == JOURNAL || iFlag == BOOT_KLU) {
818 // xlsx.write(currentXlsRow, col++, message.level);
819 // xlsx.write(currentXlsRow, col++, message.daemonName);
820 // xlsx.write(currentXlsRow, col++, message.dateTime);
821 // xlsx.write(currentXlsRow, col++, message.msg);
822 // xlsx.write(currentXlsRow, col++, message.hostName);
823 // xlsx.write(currentXlsRow, col++, message.daemonId);
824 // } else if (iFlag == KERN) {
825 // xlsx.write(currentXlsRow, col++, message.dateTime);
826 // xlsx.write(currentXlsRow, col++, message.hostName);
827 // xlsx.write(currentXlsRow, col++, message.daemonName);
828 // xlsx.write(currentXlsRow, col++, message.msg);
829 // }
830
831 // ++currentXlsRow;
832 // }
833 // ++currentXlsRow;
834 // xlsx.saveAs(fileName);
835 // return true;
836 //}
837
838 //bool LogExportWidget::exportToXls(QString fileName, QList<LOG_MSG_APPLICATOIN> jList, QStringList labels)
839 //{
840 // auto currentXlsRow = 1;
841 // QXlsx::Document xlsx;
842 // for (int col = 0; col < labels.count(); ++col) {
843 // QXlsx::Format boldFont;
844 // boldFont.setFontBold(true);
845 // xlsx.write(currentXlsRow, col + 1, labels.at(col), boldFont);
846 // }
847 // ++currentXlsRow;
848 // for (int row = 0; row < jList.count(); ++row) {
849 // LOG_MSG_APPLICATOIN message = jList.at(row);
850 // int col = 1;
851 // xlsx.write(currentXlsRow, col++, message.level);
852 // xlsx.write(currentXlsRow, col++, message.dateTime);
853 // xlsx.write(currentXlsRow, col++, message.src);
854 // xlsx.write(currentXlsRow, col++, message.msg);
855 // ++currentXlsRow;
856 // }
857 // ++currentXlsRow;
858 // xlsx.saveAs(fileName);
859 // return true;
860 //}
861
862 //bool LogExportWidget::exportToXls(QString fileName, QList<LOG_MSG_DPKG> jList, QStringList labels)
863 //{
864 // auto currentXlsRow = 1;
865 // QXlsx::Document xlsx;
866 // for (int col = 0; col < labels.count(); ++col) {
867 // QXlsx::Format boldFont;
868 // boldFont.setFontBold(true);
869 // xlsx.write(currentXlsRow, col + 1, labels.at(col), boldFont);
870 // }
871 // ++currentXlsRow;
872 // for (int row = 0; row < jList.count(); ++row) {
873 // LOG_MSG_DPKG message = jList.at(row);
874 // int col = 1;
875 // xlsx.write(currentXlsRow, col++, message.dateTime);
876 // xlsx.write(currentXlsRow, col++, message.msg);
877 // xlsx.write(currentXlsRow, col++, message.action);
878 // ++currentXlsRow;
879 // }
880 // ++currentXlsRow;
881 // xlsx.saveAs(fileName);
882 // return true;
883 //}
884
885 //bool LogExportWidget::exportToXls(QString fileName, QList<LOG_MSG_BOOT> jList, QStringList labels)
886 //{
887 // auto currentXlsRow = 1;
888 // QXlsx::Document xlsx;
889 // for (int col = 0; col < labels.count(); ++col) {
890 // QXlsx::Format boldFont;
891 // boldFont.setFontBold(true);
892 // xlsx.write(currentXlsRow, col + 1, labels.at(col), boldFont);
893 // }
894 // ++currentXlsRow;
895 // for (int row = 0; row < jList.count(); ++row) {
896 // LOG_MSG_BOOT message = jList.at(row);
897 // int col = 1;
898 // xlsx.write(currentXlsRow, col++, message.status);
899 // xlsx.write(currentXlsRow, col++, message.msg);
900 // ++currentXlsRow;
901 // }
902 // ++currentXlsRow;
903 // xlsx.saveAs(fileName);
904 // return true;
905 //}
906
907 //bool LogExportWidget::exportToXls(QString fileName, QList<LOG_MSG_XORG> jList, QStringList labels)
908 //{
909 // auto currentXlsRow = 1;
910 // QXlsx::Document xlsx;
911 // for (int col = 0; col < labels.count(); ++col) {
912 // QXlsx::Format boldFont;
913 // boldFont.setFontBold(true);
914 // xlsx.write(currentXlsRow, col + 1, labels.at(col), boldFont);
915 // }
916 // ++currentXlsRow;
917 // for (int row = 0; row < jList.count(); ++row) {
918 // LOG_MSG_XORG message = jList.at(row);
919 // int col = 1;
920 // xlsx.write(currentXlsRow, col++, message.dateTime);
921 // xlsx.write(currentXlsRow, col++, message.msg);
922 // ++currentXlsRow;
923 // }
924 // ++currentXlsRow;
925 // xlsx.saveAs(fileName);
926 // return true;
927 //}
928
929 //bool LogExportWidget::exportToXls(QString fileName, QList<LOG_MSG_NORMAL> jList, QStringList labels)
930 //{
931 // auto currentXlsRow = 1;
932 // QXlsx::Document xlsx;
933 // for (int col = 0; col < labels.count(); ++col) {
934 // QXlsx::Format boldFont;
935 // boldFont.setFontBold(true);
936 // xlsx.write(currentXlsRow, col + 1, labels.at(col), boldFont);
937 // }
938 // ++currentXlsRow;
939 // for (int row = 0; row < jList.count(); ++row) {
940 // LOG_MSG_NORMAL message = jList.at(row);
941 // int col = 1;
942 // xlsx.write(currentXlsRow, col++, message.eventType);
943 // xlsx.write(currentXlsRow, col++, message.userName);
944 // xlsx.write(currentXlsRow, col++, message.dateTime);
945 // xlsx.write(currentXlsRow, col++, message.msg);
946 // ++currentXlsRow;
947 // }
948 // ++currentXlsRow;
949 // xlsx.saveAs(fileName);
950 // return true;
951 //}