Browse Source

render HushChat Address in Addressbook

pull/130/head
DenioD 4 years ago
parent
commit
a5020cbe24
  1. 22
      src/addressbook.cpp
  2. 2
      src/addressbook.h
  3. 70
      src/addressbook.ui
  4. 2
      src/mainwindow.cpp
  5. 15
      src/mainwindow.ui

22
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++)

2
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);

70
src/addressbook.ui

@ -13,65 +13,61 @@
<property name="windowTitle">
<string>Address Book</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Add New Address</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_1">
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Address (z-Addr or t-Addr)</string>
<string>HushChat Address - give this Address only to your contact</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="addr"/>
<item row="3" column="0">
<widget class="QLineEdit" name="addr_chat"/>
</item>
<item>
<widget class="QLabel" name="label_2">
<item row="0" column="0">
<widget class="QLabel" name="label_1">
<property name="text">
<string>Label</string>
<string>Address (z-Addr or t-Addr)</string>
</property>
</widget>
</item>
<item>
<item row="5" column="0">
<widget class="QLineEdit" name="label">
<property name="maxLength">
<number>40</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="addNew">
<property name="text">
<string>Add to Address Book</string>
</property>
</widget>
</item>
</layout>
<item row="6" column="0">
<layout class="QHBoxLayout" name="horizontalLayout"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Label</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="addr"/>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="addNew">
<property name="text">
<string>Add to Address Book</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<item row="1" column="0">
<widget class="QTableView" name="addresses">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
@ -87,7 +83,7 @@
</attribute>
</widget>
</item>
<item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="btnImport">

2
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 % "'";

15
src/mainwindow.ui

@ -1417,6 +1417,9 @@
</property>
</widget>
<widget class="QListWidget" name="listChatMemo">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>340</x>
@ -1425,6 +1428,18 @@
<height>371</height>
</rect>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="defaultDropAction">
<enum>Qt::IgnoreAction</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
</widget>
<widget class="QPushButton" name="sendChatButton">
<property name="geometry">

Loading…
Cancel
Save