mirror of
https://git.wownero.com/wowlet/wowlet.git
synced 2024-08-15 01:03:14 +00:00
Merge pull request 'Contacts: disallow duplicates' (#254) from tobtoht/feather:contacts_duplicates into master
Reviewed-on: https://git.wownero.com/feather/feather/pulls/254
This commit is contained in:
commit
b51e1f3b0c
6 changed files with 55 additions and 32 deletions
|
@ -5,17 +5,17 @@
|
||||||
#include "ui_contactswidget.h"
|
#include "ui_contactswidget.h"
|
||||||
#include "dialog/contactsdialog.h"
|
#include "dialog/contactsdialog.h"
|
||||||
#include "model/ModelUtils.h"
|
#include "model/ModelUtils.h"
|
||||||
#include "utils/utils.h"
|
#include "mainwindow.h"
|
||||||
|
#include "libwalletqt/AddressBook.h"
|
||||||
|
|
||||||
#include <QClipboard>
|
#include <QMessageBox>
|
||||||
#include <QDebug>
|
|
||||||
#include <QKeyEvent>
|
|
||||||
|
|
||||||
ContactsWidget::ContactsWidget(QWidget *parent) :
|
ContactsWidget::ContactsWidget(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::ContactsWidget)
|
ui(new Ui::ContactsWidget)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
m_ctx = MainWindow::getContext();
|
||||||
|
|
||||||
// header context menu
|
// header context menu
|
||||||
ui->contacts->header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
ui->contacts->header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
@ -28,15 +28,16 @@ ContactsWidget::ContactsWidget(QWidget *parent) :
|
||||||
// context menu
|
// context menu
|
||||||
ui->contacts->setContextMenuPolicy(Qt::CustomContextMenu);
|
ui->contacts->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
m_contextMenu = new QMenu(ui->contacts);
|
m_contextMenu = new QMenu(ui->contacts);
|
||||||
m_contextMenu->addAction(QIcon(":/assets/images/person.svg"), "New contact", this, &ContactsWidget::newContact);
|
m_contextMenu->addAction(QIcon(":/assets/images/person.svg"), "New contact", [this]{
|
||||||
|
this->newContact();
|
||||||
|
});
|
||||||
|
|
||||||
// row context menu
|
// row context menu
|
||||||
m_rowMenu = new QMenu(ui->contacts);
|
m_rowMenu = new QMenu(ui->contacts);
|
||||||
m_rowMenu->addAction(QIcon(":/assets/images/copy.png"), "Copy address", this, &ContactsWidget::copyAddress);
|
m_rowMenu->addAction(QIcon(":/assets/images/copy.png"), "Copy address", this, &ContactsWidget::copyAddress);
|
||||||
m_rowMenu->addAction(QIcon(":/assets/images/copy.png"), "Copy name", this, &ContactsWidget::copyName);
|
m_rowMenu->addAction(QIcon(":/assets/images/copy.png"), "Copy name", this, &ContactsWidget::copyName);
|
||||||
m_rowMenu->addAction(QIcon(":/assets/images/appicons/128x128.png"), "Pay to", this, &ContactsWidget::payTo);
|
m_rowMenu->addAction("Pay to", this, &ContactsWidget::payTo);
|
||||||
m_deleteEntryAction = m_rowMenu->addAction("Delete", this, &ContactsWidget::deleteContact);
|
m_rowMenu->addAction("Delete", this, &ContactsWidget::deleteContact);
|
||||||
|
|
||||||
connect(ui->contacts, &QTreeView::customContextMenuRequested, [=](const QPoint & point){
|
connect(ui->contacts, &QTreeView::customContextMenuRequested, [=](const QPoint & point){
|
||||||
QModelIndex index = ui->contacts->indexAt(point);
|
QModelIndex index = ui->contacts->indexAt(point);
|
||||||
|
@ -95,16 +96,44 @@ void ContactsWidget::showHeaderMenu(const QPoint& position)
|
||||||
m_headerMenu->exec(QCursor::pos());
|
m_headerMenu->exec(QCursor::pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsWidget::newContact()
|
void ContactsWidget::newContact(QString address, QString name)
|
||||||
{
|
{
|
||||||
auto * dialog = new ContactsDialog(this);
|
auto * dialog = new ContactsDialog(this, address, name);
|
||||||
int ret = dialog->exec();
|
int ret = dialog->exec();
|
||||||
if (!ret) return;
|
if (!ret) return;
|
||||||
|
|
||||||
QString address = dialog->getAddress();
|
address = dialog->getAddress();
|
||||||
QString name = dialog->getName();
|
name = dialog->getName();
|
||||||
|
|
||||||
emit addContact(address, name);
|
bool addressValid = WalletManager::addressValid(address, m_ctx->currentWallet->nettype());
|
||||||
|
if (!addressValid) {
|
||||||
|
QMessageBox::warning(this, "Invalid address", "Invalid address");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int num_addresses = m_ctx->currentWallet->addressBook()->count();
|
||||||
|
QString address_entry;
|
||||||
|
QString name_entry;
|
||||||
|
for (int i=0; i<num_addresses; i++) {
|
||||||
|
m_ctx->currentWallet->addressBook()->getRow(i, [&address_entry, &name_entry](const AddressBookInfo &entry){
|
||||||
|
address_entry = entry.address();
|
||||||
|
name_entry = entry.description();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (address == address_entry) {
|
||||||
|
QMessageBox::warning(this, "Unable to add contact", "Duplicate address");
|
||||||
|
ui->contacts->setCurrentIndex(m_model->index(i,0)); // Highlight duplicate address
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (name == name_entry) {
|
||||||
|
QMessageBox::warning(this, "Unable to add contact", "Duplicate label");
|
||||||
|
this->newContact(address, name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ctx->currentWallet->addressBook()->addRow(address, "", name);
|
||||||
|
m_ctx->storeWallet();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsWidget::deleteContact()
|
void ContactsWidget::deleteContact()
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "model/AddressBookModel.h"
|
#include "model/AddressBookModel.h"
|
||||||
#include "model/AddressBookProxyModel.h"
|
#include "model/AddressBookProxyModel.h"
|
||||||
|
#include "appcontext.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
@ -21,29 +22,28 @@ class ContactsWidget : public QWidget
|
||||||
public:
|
public:
|
||||||
explicit ContactsWidget(QWidget *parent = nullptr);
|
explicit ContactsWidget(QWidget *parent = nullptr);
|
||||||
void setModel(AddressBookModel * model);
|
void setModel(AddressBookModel * model);
|
||||||
~ContactsWidget();
|
~ContactsWidget() override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void copyAddress();
|
void copyAddress();
|
||||||
void copyName();
|
void copyName();
|
||||||
void payTo();
|
void payTo();
|
||||||
void newContact();
|
void newContact(QString address = "", QString name = "");
|
||||||
void deleteContact();
|
void deleteContact();
|
||||||
void setShowFullAddresses(bool show);
|
void setShowFullAddresses(bool show);
|
||||||
void setSearchFilter(const QString &filter);
|
void setSearchFilter(const QString &filter);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void addContact(QString &address, QString &name);
|
|
||||||
void fillAddress(QString &address);
|
void fillAddress(QString &address);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void showHeaderMenu(const QPoint& position);
|
void showHeaderMenu(const QPoint &position);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ContactsWidget *ui;
|
Ui::ContactsWidget *ui;
|
||||||
|
AppContext *m_ctx;
|
||||||
|
|
||||||
QAction *m_showFullAddressesAction;
|
QAction *m_showFullAddressesAction;
|
||||||
QAction *m_deleteEntryAction;
|
|
||||||
QMenu *m_rowMenu;
|
QMenu *m_rowMenu;
|
||||||
QMenu *m_contextMenu;
|
QMenu *m_contextMenu;
|
||||||
QMenu *m_headerMenu;
|
QMenu *m_headerMenu;
|
||||||
|
|
|
@ -4,13 +4,19 @@
|
||||||
#include "ui_contactsdialog.h"
|
#include "ui_contactsdialog.h"
|
||||||
#include "contactsdialog.h"
|
#include "contactsdialog.h"
|
||||||
|
|
||||||
ContactsDialog::ContactsDialog(QWidget *parent)
|
ContactsDialog::ContactsDialog(QWidget *parent, const QString &address, const QString &name)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, ui(new Ui::ContactsDialog)
|
, ui(new Ui::ContactsDialog)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setMinimumWidth(400);
|
setMinimumWidth(400);
|
||||||
|
|
||||||
|
ui->lineEdit_address->setText(address);
|
||||||
|
ui->lineEdit_name->setText(name);
|
||||||
|
if (!name.isEmpty()) {
|
||||||
|
ui->lineEdit_name->setFocus();
|
||||||
|
}
|
||||||
|
|
||||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, [&](){
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, [&](){
|
||||||
m_address = ui->lineEdit_address->text();
|
m_address = ui->lineEdit_address->text();
|
||||||
m_name = ui->lineEdit_name->text();
|
m_name = ui->lineEdit_name->text();
|
||||||
|
|
|
@ -15,7 +15,7 @@ class ContactsDialog : public QDialog
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ContactsDialog(QWidget *parent = nullptr);
|
explicit ContactsDialog(QWidget *parent = nullptr, const QString &address = "", const QString &name = "");
|
||||||
~ContactsDialog() override;
|
~ContactsDialog() override;
|
||||||
|
|
||||||
QString getAddress();
|
QString getAddress();
|
||||||
|
|
|
@ -289,7 +289,6 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
|
||||||
connect(ui->historyWidget, &HistoryWidget::resendTransaction, this, &MainWindow::onResendTransaction);
|
connect(ui->historyWidget, &HistoryWidget::resendTransaction, this, &MainWindow::onResendTransaction);
|
||||||
|
|
||||||
// Contacts
|
// Contacts
|
||||||
connect(ui->contactWidget, &ContactsWidget::addContact, this, &MainWindow::onAddContact);
|
|
||||||
connect(ui->contactWidget, &ContactsWidget::fillAddress, ui->sendWidget, &SendWidget::fillAddress);
|
connect(ui->contactWidget, &ContactsWidget::fillAddress, ui->sendWidget, &SendWidget::fillAddress);
|
||||||
|
|
||||||
// Open alias
|
// Open alias
|
||||||
|
@ -1055,16 +1054,6 @@ void MainWindow::onResendTransaction(const QString &txid) {
|
||||||
dialog->deleteLater();
|
dialog->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onAddContact(const QString &address, const QString &name) {
|
|
||||||
bool addressValid = WalletManager::addressValid(address, m_ctx->currentWallet->nettype());
|
|
||||||
if (!addressValid)
|
|
||||||
QMessageBox::warning(this, "Invalid address", "Invalid address");
|
|
||||||
else {
|
|
||||||
m_ctx->currentWallet->addressBook()->addRow(address, "", name);
|
|
||||||
m_ctx->storeWallet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::importContacts() {
|
void MainWindow::importContacts() {
|
||||||
const QString targetFile = QFileDialog::getOpenFileName(this, "Import CSV file", QDir::homePath(), "CSV Files (*.csv)");
|
const QString targetFile = QFileDialog::getOpenFileName(this, "Import CSV file", QDir::homePath(), "CSV Files (*.csv)");
|
||||||
if(targetFile.isEmpty()) return;
|
if(targetFile.isEmpty()) return;
|
||||||
|
|
|
@ -118,7 +118,6 @@ public slots:
|
||||||
void onWalletOpenPasswordRequired(bool invalidPassword, const QString &path);
|
void onWalletOpenPasswordRequired(bool invalidPassword, const QString &path);
|
||||||
void onViewOnBlockExplorer(const QString &txid);
|
void onViewOnBlockExplorer(const QString &txid);
|
||||||
void onResendTransaction(const QString &txid);
|
void onResendTransaction(const QString &txid);
|
||||||
void onAddContact(const QString &address, const QString &name);
|
|
||||||
void importContacts();
|
void importContacts();
|
||||||
void showRestoreHeightDialog();
|
void showRestoreHeightDialog();
|
||||||
void importTransaction();
|
void importTransaction();
|
||||||
|
|
Loading…
Reference in a new issue