libkdepim

addresseelineedit.h

00001 /*
00002     This file is part of libkdepim.
00003     Copyright (c) 2002 Helge Deller <deller@gmx.de>
00004                   2002 Lubos Lunak <llunak@suse.cz>
00005                   2001,2003 Carsten Pfeiffer <pfeiffer@kde.org>
00006                   2001 Waldo Bastian <bastian@kde.org>
00007                   2004 Daniel Molkentin <danimo@klaralvdalens-datakonsult.se>
00008                   2004 Karl-Heinz Zimmer <khz@klaralvdalens-datakonsult.se>
00009 
00010     This library is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Library General Public
00012     License as published by the Free Software Foundation; either
00013     version 2 of the License, or (at your option) any later version.
00014 
00015     This library is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018     Library General Public License for more details.
00019 
00020     You should have received a copy of the GNU Library General Public License
00021     along with this library; see the file COPYING.LIB.  If not, write to
00022     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00023     Boston, MA 02110-1301, USA.
00024 */
00025 
00026 #ifndef ADDRESSEELINEEDIT_H
00027 #define ADDRESSEELINEEDIT_H
00028 
00029 #include <qobject.h>
00030 #include <qptrlist.h>
00031 #include <qtimer.h>
00032 #include <qpair.h>
00033 #include <qvaluelist.h>
00034 
00035 #include <kabc/addressee.h>
00036 
00037 #include "clicklineedit.h"
00038 #include "kmailcompletion.h"
00039 #include <dcopobject.h>
00040 #include <kdepimmacros.h>
00041 
00042 class KConfig;
00043 
00044 namespace KPIM {
00045 class LdapSearch;
00046 class LdapResult;
00047 typedef QValueList<LdapResult> LdapResultList;
00048 typedef QMap< QString, QPair<int,int> > CompletionItemsMap;
00049 }
00050 
00051 namespace KPIM {
00052 
00053 class KDE_EXPORT AddresseeLineEdit : public ClickLineEdit, public DCOPObject
00054 {
00055   K_DCOP
00056   Q_OBJECT
00057 
00058   public:
00059     AddresseeLineEdit( QWidget* parent, bool useCompletion = true,
00060                      const char *name = 0L);
00061     virtual ~AddresseeLineEdit();
00062 
00063     virtual void setFont( const QFont& );
00064     void allowSemiColonAsSeparator( bool );
00065 
00066   public slots:
00067     void cursorAtEnd();
00068     void enableCompletion( bool enable );
00070     virtual void setText( const QString& txt );
00071 
00072   protected slots:
00073     virtual void loadContacts();
00074   protected:
00075     void addContact( const KABC::Addressee&, int weight, int source = -1 );
00076     virtual void keyPressEvent( QKeyEvent* );
00085     virtual void insert( const QString &text );
00087     virtual void paste();
00089     virtual void mouseReleaseEvent( QMouseEvent *e );
00091     virtual void dropEvent( QDropEvent *e );
00092     void doCompletion( bool ctrlT );
00093     virtual QPopupMenu *createPopupMenu();
00094 
00102     int addCompletionSource( const QString&, int weight );
00103 
00105     static KCompletion::CompOrder completionOrder();
00106 
00107   k_dcop:
00108     // Connected to the DCOP signal
00109     void slotIMAPCompletionOrderChanged();
00110 
00111   private slots:
00112     void slotCompletion();
00113     void slotPopupCompletion( const QString& );
00114     void slotReturnPressed( const QString& );
00115     void slotStartLDAPLookup();
00116     void slotLDAPSearchData( const KPIM::LdapResultList& );
00117     void slotEditCompletionOrder();
00118     void slotUserCancelled( const QString& );
00119 
00120   private:
00121     virtual bool eventFilter(QObject *o, QEvent *e);
00122     void init();
00123     void startLoadingLDAPEntries();
00124     void stopLDAPLookup();
00125     void updateLDAPWeights();
00126 
00127     void setCompletedItems( const QStringList& items, bool autoSuggest );
00128     void addCompletionItem( const QString& string, int weight, int source, const QStringList * keyWords=0 );
00129     QString completionSearchText( QString& );
00130     const QStringList getAdjustedCompletionItems( bool fullSearch );
00131     void updateSearchString();
00132 
00133     QString m_previousAddresses;
00134     QString m_searchString;
00135     bool m_useCompletion;
00136     bool m_completionInitialized;
00137     bool m_smartPaste;
00138     bool m_addressBookConnected;
00139     bool m_lastSearchMode;
00140     bool m_searchExtended; //has \" been added?
00141     bool m_useSemiColonAsSeparator;
00142 
00143     //QMap<QString, KABC::Addressee> m_contactMap;
00144 
00145     static bool s_addressesDirty;
00146     static KMailCompletion *s_completion;
00147     static CompletionItemsMap* s_completionItemMap;
00148     static QTimer *s_LDAPTimer;
00149     static KPIM::LdapSearch *s_LDAPSearch;
00150     static QString *s_LDAPText;
00151     static AddresseeLineEdit *s_LDAPLineEdit;
00152     static QStringList *s_completionSources;
00153 
00154     class AddresseeLineEditPrivate;
00155     AddresseeLineEditPrivate *d;
00156 
00157     //until MenuID moves into protected in KLineEdit, we keep a copy here
00158     //Constants that represent the ID's of the popup menu.
00159       enum MenuID
00160       {
00161         Default = 42,
00162         NoCompletion,
00163         AutoCompletion,
00164         ShellCompletion,
00165         PopupCompletion,
00166         ShortAutoCompletion,
00167         PopupAutoCompletion
00168       };
00169 
00170 };
00171 
00172 }
00173 
00174 #endif