1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef nsLocalUndoTxn_h__
7 #define nsLocalUndoTxn_h__
8 
9 #include "mozilla/Attributes.h"
10 #include "msgCore.h"
11 #include "nsIMsgFolder.h"
12 #include "nsMailboxService.h"
13 #include "nsMsgTxn.h"
14 #include "MailNewsTypes.h"
15 #include "nsTArray.h"
16 #include "nsCOMPtr.h"
17 #include "nsIFolderListener.h"
18 #include "nsIWeakReferenceUtils.h"
19 
20 class nsLocalUndoFolderListener;
21 
22 class nsLocalMoveCopyMsgTxn : public nsIFolderListener, public nsMsgTxn {
23  public:
24   nsLocalMoveCopyMsgTxn();
25   NS_DECL_ISUPPORTS_INHERITED
26   NS_DECL_NSIFOLDERLISTENER
27 
28   // overloading nsITransaction methods
29   NS_IMETHOD UndoTransaction(void) override;
30   NS_IMETHOD RedoTransaction(void) override;
31 
32   // helper
33   nsresult AddSrcKey(nsMsgKey aKey);
34   nsresult AddSrcStatusOffset(uint32_t statusOffset);
35   nsresult AddDstKey(nsMsgKey aKey);
36   nsresult AddDstMsgSize(uint32_t msgSize);
37   nsresult SetSrcFolder(nsIMsgFolder* srcFolder);
38   nsresult GetSrcIsImap(bool* isImap);
39   nsresult SetDstFolder(nsIMsgFolder* dstFolder);
40   nsresult Init(nsIMsgFolder* srcFolder, nsIMsgFolder* dstFolder, bool isMove);
41   nsresult UndoImapDeleteFlag(nsIMsgFolder* aFolder,
42                               nsTArray<nsMsgKey>& aKeyArray, bool deleteFlag);
43   nsresult UndoTransactionInternal();
44   // If the store using this undo transaction can "undelete" a message,
45   // it will call this function on the transaction; This makes undo/redo
46   // easy because message keys don't change after undo/redo. Otherwise,
47   // we need to adjust the src or dst keys after every undo/redo action
48   // to note the new keys.
SetCanUndelete(bool canUndelete)49   void SetCanUndelete(bool canUndelete) { m_canUndelete = canUndelete; }
50 
51  private:
52   virtual ~nsLocalMoveCopyMsgTxn();
53   nsWeakPtr m_srcFolder;
54   nsTArray<nsMsgKey> m_srcKeyArray;           // used when src is local or imap
55   nsTArray<uint32_t> m_srcStatusOffsetArray;  // used when src is local
56   nsWeakPtr m_dstFolder;
57   nsTArray<nsMsgKey> m_dstKeyArray;
58   bool m_isMove;
59   bool m_srcIsImap4;
60   bool m_canUndelete;
61   nsTArray<uint32_t> m_dstSizeArray;
62   bool m_undoing;  // if false, re-doing
63   uint32_t m_numHdrsCopied;
64   nsTArray<nsCString> m_copiedMsgIds;
65   nsLocalUndoFolderListener* mUndoFolderListener;
66 };
67 
68 class nsLocalUndoFolderListener : public nsIFolderListener {
69  public:
70   NS_DECL_ISUPPORTS
71   NS_DECL_NSIFOLDERLISTENER
72 
73   nsLocalUndoFolderListener(nsLocalMoveCopyMsgTxn* aTxn, nsIMsgFolder* aFolder);
74 
75  private:
76   virtual ~nsLocalUndoFolderListener();
77   nsLocalMoveCopyMsgTxn* mTxn;
78   nsIMsgFolder* mFolder;
79 };
80 
81 #endif
82