kmail

kmfoldertree.h

Go to the documentation of this file.
00001 /* -*- mode: C++ -*-
00002    This file is part of the KDE libraries
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 #ifndef __KMFOLDERTREE
00019 #define __KMFOLDERTREE
00020 
00021 #include "foldertreebase.h"
00022 
00023 #include <klocale.h>
00024 #include <kdepimmacros.h>
00025 
00026 #include <qguardedptr.h>
00027 #include <qwidget.h>
00028 #include <qtimer.h>
00029 #include <qheader.h>
00030 
00031 class QDropEvent;
00032 class QPixmap;
00033 class QPainter;
00034 class QPopupMenu;
00035 class KPopupMenu;
00036 class KMFolder;
00037 class KMFolderDir;
00038 class KMFolderImap;
00039 class KMFolderTree;
00040 class KMAccount;
00041 // duplication from kmcommands.h, to avoid the include
00042 typedef QMap<int,KMFolder*> KMMenuToFolder;
00043 template <typename T> class QGuardedPtr;
00044 
00045 class KDE_EXPORT KMFolderTreeItem : public QObject, public KFolderTreeItem
00046 {
00047   Q_OBJECT
00048 public:
00050   KMFolderTreeItem( KFolderTree *parent, const QString & name,
00051                     KFolderTreeItem::Protocol protocol=KFolderTreeItem::NONE );
00052 
00054   KMFolderTreeItem( KFolderTree *parent, const QString & name,
00055                     KMFolder* folder );
00056 
00058   KMFolderTreeItem( KFolderTreeItem* parent, const QString & name,
00059                     KMFolder* folder );
00060   virtual ~KMFolderTreeItem();
00061 
00062   QPixmap normalIcon( int size ) const;
00063   QPixmap unreadIcon( int size ) const;
00064 
00065   void setNeedsRepaint( bool value ) { mNeedsRepaint = value; }
00066   bool needsRepaint() const { return mNeedsRepaint; }
00067 
00069   KMFolder* folder() const { return mFolder; }
00070   QListViewItem* parent() const { return KFolderTreeItem::parent(); }
00071 
00074   void adjustUnreadCount( int newUnreadCount );
00075 
00077   virtual bool acceptDrag(QDropEvent* e) const;
00078 
00079 signals:
00081   void iconChanged( KMFolderTreeItem * );
00083   void nameChanged( KMFolderTreeItem * );
00084 
00085 public slots:
00086   void properties();
00087   void assignShortcut();
00088   void slotShowExpiryProperties();
00089   void slotIconsChanged();
00090   void slotNameChanged();
00091   void updateCount();
00092 
00093 protected:
00094   void init();
00095   KMFolder* mFolder;
00097   virtual bool useTopLevelIcon() const { return depth() == 0; }
00099   virtual int iconSize() const { return 16; }
00100 
00101 private:
00102   bool mNeedsRepaint;
00103 };
00104 
00105 //==========================================================================
00106 
00107 class KMFolderTree : public KMail::FolderTreeBase
00108 {
00109   Q_OBJECT
00110 
00111 public:
00112   KMFolderTree( KMMainWidget *mainWidget, QWidget *parent=0,
00113         const char *name=0 );
00114 
00116   void writeConfig();
00117 
00119   virtual void reload(bool openFolders = false);
00120 
00122   virtual void addDirectory( KMFolderDir *fdir, KMFolderTreeItem* parent );
00123 
00125   void createFolderList( QStringList *str,
00126                          QValueList<QGuardedPtr<KMFolder> > *folders,
00127                          bool localFolders=true,
00128                          bool imapFolders=true,
00129                          bool dimapFolders=true,
00130                          bool searchFolders=false,
00131                          bool includeNoContent=true,
00132                          bool includeNoChildren=true );
00133 
00135   virtual void readConfig(void);
00136 
00138   void cleanupConfigFile();
00139 
00141   void nextUnreadFolder(bool confirm);
00142 
00144   bool checkUnreadFolder(KMFolderTreeItem* ftl, bool confirm);
00145 
00146   KMFolder *currentFolder() const;
00147 
00148   QValueList<QGuardedPtr<KMFolder> > selectedFolders();
00149 
00150   enum ColumnMode {unread=15, total=16, foldersize=17};
00151 
00153   void toggleColumn(int column, bool openFolders = false);
00154 
00157   virtual void updatePopup() const;
00158 
00160   void showFolder( KMFolder* );
00161 
00163   enum MenuAction {
00164     CopyMessage,
00165     MoveMessage,
00166     CopyFolder,
00167     MoveFolder
00168   };
00169 
00171   void folderToPopupMenu( MenuAction action, QObject *receiver, KMMenuToFolder *,
00172       QPopupMenu *menu, QListViewItem *start = 0 );
00173 
00174 signals:
00176   void folderSelected(KMFolder*);
00177 
00179   void folderSelectedUnread( KMFolder * );
00180 
00182   void columnsChanged();
00183 
00185   void iconChanged( KMFolderTreeItem * );
00186 
00188   void nameChanged( KMFolderTreeItem * );
00189 
00190 public slots:
00192   void nextUnreadFolder();
00193 
00195   void prevUnreadFolder();
00196 
00198   void incCurrentFolder();
00199 
00201   void decCurrentFolder();
00202 
00204   void selectCurrentFolder();
00205 
00207   void delayedUpdate();
00208 
00210   void slotAccountRemoved(KMAccount*);
00211 
00213   void doFolderSelected(QListViewItem *qlvi, bool keepSelection = false);
00214 
00220   void slotResetFolderList( QListViewItem* item = 0, bool startList = true );
00221 
00223   void addChildFolder( KMFolder *folder = 0, QWidget * parent = 0 );
00224 
00226   void copyFolder();
00227 
00229   void cutFolder();
00230 
00232   void pasteFolder();
00233 
00234 protected slots:
00235   //  void slotRMB(int, int);
00237   void doFolderListChanged();
00238 
00240   void slotFolderRemoved(KMFolder *);
00241 
00243   void slotFolderMoveOrCopyOperationFinished();
00244 
00246   void refresh();
00247 
00249   void openFolder();
00250 
00252   void slotFolderExpanded( QListViewItem * item );
00253 
00255   void slotFolderCollapsed( QListViewItem * item );
00256 
00258   void slotRenameFolder( QListViewItem * item, int col, const QString& text);
00259 
00261   void slotUpdateCountsDelayed(KMFolder * folder);
00262   void slotUpdateCountTimeout();
00263   void slotUpdateOneCount();
00264 
00266   void slotToggleUnreadColumn();
00267   void slotToggleTotalColumn();
00268   void slotToggleSizeColumn();
00269 
00270   void slotContextMenuRequested( QListViewItem *, const QPoint & );
00271 
00273   void slotCheckMail();
00274 
00275   void slotNewMessageToMailingList();
00276 
00278   virtual void moveSelectedToFolder( int menuId );
00280   virtual void copySelectedToFolder( int menuId );
00281 
00283   void updateCopyActions();
00284 
00285 protected:
00286   virtual void contentsMousePressEvent( QMouseEvent *e );
00287   virtual void contentsMouseReleaseEvent(QMouseEvent* me);
00288 
00290   virtual void updateUnreadAll( );
00291 
00292   virtual void resizeEvent(QResizeEvent*);
00293 
00295   bool readIsListViewItemOpen(KMFolderTreeItem *fti);
00296   void writeIsListViewItemOpen(KMFolderTreeItem *fti);
00297 
00298   QTimer mUpdateTimer;
00299 
00301   void contentsDragEnterEvent( QDragEnterEvent *e );
00302   void contentsDragMoveEvent( QDragMoveEvent *e );
00303   void contentsDragLeaveEvent( QDragLeaveEvent *e );
00304   void contentsDropEvent( QDropEvent *e );
00305   virtual QDragObject* dragObject();
00306 
00308   QListViewItem *oldCurrent, *oldSelected;
00309   QListViewItem *dropItem;
00310   KMFolderTreeItem *mLastItem;
00311   QTimer autoopen_timer;
00312 
00313   // filter some rmb-events
00314   bool eventFilter(QObject*, QEvent*);
00315 
00317   void prepareItem( KMFolderTreeItem* );
00318 
00320   void connectSignals();
00321 
00323   void moveOrCopyFolder( QValueList<QGuardedPtr<KMFolder> > sources, KMFolder* destination, bool move=false );
00324 
00325 private slots:
00326   void slotAddToFavorites();
00327   void slotUnhideLocalInbox();
00328 
00329 private:
00331   QListViewItemIterator mUpdateIterator;
00332 
00334   KPopupMenu* mPopup;
00335   int mUnreadPop;
00336   int mTotalPop;
00337   int mSizePop;
00338 
00339   bool mReloading;
00340   QValueList<QGuardedPtr<KMFolder> > mCopySourceFolders;
00341   bool mCutFolder;
00342 
00343   QTimer *mUpdateCountTimer;
00344   QMap<QString,KMFolder*> mFolderToUpdateCount;
00345 
00347   KMMenuToFolder mMenuToFolder;
00348 };
00349 
00350 #endif