42974e3e1f9ba17511b35ca6562d46fc6f9c3e6d
[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 /**
12    Qt model of the address book in the core. This allows views to access and modify the address book.
13  */
14 class AddressTableModel : public QAbstractTableModel
15 {
16     Q_OBJECT
17 public:
18     explicit AddressTableModel(CWallet *wallet, WalletModel *parent = 0);
19     ~AddressTableModel();
20
21     enum ColumnIndex {
22         Label = 0,   /**< User specified label */
23         Address = 1  /**< Bitcoin address */
24     };
25
26     enum RoleIndex {
27         TypeRole = Qt::UserRole /**< Type of address (#Send or #Receive) */
28     };
29
30     /** Return status of edit/insert operation */
31     enum EditStatus {
32         OK,
33         INVALID_ADDRESS,   /**< Unparseable address */
34         DUPLICATE_ADDRESS,  /**< Address already in address book */
35         WALLET_UNLOCK_FAILURE, /**< Wallet could not be unlocked to create new receiving address */
36         KEY_GENERATION_FAILURE /**< Generating a new public key for a receiving address failed */
37     };
38
39     static const QString Send; /**< Specifies send address */
40     static const QString Receive; /**< Specifies receive address */
41
42     /** @name Methods overridden from QAbstractTableModel
43         @{*/
44     int rowCount(const QModelIndex &parent) const;
45     int columnCount(const QModelIndex &parent) const;
46     QVariant data(const QModelIndex &index, int role) const;
47     bool setData(const QModelIndex & index, const QVariant & value, int role);
48     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
49     QModelIndex index(int row, int column, const QModelIndex & parent) const;
50     bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
51     Qt::ItemFlags flags(const QModelIndex & index) const;
52     /*@}*/
53
54     /* Add an address to the model.
55        Returns the added address on success, and an empty string otherwise.
56      */
57     QString addRow(const QString &type, const QString &label, const QString &address);
58
59     /* Look up label for address in address book, if not found return empty string.
60      */
61     QString labelForAddress(const QString &address) const;
62
63     /* Look up row index of an address in the model.
64        Return -1 if not found.
65      */
66     int lookupAddress(const QString &address) const;
67
68     EditStatus getEditStatus() const { return editStatus; }
69
70 private:
71     WalletModel *walletModel;
72     CWallet *wallet;
73     AddressTablePriv *priv;
74     QStringList columns;
75     EditStatus editStatus;
76
77     /** Notify listeners that data changed. */
78     void emitDataChanged(int index);
79
80 signals:
81     void defaultAddressChanged(const QString &address);
82
83 public slots:
84     /* Update address list from core.
85      */
86     void updateEntry(const QString &address, const QString &label, bool isMine, int status);
87
88     friend class AddressTablePriv;
89 };
90
91 #endif // ADDRESSTABLEMODEL_H