Skip to content

Commit 0152fab

Browse files
JeremyRandJeremy Rand
authored andcommitted
Namecoin / Qt: Show namespace in Manage Names tab
1 parent 763e0f5 commit 0152fab

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

src/qt/managenamespage.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ void ManageNamesPage::contextualMenu(const QPoint &point)
162162

163163
void ManageNamesPage::onCopyNameAction()
164164
{
165-
GUIUtil::copyEntryData(ui->tableView, NameTableModel::Name);
165+
GUIUtil::copyEntryData(ui->tableView, NameTableModel::Name, NameTableModel::BinaryRole);
166166
}
167167

168168
void ManageNamesPage::onCopyValueAction()
169169
{
170-
GUIUtil::copyEntryData(ui->tableView, NameTableModel::Value);
170+
GUIUtil::copyEntryData(ui->tableView, NameTableModel::Value, NameTableModel::BinaryRole);
171171
}
172172

173173
void ManageNamesPage::onConfigureNameAction()
@@ -185,9 +185,9 @@ void ManageNamesPage::onConfigureNameAction()
185185
return;
186186

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

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

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

244244
for (const QModelIndex& index : indexes)
245245
{
246-
const QString name = index.data(Qt::EditRole).toString();
246+
const QString name = index.data(NameTableModel::BinaryRole).toString();
247247

248248
const QString err_msg = model->renew(name);
249249
if (!err_msg.isEmpty() && err_msg != "ABORTED")

src/qt/nametablemodel.cpp

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include <qt/clientmodel.h>
55
#include <qt/transactiontablemodel.h>
66
#include <qt/walletmodel.h>
7+
8+
#include <names/applications.h>
9+
#include <names/encoding.h>
710
#include <univalue.h>
811
#include <wallet/wallet.h>
912

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

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

413-
// TODO: implement Qt::ForegroudRole for font color styling for states?
416+
// TODO: implement Qt::ForegroundRole for font color styling for states?
414417
// TODO: implement Qt::ToolTipRole show name status on tooltip
415418
if(role == Qt::DisplayRole || role == Qt::EditRole)
416419
{
417420
switch(index.column())
418421
{
419422
case Name:
420-
return rec->name;
423+
{
424+
NameNamespace ns = NamespaceFromName(rec->name.toStdString());
425+
std::string strDesc = DescFromName(rec->name.toStdString(), ns);
426+
QString desc = QString::fromStdString(strDesc);
427+
428+
switch(ns)
429+
{
430+
case NameNamespace::Domain:
431+
return tr("Domain %1").arg(desc);
432+
case NameNamespace::DomainData:
433+
return tr("Domain data %1").arg(desc);
434+
case NameNamespace::Identity:
435+
return tr("Identity %1").arg(desc);
436+
case NameNamespace::IdentityData:
437+
return tr("Identity data %1").arg(desc);
438+
case NameNamespace::NonStandard:
439+
return tr("Non-standard name %1").arg(desc);
440+
} // no default case, so the compiler can warn about missing cases
441+
assert(false);
442+
}
421443
case Value:
422-
return rec->value;
444+
{
445+
// TODO: Refactor this function and EncodeNameForMessage to avoid double conversion
446+
std::string strValue = rec->value.toStdString();
447+
const valtype vtValue = valtype (strValue.begin (), strValue.end ());
448+
std::string encodedValue = EncodeNameForMessage(vtValue);
449+
450+
return QString::fromStdString(encodedValue);
451+
}
423452
case ExpiresIn:
424453
return rec->expiresIn;
425454
case NameStatus:
@@ -430,6 +459,17 @@ QVariant NameTableModel::data(const QModelIndex &index, int role) const
430459
if(role == Qt::TextAlignmentRole)
431460
return column_alignments[index.column()];
432461

462+
if(role == BinaryRole)
463+
{
464+
switch(index.column())
465+
{
466+
case Name:
467+
return rec->name;
468+
case Value:
469+
return rec->value;
470+
}
471+
}
472+
433473
return QVariant();
434474
}
435475

src/qt/nametablemodel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ class NameTableModel : public QAbstractTableModel
4141
NameStatus = 3
4242
};
4343

44+
enum RoleIndex {
45+
/** Binary data corresponding to name/value */
46+
BinaryRole = Qt::UserRole,
47+
};
48+
4449
/** @name Methods overridden from QAbstractTableModel
4550
@{*/
4651
int rowCount(const QModelIndex &parent = QModelIndex()) const;

0 commit comments

Comments
 (0)