Browse Source

WIP: Listed namespaces.

kevaview
Just Wonder 5 years ago
parent
commit
448f25f159
  1. 7
      src/Makefile.qt.include
  2. 20
      src/qt/forms/kevadialog.ui
  3. 77
      src/qt/forms/kevamynamespacesdialog.ui
  4. 20
      src/qt/kevadialog.cpp
  5. 1
      src/qt/kevadialog.h
  6. 53
      src/qt/kevamynamespacesdialog.cpp
  7. 42
      src/qt/kevamynamespacesdialog.h
  8. 149
      src/qt/kevanamespacemodel.cpp
  9. 79
      src/qt/kevanamespacemodel.h
  10. 66
      src/qt/walletmodel.cpp
  11. 5
      src/qt/walletmodel.h

7
src/Makefile.qt.include

@ -138,6 +138,7 @@ QT_FORMS_UI = \ @@ -138,6 +138,7 @@ QT_FORMS_UI = \
qt/forms/kevadialog.ui \
qt/forms/kevadetaildialog.ui \
qt/forms/kevanewnamespacedialog.ui \
qt/forms/kevamynamespacesdialog.ui \
qt/forms/debugwindow.ui \
qt/forms/sendcoinsdialog.ui \
qt/forms/sendcoinsentry.ui \
@ -177,8 +178,10 @@ QT_MOC_CPP = \ @@ -177,8 +178,10 @@ QT_MOC_CPP = \
qt/moc_receiverequestdialog.cpp \
qt/moc_recentrequeststablemodel.cpp \
qt/moc_kevatablemodel.cpp \
qt/moc_kevanamespacemodel.cpp \
qt/moc_kevadetaildialog.cpp \
qt/moc_kevanewnamespacedialog.cpp \
qt/moc_kevamynamespacesdialog.cpp \
qt/moc_rpcconsole.cpp \
qt/moc_sendcoinsdialog.cpp \
qt/moc_sendcoinsentry.cpp \
@ -267,8 +270,10 @@ BITCOIN_QT_H = \ @@ -267,8 +270,10 @@ BITCOIN_QT_H = \
qt/transactionview.h \
qt/kevadialog.h \
qt/kevatablemodel.h \
qt/kevanamespacemodel.h \
qt/kevadetaildialog.h \
qt/kevanewnamespacedialog.h \
qt/kevamynamespacesdialog.h \
qt/utilitydialog.h \
qt/walletframe.h \
qt/walletmodel.h \
@ -386,8 +391,10 @@ BITCOIN_QT_WALLET_CPP = \ @@ -386,8 +391,10 @@ BITCOIN_QT_WALLET_CPP = \
qt/transactionview.cpp \
qt/kevadialog.cpp \
qt/kevatablemodel.cpp \
qt/kevanamespacemodel.cpp \
qt/kevadetaildialog.cpp \
qt/kevanewnamespacedialog.cpp \
qt/kevamynamespacesdialog.cpp \
qt/walletframe.cpp \
qt/walletmodel.cpp \
qt/walletmodeltransaction.cpp \

20
src/qt/forms/kevadialog.ui

@ -123,6 +123,26 @@ @@ -123,6 +123,26 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="listNamespaces">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>List my namepsaces</string>
</property>
<property name="text">
<string>&amp;My Namespaces</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/editpaste</normaloff>:/icons/editpaste</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">

77
src/qt/forms/kevamynamespacesdialog.ui

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>KevaMyNamespacesDialog</class>
<widget class="QDialog" name="KevaMyNamespacesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">My Namespaces</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableView" name="namespaceView">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="tabKeyNavigation">
<bool>false</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>KevaMyNamespacesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>KevaMyNamespacesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections>
</ui>

20
src/qt/kevadialog.cpp

@ -15,8 +15,10 @@ @@ -15,8 +15,10 @@
#include <qt/platformstyle.h>
#include <qt/receiverequestdialog.h>
#include <qt/kevatablemodel.h>
#include <qt/kevanamespacemodel.h>
#include <qt/kevadetaildialog.h>
#include <qt/kevanewnamespacedialog.h>
#include <qt/kevamynamespacesdialog.h>
#include <qt/walletmodel.h>
#include <QAction>
@ -131,6 +133,24 @@ void KevaDialog::on_createNamespace_clicked() @@ -131,6 +133,24 @@ void KevaDialog::on_createNamespace_clicked()
dialog->show();
}
void KevaDialog::on_listNamespaces_clicked()
{
if(!model || !model->getKevaTableModel())
return;
KevaMyNamespacesDialog *dialog = new KevaMyNamespacesDialog(this);
std::vector<NamespaceEntry> vNamespaceEntries;
model->getNamespaceEntries(vNamespaceEntries);
model->getKevaNamespaceModel()->setNamespace(std::move(vNamespaceEntries));
model->getKevaNamespaceModel()->sort(KevaNamespaceModel::Name, Qt::DescendingOrder);
dialog->setModel(model);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
}
void KevaDialog::on_showContent_clicked()
{
if(!model || !model->getKevaTableModel())

1
src/qt/kevadialog.h

@ -66,6 +66,7 @@ private: @@ -66,6 +66,7 @@ private:
private Q_SLOTS:
void on_showContent_clicked();
void on_createNamespace_clicked();
void on_listNamespaces_clicked();
void on_showRequestButton_clicked();
void on_removeRequestButton_clicked();
void on_kevaView_doubleClicked(const QModelIndex &index);

53
src/qt/kevamynamespacesdialog.cpp

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
// Copyright (c) 2011-2017 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <qt/kevamynamespacesdialog.h>
#include <qt/forms/ui_kevamynamespacesdialog.h>
#include <qt/kevanamespacemodel.h>
#include <QModelIndex>
KevaMyNamespacesDialog::KevaMyNamespacesDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::KevaMyNamespacesDialog)
{
ui->setupUi(this);
}
void KevaMyNamespacesDialog::setModel(WalletModel *_model)
{
this->model = _model;
if(_model && _model->getOptionsModel())
{
_model->getKevaNamespaceModel()->sort(KevaNamespaceModel::Name, Qt::DescendingOrder);
QTableView* tableView = ui->namespaceView;
tableView->verticalHeader()->hide();
tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
tableView->setModel(_model->getKevaNamespaceModel());
tableView->setAlternatingRowColors(true);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
//tableView->setColumnWidth(KevaNamespaceModel::Id, ID_COLUMN_WIDTH);
//tableView->setColumnWidth(KevaNamespaceModel::Name, NAME_COLUMN_WIDTH);
tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
connect(tableView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this,
SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection)));
}
}
void KevaMyNamespacesDialog::accept()
{
// Create the namespace here.
QDialog::accept();
}
KevaMyNamespacesDialog::~KevaMyNamespacesDialog()
{
delete ui;
}

42
src/qt/kevamynamespacesdialog.h

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
// Copyright (c) 2011-2014 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_QT_KEVAMYNMAESPACESDIALOG_H
#define BITCOIN_QT_KEVAMYNMAESPACESDIALOG_H
#include <QObject>
#include <QString>
#include <QDialog>
class WalletModel;
namespace Ui {
class KevaMyNamespacesDialog;
}
/** Dialog showing namepsace creation. */
class KevaMyNamespacesDialog : public QDialog
{
Q_OBJECT
enum ColumnWidths {
ID_COLUMN_WIDTH = 260,
NAME_COLUMN_WIDTH = 260,
MINIMUM_COLUMN_WIDTH = 260
};
public:
explicit KevaMyNamespacesDialog(QWidget *parent = 0);
~KevaMyNamespacesDialog();
void accept();
void setModel(WalletModel *_model);
private:
Ui::KevaMyNamespacesDialog *ui;
WalletModel *model;
};
#endif // BITCOIN_QT_KEVAMYNMAESPACESDIALOG_H

149
src/qt/kevanamespacemodel.cpp

@ -0,0 +1,149 @@ @@ -0,0 +1,149 @@
// Copyright (c) 2011-2017 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <qt/kevanamespacemodel.h>
#include <qt/bitcoinunits.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>
#include <clientversion.h>
#include <streams.h>
KevaNamespaceModel::KevaNamespaceModel(CWallet *wallet, WalletModel *parent) :
QAbstractTableModel(parent), walletModel(parent)
{
Q_UNUSED(wallet)
/* These columns must match the indices in the ColumnIndex enumeration */
columns << tr("Id") << tr("Name");
}
KevaNamespaceModel::~KevaNamespaceModel()
{
/* Intentionally left empty */
}
int KevaNamespaceModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return list.length();
}
int KevaNamespaceModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return columns.length();
}
QVariant KevaNamespaceModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid() || index.row() >= list.length())
return QVariant();
if(role == Qt::DisplayRole || role == Qt::EditRole)
{
const NamespaceEntry *rec = &list[index.row()];
switch(index.column())
{
case Id:
return QString::fromStdString(rec->id);
case Name:
return QString::fromStdString(rec->name);
}
}
else if (role == Qt::TextAlignmentRole)
{
return (int)(Qt::AlignLeft|Qt::AlignVCenter);
}
return QVariant();
}
bool KevaNamespaceModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
return true;
}
QVariant KevaNamespaceModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(orientation == Qt::Horizontal)
{
if(role == Qt::DisplayRole && section < columns.size())
{
return columns[section];
}
}
return QVariant();
}
QModelIndex KevaNamespaceModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent);
return createIndex(row, column);
}
bool KevaNamespaceModel::removeRows(int row, int count, const QModelIndex &parent)
{
Q_UNUSED(parent);
if(count > 0 && row >= 0 && (row+count) <= list.size())
{
beginRemoveRows(parent, row, row + count - 1);
list.erase(list.begin() + row, list.begin() + row + count);
endRemoveRows();
return true;
} else {
return false;
}
}
Qt::ItemFlags KevaNamespaceModel::flags(const QModelIndex &index) const
{
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
// actually add to table in GUI
void KevaNamespaceModel::setNamespace(std::vector<NamespaceEntry> vNamespaceEntries)
{
// Remove the old ones.
removeRows(0, list.size());
list.clear();
for (auto it = vNamespaceEntries.begin(); it != vNamespaceEntries.end(); it++) {
beginInsertRows(QModelIndex(), 0, 0);
list.prepend(*it);
endInsertRows();
}
}
void KevaNamespaceModel::sort(int column, Qt::SortOrder order)
{
qSort(list.begin(), list.end(), NamespaceEntryLessThan(column, order));
Q_EMIT dataChanged(index(0, 0, QModelIndex()), index(list.size() - 1, NUMBER_OF_COLUMNS - 1, QModelIndex()));
}
bool NamespaceEntryLessThan::operator()(NamespaceEntry &left, NamespaceEntry &right) const
{
NamespaceEntry *pLeft = &left;
NamespaceEntry *pRight = &right;
if (order == Qt::DescendingOrder)
std::swap(pLeft, pRight);
switch(column)
{
case KevaNamespaceModel::Id:
return pLeft->id < pRight->id;
case KevaNamespaceModel::Name:
return pLeft->name < pRight->name;
default:
return pLeft->id < pRight->id;
}
}

79
src/qt/kevanamespacemodel.h

@ -0,0 +1,79 @@ @@ -0,0 +1,79 @@
// Copyright (c) 2011-2017 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_QT_KEVANAMESPACEMODEL_H
#define BITCOIN_QT_KEVANAMESPACEMODEL_H
#include <qt/walletmodel.h>
#include <QAbstractTableModel>
#include <QStringList>
#include <QDateTime>
class CWallet;
class NamespaceEntry
{
public:
NamespaceEntry() { }
std::string id;
std::string name;
};
class NamespaceEntryLessThan
{
public:
NamespaceEntryLessThan(int nColumn, Qt::SortOrder fOrder):
column(nColumn), order(fOrder) {}
bool operator()(NamespaceEntry &left, NamespaceEntry &right) const;
private:
int column;
Qt::SortOrder order;
};
/** Model for list of recently generated payment requests / bitcoin: URIs.
* Part of wallet model.
*/
class KevaNamespaceModel: public QAbstractTableModel
{
Q_OBJECT
public:
explicit KevaNamespaceModel(CWallet *wallet, WalletModel *parent);
~KevaNamespaceModel();
enum ColumnIndex {
Id = 0,
Name = 1,
NUMBER_OF_COLUMNS
};
/** @name Methods overridden from QAbstractTableModel
@{*/
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QModelIndex index(int row, int column, const QModelIndex &parent) const;
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
Qt::ItemFlags flags(const QModelIndex &index) const;
/*@}*/
const NamespaceEntry &entry(int row) const { return list[row]; }
void setNamespace(std::vector<NamespaceEntry> vNamespaceEntries);
public Q_SLOTS:
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
private:
WalletModel *walletModel;
QStringList columns;
QList<NamespaceEntry> list;
int64_t nReceiveRequestsMaxId;
};
#endif // BITCOIN_QT_KEVANAMESPACEMODEL_H

66
src/qt/walletmodel.cpp

@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
#include <qt/paymentserver.h>
#include <qt/recentrequeststablemodel.h>
#include <qt/kevatablemodel.h>
#include <qt/kevanamespacemodel.h>
#include <qt/sendcoinsdialog.h>
#include <qt/transactiontablemodel.h>
@ -45,6 +46,7 @@ WalletModel::WalletModel(const PlatformStyle *platformStyle, CWallet *_wallet, O @@ -45,6 +46,7 @@ WalletModel::WalletModel(const PlatformStyle *platformStyle, CWallet *_wallet, O
transactionTableModel(0),
recentRequestsTableModel(0),
kevaTableModel(0),
kevaNamespaceModel(0),
cachedBalance(0), cachedUnconfirmedBalance(0), cachedImmatureBalance(0),
cachedEncryptionStatus(Unencrypted),
cachedNumBlocks(0)
@ -56,6 +58,7 @@ WalletModel::WalletModel(const PlatformStyle *platformStyle, CWallet *_wallet, O @@ -56,6 +58,7 @@ WalletModel::WalletModel(const PlatformStyle *platformStyle, CWallet *_wallet, O
transactionTableModel = new TransactionTableModel(platformStyle, wallet, this);
recentRequestsTableModel = new RecentRequestsTableModel(wallet, this);
kevaTableModel = new KevaTableModel(wallet, this);
kevaNamespaceModel = new KevaNamespaceModel(wallet, this);
// This timer will be fired repeatedly to update the balance
pollTimer = new QTimer(this);
@ -403,6 +406,11 @@ KevaTableModel *WalletModel::getKevaTableModel() @@ -403,6 +406,11 @@ KevaTableModel *WalletModel::getKevaTableModel()
return kevaTableModel;
}
KevaNamespaceModel *WalletModel::getKevaNamespaceModel()
{
return kevaNamespaceModel;
}
WalletModel::EncryptionStatus WalletModel::getEncryptionStatus() const
{
if(!wallet->IsCrypted())
@ -776,3 +784,61 @@ void WalletModel::getKevaEntries(std::vector<KevaEntry>& vKevaEntries, std::stri @@ -776,3 +784,61 @@ void WalletModel::getKevaEntries(std::vector<KevaEntry>& vKevaEntries, std::stri
vKevaEntries.push_back(std::move(entry));
}
}
void WalletModel::getNamespaceEntries(std::vector<NamespaceEntry>& vNamespaceEntries)
{
LOCK2(cs_main, wallet->cs_wallet);
std::map<std::string, std::string> mapObjects;
for (const auto& item : wallet->mapWallet) {
const CWalletTx& tx = item.second;
if (!tx.tx->IsKevacoin()) {
continue;
}
CKevaScript kevaOp;
int nOut = -1;
for (unsigned i = 0; i < tx.tx->vout.size(); ++i) {
const CKevaScript cur(tx.tx->vout[i].scriptPubKey);
if (cur.isKevaOp()) {
if (nOut != -1) {
LogPrintf("ERROR: wallet contains tx with multiple name outputs");
} else {
kevaOp = cur;
nOut = i;
}
}
}
if (nOut == -1) {
continue;
}
if (!kevaOp.isNamespaceRegistration() && !kevaOp.isAnyUpdate()) {
continue;
}
const valtype nameSpace = kevaOp.getOpNamespace();
const std::string nameSpaceStr = EncodeBase58Check(nameSpace);
const CBlockIndex* pindex;
const int depth = tx.GetDepthInMainChain(pindex);
if (depth <= 0) {
continue;
}
const bool mine = IsMine(*wallet, kevaOp.getAddress());
CKevaData data;
if (mine && pcoinsTip->GetNamespace(nameSpace, data)) {
std::string displayName = ValtypeToString(data.getValue());
mapObjects[nameSpaceStr] = displayName;
}
}
std::map<std::string, std::string>::iterator it = mapObjects.begin();
while (it != mapObjects.end()) {
NamespaceEntry entry;
entry.id = it->first;
entry.name = it->second;
vNamespaceEntries.push_back(std::move(entry));
it++;
}
}

5
src/qt/walletmodel.h

@ -22,7 +22,9 @@ class OptionsModel; @@ -22,7 +22,9 @@ class OptionsModel;
class PlatformStyle;
class RecentRequestsTableModel;
class KevaTableModel;
class KevaNamespaceModel;
class KevaEntry;
class NamespaceEntry;
class TransactionTableModel;
class WalletModelTransaction;
@ -133,6 +135,7 @@ public: @@ -133,6 +135,7 @@ public:
TransactionTableModel *getTransactionTableModel();
RecentRequestsTableModel *getRecentRequestsTableModel();
KevaTableModel *getKevaTableModel();
KevaNamespaceModel *getKevaNamespaceModel();
CAmount getBalance(const CCoinControl *coinControl = nullptr) const;
CAmount getUnconfirmedBalance() const;
@ -225,6 +228,7 @@ public: @@ -225,6 +228,7 @@ public:
// Keva
void getKevaEntries(std::vector<KevaEntry>& vKevaEntries, std::string nameSpace);
void getNamespaceEntries(std::vector<NamespaceEntry>& vNamespaceEntries);
private:
CWallet *wallet;
@ -239,6 +243,7 @@ private: @@ -239,6 +243,7 @@ private:
TransactionTableModel *transactionTableModel;
RecentRequestsTableModel *recentRequestsTableModel;
KevaTableModel *kevaTableModel;
KevaNamespaceModel *kevaNamespaceModel;
// Cache some values to be able to detect changes
CAmount cachedBalance;

Loading…
Cancel
Save