File r893737.diff of Package kdepimlibs4

Subject: fix korganizer crash with akonadi resources
From: wstephenson@suse.de
Bug: kde#175971
Patch-upstream: 893737
--- kabc/stdaddressbook.h	(revision 893736)
+++ kabc/stdaddressbook.h	(revision 893737)
@@ -135,6 +135,11 @@ class KABC_EXPORT StdAddressBook : publi
     StdAddressBook( bool asynchronous );
 
   private:
+    // needed another constructor for delaying Private::init() to right
+    // after the instance creation. Cannot change the other two since they
+    // are protected and might be called by subclasses
+    StdAddressBook( bool asynchronous, bool doInit );
+
     class Private;
     Private *const d;
 };
--- kabc/stdaddressbook.cpp	(revision 893736)
+++ kabc/stdaddressbook.cpp	(revision 893737)
@@ -75,36 +75,31 @@ StdAddressBook *StdAddressBook::self()
 {
   kDebug();
 
-  if ( !s_gStdAddressBook ) {
-    s_gStdAddressBook = new StdAddressBook();
-
-    // We don't use a global static here for two reasons:
-    //
-    // 1. The K_GLOBAL_STATIC does not allow two different constructor calls,
-    //    which we need because there are two self() methods
-    //
-    // 2. There are problems with the destruction order: The destructor of
-    //    StdAddressBook calls save(), which for LDAP address books, needs KIO
-    //    (more specific: KProtocolInfo) to be still alive. However, with a global
-    //    static, KProtocolInfo is already deleted, and the app will crash.
-    //
-    // qAddPostRoutine deletes the objects when the QApplication is destroyed,
-    // which is earlier than the global statics, so this will work.
-    qAddPostRoutine( deleteGlobalStdAddressBook );
-  }
-
-  return s_gStdAddressBook;
+  // delegate to other self() method since the only difference
+  // was the constructor being used and their only difference is
+  // what they pass to Private::init()
+  return self( false );
 }
 
 StdAddressBook *StdAddressBook::self( bool asynchronous )
 {
-  kDebug();
+  kDebug() << "asynchronous=" << asynchronous;
 
   if ( !s_gStdAddressBook ) {
-    s_gStdAddressBook = new StdAddressBook( asynchronous );
+    s_gStdAddressBook = new StdAddressBook( asynchronous, false );
 
-    // See comment in the other self() method for this.
+    // We don't use a global static here for this reason:
+    //
+    // There are problems with the destruction order: The destructor of
+    // StdAddressBook calls save(), which for LDAP address books, needs KIO
+    // (more specific: KProtocolInfo) to be still alive. However, with a global
+    // static, KProtocolInfo is already deleted, and the app will crash.
+    //
+    // qAddPostRoutine deletes the objects when the QApplication is destroyed,
+    // which is earlier than the global statics, so this will work.
     qAddPostRoutine( deleteGlobalStdAddressBook );
+
+    s_gStdAddressBook->d->init( asynchronous );
   }
 
   return s_gStdAddressBook;
@@ -126,6 +121,15 @@ StdAddressBook::StdAddressBook( bool asy
   d->init( asynchronous );
 }
 
+StdAddressBook::StdAddressBook( bool asynchronous, bool doInit )
+  : AddressBook( "" ), d( new Private( this ) )
+{
+  kDebug();
+
+  if ( doInit )
+    d->init( asynchronous );
+}
+
 StdAddressBook::~StdAddressBook()
 {
   if ( Private::mAutomaticSave ) {
Index: kabc/stdaddressbook.h
===================================================================
Index: kabc/stdaddressbook.cpp
===================================================================
openSUSE Build Service is sponsored by