Skip to content

Commit

Permalink
Namecoin / Qt: Show namespace in Manage Names tab
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRand committed Jan 3, 2022
1 parent 753920c commit 6966912
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/qt/managenamespage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,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 @@ -169,9 +169,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 @@ -204,7 +204,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 @@ -227,7 +227,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);
} // 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 @@ -40,6 +40,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

0 comments on commit 6966912

Please sign in to comment.