Commit e796f267 authored by camilo higuita's avatar camilo higuita

clean up work on the interfaces

parent c877080b
......@@ -76,55 +76,38 @@ static FMH::MODEL vCardData(const QString &url)
{FMH::MODEL_KEY::PHOTO, adr.photo().url()}
};
qDebug() << adr.toString();
// file.write(vcard);
file.close();
// return true;
return res;
}
void LinuxInterface::getContacts()
{
KPeople::PersonsModel model;
qDebug()<< "KPEOPLE CONTACTS" << model.rowCount();
QDir dir;
dir.setPath(this->path);
// for(auto url : dir.entryList({"*.vcf"}, QDir::Filter::Files))
// {
// qDebug()<< url;
// }
QDirIterator it(this->path, {"*.vcf"}, QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while(it.hasNext())
{
this->m_contacts << vCardData(it.next());
}
// for(auto i = 0 ; i< model.rowCount(); i++)
// {
// const auto uri = model.get(i, KPeople::PersonsModel::PersonUriRole).toString();
// KPeople::PersonData person(uri);
// this->m_contacts << FMH::MODEL {
// {FMH::MODEL_KEY::ID, person.personUri()},
// {FMH::MODEL_KEY::N, person.name()},
// {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()}};
//qDebug() << "CUSTOM RPOP" << person.contactCustomProperty(FMH::MODEL_NAME[FMH::MODEL_KEY::FAV]).toString();
//qDebug() << "CUSTOM RPOP" << person.contactCustomProperty("fav");
//qDebug()<< person.contactCustomProperty("phoneNumber").toString();
//}
emit this->contactsReady(this->m_contacts);
// KPeople::PersonsModel model;
// for(auto i = 0 ; i< model.rowCount(); i++)
// {
// const auto uri = model.get(i, KPeople::PersonsModel::PersonUriRole).toString();
// KPeople::PersonData person(uri);
// this->m_contacts << FMH::MODEL {
// {FMH::MODEL_KEY::ID, person.personUri()},
// {FMH::MODEL_KEY::N, person.name()},
// {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()}};
//qDebug() << "CUSTOM RPOP" << person.contactCustomProperty(FMH::MODEL_NAME[FMH::MODEL_KEY::FAV]).toString();
//qDebug() << "CUSTOM RPOP" << person.contactCustomProperty("fav");
//qDebug()<< person.contactCustomProperty("phoneNumber").toString();
//}
emit this->contactsReady(this->m_contacts);
}
FMH::MODEL LinuxInterface::getContact(const QString &id)
......@@ -133,27 +116,10 @@ FMH::MODEL LinuxInterface::getContact(const QString &id)
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";
qWarning() << "uri of contact is not a vcard, cannot get contact.";
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 = {
};
return res;
return vCardData(personUri.remove("vcard:/"));
}
bool LinuxInterface::insertContact(const FMH::MODEL &contact)
......@@ -162,7 +128,7 @@ 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.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]);
......@@ -316,7 +282,8 @@ bool LinuxInterface::updateContact(const QString &id, const FMH::MODEL &contact)
bool LinuxInterface::removeContact(const QString &id)
{
if (!(QUrl(id).scheme() == "vcard")) {
if (!(QUrl(id).scheme() == "vcard"))
{
qWarning() << "uri of contact to remove is not a vcard, cannot remove.";
return false;
}
......
......@@ -44,6 +44,12 @@ public:
bool removeContact(const QString &id) override final;
/**
* @brief contactPhoto is a static function to be used with the contactImage provider,
* it takes the id of the contact and then looks for the photo url in the vcard
* @param id of the vcard, it is the vcard filename for now
* @return returns a QImage to be used with the contactImage provider
*/
static QImage contactPhoto(const QString &id);
private:
......
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