Exemplo n.º 1
0
void ContactsTable::onDeleteContact()
  {
  //remove selected contacts from inbox model (and database)
  QSortFilterProxyModel* model = dynamic_cast<QSortFilterProxyModel*>(ui->contact_table->model());
  //model->setUpdatesEnabled(false);
  QItemSelectionModel*   selection_model = ui->contact_table->selectionModel();
  QModelIndexList        sortFilterIndexes = selection_model->selectedRows();
  if (sortFilterIndexes.count() == 0)
    return;
  if (QMessageBox::question(this, "Delete Contact", "Are you sure you want to delete this contact?") == QMessageBox::Button::No)
    return;
  QModelIndexList        indexes;
  foreach(QModelIndex sortFilterIndex, sortFilterIndexes)
    indexes.append(model->mapToSource(sortFilterIndex));
  qSort(indexes);
  auto sourceModel = model->sourceModel();
  for (int i = indexes.count() - 1; i > -1; --i)
    {
    auto contact_id = ((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).wallet_index;
    sourceModel->removeRows(indexes.at(i).row(), 1);    
    Q_EMIT contactDeleted(contact_id); //emit signal so that ContactGui is also deleted
    }
  //model->setUpdatesEnabled(true);

  //TODO Remove fullname/bitname for deleted contacts from QCompleter
  }
Exemplo n.º 2
0
void ContactUser::deleteContact()
{
    /* Anything that uses ContactUser is required to either respond to the contactDeleted signal
     * synchronously, or make use of QWeakPointer. */

    qDebug() << "Deleting contact" << uniqueID;

    if (m_contactRequest) {
        qDebug() << "Cancelling request associated with contact to be deleted";
        m_contactRequest->cancel();
        m_contactRequest->deleteLater();
    }

    emit contactDeleted(this);

    m_settings->undefine();
    deleteLater();
}
Exemplo n.º 3
0
void ContactsTable::onDeleteContact()
  {
  //remove selected contacts from inbox model (and database)
  QSortFilterProxyModel* model = dynamic_cast<QSortFilterProxyModel*>(ui->contact_table->model());
  //model->setUpdatesEnabled(false);
  QItemSelectionModel*   selection_model = ui->contact_table->selectionModel();
  QModelIndexList        sortFilterIndexes = selection_model->selectedRows();
  if (sortFilterIndexes.count() == 0)
    return;
  if (QMessageBox::question(this, tr("Delete Contact"), tr("Are you sure you want to delete selected contact(s)?")) == QMessageBox::Button::No)
    return;
  QModelIndexList        indexes;
  for(const QModelIndex& sortFilterIndex : sortFilterIndexes)
    indexes.append(model->mapToSource(sortFilterIndex));
  qSort(indexes);
  auto sourceModel = model->sourceModel();
  auto app = bts::application::instance();
  auto profile = app->get_profile();

  for (int i = indexes.count() - 1; i > -1; --i)
  {
    auto contact_id = ((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).wallet_index;
    if(profile->isIdentityPresent(((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).dac_id_string))
    {
      auto priv_key = profile->get_keychain().get_identity_key(((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).dac_id_string);
      app->remove_receive_key(priv_key);
      profile->removeIdentity(((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).dac_id_string);

      /// notify identity observers
      IdentityObservable::getInstance().notify();
    }
    sourceModel->removeRows(indexes.at(i).row(), 1);
    Q_EMIT contactDeleted(contact_id); //emit signal so that ContactGui is also deleted
  }
  //model->setUpdatesEnabled(true);
  //TODO Remove fullname/bitname for deleted contacts from QCompleter

  qSort(sortFilterIndexes);
  selectNextRow(sortFilterIndexes.takeLast().row(), indexes.count());
  }