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

Add support for multiple emails and phone numbers

parent d02123c6
......@@ -18,7 +18,7 @@
*/
import QtQuick 2.6
import QtQuick.Controls 2.2
import QtQuick.Controls 2.2 as Controls
import QtQuick.Layouts 1.2
import org.kde.kirigami 2.4 as Kirigami
import org.kde.people 1.0 as KPeople
......@@ -49,43 +49,77 @@ Kirigami.Page {
main: Kirigami.Action {
icon.name: "dialog-ok-apply"
text: i18n("Save")
enabled: firstname.text !== ""
onTriggered: {
var emailList = []
for (var index in email.children)
emailList.push(email.children[index].text)
var phoneNumberList = []
for (var index in phoneNumber.children)
phoneNumberList.push(phoneNumber.children[index].text)
if (root.state === "create") {
phonebook.addContact(firstname.text + " " + lastname.text, phoneNumber.text, email.text)
phonebook.addContact(firstname.text + " " + lastname.text, phoneNumberList, emailList)
}
else if (root.state === "update") {
phonebook.updateContact(root.personUri, firstname.text + " " + lastname.text, phoneNumber.text, email.text)
phonebook.updateContact(root.personUri, firstname.text + " " + lastname.text, phoneNumberList, emailList)
}
pageStack.pop()
}
}
}
// TextField for dynamic creation
Component {
id: textFieldComponent
Controls.TextField {
}
}
Kirigami.FormLayout {
id: form
anchors.fill: parent
TextField {
Controls.TextField {
Kirigami.FormData.label: i18n("First name:")
// FIXME PersonData doesn't have separate first/last name
text: personUri ? personData.person.name.split(" ")[0] : ""
id: firstname
}
TextField {
Controls.TextField {
Kirigami.FormData.label: i18n("Last name:")
// FIXME KPeople doesn't have separate first/last name
text: personUri ? personData.person.name.split(" ")[1] : ""
id: lastname
}
TextField {
ColumnLayout {
id: phoneNumber
Kirigami.FormData.label: i18n("Phone:")
// FIXME PersonData doesn't have phonenumber property
Controls.TextField {
// FIXME PersonData doesn't have phonenumber property
}
}
TextField {
Controls.Button {
text: "Add more"
onClicked: textFieldComponent.createObject(phoneNumber)
}
ColumnLayout {
id: email
Kirigami.FormData.label: i18n("Email:")
// FIXME PersonData doesn't have email property
Controls.TextField {
placeholderText: i18n("user@example.org")
// FIXME PersonData doesn't have email property
}
}
Controls.Button {
text: "Add more"
onClicked: textFieldComponent.createObject(email, { placeholderText: i18n("user@example.org") })
}
}
}
......@@ -33,23 +33,26 @@ PhoneBook::PhoneBook(QObject *parent) : QObject(parent)
}
void PhoneBook::addContact(QString name, QString tel, QString email)
void PhoneBook::addContact(const QString name, const QStringList tels, const QStringList emails)
{
// addresses
Addressee adr;
adr.setName(name);
if (!email.isEmpty()) {
adr.setEmails(QStringList(email));
if (!emails.isEmpty()) {
adr.setEmails(emails);
}
if (!tel.isEmpty()) {
if (!tels.isEmpty()) {
PhoneNumber::List phoneNums;
PhoneNumber phoneNum;
phoneNum.setNumber(tel);
phoneNum.setType(PhoneNumber::Cell);
phoneNums.append(phoneNum);
adr.setPhoneNumbers(phoneNums);
for (const QString &tel : tels) {
PhoneNumber phoneNum;
phoneNum.setNumber(tel);
phoneNum.setType(PhoneNumber::Cell);
phoneNums.append(phoneNum);
}
adr.setPhoneNumbers(phoneNums);
}
// create vcard
......@@ -81,7 +84,7 @@ void PhoneBook::deleteContact(QString personUri)
QFile::remove(personUri.remove("vcard:/"));
}
void PhoneBook::updateContact(QString personUri, QString name, QString tel, QString email)
void PhoneBook::updateContact(QString personUri, const QString name, const QStringList tels, const QStringList emails)
{
if (!(QUrl(personUri).scheme() == "vcard")) {
qWarning() << "uri of contact to update is not a vcard, cannot update.";
......@@ -105,17 +108,20 @@ void PhoneBook::updateContact(QString personUri, QString name, QString tel, QStr
adr.setName(name);
}
if (!tel.isEmpty()) {
if (!tels.isEmpty()) {
PhoneNumber::List phoneNums;
PhoneNumber phoneNum;
phoneNum.setNumber(tel);
phoneNum.setType(PhoneNumber::Cell);
phoneNums.append(phoneNum);
adr.setPhoneNumbers(phoneNums);
for (const QString &tel : tels) {
PhoneNumber phoneNum;
phoneNum.setNumber(tel);
phoneNum.setType(PhoneNumber::Cell);
phoneNums.append(phoneNum);
}
adr.setPhoneNumbers(phoneNums);
}
if (!email.isEmpty()) {
adr.setEmails(QStringList(email));
if (!emails.isEmpty()) {
adr.setEmails(emails);
}
QByteArray vcard = converter.createVCard(adr);
......
......@@ -32,9 +32,9 @@ public:
signals:
public slots:
void addContact(QString name, QString tel, QString email);
void addContact(QString const name, const QStringList tels, const QStringList emails);
void deleteContact(QString personUri);
void updateContact(QString personUri, QString name, QString tel, QString email);
void updateContact(QString personUri, const QString name, const QStringList tels, const QStringList emails);
};
#endif // PHONEBOOK_H
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