Commit 9949b346 authored by Edric Milaret's avatar Edric Milaret

smartlist: refactor context menu

- Add possibility to call or copy when a person have
more than one contact method.

Change-Id: Ic00057636114de2bf8a6f547e72fde0e93ffa0a0
Tuleap: #320
parent 3658736c
......@@ -236,23 +236,45 @@ CallWidget::setupSmartListMenu() {
QPoint globalPos = ui->smartList->mapToGlobal(pos);
QMenu menu;
ContactMethod* contactMethod = RecentModel::instance()
.getContactMethods(RecentModel::instance().peopleProxy()->mapToSource(idx)).at(0);
if (not contactMethod)
QVector<ContactMethod*> contactMethods = RecentModel::instance()
.getContactMethods(RecentModel::instance().peopleProxy()->mapToSource(idx));
if (contactMethods.isEmpty())
return;
auto copyAction = new QAction(tr("Copy number"), this);
menu.addAction(copyAction);
connect(copyAction, &QAction::triggered, [=]() {
QApplication::clipboard()->setText(contactMethod->uri());
});
if (not contactMethod->contact() || contactMethod->contact()->isPlaceHolder()) {
auto addExisting = new QAction(tr("Add to contact"), this);
menu.addAction(addExisting);
connect(addExisting, &QAction::triggered, [=]() {
ContactPicker contactPicker(contactMethod);
contactPicker.move(globalPos.x(), globalPos.y() - (contactPicker.height()/2));
contactPicker.exec();
if (contactMethods.size() == 1) {
auto contactMethod = contactMethods.at(0);
auto copyAction = new QAction(tr("Copy number"), this);
menu.addAction(copyAction);
connect(copyAction, &QAction::triggered, [contactMethod]() {
QApplication::clipboard()->setText(contactMethod->uri());
});
if (not contactMethod->contact() || contactMethod->contact()->isPlaceHolder()) {
auto addExisting = new QAction(tr("Add to contact"), this);
menu.addAction(addExisting);
connect(addExisting, &QAction::triggered, [globalPos, contactMethod]() {
ContactPicker contactPicker(contactMethod);
contactPicker.move(globalPos.x(), globalPos.y() - (contactPicker.height()/2));
contactPicker.exec();
});
}
}
else {
auto callMenu = menu.addMenu(tr("Call Number"));
auto copyMenu = menu.addMenu(tr("Copy Number"));
for (auto cM : contactMethods) {
auto uri = cM->uri();
auto copyAction = new QAction(tr("Copy %1").arg(uri), this);
copyMenu->addAction(copyAction);
connect(copyAction, &QAction::triggered, [uri]() {
QApplication::clipboard()->setText(uri);
});
auto callAction = new QAction(tr("Call %1").arg(uri), this);
callMenu->addAction(callAction);
connect(callAction, &QAction::triggered, [cM]() {
Call* c = CallModel::instance().dialingCall(cM);
c->performAction(Call::Action::ACCEPT);
});
}
}
menu.exec(globalPos);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment