Browse Source

WIP: bookmark add/remove.

keva-gui
Just Wonder 5 years ago
parent
commit
21747533fb
  1. 10
      src/qt/kevabookmarksmodel.cpp
  2. 1
      src/qt/kevabookmarksmodel.h
  3. 59
      src/qt/kevadialog.cpp
  4. 2
      src/qt/kevadialog.h

10
src/qt/kevabookmarksmodel.cpp

@ -146,6 +146,16 @@ void KevaBookmarksModel::setBookmarks(QJsonArray &array) @@ -146,6 +146,16 @@ void KevaBookmarksModel::setBookmarks(QJsonArray &array)
setBookmarks(std::move(vBookmarEntries));
}
bool KevaBookmarksModel::isBookmarked(std::string& ns)
{
for (int i = 0; i < list.size(); ++i) {
if (list.at(i).id == ns) {
return true;
}
}
return false;
}
void KevaBookmarksModel::sort(int column, Qt::SortOrder order)
{
qSort(list.begin(), list.end(), BookmarkEntryLessThan(column, order));

1
src/qt/kevabookmarksmodel.h

@ -74,6 +74,7 @@ public: @@ -74,6 +74,7 @@ public:
int loadBookmarks();
int loadBookmarks(QJsonArray &json);
int saveBookmarks(QJsonArray &json);
bool isBookmarked(std::string& ns);
public Q_SLOTS:
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);

59
src/qt/kevadialog.cpp

@ -55,6 +55,9 @@ KevaDialog::KevaDialog(const PlatformStyle *_platformStyle, QWidget *parent) : @@ -55,6 +55,9 @@ KevaDialog::KevaDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
QAction *copyMessageAction = new QAction(tr("Copy message"), this);
QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
bookmarks = new KevaBookmarksModel(NULL, NULL);
bookmarks->loadBookmarks();
// context menu
contextMenu = new QMenu(this);
contextMenu->addAction(copyURIAction);
@ -147,10 +150,23 @@ void KevaDialog::onNamespaceChanged(const QString& nameSpace) @@ -147,10 +150,23 @@ void KevaDialog::onNamespaceChanged(const QString& nameSpace)
{
std::string namespaceStr = nameSpace.toStdString();
valtype nameSpaceVal;
bool isValidNamespace = false;
if (DecodeKevaNamespace(namespaceStr, Params(), nameSpaceVal)) {
ui->addKVButton->setEnabled(true);
isValidNamespace = true;
} else {
ui->addKVButton->setEnabled(false);
ui->bookmarkNamespace->setIcon(QIcon(":/icons/star_empty"));
}
if (!isValidNamespace) {
return;
}
if (bookmarks->isBookmarked(namespaceStr)) {
ui->bookmarkNamespace->setIcon(QIcon(":/icons/star"));
} else {
ui->bookmarkNamespace->setIcon(QIcon(":/icons/star_empty"));
}
}
@ -215,9 +231,52 @@ void KevaDialog::on_kevaView_doubleClicked(const QModelIndex &index) @@ -215,9 +231,52 @@ void KevaDialog::on_kevaView_doubleClicked(const QModelIndex &index)
void KevaDialog::on_bookmarkNamespace_clicked()
{
valtype namespaceVal;
QString nameSpace = ui->nameSpace->text();
std::string namespaceStr = nameSpace.toStdString();
if (!DecodeKevaNamespace(namespaceStr, Params(), namespaceVal)) {
return;
}
QJsonArray array;
bookmarks->loadBookmarks(array);
int index = -1;
for (int i = 0; i < array.size(); ++i) {
QJsonObject obj = array[i].toObject();
BookmarkEntry entry;
std::string id = obj["id"].toString().toStdString();
if (id == namespaceStr) {
index = i;
break;
}
}
if (index >= 0) {
// Remove bookmark
array.removeAt(index);
ui->bookmarkNamespace->setIcon(QIcon(":/icons/star_empty"));
} else {
// Add bookmark
QJsonObject entry;
entry["id"] = namespaceStr.c_str();
entry["name"] = "";
std::vector<NamespaceEntry> vNamespaceEntries;
this->model->getNamespaceEntries(vNamespaceEntries);
for(auto it = vNamespaceEntries.begin(); it != vNamespaceEntries.end(); it++) {
if ((*it).id == namespaceStr) {
entry["name"] = (*it).name.c_str();
break;
}
}
array.prepend(entry);
ui->bookmarkNamespace->setIcon(QIcon(":/icons/star"));
}
bookmarks->saveBookmarks(array);
}
void KevaDialog::kevaView_selectionChanged()
{
// Enable Show/Remove buttons only if anything is selected.

2
src/qt/kevadialog.h

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
class PlatformStyle;
class WalletModel;
class KevaBookmarksModel;
namespace Ui {
class KevaDialog;
@ -62,6 +63,7 @@ private: @@ -62,6 +63,7 @@ private:
WalletModel *model;
QMenu *contextMenu;
const PlatformStyle *platformStyle;
KevaBookmarksModel* bookmarks;
QModelIndex selectedRow();
void copyColumnToClipboard(int column);

Loading…
Cancel
Save