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 DebugDetails::~DebugDetails()
29 {
30 }
31 
32 void DebugDetails::collect(const DebugDetails& d)
33 {
34  for (const QString& s : d.mDetails)
35  {
36  mDetails.append("&nbsp;&nbsp;" + s);
37  }
38 }
39 
40 QString DebugDetails::str()
41 {
42  appendSystemInfo();
43  return mDetails.join("\n");
44 }
45 
46 QString DebugDetails::html()
47 {
48  appendSystemInfo();
49  return mDetails.join("<br>");
50 }
51 
52 DebugDetails& DebugDetails::operator<<(const QString& s)
53 {
54  mDetails.append(s);
55  return *this;
56 }
57 
58 void DebugDetails::appendSystemInfo()
59 {
60  if (mDetails.empty() || mDetails.last() == "end")
61  return;
62 
63 #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
64  mDetails << "System Info";
65 #if defined(PENCIL2D_RELEASE_BUILD)
66  mDetails << "Pencil2D version: " APP_VERSION " (stable)";
67 #elif defined(PENCIL2D_NIGHTLY_BUILD)
68  mDetails << "Pencil2D version: " APP_VERSION " (nightly)";
69 #else
70  mDetails << "Pencil2D version: " APP_VERSION " (dev)";
71 #endif
72 
73 #if defined(GIT_EXISTS)
74  mDetails << "Commit: " S__GIT_COMMIT_HASH;
75 #endif
76  mDetails << "Build ABI: " + QSysInfo::buildAbi();
77  mDetails << "Kernel: " + QSysInfo::kernelType() + ", " + QSysInfo::kernelVersion();
78  mDetails << "Operating System: " + QSysInfo::prettyProductName();
79  mDetails << "end";
80 #endif
81 }
82 
83 Status::Status(ErrorCode code)
84  : mCode(code)
85 {
86 }
87 
88 Status::Status(Status::ErrorCode eCode, const DebugDetails& detailsList, QString title, QString description)
89  : mCode(eCode)
90  , mTitle(title)
91  , mDescription(description)
92  , mDetails(detailsList)
93 {
94 }
95 
96 Status::Status(const ErrorCode code, const QString& title, const QString& description)
97  : mCode(code)
98  , mTitle(title)
99  , mDescription(description)
100 {
101 }
102 
103 QString Status::msg()
104 {
105  static std::map<ErrorCode, QString> msgMap =
106  {
107  // error messages.
108  { OK, QObject::tr("Everything ok.") },
109  { FAIL, QObject::tr("Ooops, Something went wrong.") },
110  { FILE_NOT_FOUND, QObject::tr("File doesn't exist.") },
111  { ERROR_FILE_CANNOT_OPEN, QObject::tr("Cannot open file.") },
112  { ERROR_INVALID_XML_FILE, QObject::tr("The file is not a valid xml document.") },
113  { ERROR_INVALID_PENCIL_FILE, QObject::tr("The file is not valid pencil document.") },
114  };
115 
116  auto it = msgMap.find(mCode);
117  if (it == msgMap.end())
118  {
119  return msgMap[FAIL];
120  }
121  return msgMap[mCode];
122 }
123 
124 bool Status::operator==(Status::ErrorCode code) const
125 {
126  return (mCode == code);
127 }
128 
129 bool Status::operator!=(Status::ErrorCode code) const
130 {
131  return (mCode != code);
132 }
QString join(const QString &separator) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString buildAbi()
void append(const T &value)
bool empty() const const
QString kernelType()
QString prettyProductName()
QString kernelVersion()
T & last()