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 <tqobject.h>
00030 #include <tqptrlist.h>
00031 #include <tqtimer.h>
00032 #include <tqpair.h>
00033 #include <tqvaluelist.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 TQValueList<LdapResult> LdapResultList;
00048 typedef TQMap< TQString, 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( TQWidget* parent, bool useCompletion = true,
00060                      const char *name = 0L);
00061     virtual ~AddresseeLineEdit();
00062 
00063     virtual void setFont( const TQFont& );
00064     void allowSemiColonAsSeparator( bool );
00065 
00070     void allowDistributionLists( bool allowDistLists );
00071 
00072   public slots:
00073     void cursorAtEnd();
00074     void enableCompletion( bool enable );
00076     virtual void setText( const TQString& txt );
00077 
00078   protected slots:
00079     virtual void loadContacts();
00080   protected:
00081     void addContact( const KABC::Addressee&, int weight, int source = -1 );
00082     virtual void keyPressEvent( TQKeyEvent* );
00091     virtual void insert( const TQString &text );
00093     virtual void paste();
00095     virtual void mouseReleaseEvent( TQMouseEvent *e );
00097     virtual void dropEvent( TQDropEvent *e );
00098     void doCompletion( bool ctrlT );
00099     virtual TQPopupMenu *createPopupMenu();
00100 
00108     int addCompletionSource( const TQString&, int weight );
00109 
00111     static KCompletion::CompOrder completionOrder();
00112 
00113   k_dcop:
00114     // Connected to the DCOP signal
00115     void slotIMAPCompletionOrderChanged();
00116 
00117   private slots:
00118     void slotCompletion();
00119     void slotPopupCompletion( const TQString& );
00120     void slotReturnPressed( const TQString& );
00121     void slotStartLDAPLookup();
00122     void slotLDAPSearchData( const KPIM::LdapResultList& );
00123     void slotEditCompletionOrder();
00124     void slotUserCancelled( const TQString& );
00125 
00126   private:
00127     virtual bool eventFilter(TQObject *o, TQEvent *e);
00128     void init();
00129     void startLoadingLDAPEntries();
00130     void stopLDAPLookup();
00131     void updateLDAPWeights();
00132 
00133     void setCompletedItems( const TQStringList& items, bool autoSuggest );
00134     void addCompletionItem( const TQString& string, int weight, int source, const TQStringList * keyWords=0 );
00135     TQString completionSearchText( TQString& );
00136     const TQStringList getAdjustedCompletionItems( bool fullSearch );
00137     void updateSearchString();
00138 
00139     TQString m_previousAddresses;
00140     TQString m_searchString;
00141     bool m_useCompletion;
00142     bool m_completionInitialized;
00143     bool m_smartPaste;
00144     bool m_addressBookConnected;
00145     bool m_lastSearchMode;
00146     bool m_searchExtended; //has \" been added?
00147     bool m_useSemiColonAsSeparator;
00148     bool m_allowDistLists;
00149 
00150     //TQMap<TQString, KABC::Addressee> m_contactMap;
00151 
00152     static bool s_addressesDirty;
00153     static KMailCompletion *s_completion;
00154     static CompletionItemsMap* s_completionItemMap;
00155     static TQTimer *s_LDAPTimer;
00156     static KPIM::LdapSearch *s_LDAPSearch;
00157     static TQString *s_LDAPText;
00158     static AddresseeLineEdit *s_LDAPLineEdit;
00159     static TQStringList *s_completionSources;
00160     static TQMap<int,int> *s_ldapClientToCompletionSourceMap;
00161 
00162     class AddresseeLineEditPrivate;
00163     AddresseeLineEditPrivate *d;
00164 
00165     //until MenuID moves into protected in KLineEdit, we keep a copy here
00166     //Constants that represent the ID's of the popup menu.
00167       enum MenuID
00168       {
00169         Default = 42,
00170         NoCompletion,
00171         AutoCompletion,
00172         ShellCompletion,
00173         PopupCompletion,
00174         ShortAutoCompletion,
00175         PopupAutoCompletion
00176       };
00177 
00178 };
00179 
00180 }
00181 
00182 #endif