Commit 7af0cb82 authored by Sébastien Blin's avatar Sébastien Blin

contactModel: use profileReceived signal

Change-Id: I91c3a81b78a4b2faad0979b59139f46594d1005a
parent d44a6567
......@@ -181,6 +181,14 @@ public Q_SLOTS:
* @param transferInfo DataTransferInfo structure from daemon
*/
void slotNewAccountTransfer(long long dringId, datatransfer::Info info);
/**
* Listen from daemon to know when a VCard is received
* @param accountId
* @param peer
* @param vCard
*/
void slotProfileReceived(const QString& accountId, const QString& peer, const QString& vCard);
};
using namespace authority;
......@@ -484,6 +492,8 @@ ContactModelPimpl::ContactModelPimpl(const ContactModel& linked,
this, &ContactModelPimpl::slotNewAccountMessage);
connect(&callbacksHandler, &CallbacksHandler::transferStatusCreated,
this, &ContactModelPimpl::slotNewAccountTransfer);
connect(&ConfigurationManager::instance(), &ConfigurationManagerInterface::profileReceived,
this, &ContactModelPimpl::slotProfileReceived);
}
ContactModelPimpl::~ContactModelPimpl()
......@@ -504,6 +514,8 @@ ContactModelPimpl::~ContactModelPimpl()
this, &ContactModelPimpl::slotNewAccountMessage);
disconnect(&callbacksHandler, &CallbacksHandler::transferStatusCreated,
this, &ContactModelPimpl::slotNewAccountTransfer);
disconnect(&ConfigurationManager::instance(), &ConfigurationManagerInterface::profileReceived,
this, &ContactModelPimpl::slotProfileReceived);
}
bool
......@@ -969,6 +981,35 @@ ContactModelPimpl::slotNewAccountTransfer(long long dringId, datatransfer::Info
emit linked.newAccountTransfer(dringId, info);
}
void
ContactModelPimpl::slotProfileReceived(const QString& accountId, const QString& peer, const QString& path)
{
if (accountId != linked.owner.id) return;
QFile vCardFile(path);
if (!vCardFile.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&vCardFile);
auto vCard = in.readAll();
vCardFile.remove();
profile::Info profileInfo;
profileInfo.uri = peer;
profileInfo.type = profile::Type::RING;
for (auto& e : QString(vCard).split( "\n" ))
if (e.contains("PHOTO"))
profileInfo.avatar = e.split( ":" )[1];
else if (e.contains("FN"))
profileInfo.alias = e.split( ":" )[1];
contact::Info contactInfo;
contactInfo.profileInfo = profileInfo;
linked.owner.contactModel->addContact(contactInfo);
}
} // namespace lrc
#include "api/moc_contactmodel.cpp"
......
......@@ -168,6 +168,10 @@ public:
[this] (const std::string& account_id, const std::string& uri, const bool& confirmed) {
Q_EMIT this->contactAdded(QString(account_id.c_str()), QString(uri.c_str()), confirmed);
}),
exportable_callback<ConfigurationSignal::ProfileReceived>(
[this] (const std::string& accountID, const std::string& peer, const std::string& vCard) {
Q_EMIT this->profileReceived(QString(accountID.c_str()), QString(peer.c_str()), QString(vCard.c_str()));
}),
exportable_callback<ConfigurationSignal::ContactRemoved>(
[this] (const std::string& account_id, const std::string& uri, const bool& banned) {
Q_EMIT this->contactRemoved(QString(account_id.c_str()), QString(uri.c_str()), banned);
......@@ -748,6 +752,7 @@ Q_SIGNALS: // SIGNALS
void migrationEnded(const QString &accountID, const QString &result);
void contactAdded(const QString &accountID, const QString &uri, bool banned);
void contactRemoved(const QString &accountID, const QString &uri, bool banned);
void profileReceived(const QString &accountID, const QString &peer, const QString &vCard);
void dataTransferEvent(qulonglong transfer_id, uint code);
void deviceRevocationEnded(const QString& accountId, const QString& deviceId, int status);
void accountAvatarReceived(const QString& accountId, const QString& userPhoto);
......
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