diff --git a/linphone-desktop/CMakeLists.txt b/linphone-desktop/CMakeLists.txt index 5abddd9a8..e933c547a 100644 --- a/linphone-desktop/CMakeLists.txt +++ b/linphone-desktop/CMakeLists.txt @@ -86,12 +86,15 @@ set(SOURCES src/app/providers/AvatarProvider.cpp src/app/providers/ThumbnailProvider.cpp src/app/translator/DefaultTranslator.cpp - src/components/camera/Camera.cpp - src/components/camera/MSFunctions.cpp src/components/call/CallModel.cpp src/components/calls/CallsListModel.cpp + src/components/camera/Camera.cpp + src/components/camera/MSFunctions.cpp src/components/chat/ChatModel.cpp src/components/chat/ChatProxyModel.cpp + src/components/codecs/CodecsModel.cpp + src/components/codecs/AudioCodecsModel.cpp + src/components/codecs/VideoCodecsModel.cpp src/components/contact/ContactModel.cpp src/components/contact/VcardModel.cpp src/components/contacts/ContactsListModel.cpp @@ -126,6 +129,9 @@ set(HEADERS src/components/calls/CallsListModel.hpp src/components/chat/ChatModel.hpp src/components/chat/ChatProxyModel.hpp + src/components/codecs/CodecsModel.cpp + src/components/codecs/AudioCodecsModel.cpp + src/components/codecs/VideoCodecsModel.cpp src/components/contact/ContactModel.hpp src/components/contact/VcardModel.hpp src/components/contacts/ContactsListModel.hpp diff --git a/linphone-desktop/src/app/App.cpp b/linphone-desktop/src/app/App.cpp index c32a6b8ed..dd3203beb 100644 --- a/linphone-desktop/src/app/App.cpp +++ b/linphone-desktop/src/app/App.cpp @@ -23,6 +23,8 @@ #include "../components/calls/CallsListModel.hpp" #include "../components/camera/Camera.hpp" #include "../components/chat/ChatProxyModel.hpp" +#include "../components/codecs/AudioCodecsModel.hpp" +#include "../components/codecs/VideoCodecsModel.hpp" #include "../components/contacts/ContactsListProxyModel.hpp" #include "../components/core/CoreManager.hpp" #include "../components/presence/OwnPresenceModel.hpp" @@ -290,6 +292,8 @@ void App::registerTypes () { registerSingletonType("OwnPresenceModel"); registerSingletonType("Presence"); registerSingletonType("TimelineModel"); + registerSingletonType("AudioCodecsModel"); + registerSingletonType("VideoCodecsModel"); registerSharedSingletonType(App, "App", App::getInstance); registerSharedSingletonType(CoreManager, "CoreManager", CoreManager::getInstance); diff --git a/linphone-desktop/src/components/codecs/AudioCodecsModel.cpp b/linphone-desktop/src/components/codecs/AudioCodecsModel.cpp new file mode 100644 index 000000000..172ec88fe --- /dev/null +++ b/linphone-desktop/src/components/codecs/AudioCodecsModel.cpp @@ -0,0 +1,36 @@ +/* + * AudioCodecsModel.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 "../core/CoreManager.hpp" + +#include "AudioCodecsModel.hpp" + +// ============================================================================= + +AudioCodecsModel::AudioCodecsModel (QObject *parent) : QSortFilterProxyModel(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; +} diff --git a/linphone-desktop/src/components/codecs/AudioCodecsModel.hpp b/linphone-desktop/src/components/codecs/AudioCodecsModel.hpp new file mode 100644 index 000000000..a840f769c --- /dev/null +++ b/linphone-desktop/src/components/codecs/AudioCodecsModel.hpp @@ -0,0 +1,41 @@ +/* + * AudioCodecsModel.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 AUDIO_CODECS_MODEL_H_ +#define AUDIO_CODECS_MODEL_H_ + +#include + +// ============================================================================= + +class AudioCodecsModel : public QSortFilterProxyModel { + Q_OBJECT; + +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 new file mode 100644 index 000000000..34fd9e51d --- /dev/null +++ b/linphone-desktop/src/components/codecs/CodecsModel.cpp @@ -0,0 +1,82 @@ +/* + * 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 (QVariantList &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; + + list << map; +} + +// ----------------------------------------------------------------------------- + +CodecsModel::CodecsModel (QObject *parent) : QAbstractListModel(parent) { + for (const auto &codec : CoreManager::getInstance()->getCore()->getAudioPayloadTypes()) + addCodecToList(m_codecs, codec, AudioCodec); + + for (const auto &codec : CoreManager::getInstance()->getCore()->getVideoPayloadTypes()) + addCodecToList(m_codecs, codec, VideoCodec); + + for (const auto &codec : CoreManager::getInstance()->getCore()->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(); +} diff --git a/linphone-desktop/src/components/codecs/CodecsModel.hpp b/linphone-desktop/src/components/codecs/CodecsModel.hpp new file mode 100644 index 000000000..8c19c8030 --- /dev/null +++ b/linphone-desktop/src/components/codecs/CodecsModel.hpp @@ -0,0 +1,54 @@ +/* + * 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 + +// ============================================================================= + +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; + +private: + QVariantList m_codecs; +}; + +#endif // CODECS_MODEL_H_ diff --git a/linphone-desktop/src/components/codecs/VideoCodecsModel.cpp b/linphone-desktop/src/components/codecs/VideoCodecsModel.cpp new file mode 100644 index 000000000..996a509ca --- /dev/null +++ b/linphone-desktop/src/components/codecs/VideoCodecsModel.cpp @@ -0,0 +1,36 @@ +/* + * VideoCodecsModel.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 "../core/CoreManager.hpp" + +#include "VideoCodecsModel.hpp" + +// ============================================================================= + +VideoCodecsModel::VideoCodecsModel (QObject *parent) : QSortFilterProxyModel(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; +} diff --git a/linphone-desktop/src/components/codecs/VideoCodecsModel.hpp b/linphone-desktop/src/components/codecs/VideoCodecsModel.hpp new file mode 100644 index 000000000..3962445cd --- /dev/null +++ b/linphone-desktop/src/components/codecs/VideoCodecsModel.hpp @@ -0,0 +1,41 @@ +/* + * VideoCodecsModel.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 VIDEO_CODECS_MODEL_H_ +#define VIDEO_CODECS_MODEL_H_ + +#include + +// ============================================================================= + +class VideoCodecsModel : public QSortFilterProxyModel { + Q_OBJECT; + +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 fa748ad23..48fc1a636 100644 --- a/linphone-desktop/src/components/core/CoreManager.cpp +++ b/linphone-desktop/src/components/core/CoreManager.cpp @@ -44,6 +44,7 @@ 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 20794583b..174e1407b 100644 --- a/linphone-desktop/src/components/core/CoreManager.hpp +++ b/linphone-desktop/src/components/core/CoreManager.hpp @@ -24,6 +24,7 @@ #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" @@ -82,6 +83,10 @@ public: return m_sip_addresses_model; } + CodecsModel *getCodecsModel () const { + return m_codecs_model; + } + SettingsModel *getSettingsModel () const { return m_settings_model; } @@ -124,6 +129,7 @@ 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; diff --git a/linphone-desktop/src/components/settings/SettingsModel.cpp b/linphone-desktop/src/components/settings/SettingsModel.cpp index a7d6f2787..a564c9e09 100644 --- a/linphone-desktop/src/components/settings/SettingsModel.cpp +++ b/linphone-desktop/src/components/settings/SettingsModel.cpp @@ -42,31 +42,6 @@ SettingsModel::SettingsModel (QObject *parent) : QObject(parent) { // Audio. // ============================================================================= -QVariantList SettingsModel::getAudioCodecs () const { - QVariantList list; - - // for (const auto &codec : CoreManager::getInstance()->getCore()->getAudioCodecs()) { - // QVariantMap map; - // - // map["mime"] = ::Utils::linphoneStringToQString(codec->getMimeType()); - // map["channels"] = codec->getChannels(); - // map["bitrate"] = codec->getNormalBitrate(); - // map["type"] = codec->getType(); - // map["isVbr"] = codec->isVbr(); - // - // list << map; - // } - - return list; -} - -void SettingsModel::setAudioCodecs (const QVariantList &codecs) { - // TODO - emit audioCodecsChanged(codecs); -} - -// ----------------------------------------------------------------------------- - QStringList SettingsModel::getAudioDevices () const { QStringList list; diff --git a/linphone-desktop/src/components/settings/SettingsModel.hpp b/linphone-desktop/src/components/settings/SettingsModel.hpp index 957ae40e1..839f2b8cb 100644 --- a/linphone-desktop/src/components/settings/SettingsModel.hpp +++ b/linphone-desktop/src/components/settings/SettingsModel.hpp @@ -37,8 +37,6 @@ class SettingsModel : public QObject { // Audio. -------------------------------------------------------------------- - Q_PROPERTY(QVariantList audioCodecs READ getAudioCodecs WRITE setAudioCodecs NOTIFY audioCodecsChanged); - Q_PROPERTY(QStringList audioDevices READ getAudioDevices CONSTANT); Q_PROPERTY(QString captureDevice READ getCaptureDevice WRITE setCaptureDevice NOTIFY captureDeviceChanged); @@ -136,9 +134,6 @@ public: // Audio. -------------------------------------------------------------------- - QVariantList getAudioCodecs () const; - void setAudioCodecs (const QVariantList &codecs); - QStringList getAudioDevices () const; QString getCaptureDevice () const; @@ -261,8 +256,6 @@ public: signals: // Audio. -------------------------------------------------------------------- - void audioCodecsChanged (const QVariantList &codecs); - void captureDeviceChanged (const QString &device); void playbackDeviceChanged (const QString &device); void ringerDeviceChanged (const QString &device);