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. 61
      src/qt/kevadialog.cpp
  4. 2
      src/qt/kevadialog.h

10
src/qt/kevabookmarksmodel.cpp

@ -146,6 +146,16 @@ void KevaBookmarksModel::setBookmarks(QJsonArray &array)
setBookmarks(std::move(vBookmarEntries)); 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) void KevaBookmarksModel::sort(int column, Qt::SortOrder order)
{ {
qSort(list.begin(), list.end(), BookmarkEntryLessThan(column, order)); qSort(list.begin(), list.end(), BookmarkEntryLessThan(column, order));

1
src/qt/kevabookmarksmodel.h

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

61
src/qt/kevadialog.cpp

@ -55,6 +55,9 @@ KevaDialog::KevaDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
QAction *copyMessageAction = new QAction(tr("Copy message"), this); QAction *copyMessageAction = new QAction(tr("Copy message"), this);
QAction *copyAmountAction = new QAction(tr("Copy amount"), this); QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
bookmarks = new KevaBookmarksModel(NULL, NULL);
bookmarks->loadBookmarks();
// context menu // context menu
contextMenu = new QMenu(this); contextMenu = new QMenu(this);
contextMenu->addAction(copyURIAction); contextMenu->addAction(copyURIAction);
@ -147,10 +150,23 @@ void KevaDialog::onNamespaceChanged(const QString& nameSpace)
{ {
std::string namespaceStr = nameSpace.toStdString(); std::string namespaceStr = nameSpace.toStdString();
valtype nameSpaceVal; valtype nameSpaceVal;
bool isValidNamespace = false;
if (DecodeKevaNamespace(namespaceStr, Params(), nameSpaceVal)) { if (DecodeKevaNamespace(namespaceStr, Params(), nameSpaceVal)) {
ui->addKVButton->setEnabled(true); ui->addKVButton->setEnabled(true);
isValidNamespace = true;
} else { } else {
ui->addKVButton->setEnabled(false); 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,7 +231,50 @@ void KevaDialog::on_kevaView_doubleClicked(const QModelIndex &index)
void KevaDialog::on_bookmarkNamespace_clicked() void KevaDialog::on_bookmarkNamespace_clicked()
{ {
ui->bookmarkNamespace->setIcon(QIcon(":/icons/star")); 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() void KevaDialog::kevaView_selectionChanged()

2
src/qt/kevadialog.h

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

Loading…
Cancel
Save