ContactModel.cpp 1.41 KB
Newer Older
1 2
#include <QtDebug>

Ronan's avatar
Ronan committed
3 4 5 6 7 8 9 10 11 12 13 14
#include "../../app/App.hpp"

#include "ContactModel.hpp"

using namespace std;

// =============================================================================

const char *ContactModel::NAME = "contact-model";

ContactModel::ContactModel (shared_ptr<linphone::Friend> linphone_friend) {
  m_linphone_friend = linphone_friend;
15
  m_linphone_friend->setData(NAME, *this);
Ronan's avatar
Ronan committed
16 17 18
  m_vcard = make_shared<VcardModel>(linphone_friend->getVcard());

  App::getInstance()->getEngine()->setObjectOwnership(m_vcard.get(), QQmlEngine::CppOwnership);
19
  QObject::connect(m_vcard.get(), &VcardModel::vcardUpdated, this, &ContactModel::contactUpdated);
Ronan's avatar
Ronan committed
20 21
}

22 23 24 25 26 27 28 29 30 31
ContactModel::ContactModel (VcardModel *vcard) {
  QQmlEngine *engine = App::getInstance()->getEngine();
  if (engine->objectOwnership(vcard) == QQmlEngine::CppOwnership)
    throw std::invalid_argument("A contact is already linked to this vcard.");

  m_linphone_friend = linphone::Friend::newFromVcard(vcard->m_vcard);
  m_linphone_friend->setData(NAME, *this);
  m_vcard.reset(vcard);

  engine->setObjectOwnership(vcard, QQmlEngine::CppOwnership);
32
  QObject::connect(vcard, &VcardModel::vcardUpdated, this, &ContactModel::contactUpdated);
33 34
}

Ronan's avatar
Ronan committed
35 36 37 38 39 40 41
Presence::PresenceStatus ContactModel::getPresenceStatus () const {
  return Presence::PresenceStatus::Offline;
}

Presence::PresenceLevel ContactModel::getPresenceLevel () const {
  return Presence::getPresenceLevel(getPresenceStatus());
}