All Classes Namespaces Functions Variables Enumerations Properties Pages
pencilerror.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #include "pencilerror.h"
19 #include <map>
20 #include <QObject>
21 #include <QSysInfo>
22 #include "pencildef.h"
23 
24 DebugDetails::DebugDetails()
25 {
26 }
27 
28 void DebugDetails::collect(const DebugDetails& d)
29 {
30  for (const QString& s : d.mDetails)
31  {
32  mDetails.append("&nbsp;&nbsp;" + s);
33  }
34 }
35 
36 QString DebugDetails::str()
37 {
38  appendSystemInfo();
39  return mDetails.join("\n");
40 }
41 
42 QString DebugDetails::html()
43 {
44  appendSystemInfo();
45  return mDetails.join("<br>");
46 }
47 
48 DebugDetails& DebugDetails::operator<<(const QString& s)
49 {
50  mDetails.append(s);
51  return *this;
52 }
53 
54 void DebugDetails::appendSystemInfo()
55 {
56  if (mDetails.empty() || mDetails.last() == "end")
57  return;
58 
59 #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
60  mDetails << "System Info";
61 #if defined(PENCIL2D_RELEASE_BUILD)
62  mDetails << "Pencil2D version: " APP_VERSION " (stable)";
63 #elif defined(PENCIL2D_NIGHTLY_BUILD)
64  mDetails << "Pencil2D version: " APP_VERSION " (nightly)";
65 #else
66  mDetails << "Pencil2D version: " APP_VERSION " (dev)";
67 #endif
68 
69 #if defined(GIT_EXISTS)
70  mDetails << "Commit: " S__GIT_COMMIT_HASH;
71 #endif
72  mDetails << "Build ABI: " + QSysInfo::buildAbi();
73  mDetails << "Kernel: " + QSysInfo::kernelType() + ", " + QSysInfo::kernelVersion();
74  mDetails << "Operating System: " + QSysInfo::prettyProductName();
75  mDetails << "end";
76 #endif
77 }
78 
79 Status::Status(ErrorCode code)
80  : mCode(code)
81 {
82 }
83 
84 Status::Status(const ErrorCode code, const QString& description)
85  : mCode(code)
86  , mDescription(description)
87 {
88 }
89 
90 Status::Status(Status::ErrorCode eCode, const DebugDetails& detailsList)
91  : mCode(eCode)
92  , mDetails(detailsList)
93 {
94 }
95 
96 Status::Status(Status::ErrorCode eCode, const DebugDetails& detailsList, QString title, QString description)
97  : mCode(eCode)
98  , mTitle(title)
99  , mDescription(description)
100  , mDetails(detailsList)
101 {
102 }
103 
104 
105 QString Status::msg() const
106 {
107  static std::map<ErrorCode, QString> msgMap =
108  {
109  // error messages.
110  { OK, tr("Everything ok.") },
111  { FAIL, tr("Ooops, Something went wrong.") },
112  { FILE_NOT_FOUND, tr("File doesn't exist.") },
113  { ERROR_FILE_CANNOT_OPEN, tr("Cannot open file.") },
114  { ERROR_INVALID_XML_FILE, tr("The file is not a valid xml document.") },
115  { ERROR_INVALID_PENCIL_FILE, tr("The file is not valid pencil document.") },
116  };
117 
118  auto it = msgMap.find(mCode);
119  if (it == msgMap.end())
120  {
121  return msgMap[FAIL];
122  }
123  return msgMap[mCode];
124 }
125 
126 bool Status::operator==(Status::ErrorCode code) const
127 {
128  return (mCode == code);
129 }
130 
131 bool Status::operator!=(Status::ErrorCode code) const
132 {
133  return (mCode != code);
134 }
QString join(const QString &separator) const const
QString buildAbi()
void append(const T &value)
bool empty() const const
QString kernelType()
QString prettyProductName()
QString kernelVersion()
T & last()