accounts-qt  1.16
error.cpp
1 /*
2  * This file is part of libaccounts-qt
3  *
4  * Copyright (C) 2011 Nokia Corporation.
5  * Copyright (C) 2012-2016 Canonical Ltd.
6  *
7  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * version 2.1 as published by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  */
23 
24 #include "error.h"
25 
26 #include <libaccounts-glib/ag-errors.h>
27 
28 namespace Accounts {
29 
36 Error::Error(const GError *error)
37 {
38  registerType();
39 
40  if (error == NULL) {
41  m_type = NoError;
42  m_message = QString();
43  } else {
44  if (error->domain == AG_ERRORS) {
45  switch (error->code) {
46  case AG_ERROR_DB:
47  m_type = Database;
48  break;
49  case AG_ERROR_DELETED:
50  m_type = Deleted;
51  break;
52  case AG_ERROR_DISPOSED:
53  // Should never happen here!
54  qCritical() << Q_FUNC_INFO << "Account object is disposed!";
55  m_type = Unknown;
56  break;
57  case AG_ERROR_DB_LOCKED:
58  m_type = DatabaseLocked;
59  break;
60  case AG_ERROR_ACCOUNT_NOT_FOUND:
61  m_type = AccountNotFound;
62  break;
63  default:
64  qWarning() << Q_FUNC_INFO << "Unknown error:" << error->code;
65  m_type = Unknown;
66  break;
67  }
68  } else {
69  // The error is coming from another domain; this shouldn't happen
70  qCritical() << Q_FUNC_INFO << "Error is coming from unknown domain";
71  m_type = Unknown;
72  }
73 
74  m_message = QString::fromUtf8(error->message);
75  }
76 }
77 
78 }; // namespace
79 
Accounts::Error::Deleted
@ Deleted
Definition: error.h:53
Accounts::Error::Database
@ Database
Definition: error.h:52
Accounts::Error::DatabaseLocked
@ DatabaseLocked
Definition: error.h:55
Accounts::Error::Error
Error()
Basic constructor.
Definition: error.h:62
Accounts::Error::AccountNotFound
@ AccountNotFound
Definition: error.h:56