libtdepim

kfoldertree.h
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 
3  This file is part of libtdepim.
4 
5  Copyright (C) 2002 Carsten Burghardt <burghardt@kde.org>
6  Copyright (C) 2002 Marc Mutz <mutz@kde.org>
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License version 2 as published by the Free Software Foundation.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 #ifndef __KFOLDERTREE
23 #define __KFOLDERTREE
24 
25 #include <tqpixmap.h>
26 #include <tqbitarray.h>
27 #include <tqdragobject.h>
28 #include <tqcolor.h>
29 #include <tdelistview.h>
30 #include <tdepimmacros.h>
31 
32 class KFolderTree;
33 
35 struct KPaintInfo {
36 
37  // Popup ids for toggle-able columns
38  enum ColumnIds
39  {
40  COL_SIZE,
41  COL_ATTACHMENT,
42  COL_INVITATION,
43  COL_IMPORTANT,
44  COL_TODO,
45  COL_SPAM_HAM,
46  COL_WATCHED_IGNORED,
47  COL_STATUS,
48  COL_SIGNED,
49  COL_CRYPTO,
50  COL_RECEIVER,
51  COL_SCORE
52  };
53 
54  KPaintInfo() :
55  pixmapOn(false),
56 
57  showSize(false),
58  showAttachment(false),
59  showInvitation(false),
60  showImportant(false),
61  showTodo(false),
62  showSpamHam(false),
63  showWatchedIgnored(false),
64  showStatus(false),
65  showSigned(false),
66  showCrypto(false),
67  showReceiver(false),
68  showScore(false),
69 
70  scoreCol(-1),
71  flagCol(-1),
72  senderCol(-1),
73  receiverCol(-1),
74  subCol(-1),
75  dateCol(-1),
76  sizeCol(-1),
77  attachmentCol(-1),
78  invitationCol(-1),
79  importantCol(-1),
80  todoCol(-1),
81  spamHamCol(-1),
82  watchedIgnoredCol(-1),
83  statusCol(-1),
84  signedCol(-1),
85  cryptoCol(-1),
86 
87  orderOfArrival(false),
88  status(false),
89  showCryptoIcons(false),
90  showAttachmentIcon(false),
91  showInvitationIcon(false)
92  {}
93 
94  bool pixmapOn;
95  TQPixmap pixmap;
96  TQColor colFore;
97  TQColor colBack;
98  TQColor colNew;
99  TQColor colUnread;
100  TQColor colFlag;
101  TQColor colTodo;
102  TQColor colCloseToQuota;
103 
104  bool showSize;
105  bool showAttachment;
106  bool showInvitation;
107  bool showImportant;
108  bool showTodo;
109  bool showSpamHam;
110  bool showWatchedIgnored;
111  bool showStatus;
112  bool showSigned;
113  bool showCrypto;
114  bool showReceiver;
115  bool showScore;
116 
117  int scoreCol;
118  int flagCol;
119  int senderCol;
120  int receiverCol;
121  int subCol;
122  int dateCol;
123  int sizeCol;
124  int attachmentCol;
125  int invitationCol;
126  int importantCol;
127  int todoCol;
128  int spamHamCol;
129  int watchedIgnoredCol;
130  int statusCol;
131  int signedCol;
132  int cryptoCol;
133 
134  bool orderOfArrival;
135  bool status;
136  bool showCryptoIcons;
137  bool showAttachmentIcon;
138  bool showInvitationIcon;
139 };
140 
141 //==========================================================================
142 
143 class KDE_EXPORT KFolderTreeItem : public TDEListViewItem
144 {
145  public:
147  enum Protocol {
148  Imap,
149  Local,
150  News,
151  CachedImap,
152  Search,
153  NONE
154  };
155 
157  enum Type {
158  Inbox,
159  Outbox,
160  SentMail,
161  Trash,
162  Drafts,
163  Templates,
164  Root,
165  Calendar,
166  Tasks,
167  Journals,
168  Contacts,
169  Notes,
170  Other
171  };
172 
174  KFolderTreeItem( KFolderTree *parent, const TQString & label=TQString(),
175  Protocol protocol=NONE, Type type=Root );
176 
178  KFolderTreeItem( KFolderTreeItem *parent, const TQString & label=TQString(),
179  Protocol protocol=NONE, Type type=Other, int unread=0, int total=0 );
180 
182  virtual int compare( TQListViewItem * i, int col,
183  bool ascending ) const;
184 
186  int unreadCount() { return mUnread; }
187  virtual void setUnreadCount( int aUnread );
188 
190  int totalCount() { return mTotal; }
191  virtual void setTotalCount( int aTotal );
192 
194  TQ_INT64 folderSize() { return mSize; }
195  virtual void setFolderSize( TQ_INT64 aSize );
196 
198  Protocol protocol() const { return mProtocol; }
199  virtual void setProtocol( Protocol aProtocol ) { mProtocol = aProtocol; }
200 
202  Type type() const { return mType; }
203  virtual void setType( Type aType ) { mType = aType; }
204 
206  virtual int countUnreadRecursive();
207 
208  virtual TQ_INT64 recursiveFolderSize() const;
209 
211  virtual void paintCell( TQPainter * p, const TQColorGroup & cg,
212  int column, int width, int align );
213 
215  virtual bool acceptDrag(TQDropEvent* ) const { return true; }
216 
217  void setFolderIsCloseToQuota( bool );
218  bool folderIsCloseToQuota() const;
219 
220  private:
222  int protocolSortingKey() const;
224  int typeSortingKey() const;
225 
226  protected:
228  virtual TQString squeezeFolderName( const TQString &text,
229  const TQFontMetrics &fm,
230  uint width ) const;
231 
232  Protocol mProtocol;
233  Type mType;
234  int mUnread;
235  int mTotal;
236  TQ_INT64 mSize;
237  bool mFolderIsCloseToQuota;
238 };
239 
240 //==========================================================================
241 
242 class KDE_EXPORT KFolderTree : public TDEListView
243 {
244  Q_OBJECT
245 
246 
247  public:
248  KFolderTree( TQWidget *parent, const char *name=0 );
249 
254  virtual void addAcceptableDropMimetype( const char *mimeType, bool outsideOk );
255 
257  virtual bool acceptDrag( TQDropEvent* event ) const;
258 
260  KPaintInfo paintInfo() const { return mPaintInfo; }
261 
263  virtual void addUnreadColumn( const TQString & name, int width=70 );
264  virtual void removeUnreadColumn();
265  virtual void addTotalColumn( const TQString & name, int width=70 );
266  virtual void removeTotalColumn();
267  virtual void addSizeColumn( const TQString & name, int width=70 );
268  virtual void removeSizeColumn();
269 
270 
272  int unreadIndex() const { return mUnreadIndex; }
273  int totalIndex() const { return mTotalIndex; }
274  int sizeIndex() const { return mSizeIndex; }
275 
277  bool isUnreadActive() const { return mUnreadIndex >= 0; }
278  bool isTotalActive() const { return mTotalIndex >= 0; }
279  bool isSizeActive() const { return mSizeIndex >= 0; }
280 
282  virtual void setFullWidth( bool fullWidth );
283 
284  protected:
287  void styleChange( TQStyle& oldStyle );
288 
291  void setStyleDependantFrameWidth();
292 
293  virtual void drawContentsOffset( TQPainter * p, int ox, int oy,
294  int cx, int cy, int cw, int ch );
295 
296  virtual void contentsMousePressEvent( TQMouseEvent *e );
297  virtual void contentsMouseReleaseEvent( TQMouseEvent *e );
298 
300  TQMemArray<const char*> mAcceptableDropMimetypes;
301  TQBitArray mAcceptOutside;
302  // ### why isn't it then static? ;-)
304  KPaintInfo mPaintInfo;
305 
308  int mUnreadIndex;
309  int mTotalIndex;
310  int mSizeIndex;
311 
312  private slots:
315  void slotSizeChanged( int section, int oldSize, int newSize );
316 
317 };
318 
319 #endif