diff --git a/Linphone/core/App.cpp b/Linphone/core/App.cpp index 25f98ca58..a620ca6dd 100644 --- a/Linphone/core/App.cpp +++ b/Linphone/core/App.cpp @@ -81,6 +81,7 @@ #include "core/variant/VariantList.hpp" #include "core/videoSource/VideoSourceDescriptorGui.hpp" #include "model/object/VariantObject.hpp" +#include "model/tool/ToolModel.hpp" #include "tool/Constants.hpp" #include "tool/EnumsToString.hpp" #include "tool/Utils.hpp" @@ -434,10 +435,10 @@ void App::initCore() { mLinphoneThread->getThreadId(), [this]() mutable { lInfo() << log().arg("Updating downloaded codec files"); - Utils::updateCodecs(); // removing codec updates suffic (.in) before the core is created. + ToolModel::updateCodecs(); // removing codec updates suffic (.in) before the core is created. lInfo() << log().arg("Starting Core"); CoreModel::getInstance()->start(); - Utils::loadDownloadedCodecs(); + ToolModel::loadDownloadedCodecs(); auto coreStarted = CoreModel::getInstance()->getCore()->getGlobalState() == linphone::GlobalState::On; lDebug() << log().arg("Creating SettingsModel"); SettingsModel::create(); diff --git a/Linphone/core/payload-type/DownloadablePayloadTypeCore.hpp b/Linphone/core/payload-type/DownloadablePayloadTypeCore.hpp index 62210ced4..8f4820850 100644 --- a/Linphone/core/payload-type/DownloadablePayloadTypeCore.hpp +++ b/Linphone/core/payload-type/DownloadablePayloadTypeCore.hpp @@ -62,7 +62,6 @@ private: QString mDownloadUrl; QString mInstallName; QString mCheckSum; - bool mInstalled; QString mVersion; DECLARE_ABSTRACT_OBJECT diff --git a/Linphone/core/payload-type/PayloadTypeCore.cpp b/Linphone/core/payload-type/PayloadTypeCore.cpp index 5d764d51b..df22b3bda 100644 --- a/Linphone/core/payload-type/PayloadTypeCore.cpp +++ b/Linphone/core/payload-type/PayloadTypeCore.cpp @@ -64,6 +64,6 @@ QString PayloadTypeCore::getMimeType() { return mMimeType; } -bool PayloadTypeCore::getDownloadable() { +bool PayloadTypeCore::isDownloadable() { return mDownloadable; } diff --git a/Linphone/core/payload-type/PayloadTypeCore.hpp b/Linphone/core/payload-type/PayloadTypeCore.hpp index 2d7ae3bea..04dd03291 100644 --- a/Linphone/core/payload-type/PayloadTypeCore.hpp +++ b/Linphone/core/payload-type/PayloadTypeCore.hpp @@ -37,7 +37,7 @@ class PayloadTypeCore : public QObject, public AbstractObject { DECLARE_CORE_MEMBER(QString, recvFmtp, RecvFmtp) public: - enum Family { None, Audio, Video, Text }; + enum Family { Audio, Video, Text }; static QSharedPointer create(Family family, const std::shared_ptr &payloadType); @@ -48,7 +48,7 @@ public: void setSelf(QSharedPointer me); Family getFamily(); - bool getDownloadable(); + bool isDownloadable(); QString getMimeType(); protected: diff --git a/Linphone/core/payload-type/PayloadTypeList.cpp b/Linphone/core/payload-type/PayloadTypeList.cpp index 123e8d442..6a52b3f78 100644 --- a/Linphone/core/payload-type/PayloadTypeList.cpp +++ b/Linphone/core/payload-type/PayloadTypeList.cpp @@ -24,6 +24,7 @@ #include "core/App.hpp" #include "core/path/Paths.hpp" #include "model/object/VariantObject.hpp" +#include "model/tool/ToolModel.hpp" #include #include @@ -56,7 +57,7 @@ void PayloadTypeList::setSelf(QSharedPointer me) { QList> *payloadTypes = new QList>(); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); - Utils::loadDownloadedCodecs(); + ToolModel::loadDownloadedCodecs(); // Audio for (auto payloadType : CoreModel::getInstance()->getCore()->getAudioPayloadTypes()) { diff --git a/Linphone/core/payload-type/PayloadTypeProxy.cpp b/Linphone/core/payload-type/PayloadTypeProxy.cpp index e3ec52274..76846dadf 100644 --- a/Linphone/core/payload-type/PayloadTypeProxy.cpp +++ b/Linphone/core/payload-type/PayloadTypeProxy.cpp @@ -32,33 +32,16 @@ PayloadTypeProxy::PayloadTypeProxy(QObject *parent) : LimitProxy(parent) { PayloadTypeProxy::~PayloadTypeProxy() { } -PayloadTypeCore::Family PayloadTypeProxy::getFamily() const { - return dynamic_cast(sourceModel())->mFamily; -} - -void PayloadTypeProxy::setFamily(PayloadTypeCore::Family data) { - auto list = dynamic_cast(sourceModel()); - if (list->mFamily != data) { - list->mFamily = data; - familyChanged(); - } -} - -bool PayloadTypeProxy::isDownloadable() const { - return dynamic_cast(sourceModel())->mDownloadable; -} - -void PayloadTypeProxy::setDownloadable(bool data) { - auto list = dynamic_cast(sourceModel()); - if (list->mDownloadable != data) { - list->mDownloadable = data; - downloadableChanged(); - } -} - bool PayloadTypeProxy::SortFilterList::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { auto payload = qobject_cast(sourceModel())->getAt(sourceRow); - return payload->getFamily() == mFamily && payload->getDownloadable() == mDownloadable; + int payloadFlag = PayloadTypeProxyFiltering::All; + payloadFlag += payload->isDownloadable() ? PayloadTypeProxyFiltering::Downloadable + : PayloadTypeProxyFiltering::NotDownloadable; + auto family = payload->getFamily(); + payloadFlag += family == PayloadTypeCore::Family::Audio ? PayloadTypeProxyFiltering::Audio : 0; + payloadFlag += family == PayloadTypeCore::Family::Video ? PayloadTypeProxyFiltering::Video : 0; + payloadFlag += family == PayloadTypeCore::Family::Text ? PayloadTypeProxyFiltering::Text : 0; + return mFilterType == payloadFlag; } bool PayloadTypeProxy::SortFilterList::lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const { diff --git a/Linphone/core/payload-type/PayloadTypeProxy.hpp b/Linphone/core/payload-type/PayloadTypeProxy.hpp index 0879fb215..102c67ab7 100644 --- a/Linphone/core/payload-type/PayloadTypeProxy.hpp +++ b/Linphone/core/payload-type/PayloadTypeProxy.hpp @@ -30,26 +30,24 @@ class PayloadTypeProxy : public LimitProxy, public AbstractObject { Q_OBJECT - Q_PROPERTY(PayloadTypeCore::Family family READ getFamily WRITE setFamily NOTIFY familyChanged) - Q_PROPERTY(bool downloadable READ isDownloadable WRITE setDownloadable NOTIFY downloadableChanged) - public: - DECLARE_SORTFILTER_CLASS(PayloadTypeCore::Family mFamily; bool mDownloadable;) + enum PayloadTypeProxyFiltering { + All = 0, + Audio = 2, + Video = 4, + Text = 8, + Downloadable = 16, + NotDownloadable = 32 + }; + Q_ENUMS(PayloadTypeProxyFiltering) + + DECLARE_SORTFILTER_CLASS() Q_INVOKABLE void reload(); PayloadTypeProxy(QObject *parent = Q_NULLPTR); ~PayloadTypeProxy(); - PayloadTypeCore::Family getFamily() const; - void setFamily(PayloadTypeCore::Family data); - bool isDownloadable() const; - void setDownloadable(bool data); - -signals: - void familyChanged(); - void downloadableChanged(); - protected: QSharedPointer mPayloadTypeList; diff --git a/Linphone/model/tool/ToolModel.cpp b/Linphone/model/tool/ToolModel.cpp index e2f75855f..a6c4ed89d 100644 --- a/Linphone/model/tool/ToolModel.cpp +++ b/Linphone/model/tool/ToolModel.cpp @@ -24,6 +24,8 @@ #include "model/core/CoreModel.hpp" #include "tool/Utils.hpp" #include +#include +#include #include DEFINE_ABSTRACT_OBJECT(ToolModel) @@ -304,3 +306,47 @@ bool ToolModel::friendIsInFriendList(const std::shared_ptr } return false; } + +// Load downloaded codecs like OpenH264 (needs to be after core is created and has loaded its plugins, as +// reloadMsPlugins modifies plugin path for the factory) +void ToolModel::loadDownloadedCodecs() { + mustBeInLinphoneThread(sLog().arg(Q_FUNC_INFO)); +#if defined(Q_OS_LINUX) || defined(Q_OS_WIN) + QDirIterator it(Paths::getCodecsDirPath()); + while (it.hasNext()) { + QFileInfo info(it.next()); + const QString filename(info.fileName()); + if (QLibrary::isLibrary(filename)) { + qInfo() << QStringLiteral("Loading `%1` symbols...").arg(filename); + if (!QLibrary(info.filePath()).load()) // lib.load()) + qWarning() << QStringLiteral("Failed to load `%1` symbols.").arg(filename); + else qInfo() << QStringLiteral("Loaded `%1` symbols...").arg(filename); + } + } + CoreModel::getInstance()->getCore()->reloadMsPlugins(""); +#endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN) +} + +// Removes .in suffix from downloaded updates. +// Updates are downloaded with .in suffix as they can't overwrite already loaded plugin +// they are loaded at next app startup. + +void ToolModel::updateCodecs() { + mustBeInLinphoneThread(sLog().arg(Q_FUNC_INFO)); +#if defined(Q_OS_LINUX) || defined(Q_OS_WIN) + static const QString codecSuffix = QStringLiteral(".%1").arg(Constants::LibraryExtension); + + QDirIterator it(Paths::getCodecsDirPath()); + while (it.hasNext()) { + QFileInfo info(it.next()); + if (info.suffix() == QLatin1String("in")) { + QString codecName = info.completeBaseName(); + if (codecName.endsWith(codecSuffix)) { + QString codecPath = info.dir().path() + QDir::separator() + codecName; + QFile::remove(codecPath); + QFile::rename(info.filePath(), codecPath); + } + } + } +#endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN) +} diff --git a/Linphone/model/tool/ToolModel.hpp b/Linphone/model/tool/ToolModel.hpp index 5b90155ee..b42d447c7 100644 --- a/Linphone/model/tool/ToolModel.hpp +++ b/Linphone/model/tool/ToolModel.hpp @@ -65,6 +65,8 @@ public: static bool friendIsInFriendList(const std::shared_ptr &friendList, const std::shared_ptr &f); + static void loadDownloadedCodecs(); + static void updateCodecs(); private: DECLARE_ABSTRACT_OBJECT diff --git a/Linphone/tool/Utils.cpp b/Linphone/tool/Utils.cpp index 4527d08ce..e4771f3e8 100644 --- a/Linphone/tool/Utils.cpp +++ b/Linphone/tool/Utils.cpp @@ -36,10 +36,8 @@ #include #include #include -#include #include #include -#include #include #include #include @@ -1439,47 +1437,3 @@ void Utils::checkDownloadedCodecsUpdates() { if (codec->shouldDownloadUpdate()) codec->downloadAndExtract(true); } } - -// Load downloaded codecs like OpenH264 (needs to be after core is created and has loaded its plugins, as -// reloadMsPlugins modifies plugin path for the factory) -void Utils::loadDownloadedCodecs() { - mustBeInLinphoneThread(sLog().arg(Q_FUNC_INFO)); -#if defined(Q_OS_LINUX) || defined(Q_OS_WIN) - QDirIterator it(Paths::getCodecsDirPath()); - while (it.hasNext()) { - QFileInfo info(it.next()); - const QString filename(info.fileName()); - if (QLibrary::isLibrary(filename)) { - qInfo() << QStringLiteral("Loading `%1` symbols...").arg(filename); - if (!QLibrary(info.filePath()).load()) // lib.load()) - qWarning() << QStringLiteral("Failed to load `%1` symbols.").arg(filename); - else qInfo() << QStringLiteral("Loaded `%1` symbols...").arg(filename); - } - } - CoreModel::getInstance()->getCore()->reloadMsPlugins(""); -#endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN) -} - -// Removes .in suffix from downloaded updates. -// Updates are downloaded with .in suffix as they can't overwrite already loaded plugin -// they are loaded at next app startup. - -void Utils::updateCodecs() { - mustBeInLinphoneThread(sLog().arg(Q_FUNC_INFO)); -#if defined(Q_OS_LINUX) || defined(Q_OS_WIN) - static const QString codecSuffix = QStringLiteral(".%1").arg(Constants::LibraryExtension); - - QDirIterator it(Paths::getCodecsDirPath()); - while (it.hasNext()) { - QFileInfo info(it.next()); - if (info.suffix() == QLatin1String("in")) { - QString codecName = info.completeBaseName(); - if (codecName.endsWith(codecSuffix)) { - QString codecPath = info.dir().path() + QDir::separator() + codecName; - QFile::remove(codecPath); - QFile::rename(info.filePath(), codecPath); - } - } - } -#endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN) -} diff --git a/Linphone/tool/Utils.hpp b/Linphone/tool/Utils.hpp index 66a49cbdc..6c57f3b23 100644 --- a/Linphone/tool/Utils.hpp +++ b/Linphone/tool/Utils.hpp @@ -140,8 +140,6 @@ public: static QString computeUserAgent(); static QList> getDownloadableVideoPayloadTypes(); static void checkDownloadedCodecsUpdates(); - static void loadDownloadedCodecs(); - static void updateCodecs(); static inline QString coreStringToAppString(const std::string &str) { if (Constants::LinphoneLocaleEncoding == QString("UTF-8")) return QString::fromStdString(str); diff --git a/Linphone/view/Page/Layout/Settings/AdvancedSettingsLayout.qml b/Linphone/view/Page/Layout/Settings/AdvancedSettingsLayout.qml index 1869acbf8..80c11af8e 100644 --- a/Linphone/view/Page/Layout/Settings/AdvancedSettingsLayout.qml +++ b/Linphone/view/Page/Layout/Settings/AdvancedSettingsLayout.qml @@ -100,7 +100,7 @@ AbstractSettingsLayout { Layout.leftMargin: 64 * DefaultStyle.dp Repeater { model: PayloadTypeProxy { - family: PayloadTypeCore.Audio + filterType: PayloadTypeProxy.Audio | PayloadTypeProxy.NotDownloadable } SwitchSetting { Layout.fillWidth: true @@ -151,7 +151,7 @@ AbstractSettingsLayout { Repeater { model: PayloadTypeProxy { id: videoPayloadTypeProxy - family: PayloadTypeCore.Video + filterType: PayloadTypeProxy.Video | PayloadTypeProxy.NotDownloadable } SwitchSetting { Layout.fillWidth: true @@ -164,26 +164,15 @@ AbstractSettingsLayout { Repeater { model: PayloadTypeProxy { id: downloadableVideoPayloadTypeProxy - family: PayloadTypeCore.Video - downloadable: true + filterType: PayloadTypeProxy.Video | PayloadTypeProxy.Downloadable } SwitchSetting { Layout.fillWidth: true titleText: Utils.capitalizeFirstLetter(modelData.core.mimeType) subTitleText: modelData.core.encoderDescription - onCheckChanged: function(checked) { + onCheckedChanged: function(checked) { if (checked) - UtilsCpp.getMainWindow().showConfirmationLambdaPopup("", - qsTr("Installation"), - qsTr("Télécharger le codec ") + Utils.capitalizeFirstLetter(modelData.core.mimeType) + " ("+modelData.core.encoderDescription+")"+" ?", - function (confirmed) { - if (confirmed) { - UtilsCpp.getMainWindow().showLoadingPopup(qsTr("Téléchargement en cours ...")) - modelData.core.downloadAndExtract() - } else - setChecked(false) - } - ) + Utils.openCodecOnlineInstallerDialog(mainWindow, modelData.core) } } } diff --git a/Linphone/view/Page/Window/Main/MainWindow.qml b/Linphone/view/Page/Window/Main/MainWindow.qml index 5a7cb83b3..7ad97f51d 100644 --- a/Linphone/view/Page/Window/Main/MainWindow.qml +++ b/Linphone/view/Page/Window/Main/MainWindow.qml @@ -232,8 +232,7 @@ AbstractWindow { // H264 Cisco codec download PayloadTypeProxy { id: downloadableVideoPayloadTypeProxy - family: PayloadTypeCore.Video - downloadable: true + filterType: PayloadTypeProxy.Video | PayloadTypeProxy.Downloadable } Repeater { id: codecDownloader