signonerror.h
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  *
00006  * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
00007  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public License
00011  * version 2.1 as published by the Free Software Foundation.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  */
00028 #ifndef SIGNONERROR_H
00029 #define SIGNONERROR_H
00030 
00031 
00032 #ifdef SIGNON_INTERNAL
00033     #include <QObject>
00034 #endif
00035 
00036 #include <QMetaType>
00037 #include <QString>
00038 
00039 #include <SignOn/libsignoncommon.h>
00040 
00041 namespace SignOn {
00042 
00049 class SIGNON_EXPORT Error
00050 #ifdef SIGNON_INTERNAL
00051 : public QObject { Q_OBJECT
00052 #else
00053 {
00054 #endif
00055 public:
00064     enum ErrorType {
00065         Unknown = 1,               
00067         InternalServer = 2,        
00068         InternalCommunication = 3, 
00070         PermissionDenied = 4,      
00072         EncryptionFailure,         
00074         AuthServiceErr = 100,           /* Placeholder to rearrange enumeration
00075                                          - AuthService specific */
00076         MethodNotKnown,            
00078         ServiceNotAvailable,       
00080         InvalidQuery,              
00081         IdentityErr = 200,              /* Placeholder to rearrange enumeration
00082                                          - Identity specific */
00083         MethodNotAvailable,        
00084         IdentityNotFound,          
00086         StoreFailed,               
00087         RemoveFailed,              
00088         SignOutFailed,             
00089         IdentityOperationCanceled, 
00091         CredentialsNotAvailable,   
00092         ReferenceNotFound,         
00094         AuthSessionErr = 300,      /* Placeholder to rearrange enumeration
00095                                      - AuthSession/AuthPluginInterface
00096                                      specific */
00097         MechanismNotAvailable,     
00099         MissingData,               
00101         InvalidCredentials,        
00103         NotAuthorized,             
00104         WrongState,                
00106         OperationNotSupported,     
00108         NoConnection,              
00109         Network,                   
00110         Ssl,                       
00111         Runtime,                   
00113         SessionCanceled,           
00114         TimedOut,                  
00115         UserInteraction,           
00116         OperationFailed,           
00117         EncryptionFailed,          
00119         TOSNotAccepted,            
00120         ForgotPassword,            
00122         MethodOrMechanismNotAllowed, 
00124         IncorrectDate,             
00125         UserErr = 400                   /* Placeholder to rearrange enumeration
00126                                          - User space specific */
00127     };
00128 
00132     Error() : m_type((int)Unknown), m_message(QString()) { registerType(); }
00133 
00139     Error(const Error &src) :
00140 #ifdef SIGNON_INTERNAL
00141         QObject(),
00142 #endif
00143         m_type(src.type()), m_message(src.message()) {}
00144 
00150     Error(int type, const QString &message = QString()):
00151         m_type(type), m_message(message) { registerType(); }
00152 
00157     Error &operator=(const Error &src)
00158         { m_type = src.type(); m_message = src.message(); return *this; }
00159 
00163     virtual ~Error() {}
00164 
00172     void setType(int type) { m_type = type; }
00173 
00178     void setMessage(const QString &message) { m_message = message; }
00179 
00183     int type() const { return m_type; }
00184 
00188     QString message() const { return m_message; }
00189 
00190 private:
00191     inline void registerType();
00192 
00193 private:
00194     int m_type;
00195     QString m_message;
00196 };
00197 
00198 } //namespace SignOn
00199 
00200 Q_DECLARE_METATYPE(SignOn::Error)
00201 
00202 void SignOn::Error::registerType() {
00203     qRegisterMetaType<SignOn::Error>("SignOn::Error");
00204 }
00205 
00206 #endif // SIGNONERROR_H