]>
Commit | Line | Data |
---|---|---|
13740b7e WL |
1 | #ifndef ADDRESSTABLEMODEL_H |
2 | #define ADDRESSTABLEMODEL_H | |
3 | ||
4 | #include <QAbstractTableModel> | |
f96681c5 WL |
5 | #include <QStringList> |
6 | ||
7 | class AddressTablePriv; | |
e8ef3da7 | 8 | class CWallet; |
a5e6d723 | 9 | class WalletModel; |
13740b7e | 10 | |
af836ad5 WL |
11 | /** |
12 | Qt model of the address book in the core. This allows views to access and modify the address book. | |
13 | */ | |
13740b7e WL |
14 | class AddressTableModel : public QAbstractTableModel |
15 | { | |
16 | Q_OBJECT | |
17 | public: | |
a5e6d723 | 18 | explicit AddressTableModel(CWallet *wallet, WalletModel *parent = 0); |
f96681c5 | 19 | ~AddressTableModel(); |
13740b7e | 20 | |
48208883 | 21 | enum ColumnIndex { |
af836ad5 WL |
22 | Label = 0, /**< User specified label */ |
23 | Address = 1 /**< Bitcoin address */ | |
48208883 | 24 | }; |
b8e302eb | 25 | |
a5e6d723 | 26 | enum RoleIndex { |
af836ad5 | 27 | TypeRole = Qt::UserRole /**< Type of address (#Send or #Receive) */ |
a5e6d723 WL |
28 | }; |
29 | ||
af836ad5 | 30 | /** Return status of edit/insert operation */ |
a5e6d723 | 31 | enum EditStatus { |
b7bcaf94 | 32 | OK, |
af836ad5 WL |
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 */ | |
a5e6d723 | 37 | }; |
8968bf2e | 38 | |
af836ad5 WL |
39 | static const QString Send; /**< Specifies send address */ |
40 | static const QString Receive; /**< Specifies receive address */ | |
b8e302eb | 41 | |
af836ad5 WL |
42 | /** @name Methods overridden from QAbstractTableModel |
43 | @{*/ | |
b8e302eb WL |
44 | int rowCount(const QModelIndex &parent) const; |
45 | int columnCount(const QModelIndex &parent) const; | |
46 | QVariant data(const QModelIndex &index, int role) const; | |
44384a46 | 47 | bool setData(const QModelIndex & index, const QVariant & value, int role); |
b8e302eb | 48 | QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
ef1b844e | 49 | QModelIndex index(int row, int column, const QModelIndex & parent) const; |
48208883 | 50 | bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); |
154e25ff | 51 | Qt::ItemFlags flags(const QModelIndex & index) const; |
af836ad5 | 52 | /*@}*/ |
48208883 WL |
53 | |
54 | /* Add an address to the model. | |
2547f1f7 | 55 | Returns the added address on success, and an empty string otherwise. |
48208883 | 56 | */ |
ebff5c40 | 57 | QString addRow(const QString &type, const QString &label, const QString &address); |
ef1b844e | 58 | |
48208883 WL |
59 | /* Update address list from core. Invalidates any indices. |
60 | */ | |
ef1b844e | 61 | void updateList(); |
b9e80983 | 62 | |
51d7cc07 WL |
63 | /* Look up label for address in address book, if not found return empty string. |
64 | */ | |
65 | QString labelForAddress(const QString &address) const; | |
66 | ||
67 | /* Look up row index of an address in the model. | |
68 | Return -1 if not found. | |
69 | */ | |
70 | int lookupAddress(const QString &address) const; | |
71 | ||
a5e6d723 WL |
72 | EditStatus getEditStatus() const { return editStatus; } |
73 | ||
f96681c5 | 74 | private: |
a5e6d723 | 75 | WalletModel *walletModel; |
e8ef3da7 | 76 | CWallet *wallet; |
f96681c5 WL |
77 | AddressTablePriv *priv; |
78 | QStringList columns; | |
a5e6d723 | 79 | EditStatus editStatus; |
b9e80983 | 80 | |
13740b7e | 81 | signals: |
b9e80983 | 82 | void defaultAddressChanged(const QString &address); |
13740b7e WL |
83 | |
84 | public slots: | |
b9e80983 | 85 | void update(); |
13740b7e WL |
86 | }; |
87 | ||
88 | #endif // ADDRESSTABLEMODEL_H |