update to work with new lock system, add protocol.* to build system
[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         KEY_GENERATION_FAILURE
34     };
35
36     static const QString Send; /* Send addres */
37     static const QString Receive; /* Receive address */
38
39     /* Overridden methods from QAbstractTableModel */
40     int rowCount(const QModelIndex &parent) const;
41     int columnCount(const QModelIndex &parent) const;
42     QVariant data(const QModelIndex &index, int role) const;
43     bool setData(const QModelIndex & index, const QVariant & value, int role);
44     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
45     QModelIndex index(int row, int column, const QModelIndex & parent) const;
46     bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
47     Qt::ItemFlags flags(const QModelIndex & index) const;
48
49     /* Add an address to the model.
50        Returns the added address on success, and an empty string otherwise.
51      */
52     QString addRow(const QString &type, const QString &label, const QString &address);
53
54     /* Update address list from core. Invalidates any indices.
55      */
56     void updateList();
57
58     /* Look up label for address in address book, if not found return empty string.
59      */
60     QString labelForAddress(const QString &address) const;
61
62     /* Look up row index of an address in the model.
63        Return -1 if not found.
64      */
65     int lookupAddress(const QString &address) const;
66
67     EditStatus getEditStatus() const { return editStatus; }
68
69 private:
70     WalletModel *walletModel;
71     CWallet *wallet;
72     AddressTablePriv *priv;
73     QStringList columns;
74     EditStatus editStatus;
75
76 signals:
77     void defaultAddressChanged(const QString &address);
78
79 public slots:
80     void update();
81 };
82
83 #endif // ADDRESSTABLEMODEL_H