summaryrefslogtreecommitdiffstats
path: root/mailnews/local/src/nsLocalUndoTxn.h
blob: 62f93f20a12615170368988a13d315ddd5f5fc0b (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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef nsLocalUndoTxn_h__
#define nsLocalUndoTxn_h__

#include "mozilla/Attributes.h"
#include "msgCore.h"
#include "nsIMsgFolder.h"
#include "nsMailboxService.h"
#include "nsMsgTxn.h"
#include "MailNewsTypes.h"
#include "nsTArray.h"
#include "nsCOMPtr.h"
#include "nsIUrlListener.h"
#include "nsIWeakReference.h"
#include "nsIWeakReferenceUtils.h"

class nsLocalUndoFolderListener;

class nsLocalMoveCopyMsgTxn : public nsIFolderListener, public nsMsgTxn
{
public:
    nsLocalMoveCopyMsgTxn();
    NS_DECL_ISUPPORTS_INHERITED
    NS_DECL_NSIFOLDERLISTENER

    // overloading nsITransaction methods
    NS_IMETHOD UndoTransaction(void) override;
    NS_IMETHOD RedoTransaction(void) override;

    // helper
    nsresult AddSrcKey(nsMsgKey aKey);
    nsresult AddSrcStatusOffset(uint32_t statusOffset);
    nsresult AddDstKey(nsMsgKey aKey);
    nsresult AddDstMsgSize(uint32_t msgSize);
    nsresult SetSrcFolder(nsIMsgFolder* srcFolder);
    nsresult GetSrcIsImap(bool *isImap);
    nsresult SetDstFolder(nsIMsgFolder* dstFolder);
    nsresult Init(nsIMsgFolder* srcFolder,
                  nsIMsgFolder* dstFolder, bool isMove);
    nsresult UndoImapDeleteFlag(nsIMsgFolder* aFolder,
                                nsTArray<nsMsgKey>& aKeyArray,
                                bool deleteFlag);
    nsresult UndoTransactionInternal();
    // If the store using this undo transaction can "undelete" a message,
    // it will call this function on the transaction; This makes undo/redo
    // easy because message keys don't change after undo/redo. Otherwise,
    // we need to adjust the src or dst keys after every undo/redo action
    // to note the new keys.
    void SetCanUndelete(bool canUndelete) {m_canUndelete = canUndelete;}

private:
    virtual ~nsLocalMoveCopyMsgTxn();
    nsWeakPtr m_srcFolder;
    nsTArray<nsMsgKey> m_srcKeyArray; // used when src is local or imap
    nsTArray<uint32_t> m_srcStatusOffsetArray; // used when src is local
    nsWeakPtr m_dstFolder;
    nsTArray<nsMsgKey> m_dstKeyArray;
    bool m_isMove;
    bool m_srcIsImap4;
    bool m_canUndelete;
    nsTArray<uint32_t> m_dstSizeArray;
    bool m_undoing; // if false, re-doing
    uint32_t m_numHdrsCopied;
    nsTArray<nsCString> m_copiedMsgIds;
    nsLocalUndoFolderListener *mUndoFolderListener;
};

class nsLocalUndoFolderListener : public nsIFolderListener
{
public:
  NS_DECL_ISUPPORTS
  NS_DECL_NSIFOLDERLISTENER

  nsLocalUndoFolderListener(nsLocalMoveCopyMsgTxn *aTxn, nsIMsgFolder *aFolder);

private:
  virtual ~nsLocalUndoFolderListener();
  nsLocalMoveCopyMsgTxn *mTxn;
  nsIMsgFolder *mFolder;
};

#endif