Commit 2afd2bfe authored by Edric Milaret's avatar Edric Milaret Committed by gerrit2

contact: add choose dialog for contact with multiple contact method

- Add a little popup that let you choose the contactmethod you want to use
when you doubleclick on a Contact who have more than one.

Refs #77968

Change-Id: Iec645756afda419c97496d58a9816b748b480bc0
parent 16f997dd
...@@ -49,7 +49,8 @@ SOURCES += main.cpp\ ...@@ -49,7 +49,8 @@ SOURCES += main.cpp\
videooverlay.cpp \ videooverlay.cpp \
imdelegate.cpp \ imdelegate.cpp \
contactdialog.cpp \ contactdialog.cpp \
contactpicker.cpp contactpicker.cpp \
contactmethodpicker.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
callwidget.h \ callwidget.h \
...@@ -74,7 +75,8 @@ HEADERS += mainwindow.h \ ...@@ -74,7 +75,8 @@ HEADERS += mainwindow.h \
videooverlay.h \ videooverlay.h \
imdelegate.h \ imdelegate.h \
contactdialog.h \ contactdialog.h \
contactpicker.h contactpicker.h \
contactmethodpicker.h
FORMS += mainwindow.ui \ FORMS += mainwindow.ui \
callwidget.ui \ callwidget.ui \
...@@ -89,7 +91,8 @@ FORMS += mainwindow.ui \ ...@@ -89,7 +91,8 @@ FORMS += mainwindow.ui \
videoview.ui \ videoview.ui \
videooverlay.ui \ videooverlay.ui \
contactdialog.ui \ contactdialog.ui \
contactpicker.ui contactpicker.ui \
contactmethodpicker.ui
win32: LIBS += -lole32 -luuid -lshlwapi win32: LIBS += -lole32 -luuid -lshlwapi
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "windowscontactbackend.h" #include "windowscontactbackend.h"
#include "contactdialog.h" #include "contactdialog.h"
#include "contactpicker.h" #include "contactpicker.h"
#include "contactmethodpicker.h"
CallWidget::CallWidget(QWidget *parent) : CallWidget::CallWidget(QWidget *parent) :
NavWidget(Main ,parent), NavWidget(Main ,parent),
...@@ -125,7 +126,6 @@ CallWidget::CallWidget(QWidget *parent) : ...@@ -125,7 +126,6 @@ CallWidget::CallWidget(QWidget *parent) :
connect(copyAction, &QAction::triggered, [=]() { connect(copyAction, &QAction::triggered, [=]() {
QApplication::clipboard()->setText(contactMethod->uri()); QApplication::clipboard()->setText(contactMethod->uri());
}); });
if (not contactMethod->contact()) { if (not contactMethod->contact()) {
auto addNew = new QAction("Add to new contact", this); auto addNew = new QAction("Add to new contact", this);
menu.addAction(addNew); menu.addAction(addNew);
...@@ -373,19 +373,25 @@ CallWidget::on_contactView_doubleClicked(const QModelIndex &index) ...@@ -373,19 +373,25 @@ CallWidget::on_contactView_doubleClicked(const QModelIndex &index)
if (not index.isValid()) if (not index.isValid())
return; return;
ContactMethod* uri; ContactMethod* uri = nullptr;
auto var = index.child(0,0).data( auto var = index.child(0,0).data(
static_cast<int>(Person::Role::Object)); static_cast<int>(Person::Role::Object));
if (var.isValid()) { if (var.isValid()) {
Person* person = var.value<Person*>(); Person* person = var.value<Person*>();
if (person->phoneNumbers().size() > 0) { if (person->phoneNumbers().size() == 1) {
uri = person->phoneNumbers().at(0); // FIXME: A person can have multiple contact method uri = person->phoneNumbers().at(0);
if (uri) { } else if (person->phoneNumbers().size() > 1) {
auto outCall = CallModel::instance()->dialingCall(person->formattedName()); ContactMethodPicker dlg(person->phoneNumbers());
outCall->setDialNumber(uri); auto pos = QCursor::pos();
outCall->performAction(Call::Action::ACCEPT); dlg.move(pos.x(), pos.y());
} if (dlg.exec())
uri = dlg.getSelected();
}
if (uri) {
auto outCall = CallModel::instance()->dialingCall(person->formattedName());
outCall->setDialNumber(uri);
outCall->performAction(Call::Action::ACCEPT);
} }
} }
} }
......
...@@ -315,15 +315,6 @@ ...@@ -315,15 +315,6 @@
<property name="sizeAdjustPolicy"> <property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum> <enum>QAbstractScrollArea::AdjustIgnored</enum>
</property> </property>
<property name="resizeMode">
<enum>QListView::Fixed</enum>
</property>
<property name="layoutMode">
<enum>QListView::SinglePass</enum>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
......
...@@ -83,7 +83,10 @@ ContactDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, ...@@ -83,7 +83,10 @@ ContactDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
break; break;
} }
default: default:
/* more than one, for now don't show any of the contact methods */ painter->drawText(QRect(rect.left()+sizeImage_+5,
rect.top() + rect.height()/2,
rect.width(), rect.height()/2),
opt.displayAlignment, "<Multiple contact methods>");
break; break;
} }
} }
......
/***************************************************************************
* Copyright (C) 2015 by Savoir-Faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "contactmethodpicker.h"
#include "ui_contactmethodpicker.h"
#include "contactmethod.h"
ContactMethodPicker::ContactMethodPicker(const Person::ContactMethods& cM, QWidget *parent) :
QDialog(parent),
ui(new Ui::ContactMethodPicker),
contactMethods_(cM)
{
ui->setupUi(this);
this->setWindowFlags(Qt::CustomizeWindowHint);
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
for (auto contactMethod : cM) {
auto item = new QListWidgetItem();
item->setText(contactMethod->uri());
ui->contactMethodListWidget->addItem(item);
}
}
ContactMethodPicker::~ContactMethodPicker()
{
delete ui;
}
void
ContactMethodPicker::on_contactMethodListWidget_clicked(const QModelIndex &index)
{
index_ = index.row();
accept();
}
ContactMethod*
ContactMethodPicker::getSelected() const
{
return contactMethods_.at(index_);
}
/***************************************************************************
* Copyright (C) 2015 by Savoir-Faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#ifndef CONTACTMETHODPICKER_H
#define CONTACTMETHODPICKER_H
#include <QDialog>
#include "person.h"
#include "personmodel.h"
namespace Ui {
class ContactMethodPicker;
}
class ContactMethodPicker final : public QDialog
{
Q_OBJECT
public:
explicit ContactMethodPicker(const Person::ContactMethods &cM, QWidget *parent = 0);
~ContactMethodPicker();
ContactMethod* getSelected() const;
//UI SLOTS
private slots:
void on_contactMethodListWidget_clicked(const QModelIndex &index);
private:
Ui::ContactMethodPicker *ui;
const Person::ContactMethods& contactMethods_;
int index_;
};
#endif // CONTACTMETHODPICKER_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ContactMethodPicker</class>
<widget class="QDialog" name="ContactMethodPicker">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>93</width>
<height>93</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QListWidget" name="contactMethodListWidget"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
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