accounts-qt  1.15
error.cpp
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  */
00023 
00024 #include "error.h"
00025 
00026 #include <libaccounts-glib/ag-errors.h>
00027 
00028 namespace Accounts {
00029 
00036 Error::Error(const GError *error)
00037 {
00038     registerType();
00039 
00040     if (error == NULL) {
00041         m_type = NoError;
00042         m_message = QString();
00043     } else {
00044         if (error->domain == AG_ERRORS) {
00045             switch (error->code) {
00046             case AG_ERROR_DB:
00047                 m_type = Database;
00048                 break;
00049             case AG_ERROR_DELETED:
00050                 m_type = Deleted;
00051                 break;
00052             case AG_ERROR_DISPOSED:
00053                 // Should never happen here!
00054                 qCritical() << Q_FUNC_INFO << "Account object is disposed!";
00055                 m_type = Unknown;
00056                 break;
00057             case AG_ERROR_DB_LOCKED:
00058                 m_type = DatabaseLocked;
00059                 break;
00060             case AG_ERROR_ACCOUNT_NOT_FOUND:
00061                 m_type = AccountNotFound;
00062                 break;
00063             default:
00064                 qWarning() << Q_FUNC_INFO << "Unknown error:" << error->code;
00065                 m_type = Unknown;
00066                 break;
00067             }
00068         } else {
00069             // The error is coming from another domain; this shouldn't happen
00070             qCritical() << Q_FUNC_INFO << "Error is coming from unknown domain";
00071             m_type = Unknown;
00072         }
00073 
00074         m_message = QString::fromUtf8(error->message);
00075     }
00076 }
00077 
00078 }; // namespace
00079