forked from cryptonotefoundation/cryptonotewallet
/
AddressBookFrame.cpp
57 lines (44 loc) · 1.81 KB
/
AddressBookFrame.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2011-2015 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <QApplication>
#include <QClipboard>
#include "CurrencyAdapter.h"
#include "AddressBookModel.h"
#include "AddressBookFrame.h"
#include "MainWindow.h"
#include "NewAddressDialog.h"
#include "WalletEvents.h"
#include "ui_addressbookframe.h"
namespace WalletGui {
AddressBookFrame::AddressBookFrame(QWidget* _parent) : QFrame(_parent), m_ui(new Ui::AddressBookFrame) {
m_ui->setupUi(this);
m_ui->m_addressBookView->setModel(&AddressBookModel::instance());
connect(m_ui->m_addressBookView->selectionModel(), &QItemSelectionModel::currentChanged, this, &AddressBookFrame::currentAddressChanged);
}
AddressBookFrame::~AddressBookFrame() {
}
void AddressBookFrame::addClicked() {
NewAddressDialog dlg(&MainWindow::instance());
if (dlg.exec() == QDialog::Accepted) {
QString label = dlg.getLabel();
QString address = dlg.getAddress();
if (!CurrencyAdapter::instance().validateAddress(address)) {
QCoreApplication::postEvent(&MainWindow::instance(), new ShowMessageEvent(tr("Invalid address"), QtCriticalMsg));
return;
}
AddressBookModel::instance().addAddress(label, address);
}
}
void AddressBookFrame::copyClicked() {
QApplication::clipboard()->setText(m_ui->m_addressBookView->currentIndex().data(AddressBookModel::ROLE_ADDRESS).toString());
}
void AddressBookFrame::deleteClicked() {
int row = m_ui->m_addressBookView->currentIndex().row();
AddressBookModel::instance().removeAddress(row);
}
void AddressBookFrame::currentAddressChanged(const QModelIndex& _index) {
m_ui->m_copyAddressButton->setEnabled(_index.isValid());
m_ui->m_deleteAddressButton->setEnabled(_index.isValid());
}
}