diff --git a/linphone-desktop/CMakeLists.txt b/linphone-desktop/CMakeLists.txt index eacfd3d75..3acf806bb 100644 --- a/linphone-desktop/CMakeLists.txt +++ b/linphone-desktop/CMakeLists.txt @@ -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 diff --git a/linphone-desktop/src/components/codecs/AbstractCodecsModel.cpp b/linphone-desktop/src/components/codecs/AbstractCodecsModel.cpp index c402a5e29..18409b2ae 100644 --- a/linphone-desktop/src/components/codecs/AbstractCodecsModel.cpp +++ b/linphone-desktop/src/components/codecs/AbstractCodecsModel.cpp @@ -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 + +#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 AbstractCodecsModel::roleNames () const { + QHash 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(sourceModel())->enableCodec(source_index.row(), status); + Q_ASSERT(id >= 0 && id < m_codecs.count()); + + QVariantMap &map = m_codecs[id]; + shared_ptr codec = map.value("__codec").value >(); + + codec->enable(status); + map["enabled"] = status; + + emit dataChanged(index(id, 0), index(id, 0)); +} + +// ----------------------------------------------------------------------------- + +void AbstractCodecsModel::addCodec (std::shared_ptr &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; } diff --git a/linphone-desktop/src/components/codecs/AbstractCodecsModel.hpp b/linphone-desktop/src/components/codecs/AbstractCodecsModel.hpp index eec6584ef..35e8b6b72 100644 --- a/linphone-desktop/src/components/codecs/AbstractCodecsModel.hpp +++ b/linphone-desktop/src/components/codecs/AbstractCodecsModel.hpp @@ -23,21 +23,52 @@ #ifndef ABSTRACT_CODECS_MODEL_H_ #define ABSTRACT_CODECS_MODEL_H_ -#include +#include + +#include // ============================================================================= -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 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 &codec); + +private: + QList m_codecs; }; +Q_DECLARE_METATYPE(std::shared_ptr ); + #endif // ABSTRACT_CODECS_MODEL_H_ diff --git a/linphone-desktop/src/components/codecs/AudioCodecsModel.cpp b/linphone-desktop/src/components/codecs/AudioCodecsModel.cpp index 3e9243cd3..3353e0e14 100644 --- a/linphone-desktop/src/components/codecs/AudioCodecsModel.cpp +++ b/linphone-desktop/src/components/codecs/AudioCodecsModel.cpp @@ -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); } diff --git a/linphone-desktop/src/components/codecs/AudioCodecsModel.hpp b/linphone-desktop/src/components/codecs/AudioCodecsModel.hpp index 406a1eac3..56875918c 100644 --- a/linphone-desktop/src/components/codecs/AudioCodecsModel.hpp +++ b/linphone-desktop/src/components/codecs/AudioCodecsModel.hpp @@ -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_ diff --git a/linphone-desktop/src/components/codecs/CodecsModel.cpp b/linphone-desktop/src/components/codecs/CodecsModel.cpp deleted file mode 100644 index c43429d9e..000000000 --- a/linphone-desktop/src/components/codecs/CodecsModel.cpp +++ /dev/null @@ -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 -inline void addCodecToList (QList &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 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 CodecsModel::roleNames () const { - QHash 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 codec = map.value("__codec").value >(); - - codec->enable(status); - map["enabled"] = status; - - emit dataChanged(index(id, 0), index(id, 0)); -} diff --git a/linphone-desktop/src/components/codecs/CodecsModel.hpp b/linphone-desktop/src/components/codecs/CodecsModel.hpp deleted file mode 100644 index c7446e02d..000000000 --- a/linphone-desktop/src/components/codecs/CodecsModel.hpp +++ /dev/null @@ -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 - -#include - -// ============================================================================= - -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 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 m_codecs; -}; - -Q_DECLARE_METATYPE(std::shared_ptr ); - -#endif // CODECS_MODEL_H_ diff --git a/linphone-desktop/src/components/codecs/VideoCodecsModel.cpp b/linphone-desktop/src/components/codecs/VideoCodecsModel.cpp index db4f80ead..d6d5d8178 100644 --- a/linphone-desktop/src/components/codecs/VideoCodecsModel.cpp +++ b/linphone-desktop/src/components/codecs/VideoCodecsModel.cpp @@ -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); } diff --git a/linphone-desktop/src/components/codecs/VideoCodecsModel.hpp b/linphone-desktop/src/components/codecs/VideoCodecsModel.hpp index 88dd7919b..012022b50 100644 --- a/linphone-desktop/src/components/codecs/VideoCodecsModel.hpp +++ b/linphone-desktop/src/components/codecs/VideoCodecsModel.hpp @@ -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_ diff --git a/linphone-desktop/src/components/core/CoreManager.cpp b/linphone-desktop/src/components/core/CoreManager.cpp index 48fc1a636..fa748ad23 100644 --- a/linphone-desktop/src/components/core/CoreManager.cpp +++ b/linphone-desktop/src/components/core/CoreManager.cpp @@ -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(); diff --git a/linphone-desktop/src/components/core/CoreManager.hpp b/linphone-desktop/src/components/core/CoreManager.hpp index 174e1407b..20794583b 100644 --- a/linphone-desktop/src/components/core/CoreManager.hpp +++ b/linphone-desktop/src/components/core/CoreManager.hpp @@ -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;