~online-accounts/libaccounts-qt/13.04

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * This file is part of libaccounts-qt
 *
 * Copyright (C) 2011 Nokia Corporation.
 *
 * Contact: Alberto Mardegan <alberto.mardegan@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */
/*!
 * @copyright Copyright (C) 2009-2011 Nokia Corporation.
 * @license LGPL
 */

#ifndef ACCOUNTS_ERROR_H
#define ACCOUNTS_ERROR_H

#include <QMetaType>
#include <QString>

#include <Accounts/accountscommon.h>

extern "C"
{
    typedef struct _GError GError;
}

namespace Accounts {

class ACCOUNTS_EXPORT Error
{
public:
    /*!
     * @enum ErrorType Error codes for all the accounts errors.
     */
    enum ErrorType {
        NoError = 0,
        Unknown,
        Database,                   /**< Generic database error */
        Deleted,                    /**< The account object refers to an
                                      account which has been deleted */
        DatabaseLocked,             /**< The database is locked */
        AccountNotFound,            /**< The account couldn't be found */
    };

    /*!
     * Basic constructor.
     */
    Error(): m_type(NoError), m_message(QString()) { registerType(); }

    /*!
     * Copy constructor
     * @param src Error object to be copied.
     */
    Error(const Error &src):
        m_type(src.type()), m_message(src.message()) {}

    /*!
     * Constructor.
     * @param type The error's type.
     * @param message The error's message.
     */
    Error(ErrorType type, const QString &message = QString()):
        m_type(type), m_message(message)
        { registerType(); }

    /*!
     * Assignment operator.
     * @param src The error object to be assigned to this instance.
     */
    Error &operator=(const Error &src)
        { m_type = src.type(); m_message = src.message(); return *this; }

    /*!
     * Destructor.
     */
    virtual ~Error() {}

    /*!
     * @return The error's type.
     */
    ErrorType type() const { return m_type; }

    /*!
     * @return The error's message.
     */
    QString message() const { return m_message; }

private:
    // Don't include in docs: \cond
    friend class Account;
    friend class Manager;
    Error(const GError *error);

    inline void registerType();
    // \endcond

private:
    // Don't include private data in docs: \cond
    ErrorType m_type;
    QString m_message;
    // \endcond
};

} //namespace

Q_DECLARE_METATYPE(Accounts::Error)

void Accounts::Error::registerType()
{
    qRegisterMetaType<Accounts::Error>("Accounts::Error");
}

#endif // ACCOUNTS_ERROR_H