mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-22 22:28:08 +00:00
feat(src/components/codecs): remove proxy
This commit is contained in:
parent
37797ea0b1
commit
7ac68672a5
11 changed files with 134 additions and 251 deletions
|
|
@ -94,7 +94,6 @@ set(SOURCES
|
|||
src/components/chat/ChatProxyModel.cpp
|
||||
src/components/codecs/AbstractCodecsModel.cpp
|
||||
src/components/codecs/AudioCodecsModel.cpp
|
||||
src/components/codecs/CodecsModel.cpp
|
||||
src/components/codecs/VideoCodecsModel.cpp
|
||||
src/components/contact/ContactModel.cpp
|
||||
src/components/contact/VcardModel.cpp
|
||||
|
|
@ -130,7 +129,6 @@ set(HEADERS
|
|||
src/components/calls/CallsListModel.hpp
|
||||
src/components/chat/ChatModel.hpp
|
||||
src/components/chat/ChatProxyModel.hpp
|
||||
src/components/codecs/CodecsModel.hpp
|
||||
src/components/codecs/AbstractCodecsModel.hpp
|
||||
src/components/codecs/AudioCodecsModel.hpp
|
||||
src/components/codecs/VideoCodecsModel.hpp
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* AbstractCodecsModel.cpp
|
||||
* AbstractAbstractCodecsModel.cBase::pp
|
||||
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
|
@ -20,15 +20,105 @@
|
|||
* Author: Ronan Abhamon
|
||||
*/
|
||||
|
||||
#include "CodecsModel.hpp"
|
||||
#include <linphone++/linphone.hh>
|
||||
|
||||
#include "../../utils.hpp"
|
||||
|
||||
#include "AbstractCodecsModel.hpp"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
AbstractCodecsModel::AbstractCodecsModel (QObject *parent) : QSortFilterProxyModel(parent) {}
|
||||
AbstractCodecsModel::AbstractCodecsModel (QObject *parent) : QAbstractListModel(parent) {}
|
||||
|
||||
int AbstractCodecsModel::rowCount (const QModelIndex &) const {
|
||||
return m_codecs.count();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> AbstractCodecsModel::roleNames () const {
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[Qt::DisplayRole] = "$codec";
|
||||
return roles;
|
||||
}
|
||||
|
||||
QVariant AbstractCodecsModel::data (const QModelIndex &index, int role) const {
|
||||
int row = index.row();
|
||||
|
||||
if (!index.isValid() || row < 0 || row >= m_codecs.count())
|
||||
return QVariant();
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
return m_codecs[row];
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool AbstractCodecsModel::moveRow (
|
||||
const QModelIndex &source_parent,
|
||||
int source_row,
|
||||
const QModelIndex &destination_parent,
|
||||
int destination_child
|
||||
) {
|
||||
return moveRows(source_parent, source_row, 1, destination_parent, destination_child);
|
||||
}
|
||||
|
||||
bool AbstractCodecsModel::moveRows (
|
||||
const QModelIndex &source_parent,
|
||||
int source_row,
|
||||
int count,
|
||||
const QModelIndex &destination_parent,
|
||||
int destination_child
|
||||
) {
|
||||
int limit = source_row + count - 1;
|
||||
|
||||
if (source_row < 0 || count < 0 || limit >= m_codecs.count())
|
||||
return false;
|
||||
|
||||
beginMoveRows(source_parent, source_row, limit, destination_parent, destination_child);
|
||||
|
||||
if (destination_child < source_row) {
|
||||
for (int i = source_row; i <= limit; ++i)
|
||||
m_codecs.move(source_row, destination_child + i - source_row);
|
||||
} else {
|
||||
for (int i = source_row; i <= limit; ++i)
|
||||
m_codecs.move(source_row, destination_child + i);
|
||||
}
|
||||
|
||||
endRemoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void AbstractCodecsModel::enableCodec (int id, bool status) {
|
||||
QModelIndex source_index = mapToSource(index(id, 0));
|
||||
static_cast<CodecsModel *>(sourceModel())->enableCodec(source_index.row(), status);
|
||||
Q_ASSERT(id >= 0 && id < m_codecs.count());
|
||||
|
||||
QVariantMap &map = m_codecs[id];
|
||||
shared_ptr<linphone::PayloadType> codec = map.value("__codec").value<shared_ptr<linphone::PayloadType> >();
|
||||
|
||||
codec->enable(status);
|
||||
map["enabled"] = status;
|
||||
|
||||
emit dataChanged(index(id, 0), index(id, 0));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void AbstractCodecsModel::addCodec (std::shared_ptr<linphone::PayloadType> &codec) {
|
||||
QVariantMap map;
|
||||
|
||||
map["bitrate"] = codec->getNormalBitrate();
|
||||
map["channels"] = codec->getChannels();
|
||||
map["clockRate"] = codec->getClockRate();
|
||||
map["description"] = ::Utils::linphoneStringToQString(codec->getDescription());
|
||||
map["enabled"] = codec->enabled();
|
||||
map["encoderDescription"] = ::Utils::linphoneStringToQString(codec->getEncoderDescription());
|
||||
map["isUsable"] = codec->isUsable();
|
||||
map["isVbr"] = codec->isVbr();
|
||||
map["mime"] = ::Utils::linphoneStringToQString(codec->getMimeType());
|
||||
map["number"] = codec->getNumber();
|
||||
map["recvFmtp"] = ::Utils::linphoneStringToQString(codec->getRecvFmtp());
|
||||
map["__codec"] = QVariant::fromValue(codec);
|
||||
|
||||
m_codecs << map;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,21 +23,52 @@
|
|||
#ifndef ABSTRACT_CODECS_MODEL_H_
|
||||
#define ABSTRACT_CODECS_MODEL_H_
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <memory>
|
||||
|
||||
#include <QAbstractListModel>
|
||||
|
||||
// =============================================================================
|
||||
|
||||
class AbstractCodecsModel : public QSortFilterProxyModel {
|
||||
namespace linphone {
|
||||
class PayloadType;
|
||||
}
|
||||
|
||||
class AbstractCodecsModel : public QAbstractListModel {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
AbstractCodecsModel (QObject *parent = Q_NULLPTR);
|
||||
virtual ~AbstractCodecsModel () = default;
|
||||
|
||||
Q_INVOKABLE void enableCodec (int id, bool status);
|
||||
int rowCount (const QModelIndex &index = QModelIndex()) const override;
|
||||
|
||||
QHash<int, QByteArray> roleNames () const override;
|
||||
QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
bool moveRow (
|
||||
const QModelIndex &source_parent,
|
||||
int source_row,
|
||||
const QModelIndex &destination_parent,
|
||||
int destination_child
|
||||
);
|
||||
|
||||
bool moveRows (
|
||||
const QModelIndex &source_parent,
|
||||
int source_row,
|
||||
int count,
|
||||
const QModelIndex &destination_parent,
|
||||
int destination_child
|
||||
) override;
|
||||
|
||||
void enableCodec (int id, bool status);
|
||||
|
||||
protected:
|
||||
virtual bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const override = 0;
|
||||
void addCodec (std::shared_ptr<linphone::PayloadType> &codec);
|
||||
|
||||
private:
|
||||
QList<QVariantMap> m_codecs;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(std::shared_ptr<linphone::PayloadType> );
|
||||
|
||||
#endif // ABSTRACT_CODECS_MODEL_H_
|
||||
|
|
|
|||
|
|
@ -27,10 +27,6 @@
|
|||
// =============================================================================
|
||||
|
||||
AudioCodecsModel::AudioCodecsModel (QObject *parent) : AbstractCodecsModel(parent) {
|
||||
setSourceModel(CoreManager::getInstance()->getCodecsModel());
|
||||
}
|
||||
|
||||
bool AudioCodecsModel::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const {
|
||||
const QModelIndex &index = sourceModel()->index(source_row, 0, source_parent);
|
||||
return index.data().toMap()["type"] == CodecsModel::AudioCodec;
|
||||
for (auto &codec : CoreManager::getInstance()->getCore()->getAudioPayloadTypes())
|
||||
addCodec(codec);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,9 +33,6 @@ class AudioCodecsModel : public AbstractCodecsModel {
|
|||
public:
|
||||
AudioCodecsModel (QObject *parent = Q_NULLPTR);
|
||||
~AudioCodecsModel () = default;
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const override;
|
||||
};
|
||||
|
||||
#endif // AUDIO_CODECS_MODEL_H_
|
||||
|
|
|
|||
|
|
@ -1,136 +0,0 @@
|
|||
/*
|
||||
* CodecsModel.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: April 3, 2017
|
||||
* Author: Ronan Abhamon
|
||||
*/
|
||||
|
||||
#include "../../utils.hpp"
|
||||
#include "../core/CoreManager.hpp"
|
||||
|
||||
#include "CodecsModel.hpp"
|
||||
|
||||
// ============================================================================
|
||||
|
||||
template<typename T>
|
||||
inline void addCodecToList (QList<QVariantMap> &list, const T &codec, CodecsModel::CodecType type) {
|
||||
QVariantMap map;
|
||||
|
||||
map["bitrate"] = codec->getNormalBitrate();
|
||||
map["channels"] = codec->getChannels();
|
||||
map["clockRate"] = codec->getClockRate();
|
||||
map["description"] = ::Utils::linphoneStringToQString(codec->getDescription());
|
||||
map["enabled"] = codec->enabled();
|
||||
map["encoderDescription"] = ::Utils::linphoneStringToQString(codec->getEncoderDescription());
|
||||
map["isUsable"] = codec->isUsable();
|
||||
map["isVbr"] = codec->isVbr();
|
||||
map["mime"] = ::Utils::linphoneStringToQString(codec->getMimeType());
|
||||
map["number"] = codec->getNumber();
|
||||
map["type"] = type;
|
||||
map["recvFmtp"] = ::Utils::linphoneStringToQString(codec->getRecvFmtp());
|
||||
map["__codec"] = QVariant::fromValue(codec);
|
||||
|
||||
list << map;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
CodecsModel::CodecsModel (QObject *parent) : QAbstractListModel(parent) {
|
||||
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
|
||||
|
||||
for (const auto &codec : core->getAudioPayloadTypes())
|
||||
addCodecToList(m_codecs, codec, AudioCodec);
|
||||
|
||||
for (const auto &codec : core->getVideoPayloadTypes())
|
||||
addCodecToList(m_codecs, codec, VideoCodec);
|
||||
|
||||
for (const auto &codec : core->getTextPayloadTypes())
|
||||
addCodecToList(m_codecs, codec, TextCodec);
|
||||
}
|
||||
|
||||
int CodecsModel::rowCount (const QModelIndex &) const {
|
||||
return m_codecs.count();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> CodecsModel::roleNames () const {
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[Qt::DisplayRole] = "$codec";
|
||||
return roles;
|
||||
}
|
||||
|
||||
QVariant CodecsModel::data (const QModelIndex &index, int role) const {
|
||||
int row = index.row();
|
||||
|
||||
if (!index.isValid() || row < 0 || row >= m_codecs.count())
|
||||
return QVariant();
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
return m_codecs[row];
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool CodecsModel::moveRow (
|
||||
const QModelIndex &source_parent,
|
||||
int source_row,
|
||||
const QModelIndex &destination_parent,
|
||||
int destination_child
|
||||
) {
|
||||
return moveRows(source_parent, source_row, 1, destination_parent, destination_child);
|
||||
}
|
||||
|
||||
bool CodecsModel::moveRows (
|
||||
const QModelIndex &source_parent,
|
||||
int source_row,
|
||||
int count,
|
||||
const QModelIndex &destination_parent,
|
||||
int destination_child
|
||||
) {
|
||||
int limit = source_row + count - 1;
|
||||
|
||||
if (source_row < 0 || count < 0 || limit >= m_codecs.count())
|
||||
return false;
|
||||
|
||||
beginMoveRows(source_parent, source_row, limit, destination_parent, destination_child);
|
||||
|
||||
if (destination_child < source_row) {
|
||||
for (int i = source_row; i <= limit; ++i)
|
||||
m_codecs.move(source_row, destination_child + i - source_row);
|
||||
} else {
|
||||
for (int i = source_row; i <= limit; ++i)
|
||||
m_codecs.move(source_row, destination_child + i);
|
||||
}
|
||||
|
||||
endRemoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void CodecsModel::enableCodec (int id, bool status) {
|
||||
Q_ASSERT(id >= 0 && id < m_codecs.count());
|
||||
|
||||
QVariantMap &map = m_codecs[id];
|
||||
shared_ptr<linphone::PayloadType> codec = map.value("__codec").value<shared_ptr<linphone::PayloadType> >();
|
||||
|
||||
codec->enable(status);
|
||||
map["enabled"] = status;
|
||||
|
||||
emit dataChanged(index(id, 0), index(id, 0));
|
||||
}
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* CodecsModel.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: April 3, 2017
|
||||
* Author: Ronan Abhamon
|
||||
*/
|
||||
|
||||
#ifndef CODECS_MODEL_H_
|
||||
#define CODECS_MODEL_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QAbstractListModel>
|
||||
|
||||
// =============================================================================
|
||||
|
||||
namespace linphone {
|
||||
class PayloadType;
|
||||
}
|
||||
|
||||
class CodecsModel : public QAbstractListModel {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
enum CodecType {
|
||||
AudioCodec,
|
||||
VideoCodec,
|
||||
TextCodec
|
||||
};
|
||||
|
||||
Q_ENUMS(CodecType);
|
||||
|
||||
CodecsModel (QObject *parent = Q_NULLPTR);
|
||||
~CodecsModel () = default;
|
||||
|
||||
int rowCount (const QModelIndex &index = QModelIndex()) const override;
|
||||
|
||||
QHash<int, QByteArray> roleNames () const override;
|
||||
QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
bool moveRow (
|
||||
const QModelIndex &source_parent,
|
||||
int source_row,
|
||||
const QModelIndex &destination_parent,
|
||||
int destination_child
|
||||
);
|
||||
|
||||
bool moveRows (
|
||||
const QModelIndex &source_parent,
|
||||
int source_row,
|
||||
int count,
|
||||
const QModelIndex &destination_parent,
|
||||
int destination_child
|
||||
) override;
|
||||
|
||||
void enableCodec (int id, bool status);
|
||||
|
||||
private:
|
||||
QList<QVariantMap> m_codecs;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(std::shared_ptr<linphone::PayloadType> );
|
||||
|
||||
#endif // CODECS_MODEL_H_
|
||||
|
|
@ -27,10 +27,6 @@
|
|||
// =============================================================================
|
||||
|
||||
VideoCodecsModel::VideoCodecsModel (QObject *parent) : AbstractCodecsModel(parent) {
|
||||
setSourceModel(CoreManager::getInstance()->getCodecsModel());
|
||||
}
|
||||
|
||||
bool VideoCodecsModel::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const {
|
||||
const QModelIndex &index = sourceModel()->index(source_row, 0, source_parent);
|
||||
return index.data().toMap()["type"] == CodecsModel::VideoCodec;
|
||||
for (auto &codec : CoreManager::getInstance()->getCore()->getVideoPayloadTypes())
|
||||
addCodec(codec);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,9 +33,6 @@ class VideoCodecsModel : public AbstractCodecsModel {
|
|||
public:
|
||||
VideoCodecsModel (QObject *parent = Q_NULLPTR);
|
||||
~VideoCodecsModel () = default;
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const override;
|
||||
};
|
||||
|
||||
#endif // VIDEO_CODECS_MODEL_H_
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ CoreManager::CoreManager (QObject *parent, const QString &config_path) : QObject
|
|||
m_instance->m_calls_list_model = new CallsListModel(m_instance);
|
||||
m_instance->m_contacts_list_model = new ContactsListModel(m_instance);
|
||||
m_instance->m_sip_addresses_model = new SipAddressesModel(m_instance);
|
||||
m_instance->m_codecs_model = new CodecsModel(m_instance);
|
||||
m_instance->m_settings_model = new SettingsModel(m_instance);
|
||||
|
||||
emit m_instance->linphoneCoreCreated();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
#define CORE_MANAGER_H_
|
||||
|
||||
#include "../calls/CallsListModel.hpp"
|
||||
#include "../codecs/CodecsModel.hpp"
|
||||
#include "../contacts/ContactsListModel.hpp"
|
||||
#include "../settings/SettingsModel.hpp"
|
||||
#include "../sip-addresses/SipAddressesModel.hpp"
|
||||
|
|
@ -83,10 +82,6 @@ public:
|
|||
return m_sip_addresses_model;
|
||||
}
|
||||
|
||||
CodecsModel *getCodecsModel () const {
|
||||
return m_codecs_model;
|
||||
}
|
||||
|
||||
SettingsModel *getSettingsModel () const {
|
||||
return m_settings_model;
|
||||
}
|
||||
|
|
@ -129,7 +124,6 @@ private:
|
|||
CallsListModel *m_calls_list_model;
|
||||
ContactsListModel *m_contacts_list_model;
|
||||
SipAddressesModel *m_sip_addresses_model;
|
||||
CodecsModel *m_codecs_model;
|
||||
SettingsModel *m_settings_model;
|
||||
|
||||
QTimer *m_cbs_timer;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue