[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/pim/akonadi/exchange
From:       Shaheed Haque <srhaque () theiet ! org>
Date:       2011-11-29 22:43:31
Message-ID: 20111129224331.BF668AC88F () svn ! kde ! org
[Download RAW message or body]

SVN commit 1266564 by shaheed:

Consistently check the logon status to prevent SEGVs due to broken connections
and the like. We also now clear the cached logon status at the end of
retrieveItems() to force a connection retry "sometimes" (previously, once
a broken state was cahced, we'd never retry things!).

TODO: Move all this into the mapiconnector layer.



 M  +31 -18    calendar/excalresource.cpp  
 M  +13 -0     calendar/excalresource.h  
 M  +30 -8     contacts/exgalresource.cpp  
 M  +14 -0     contacts/exgalresource.h  


--- trunk/playground/pim/akonadi/exchange/calendar/excalresource.cpp #1266563:1266564
@@ -38,30 +38,24 @@
 using namespace Akonadi;
 
 ExCalResource::ExCalResource( const QString &id )
-  : ResourceBase( id )
+  : ResourceBase( id ),
+  connector( 0 )
 {
 	new SettingsAdaptor( Settings::self() );
 	QDBusConnection::sessionBus().registerObject( QLatin1String( "/Settings" ),
 							Settings::self(), QDBusConnection::ExportAdaptors );
-
-	// initialize the mapi connector
-	connector = new MapiConnector2;
 }
 
 ExCalResource::~ExCalResource()
 {
-	if (connector)
-		delete connector;
+	logoff();
 }
 
 void ExCalResource::retrieveCollections()
 {
 	kDebug() << "retrieveCollections() called";
 
-	emit status(Running, i18n("Logging in to Exchange"));
-	bool ok = connector->login(Settings::self()->profileName());
-	if (!ok) {
-		emit status(Broken, i18n("Unable to login") );
+	if (!logon()) {
 		return;
 	}
 
@@ -95,11 +89,7 @@
 {
 	kDebug() << "retrieveItems() called for collection "<< collection.id();
 
-	// logon to exchange (if needed)
-	emit status(Running, i18n("Logging in to Exchange"));
-	bool ok = connector->login(Settings::self()->profileName());
-	if (!ok) {
-		emit status(Broken, i18n("Unable to login") );
+	if (!logon()) {
 		return;
 	}
 
@@ -185,6 +175,10 @@
 	foreach(Item item, items) {
 		kDebug() << "[Item-Dump] \
ID:"<<item.id()<<"RemoteId:"<<item.remoteId()<<"Revision:"<<item.revision()<<"ModTime:"<<item.modificationTime();
  }
+
+	// This seems like a good place to force any subsequent activity
+	// to attempt the login.
+	logoff();
 }
 
 bool ExCalResource::retrieveItem( const Akonadi::Item &itemOrig, const \
QSet<QByteArray> &parts ) @@ -193,9 +187,9 @@
 
 	kDebug() << "retrieveItem() called for item "<< itemOrig.id() << "remoteId:" << \
itemOrig.remoteId();  
-	// logon to exchange (if needed)
-	emit status(Running, i18n("Logging in to Exchange"));
-	connector->login(Settings::self()->profileName());
+	if (!logon()) {
+		return false;
+	}
 
 	// find the remoteId of the item and the collection and try to fetch the needed \
data from the server  CalendarData data;
@@ -352,7 +346,26 @@
 	} 
 }
 
+bool ExCalResource::logon(void)
+{
+	if (!connector) {
+		// logon to exchange (if needed)
+		emit status(Running, i18n("Logging in to Exchange"));
+		connector = new MapiConnector2;
+	}
+	bool ok = connector->login(Settings::self()->profileName());
+	if (!ok) {
+		emit status(Broken, i18n("Unable to login") );
+	}
+	return ok;
+}
 
+void ExCalResource::logoff(void)
+{
+	delete connector;
+	connector = 0;
+}
+
 AKONADI_RESOURCE_MAIN( ExCalResource )
 
 #include "excalresource.moc"
--- trunk/playground/pim/akonadi/exchange/calendar/excalresource.h #1266563:1266564
@@ -52,6 +52,19 @@
 private:
 	void createKCalRecurrency(KCal::Recurrence* rec, const MapiRecurrencyPattern& \
pattern);  
+	/**
+	 * Logon to Exchange. A successful login is cached and subsequent calls
+	 * short-circuited.
+	 *
+	 * @return True if the login attempt succeeded.
+	 */
+	bool logon(void);
+
+	/**
+	 * Logout from Exchange.
+	 */
+	void logoff(void);
+
 	MapiConnector2* connector;
 };
 
--- trunk/playground/pim/akonadi/exchange/contacts/exgalresource.cpp #1266563:1266564
@@ -34,20 +34,17 @@
 using namespace Akonadi;
 
 exgalResource::exgalResource( const QString &id )
-  : ResourceBase( id )
+  : ResourceBase( id ),
+  connector( 0 )
 {
 	new SettingsAdaptor( Settings::self() );
 	QDBusConnection::sessionBus().registerObject( QLatin1String( "/Settings" ),
 							Settings::self(), QDBusConnection::ExportAdaptors );
-
-	// initialize the mapi connector
-	connector = new MapiConnector2;
 }
 
 exgalResource::~exgalResource()
 {
-	if (connector)
-		delete connector;
+	logoff();
 }
 
 void exgalResource::retrieveCollections()
@@ -77,8 +74,9 @@
 {
 	Q_UNUSED( collection );
 
-	emit status(Running, i18n("Logging in to Exchange"));
-	connector->login(Settings::self()->profileName());
+	if (!logon()) {
+		return;
+	}
 
 	Item::List items;
 
@@ -109,6 +107,10 @@
 	}
 
 	itemsRetrieved(items);
+
+	// This seems like a good place to force any subsequent activity
+	// to attempt the login.
+	logoff();
 }
 
 bool exgalResource::retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> \
&parts ) @@ -183,6 +185,26 @@
   // of this template code to keep it simple
 }
 
+bool exgalResource::logon(void)
+{
+	if (!connector) {
+		// logon to exchange (if needed)
+		emit status(Running, i18n("Logging in to Exchange"));
+		connector = new MapiConnector2;
+	}
+	bool ok = connector->login(Settings::self()->profileName());
+	if (!ok) {
+		emit status(Broken, i18n("Unable to login") );
+	}
+	return ok;
+}
+
+void exgalResource::logoff(void)
+{
+	delete connector;
+	connector = 0;
+}
+
 AKONADI_RESOURCE_MAIN( exgalResource )
 
 #include "exgalresource.moc"
--- trunk/playground/pim/akonadi/exchange/contacts/exgalresource.h #1266563:1266564
@@ -49,6 +49,20 @@
     virtual void itemRemoved( const Akonadi::Item &item );
 
 private:
+
+	/**
+	 * Logon to Exchange. A successful login is cached and subsequent calls
+	 * short-circuited.
+	 *
+	 * @return True if the login attempt succeeded.
+	 */
+	bool logon(void);
+
+	/**
+	 * Logout from Exchange.
+	 */
+	void logoff(void);
+
 	MapiConnector2* connector;
 };
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic