Branch 'kolab/integration/4.13.0' - libkdepim/addressline libkdepim/ldap

Sandro Knauß knauss at kolabsys.com
Tue Jun 24 15:05:30 CEST 2014


 libkdepim/addressline/addresseelineedit.cpp |   57 +++++++++++++++++++++++++---
 libkdepim/addressline/addresseelineedit.h   |    8 ++-
 libkdepim/ldap/ldapclientsearch.cpp         |    1 
 libkdepim/ldap/ldapclientsearch.h           |    1 
 4 files changed, 60 insertions(+), 7 deletions(-)

New commits:
commit d41b31f647c336fdf5b939c87d0521aeddd5b433
Author: Sandro Knauß <knauss at kolabsys.com>
Date:   Thu Jun 12 21:29:47 2014 +0200

    Display OU inside the addresslineedit completer
    
    When using a large LDAP Server, it is nice to see in what organization
    unit one specific address comes from.
    We display the ou after the mailaddress autocompletion list like this:
    
    "John Doe" <doe at example.com> (staff)
    "John Doe" <master at example.com> (customer)
    
    If it is used as mailadress(enter/mouse etc.), the ou part is stripped
    out before.
    
    The Display OU is configurable via context Menu.
    
    REVIEW: 118726
    (cherry picked from commit 3d7c250a3455b9713f89f979ba5c39d37f7da149)

diff --git a/libkdepim/addressline/addresseelineedit.cpp b/libkdepim/addressline/addresseelineedit.cpp
index 6134168..3cc65cd 100644
--- a/libkdepim/addressline/addresseelineedit.cpp
+++ b/libkdepim/addressline/addresseelineedit.cpp
@@ -259,6 +259,7 @@ public:
     void slotAkonadiCollectionsReceived( const Akonadi::Collection::List & );
     void searchInBaloo();
     void slotTriggerDelayedQueries();
+    void slotShowOUChanged( bool );
     static KCompletion::CompOrder completionOrder();
 
     AddresseeLineEdit *q;
@@ -271,6 +272,7 @@ public:
     bool m_lastSearchMode;
     bool m_searchExtended; //has \" been added?
     bool m_useSemicolonAsSeparator;
+    bool m_showOU;
     QTimer m_delayedQueryTimer;
     QColor m_alternateColor;
 };
@@ -312,6 +314,10 @@ void AddresseeLineEdit::Private::init()
 
             m_completionInitialized = true;
         }
+
+        KConfigGroup group( KGlobal::config(), "AddressLineEdit" );
+        m_showOU = group.readEntry( "ShowOU", false );
+
     }
 }
 
@@ -792,7 +798,11 @@ void AddresseeLineEdit::Private::slotCompletion()
 
 void AddresseeLineEdit::Private::slotPopupCompletion( const QString &completion )
 {
-    q->setText( m_previousAddresses + completion.trimmed() );
+    QString c = completion.trimmed();
+    if ( c.endsWith( QLatin1Char( ')' ) ) ) {
+        c = completion.mid( 0, completion.lastIndexOf( QLatin1String( " (" )) ).trimmed();
+    }
+    q->setText( m_previousAddresses + c );
     q->cursorAtEnd();
     updateSearchString();
     q->emitTextCompleted();
@@ -838,13 +848,25 @@ void AddresseeLineEdit::Private::slotLDAPSearchData( const KLDAP::LdapResult::Li
         KABC::Addressee contact;
         contact.setNameFromString( result.name );
         contact.setEmails( result.email );
+        QString ou;
+
+        if ( m_showOU ) {
+            const int depth = result.dn.depth();
+            for ( int i = 0; i < depth; ++i ) {
+                const QString rdnStr = result.dn.rdnString( i );
+                if ( rdnStr.startsWith( QLatin1String( "ou=" ), Qt::CaseInsensitive ) ) {
+                    ou = rdnStr.mid( 3 );
+                    break;
+                }
+            }
+        }
 
         if ( !s_static->ldapClientToCompletionSourceMap.contains( result.clientNumber ) ) {
             s_static->updateLDAPWeights(); // we got results from a new source, so update the completion sources
         }
 
         q->addContact( contact, result.completionWeight,
-                       s_static->ldapClientToCompletionSourceMap[ result.clientNumber ] );
+                       s_static->ldapClientToCompletionSourceMap[ result.clientNumber ], ou );
     }
 
     if ( ( q->hasFocus() || q->completionBox()->hasFocus() ) &&
@@ -965,6 +987,15 @@ KCompletion::CompOrder AddresseeLineEdit::Private::completionOrder()
     }
 }
 
+void AddresseeLineEdit::Private::slotShowOUChanged(bool checked)
+{
+    if ( checked != m_showOU ) {
+        KConfigGroup group( KGlobal::config(), "AddressLineEdit" );
+        group.writeEntry( "ShowOU", checked );
+        m_showOU = checked;
+    }
+}
+
 AddresseeLineEdit::AddresseeLineEdit( QWidget *parent, bool enableCompletion )
     : KLineEdit( parent ), d( new Private( this, enableCompletion ) )
 {
@@ -1232,7 +1263,7 @@ void AddresseeLineEdit::addContactGroup( const KABC::ContactGroup &group, int we
     d->addCompletionItem( group.name(), weight, source );
 }
 
-void AddresseeLineEdit::addContact( const KABC::Addressee &addr, int weight, int source )
+void AddresseeLineEdit::addContact( const KABC::Addressee &addr, int weight, int source, QString append )
 {
     const QStringList emails = addr.emails();
     QStringList::ConstIterator it;
@@ -1246,6 +1277,15 @@ void AddresseeLineEdit::addContact( const KABC::Addressee &addr, int weight, int
         const QString nickName  = addr.nickName();
         QString fullEmail       = addr.fullEmail( email );
 
+        QString appendix;
+
+        if ( !append.isEmpty() ) {
+            appendix = QLatin1String( " (%1)" );
+            append = append.replace( QLatin1String("("), QLatin1String("[") );
+            append = append.replace( QLatin1String(")"), QLatin1String("]") );
+            appendix = appendix.arg( append );
+        }
+
         // Prepare "givenName" + ' ' + "familyName"
         QString fullName = givenName;
         if (!familyName.isEmpty()) {
@@ -1260,7 +1300,7 @@ void AddresseeLineEdit::addContact( const KABC::Addressee &addr, int weight, int
             if (fullEmail != address) {
                 // This happens when fullEmail contains a middle name, while our own fullName+email only has "first last".
                 // Let's offer both, the fullEmail with 3 parts, looks a tad formal.
-                d->addCompletionItem(address, weight + isPrefEmail, source);
+                d->addCompletionItem(address + appendix, weight + isPrefEmail, source);
             }
         }
 
@@ -1269,7 +1309,7 @@ void AddresseeLineEdit::addContact( const KABC::Addressee &addr, int weight, int
             keyWords.append(nickName);
         }
 
-        d->addCompletionItem( fullEmail, weight + isPrefEmail, source, &keyWords );
+        d->addCompletionItem( fullEmail + appendix, weight + isPrefEmail, source, &keyWords );
 
         isPrefEmail = 0;
     }
@@ -1299,6 +1339,13 @@ QMenu *AddresseeLineEdit::createStandardContextMenu()
     if ( d->m_useCompletion ) {
         menu->addAction( i18n( "Configure Completion Order..." ),
                          this, SLOT(slotEditCompletionOrder()) );
+
+        QAction *showOU = new QAction(i18n( "Show Organication Unit for LDAP results" ),menu);
+        showOU->setCheckable(true);
+
+        showOU->setChecked( d->m_showOU );
+        connect(showOU, SIGNAL(triggered(bool)), this, SLOT(slotShowOUChanged(bool)));
+        menu->addAction(showOU);
     }
     return menu;
 }
diff --git a/libkdepim/addressline/addresseelineedit.h b/libkdepim/addressline/addresseelineedit.h
index 7d458d7..4ac3095 100644
--- a/libkdepim/addressline/addresseelineedit.h
+++ b/libkdepim/addressline/addresseelineedit.h
@@ -101,9 +101,12 @@ public Q_SLOTS:
 
 protected:
     /**
-     * Adds a new @p contact to the completion with a given @p weight and @p source index.
+     * Adds a new @p contact to the completion with a given
+     * @p weight
+     * @p source index
+     * @p append  is added to completion string, but removed, when mail is selected.
      */
-    void addContact( const KABC::Addressee &contact, int weight, int source = -1 );
+    void addContact( const KABC::Addressee &contact, int weight, int source = -1, QString append = QString() );
 
     /**
      * Same as the above, but this time with contact groups.
@@ -183,6 +186,7 @@ private:
     Q_PRIVATE_SLOT( d, void slotStartLDAPLookup() )
     Q_PRIVATE_SLOT( d, void slotLDAPSearchData( const KLDAP::LdapResult::List & ) )
     Q_PRIVATE_SLOT( d, void slotEditCompletionOrder() )
+    Q_PRIVATE_SLOT( d, void slotShowOUChanged( bool ) )
     Q_PRIVATE_SLOT( d, void slotUserCancelled( const QString & ) )
     Q_PRIVATE_SLOT( d, void slotAkonadiHandleItems( const Akonadi::Item::List & ) )
     Q_PRIVATE_SLOT( d, void slotAkonadiSearchResult( KJob * ) )
diff --git a/libkdepim/ldap/ldapclientsearch.cpp b/libkdepim/ldap/ldapclientsearch.cpp
index 47e3e09..ed5c23f 100644
--- a/libkdepim/ldap/ldapclientsearch.cpp
+++ b/libkdepim/ldap/ldapclientsearch.cpp
@@ -384,6 +384,7 @@ void LdapClientSearch::Private::makeSearchData( QStringList &ret, LdapResult::Li
         }
 
         LdapResult sr;
+        sr.dn = (*it1).object.dn();
         sr.clientNumber = (*it1).client->clientNumber();
         sr.completionWeight = (*it1).client->completionWeight();
         sr.name = name;
diff --git a/libkdepim/ldap/ldapclientsearch.h b/libkdepim/ldap/ldapclientsearch.h
index b219972..d20dd97 100644
--- a/libkdepim/ldap/ldapclientsearch.h
+++ b/libkdepim/ldap/ldapclientsearch.h
@@ -44,6 +44,7 @@ struct LdapResult
    */
     typedef QList<LdapResult> List;
 
+    LdapDN dn;
     QString name;         ///< The full name of the contact.
     QStringList email;    ///< The list of emails of the contact.
     int clientNumber;     ///< The client the contact comes from (used for sorting in a ldap-only lookup).




More information about the commits mailing list