summaryrefslogtreecommitdiffstats
path: root/libkdepim/addresseeview.h
blob: ae7281b5b0f48344c30d55bc4954619748a064a9 (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
    This file is part of libkdepim.

    Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>

    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 KPIM_ADDRESSEEVIEW_H
#define KPIM_ADDRESSEEVIEW_H

#include <tqcstring.h>

#include <kabc/addressee.h>
#include <ktextbrowser.h>
#include <kimproxy.h>
#include <kdepimmacros.h>

namespace KIO {
class Job;
}
class KToggleAction;

class TQPopupMenu;


namespace KPIM {


class KDE_EXPORT AddresseeView : public KTextBrowser
{
  Q_OBJECT
  public:
    /**
      Constructor.
 
      @param config The config object where the settings are stored
                    which fields will be shown.
     */
    AddresseeView( TQWidget *parent = 0, const char *name = 0,
                   KConfig *config = 0 );

    ~AddresseeView();

    /**
      Sets the addressee object. The addressee is displayed immediately.

      @param addr The addressee object.
     */
    void setAddressee( const KABC::Addressee& addr );

    /**
      Returns the current addressee object.
     */
    KABC::Addressee addressee() const;


    /**
      This enums are used by enableLinks to set which kind of links shall
      be enabled.
     */
    enum LinkMask {
      NoLinks = 0,
      AddressLinks = 1,
      EmailLinks = 2,
      PhoneLinks = 4,
      URLLinks = 8,
      IMLinks = 16,
      DefaultLinks = AddressLinks | EmailLinks | PhoneLinks | URLLinks | IMLinks
    };

    /**
      Sets which parts of the contact shall be presented as links.
      The mask can be OR'ed LinkMask. By default all links are enabled.
     */
    void enableLinks( int linkMask );

    /**
      This enums are used by vCardAsHTML to decide which fields shall be
      shown.
     */
    enum FieldMask {
      NoFields = 0,
      BirthdayFields = 1,
      AddressFields = 2,
      EmailFields = 4,
      PhoneFields = 8,
      URLFields = 16,
      IMFields = 32,
      CustomFields = 64,
      DefaultFields = AddressFields | EmailFields | PhoneFields | URLFields
    };

    /**
      Returns the HTML representation of a contact.
      The HTML code looks like
        <div>
        <table>
        ...
        </table>
        </div>

      @param addr The addressee object.
      @param linkMask The mask for which parts of the contact will
                      be displayed as links.
                      The links looks like this:
                        "addr://<addr id>" for addresses
                        "mailto:<email address>" for emails
                        "phone://<phone number>" for phone numbers
                        "http://<url>" for urls
                        "im:<im addrss>" for instant messaging addresses
                        "sms://<phone number>" for sending a sms
      @param internalLoading If true, the loading of internal pictures is done automatically.
      @param fieldMask The mask for which fields of the contact will
                       be displayed.
     */
    static TQString vCardAsHTML( const KABC::Addressee& addr, ::KIMProxy *proxy, LinkMask linkMask = DefaultLinks,
                                bool internalLoading = true, FieldMask fieldMask = DefaultFields );

    /**
     * Encodes a TQPixmap as a PNG into a data: URL (rfc2397), readable by the data kio protocol
     * @param pixmap the pixmap to encode
     * @return a data: URL
     */
    static TQString pixmapAsDataUrl( const TQPixmap& pixmap );

  signals:
    void urlHighlighted( const TQString &url );
    void emailHighlighted( const TQString &email );
    void phoneNumberHighlighted( const TQString &number );
    void faxNumberHighlighted( const TQString &number );

    void highlightedMessage( const TQString &message );

    void addressClicked( const TQString &uid );

  protected:
    virtual void urlClicked( const TQString &url );
    virtual void emailClicked( const TQString &mail );
    virtual void phoneNumberClicked( const TQString &number );
    virtual void smsTextClicked( const TQString &number );
    virtual void sendSMS( const TQString &number, const TQString &msg );
    virtual void faxNumberClicked( const TQString &number );
    virtual void imAddressClicked();

    virtual TQPopupMenu *createPopupMenu( const TQPoint& );

  private slots:
    void slotMailClicked( const TQString&, const TQString& );
    void slotUrlClicked( const TQString& );
    void slotHighlighted( const TQString& );
    void slotPresenceChanged( const TQString & );
    void slotPresenceInfoExpired();
    void configChanged();

    void data( KIO::Job*, const TQByteArray& );
    void result( KIO::Job* );

  private:
    void load();
    void save();

    void updateView();

    TQString strippedNumber( const TQString &number );

    KConfig *mConfig;
    bool mDefaultConfig;

    TQByteArray mImageData;
    KIO::Job *mImageJob;

    KToggleAction *mActionShowBirthday;
    KToggleAction *mActionShowAddresses;
    KToggleAction *mActionShowEmails;
    KToggleAction *mActionShowPhones;
    KToggleAction *mActionShowURLs;
    KToggleAction *mActionShowIMAddresses;
    KToggleAction *mActionShowCustomFields;

    KABC::Addressee mAddressee;
    int mLinkMask;

    class AddresseeViewPrivate;
    AddresseeViewPrivate *d;
    ::KIMProxy *mKIMProxy;
};

}

#endif