diff --git a/src/addressbook.cpp b/src/addressbook.cpp index 6ed874c..178cbdf 100644 --- a/src/addressbook.cpp +++ b/src/addressbook.cpp @@ -8,7 +8,7 @@ AddressBookModel::AddressBookModel(QTableView *parent) : QAbstractTableModel(parent) { - headers << tr("Label") << tr("Address"); + headers << tr("Label") << tr("Address") << tr("HushChatAddress"); this->parent = parent; loadData(); } @@ -59,7 +59,7 @@ void AddressBookModel::removeItemAt(int row) if (row >= labels.size()) return; - AddressBook::getInstance()->removeAddressLabel(labels[row].getName(), labels[row].getPartnerAddress()); + AddressBook::getInstance()->removeAddressLabel(labels[row].getName(), labels[row].getPartnerAddress(), labels[row].getMyAddress()); labels.clear(); labels = AddressBook::getInstance()->getAllAddressLabels(); dataChanged(index(0, 0), index(labels.size()-1, columnCount(index(0,0))-1)); @@ -99,6 +99,7 @@ QVariant AddressBookModel::data(const QModelIndex &index, int role) const { case 0: return labels.at(index.row()).getName(); case 1: return labels.at(index.row()).getPartnerAddress(); + case 2: return labels.at(index.row()).getMyAddress(); } } @@ -192,6 +193,7 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target) message, //todo traslate this shit QMessageBox::Ok ); + // ab.addr_chat->setText(myAddr); qDebug() << "new generated myAddr" << myAddr; AddressBook::getInstance()->addAddressLabel(newLabel, ab.addr->text(), myAddr); }); @@ -245,8 +247,8 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target) ); }); - auto fnSetTargetLabelAddr = [=] (QLineEdit* target, QString label, QString addr) { - target->setText(label % "/" % addr); + auto fnSetTargetLabelAddr = [=] (QLineEdit* target, QString label, QString addr, QString myAddr) { + target->setText(label % "/" % addr % myAddr); }; // Double-Click picks the item @@ -260,8 +262,9 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target) QString lbl = model.itemAt(index.row()).getName(); QString addr = model.itemAt(index.row()).getPartnerAddress(); + QString myAddr = model.itemAt(index.row()).getMyAddress(); d.accept(); - fnSetTargetLabelAddr(target, lbl, addr); + fnSetTargetLabelAddr(target, lbl, addr, myAddr); }); // Right-Click @@ -273,13 +276,14 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target) QString lbl = model.itemAt(index.row()).getName(); QString addr = model.itemAt(index.row()).getPartnerAddress(); + QString myAddr = model.itemAt(index.row()).getMyAddress(); QMenu menu(parent); if (target != nullptr) menu.addAction("Pick", [&] () { d.accept(); - fnSetTargetLabelAddr(target, lbl, addr); + fnSetTargetLabelAddr(target, lbl, addr, myAddr); }); menu.addAction(QObject::tr("Copy address"), [&] () { @@ -298,7 +302,7 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target) auto selection = ab.addresses->selectionModel(); if (selection && selection->hasSelection() && selection->selectedRows().size() > 0) { auto item = model.itemAt(selection->selectedRows().at(0).row()); - fnSetTargetLabelAddr(target, item.getName(), item.getPartnerAddress()); + fnSetTargetLabelAddr(target, item.getName(), item.getMyAddress(), item.getPartnerAddress()); } }; @@ -408,7 +412,7 @@ void AddressBook::addAddressLabel(QString label, QString address, QString myAddr // Iterate over the list and remove the label/address for (int i=0; i < allLabels.size(); i++) if (allLabels[i].getName() == label) - removeAddressLabel(allLabels[i].getName(), allLabels[i].getPartnerAddress()); + removeAddressLabel(allLabels[i].getName(), allLabels[i].getPartnerAddress(),allLabels[i].getMyAddress()); ContactItem item = ContactItem(myAddr, address, label); allLabels.push_back(item); @@ -416,7 +420,7 @@ void AddressBook::addAddressLabel(QString label, QString address, QString myAddr } // Remove a new address/label from the database -void AddressBook::removeAddressLabel(QString label, QString address) +void AddressBook::removeAddressLabel(QString label, QString address, QString myAddr) { // Iterate over the list and remove the label/address for (int i=0; i < allLabels.size(); i++) diff --git a/src/addressbook.h b/src/addressbook.h index fc3d4b9..ec3b6fe 100644 --- a/src/addressbook.h +++ b/src/addressbook.h @@ -46,7 +46,7 @@ public: void addAddressLabel(QString label, QString address, QString myAddr); // Remove a new address/label from the database - void removeAddressLabel(QString label, QString address); + void removeAddressLabel(QString label, QString address, QString myAddr); // Update a label/address void updateLabel(QString oldlabel, QString address, QString newlabel); diff --git a/src/addressbook.ui b/src/addressbook.ui index a20ee8f..20104b9 100644 --- a/src/addressbook.ui +++ b/src/addressbook.ui @@ -13,65 +13,61 @@ Address Book - - + + Add New Address - - - + + + - Address (z-Addr or t-Addr) + HushChat Address - give this Address only to your contact - - + + - - + + - Label + Address (z-Addr or t-Addr) - + 40 - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Add to Address Book - - - - + + + + + + + Label + + + + + + + + + + Add to Address Book + + - + QAbstractItemView::SingleSelection @@ -87,7 +83,7 @@ - + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7ab2da2..d1c331e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1286,7 +1286,7 @@ void MainWindow::setupReceiveTab() { if (!curLabel.isEmpty() && label.isEmpty()) { info = "Removed Label '" % curLabel % "'"; - AddressBook::getInstance()->removeAddressLabel(curLabel, addr); + AddressBook::getInstance()->removeAddressLabel(curLabel, addr, ""); } else if (!curLabel.isEmpty() && !label.isEmpty()) { info = "Updated Label '" % curLabel % "' to '" % label % "'"; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 02c074c..8dd559f 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1417,6 +1417,9 @@ + + true + 340 @@ -1425,6 +1428,18 @@ 371 + + QAbstractItemView::NoEditTriggers + + + false + + + Qt::IgnoreAction + + + QAbstractItemView::NoSelection +