Bug 133395

Summary: libkdepim: use proper error handler to show kabc errors
Product: [Unmaintained] kresources Reporter: Felix Berger <bflat1>
Component: frameworkAssignee: Cornelius Schumacher <schumacher>
Status: RESOLVED FIXED    
Severity: normal CC: steffenp
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Patch implements the described fix.
Use error handler in KAddrBookExternal::addVCard as well

Description Felix Berger 2006-09-01 18:49:48 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources
OS:                Linux

Symptom

When you add an email address from KMail to the address book and it for instance fails due to stale lock files in .kde/share/apps/kabc/lock/, the error message is not descriptive enough. The user is just told that saving failed.

Cause

KMail use libkdepim's KAddrBookExternal::addEmail to add emails, which provides its own error handling based on a boolean return value from KAddrBookExternal::addAddressee instead of setting an error handler for the addressbook instance, which displays more detailed messages as exemplified in KAddressbook where the user is informed about possibly stale lock files.

Suggestion

Use the widget passed to KAddrBookExternal::addEmail to install the KABC::GuiErrorHandler for error display and deinstall it afterwards. In fact, applications should install the error handler themselves, but since libkdepim already decides to handle errors by displaying a message box, it is unlikely there are client apps that install an error handler themselves already, because this would have caused multiple consecutive error dialogs to pop up in the past. The attached patch implements this fix.

In the long run, KMail and other clients should set a proper error handler once and libkdepim should not take care of error display.
Comment 1 Felix Berger 2006-09-01 18:51:33 UTC
Created attachment 17604 [details]
Patch implements the described fix.
Comment 2 Felix Berger 2006-09-02 13:38:22 UTC
Created attachment 17616 [details]
Use error handler in KAddrBookExternal::addVCard as well
Comment 3 Felix Berger 2006-09-21 15:04:13 UTC
Is there any more information I can provide?
Comment 4 Allen Winter 2007-04-18 15:55:09 UTC
SVN commit 655461 by winterz:

fix use proper error handler to show kabc errors
patch provided by Felix Berger. Thanks!

BUGS: 133395


 M  +9 -7      kaddrbook.cpp  


--- branches/KDE/3.5/kdepim/libkdepim/kaddrbook.cpp #655460:655461
@@ -21,6 +21,7 @@
 #include <kabc/resource.h>
 #include <kabc/stdaddressbook.h>
 #include <kabc/vcardconverter.h>
+#include <kabc/errorhandler.h>
 #include <kresources/selectdialog.h>
 #include <dcopref.h>
 #include <dcopclient.h>
@@ -90,6 +91,8 @@
 
   KABC::AddressBook *ab = KABC::StdAddressBook::self( true );
 
+  ab->setErrorHandler( new KABC::GuiErrorHandler( parent ) );
+
   // force a reload of the address book file so that changes that were made
   // by other programs are loaded
   ab->asyncLoad();
@@ -144,9 +147,7 @@
       a.setFormattedName( name );
     }
 
-    if ( !KAddrBookExternal::addAddressee( a ) ) {
-      KMessageBox::error( parent, i18n("Cannot save to addressbook.") );
-    } else {
+    if ( KAddrBookExternal::addAddressee( a ) ) {
       QString text = i18n("<qt>The email address <b>%1</b> was added to your "
                           "addressbook; you can add more information to this "
                           "entry by opening the addressbook.</qt>").arg( addr );
@@ -158,6 +159,7 @@
     KMessageBox::information( parent, text, QString::null,
                               "alreadyInAddressBook" );
   }
+  ab->setErrorHandler( 0 );
 }
 
 void KAddrBookExternal::openAddressBook(QWidget *) {
@@ -176,14 +178,13 @@
   KABC::AddressBook *ab = KABC::StdAddressBook::self( true );
   bool inserted = false;
 
+  ab->setErrorHandler( new KABC::GuiErrorHandler( parent ) );
+
   KABC::Addressee::List addressees =
       ab->findByEmail( addressee.preferredEmail() );
 
   if ( addressees.isEmpty() ) {
-    if ( !KAddrBookExternal::addAddressee( addressee ) ) {
-      KMessageBox::error( parent, i18n("Cannot save to addressbook.") );
-      inserted = false;
-    } else {
+    if ( KAddrBookExternal::addAddressee( addressee ) ) {
       QString text = i18n("The VCard was added to your addressbook; "
                           "you can add more information to this "
                           "entry by opening the addressbook.");
@@ -199,6 +200,7 @@
     inserted = true;
   }
 
+  ab->setErrorHandler( 0 );
   return inserted;
 }