accounts-qt  1.13
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     inline void registerType();
00108     // \endcond
00109 
00110 private:
00111     // Don't include private data in docs: \cond
00112     ErrorType m_type;
00113     QString m_message;
00114     // \endcond
00115 };
00116 
00117 } //namespace
00118 
00119 Q_DECLARE_METATYPE(Accounts::Error)
00120 
00121 void Accounts::Error::registerType()
00122 {
00123     qRegisterMetaType<Accounts::Error>("Accounts::Error");
00124 }
00125 
00126 #endif // ACCOUNTS_ERROR_H