libkdepim

kfoldertree.h

00001 /* -*- mode: C++; c-file-style: "gnu" -*-
00002 
00003    This file is part of libkdepim.
00004 
00005    Copyright (C) 2002 Carsten Burghardt <burghardt@kde.org>
00006    Copyright (C) 2002 Marc Mutz <mutz@kde.org>
00007 
00008    This library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Library General Public
00010    License version 2 as published by the Free Software Foundation.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 */
00022 #ifndef __KFOLDERTREE
00023 #define __KFOLDERTREE
00024 
00025 #include <tqpixmap.h>
00026 #include <tqbitarray.h>
00027 #include <tqdragobject.h>
00028 #include <tqcolor.h>
00029 #include <klistview.h>
00030 #include <kdepimmacros.h>
00031 
00032 class KFolderTree;
00033 
00035 struct KPaintInfo {
00036 
00037   // Popup ids for toggle-able columns
00038   enum ColumnIds
00039   {
00040     COL_SIZE,
00041     COL_ATTACHMENT,
00042     COL_INVITATION,
00043     COL_IMPORTANT,
00044     COL_TODO,
00045     COL_SPAM_HAM,
00046     COL_WATCHED_IGNORED,
00047     COL_STATUS,
00048     COL_SIGNED,
00049     COL_CRYPTO,
00050     COL_RECEIVER,
00051     COL_SCORE
00052   };
00053 
00054   KPaintInfo() :
00055     pixmapOn(false),
00056 
00057     showSize(false),
00058     showAttachment(false),
00059     showInvitation(false),
00060     showImportant(false),
00061     showTodo(false),
00062     showSpamHam(false),
00063     showWatchedIgnored(false),
00064     showStatus(false),
00065     showSigned(false),
00066     showCrypto(false),
00067     showReceiver(false),
00068     showScore(false),
00069 
00070     scoreCol(-1),
00071     flagCol(-1),
00072     senderCol(-1),
00073     receiverCol(-1),
00074     subCol(-1),
00075     dateCol(-1),
00076     sizeCol(-1),
00077     attachmentCol(-1),
00078     invitationCol(-1),
00079     importantCol(-1),
00080     todoCol(-1),
00081     spamHamCol(-1),
00082     watchedIgnoredCol(-1),
00083     statusCol(-1),
00084     signedCol(-1),
00085     cryptoCol(-1),
00086 
00087     orderOfArrival(false),
00088     status(false),
00089     showCryptoIcons(false),
00090     showAttachmentIcon(false),
00091     showInvitationIcon(false)
00092     {}
00093 
00094   bool pixmapOn;
00095   TQPixmap pixmap;
00096   TQColor colFore;
00097   TQColor colBack;
00098   TQColor colNew;
00099   TQColor colUnread;
00100   TQColor colFlag;
00101   TQColor colTodo;
00102   TQColor colCloseToQuota;
00103 
00104   bool showSize;
00105   bool showAttachment;
00106   bool showInvitation;
00107   bool showImportant;
00108   bool showTodo;
00109   bool showSpamHam;
00110   bool showWatchedIgnored;
00111   bool showStatus;
00112   bool showSigned;
00113   bool showCrypto;
00114   bool showReceiver;
00115   bool showScore;
00116 
00117   int scoreCol;
00118   int flagCol;
00119   int senderCol;
00120   int receiverCol;
00121   int subCol;
00122   int dateCol;
00123   int sizeCol;
00124   int attachmentCol;
00125   int invitationCol;
00126   int importantCol;
00127   int todoCol;
00128   int spamHamCol;
00129   int watchedIgnoredCol;
00130   int statusCol;
00131   int signedCol;
00132   int cryptoCol;
00133 
00134   bool orderOfArrival;
00135   bool status;
00136   bool showCryptoIcons;
00137   bool showAttachmentIcon;
00138   bool showInvitationIcon;
00139 };
00140 
00141 //==========================================================================
00142 
00143 class KDE_EXPORT KFolderTreeItem : public KListViewItem
00144 {
00145   public:
00147     enum Protocol {
00148       Imap,
00149       Local,
00150       News,
00151       CachedImap,
00152       Search,
00153       NONE
00154     };
00155 
00157     enum Type {
00158       Inbox,
00159       Outbox,
00160       SentMail,
00161       Trash,
00162       Drafts,
00163       Templates,
00164       Root,
00165       Calendar,
00166       Tasks,
00167       Journals,
00168       Contacts,
00169       Notes,
00170       Other
00171     };
00172 
00174     KFolderTreeItem( KFolderTree *parent, const TQString & label=TQString::null,
00175         Protocol protocol=NONE, Type type=Root );
00176 
00178     KFolderTreeItem( KFolderTreeItem *parent, const TQString & label=TQString::null,
00179         Protocol protocol=NONE, Type type=Other, int unread=0, int total=0 );
00180 
00182     virtual int compare( TQListViewItem * i, int col,
00183         bool ascending ) const;
00184 
00186     int unreadCount() { return mUnread; }
00187     virtual void setUnreadCount( int aUnread );
00188 
00190     int totalCount() { return mTotal; }
00191     virtual void setTotalCount( int aTotal );
00192 
00194     Q_INT64 folderSize() { return mSize; }
00195     virtual void setFolderSize( Q_INT64 aSize );
00196 
00198     Protocol protocol() const { return mProtocol; }
00199     virtual void setProtocol( Protocol aProtocol ) { mProtocol = aProtocol; }
00200 
00202     Type type() const { return mType; }
00203     virtual void setType( Type aType ) { mType = aType; }
00204 
00206     virtual int countUnreadRecursive();
00207 
00208     virtual Q_INT64 recursiveFolderSize() const;
00209 
00211     virtual void paintCell( TQPainter * p, const TQColorGroup & cg,
00212         int column, int width, int align );
00213 
00215     virtual bool acceptDrag(TQDropEvent* ) const { return true; }
00216 
00217     void setFolderIsCloseToQuota( bool );
00218     bool folderIsCloseToQuota() const;
00219 
00220   private:
00222     int protocolSortingKey() const;
00224     int typeSortingKey() const;
00225 
00226   protected:
00228     virtual TQString squeezeFolderName( const TQString &text,
00229                                        const TQFontMetrics &fm,
00230                                        uint width ) const;
00231 
00232     Protocol mProtocol;
00233     Type mType;
00234     int mUnread;
00235     int mTotal;
00236     Q_INT64 mSize;
00237     bool mFolderIsCloseToQuota;
00238 };
00239 
00240 //==========================================================================
00241 
00242 class KDE_EXPORT KFolderTree : public KListView
00243 {
00244   Q_OBJECT
00245 
00246   public:
00247     KFolderTree( TQWidget *parent, const char *name=0 );
00248 
00253     virtual void addAcceptableDropMimetype( const char *mimeType, bool outsideOk );
00254 
00256     virtual bool acceptDrag( TQDropEvent* event ) const;
00257 
00259     KPaintInfo paintInfo() const { return mPaintInfo; }
00260 
00262     virtual void addUnreadColumn( const TQString & name, int width=70 );
00263     virtual void removeUnreadColumn();
00264     virtual void addTotalColumn( const TQString & name, int width=70 );
00265     virtual void removeTotalColumn();
00266     virtual void addSizeColumn( const TQString & name, int width=70 );
00267     virtual void removeSizeColumn();
00268 
00269 
00271     int unreadIndex() const { return mUnreadIndex; }
00272     int totalIndex() const { return mTotalIndex;  }
00273     int sizeIndex() const { return mSizeIndex;  }
00274 
00276     bool isUnreadActive() const { return mUnreadIndex >= 0; }
00277     bool isTotalActive() const { return mTotalIndex >=  0; }
00278     bool isSizeActive() const { return mSizeIndex >=  0; }
00279 
00281     virtual void setFullWidth( bool fullWidth );
00282 
00283   protected:
00286     void styleChange( TQStyle& oldStyle );
00287 
00290     void setStyleDependantFrameWidth();
00291 
00292     virtual void drawContentsOffset( TQPainter * p, int ox, int oy,
00293         int cx, int cy, int cw, int ch );
00294 
00295     virtual void contentsMousePressEvent( TQMouseEvent *e );
00296     virtual void contentsMouseReleaseEvent( TQMouseEvent *e );
00297 
00299     TQMemArray<const char*> mAcceptableDropMimetypes;
00300     TQBitArray mAcceptOutside;
00301  // ### why isn't it then static? ;-)
00303     KPaintInfo mPaintInfo;
00304 
00307     int mUnreadIndex;
00308     int mTotalIndex;
00309     int mSizeIndex;
00310 
00311   private slots:
00314     void slotSizeChanged( int section, int oldSize, int newSize );
00315 
00316 };
00317 
00318 #endif