forked from SaschaWillems/OpenCLCapsViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.cpp
More file actions
102 lines (95 loc) · 2.98 KB
/
report.cpp
File metadata and controls
102 lines (95 loc) · 2.98 KB
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
/*
*
* OpenCL hardware capability viewer
*
* Copyright (C) 2021-2022 by Sascha Willems (www.saschawillems.de)
*
* This code is free software, you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 3 as published by the Free Software Foundation.
*
* Please review the following information to ensure the GNU Lesser
* General Public License version 3 requirements will be met:
* http://opensource.org/licenses/lgpl-3.0.html
*
* The code is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU LGPL 3.0 for more details.
*
*/
#include "report.h"
void Report::toJson(DeviceInfo& device, QString submitter, QString comment, QJsonObject& jsonObject)
{
// Environment
QJsonObject jsonEnv;
jsonEnv["name"] = operatingSystem.name;
jsonEnv["version"] = operatingSystem.version;
jsonEnv["architecture"] = operatingSystem.architecture;
jsonEnv["type"] = operatingSystem.type;
jsonEnv["submitter"] = submitter;
jsonEnv["comment"] = comment;
jsonEnv["reportversion"] = reportVersion;
jsonEnv["appversion"] = appVersion;
jsonObject["environment"] = jsonEnv;
// Platform
jsonObject["platform"] = device.platform->toJson();
// Device
jsonObject["device"] = device.toJson();
}
void Report::saveToFile(DeviceInfo& device, QString fileName, QString submitter, QString comment)
{
QJsonObject jsonReport;
toJson(device, submitter, comment, jsonReport);
QJsonDocument doc(jsonReport);
QFile jsonFile(fileName);
jsonFile.open(QFile::WriteOnly);
jsonFile.write(doc.toJson(QJsonDocument::Indented));
jsonFile.flush();
}
int Report::uploadNonVisual(DeviceInfo& device, QString submitter, QString comment)
{
QString message;
bool dbstatus = database.checkServerConnection(message);
if (!dbstatus)
{
#ifndef GUI_BUILD
std::cout << "Database unreachable\n";
#endif
qWarning() << "Database unreachable";
return -1;
}
QJsonObject reportJson;
toJson(device, submitter, comment, reportJson);
int reportId;
if (!database.getReportId(reportJson, reportId)) {
#ifndef GUI_BUILD
std::cout << "Database unreachable\n";
#endif
qWarning() << "Could not get report id from database";
return -2;
}
if (reportId > -1)
{
#ifndef GUI_BUILD
std::cout << "Device already present in database\n";
#endif
qWarning() << "Device already present in database";
return -3;
}
if (database.uploadReport(reportJson, message))
{
#ifndef GUI_BUILD
std::cout << "Report successfully submitted. Thanks for your contribution!\n";
#endif
qInfo() << "Report successfully submitted. Thanks for your contribution!";
return 0;
}
else
{
#ifndef GUI_BUILD
std::cout << "The report could not be uploaded\n";
#endif
qInfo() << "The report could not be uploaded : \n" << message;
return -4;
}
}