accounts-qt  1.11
error.cpp
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  */
22 
23 #include "error.h"
24 
25 #include <libaccounts-glib/ag-errors.h>
26 
27 namespace Accounts {
28 
35 Error::Error(const GError *error)
36 {
37  registerType();
38 
39  if (error == NULL) {
40  m_type = NoError;
41  m_message = QString();
42  } else {
43  if (error->domain == AG_ERRORS) {
44  switch (error->code) {
45  case AG_ERROR_DB:
46  m_type = Database;
47  break;
48  case AG_ERROR_DELETED:
49  m_type = Deleted;
50  break;
51  case AG_ERROR_DISPOSED:
52  // Should never happen here!
53  qCritical() << Q_FUNC_INFO << "Account object is disposed!";
54  m_type = Unknown;
55  break;
56  case AG_ERROR_DB_LOCKED:
57  m_type = DatabaseLocked;
58  break;
59  case AG_ERROR_ACCOUNT_NOT_FOUND:
60  m_type = AccountNotFound;
61  break;
62  default:
63  qWarning() << Q_FUNC_INFO << "Unknown error:" << error->code;
64  m_type = Unknown;
65  break;
66  }
67  } else {
68  // The error is coming from another domain; this shouldn't happen
69  qCritical() << Q_FUNC_INFO << "Error is coming from unknown domain";
70  m_type = Unknown;
71  }
72 
73  m_message = QString::fromUtf8(error->message);
74  }
75 }
76 
77 }; // namespace
78