My Project
signonerror.h
1 /*
2  * This file is part of signon
3  *
4  * Copyright (C) 2009-2010 Nokia Corporation.
5  * Copyright (C) 2012-2016 Canonical Ltd.
6  *
7  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * version 2.1 as published by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  */
28 #ifndef SIGNONERROR_H
29 #define SIGNONERROR_H
30 
31 
32 #ifdef SIGNON_INTERNAL
33  #include <QObject>
34 #endif
35 
36 #include <QMetaType>
37 #include <QString>
38 
39 #include <SignOn/libsignoncommon.h>
40 
41 namespace SignOn {
42 
49 class SIGNON_EXPORT Error
50 #ifdef SIGNON_INTERNAL
51 : public QObject { Q_OBJECT
52 #else
53 {
54 #endif
55 public:
64  enum ErrorType {
65  Unknown = 1,
67  InternalServer = 2,
68  InternalCommunication = 3,
70  PermissionDenied = 4,
72  EncryptionFailure,
74  AuthServiceErr = 100, /* Placeholder to rearrange enumeration
75  - AuthService specific */
76  MethodNotKnown,
78  ServiceNotAvailable,
81  IdentityErr = 200, /* Placeholder to rearrange enumeration
82  - Identity specific */
84  IdentityNotFound,
89  IdentityOperationCanceled,
92  ReferenceNotFound,
94  AuthSessionErr = 300, /* Placeholder to rearrange enumeration
95  - AuthSession/AuthPluginInterface
96  specific */
97  MechanismNotAvailable,
99  MissingData,
101  InvalidCredentials,
104  WrongState,
106  OperationNotSupported,
110  Ssl,
111  Runtime,
117  EncryptionFailed,
120  ForgotPassword,
122  MethodOrMechanismNotAllowed,
125  UserErr = 400 /* Placeholder to rearrange enumeration
126  - User space specific */
127  };
128 
132  Error() : m_type((int)Unknown), m_message(QString()) { registerType(); }
133 
139  Error(const Error &src) :
140 #ifdef SIGNON_INTERNAL
141  QObject(),
142 #endif
143  m_type(src.type()), m_message(src.message()) {}
144 
150  Error(int type, const QString &message = QString()):
151  m_type(type), m_message(message) { registerType(); }
152 
157  Error &operator=(const Error &src)
158  { m_type = src.type(); m_message = src.message(); return *this; }
159 
163  virtual ~Error() {}
164 
172  void setType(int type) { m_type = type; }
173 
178  void setMessage(const QString &message) { m_message = message; }
179 
183  int type() const { return m_type; }
184 
188  QString message() const { return m_message; }
189 
190 private:
191  inline void registerType();
192 
193 private:
194  int m_type;
195  QString m_message;
196 };
197 
198 } //namespace SignOn
199 
200 Q_DECLARE_METATYPE(SignOn::Error)
201 
202 void SignOn::Error::registerType() {
203  qRegisterMetaType<SignOn::Error>("SignOn::Error");
204 }
205 
206 #endif // SIGNONERROR_H
definition for Signon error handling.
Definition: signonerror.h:53
Error(const Error &src)
Copy constructor.
Definition: signonerror.h:139
Error(int type, const QString &message=QString())
For convenience constructor.
Definition: signonerror.h:150
QString message() const
Definition: signonerror.h:188
Error & operator=(const Error &src)
Assignment operator.
Definition: signonerror.h:157
ErrorType
Error codes for all the Signon by default supported errors.
Definition: signonerror.h:64
@ CredentialsNotAvailable
Definition: signonerror.h:91
int type() const
Definition: signonerror.h:183
void setType(int type)
Sets the type of the error.
Definition: signonerror.h:172
void setMessage(const QString &message)
Sets the error message.
Definition: signonerror.h:178
virtual ~Error()
Destructor.
Definition: signonerror.h:163
Error()
Constructor.
Definition: signonerror.h:132