accounts-qt  1.11
error.h
1 /*
2  * This file is part of libaccounts-qt
3  *
4  * Copyright (C) 2011 Nokia Corporation.
5  *
6  * Contact: Alberto Mardegan <alberto.mardegan@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
27 #ifndef ACCOUNTS_ERROR_H
28 #define ACCOUNTS_ERROR_H
29 
30 #include <QMetaType>
31 #include <QString>
32 
33 #include <Accounts/accountscommon.h>
34 
35 extern "C"
36 {
37  typedef struct _GError GError;
38 }
39 
40 namespace Accounts {
41 
42 class ACCOUNTS_EXPORT Error
43 {
44 public:
48  enum ErrorType {
49  NoError = 0,
50  Unknown,
52  Deleted,
56  };
57 
61  Error(): m_type(NoError), m_message(QString()) { registerType(); }
62 
67  Error(const Error &src):
68  m_type(src.type()), m_message(src.message()) {}
69 
75  Error(ErrorType type, const QString &message = QString()):
76  m_type(type), m_message(message)
77  { registerType(); }
78 
83  Error &operator=(const Error &src)
84  { m_type = src.type(); m_message = src.message(); return *this; }
85 
89  virtual ~Error() {}
90 
94  ErrorType type() const { return m_type; }
95 
99  QString message() const { return m_message; }
100 
101 private:
102  // Don't include in docs: \cond
103  friend class Account;
104  friend class Manager;
105  Error(const GError *error);
106 
107  inline void registerType();
108  // \endcond
109 
110 private:
111  // Don't include private data in docs: \cond
112  ErrorType m_type;
113  QString m_message;
114  // \endcond
115 };
116 
117 } //namespace
118 
119 Q_DECLARE_METATYPE(Accounts::Error)
120 
121 void Accounts::Error::registerType()
122 {
123  qRegisterMetaType<Accounts::Error>("Accounts::Error");
124 }
125 
126 #endif // ACCOUNTS_ERROR_H