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