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