Commit 7339b7e4 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Handle presence.

parent 28815a2e
......@@ -90,6 +90,8 @@ set(SOURCES
src/components/core/CoreHandlers.cpp
src/components/core/CoreManager.cpp
src/components/notifier/Notifier.cpp
src/components/presence/Presence.cpp
src/components/presence/PresenceStatusModel.cpp
src/components/settings/AccountSettingsModel.cpp
src/components/settings/SettingsModel.cpp
src/components/sip-addresses/SipAddressesModel.cpp
......@@ -121,6 +123,7 @@ set(HEADERS
src/components/core/CoreManager.hpp
src/components/notifier/Notifier.hpp
src/components/presence/Presence.hpp
src/components/presence/PresenceStatusModel.hpp
src/components/settings/AccountSettingsModel.hpp
src/components/settings/SettingsModel.hpp
src/components/sip-addresses/SipAddressesModel.hpp
......
<?xml version="1.0" encoding="UTF-8"?>
<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 40.3 (33839) - http://www.bohemiancoding.com/sketch -->
<title>status_username_available</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Symbols" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="status_username_available">
<circle fill="#9ECD1D" transform="translate(8.000000, 8.000000) rotate(-180.000000) translate(-8.000000, -8.000000) " cx="8" cy="8" r="8"></circle>
<path d="M6.28571429,12 L9.71428571,8.57142857 M6.28859181,5.14285714 L9.71428571,8.57142857" stroke="#FFFFFF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" transform="translate(8.000000, 8.571429) rotate(-270.000000) translate(-8.000000, -8.571429) "></path>
</g>
</g>
</svg>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 40.3 (33839) - http://www.bohemiancoding.com/sketch -->
<title>status_username_absent</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Symbols" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="status_username_absent">
<circle fill="#EFAE00" transform="translate(8.000000, 8.000000) rotate(-180.000000) translate(-8.000000, -8.000000) " cx="8" cy="8" r="8"></circle>
<path d="M6.28571429,12 L9.71428571,8.57142857 M6.28859181,5.14285714 L9.71428571,8.57142857" stroke="#FFFFFF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" transform="translate(8.000000, 8.571429) rotate(-270.000000) translate(-8.000000, -8.571429) "></path>
</g>
</g>
</svg>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 40.3 (33839) - http://www.bohemiancoding.com/sketch -->
<title>status_username_busy</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Symbols" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="status_username_busy">
<circle fill="#DC4100" transform="translate(8.000000, 8.000000) rotate(-180.000000) translate(-8.000000, -8.000000) " cx="8" cy="8" r="8"></circle>
<path d="M6.28571429,12 L9.71428571,8.57142857 M6.28859181,5.14285714 L9.71428571,8.57142857" stroke="#FFFFFF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" transform="translate(8.000000, 8.571429) rotate(-270.000000) translate(-8.000000, -8.571429) "></path>
</g>
</g>
</svg>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 40.3 (33839) - http://www.bohemiancoding.com/sketch -->
<title>status_username_disconnected</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Symbols" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="status_username_disconnected">
<circle fill="#B1B1B1" transform="translate(8.000000, 8.000000) rotate(-180.000000) translate(-8.000000, -8.000000) " cx="8" cy="8" r="8"></circle>
<path d="M6.28571429,12 L9.71428571,8.57142857 M6.28859181,5.14285714 L9.71428571,8.57142857" stroke="#FFFFFF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" transform="translate(8.000000, 8.571429) rotate(-270.000000) translate(-8.000000, -8.571429) "></path>
</g>
</g>
</svg>
\ No newline at end of file
......@@ -586,48 +586,28 @@ Server url not configured.</translation>
<source>selectAccountLabel</source>
<translation type="unfinished">Select you active account</translation>
</message>
<message>
<source>selectPresenceLabel</source>
<translation>Select a presence status</translation>
</message>
</context>
<context>
<name>PresenceString</name>
<name>Presence</name>
<message>
<source>presenceOnline</source>
<translation type="unfinished"></translation>
<translation>Available</translation>
</message>
<message>
<source>presenceOutToLunch</source>
<translation type="unfinished"></translation>
<source>presenceBusy</source>
<translation>Busy</translation>
</message>
<message>
<source>presenceDoNotDisturb</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>presenceMoved</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>presenceUsingAnotherMessagingService</source>
<translation type="unfinished"></translation>
<translation>Do not disturb</translation>
</message>
<message>
<source>presenceOffline</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>presenceUnknown</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>presenceBeRightBack</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>presenceAway</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>presenceOnThePhone</source>
<translation type="unfinished"></translation>
<translation>Offline</translation>
</message>
</context>
<context>
......
......@@ -586,48 +586,39 @@ Url du serveur non configurée.</translation>
<source>selectAccountLabel</source>
<translation type="unfinished">Sélectionner votre compte principal</translation>
</message>
<message>
<source>selectPresenceLabel</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PresenceString</name>
<name>Presence</name>
<message>
<source>presenceOnline</source>
<translation>En ligne</translation>
<translation type="unfinished">En ligne</translation>
</message>
<message>
<source>presenceOutToLunch</source>
<source>presenceBusy</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>presenceDoNotDisturb</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>presenceMoved</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>presenceUsingAnotherMessagingService</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>presenceOffline</source>
<translation>Hors-ligne</translation>
</message>
<message>
<source>presenceUnknown</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>presenceBeRightBack</source>
<translation type="unfinished"></translation>
<translation type="unfinished">Hors-ligne</translation>
</message>
</context>
<context>
<name>PresenceString</name>
<message>
<source>presenceAway</source>
<translation type="unfinished"></translation>
<source>presenceOnline</source>
<translation type="vanished">En ligne</translation>
</message>
<message>
<source>presenceOnThePhone</source>
<translation type="unfinished"></translation>
<source>presenceOffline</source>
<translation type="vanished">Hors-ligne</translation>
</message>
</context>
<context>
......
......@@ -45,10 +45,6 @@
<file>assets/images/chat_normal.svg</file>
<file>assets/images/chat_pressed.svg</file>
<file>assets/images/chat_send.svg</file>
<file>assets/images/chevron_green.svg</file>
<file>assets/images/chevron_orange.svg</file>
<file>assets/images/chevron_red.svg</file>
<file>assets/images/chevron_white.svg</file>
<file>assets/images/collapse.svg</file>
<file>assets/images/contact_add_hovered.svg</file>
<file>assets/images/contact_add_normal.svg</file>
......@@ -283,7 +279,6 @@
<file>ui/modules/Linphone/Notifications/NotificationReceivedFileMessage.qml</file>
<file>ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml</file>
<file>ui/modules/Linphone/Presence/PresenceLevel.qml</file>
<file>ui/modules/Linphone/Presence/PresenceString.qml</file>
<file>ui/modules/Linphone/qmldir</file>
<file>ui/modules/Linphone/SmartSearchBar.qml</file>
<file>ui/modules/Linphone/Styles/Account/AccountStatusStyle.qml</file>
......@@ -300,7 +295,6 @@
<file>ui/modules/Linphone/Styles/Notifications/NotificationReceivedFileMessageStyle.qml</file>
<file>ui/modules/Linphone/Styles/Notifications/NotificationReceivedMessageStyle.qml</file>
<file>ui/modules/Linphone/Styles/Notifications/NotificationStyle.qml</file>
<file>ui/modules/Linphone/Styles/Presence/PresenceStringStyle.qml</file>
<file>ui/modules/Linphone/Styles/qmldir</file>
<file>ui/modules/Linphone/Styles/SmartSearchBarStyle.qml</file>
<file>ui/modules/Linphone/Styles/TimelineStyle.qml</file>
......
......@@ -25,6 +25,7 @@
#include "../components/chat/ChatProxyModel.hpp"
#include "../components/contacts/ContactsListProxyModel.hpp"
#include "../components/core/CoreManager.hpp"
#include "../components/presence/PresenceStatusModel.hpp"
#include "../components/settings/AccountSettingsModel.hpp"
#include "../components/smart-search-bar/SmartSearchBarModel.hpp"
#include "../components/timeline/TimelineModel.hpp"
......@@ -248,9 +249,6 @@ void App::registerTypes () {
qmlRegisterUncreatableType<ContactObserver>(
"Linphone", 1, 0, "ContactObserver", "ContactObserver is uncreatable."
);
qmlRegisterUncreatableType<Presence>(
"Linphone", 1, 0, "Presence", "Presence is uncreatable."
);
qmlRegisterUncreatableType<VcardModel>(
"Linphone", 1, 0, "VcardModel", "VcardModel is uncreatable."
);
......@@ -290,6 +288,20 @@ void App::registerTypes () {
}
);
qmlRegisterSingletonType<Presence>(
"Linphone", 1, 0, "Presence",
[](QQmlEngine *, QJSEngine *) -> QObject *{
return new Presence();
}
);
qmlRegisterSingletonType<PresenceStatusModel>(
"Linphone", 1, 0, "PresenceStatusModel",
[](QQmlEngine *, QJSEngine *) -> QObject *{
return new PresenceStatusModel();
}
);
qmlRegisterSingletonType<SettingsModel>(
"Linphone", 1, 0, "SettingsModel",
[](QQmlEngine *, QJSEngine *) -> QObject *{
......
......@@ -35,6 +35,7 @@ ContactModel::ContactModel (shared_ptr<linphone::Friend> linphone_friend) {
m_vcard = make_shared<VcardModel>(linphone_friend->getVcard());
App::getInstance()->getEngine()->setObjectOwnership(m_vcard.get(), QQmlEngine::CppOwnership);
m_linphone_friend->setData("contact-model", *this);
}
ContactModel::ContactModel (VcardModel *vcard) {
......@@ -48,6 +49,12 @@ ContactModel::ContactModel (VcardModel *vcard) {
engine->setObjectOwnership(vcard, QQmlEngine::CppOwnership);
}
void ContactModel::presenceReceived () {
Presence::PresenceStatus status = static_cast<Presence::PresenceStatus>(m_linphone_friend->getConsolidatedPresence());
emit presenceStatusChanged(status);
emit presenceLevelChanged(Presence::getPresenceLevel(status));
}
void ContactModel::startEdit () {
m_linphone_friend->edit();
m_old_sip_addresses = m_vcard->getSipAddresses();
......@@ -98,7 +105,7 @@ void ContactModel::abortEdit () {
}
Presence::PresenceStatus ContactModel::getPresenceStatus () const {
return Presence::PresenceStatus::Offline;
return static_cast<Presence::PresenceStatus>(m_linphone_friend->getConsolidatedPresence());
}
Presence::PresenceLevel ContactModel::getPresenceLevel () const {
......
......@@ -31,8 +31,8 @@
class ContactModel : public QObject {
Q_OBJECT;
Q_PROPERTY(Presence::PresenceStatus presenceStatus READ getPresenceStatus NOTIFY contactUpdated);
Q_PROPERTY(Presence::PresenceLevel presenceLevel READ getPresenceLevel NOTIFY contactUpdated);
Q_PROPERTY(Presence::PresenceStatus presenceStatus READ getPresenceStatus NOTIFY presenceStatusChanged);
Q_PROPERTY(Presence::PresenceLevel presenceLevel READ getPresenceLevel NOTIFY presenceLevelChanged);
Q_PROPERTY(VcardModel * vcard READ getVcardModelPtr NOTIFY contactUpdated);
friend class ContactsListModel;
......@@ -48,12 +48,16 @@ public:
return m_vcard;
}
void presenceReceived ();
Q_INVOKABLE void startEdit ();
Q_INVOKABLE void endEdit ();
Q_INVOKABLE void abortEdit ();
signals:
void contactUpdated ();
void presenceStatusChanged (Presence::PresenceStatus status);
void presenceLevelChanged (Presence::PresenceLevel level);
void sipAddressAdded (const QString &sip_address);
void sipAddressRemoved (const QString &sip_address);
......
......@@ -67,6 +67,16 @@ void CoreHandlers::onMessageReceived (
}
}
void CoreHandlers::onNotifyPresenceReceivedForUriOrTel (
const shared_ptr<linphone::Core> &,
const shared_ptr<linphone::Friend> &lf,
const string &,
const shared_ptr<linphone::PresenceModel> &
) {
ContactModel *contact_model = &lf->getData<ContactModel>("contact-model");
if (contact_model) contact_model->presenceReceived();
}
void CoreHandlers::onRegistrationStateChanged (
const shared_ptr<linphone::Core> &core,
const shared_ptr<linphone::ProxyConfig> &config,
......
......@@ -57,6 +57,13 @@ private:
const std::shared_ptr<linphone::ChatMessage> &message
) override;
void onNotifyPresenceReceivedForUriOrTel (
const std::shared_ptr<linphone::Core> &lc,
const std::shared_ptr<linphone::Friend> &lf,
const std::string &uri_or_tel,
const std::shared_ptr<linphone::PresenceModel> &presence_model
) override;
void onRegistrationStateChanged (
const std::shared_ptr<linphone::Core> &core,
const std::shared_ptr<linphone::ProxyConfig> &config,
......
/*
* Presence.cpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: March 14, 2017
* Author: Ghislain MARY
*/
#include <QtDebug>
#include "Presence.hpp"
// =============================================================================
Presence::PresenceLevel Presence::getPresenceLevel (const PresenceStatus &status) {
switch (status) {
case Online:
return Green;
case Busy:
return Orange;
case DoNotDisturb:
return Red;
case Offline:
default:
return White;
}
}
QString Presence::getPresenceStatusAsString (const PresenceStatus &status) {
switch (status) {
case Online:
return tr("presenceOnline");
case Busy:
return tr("presenceBusy");
case DoNotDisturb:
return tr("presenceDoNotDisturb");
case Offline:
default:
return tr("presenceOffline");
}
}
QString Presence::getPresenceLevelIconName (const PresenceLevel &level) {
switch (level) {
case Green:
return "led_green";
case Orange:
return "led_orange";
case Red:
return "led_red";
case White:
default:
return "led_white";
}
}
......@@ -33,15 +33,10 @@ class Presence : public QObject {
public:
enum PresenceStatus {
Online,
BeRightBack,
Away,
OnThePhone,
OutToLunch,
DoNotDisturb,
Moved,
UsingAnotherMessagingService,
Offline
Online = linphone::ConsolidatedPresenceOnline,
Busy = linphone::ConsolidatedPresenceBusy,
DoNotDisturb = linphone::ConsolidatedPresenceDoNotDisturb,
Offline = linphone::ConsolidatedPresenceOffline
};
Q_ENUM(PresenceStatus);
......@@ -59,16 +54,9 @@ public:
~Presence () = default;
static PresenceLevel getPresenceLevel (const PresenceStatus &presenceStatus) {
if (presenceStatus == Online)
return Green;
if (presenceStatus == DoNotDisturb)
return Red;
if (presenceStatus == Offline)
return White;
return Orange;
}
static PresenceLevel getPresenceLevel (const PresenceStatus &status);
Q_INVOKABLE static QString getPresenceStatusAsString (const PresenceStatus &status);
Q_INVOKABLE static QString getPresenceLevelIconName (const PresenceLevel &level);
};
#endif // PRESENCE_H_
/*
* PresenceStatusModel.cpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: March 14, 2017
* Author: Ghislain MARY
*/
#include <QtDebug>
#include "../../utils.hpp"
#include "../core/CoreManager.hpp"
#include "PresenceStatusModel.hpp"
// =============================================================================
Presence::PresenceLevel PresenceStatusModel::getPresenceLevel () const {
return Presence::getPresenceLevel(getPresenceStatus());
}
Presence::PresenceStatus PresenceStatusModel::getPresenceStatus () const {
return static_cast<Presence::PresenceStatus>(CoreManager::getInstance()->getCore()->getConsolidatedPresence());
}
void PresenceStatusModel::setPresenceStatus (Presence::PresenceStatus status) {
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
core->setConsolidatedPresence(static_cast<linphone::ConsolidatedPresence>(status));
emit presenceStatusChanged(status);
emit presenceLevelChanged(Presence::getPresenceLevel(status));
}
// -----------------------------------------------------------------------------
QVariantList PresenceStatusModel::getStatuses () const {
QVariantList statuses;
QVariantMap online_status;
online_status["presenceLevel"] = Presence::Green;
online_status["presenceStatus"] = Presence::Online;
online_status["presenceIcon"] = Presence::getPresenceLevelIconName(Presence::Green);
online_status["presenceLabel"] = Presence::getPresenceStatusAsString(Presence::Online);
statuses << online_status;
QVariantMap busy_status;
busy_status["presenceLevel"] = Presence::Orange;
busy_status["presenceStatus"] = Presence::Busy;
busy_status["presenceIcon"] = Presence::getPresenceLevelIconName(Presence::Orange);
busy_status["presenceLabel"] = Presence::getPresenceStatusAsString(Presence::Busy);
statuses << busy_status;
QVariantMap do_not_disturb_status;
do_not_disturb_status["presenceLevel"] = Presence::Red;
do_not_disturb_status["presenceStatus"] = Presence::DoNotDisturb;
do_not_disturb_status["presenceIcon"] = Presence::getPresenceLevelIconName(Presence::Red);
do_not_disturb_status["presenceLabel"] = Presence::getPresenceStatusAsString(Presence::DoNotDisturb);
statuses << do_not_disturb_status;
QVariantMap offline_status;
offline_status["presenceLevel"] = Presence::White;
offline_status["presenceStatus"] = Presence::Offline;
offline_status["presenceIcon"] = Presence::getPresenceLevelIconName(Presence::White);
offline_status["presenceLabel"] = Presence::getPresenceStatusAsString(Presence::Offline);
statuses << offline_status;
return statuses;
}
/*
* PresenceStatusModel.hpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: March 14, 2017
* Author: Ghislain MARY
*/
#ifndef PRESENCE_STATUS_MODEL_H_
#define PRESENCE_STATUS_MODEL_H_
#include "../presence/Presence.hpp"
#include <QObject>
// =============================================================================
class PresenceStatusModel : public QObject {
Q_OBJECT;
Q_PROPERTY(QVariantList statuses READ