Commit cf2af1f1 authored by camilo higuita's avatar camilo higuita

conatcts can now be updated

parent 6eebf6ef
......@@ -20,29 +20,32 @@ include(ECMInstallIcons)
include(FeatureSummary)
include(ECMAddAppIcon)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/src/interfaces
${CMAKE_CURRENT_BINARY_DIR}/src/interfaces
${CMAKE_CURRENT_SOURCE_DIR}/src/models
${CMAKE_CURRENT_BINARY_DIR}/src/models
)
set(dialer_SRCS
src/main.cpp
src/interfaces/synchroniser.cpp
src/db/db.cpp
src/db/dbactions.cpp
src/models/baselist.cpp
src/models/basemodel.cpp
src/models/contacts/contactsmodel.cpp
src/models/contacts/calllogs.cpp
src/interfaces/kcontactsinterface.cpp
src/interfaces/linuxinterface.cpp
src/interfaces/contactimage.cpp
)
set(dialer_HDRS
src/union.h
src/db/db.h
src/db/dbactions.h
src/interfaces/synchroniser.h
src/models/baselist.h
src/models/basemodel.h
src/models/contacts/contactsmodel.h
src/models/contacts/calllogs.h
src/interfaces/kcontactsinterface.h
src/interfaces/abstractinterface.h
src/interfaces/linuxinterface.h
src/interfaces/contactimage.h
)
......
......@@ -47,20 +47,47 @@ void LinuxInterface::getContacts()
this->m_contacts << FMH::MODEL {
{FMH::MODEL_KEY::ID, person.personUri()},
{FMH::MODEL_KEY::N, person.name()},
{FMH::MODEL_KEY::EMAIL, person.email()},
{FMH::MODEL_KEY::TEL, person.contactCustomProperty("phoneNumber").toString()},
{FMH::MODEL_KEY::PHOTO, person.pictureUrl().toString()}};
qDebug() << person.pictureUrl();
}
{FMH::MODEL_KEY::FAV, person.contactCustomProperty(FMH::MODEL_NAME[FMH::MODEL_KEY::FAV]).toString()},
{FMH::MODEL_KEY::EMAIL, person.email()},
{FMH::MODEL_KEY::TEL, person.contactCustomProperty("phoneNumber").toString()},
{FMH::MODEL_KEY::PHOTO, person.pictureUrl().toString()}};
}
emit this->contactsReady(this->m_contacts);
emit this->contactsReady(this->m_contacts);
}
FMH::MODEL LinuxInterface::getContact(const QString &id)
{
return FMH::MODEL();
FMH::MODEL res;
auto personUri = id;
if (!(QUrl(personUri).scheme() == "vcard")) {
qWarning() << "uri of contact to update is not a vcard, cannot update.";
return res;
}
QFile file(personUri.remove("vcard:/"));
if (!(file.exists())) {
qWarning() << "Can't read vcard, file doesn't exist";
return res;
}
if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
qWarning() << "Couldn't update vCard: Couldn't open file for reading / writing.";
return res;
}
VCardConverter converter;
Addressee adr = converter.parseVCard(file.readAll());
res = {
{FMH::MODEL_KEY::ID, id},
{FMH::MODEL_KEY::N, adr.name()},
// {FMH::MODEL_KEY::FAV, adr.customs()},
{FMH::MODEL_KEY::EMAIL, adr.emails().join(",")},
{FMH::MODEL_KEY::TEL, adr.phoneNumber(PhoneNumber::Cell).toString()},
{FMH::MODEL_KEY::PHOTO, adr.photo().url()}};
return res;
}
bool LinuxInterface::insertContact(const FMH::MODEL &contact)
......@@ -69,33 +96,27 @@ bool LinuxInterface::insertContact(const FMH::MODEL &contact)
// addresses
Addressee adr;
adr.setName(contact[FMH::MODEL_KEY::N]);
adr.setUid(contact[FMH::MODEL_KEY::ID]);
adr.setUrl(contact[FMH::MODEL_KEY::URL]);
adr.setNote(contact[FMH::MODEL_KEY::NOTE]);
adr.setTitle(contact[FMH::MODEL_KEY::TITLE]);
adr.setOrganization(contact[FMH::MODEL_KEY::ORG]);
adr.setGender(contact[FMH::MODEL_KEY::GENDER]);
adr.setCustoms({QString("fav:%1").arg(contact[FMH::MODEL_KEY::FAV])});
adr.setCustoms({QString("%1:%2").arg(FMH::MODEL_NAME[FMH::MODEL_KEY::FAV], contact[FMH::MODEL_KEY::FAV])});
Email::List emailList;
Email email;
email.setEmail(contact[FMH::MODEL_KEY::EMAIL]);
emailList << email;
adr.setEmailList(emailList);
adr.setEmailList({email});
Picture photo;
photo.setUrl(contact[FMH::MODEL_KEY::PHOTO]);
adr.setPhoto(photo);
adr.setTitle(contact[FMH::MODEL_KEY::TITLE]);
adr.setOrganization(contact[FMH::MODEL_KEY::ORG]);
adr.setGender(contact[FMH::MODEL_KEY::GENDER]);
PhoneNumber::List phoneNums;
PhoneNumber phoneNum;
phoneNum.setNumber(contact[FMH::MODEL_KEY::TEL]);
phoneNum.setType(PhoneNumber::Cell);
phoneNums.append(phoneNum);
adr.setPhoneNumbers(phoneNums);
adr.setPhoneNumbers({phoneNum});
// create vcard
VCardConverter converter;
......@@ -119,15 +140,120 @@ bool LinuxInterface::insertContact(const FMH::MODEL &contact)
bool LinuxInterface::updateContact(const QString &id, const FMH::MODEL &contact)
{
return false;
auto personUri = id;
if (!(QUrl(personUri).scheme() == "vcard")) {
qWarning() << "uri of contact to update is not a vcard, cannot update.";
return false;
}
QFile file(personUri.remove("vcard:/"));
if (!(file.exists())) {
qWarning() << "Can't read vcard, file doesn't exist";
return false;
}
if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
qWarning() << "Couldn't update vCard: Couldn't open file for reading / writing.";
return false;
}
VCardConverter converter;
Addressee adr = converter.parseVCard(file.readAll());
for(const auto &key : contact.keys())
{
const auto data = contact[key];
qDebug()<< "updating filed:" << key << data;
switch(key)
{
case FMH::MODEL_KEY::N:
{
if (!data.isEmpty())
adr.setName(data);
break;
}
case FMH::MODEL_KEY::TEL:
{
PhoneNumber::List phoneNums;
PhoneNumber phoneNum;
phoneNum.setNumber(data);
phoneNum.setType(PhoneNumber::Cell);
phoneNums.append(phoneNum);
adr.setPhoneNumbers(phoneNums);
break;
}
case FMH::MODEL_KEY::ORG:
{
adr.setOrganization(data);
break;
}
case FMH::MODEL_KEY::TITLE:
{
adr.setTitle(data);
break;
}
case FMH::MODEL_KEY::FAV:
{
adr.setCustoms({QString("%1:%2").arg(FMH::MODEL_NAME[FMH::MODEL_KEY::FAV],data)});
break;
}
case FMH::MODEL_KEY::EMAIL:
{
Email email;
email.setEmail(data);
adr.setEmailList({email});
break;
}
case FMH::MODEL_KEY::NOTE:
{
adr.setNote(data);
break;
}
case FMH::MODEL_KEY::GENDER:
{
adr.setGender(data);
break;
}
case FMH::MODEL_KEY::PHOTO:
{
Picture photo;
photo.setUrl(data);
adr.setPhoto(photo);
break;
}
case FMH::MODEL_KEY::URL:
{
adr.setUrl(data);
break;
}
default: break;
}
}
QByteArray vcard = converter.createVCard(adr);
qDebug() << vcard;
file.write(vcard);
file.close();
return true;
}
bool LinuxInterface::removeContact(const QString &id)
{
if (!(QUrl(id).scheme() == "vcard")) {
qWarning() << "uri of contact to remove is not a vcard, cannot remove.";
return false;
}
qWarning() << "uri of contact to remove is not a vcard, cannot remove.";
return false;
}
return QFile::remove(QString(id).remove("vcard:/"));
return QFile::remove(QString(id).remove("vcard:/"));
}
......@@ -240,8 +240,8 @@ Maui.ApplicationWindow
id: _newContactDialog
onNewContact:
{
_contacsView.list.insert(con)
notify("list-add-user", qsTr("New contact added"), con.n)
_contacsView.list.insert(contact)
notify("list-add-user", qsTr("New contact added"), contact.n)
}
}
......
......@@ -185,6 +185,8 @@ bool ContactsModel::update(const QVariantMap &map, const int &index)
const auto newItem = FM::toModel(map);
const auto oldItem = this->list[index];
auto updatedItem = FMH::MODEL();
updatedItem[FMH::MODEL_KEY::ID] = oldItem[FMH::MODEL_KEY::ID];
......@@ -198,7 +200,9 @@ bool ContactsModel::update(const QVariantMap &map, const int &index)
}
}
this->syncer->updateContact(updatedItem[FMH::MODEL_KEY::ID], updatedItem);
qDebug()<< "trying to update contact:" << oldItem << "\n\n" << newItem << "\n\n" << updatedItem;
this->syncer->updateContact(oldItem[FMH::MODEL_KEY::ID], newItem);
this->list[index] = newItem;
emit this->updateModel(index, roles);
......
......@@ -7,7 +7,6 @@
<file>views/contacts/EditContactDialog.qml</file>
<file>views/dialer/Dialer.qml</file>
<file>views/dialer/DialerView.qml</file>
<file>db/script.sql</file>
<file>widgets/MessageComposer.qml</file>
<file>views/contacts/GridContactDelegate.qml</file>
<file>views/logs/LogsView.qml</file>
......
......@@ -150,11 +150,9 @@ Maui.Dialog
var id = control.contact.id
con["id"] = id
console.log("trying to edit contact", id)
_contacsView.list.update(con, _contacsView.listView.currentIndex)
control.contact = _contacsView.list.get(_contacsView.listView.currentIndex)
list.update(con, view.currentIndex)
control.contact = list.get(view.currentIndex)
_editContactDialog.close()
}
headBar.drawBorder: false
......
......@@ -33,8 +33,8 @@ linux:unix:!android {
DEFINES += STATIC_KIRIGAMI
SOURCES += src/interfaces/androidintents.cpp
HEADERS += src/interfaces/androidintents.h
SOURCES +=
HEADERS +=
} else {
message("Unknown configuration")
......@@ -42,14 +42,13 @@ linux:unix:!android {
SOURCES += \
$$PWD/src/main.cpp \
src/interfaces/androidinterface.cpp \
src/interfaces/contactimage.cpp \
src/models/baselist.cpp \
src/models/basemodel.cpp \
src/models/contacts/calllogs.cpp \
src/models/contacts/contactsmodel.cpp \
src/interfaces/synchroniser.cpp \
src/db/db.cpp \
src/db/dbactions.cpp \
RESOURCES += \
$$PWD/src/qml.qrc \
......@@ -60,11 +59,11 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
src/interfaces/abstractinterface.h \
src/interfaces/androidinterface.h \
src/interfaces/contactimage.h \
src/models/contacts/calllogs.h \
src/union.h \
src/db/db.h \
src/db/dbactions.h \
src/models/baselist.h \
src/models/basemodel.h \
src/models/contacts/contactsmodel.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