All Classes Namespaces Functions Variables Enumerations Properties Pages
pencilerror.h
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 #ifndef PENCILERROR_H
19 #define PENCILERROR_H
20 
21 #include <QStringList>
22 
24 {
25 public:
26  DebugDetails();
27  ~DebugDetails();
28 
29  void collect(const DebugDetails& d);
30  QString str();
31  QString html();
32  DebugDetails& operator<<(const QString& s);
33 
34 private:
35  void appendSystemInfo();
36  QStringList mDetails;
37 };
38 
39 class Status
40 {
41 public:
42  enum ErrorCode
43  {
44  OK = 0,
45  SAFE,
46  FAIL,
47  CANCELED,
48  FILE_NOT_FOUND,
49  NOT_SUPPORTED,
50  INVALID_ARGUMENT,
51  NOT_IMPLEMENTED_YET,
52 
53  // for Object load/save
54  ERROR_FILE_CANNOT_OPEN,
55  ERROR_INVALID_XML_FILE,
56  ERROR_INVALID_PENCIL_FILE,
57  ERROR_MINIZ_FAIL,
58 
59  // General
60  ERROR_INVALID_LAYER_TYPE,
61  ERROR_INVALID_FRAME_NUMBER,
62  ERROR_LOAD_IMAGE_FAIL,
63 
64  // Sound
65  ERROR_LOAD_SOUND_FILE,
66 
67  // Export
68  ERROR_FFMPEG_NOT_FOUND,
69 
70  // Layer
71  ERROR_NEED_AT_LEAST_ONE_CAMERA_LAYER
72  };
73 
74  Status(const ErrorCode code);
75  Status(const ErrorCode code, const QString& title, const QString& description);
76  Status(const ErrorCode code, const DebugDetails& detailsList, QString title = "", QString description = "");
77 
78  ErrorCode code() { return mCode; }
79  bool ok() const { return (mCode == OK) || (mCode == SAFE); }
80  QString msg();
81  QString title() { return !mTitle.isEmpty() ? mTitle : msg(); }
82  QString description() const { return mDescription; }
83  DebugDetails details() const { return mDetails; }
84 
85  void setTitle(QString title) { mTitle = title; }
86  void setDescription(QString description) { mDescription = description; }
87  void setDetails(DebugDetails dd) { mDetails = dd; }
88 
89  bool operator==(ErrorCode code) const;
90  bool operator!=(ErrorCode code) const;
91 
92 private:
93  ErrorCode mCode = OK;
94  QString mTitle;
95  QString mDescription;
96  DebugDetails mDetails;
97 };
98 
100 {
101  int value = 0;
102  Status::ErrorCode errorcode = Status::OK;
103 };
104 
105 #ifndef STATUS_CHECK
106 #define STATUS_CHECK( x )\
107  { Status st = (x); if (!st.ok()) { return st; } }
108 #endif
109 
110 #ifndef STATUS_FAILED
111 #define STATUS_FAILED(stcode) ((int)stcode >= (int)Status::FAIL)
112 #endif
113 
114 #endif // PENCILERROR_H
bool isEmpty() const const