mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-17 11:28:07 +00:00
- Implement shaders to make round images and use qsb --qt6. - Add picture to Friend. - Display username if displayname is not found. - Compute initials from C++ with emojis. - Add Accounts list in a popup from main window. - Add a hack on account to update avatar on all AcountModel. - Add Avatar item for initials/picture. - Add Contact description item. - Make sizes proportionals to match designs. - Add image colorization.
125 lines
5.3 KiB
C++
125 lines
5.3 KiB
C++
/*
|
|
* 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 "ToolModel.hpp"
|
|
#include "core/App.hpp"
|
|
#include "model/core/CoreModel.hpp"
|
|
#include "tool/Utils.hpp"
|
|
#include <QDebug>
|
|
#include <QTest>
|
|
|
|
DEFINE_ABSTRACT_OBJECT(ToolModel)
|
|
|
|
ToolModel::ToolModel(QObject *parent) {
|
|
}
|
|
ToolModel::~ToolModel() {
|
|
}
|
|
std::shared_ptr<linphone::Address> ToolModel::interpretUrl(const QString &address) {
|
|
bool usePrefix = false; // TODO
|
|
// CoreManager::getInstance()->getAccountSettingsModel()->getUseInternationalPrefixForCallsAndChats();
|
|
auto interpretedAddress =
|
|
CoreModel::getInstance()->getCore()->interpretUrl(Utils::appStringToCoreString(address), usePrefix);
|
|
if (!interpretedAddress) { // Try by removing scheme.
|
|
QStringList splitted = address.split(":");
|
|
if (splitted.size() > 0 && splitted[0] == "sip") {
|
|
splitted.removeFirst();
|
|
interpretedAddress = CoreModel::getInstance()->getCore()->interpretUrl(
|
|
Utils::appStringToCoreString(splitted.join(":")), usePrefix);
|
|
}
|
|
}
|
|
return interpretedAddress;
|
|
}
|
|
|
|
QString ToolModel::getDisplayName(const std::shared_ptr<const linphone::Address> &address) {
|
|
QString displayName;
|
|
if (address) {
|
|
displayName = Utils::coreStringToAppString(address->getDisplayName());
|
|
if (displayName.isEmpty()) displayName = Utils::coreStringToAppString(address->getUsername());
|
|
// TODO
|
|
// std::shared_ptr<linphone::Address> cleanAddress = address->clone();
|
|
// cleanAddress->clean();
|
|
// QString qtAddress = Utils::coreStringToAppString(cleanAddress->asStringUriOnly());
|
|
// auto sipAddressEntry = getSipAddressEntry(qtAddress, cleanAddress);
|
|
// displayName = sipAddressEntry->displayNames.get();
|
|
}
|
|
return displayName;
|
|
}
|
|
|
|
QString ToolModel::getDisplayName(QString address) {
|
|
mustBeInLinphoneThread(QString(gClassName) + " : " + Q_FUNC_INFO);
|
|
|
|
QString displayName = getDisplayName(interpretUrl(address));
|
|
return displayName.isEmpty() ? address : displayName;
|
|
}
|
|
|
|
QSharedPointer<CallCore> ToolModel::createCall(const QString &sipAddress,
|
|
const QString &prepareTransfertAddress,
|
|
const QHash<QString, QString> &headers) {
|
|
bool waitRegistrationForCall = true; // getSettingsModel()->getWaitRegistrationForCall()
|
|
std::shared_ptr<linphone::Core> core = CoreModel::getInstance()->getCore();
|
|
|
|
std::shared_ptr<linphone::Address> address = interpretUrl(sipAddress);
|
|
if (!address) {
|
|
qCritical() << "[" + QString(gClassName) + "] The calling address is not an interpretable SIP address: "
|
|
<< sipAddress;
|
|
return nullptr;
|
|
}
|
|
|
|
std::shared_ptr<linphone::CallParams> params = core->createCallParams(nullptr);
|
|
params->enableVideo(false);
|
|
|
|
QHashIterator<QString, QString> iterator(headers);
|
|
while (iterator.hasNext()) {
|
|
iterator.next();
|
|
params->addCustomHeader(Utils::appStringToCoreString(iterator.key()),
|
|
Utils::appStringToCoreString(iterator.value()));
|
|
}
|
|
if (core->getDefaultAccount()) params->setAccount(core->getDefaultAccount());
|
|
// CallModel::setRecordFile(params, Utils::coreStringToAppString(address->getUsername()));
|
|
auto call = core->inviteAddressWithParams(address, params);
|
|
return call ? CallCore::create(call) : nullptr;
|
|
|
|
/* TODO transfer
|
|
|
|
std::shared_ptr<linphone::Account> currentAccount = core->getDefaultAccount();
|
|
if (currentAccount) {
|
|
if (!waitRegistrationForCall || currentAccount->getState() == linphone::RegistrationState::Ok) {
|
|
qWarning() << "prepareTransfert not impolemented";
|
|
// CallModel::prepareTransfert(core->inviteAddressWithParams(address, params), prepareTransfertAddress);
|
|
} else {
|
|
qWarning() << "Waiting registration not implemented";
|
|
|
|
// QObject *context = new QObject();
|
|
// QObject::connect(
|
|
// CoreManager::getInstance()->getHandlers().get(), &CoreHandlers::registrationStateChanged, context,
|
|
// [address, core, params, currentAccount, prepareTransfertAddress, context](
|
|
// const std::shared_ptr<linphone::Account> &account, linphone::RegistrationState state) mutable {
|
|
// if (context && account == currentAccount && state == linphone::RegistrationState::Ok) {
|
|
// CallModel::prepareTransfert(core->inviteAddressWithParams(address, params),
|
|
// prepareTransfertAddress);
|
|
// context->deleteLater();
|
|
// context = nullptr;
|
|
// }
|
|
// });
|
|
}
|
|
} else qWarning() << "prepareTransfert not impolemented";
|
|
// CallModel::prepareTransfert(core->inviteAddressWithParams(address, params), prepareTransfertAddress);
|
|
*/
|
|
}
|