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

List:       kde-commits
Subject:    branches/kdepim/enterprise/kdepim/libkdepim
From:       Thomas McGuire <mcguire () kde ! org>
Date:       2010-06-01 8:54:56
Message-ID: 20100601090112.1E3E0AC8C7 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1133221 by tmcguire:

Factor out the resource selection into a seperate method.

MERGE: can probably be blocked, I need to check.


 M  +31 -27    kaddrbook.cpp  
 M  +15 -0     kaddrbook.h  


--- branches/kdepim/enterprise/kdepim/libkdepim/kaddrbook.cpp #1133220:1133221
@@ -207,33 +207,7 @@
 bool KAddrBookExternal::addAddressee( const KABC::Addressee& addr )
 {
   KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true );
-
-#if KDE_IS_VERSION(3,4,89)
-  // This ugly hack will be removed in 4.0
-  while ( !addressBook->loadingHasFinished() ) {
-    QApplication::eventLoop()->processEvents( QEventLoop::ExcludeUserInput );
-
-    // use sleep here to reduce cpu usage
-    usleep( 100 );
-  }
-#endif
-
-  // Select a resource
-  QPtrList<KABC::Resource> kabcResources = addressBook->resources();
-
-  QPtrList<KRES::Resource> kresResources;
-  QPtrListIterator<KABC::Resource> resIt( kabcResources );
-  KABC::Resource *kabcResource;
-  while ( ( kabcResource = resIt.current() ) != 0 ) {
-    ++resIt;
-    if ( !kabcResource->readOnly() ) {
-      KRES::Resource *res = static_cast<KRES::Resource*>( kabcResource );
-      if ( res )
-        kresResources.append( res );
-    }
-  }
-
-  kabcResource = static_cast<KABC::Resource*>( KRES::SelectDialog::getResource( kresResources, 0 ) );
+  KABC::Resource *kabcResource = selectResourceForSaving( addressBook );
   if( !kabcResource ) 
      return false;
   KABC::Ticket *ticket = addressBook->requestSaveTicket( kabcResource );
@@ -279,3 +253,33 @@
 #endif
   return QString::null;
 }
+
+KABC::Resource* KAddrBookExternal::selectResourceForSaving( KABC::AddressBook *addressBook )
+{
+#if KDE_IS_VERSION(3,4,89)
+  // This ugly hack will be removed in 4.0
+  while ( !addressBook->loadingHasFinished() ) {
+    QApplication::eventLoop()->processEvents( QEventLoop::ExcludeUserInput );
+
+    // use sleep here to reduce cpu usage
+    usleep( 100 );
+  }
+#endif
+
+  // Select a resource
+  QPtrList<KABC::Resource> kabcResources = addressBook->resources();
+
+  QPtrList<KRES::Resource> kresResources;
+  QPtrListIterator<KABC::Resource> resIt( kabcResources );
+  KABC::Resource *kabcResource;
+  while ( ( kabcResource = resIt.current() ) != 0 ) {
+    ++resIt;
+    if ( !kabcResource->readOnly() ) {
+      KRES::Resource *res = static_cast<KRES::Resource*>( kabcResource );
+      if ( res )
+        kresResources.append( res );
+    }
+  }
+
+  return static_cast<KABC::Resource*>( KRES::SelectDialog::getResource( kresResources, 0 ) );
+}
--- branches/kdepim/enterprise/kdepim/libkdepim/kaddrbook.h #1133220:1133221
@@ -11,6 +11,10 @@
 #include <kabc/addressee.h>
 #include <kdepimmacros.h>
 
+namespace KABC {
+  class AddressBook;
+}
+
 class QWidget;
 
 class KDE_EXPORT KAddrBookExternal {
@@ -23,6 +27,17 @@
   static bool addVCard( const KABC::Addressee& addressee, QWidget *parent );
 
   static QString expandDistributionList( const QString& listName );
+
+  /**
+   * Pops up a dialog to ask the user to select a resource for saving something, and
+   * returns the selected resource or 0 on failure or if the user cancelled.
+   *
+   * The addressbook used to get the resource list from. If the addressbook was loaded
+   * async and loading is not yet finished, this method will run an eventloop until the
+   * addressbook is loaded.
+   */
+  static KABC::Resource* selectResourceForSaving( KABC::AddressBook *addressBook );
+
 private:
   static bool addAddressee( const KABC::Addressee& addressee );
 };
[prev in list] [next in list] [prev in thread] [next in thread] 

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