From 48a769972fd65ad52cb3ab38841a876cf4613bb9 Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Date: Tue, 3 Feb 2009 11:28:31 -0400 Subject: [PATCH] Adding error handling in resource. It will test for user authentication status and exit if is not set. --- googledataresource.cpp | 83 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 19 deletions(-) diff --git a/googledataresource.cpp b/googledataresource.cpp index 92339f0..75289c2 100644 --- a/googledataresource.cpp +++ b/googledataresource.cpp @@ -20,7 +20,7 @@ extern "C" { using namespace Akonadi; GoogleDataResource::GoogleDataResource( const QString &id ) - : ResourceBase( id ), authenticated(false), dlgConf(NULL) + : ResourceBase(id), authenticated(false), dlgConf(NULL) { new SettingsAdaptor( Settings::self() ); QDBusConnection::sessionBus().registerObject( QLatin1String( "/Settings" ), @@ -42,14 +42,16 @@ GoogleDataResource::~GoogleDataResource() void GoogleDataResource::retrieveCollections() { -// if ( mBaseResource == 0 ) { -// kError() << "No Google Contacts resource"; -// const QString message = i18nc( "@info:status", "No Google Contact configured yet" ); -// emit error( message ); - -// emit status( Broken, message ); -// return; -// } + if (!authenticated) { + kError() << "No athentication for Google Contacts available"; + const QString message = i18nc("@info:status", + "No yet authenticated for" + " use of Google Contacts"); + emit error(message); + + emit status(Broken, message); + return; + } Collection c; c.setParent(Collection::root()); @@ -73,8 +75,16 @@ void GoogleDataResource::retrieveItems( const Akonadi::Collection &collection ) Item::List items; int result; - if (!authenticated) - exit(1); + if (!authenticated) { + kError() << "No athentication for Google Contacts available"; + const QString message = i18nc("@info:status", + "No yet authenticated for" + " use of Google Contacts"); + emit error(message); + + emit status(Broken, message); + return; + } /* Downloading the contacts can be slow and it is blocking. Will * it mess up with akonadi? @@ -106,8 +116,16 @@ bool GoogleDataResource::retrieveItem( const Akonadi::Item &item, const QSet()) addressee = item.payload(); @@ -216,6 +244,7 @@ void GoogleDataResource::itemAdded( const Akonadi::Item &item, const Akonadi::Co void GoogleDataResource::itemChanged( const Akonadi::Item &item, const QSet &parts ) { + Q_UNUSED(parts); KABC::Addressee addressee; gcal_contact_t contact; @@ -223,8 +252,16 @@ void GoogleDataResource::itemChanged( const Akonadi::Item &item, const QSet()) addressee = item.payload(); @@ -274,8 +311,16 @@ void GoogleDataResource::itemRemoved( const Akonadi::Item &item ) QString temp; int result; - if (!authenticated) - exit(1); + if (!authenticated) { + kError() << "No athentication for Google Contacts available"; + const QString message = i18nc("@info:status", + "No yet authenticated for" + " use of Google Contacts"); + emit error(message); + + emit status(Broken, message); + return; + } if (item.hasPayload()) addressee = item.payload(); -- 2.11.4.GIT