void ContactView::onSave() { try { if (FromDialog()) { if (_current_record) { //_current_contact.bit_id_hash = _current_record->name_hash; if (!_current_contact.public_key.valid() ) { _current_contact.public_key = _current_record->active_key; FC_ASSERT(_current_contact.public_key.valid() ); } // TODO: lookup block id / timestamp that registered this ID // _current_contact.known_since.setMSecsSinceEpoch( ); } else if (!_current_record) /// note: user is entering manual public key { elog("!current record??\n"); /* if( _current_contact.known_since == QDateTime() ) { _current_contact.known_since = QDateTime::currentDateTime(); } */ std::string enteredPKey = ui->khid_pubkey->getPublicKeyText().toStdString(); if (enteredPKey.empty() == false) { bool publicKeySemanticallyValid = false; assert(public_key_address::is_valid(enteredPKey, &publicKeySemanticallyValid)); assert(publicKeySemanticallyValid); public_key_address key_address(enteredPKey); _current_contact.public_key = key_address.key; } } _current_contact.privacy_setting = bts::addressbook::secret_contact; int idxNewContact = _address_book->storeContact(_current_contact); /// notify identity observers if (_current_contact.isOwn()) IdentityObservable::getInstance().notify(_current_contact); contactEditable(false); emit savedNewContact(idxNewContact); } } FC_RETHROW_EXCEPTIONS(warn, "onSave") }
void ContactView::onSave() { try { if (doDataExchange (true)) { if (_current_record) { //_current_contact.bit_id_hash = _current_record->name_hash; if (!_current_contact.public_key.valid() ) { _current_contact.public_key = _current_record->active_key; FC_ASSERT(_current_contact.public_key.valid() ); } // TODO: lookup block id / timestamp that registered this ID // _current_contact.known_since.setMSecsSinceEpoch( ); } else if (!_current_record) /// note: user is entering manual public key { elog("!current record??\n"); /* if( _current_contact.known_since == QDateTime() ) { _current_contact.known_since = QDateTime::currentDateTime(); } */ std::string enteredPKey = ui->public_key->text().toStdString(); if (enteredPKey.empty() == false) { assert(public_key_address::is_valid(enteredPKey) && "Some bug in control validator"); public_key_address key_address(enteredPKey); _current_contact.public_key = key_address.key; } } _current_contact.privacy_setting = bts::addressbook::secret_contact; int idxNewContact = _address_book->storeContact(_current_contact); keyEdit(false); emit savedNewContact(idxNewContact); } } FC_RETHROW_EXCEPTIONS(warn, "onSave") }
bool ContactView::existContactWithPublicKey (const std::string& public_key_string) { std::string my_public_key = public_key_address( _current_contact.public_key ); if (public_key_string != my_public_key) { auto addressbook = bts::get_profile()->get_addressbook(); if(! public_key_string.size()==0) { public_key_address key_address(public_key_string); auto findContact = addressbook->get_contact_by_public_key( key_address.key ); if (findContact) { ui->id_status->setText( tr("This contact is already added to the list") ); ui->id_status->setStyleSheet("QLabel { color : red; }"); return true; } } } return false; }