summaryrefslogtreecommitdiffstats
path: root/libtdepim/addresseelineedit.h
blob: 3c98fe132c816ee78e91fc1b82fa2c43b41b2b51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
    This file is part of libtdepim.
    Copyright (c) 2002 Helge Deller <deller@gmx.de>
                  2002 Lubos Lunak <llunak@suse.cz>
                  2001,2003 Carsten Pfeiffer <pfeiffer@kde.org>
                  2001 Waldo Bastian <bastian@kde.org>
                  2004 Daniel Molkentin <danimo@klaralvdalens-datakonsult.se>
                  2004 Karl-Heinz Zimmer <khz@klaralvdalens-datakonsult.se>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef ADDRESSEELINEEDIT_H
#define ADDRESSEELINEEDIT_H

#include <tqobject.h>
#include <tqptrlist.h>
#include <tqtimer.h>
#include <tqpair.h>
#include <tqvaluelist.h>

#include <kabc/addressee.h>

#include "clicklineedit.h"
#include "kmailcompletion.h"
#include <dcopobject.h>
#include <tdepimmacros.h>

class KConfig;

namespace KPIM {
class LdapSearch;
class LdapResult;
typedef TQValueList<LdapResult> LdapResultList;
typedef TQMap< TQString, TQPair<int,int> > CompletionItemsMap;
}

namespace KPIM {

class KDE_EXPORT AddresseeLineEdit : public ClickLineEdit, public DCOPObject
{
  K_DCOP
  Q_OBJECT
  

  public:
    AddresseeLineEdit( TQWidget* parent, bool useCompletion = true,
                     const char *name = 0L);
    virtual ~AddresseeLineEdit();

    virtual void setFont( const TQFont& );
    void allowSemiColonAsSeparator( bool );

    /// Sets if distribution lists will be used for completion.
    /// This is true by default.
    /// Call this right after the constructor, before anything calls loadContacts(),
    /// otherwise this has no effect.
    void allowDistributionLists( bool allowDistLists );

  public slots:
    void cursorAtEnd();
    void enableCompletion( bool enable );
    /** Reimplemented for stripping whitespace after completion */
    virtual void setText( const TQString& txt );

  protected slots:
    virtual void loadContacts();
  protected:
    void addContact( const KABC::Addressee&, int weight, int source = -1 );
    virtual void keyPressEvent( TQKeyEvent* );
    /**
     * Reimplemented for smart insertion of email addresses.
     * Features:
     * - Automatically adds ',' if necessary to separate email addresses
     * - Correctly decodes mailto URLs
     * - Recognizes email addresses which are protected against address
     *   harvesters, i.e. "name at kde dot org" and "name(at)kde.org"
     */
    virtual void insert( const TQString &text );
    /** Reimplemented for smart insertion of pasted email addresses. */
    virtual void paste();
    /** Reimplemented for smart insertion with middle mouse button. */
    virtual void mouseReleaseEvent( TQMouseEvent *e );
    /** Reimplemented for smart insertion of dragged email addresses. */
    virtual void dropEvent( TQDropEvent *e );
    void doCompletion( bool ctrlT );
    virtual TQPopupMenu *createPopupMenu();

    /**
     * Adds the name of a completion source to the internal list of
     * such sources and returns its index, such that that can be used
     * for insertion of items associated with that source.
     * 
     * If the source already exists, the weight will be updated.
     */
    int addCompletionSource( const TQString&, int weight );

    /** return whether we are using sorted or weighted display */
    static KCompletion::CompOrder completionOrder();

  k_dcop:
    // Connected to the DCOP signal
    void slotIMAPCompletionOrderChanged();

  private slots:
    void slotCompletion();
    void slotPopupCompletion( const TQString& );
    void slotReturnPressed( const TQString& );
    void slotStartLDAPLookup();
    void slotLDAPSearchData( const KPIM::LdapResultList& );
    void slotEditCompletionOrder();
    void slotUserCancelled( const TQString& );

  private:
    virtual bool eventFilter(TQObject *o, TQEvent *e);
    void init();
    void startLoadingLDAPEntries();
    void stopLDAPLookup();
    void updateLDAPWeights();

    void setCompletedItems( const TQStringList& items, bool autoSuggest );
    void addCompletionItem( const TQString& string, int weight, int source, const TQStringList * keyWords=0 );
    TQString completionSearchText( TQString& );
    const TQStringList getAdjustedCompletionItems( bool fullSearch );
    void updateSearchString();

    TQString m_previousAddresses;
    TQString m_searchString;
    bool m_useCompletion;
    bool m_completionInitialized;
    bool m_smartPaste;
    bool m_addressBookConnected;
    bool m_lastSearchMode;
    bool m_searchExtended; //has \" been added?
    bool m_useSemiColonAsSeparator;
    bool m_allowDistLists;

    //TQMap<TQString, KABC::Addressee> m_contactMap;

    static bool s_addressesDirty;
    static KMailCompletion *s_completion;
    static CompletionItemsMap* s_completionItemMap;
    static TQTimer *s_LDAPTimer;
    static KPIM::LdapSearch *s_LDAPSearch;
    static TQString *s_LDAPText;
    static AddresseeLineEdit *s_LDAPLineEdit;
    static TQStringList *s_completionSources;
    static TQMap<int,int> *s_ldapClientToCompletionSourceMap;

    class AddresseeLineEditPrivate;
    AddresseeLineEditPrivate *d;

    //until MenuID moves into protected in KLineEdit, we keep a copy here
    //Constants that represent the ID's of the popup menu.
      enum MenuID
      {
        Default = 42,
        NoCompletion,
        AutoCompletion,
        ShellCompletion,
        PopupCompletion,
        ShortAutoCompletion,
        PopupAutoCompletion
      };

};

}

#endif