add friends manager
This commit is contained in:
parent
ac79b1de51
commit
9f4af14662
6 changed files with 297 additions and 87 deletions
|
|
@ -22,6 +22,7 @@ list(APPEND _LINPHONEAPP_SOURCES
|
||||||
model/core/CoreModel.cpp
|
model/core/CoreModel.cpp
|
||||||
|
|
||||||
model/friend/FriendModel.cpp
|
model/friend/FriendModel.cpp
|
||||||
|
model/friend/FriendsManager.cpp
|
||||||
|
|
||||||
model/listener/Listener.hpp
|
model/listener/Listener.hpp
|
||||||
|
|
||||||
|
|
|
||||||
118
Linphone/model/friend/FriendsManager.cpp
Normal file
118
Linphone/model/friend/FriendsManager.cpp
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2024 Belledonne Communications SARL.
|
||||||
|
*
|
||||||
|
* This file is part of linphone-desktop
|
||||||
|
* (see https://www.linphone.org).
|
||||||
|
*
|
||||||
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "FriendsManager.hpp"
|
||||||
|
|
||||||
|
#include "model/core/CoreModel.hpp"
|
||||||
|
#include "tool/Utils.hpp"
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
DEFINE_ABSTRACT_OBJECT(FriendsManager)
|
||||||
|
|
||||||
|
std::shared_ptr<FriendsManager> FriendsManager::gFriendsManager;
|
||||||
|
FriendsManager::FriendsManager(QObject *parent) : QObject(parent) {
|
||||||
|
moveToThread(CoreModel::getInstance()->thread());
|
||||||
|
}
|
||||||
|
|
||||||
|
FriendsManager::~FriendsManager() {
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<FriendsManager> FriendsManager::create(QObject *parent) {
|
||||||
|
auto model = std::make_shared<FriendsManager>(parent);
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<FriendsManager> FriendsManager::getInstance() {
|
||||||
|
if (!gFriendsManager) gFriendsManager = FriendsManager::create(nullptr);
|
||||||
|
return gFriendsManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap FriendsManager::getKnownFriends() const {
|
||||||
|
return mKnownFriends;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap FriendsManager::getUnknownFriends() const {
|
||||||
|
return mUnknownFriends;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList FriendsManager::getOtherAddresses() const {
|
||||||
|
return mOtherAddresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<linphone::Friend> FriendsManager::getKnownFriendAtKey(const QString& key) {
|
||||||
|
if (isInKnownFriends(key)) {
|
||||||
|
return mKnownFriends.value(key).value<std::shared_ptr<linphone::Friend>>();
|
||||||
|
} else return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<linphone::Friend> FriendsManager::getUnknownFriendAtKey(const QString& key) {
|
||||||
|
if (isInUnknownFriends(key)) {
|
||||||
|
return mUnknownFriends.value(key).value<std::shared_ptr<linphone::Friend>>();
|
||||||
|
} else return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FriendsManager::isInKnownFriends(const QString& key) {
|
||||||
|
return mKnownFriends.contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FriendsManager::isInUnknownFriends(const QString& key) {
|
||||||
|
return mUnknownFriends.contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FriendsManager::isInOtherAddresses(const QString& key) {
|
||||||
|
return mOtherAddresses.contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FriendsManager::appendKnownFriend(std::shared_ptr<linphone::Address> address, std::shared_ptr<linphone::Friend> f) {
|
||||||
|
auto key = Utils::coreStringToAppString(address->asStringUriOnly());
|
||||||
|
if (mKnownFriends.contains(key)) {
|
||||||
|
qDebug() << "friend is already in konwn list, return";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mKnownFriends.insert(key, QVariant::fromValue(f));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FriendsManager::appendUnknownFriend(std::shared_ptr<linphone::Address> address, std::shared_ptr<linphone::Friend> f) {
|
||||||
|
auto key = Utils::coreStringToAppString(address->asStringUriOnly());
|
||||||
|
if (mUnknownFriends.contains(key)) {
|
||||||
|
qDebug() << "friend is already in unkonwn list, return";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mUnknownFriends.insert(key, QVariant::fromValue(f));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FriendsManager::appendOtherAddress(QString address) {
|
||||||
|
if (mOtherAddresses.contains(address)) {
|
||||||
|
qDebug() << "friend is already in other addresses, return";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mOtherAddresses.append(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FriendsManager::removeUnknownFriend(const QString& key) {
|
||||||
|
mUnknownFriends.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FriendsManager::removeOtherAddress(const QString& key) {
|
||||||
|
mOtherAddresses.removeAll(key);
|
||||||
|
}
|
||||||
67
Linphone/model/friend/FriendsManager.hpp
Normal file
67
Linphone/model/friend/FriendsManager.hpp
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2024 Belledonne Communications SARL.
|
||||||
|
*
|
||||||
|
* This file is part of linphone-desktop
|
||||||
|
* (see https://www.linphone.org).
|
||||||
|
*
|
||||||
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FRIENDS_MANAGER_H_
|
||||||
|
#define FRIENDS_MANAGER_H_
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
#include <QThread>
|
||||||
|
#include <QVariantMap>
|
||||||
|
#include <linphone++/linphone.hh>
|
||||||
|
#include "tool/AbstractObject.hpp"
|
||||||
|
|
||||||
|
class FriendsManager : public QObject, public AbstractObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
FriendsManager(QObject *parent);
|
||||||
|
~FriendsManager();
|
||||||
|
static std::shared_ptr<FriendsManager> create(QObject *parent);
|
||||||
|
static std::shared_ptr<FriendsManager> getInstance();
|
||||||
|
|
||||||
|
QVariantMap getKnownFriends() const;
|
||||||
|
QVariantMap getUnknownFriends() const;
|
||||||
|
QStringList getOtherAddresses() const;
|
||||||
|
|
||||||
|
std::shared_ptr<linphone::Friend> getKnownFriendAtKey(const QString& key);
|
||||||
|
std::shared_ptr<linphone::Friend> getUnknownFriendAtKey(const QString& key);
|
||||||
|
|
||||||
|
bool isInKnownFriends(const QString& key);
|
||||||
|
bool isInUnknownFriends(const QString& key);
|
||||||
|
bool isInOtherAddresses(const QString& key);
|
||||||
|
|
||||||
|
void appendKnownFriend(std::shared_ptr<linphone::Address> address, std::shared_ptr<linphone::Friend> f);
|
||||||
|
void appendUnknownFriend(std::shared_ptr<linphone::Address> address, std::shared_ptr<linphone::Friend> f);
|
||||||
|
void appendOtherAddress(QString address);
|
||||||
|
|
||||||
|
void removeUnknownFriend(const QString& key);
|
||||||
|
void removeOtherAddress(const QString& key);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static std::shared_ptr<FriendsManager> gFriendsManager;
|
||||||
|
QVariantMap mKnownFriends;
|
||||||
|
QVariantMap mUnknownFriends;
|
||||||
|
QStringList mOtherAddresses;
|
||||||
|
//core model connection + reset unknown et other quand friend ajouté, supprimé, updated
|
||||||
|
DECLARE_ABSTRACT_OBJECT
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "model/core/CoreModel.hpp"
|
#include "model/core/CoreModel.hpp"
|
||||||
|
#include "model/friend/FriendsManager.hpp"
|
||||||
#include "model/setting/SettingsModel.hpp"
|
#include "model/setting/SettingsModel.hpp"
|
||||||
#include "model/tool/ToolModel.hpp"
|
#include "model/tool/ToolModel.hpp"
|
||||||
#include "tool/Utils.hpp"
|
#include "tool/Utils.hpp"
|
||||||
|
|
@ -83,6 +84,15 @@ void MagicSearchModel::onSearchResultsReceived(const std::shared_ptr<linphone::M
|
||||||
emit searchResultsReceived(results);
|
emit searchResultsReceived(results);
|
||||||
for (auto result : results) {
|
for (auto result : results) {
|
||||||
auto f = result->getFriend();
|
auto f = result->getFriend();
|
||||||
|
auto friendsManager = FriendsManager::getInstance();
|
||||||
|
if (f) {
|
||||||
|
qDebug() << "friend exists, append to unknown map";
|
||||||
|
auto friendAddress = f->getAddress();
|
||||||
|
friendsManager->appendUnknownFriend(friendAddress->clone(), f);
|
||||||
|
if (friendsManager->isInOtherAddresses(Utils::coreStringToAppString(friendAddress->asStringUriOnly()))) {
|
||||||
|
friendsManager->removeOtherAddress(Utils::coreStringToAppString(friendAddress->asStringUriOnly()));
|
||||||
|
}
|
||||||
|
}
|
||||||
auto fList = f ? f->getFriendList() : nullptr;
|
auto fList = f ? f->getFriendList() : nullptr;
|
||||||
|
|
||||||
// qDebug() << log().arg("") << (f ? f->getName().c_str() : "NoFriend") << ", "
|
// qDebug() << log().arg("") << (f ? f->getName().c_str() : "NoFriend") << ", "
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#include "core/App.hpp"
|
#include "core/App.hpp"
|
||||||
#include "core/path/Paths.hpp"
|
#include "core/path/Paths.hpp"
|
||||||
#include "model/core/CoreModel.hpp"
|
#include "model/core/CoreModel.hpp"
|
||||||
|
#include "model/friend/FriendsManager.hpp"
|
||||||
#include "tool/Utils.hpp"
|
#include "tool/Utils.hpp"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
|
|
@ -126,8 +127,29 @@ std::shared_ptr<linphone::Friend> ToolModel::findFriendByAddress(const QString &
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<linphone::Friend> ToolModel::findFriendByAddress(std::shared_ptr<linphone::Address> linphoneAddr) {
|
std::shared_ptr<linphone::Friend> ToolModel::findFriendByAddress(std::shared_ptr<linphone::Address> linphoneAddr) {
|
||||||
|
auto friendsManager = FriendsManager::getInstance();
|
||||||
|
QString key = Utils::coreStringToAppString(linphoneAddr->asStringUriOnly());
|
||||||
|
if (friendsManager->isInKnownFriends(key)) {
|
||||||
|
qDebug() << "Friend have been found in known friend, return it";
|
||||||
|
return friendsManager->getKnownFriendAtKey(key);
|
||||||
|
} else if (friendsManager->isInUnknownFriends(key)) {
|
||||||
|
qDebug() << "Friend have been found in unknown friend, return it";
|
||||||
|
return friendsManager->getUnknownFriendAtKey(key);
|
||||||
|
}
|
||||||
auto f = CoreModel::getInstance()->getCore()->findFriend(linphoneAddr);
|
auto f = CoreModel::getInstance()->getCore()->findFriend(linphoneAddr);
|
||||||
|
if (f) {
|
||||||
|
if (friendsManager->isInUnknownFriends(key)) {
|
||||||
|
friendsManager->removeUnknownFriend(key);
|
||||||
|
}
|
||||||
|
qDebug() << "found friend, add to known map";
|
||||||
|
friendsManager->appendKnownFriend(linphoneAddr, f);
|
||||||
|
}
|
||||||
if (!f) {
|
if (!f) {
|
||||||
|
if (friendsManager->isInOtherAddresses(key)) {
|
||||||
|
qDebug() << "A magic search has already be done for this address and nothing was found, return";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
friendsManager->appendOtherAddress(key);
|
||||||
qDebug() << "Couldn't find friend" << linphoneAddr->asStringUriOnly() << "in core, use magic search";
|
qDebug() << "Couldn't find friend" << linphoneAddr->asStringUriOnly() << "in core, use magic search";
|
||||||
CoreModel::getInstance()->searchInMagicSearch(Utils::coreStringToAppString(linphoneAddr->asStringUriOnly()),
|
CoreModel::getInstance()->searchInMagicSearch(Utils::coreStringToAppString(linphoneAddr->asStringUriOnly()),
|
||||||
(int)linphone::MagicSearch::Source::LdapServers
|
(int)linphone::MagicSearch::Source::LdapServers
|
||||||
|
|
|
||||||
|
|
@ -55,90 +55,82 @@ FocusScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Control.Control {
|
ColumnLayout {
|
||||||
id: listLayout
|
onVisibleChanged: if (!visible) mainItem.numPadPopup.close()
|
||||||
Layout.fillWidth: true
|
spacing: Math.round(38 * DefaultStyle.dp)
|
||||||
Layout.fillHeight: true
|
SearchBar {
|
||||||
background: Item {
|
id: searchBar
|
||||||
anchors.fill: parent
|
Layout.alignment: Qt.AlignTop
|
||||||
}
|
Layout.fillWidth: true
|
||||||
onVisibleChanged: if (!visible) mainItem.numPadPopup.close()
|
Layout.rightMargin: Math.round(39 * DefaultStyle.dp)
|
||||||
contentItem: ColumnLayout {
|
focus: true
|
||||||
spacing: Math.round(38 * DefaultStyle.dp)
|
color: mainItem.searchBarColor
|
||||||
SearchBar {
|
borderColor: mainItem.searchBarBorderColor
|
||||||
id: searchBar
|
//: "Rechercher un contact"
|
||||||
Layout.alignment: Qt.AlignTop
|
placeholderText: qsTr("search_bar_look_for_contact_text")
|
||||||
Layout.fillWidth: true
|
numericPadPopup: mainItem.numPadPopup
|
||||||
Layout.rightMargin: Math.round(39 * DefaultStyle.dp)
|
KeyNavigation.down: grouCallButton
|
||||||
focus: true
|
}
|
||||||
color: mainItem.searchBarColor
|
ColumnLayout {
|
||||||
borderColor: mainItem.searchBarBorderColor
|
id: content
|
||||||
//: "Rechercher un contact"
|
spacing: Math.round(32 * DefaultStyle.dp)
|
||||||
placeholderText: qsTr("search_bar_look_for_contact_text")
|
Button {
|
||||||
numericPadPopup: mainItem.numPadPopup
|
id: grouCallButton
|
||||||
KeyNavigation.down: grouCallButton
|
visible: mainItem.groupCallVisible && !SettingsCpp.disableMeetingsFeature
|
||||||
}
|
Layout.preferredWidth: Math.round(320 * DefaultStyle.dp)
|
||||||
ColumnLayout {
|
Layout.preferredHeight: Math.round(44 * DefaultStyle.dp)
|
||||||
id: content
|
padding: 0
|
||||||
spacing: Math.round(32 * DefaultStyle.dp)
|
KeyNavigation.up: searchBar
|
||||||
Button {
|
KeyNavigation.down: contactList
|
||||||
id: grouCallButton
|
onClicked: mainItem.groupCallCreationRequested()
|
||||||
visible: mainItem.groupCallVisible && !SettingsCpp.disableMeetingsFeature
|
background: Rectangle {
|
||||||
Layout.preferredWidth: Math.round(320 * DefaultStyle.dp)
|
anchors.fill: parent
|
||||||
Layout.preferredHeight: Math.round(44 * DefaultStyle.dp)
|
radius: Math.round(50 * DefaultStyle.dp)
|
||||||
padding: 0
|
gradient: Gradient {
|
||||||
KeyNavigation.up: searchBar
|
orientation: Gradient.Horizontal
|
||||||
KeyNavigation.down: contactList
|
GradientStop { position: 0.0; color: DefaultStyle.main2_100}
|
||||||
onClicked: mainItem.groupCallCreationRequested()
|
GradientStop { position: 1.0; color: DefaultStyle.grey_0}
|
||||||
background: Rectangle {
|
}
|
||||||
anchors.fill: parent
|
}
|
||||||
radius: Math.round(50 * DefaultStyle.dp)
|
contentItem: RowLayout {
|
||||||
gradient: Gradient {
|
spacing: Math.round(16 * DefaultStyle.dp)
|
||||||
orientation: Gradient.Horizontal
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
GradientStop { position: 0.0; color: DefaultStyle.main2_100}
|
Image {
|
||||||
GradientStop { position: 1.0; color: DefaultStyle.grey_0}
|
source: AppIcons.groupCall
|
||||||
}
|
Layout.preferredWidth: Math.round(44 * DefaultStyle.dp)
|
||||||
}
|
sourceSize.width: Math.round(44 * DefaultStyle.dp)
|
||||||
contentItem: RowLayout {
|
fillMode: Image.PreserveAspectFit
|
||||||
spacing: Math.round(16 * DefaultStyle.dp)
|
}
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
Text {
|
||||||
Image {
|
text: qsTr("call_start_group_call_title")
|
||||||
source: AppIcons.groupCall
|
color: DefaultStyle.grey_1000
|
||||||
Layout.preferredWidth: Math.round(44 * DefaultStyle.dp)
|
font {
|
||||||
sourceSize.width: Math.round(44 * DefaultStyle.dp)
|
pixelSize: Typography.h4.pixelSize
|
||||||
fillMode: Image.PreserveAspectFit
|
weight: Typography.h4.weight
|
||||||
}
|
}
|
||||||
Text {
|
}
|
||||||
text: qsTr("call_start_group_call_title")
|
Item {
|
||||||
color: DefaultStyle.grey_1000
|
Layout.fillWidth: true
|
||||||
font {
|
}
|
||||||
pixelSize: Typography.h4.pixelSize
|
EffectImage {
|
||||||
weight: Typography.h4.weight
|
imageSource: AppIcons.rightArrow
|
||||||
}
|
Layout.preferredWidth: Math.round(24 * DefaultStyle.dp)
|
||||||
}
|
Layout.preferredHeight: Math.round(24 * DefaultStyle.dp)
|
||||||
Item {
|
colorizationColor: DefaultStyle.main2_500main
|
||||||
Layout.fillWidth: true
|
}
|
||||||
}
|
}
|
||||||
EffectImage {
|
}
|
||||||
imageSource: AppIcons.rightArrow
|
AllContactListView{
|
||||||
Layout.preferredWidth: Math.round(24 * DefaultStyle.dp)
|
id: contactList
|
||||||
Layout.preferredHeight: Math.round(24 * DefaultStyle.dp)
|
Layout.fillWidth: true
|
||||||
colorizationColor: DefaultStyle.main2_500main
|
Layout.fillHeight: true
|
||||||
}
|
showContactMenu: false
|
||||||
}
|
searchBarText: searchBar.text
|
||||||
}
|
onContactSelected: (contact) => {
|
||||||
AllContactListView{
|
mainItem.contactClicked(contact)
|
||||||
id: contactList
|
}
|
||||||
Layout.fillWidth: true
|
}
|
||||||
Layout.fillHeight: true
|
}
|
||||||
showContactMenu: false
|
}
|
||||||
searchBarText: searchBar.text
|
}
|
||||||
onContactSelected: (contact) => {
|
|
||||||
mainItem.contactClicked(contact)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue