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 and #373, do not merge this until those are merged and
this PR is rebased.

TODO: Untested.

Based on namecoin#187 by Brandon
Roberts.
  • Loading branch information
JeremyRand committed Oct 18, 2020
1 parent a9df3e4 commit 02aad7d
Show file tree
Hide file tree
Showing 5 changed files with 83 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 @@ -32,15 +32,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 Name"), 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 @@ -120,6 +123,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 != items.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
28 changes: 28 additions & 0 deletions src/qt/nametablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,31 @@ NameTableModel::emitDataChanged(int idx)
//emit
dataChanged(index(idx, 0), index(idx, columns.length()-1));
}

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

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

util::Ref nameUpdateContext;
JSONRPCRequest nameUpdateRequest(nameUpdateContext);
nameUpdateRequest.URI = ("/wallet/" + walletModel->getWalletName()).toStdString();
nameUpdateRequest.strMethod = "name_update";
nameUpdateRequest.params = params;
nameUpdateRequest.fHelp = false;

UniValue res;
try {
res = tableRPC.execute(nameUpdateRequest);
}
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 02aad7d

Please sign in to comment.