Skip to content

Commit

Permalink
(WIP) Namecoin: Add Renew to Qt GUI context menu
Browse files Browse the repository at this point in the history
Depends on #353, do not merge this until that PR is merged and this PR
is rebased.

Based on namecoin#187 by Brandon
Roberts.
  • Loading branch information
JeremyRand committed Oct 22, 2020
1 parent 1e24765 commit cce3dc4
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/qt/forms/managenamespage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ to the network and creates a pending name_firstupdate transaction.</string>
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
Expand Down
51 changes: 51 additions & 0 deletions src/qt/managenamespage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ ManageNamesPage::ManageNamesPage(const PlatformStyle *platformStyle, QWidget *pa
// Context menu actions
QAction *copyNameAction = new QAction(tr("Copy &Name"), this);
QAction *copyValueAction = new QAction(tr("Copy &Value"), this);
QAction *renewNameAction = new QAction(tr("&Renew Names"), this);

// Build context menu
contextMenu = new QMenu();
contextMenu->addAction(copyNameAction);
contextMenu->addAction(copyValueAction);
contextMenu->addAction(renewNameAction);

// Connect signals for context menu actions
connect(copyNameAction, &QAction::triggered, this, &ManageNamesPage::onCopyNameAction);
connect(copyValueAction, &QAction::triggered, this, &ManageNamesPage::onCopyValueAction);
connect(renewNameAction, &QAction::triggered, this, &ManageNamesPage::onRenewNameAction);

connect(ui->tableView, &QTableView::customContextMenuRequested, this, &ManageNamesPage::contextualMenu);
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
Expand Down Expand Up @@ -112,6 +115,54 @@ void ManageNamesPage::onCopyValueAction()
GUIUtil::copyEntryData(ui->tableView, NameTableModel::Value);
}

void ManageNamesPage::onRenewNameAction()
{
QModelIndexList indexes = GUIUtil::getEntryData(ui->tableView, NameTableModel::Name);

if (indexes.isEmpty())
return;

QString msg;
QString title;

if (indexes.size() == 1)
{
const QString &name = indexes.at(0).data(Qt::EditRole).toString();

msg = tr ("Are you sure you want to renew the name <b>%1</b>?")
.arg (GUIUtil::HtmlEscape (name));
title = tr ("Confirm name renewal");
}
else
{
msg = tr ("Are you sure you want to renew multiple names simultaneously? This will reveal common ownership of the renewed names (bad for anonymity).");
title = tr ("Confirm multiple name renewal");
}

QMessageBox::StandardButton res;
res = QMessageBox::question (this, title, msg,
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Cancel);
if (res != QMessageBox::Yes)
return;

WalletModel::UnlockContext ctx(walletModel->requestUnlock ());
if (!ctx.isValid ())
return;

for (QModelIndexList::iterator i = indexes.begin(); i != indexes.end(); i++)
{
const QString &name = i->data(Qt::EditRole).toString();

const QString err_msg = model->renew(name);
if (!err_msg.isEmpty() && err_msg != "ABORTED")
{
QMessageBox::critical(this, tr("Name renew error"), err_msg);
return;
}
}
}

void ManageNamesPage::exportClicked()
{
// CSV is currently the only supported format
Expand Down
1 change: 1 addition & 0 deletions src/qt/managenamespage.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private Q_SLOTS:

void onCopyNameAction();
void onCopyValueAction();
void onRenewNameAction();
};

#endif // MANAGENAMESPAGE_H
23 changes: 23 additions & 0 deletions src/qt/nametablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,26 @@ NameTableModel::emitDataChanged(int idx)
//emit
dataChanged(index(idx, 0), index(idx, columns.length()-1));
}

QString NameTableModel::renew(const QString &name) const
{
std::string strName = name.toStdString();
LogPrintf ("wallet attempting name_update: name=%s\n", strName);

UniValue params(UniValue::VOBJ);
params.pushKV ("name", strName);

std::string walletURI = ("/wallet/" + walletModel->getWalletName()).toStdString();

UniValue res;
try {
res = walletModel->node().executeRpc("name_update", params, walletURI);
}
catch (const UniValue& e) {
UniValue message = find_value( e, "message");
std::string errorStr = message.get_str();
LogPrintf ("name_update error: %s\n", errorStr);
return QString::fromStdString(errorStr);
}
return tr ("");
}
2 changes: 2 additions & 0 deletions src/qt/nametablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class NameTableModel : public QAbstractTableModel
Qt::ItemFlags flags(const QModelIndex &index) const;
/*@}*/

QString renew(const QString &name) const;

private:
WalletModel *walletModel;
std::unique_ptr<interfaces::Handler> m_handler_transaction_changed;
Expand Down

0 comments on commit cce3dc4

Please sign in to comment.