summaryrefslogtreecommitdiffstats
path: root/libkdepim/kfoldertree.h
blob: 5ee2557313311fb7eae2222b7768d5e0d433f67a (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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/* -*- mode: C++; c-file-style: "gnu" -*-

   This file is part of libtdepim.

   Copyright (C) 2002 Carsten Burghardt <burghardt@kde.org>
   Copyright (C) 2002 Marc Mutz <mutz@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 version 2 as published by the Free Software Foundation.

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

#include <tqpixmap.h>
#include <tqbitarray.h>
#include <tqdragobject.h>
#include <tqcolor.h>
#include <klistview.h>
#include <tdepimmacros.h>

class KFolderTree;

/** Information shared by all items in a list view */
struct KPaintInfo {

  // Popup ids for toggle-able columns
  enum ColumnIds
  {
    COL_SIZE,
    COL_ATTACHMENT,
    COL_INVITATION,
    COL_IMPORTANT,
    COL_TODO,
    COL_SPAM_HAM,
    COL_WATCHED_IGNORED,
    COL_STATUS,
    COL_SIGNED,
    COL_CRYPTO,
    COL_RECEIVER,
    COL_SCORE
  };

  KPaintInfo() :
    pixmapOn(false),

    showSize(false),
    showAttachment(false),
    showInvitation(false),
    showImportant(false),
    showTodo(false),
    showSpamHam(false),
    showWatchedIgnored(false),
    showtqStatus(false),
    showSigned(false),
    showCrypto(false),
    showReceiver(false),
    showScore(false),

    scoreCol(-1),
    flagCol(-1),
    senderCol(-1),
    receiverCol(-1),
    subCol(-1),
    dateCol(-1),
    sizeCol(-1),
    attachmentCol(-1),
    invitationCol(-1),
    importantCol(-1),
    todoCol(-1),
    spamHamCol(-1),
    watchedIgnoredCol(-1),
    statusCol(-1),
    signedCol(-1),
    cryptoCol(-1),

    orderOfArrival(false),
    status(false),
    showCryptoIcons(false),
    showAttachmentIcon(false),
    showInvitationIcon(false)
    {}

  bool pixmapOn;
  TQPixmap pixmap;
  TQColor colFore;
  TQColor colBack;
  TQColor colNew;
  TQColor colUnread;
  TQColor colFlag;
  TQColor colTodo;
  TQColor colCloseToQuota;

  bool showSize;
  bool showAttachment;
  bool showInvitation;
  bool showImportant;
  bool showTodo;
  bool showSpamHam;
  bool showWatchedIgnored;
  bool showtqStatus;
  bool showSigned;
  bool showCrypto;
  bool showReceiver;
  bool showScore;

  int scoreCol;
  int flagCol;
  int senderCol;
  int receiverCol;
  int subCol;
  int dateCol;
  int sizeCol;
  int attachmentCol;
  int invitationCol;
  int importantCol;
  int todoCol;
  int spamHamCol;
  int watchedIgnoredCol;
  int statusCol;
  int signedCol;
  int cryptoCol;

  bool orderOfArrival;
  bool status;
  bool showCryptoIcons;
  bool showAttachmentIcon;
  bool showInvitationIcon;
};

//==========================================================================

class KDE_EXPORT KFolderTreeItem : public KListViewItem
{
  public:
    /** Protocol information */
    enum Protocol {
      Imap,
      Local,
      News,
      CachedImap,
      Search,
      NONE
    };

    /** Type information */
    enum Type {
      Inbox,
      Outbox,
      SentMail,
      Trash,
      Drafts,
      Templates,
      Root,
      Calendar,
      Tasks,
      Journals,
      Contacts,
      Notes,
      Other
    };

    /** constructs a root-item */
    KFolderTreeItem( KFolderTree *parent, const TQString & label=TQString(),
        Protocol protocol=NONE, Type type=Root );

    /** constructs a child-item */
    KFolderTreeItem( KFolderTreeItem *parent, const TQString & label=TQString(),
        Protocol protocol=NONE, Type type=Other, int unread=0, int total=0 );

    /** compare */
    virtual int compare( TQListViewItem * i, int col,
        bool ascending ) const;

    /** set/get the unread-count */
    int unreadCount() { return mUnread; }
    virtual void setUnreadCount( int aUnread );

    /** set/get the total-count */
    int totalCount() { return mTotal; }
    virtual void setTotalCount( int aTotal );

    /** set/get the total-count */
    TQ_INT64 folderSize() { return mSize; }
    virtual void setFolderSize( TQ_INT64 aSize );

    /** set/get the protocol of the item */
    Protocol protocol() const { return mProtocol; }
    virtual void setProtocol( Protocol aProtocol ) { mProtocol = aProtocol; }

    /** set/get the type of the item */
    Type type() const { return mType; }
    virtual void setType( Type aType ) { mType = aType; }

    /** recursive unread count */
    virtual int countUnreadRecursive();

    virtual TQ_INT64 recursiveFolderSize() const;

    /** paints the cell */
    virtual void paintCell( TQPainter * p, const TQColorGroup & cg,
        int column, int width, int align );

    /** dnd */
    virtual bool acceptDrag(TQDropEvent* ) const { return true; }

    void setFolderIsCloseToQuota( bool );
    bool folderIsCloseToQuota() const;

  private:
    /** returns a sorting key based on the folder's protocol */
    int protocolSortingKey() const;
    /** returns a sorting key based on the folder's type */
    int typeSortingKey() const;

  protected:
    /** reimplement to use special squeezing algorithm for the folder name */
    virtual TQString squeezeFolderName( const TQString &text,
                                       const TQFontMetrics &fm,
                                       uint width ) const;

    Protocol mProtocol;
    Type mType;
    int mUnread;
    int mTotal;
    TQ_INT64 mSize;
    bool mFolderIsCloseToQuota;
};

//==========================================================================

class KDE_EXPORT KFolderTree : public KListView
{
  Q_OBJECT
  TQ_OBJECT

  public:
    KFolderTree( TQWidget *parent, const char *name=0 );

    /** registers MIMETypes that are handled
      @param mimeType the name of the MIMEType
      @param outsideOk accept drops of this type even if
      the mouse cursor is not on top of an item */
    virtual void addAcceptableDropMimetype( const char *mimeType, bool outsideOk );

    /** checks if the drag is acceptable */
    virtual bool acceptDrag( TQDropEvent* event ) const;

    /** returns the KPaintInfo */
    KPaintInfo paintInfo() const { return mPaintInfo; }

    /** add/remove unread/total-columns */
    virtual void addUnreadColumn( const TQString & name, int width=70 );
    virtual void removeUnreadColumn();
    virtual void addTotalColumn( const TQString & name, int width=70 );
    virtual void removeTotalColumn();
    virtual void addSizeColumn( const TQString & name, int width=70 );
    virtual void removeSizeColumn();


    /** the current index of the unread/total column */
    int unreadIndex() const { return mUnreadIndex; }
    int totalIndex() const { return mTotalIndex;  }
    int sizeIndex() const { return mSizeIndex;  }

    /** is the unread/total-column active? */
    bool isUnreadActive() const { return mUnreadIndex >= 0; }
    bool isTotalActive() const { return mTotalIndex >=  0; }
    bool isSizeActive() const { return mSizeIndex >=  0; }

    /** reimp to set full width of the _first_ column */
    virtual void setFullWidth( bool fullWidth );

  protected:
    /** reimplemented in order to update the frame width in case of a changed
        GUI style */
    void styleChange( TQStyle& oldStyle );

    /** Set the width of the frame to a reasonable value for the current GUI
        style */
    void setStyleDependantFrameWidth();

    virtual void drawContentsOffset( TQPainter * p, int ox, int oy,
        int cx, int cy, int cw, int ch );

    virtual void contentsMousePressEvent( TQMouseEvent *e );
    virtual void contentsMouseReleaseEvent( TQMouseEvent *e );

    /** for mimetypes */
    TQMemArray<const char*> mAcceptableDropMimetypes;
    TQBitArray mAcceptOutside;

    /** shared information */ // ### why isn't it then static? ;-)
    KPaintInfo mPaintInfo;

    /** current index of unread/total-column
     * -1 is deactivated */
    int mUnreadIndex;
    int mTotalIndex;
    int mSizeIndex;

  private slots:
    /** repaints the complete column (instead of only parts of it as done in
        TQListView) if the size has changed */
    void slotSizeChanged( int section, int oldSize, int newSize );

};

#endif