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 <QCoreApplication>
22 #include <QStringList>
23 
25 {
26 public:
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  Q_DECLARE_TR_FUNCTIONS(Status)
42 public:
43  enum ErrorCode
44  {
45  OK = 0,
46  SAFE,
47  FAIL,
48  CANCELED,
49  FILE_NOT_FOUND,
50  NOT_SUPPORTED,
51  INVALID_ARGUMENT,
52  NOT_IMPLEMENTED_YET,
53 
54  // for Object load/save
55  ERROR_FILE_CANNOT_OPEN,
56  ERROR_INVALID_XML_FILE,
57  ERROR_INVALID_PENCIL_FILE,
58  ERROR_MINIZ_FAIL,
59 
60  // General
61  ERROR_INVALID_LAYER_TYPE,
62  ERROR_INVALID_FRAME_NUMBER,
63  ERROR_LOAD_IMAGE_FAIL,
64 
65  // Sound
66  ERROR_LOAD_SOUND_FILE,
67 
68  // Export
69  ERROR_FFMPEG_NOT_FOUND,
70 
71  // Layer
72  ERROR_NEED_AT_LEAST_ONE_CAMERA_LAYER
73  };
74 
75  Status(const ErrorCode code);
76  Status(const ErrorCode code, const QString& description);
77  Status(const ErrorCode code, const DebugDetails& detailsList);
78  Status(const ErrorCode code, const DebugDetails& detailsList, QString title, QString description);
79 
80  ErrorCode code() const { return mCode; }
81  bool ok() const { return (mCode == OK) || (mCode == SAFE); }
82  QString msg() const;
83  QString title() const { return !mTitle.isEmpty() ? mTitle : msg(); }
84  QString description() const { return mDescription; }
85  DebugDetails details() const { return mDetails; }
86 
87  void setTitle(QString title) { mTitle = title; }
88  void setDescription(QString description) { mDescription = description; }
89  void setDetails(DebugDetails dd) { mDetails = dd; }
90 
91  bool operator==(ErrorCode code) const;
92  bool operator!=(ErrorCode code) const;
93 
94 private:
95  ErrorCode mCode = OK;
96  QString mTitle;
97  QString mDescription;
98  DebugDetails mDetails;
99 };
100 
101 #ifndef STATUS_CHECK
102 #define STATUS_CHECK( x )\
103  { Status st = (x); if (!st.ok()) { return st; } }
104 #endif
105 
106 #ifndef STATUS_FAILED
107 #define STATUS_FAILED(stcode) ((int)stcode >= (int)Status::FAIL)
108 #endif
109 
110 #endif // PENCILERROR_H
bool isEmpty() const const