error.h

Go to the documentation of this file.
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 
00046 class ACCOUNTS_EXPORT Error
00047 {
00048 public:
00052     enum ErrorType {
00053         NoError = 0,
00054         Unknown,
00055         Database,                   
00056         Deleted,                    
00058         DatabaseLocked,             
00059         AccountNotFound,            
00060     };
00061 
00065     Error(): m_type(NoError), m_message(QString()) { registerType(); }
00066 
00071     Error(const Error &src):
00072         m_type(src.type()), m_message(src.message()) {}
00073 
00079     Error(ErrorType type, const QString &message = QString()):
00080         m_type(type), m_message(message)
00081         { registerType(); }
00082 
00087     Error &operator=(const Error &src)
00088         { m_type = src.type(); m_message = src.message(); return *this; }
00089 
00093     virtual ~Error() {}
00094 
00098     ErrorType type() const { return m_type; }
00099 
00103     QString message() const { return m_message; }
00104 
00105 private:
00106     // Don't include in docs: \cond
00107     friend class Account;
00108     friend class Manager;
00109     Error(const GError *error);
00110 
00111     void registerType()
00112         { qRegisterMetaType<Error>("Accounts::Error"); }
00113     // \endcond
00114 
00115 private:
00116     // Don't include private data in docs: \cond
00117     ErrorType m_type;
00118     QString m_message;
00119     // \endcond
00120 };
00121 
00122 } //namespace
00123 
00124 Q_DECLARE_METATYPE(Accounts::Error)
00125 
00126 #endif // ACCOUNTS_ERROR_H