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