Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show namespace in Manage Names tab #486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/qt/managenamespage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ void ManageNamesPage::contextualMenu(const QPoint &point)

void ManageNamesPage::onCopyNameAction()
{
GUIUtil::copyEntryData(ui->tableView, NameTableModel::Name);
GUIUtil::copyEntryData(ui->tableView, NameTableModel::Name, NameTableModel::BinaryRole);
}

void ManageNamesPage::onCopyValueAction()
{
GUIUtil::copyEntryData(ui->tableView, NameTableModel::Value);
GUIUtil::copyEntryData(ui->tableView, NameTableModel::Value, NameTableModel::BinaryRole);
}

void ManageNamesPage::onConfigureNameAction()
Expand All @@ -185,9 +185,9 @@ void ManageNamesPage::onConfigureNameAction()
return;

const QModelIndex &index = indexes.at(0);
const QString name = index.data(Qt::EditRole).toString();
const QString name = index.data(NameTableModel::BinaryRole).toString();
const std::string strName = name.toStdString();
const QString initValue = index.sibling(index.row(), NameTableModel::Value).data(Qt::EditRole).toString();
const QString initValue = index.sibling(index.row(), NameTableModel::Value).data(NameTableModel::BinaryRole).toString();

ConfigureNameDialog dlg(platformStyle, name, initValue, this);
dlg.setModel(walletModel);
Expand Down Expand Up @@ -220,7 +220,7 @@ void ManageNamesPage::onRenewNameAction()
{
const QString name = indexes.at(0).data(Qt::EditRole).toString();

msg = tr ("Are you sure you want to renew the name <b>%1</b>?")
msg = tr ("Are you sure you want to renew the <b>%1</b>?")
.arg (GUIUtil::HtmlEscape (name));
title = tr ("Confirm name renewal");
}
Expand All @@ -243,7 +243,7 @@ void ManageNamesPage::onRenewNameAction()

for (const QModelIndex& index : indexes)
{
const QString name = index.data(Qt::EditRole).toString();
const QString name = index.data(NameTableModel::BinaryRole).toString();

const QString err_msg = model->renew(name);
if (!err_msg.isEmpty() && err_msg != "ABORTED")
Expand Down
46 changes: 43 additions & 3 deletions src/qt/nametablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <qt/clientmodel.h>
#include <qt/transactiontablemodel.h>
#include <qt/walletmodel.h>

#include <names/applications.h>
#include <names/encoding.h>
#include <univalue.h>
#include <wallet/wallet.h>

Expand Down Expand Up @@ -410,16 +413,42 @@ QVariant NameTableModel::data(const QModelIndex &index, int role) const

NameTableEntry *rec = static_cast<NameTableEntry*>(index.internalPointer());

// TODO: implement Qt::ForegroudRole for font color styling for states?
// TODO: implement Qt::ForegroundRole for font color styling for states?
// TODO: implement Qt::ToolTipRole show name status on tooltip
if(role == Qt::DisplayRole || role == Qt::EditRole)
{
switch(index.column())
{
case Name:
return rec->name;
{
NameNamespace ns = NamespaceFromName(rec->name.toStdString());
std::string strDesc = DescFromName(rec->name.toStdString(), ns);
QString desc = QString::fromStdString(strDesc);

switch(ns)
{
case NameNamespace::Domain:
return tr("Domain %1").arg(desc);
case NameNamespace::DomainData:
return tr("Domain data %1").arg(desc);
case NameNamespace::Identity:
return tr("Identity %1").arg(desc);
case NameNamespace::IdentityData:
return tr("Identity data %1").arg(desc);
case NameNamespace::NonStandard:
return tr("Non-standard name %1").arg(desc);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, I remember already seeing code like this, but I can't find it in the current codebase. Was that just another PR or am I simply mistaken here? Of course if we already have a switch to generate text representations, we should reuse it, but seems we don't, so this is fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's something mildly similar in transactiontablemodel.cpp, but it's for generating a text representation of the namespace without the rest of the name. That might be what you were thinking of?

} // no default case, so the compiler can warn about missing cases
assert(false);
}
case Value:
return rec->value;
{
// TODO: Refactor this function and EncodeNameForMessage to avoid double conversion
std::string strValue = rec->value.toStdString();
const valtype vtValue = valtype (strValue.begin (), strValue.end ());
std::string encodedValue = EncodeNameForMessage(vtValue);

return QString::fromStdString(encodedValue);
}
case ExpiresIn:
return rec->expiresIn;
case NameStatus:
Expand All @@ -430,6 +459,17 @@ QVariant NameTableModel::data(const QModelIndex &index, int role) const
if(role == Qt::TextAlignmentRole)
return column_alignments[index.column()];

if(role == BinaryRole)
{
switch(index.column())
{
case Name:
return rec->name;
case Value:
return rec->value;
}
}

return QVariant();
}

Expand Down
5 changes: 5 additions & 0 deletions src/qt/nametablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class NameTableModel : public QAbstractTableModel
NameStatus = 3
};

enum RoleIndex {
/** Binary data corresponding to name/value */
BinaryRole = Qt::UserRole,
};

/** @name Methods overridden from QAbstractTableModel
@{*/
int rowCount(const QModelIndex &parent = QModelIndex()) const;
Expand Down
Loading