Wallet encryption part 2: ask passphrase when needed, add menu options
[novacoin.git] / src / qt / addresstablemodel.h
1 #ifndef ADDRESSTABLEMODEL_H
2 #define ADDRESSTABLEMODEL_H
3
4 #include <QAbstractTableModel>
5 #include <QStringList>
6
7 class AddressTablePriv;
8 class CWallet;
9 class WalletModel;
10
11 class AddressTableModel : public QAbstractTableModel
12 {
13     Q_OBJECT
14 public:
15     explicit AddressTableModel(CWallet *wallet, WalletModel *parent = 0);
16     ~AddressTableModel();
17
18     enum ColumnIndex {
19         Label = 0,   /* User specified label */
20         Address = 1  /* Bitcoin address */
21     };
22
23     enum RoleIndex {
24         TypeRole = Qt::UserRole
25     };
26
27     // Return status of last edit/insert operation
28     enum EditStatus {
29         OK,
30         INVALID_ADDRESS,
31         DUPLICATE_ADDRESS,
32         WALLET_UNLOCK_FAILURE
33     };
34
35     static const QString Send; /* Send addres */
36     static const QString Receive; /* Receive address */
37
38     /* Overridden methods from QAbstractTableModel */
39     int rowCount(const QModelIndex &parent) const;
40     int columnCount(const QModelIndex &parent) const;
41     QVariant data(const QModelIndex &index, int role) const;
42     bool setData(const QModelIndex & index, const QVariant & value, int role);
43     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
44     QModelIndex index(int row, int column, const QModelIndex & parent) const;
45     bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
46     Qt::ItemFlags flags(const QModelIndex & index) const;
47
48     /* Add an address to the model.
49        Returns the added address on success, and an empty string otherwise.
50      */
51     QString addRow(const QString &type, const QString &label, const QString &address);
52
53     /* Update address list from core. Invalidates any indices.
54      */
55     void updateList();
56
57     /* Look up label for address in address book, if not found return empty string.
58      */
59     QString labelForAddress(const QString &address) const;
60
61     /* Look up row index of an address in the model.
62        Return -1 if not found.
63      */
64     int lookupAddress(const QString &address) const;
65
66     EditStatus getEditStatus() const { return editStatus; }
67
68 private:
69     WalletModel *walletModel;
70     CWallet *wallet;
71     AddressTablePriv *priv;
72     QStringList columns;
73     EditStatus editStatus;
74
75 signals:
76     void defaultAddressChanged(const QString &address);
77
78 public slots:
79     void update();
80 };
81
82 #endif // ADDRESSTABLEMODEL_H