libaccounts-qt  1.1
error.h
00001 /*
00002  * This file is part of libaccounts-qt
00003  *
00004  * Copyright (C) 2011 Nokia Corporation.
00005  *
00006  * Contact: Alberto Mardegan <alberto.mardegan@nokia.com>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * version 2.1 as published by the Free Software Foundation.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00020  * 02110-1301 USA
00021  */
00027 #ifndef ACCOUNTS_ERROR_H
00028 #define ACCOUNTS_ERROR_H
00029 
00030 #include <QMetaType>
00031 #include <QString>
00032 
00033 #include <Accounts/accountscommon.h>
00034 
00035 extern "C"
00036 {
00037     typedef struct _GError GError;
00038 }
00039 
00040 namespace Accounts {
00041 
00042 class ACCOUNTS_EXPORT Error
00043 {
00044 public:
00048     enum ErrorType {
00049         NoError = 0,
00050         Unknown,
00051         Database,                   
00052         Deleted,                    
00054         DatabaseLocked,             
00055         AccountNotFound,            
00056     };
00057 
00061     Error(): m_type(NoError), m_message(QString()) { registerType(); }
00062 
00067     Error(const Error &src):
00068         m_type(src.type()), m_message(src.message()) {}
00069 
00075     Error(ErrorType type, const QString &message = QString()):
00076         m_type(type), m_message(message)
00077         { registerType(); }
00078 
00083     Error &operator=(const Error &src)
00084         { m_type = src.type(); m_message = src.message(); return *this; }
00085 
00089     virtual ~Error() {}
00090 
00094     ErrorType type() const { return m_type; }
00095 
00099     QString message() const { return m_message; }
00100 
00101 private:
00102     // Don't include in docs: \cond
00103     friend class Account;
00104     friend class Manager;
00105     Error(const GError *error);
00106 
00107     void registerType()
00108         { qRegisterMetaType<Error>("Accounts::Error"); }
00109     // \endcond
00110 
00111 private:
00112     // Don't include private data in docs: \cond
00113     ErrorType m_type;
00114     QString m_message;
00115     // \endcond
00116 };
00117 
00118 } //namespace
00119 
00120 Q_DECLARE_METATYPE(Accounts::Error)
00121 
00122 #endif // ACCOUNTS_ERROR_H