]>
Commit | Line | Data |
---|---|---|
f914f1a7 | 1 | // Copyright (c) 2011-2013 The Bitcoin Core developers |
78253fcb | 2 | // Distributed under the MIT software license, see the accompanying |
e592d43f WL |
3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
4 | ||
84738627 PJ |
5 | #ifndef BITCOIN_QT_ADDRESSTABLEMODEL_H |
6 | #define BITCOIN_QT_ADDRESSTABLEMODEL_H | |
13740b7e WL |
7 | |
8 | #include <QAbstractTableModel> | |
f96681c5 WL |
9 | #include <QStringList> |
10 | ||
11 | class AddressTablePriv; | |
a5e6d723 | 12 | class WalletModel; |
13740b7e | 13 | |
51ed9ec9 BD |
14 | class CWallet; |
15 | ||
af836ad5 WL |
16 | /** |
17 | Qt model of the address book in the core. This allows views to access and modify the address book. | |
18 | */ | |
13740b7e WL |
19 | class AddressTableModel : public QAbstractTableModel |
20 | { | |
21 | Q_OBJECT | |
32af5266 | 22 | |
13740b7e | 23 | public: |
a5e6d723 | 24 | explicit AddressTableModel(CWallet *wallet, WalletModel *parent = 0); |
f96681c5 | 25 | ~AddressTableModel(); |
13740b7e | 26 | |
48208883 | 27 | enum ColumnIndex { |
af836ad5 WL |
28 | Label = 0, /**< User specified label */ |
29 | Address = 1 /**< Bitcoin address */ | |
48208883 | 30 | }; |
b8e302eb | 31 | |
a5e6d723 | 32 | enum RoleIndex { |
af836ad5 | 33 | TypeRole = Qt::UserRole /**< Type of address (#Send or #Receive) */ |
a5e6d723 WL |
34 | }; |
35 | ||
af836ad5 | 36 | /** Return status of edit/insert operation */ |
a5e6d723 | 37 | enum EditStatus { |
e6d23005 PK |
38 | OK, /**< Everything ok */ |
39 | NO_CHANGES, /**< No changes were made during edit operation */ | |
40 | INVALID_ADDRESS, /**< Unparseable address */ | |
41 | DUPLICATE_ADDRESS, /**< Address already in address book */ | |
42 | WALLET_UNLOCK_FAILURE, /**< Wallet could not be unlocked to create new receiving address */ | |
43 | KEY_GENERATION_FAILURE /**< Generating a new public key for a receiving address failed */ | |
a5e6d723 | 44 | }; |
8968bf2e | 45 | |
e6d23005 PK |
46 | static const QString Send; /**< Specifies send address */ |
47 | static const QString Receive; /**< Specifies receive address */ | |
b8e302eb | 48 | |
af836ad5 WL |
49 | /** @name Methods overridden from QAbstractTableModel |
50 | @{*/ | |
b8e302eb WL |
51 | int rowCount(const QModelIndex &parent) const; |
52 | int columnCount(const QModelIndex &parent) const; | |
53 | QVariant data(const QModelIndex &index, int role) const; | |
e6d23005 | 54 | bool setData(const QModelIndex &index, const QVariant &value, int role); |
b8e302eb | 55 | QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
e6d23005 PK |
56 | QModelIndex index(int row, int column, const QModelIndex &parent) const; |
57 | bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); | |
58 | Qt::ItemFlags flags(const QModelIndex &index) const; | |
af836ad5 | 59 | /*@}*/ |
48208883 WL |
60 | |
61 | /* Add an address to the model. | |
2547f1f7 | 62 | Returns the added address on success, and an empty string otherwise. |
48208883 | 63 | */ |
ebff5c40 | 64 | QString addRow(const QString &type, const QString &label, const QString &address); |
ef1b844e | 65 | |
51d7cc07 WL |
66 | /* Look up label for address in address book, if not found return empty string. |
67 | */ | |
68 | QString labelForAddress(const QString &address) const; | |
69 | ||
70 | /* Look up row index of an address in the model. | |
71 | Return -1 if not found. | |
72 | */ | |
73 | int lookupAddress(const QString &address) const; | |
74 | ||
a5e6d723 WL |
75 | EditStatus getEditStatus() const { return editStatus; } |
76 | ||
f96681c5 | 77 | private: |
a5e6d723 | 78 | WalletModel *walletModel; |
e8ef3da7 | 79 | CWallet *wallet; |
f96681c5 WL |
80 | AddressTablePriv *priv; |
81 | QStringList columns; | |
a5e6d723 | 82 | EditStatus editStatus; |
b9e80983 | 83 | |
0832c0d1 WL |
84 | /** Notify listeners that data changed. */ |
85 | void emitDataChanged(int index); | |
86 | ||
13740b7e | 87 | public slots: |
fe4a6550 | 88 | /* Update address list from core. |
98e61758 | 89 | */ |
dcd0b077 | 90 | void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status); |
0832c0d1 WL |
91 | |
92 | friend class AddressTablePriv; | |
13740b7e WL |
93 | }; |
94 | ||
84738627 | 95 | #endif // BITCOIN_QT_ADDRESSTABLEMODEL_H |