Commit cdf1feec authored by Jonah Brüchert's avatar Jonah Brüchert 🌳

Rework actions list view

parent 2161d950
......@@ -81,6 +81,7 @@ Kirigami.ScrollablePage {
Kirigami.FormLayout {
id: form
wideMode: true
Controls.TextField {
id: name
......
......@@ -19,30 +19,34 @@
import QtQuick 2.2
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.2
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kirigami 2.10 as Kirigami
import QtGraphicalEffects 1.0
import org.kde.people 1.0 as KPeople
import "lib" as HIG
Flickable {
id: root
ListView {
property string personUri;
signal editClicked()
anchors.fill: parent
id: actionsListView
model: personActions
KPeople.PersonData {
id: personData
personUri: root.personUri
personUri: actionsListView.personUri
}
HIG.Header {
KPeople.PersonActions {
id: personActions
personUri: actionsListView.personUri
}
header: HIG.Header {
id: header
content.anchors.leftMargin: root.width > 400 ? 100 : Kirigami.Units.largeSpacing
content.anchors.leftMargin: actionsListView.width > 400 ? 100 : Kirigami.Units.largeSpacing
content.anchors.topMargin: Kirigami.Units.largeSpacing
content.anchors.bottomMargin: Kirigami.Units.largeSpacing
//status: root.contentY == 0 ? 1 : Math.min(1, Math.max(2 / 11, 1 - root.contentY / Kirigami.Units.gridUnit))
source: personData.person.photo
......@@ -50,35 +54,6 @@ Flickable {
// For the background image it's more important to provide something else than the default pixmap though.
backgroundSource: personData.person.pictureUrl ? personData.person.pictureUrl : "qrc:/fallbackBackground.png"
/*stripContent: Row {
anchors.fill: parent
spacing: (header.width - 3 * Kirigami.Units.iconSizes.medium) / 4
anchors.leftMargin: spacing
Kirigami.Icon {
source: "favorite"
width: Kirigami.Units.iconSizes.smallMedium
height: width
anchors.verticalCenter: parent.verticalCenter
}
Kirigami.Icon {
source: "document-share"
width: Kirigami.Units.iconSizes.smallMedium
height: width
anchors.verticalCenter: parent.verticalCenter
}
Kirigami.Icon {
source: "document-edit"
width: Kirigami.Units.iconSizes.smallMedium
height: width
anchors.verticalCenter: parent.verticalCenter
MouseArea {
onClicked: root.editClicked()
anchors.fill: parent
}
}
}*/
ColumnLayout {
Kirigami.Heading {
text: personData.person.name
......@@ -93,20 +68,23 @@ Flickable {
}
}
KPeople.PersonActions {
id: personActions
personUri: root.personUri
section.property: "actionType"
section.delegate: Kirigami.ListSectionHeader {
text: {
if (section === "3")
return i18n("Email")
else if (section === "1")
return i18n("Call")
else if (section === "0")
return i18n("Chat")
else
return i18n("Other")
}
}
ListView {
id: actionsListView
anchors.top: header.bottom
width: parent.width
model: personActions
delegate: Kirigami.BasicListItem {
text: model.display
icon: model.iconName
onClicked: personActions.triggerAction(model.action)
}
delegate: Kirigami.BasicListItem {
text: model.display
icon: model.iconName
onClicked: personActions.triggerAction(model.action)
}
}
......@@ -47,8 +47,8 @@ Kirigami.ScrollablePage {
}
Detail {
anchors.fill: parent
personUri: page.personUri
onEditClicked: form.open();
}
actions {
......
......@@ -5,4 +5,5 @@ target_link_libraries(phonebook_kpeople_plugin
KF5::I18n
KF5::People
KF5::PeopleBackend
KF5::Contacts
)
......@@ -23,6 +23,8 @@
#include <KPluginFactory>
#include <KPeopleBackend/AbstractContact>
#include <KPeople/Widgets/Actions>
#include <KContacts/VCardConverter>
KPeopleActionsPlugin::KPeopleActionsPlugin(QObject* parent, const QVariantList& args)
: AbstractPersonAction(parent)
......@@ -34,12 +36,52 @@ QList<QAction *> KPeopleActionsPlugin::actionsForPerson(const KPeople::PersonDat
{
Q_UNUSED(parent)
QList<QAction *> actions;
QVariant number = data.contactCustomProperty(KPeople::AbstractContact::PhoneNumberProperty);
if(!number.toString().isEmpty()) {
QAction *action = new QAction(QIcon::fromTheme("call-start"),
i18nc("Action to tell user to call person using phone number", "Call %1 on %2", data.name(), number.toString()));
// Fetch contact vcard
QByteArray vcard = data.contactCustomProperty(KPeople::AbstractContact::VCardProperty).toByteArray();
KContacts::VCardConverter converter;
auto addressee = converter.parseVCard(vcard);
// Phone Number actions
// TODO: Avoid looping through numbers multiple times by using a SortFilterProxyModel in phonebook.
for (auto &number : addressee.phoneNumbers()) {
if (!number.number().isEmpty()) {
QAction *callAction = new QAction(QIcon::fromTheme("call-start"),
i18nc("Action to tell user to call person using phone number", "Call on %1", number.number()));
callAction->setProperty("actionType", KPeople::AudioCallAction);
actions << callAction;
}
}
for (auto &number : addressee.phoneNumbers()) {
if (!number.number().isEmpty()) {
QAction *textAction = new QAction(QIcon::fromTheme("mail-message"),
i18nc("Action to tell user to write a message to phone number", "Write SMS on %1", number.number()));
textAction->setProperty("actionType", KPeople::TextChatAction);
actions << textAction;
}
}
// Instant messenger actions
for (auto &impp : addressee.imppList()) {
QAction *action = new QAction(QIcon::fromTheme(impp.serviceIcon()),
i18nc("Action to write xmpp message", "%1 %2", impp.serviceType(), impp.address().toString()));
action->setProperty("actionType", KPeople::TextChatAction);
actions << action;
}
// email actions
for (auto &email : addressee.emails()) {
QAction *action = new QAction(QIcon::fromTheme("mail-message"), i18nc("Action to send an email", "email %1", email));
action->setProperty("actionType", KPeople::SendEmailAction);
actions << action;
}
return actions;
}
......
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