accounts-qt  1.13
error.cpp
00001 /*
00002  * This file is part of libaccounts-qt
00003  *
00004  * Copyright (C) 2011 Nokia Corporation.
00005  *
00006  * Contact: Alberto Mardegan <alberto.mardegan@nokia.com>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * version 2.1 as published by the Free Software Foundation.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00020  * 02110-1301 USA
00021  */
00022 
00023 #include "error.h"
00024 
00025 #include <libaccounts-glib/ag-errors.h>
00026 
00027 namespace Accounts {
00028 
00035 Error::Error(const GError *error)
00036 {
00037     registerType();
00038 
00039     if (error == NULL) {
00040         m_type = NoError;
00041         m_message = QString();
00042     } else {
00043         if (error->domain == AG_ERRORS) {
00044             switch (error->code) {
00045             case AG_ERROR_DB:
00046                 m_type = Database;
00047                 break;
00048             case AG_ERROR_DELETED:
00049                 m_type = Deleted;
00050                 break;
00051             case AG_ERROR_DISPOSED:
00052                 // Should never happen here!
00053                 qCritical() << Q_FUNC_INFO << "Account object is disposed!";
00054                 m_type = Unknown;
00055                 break;
00056             case AG_ERROR_DB_LOCKED:
00057                 m_type = DatabaseLocked;
00058                 break;
00059             case AG_ERROR_ACCOUNT_NOT_FOUND:
00060                 m_type = AccountNotFound;
00061                 break;
00062             default:
00063                 qWarning() << Q_FUNC_INFO << "Unknown error:" << error->code;
00064                 m_type = Unknown;
00065                 break;
00066             }
00067         } else {
00068             // The error is coming from another domain; this shouldn't happen
00069             qCritical() << Q_FUNC_INFO << "Error is coming from unknown domain";
00070             m_type = Unknown;
00071         }
00072 
00073         m_message = QString::fromUtf8(error->message);
00074     }
00075 }
00076 
00077 }; // namespace
00078