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

List:       kde-commits
Subject:    KDE/kdepim/libkdepim
From:       Nicolas Lécureuil <nlecureuil () mandriva ! com>
Date:       2010-08-28 16:12:56
Message-ID: 20100828161256.C9962AC86C () svn ! kde ! org
[Download RAW message or body]

SVN commit 1169188 by nlecureuil:

Auto-select the Address Book if there is only one.
Do not show an empty list if there is no Adress Book but warn the user instead.
BUG: 235452



 M  +54 -8     addemailaddressjob.cpp  
 M  +1 -0      addemailaddressjob.h  


--- trunk/KDE/kdepim/libkdepim/addemailaddressjob.cpp #1169187:1169188
@@ -1,5 +1,6 @@
 /*
   Copyright 2010 Tobias Koenig <tokoe@kde.org>
+  Copyright 2010 Nicolas Lécureuil <nlecureuil@mandriva.com>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
@@ -19,14 +20,19 @@
 
 #include "addemailaddressjob.h"
 
-#include <akonadi/collectiondialog.h>
-#include <akonadi/contact/contactsearchjob.h>
-#include <akonadi/item.h>
-#include <akonadi/itemcreatejob.h>
-#include <kabc/addressee.h>
-#include <klocale.h>
-#include <kmessagebox.h>
+#include <Akonadi/CollectionDialog>
+#include <Akonadi/Contact/ContactSearchJob>
+#include <Akonadi/Item>
+#include <Akonadi/ItemCreateJob>
+#include <Akonadi/CollectionFetchJob>
+#include <Akonadi/CollectionFetchScope>
+#include <Akonadi/Collection>
 
+#include <KABC/Addressee>
+#include <KLocale>
+#include <KMessageBox>
+
+
 using namespace KPIM;
 
 class AddEmailAddressJob::Private
@@ -60,10 +66,48 @@
         return;
       }
 
+      const QStringList mimeTypes( KABC::Addressee::mimeType() );
+
+      Akonadi::CollectionFetchJob * const addressBookJob = new \
Akonadi::CollectionFetchJob( Akonadi::Collection::root(), \
Akonadi::CollectionFetchJob::Recursive ); +      \
addressBookJob->fetchScope().setContentMimeTypes( mimeTypes ); +      q->connect( \
addressBookJob, SIGNAL( result( KJob* ) ), SLOT( slotCollectionsFetched( KJob* ) ) ); \
+    } +
+    void slotCollectionsFetched( KJob *job )
+    {
+      if ( job->error() ) {
+        q->setError( job->error() );
+        q->setErrorText( job->errorText() );
+        q->emitResult();
+        return;
+      }
+
+      const Akonadi::CollectionFetchJob *addressBookJob = \
qobject_cast<Akonadi::CollectionFetchJob*>( job ); +
+      Akonadi::Collection::List canCreateItemCollections ;
+
+      foreach( const Akonadi::Collection &collection, addressBookJob->collections() \
) { +        if ( Akonadi::Collection::CanCreateItem & collection.rights() ) {
+          canCreateItemCollections.append(collection);
+        }
+      }
+
       KABC::Addressee contact;
       contact.setNameFromString( mName );
       contact.insertEmail( mEmail, true );
 
+      Akonadi::Collection addressBook;
+
+      if ( canCreateItemCollections.size() == 0 ) {
+        KMessageBox::information ( 0, i18n( "Please create an address book before \
adding a contact." ), i18n( "No Address Book Available" ) ); +        q->setError( \
UserDefinedError ); +        q->emitResult();
+        return;
+      }
+      else if ( canCreateItemCollections.size() == 1 ) {
+        addressBook = canCreateItemCollections[0];
+      }
+      else {
       // ask user in which address book the new contact shall be stored
       const QStringList mimeTypes( KABC::Addressee::mimeType() );
       Akonadi::CollectionDialog dlg;
@@ -78,7 +122,9 @@
         return;
       }
 
-      const Akonadi::Collection addressBook = dlg.selectedCollection();
+        addressBook = dlg.selectedCollection();
+      }
+
       if ( !addressBook.isValid() ) {
         q->setError( UserDefinedError );
         q->emitResult();
--- trunk/KDE/kdepim/libkdepim/addemailaddressjob.h #1169187:1169188
@@ -73,6 +73,7 @@
 
     Q_PRIVATE_SLOT( d, void slotSearchDone( KJob* ) )
     Q_PRIVATE_SLOT( d, void slotAddContactDone( KJob* ) )
+    Q_PRIVATE_SLOT( d, void slotCollectionsFetched( KJob* ) )
     //@endcond
 };
 


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

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