kmail

kmfoldertree.h

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 <klocale.h>
00022 #include <kfoldertree.h>
00023 #include <kdepimmacros.h>
00024 
00025 #include <qwidget.h>
00026 #include <qtimer.h>
00027 #include <qheader.h>
00028 
00029 class QDropEvent;
00030 class QPixmap;
00031 class QPainter;
00032 class QPopupMenu;
00033 class KPopupMenu;
00034 class KMFolder;
00035 class KMFolderDir;
00036 class KMFolderImap;
00037 class KMFolderTree;
00038 class KMMainWidget;
00039 class KMAccount;
00040 // duplication from kmcommands.h, to avoid the include
00041 typedef QMap<int,KMFolder*> KMMenuToFolder; 
00042 template <typename T> class QGuardedPtr;
00043 
00044 class KDE_EXPORT KMFolderTreeItem : public QObject, public KFolderTreeItem
00045 {
00046   Q_OBJECT
00047 public:
00049   KMFolderTreeItem( KFolderTree *parent, const QString & name,
00050                     KFolderTreeItem::Protocol protocol=KFolderTreeItem::NONE );
00051 
00053   KMFolderTreeItem( KFolderTree *parent, const QString & name,
00054                     KMFolder* folder );
00055 
00057   KMFolderTreeItem( KFolderTreeItem* parent, const QString & name,
00058                     KMFolder* folder );
00059   virtual ~KMFolderTreeItem();
00060 
00061   QPixmap normalIcon(int size=16) const;
00062   QPixmap unreadIcon(int size=16) const;
00063 
00064   void setNeedsRepaint( bool value ) { mNeedsRepaint = value; }
00065   bool needsRepaint() const { return mNeedsRepaint; }
00066 
00068   KMFolder* folder() const { return mFolder; }
00069   QListViewItem* parent() const { return KFolderTreeItem::parent(); }
00070 
00073   void adjustUnreadCount( int newUnreadCount );
00074 
00076   virtual bool acceptDrag(QDropEvent* ) const;
00077 
00078 signals:
00080   void iconChanged( KMFolderTreeItem * );
00082   void nameChanged( KMFolderTreeItem * );
00083 
00084 public slots:
00085   void properties();
00086   void assignShortcut();
00087   void slotShowExpiryProperties();
00088   void slotIconsChanged();
00089   void slotNameChanged();
00090 
00091 protected:
00092   void init();
00093   KMFolder* mFolder;
00094 private:
00095   bool mNeedsRepaint;
00096 };
00097 
00098 //==========================================================================
00099 
00100 class KMFolderTree : public KFolderTree
00101 {
00102   Q_OBJECT
00103 
00104 public:
00105   KMFolderTree( KMMainWidget *mainWidget, QWidget *parent=0,
00106         const char *name=0 );
00107 
00109   void writeConfig();
00110 
00112   virtual void reload(bool openFolders = false);
00113 
00115   virtual void addDirectory( KMFolderDir *fdir, KMFolderTreeItem* parent );
00116 
00118   virtual QListViewItem* indexOfFolder( const KMFolder* folder ) const
00119   {
00120      if ( mFolderToItem.contains( folder ) )
00121        return mFolderToItem[ folder ];
00122      else
00123        return 0;
00124   }
00125   
00127   void createFolderList( QStringList *str,
00128                          QValueList<QGuardedPtr<KMFolder> > *folders,
00129                          bool localFolders=true,
00130                          bool imapFolders=true,
00131                          bool dimapFolders=true,
00132                          bool searchFolders=false,
00133                          bool includeNoContent=true,
00134                          bool includeNoChildren=true );
00135 
00137   virtual void readConfig(void);
00138 
00140   void readColorConfig(void);
00141 
00143   void cleanupConfigFile();
00144 
00146   void nextUnreadFolder(bool confirm);
00147 
00149   bool checkUnreadFolder(KMFolderTreeItem* ftl, bool confirm);
00150 
00151   KMFolder *currentFolder() const;
00152 
00153   enum ColumnMode {unread=15, total=16};
00154 
00156   void toggleColumn(int column, bool openFolders = false);
00157 
00160   virtual void updatePopup() const;
00161 
00163   KMMainWidget * mainWidget() const { return mMainWidget; }
00164 
00166   void showFolder( KMFolder* );
00167 
00168   void insertIntoFolderToItemMap( const KMFolder *folder, KMFolderTreeItem* item )
00169   {
00170     mFolderToItem.insert( folder, item );
00171   }
00172 
00173   void removeFromFolderToItemMap( const KMFolder *folder )
00174   {
00175     mFolderToItem.remove( folder );
00176   }
00177 
00179   enum MenuAction {
00180     CopyMessage,
00181     MoveMessage,
00182     MoveFolder
00183   };
00184   
00186   void folderToPopupMenu( MenuAction action, QObject *receiver, KMMenuToFolder *, 
00187       QPopupMenu *menu, QListViewItem *start = 0 );
00188   
00189 signals:
00191   void folderSelected(KMFolder*);
00192 
00194   void folderSelectedUnread( KMFolder * );
00195 
00197   void folderDrop(KMFolder*);
00198 
00200   void folderDropCopy(KMFolder*);
00201 
00203   void columnsChanged();
00204 
00206   void iconChanged( KMFolderTreeItem * );
00207 
00209   void nameChanged( KMFolderTreeItem * );
00210 
00211 public slots:
00213   void nextUnreadFolder();
00214 
00216   void prevUnreadFolder();
00217 
00219   void incCurrentFolder();
00220 
00222   void decCurrentFolder();
00223 
00225   void selectCurrentFolder();
00226 
00228   void delayedUpdate();
00229 
00231   void slotAccountRemoved(KMAccount*);
00232 
00234   void doFolderSelected(QListViewItem*);
00235 
00241   void slotResetFolderList( QListViewItem* item = 0, bool startList = true );
00242 
00244   void addChildFolder( KMFolder *folder = 0, QWidget * parent = 0 );
00245 
00246 protected slots:
00247   //  void slotRMB(int, int);
00249   void doFolderListChanged();
00250 
00252   void slotFolderRemoved(KMFolder *);
00253 
00255   void refresh();
00256 
00258   void openFolder();
00259 
00261   void slotFolderExpanded( QListViewItem * item );
00262 
00264   void slotFolderCollapsed( QListViewItem * item );
00265 
00267   void slotRenameFolder( QListViewItem * item, int col, const QString& text);
00268 
00270   void slotUpdateCounts(KMFolder * folder);
00271   void slotUpdateCounts(KMFolderImap * folder, bool success = true);
00273   void slotUpdateCountsDelayed(KMFolder * folder);
00274   void slotUpdateCountTimeout();
00275   void slotUpdateOneCount();
00276 
00278   void slotToggleUnreadColumn();
00279   void slotToggleTotalColumn();
00280 
00281   void slotContextMenuRequested( QListViewItem *, const QPoint & );
00282 
00284   void slotCheckMail();
00285 
00286   void slotNewMessageToMailingList();
00287 
00289   virtual void moveSelectedToFolder( int menuId );
00290 
00291 protected:
00293   virtual bool event(QEvent *e);
00294 
00295   virtual void contentsMouseReleaseEvent(QMouseEvent* me);
00296 
00298   virtual void updateUnreadAll( );
00299 
00300   virtual void resizeEvent(QResizeEvent*);
00301 
00303   bool readIsListViewItemOpen(KMFolderTreeItem *fti);
00304   void writeIsListViewItemOpen(KMFolderTreeItem *fti);
00305 
00306   QTimer mUpdateTimer;
00307 
00309   void contentsDragEnterEvent( QDragEnterEvent *e );
00310   void contentsDragMoveEvent( QDragMoveEvent *e );
00311   void contentsDragLeaveEvent( QDragLeaveEvent *e );
00312   void contentsDropEvent( QDropEvent *e );
00313 
00315   QListViewItem *oldCurrent, *oldSelected;
00316   QListViewItem *dropItem;
00317   KMFolderTreeItem *mLastItem;
00318   QTimer autoopen_timer;
00319 
00320   // filter some rmb-events
00321   bool eventFilter(QObject*, QEvent*);
00322 
00324   void prepareItem( KMFolderTreeItem* );
00325 
00327   void connectSignals();
00328 
00330   void moveFolder( KMFolder* destination );
00331 
00332 private:
00334   QListViewItemIterator mUpdateIterator;
00335 
00337   KPopupMenu* mPopup;
00338   int mUnreadPop;
00339   int mTotalPop;
00340 
00341   KMMainWidget *mMainWidget;
00342   bool mReloading;
00343   QMap<const KMFolder*, KMFolderTreeItem*> mFolderToItem;
00344 
00345   QTimer *mUpdateCountTimer;
00346   QMap<QString,KMFolder*> mFolderToUpdateCount;
00347 
00349   KMMenuToFolder mMenuToFolder;
00350 };
00351 
00352 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys