accounts-qt  1.15
error.h
00001 /*
00002  * This file is part of libaccounts-qt
00003  *
00004  * Copyright (C) 2011 Nokia Corporation.
00005  * Copyright (C) 2012-2016 Canonical Ltd.
00006  *
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 ACCOUNTS_ERROR_H
00029 #define ACCOUNTS_ERROR_H
00030 
00031 #include <QMetaType>
00032 #include <QString>
00033 
00034 #include <Accounts/accountscommon.h>
00035 
00036 extern "C"
00037 {
00038     typedef struct _GError GError;
00039 }
00040 
00041 namespace Accounts {
00042 
00043 class ACCOUNTS_EXPORT Error
00044 {
00045 public:
00049     enum ErrorType {
00050         NoError = 0,
00051         Unknown,
00052         Database,                   
00053         Deleted,                    
00055         DatabaseLocked,             
00056         AccountNotFound,            
00057     };
00058 
00062     Error(): m_type(NoError), m_message(QString()) { registerType(); }
00063 
00068     Error(const Error &src):
00069         m_type(src.type()), m_message(src.message()) {}
00070 
00076     Error(ErrorType type, const QString &message = QString()):
00077         m_type(type), m_message(message)
00078         { registerType(); }
00079 
00084     Error &operator=(const Error &src)
00085         { m_type = src.type(); m_message = src.message(); return *this; }
00086 
00090     virtual ~Error() {}
00091 
00095     ErrorType type() const { return m_type; }
00096 
00100     QString message() const { return m_message; }
00101 
00102 private:
00103     // Don't include in docs: \cond
00104     friend class Account;
00105     friend class Manager;
00106     Error(const GError *error);
00107 
00108     inline void registerType();
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 void Accounts::Error::registerType()
00123 {
00124     qRegisterMetaType<Accounts::Error>("Accounts::Error");
00125 }
00126 
00127 #endif // ACCOUNTS_ERROR_H