summaryrefslogtreecommitdiffstats
path: root/kmail/kmfoldertree.h
blob: 11e7584f4837d974cf1a540d44a82e48520c45da (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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/* -*- mode: C++ -*-
   This file is part of the KDE libraries

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

#include "foldertreebase.h"

#include <tdelocale.h>
#include <tdepimmacros.h>

#include <tqguardedptr.h>
#include <tqwidget.h>
#include <tqtimer.h>
#include <tqheader.h>

class TQDropEvent;
class TQPixmap;
class TQPainter;
class TQPopupMenu;
class TDEPopupMenu;
class KMFolder;
class KMFolderDir;
class KMFolderImap;
class KMFolderTree;
class KMAccount;
// duplication from kmcommands.h, to avoid the include
typedef TQMap<int,KMFolder*> KMMenuToFolder;
template <typename T> class TQGuardedPtr;

class KDE_EXPORT KMFolderTreeItem : public TQObject, public KFolderTreeItem
{
  Q_OBJECT
  
public:
  /** Construct a root item _without_ folder */
  KMFolderTreeItem( KFolderTree *parent, const TQString & name,
                    KFolderTreeItem::Protocol protocol=KFolderTreeItem::NONE );

  /** Construct a root item _with_ folder */
  KMFolderTreeItem( KFolderTree *parent, const TQString & name,
                    KMFolder* folder );

  /** Construct a child item */
  KMFolderTreeItem( KFolderTreeItem* parent, const TQString & name,
                    KMFolder* folder );
  virtual ~KMFolderTreeItem();

  TQPixmap normalIcon( int size ) const;
  TQPixmap unreadIcon( int size ) const;

  void setNeedsRepaint( bool value ) { mNeedsRepaint = value; }
  bool needsRepaint() const { return mNeedsRepaint; }

  /** associated folder */
  KMFolder* folder() const { return mFolder; }
  TQListViewItem* parent() const { return KFolderTreeItem::parent(); }

  /** Adjust the unread count from the folder and update the
   * pixmaps accordingly. */
  void adjustUnreadCount( int newUnreadCount );

  /** dnd */
  virtual bool acceptDrag(TQDropEvent* e) const;

signals:
  /** Our icon changed */
  void iconChanged( KMFolderTreeItem * );
  /** Our name changed */
  void nameChanged( KMFolderTreeItem * );

public slots:
  void properties();
  void assignShortcut();
  void slotShowExpiryProperties();
  void slotIconsChanged();
  void slotNameChanged();
  void slotNoContentChanged();
  void updateCount();

protected:
  void init();
  KMFolder* mFolder;
  /** Returns true when top-level/account icons should be used */
  virtual bool useTopLevelIcon() const { return depth() == 0; }
  /** Returns the icon size. */
  virtual int iconSize() const { return 16; }

private:
  bool mNeedsRepaint;
};

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

class KMFolderTree : public KMail::FolderTreeBase
{
  Q_OBJECT
  

public:
  KMFolderTree( KMMainWidget *mainWidget, TQWidget *parent=0,
		const char *name=0 );

  /** Save config options */
  void writeConfig();

  /** Recusively add folders in a folder directory to a listview item. */
  virtual void addDirectory( KMFolderDir *fdir, KMFolderTreeItem* parent );

  /** create a folderlist */
  void createFolderList( TQStringList *str,
                         TQValueList<TQGuardedPtr<KMFolder> > *folders,
                         bool localFolders=true,
                         bool imapFolders=true,
                         bool dimapFolders=true,
                         bool searchFolders=false,
                         bool includeNoContent=true,
                         bool includeNoChildren=true );

  /** Read config options. */
  virtual void readConfig(void);

  /** Remove information about not existing folders from the config file */
  void cleanupConfigFile();

  /** Select the next folder with unread messages */
  void nextUnreadFolder(bool confirm);

  /** Check folder for unread messages (which isn't trash)*/
  bool checkUnreadFolder(KMFolderTreeItem* ftl, bool confirm);

  KMFolder *currentFolder() const;

  TQValueList<TQGuardedPtr<KMFolder> > selectedFolders();

  enum ColumnMode {unread=15, total=16, foldersize=17};

  /** toggles the unread and total columns on/off */
  void toggleColumn(int column, bool openFolders = false);

  /** Set the checked/unchecked state of the unread and total column
   *  in the popup correctly */
  virtual void updatePopup() const;

  /** Select the folder and make sure it's visible */
  void showFolder( KMFolder* );

  /** Valid actions for the folderToPopup method */
  enum MenuAction {
    CopyMessage,
    MoveMessage,
    CopyFolder,
    MoveFolder
  };

  /** Generate a popup menu that contains all folders that can have content */
  void folderToPopupMenu( MenuAction action, TQObject *receiver, KMMenuToFolder *,
      TQPopupMenu *menu, TQListViewItem *start = 0 );

signals:
  /** The selected folder has changed */
  void folderSelected(KMFolder*);

  /** The selected folder has changed to go to an unread message */
  void folderSelectedUnread( KMFolder * );

  /** The sync state of the _selected_ folder has changed */
  void syncStateChanged();

  /** unread/total/size column has changed */
  void columnsChanged();

  /** an icon of one of our folders changed */
  void iconChanged( KMFolderTreeItem * );

  /** the name of one of our folders changed */
  void nameChanged( KMFolderTreeItem * );

public slots:
  /** Get/refresh the folder tree */
  virtual void reload(bool openFolders = false);

  /** Select the next folder with unread messages */
  void nextUnreadFolder();

  /** Select the previous folder with unread messages */
  void prevUnreadFolder();

  /** Increment current folder */
  void incCurrentFolder();

  /** Decrement current folder */
  void decCurrentFolder();

  /** Select the current folder */
  void selectCurrentFolder();

  /** Executes delayed update of folder tree */
  void delayedUpdate();

  /** Make sure the given account is not selected because it is gone */
  void slotAccountRemoved(KMAccount*);

  /** Select the item and switch to the folder */
  void doFolderSelected(TQListViewItem *qlvi, bool keepSelection = false);

  /**
   * Reset current folder and all childs
   * If no item is given we take the current one
   * If startListing is true a folder listing is started
   */
  void slotResetFolderList( TQListViewItem* item = 0, bool startList = true );

  /** Create a child folder */
  void addChildFolder( KMFolder *folder = 0, TQWidget * parent = 0 );

  /** Copies the currently selected folder. */
  void copyFolder();

  /** Cuts the currently selected folder. */
  void cutFolder();

  /** Pastes a previously copied/cutted folder below the currently selected folder. */
  void pasteFolder();

  /** Reload the folder tree (using a single shot timer) */
  void delayedReload();

protected slots:
  //  void slotRMB(int, int);
  /** called by the folder-manager when the list of folders changed */
  void doFolderListChanged();

  /** called, when a folder has been deleted */
  void slotFolderRemoved(KMFolder *);

  /** called, when a folder has been moved or copied, successfully or not */
  void slotFolderMoveOrCopyOperationFinished();

  /** Updates the folder tree (delayed), causing a "blink" */
  void refresh();

  /** Open a folder */
  void openFolder();

  /** Expand an IMAP folder */
  void slotFolderExpanded( TQListViewItem * item );

  /** Tell the folder to refresh the contents on the next expansion */
  void slotFolderCollapsed( TQListViewItem * item );

  /** Check if the new name is valid and confirm the new name */
  void slotRenameFolder( TQListViewItem * item, int col, const TQString& text);

  /** Update the total and unread columns but delayed */
  void slotUpdateCountsDelayed(KMFolder * folder);
  void slotUpdateCountTimeout();
  void slotUpdateOneCount();

  /** slots for the unread/total/size-popup */
  void slotToggleUnreadColumn();
  void slotToggleTotalColumn();
  void slotToggleSizeColumn();

  void slotContextMenuRequested( TQListViewItem *, const TQPoint & );

  /** Fires a new-mail-check of the account that is accociated with currentItem */
  void slotCheckMail();

  void slotNewMessageToMailingList();

  /** For RMB move folder */
  virtual void moveSelectedToFolder( int menuId );
  /** For RMB copy folder */
  virtual void copySelectedToFolder( int menuId );

  /** Updates copy/cut/paste actions */
  void updateCopyActions();

  void slotSyncStateChanged();

protected:
  virtual void contentsMousePressEvent( TQMouseEvent *e );
  virtual void contentsMouseReleaseEvent(TQMouseEvent* me);

  /** Updates the number of unread messages for all folders */
  virtual void updateUnreadAll( );

  virtual void resizeEvent(TQResizeEvent*);

  /** Read/Save open/close state indicator for an item in folderTree list view */
  bool readIsListViewItemOpen(KMFolderTreeItem *fti);
  void writeIsListViewItemOpen(KMFolderTreeItem *fti);

  TQTimer mUpdateTimer;

  /** Drag and drop methods */
  void contentsDragEnterEvent( TQDragEnterEvent *e );
  void contentsDragMoveEvent( TQDragMoveEvent *e );
  void contentsDragLeaveEvent( TQDragLeaveEvent *e );
  void contentsDropEvent( TQDropEvent *e );
  virtual TQDragObject* dragObject();

  /** Drag and drop variables */
  TQListViewItem *oldCurrent, *oldSelected;
  TQListViewItem *dropItem;
  KMFolderTreeItem *mLastItem;
  TQTimer autoopen_timer;

  // filter some rmb-events
  bool eventFilter(TQObject*, TQEvent*);

  /** open ancestors and ensure item is visible  */
  void prepareItem( KMFolderTreeItem* );

  /** connect all signals */
  void connectSignals();

  /** Move or copy the folder @p source to @p destination. */
  void moveOrCopyFolder( TQValueList<TQGuardedPtr<KMFolder> > sources, KMFolder* destination, bool move=false );

private slots:
  void slotAddToFavorites();
  void slotUnhideLocalInbox();

private:
  /** total column */
  TQListViewItemIterator mUpdateIterator;

  /** popup for unread/total */
  TDEPopupMenu* mPopup;
  int mUnreadPop;
  int mTotalPop;
  int mSizePop;

  bool mReloading;
  TQValueList<TQGuardedPtr<KMFolder> > mCopySourceFolders;
  bool mCutFolder;

  TQTimer *mUpdateCountTimer;
  TQMap<TQString,KMFolder*> mFolderToUpdateCount;

  /** Map menu id into a folder */
  KMMenuToFolder mMenuToFolder;
};

#endif