diff --git a/jami-qt.pro b/jami-qt.pro index 8997b0af5fc0d00b27388b85e3e7824ffb445199..f252e1f03462488a07987b581bb4a5bffd76496c 100644 --- a/jami-qt.pro +++ b/jami-qt.pro @@ -136,9 +136,11 @@ HEADERS += ./src/smartlistmodel.h \ ./src/qmladapterbase.h \ ./src/avadapter.h \ ./src/contactadapter.h \ + ./src/mediahandleradapter.h \ ./src/settingsadaptor.h \ ./src/deviceitemlistmodel.h \ ./src/pluginitemlistmodel.h \ + ./src/mediahandleritemlistmodel.h \ ./src/preferenceitemlistmodel.h \ ./src/audiocodeclistmodel.h \ ./src/videocodeclistmodel.h \ @@ -172,9 +174,11 @@ SOURCES += ./src/bannedlistmodel.cpp \ ./src/qmladapterbase.cpp \ ./src/avadapter.cpp \ ./src/contactadapter.cpp \ + ./src/mediahandleradapter.cpp \ ./src/settingsadaptor.cpp \ ./src/deviceitemlistmodel.cpp \ ./src/pluginitemlistmodel.cpp \ + ./src/mediahandleritemlistmodel.cpp \ ./src/preferenceitemlistmodel.cpp \ ./src/audiocodeclistmodel.cpp \ ./src/videocodeclistmodel.cpp \ diff --git a/qml.qrc b/qml.qrc index 50e529759b8f54112800d2ef9a2c58df5b0a3c06..f446e4c0a980467db83c06be73393bc6f40ba444 100644 --- a/qml.qrc +++ b/qml.qrc @@ -17,6 +17,7 @@ <file>src/settingsview/components/SettingParaCombobox.qml</file> <file>src/settingsview/components/DeviceItemDelegate.qml</file> <file>src/settingsview/components/PluginItemDelegate.qml</file> + <file>src/mainview/components/MediaHandlerItemDelegate.qml</file> <file>src/settingsview/components/PreferenceItemDelegate.qml</file> <file>src/settingsview/components/BannedItemDelegate.qml</file> <file>src/settingsview/components/VideoCodecDelegate.qml</file> @@ -90,7 +91,9 @@ <file>src/mainview/js/videocallfullscreenwindowcontainercreation.js</file> <file>src/mainview/components/VideoCallFullScreenWindowContainer.qml</file> <file>src/mainview/components/ContactPicker.qml</file> + <file>src/mainview/components/MediaHandlerPicker.qml</file> <file>src/mainview/js/contactpickercreation.js</file> + <file>src/mainview/js/mediahandlerpickercreation.js</file> <file>src/mainview/components/ContactPickerItemDelegate.qml</file> <file>src/wizardview/components/HoverableGradientButton.qml</file> <file>src/commoncomponents/AccountMigrationDialog.qml</file> diff --git a/src/clientwrapper.h b/src/clientwrapper.h index d6e321a935887be94e444645874c2f37b811723b..681c35eee6de236d5aedb8502f8034c5af74f062 100644 --- a/src/clientwrapper.h +++ b/src/clientwrapper.h @@ -1,6 +1,7 @@ /* * Copyright (C) 2019-2020 by Savoir-faire Linux * Author: Yang Wang <yang.wang@savoirfairelinux.com> + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * 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 @@ -25,9 +26,11 @@ #include "bannedlistmodel.h" #include "calladapter.h" #include "contactadapter.h" +#include "mediahandleradapter.h" #include "conversationsadapter.h" #include "deviceitemlistmodel.h" #include "pluginitemlistmodel.h" +#include "mediahandleritemlistmodel.h" #include "preferenceitemlistmodel.h" #include "distantrenderer.h" #include "globalinstances.h" diff --git a/src/mainapplication.cpp b/src/mainapplication.cpp index 938a0eb55c506ddc747d2c4c3ed0218d99705db2..f53cc9582264c1ed68e0b294d979cb65c04d4e58 100644 --- a/src/mainapplication.cpp +++ b/src/mainapplication.cpp @@ -3,6 +3,7 @@ * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com> * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * 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 @@ -32,9 +33,11 @@ #include "calladapter.h" #include "clientwrapper.h" #include "contactadapter.h" +#include "mediahandleradapter.h" #include "conversationsadapter.h" #include "deviceitemlistmodel.h" #include "pluginitemlistmodel.h" +#include "mediahandleritemlistmodel.h" #include "preferenceitemlistmodel.h" #include "distantrenderer.h" #include "globalinstances.h" @@ -296,6 +299,7 @@ MainApplication::qmlInitialization() QML_REGISTERTYPE(AccountListModel, 1, 0); QML_REGISTERTYPE(DeviceItemListModel, 1, 0); QML_REGISTERTYPE(PluginItemListModel, 1, 0); + QML_REGISTERTYPE(MediaHandlerItemListModel, 1, 0); QML_REGISTERTYPE(PreferenceItemListModel, 1, 0); QML_REGISTERTYPE(BannedListModel, 1, 0); QML_REGISTERTYPE(VideoCodecListModel, 1, 0); @@ -330,6 +334,7 @@ MainApplication::qmlInitialization() QML_REGISTERSINGLETONTYPE(ConversationsAdapter, 1, 0); QML_REGISTERSINGLETONTYPE(AvAdapter, 1, 0); QML_REGISTERSINGLETONTYPE(ContactAdapter, 1, 0); + QML_REGISTERSINGLETONTYPE(MediaHandlerAdapter, 1, 0); QML_REGISTERSINGLETONTYPE(ClientWrapper, 1, 0); //QML_REGISTERSINGLETONTYPE_WITH_INSTANCE(AccountAdapter, 1, 0); diff --git a/src/mainview/components/CallOverlay.qml b/src/mainview/components/CallOverlay.qml index 2f4eac56a575754d5c5c5f331b4b297f3754a130..75774d34f1aa8aa61465ba1fc0ff6eae44070346 100644 --- a/src/mainview/components/CallOverlay.qml +++ b/src/mainview/components/CallOverlay.qml @@ -3,6 +3,7 @@ * Copyright (C) 2020 by Savoir-faire Linux * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * 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 @@ -25,6 +26,7 @@ import QtQml 2.14 import net.jami.Models 1.0 import "../js/contactpickercreation.js" as ContactPickerCreation +import "../js/mediahandlerpickercreation.js" as MediaHandlerPickerCreation import "../../commoncomponents" @@ -67,6 +69,10 @@ Rectangle { ContactPickerCreation.closeContactPicker() } + function closePotentialMediaHandlerPicker() { + MediaHandlerPickerCreation.closeMediaHandlerPicker() + } + function handleParticipantsInfo(infos) { videoCallOverlay.updateMaster() var isMaster = CallAdapter.isCurrentMaster() @@ -389,11 +395,15 @@ Rectangle { onWidthChanged: { ContactPickerCreation.calculateCurrentGeo(callOverlayRect.width / 2, callOverlayRect.height / 2) + MediaHandlerPickerCreation.calculateCurrentGeo(callOverlayRect.width / 2, + callOverlayRect.height / 2) } onHeightChanged: { ContactPickerCreation.calculateCurrentGeo(callOverlayRect.width / 2, callOverlayRect.height / 2) + MediaHandlerPickerCreation.calculateCurrentGeo(callOverlayRect.width / 2, + callOverlayRect.height / 2) } CallViewContextMenu { @@ -410,6 +420,14 @@ Rectangle { callOverlayRect.width / 2, callOverlayRect.height / 2) ContactPickerCreation.openContactPicker() } + + onPluginItemClicked: { + // Create media handler picker - PLUGINS + MediaHandlerPickerCreation.createMediaHandlerPickerObjects(callOverlayRect) + MediaHandlerPickerCreation.calculateCurrentGeo( + callOverlayRect.width / 2, callOverlayRect.height / 2) + MediaHandlerPickerCreation.openMediaHandlerPicker() + } } ParticipantContextMenu { diff --git a/src/mainview/components/CallViewContextMenu.qml b/src/mainview/components/CallViewContextMenu.qml index 93b008f1db281c895b07281cb445dab20955ce4d..23da3fd700184a619072fef6b35d1437f70e9a46 100644 --- a/src/mainview/components/CallViewContextMenu.qml +++ b/src/mainview/components/CallViewContextMenu.qml @@ -1,7 +1,8 @@ -/* +/** * Copyright (C) 2020 by Savoir-faire Linux * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * 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 @@ -31,6 +32,9 @@ Menu { property int generalMenuSeparatorCount: 0 property int commonBorderWidth: 1 + + signal pluginItemClicked + font.pointSize: JamiTheme.textFontSize+3 property bool isSIP: false @@ -267,7 +271,7 @@ Menu { onClicked: { root.close() } - } + }*/ GeneralMenuItem { id: pluginItem @@ -278,9 +282,10 @@ Menu { rightBorderWidth: commonBorderWidth onClicked: { + root.pluginItemClicked() root.close() } - }*/ + } background: Rectangle { implicitWidth: startRecordingItem.preferredWidth diff --git a/src/mainview/components/MediaHandlerItemDelegate.qml b/src/mainview/components/MediaHandlerItemDelegate.qml new file mode 100644 index 0000000000000000000000000000000000000000..650f024595ceda826a95c9fd87d5b15c1bbfd4cf --- /dev/null +++ b/src/mainview/components/MediaHandlerItemDelegate.qml @@ -0,0 +1,144 @@ +/** + * Copyright (C) 2020 by Savoir-faire Linux + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> + * + * 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/>. + */ + +import QtQuick 2.15 +import QtQuick.Window 2.15 +import QtQuick.Controls 2.15 +import QtQuick.Controls.Universal 2.12 +import QtQuick.Layouts 1.3 +import QtGraphicalEffects 1.14 +import QtQuick.Controls.Styles 1.4 +import net.jami.Models 1.0 + +import "../../commoncomponents" + +ItemDelegate { + id: root + + property string mediaHandlerName : "" + property string mediaHandlerId: "" + property string mediaHandlerIcon: "" + property bool isLoaded: false + + signal btnLoadMediaHandlerToggled + + highlighted: ListView.isCurrentItem + + RowLayout{ + anchors.fill: parent + + Label{ + Layout.leftMargin: 8 + Layout.bottomMargin: 8 + + Layout.minimumWidth: 30 + Layout.preferredWidth: 30 + Layout.maximumWidth: 30 + + Layout.minimumHeight: 30 + Layout.preferredHeight: 30 + Layout.maximumHeight: 30 + + background: Rectangle{ + anchors.fill: parent + Image { + anchors.fill: parent + source: "file:" + mediaHandlerIcon + } + } + } + + ColumnLayout{ + Layout.fillWidth: true + Layout.fillHeight: true + + Layout.leftMargin: 8 + Layout.topMargin: 8 + Layout.bottomMargin: 8 + + RowLayout{ + + Layout.minimumHeight: 30 + + Label{ + id: labelDeviceId + + Layout.minimumHeight: 20 + + font.pointSize: 10 + font.kerning: true + text: mediaHandlerName === "" ? mediaHandlerId : mediaHandlerName + } + + Item{ + Layout.fillWidth: true + + Layout.minimumWidth: 0 + Layout.minimumHeight: 20 + } + } + } + + Switch { + id: loadSwitch + property bool isHovering: false + + Layout.bottomMargin: 8 + Layout.rightMargin: 22 + Layout.alignment: Qt.AlignRight + + Layout.maximumWidth: 30 + Layout.preferredWidth: 30 + Layout.minimumWidth: 30 + + Layout.minimumHeight: 30 + Layout.preferredHeight: 30 + Layout.maximumHeight: 30 + + ToolTip.visible: isHovering + ToolTip.text: { + return qsTr("On/Off") + } + + checked: isLoaded + onClicked: { + btnLoadMediaHandlerToggled() + } + + background: Rectangle { + id: switchBackground + MouseArea { + id: btnMouseArea + anchors.fill: parent + hoverEnabled: true + onPressed: { + } + onReleased: { + loadSwitch.clicked() + } + onEntered: { + loadSwitch.isHovering = true + } + onExited: { + loadSwitch.isHovering = false + } + } + } + } + } +} diff --git a/src/mainview/components/MediaHandlerPicker.qml b/src/mainview/components/MediaHandlerPicker.qml new file mode 100644 index 0000000000000000000000000000000000000000..f6a1cc8af1f8a75604ad92596c361895de226719 --- /dev/null +++ b/src/mainview/components/MediaHandlerPicker.qml @@ -0,0 +1,131 @@ +/** + * Copyright (C) 2020 by Savoir-faire Linux + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> + * + * 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 <https://www.gnu.org/licenses/>. + */ +import QtQuick 2.14 +import QtQuick.Controls 2.14 +import QtQuick.Layouts 1.14 +import QtQuick.Controls.Universal 2.12 +import net.jami.Models 1.0 + +import "../../commoncomponents" + +Popup { + id: mediahandlerPickerPopup + + function toggleMediaHandlerSlot(mediaHandlerId, isLoaded) { + ClientWrapper.pluginModel.toggleCallMediaHandler(mediaHandlerId, !isLoaded) + mediahandlerPickerListView.model = MediaHandlerAdapter.getMediaHandlerSelectableModel() + } + + contentWidth: 350 + contentHeight: mediahandlerPickerPopupRectColumnLayout.height + 50 + + padding: 0 + + modal: true + + contentItem: Rectangle { + id: mediahandlerPickerPopupRect + + width: 250 + + HoverableButton { + id: closeButton + + anchors.top: mediahandlerPickerPopupRect.top + anchors.topMargin: 5 + anchors.right: mediahandlerPickerPopupRect.right + anchors.rightMargin: 5 + + width: 30 + height: 30 + + radius: 30 + source: "qrc:/images/icons/round-close-24px.svg" + + onClicked: { + mediahandlerPickerPopup.close() + } + } + + ColumnLayout { + id: mediahandlerPickerPopupRectColumnLayout + + anchors.top: mediahandlerPickerPopupRect.top + anchors.topMargin: 15 + + Text { + id: mediahandlerPickerTitle + + Layout.alignment: Qt.AlignCenter + Layout.preferredWidth: mediahandlerPickerPopupRect.width + Layout.preferredHeight: 30 + + font.pointSize: JamiTheme.textFontSize + font.bold: true + + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + + text: qsTr("Choose plugin") + } + + ListView { + id: mediahandlerPickerListView + + Layout.alignment: Qt.AlignCenter + Layout.preferredWidth: mediahandlerPickerPopupRect.width + Layout.preferredHeight: 200 + + model: MediaHandlerAdapter.getMediaHandlerSelectableModel() + + clip: true + + delegate: MediaHandlerItemDelegate { + id: mediaHandlerItemDelegate + visible: ClientWrapper.pluginModel.getPluginsEnabled() + width: mediahandlerPickerListView.width + height: 50 + + mediaHandlerName : MediaHandlerName + mediaHandlerId: MediaHandlerId + mediaHandlerIcon: MediaHandlerIcon + isLoaded: IsLoaded + + onBtnLoadMediaHandlerToggled: { + toggleMediaHandlerSlot(mediaHandlerId, isLoaded) + } + + } + + ScrollIndicator.vertical: ScrollIndicator {} + } + } + + radius: 10 + color: "white" + } + + onAboutToShow: { + // Reset the model on each show. + mediahandlerPickerListView.model = MediaHandlerAdapter.getMediaHandlerSelectableModel() + } + + background: Rectangle { + color: "transparent" + } +} diff --git a/src/mainview/js/mediahandlerpickercreation.js b/src/mainview/js/mediahandlerpickercreation.js new file mode 100644 index 0000000000000000000000000000000000000000..1a14eca22776448d48e9b7aff07a873281b70e79 --- /dev/null +++ b/src/mainview/js/mediahandlerpickercreation.js @@ -0,0 +1,72 @@ +/** + * Copyright (C) 2020 by Savoir-faire Linux + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> + * + * 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 <https://www.gnu.org/licenses/>. + */ + + +/* + * Global mediahandler picker component, object variable for creation. + */ +var mediahandlerPickerComponent +var mediahandlerPickerObject + +function createMediaHandlerPickerObjects(parent) { + if (mediahandlerPickerObject) { + /* + * If already created, reset parameters, since object cannot be destroyed. + */ + mediahandlerPickerObject.parent = parent + return + } + mediahandlerPickerComponent = Qt.createComponent( + "../components/MediaHandlerPicker.qml") + if (mediahandlerPickerComponent.status === Component.Ready) + finishCreation(parent) + else if (mediahandlerPickerComponent.status === Component.Error) + console.log("Error loading component:", + mediahandlerPickerComponent.errorString()) +} + +function finishCreation(parent) { + mediahandlerPickerObject = mediahandlerPickerComponent.createObject(parent) + if (mediahandlerPickerObject === null) { + /* + * Error Handling. + */ + console.log("Error creating object for mediahandler picker") + } +} + + +/* + * Put mediahandler picker in the middle of container. + */ +function calculateCurrentGeo(containerX, containerY) { + if (mediahandlerPickerObject) { + mediahandlerPickerObject.x = containerX - mediahandlerPickerObject.width / 2 + mediahandlerPickerObject.y = containerY - mediahandlerPickerObject.height / 2 + } +} + +function openMediaHandlerPicker() { + if (mediahandlerPickerObject) + mediahandlerPickerObject.open() +} + +function closeMediaHandlerPicker() { + if (mediahandlerPickerObject) + mediahandlerPickerObject.close() +} diff --git a/src/mediahandleradapter.cpp b/src/mediahandleradapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f8cb0ddf10453a47b41491acbd43a2c16d9ce20c --- /dev/null +++ b/src/mediahandleradapter.cpp @@ -0,0 +1,43 @@ +/** + * Copyright (C) 2020 by Savoir-faire Linux + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> + * + * 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 "mediahandleradapter.h" + +#include "lrcinstance.h" + +MediaHandlerAdapter::MediaHandlerAdapter(QObject *parent) + : QmlAdapterBase(parent) +{ } + +MediaHandlerAdapter::~MediaHandlerAdapter() {} + +QVariant +MediaHandlerAdapter::getMediaHandlerSelectableModel() +{ + /* + * Called from qml every time contact picker refreshes. + */ + mediaHandlerListModel_.reset(new MediaHandlerItemListModel(this)); + + return QVariant::fromValue(mediaHandlerListModel_.get()); +} + + +void +MediaHandlerAdapter::initQmlObject() +{} diff --git a/src/mediahandleradapter.h b/src/mediahandleradapter.h new file mode 100644 index 0000000000000000000000000000000000000000..6af2d130dad51a7be591a09f06bdbb1c847c47c8 --- /dev/null +++ b/src/mediahandleradapter.h @@ -0,0 +1,44 @@ +/** + * Copyright (C) 2020 by Savoir-faire Linux + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> + * + * 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/>. + */ + +#pragma once + +#include "qmladapterbase.h" +//#include "smartlistmodel.h" +#include "mediahandleritemlistmodel.h" + +#include <QObject> +#include <QSortFilterProxyModel> +#include <QString> + +class MediaHandlerAdapter : public QmlAdapterBase +{ + Q_OBJECT + +public: + explicit MediaHandlerAdapter(QObject *parent = nullptr); + ~MediaHandlerAdapter(); + + Q_INVOKABLE QVariant getMediaHandlerSelectableModel(); + +private: + void initQmlObject(); + + std::unique_ptr<MediaHandlerItemListModel> mediaHandlerListModel_; + +}; diff --git a/src/mediahandleritemlistmodel.cpp b/src/mediahandleritemlistmodel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..648cfeff3595c7668f20b9a9c48cb802c7aae75d --- /dev/null +++ b/src/mediahandleritemlistmodel.cpp @@ -0,0 +1,128 @@ +/** + * Copyright (C) 2020 by Savoir-faire Linux + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> + * + * 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 "mediahandleritemlistmodel.h" + +MediaHandlerItemListModel::MediaHandlerItemListModel(QObject *parent) + : QAbstractListModel(parent) +{} + +MediaHandlerItemListModel::~MediaHandlerItemListModel() {} + +int +MediaHandlerItemListModel::rowCount(const QModelIndex &parent) const +{ + if (!parent.isValid()) { + /* + * Count. + */ + return LRCInstance::pluginModel().listCallMediaHandlers().size(); + } + /* + * A valid QModelIndex returns 0 as no entry has sub-elements. + */ + return 0; +} + +int +MediaHandlerItemListModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + /* + * Only need one column. + */ + return 1; +} + +QVariant +MediaHandlerItemListModel::data(const QModelIndex &index, int role) const +{ + auto mediahandlerList = LRCInstance::pluginModel().listCallMediaHandlers(); + if (!index.isValid() || mediahandlerList.size() <= index.row()) { + return QVariant(); + } + + auto details = LRCInstance::pluginModel().getCallMediaHandlerDetails( + mediahandlerList.at(index.row())); + auto status = LRCInstance::pluginModel().getCallMediaHandlerStatus(); + bool loaded = false; + if (status["name"] == details.id) + loaded = true; + + switch (role) { + case Role::MediaHandlerName: + return QVariant(details.name); + case Role::MediaHandlerId: + return QVariant(mediahandlerList.at(index.row())); + case Role::MediaHandlerIcon: + return QVariant(details.iconPath); + case Role::IsLoaded: + return QVariant(loaded); + } + return QVariant(); +} + +QHash<int, QByteArray> +MediaHandlerItemListModel::roleNames() const +{ + QHash<int, QByteArray> roles; + roles[MediaHandlerName] = "MediaHandlerName"; + roles[MediaHandlerId] = "MediaHandlerId"; + roles[MediaHandlerIcon] = "MediaHandlerIcon"; + roles[IsLoaded] = "IsLoaded"; + + return roles; +} + +QModelIndex +MediaHandlerItemListModel::index(int row, int column, const QModelIndex &parent) const +{ + Q_UNUSED(parent); + if (column != 0) { + return QModelIndex(); + } + + if (row >= 0 && row < rowCount()) { + return createIndex(row, column); + } + return QModelIndex(); +} + +QModelIndex +MediaHandlerItemListModel::parent(const QModelIndex &child) const +{ + Q_UNUSED(child); + return QModelIndex(); +} + +Qt::ItemFlags +MediaHandlerItemListModel::flags(const QModelIndex &index) const +{ + auto flags = QAbstractItemModel::flags(index) | Qt::ItemNeverHasChildren | Qt::ItemIsSelectable; + if (!index.isValid()) { + return QAbstractItemModel::flags(index); + } + return flags; +} + +void +MediaHandlerItemListModel::reset() +{ + beginResetModel(); + endResetModel(); +} diff --git a/src/mediahandleritemlistmodel.h b/src/mediahandleritemlistmodel.h new file mode 100644 index 0000000000000000000000000000000000000000..ad3e43cc2af3430b9cc49cceffcc9f4ebb9d8b6b --- /dev/null +++ b/src/mediahandleritemlistmodel.h @@ -0,0 +1,56 @@ +/** + * Copyright (C) 2020 by Savoir-faire Linux + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> + * + * 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/>. + */ + +#pragma once + +#include <QAbstractItemModel> + +#include "api/pluginmodel.h" + +#include "lrcinstance.h" + +class MediaHandlerItemListModel : public QAbstractListModel +{ + Q_OBJECT + +public: + enum Role { MediaHandlerName = Qt::UserRole + 1, MediaHandlerId, MediaHandlerIcon, IsLoaded }; + Q_ENUM(Role) + + explicit MediaHandlerItemListModel(QObject *parent = 0); + ~MediaHandlerItemListModel(); + + /* + * QAbstractListModel override. + */ + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent) const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + /* + * Override role name as access point in qml. + */ + QHash<int, QByteArray> roleNames() const override; + QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &child) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + + /* + * This function is to reset the model when there's new account added. + */ + Q_INVOKABLE void reset(); +}; diff --git a/src/preferenceitemlistmodel.cpp b/src/preferenceitemlistmodel.cpp index 8e90426ee5451db972f4a31d1a119da0bc016f51..245ee77def2a76c330b4c0e82fe8f961d08a86cb 100644 --- a/src/preferenceitemlistmodel.cpp +++ b/src/preferenceitemlistmodel.cpp @@ -1,6 +1,6 @@ -/* - * Copyright (C) 2019-2020 by Savoir-faire Linux - * Author: Yang Wang <yang.wang@savoirfairelinux.com> +/** + * Copyright (C) 2020 by Savoir-faire Linux + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * 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 diff --git a/src/preferenceitemlistmodel.h b/src/preferenceitemlistmodel.h index c51a0701c84752ccb863fb5769c8727e76e27368..4c53d74cc32e2ddfb09d9925391bc2b55865dd2c 100644 --- a/src/preferenceitemlistmodel.h +++ b/src/preferenceitemlistmodel.h @@ -1,6 +1,6 @@ -/* - * Copyright (C) 2019-2020 by Savoir-faire Linux - * Author: Yang Wang <yang.wang@savoirfairelinux.com> +/** + * Copyright (C) 2020 by Savoir-faire Linux + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * 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 @@ -27,16 +27,16 @@ class PreferenceItemListModel : public QAbstractListModel { Q_OBJECT - + Q_PROPERTY(QString pluginId READ pluginId WRITE setPluginId) public: enum Role { PreferenceKey = Qt::UserRole + 1, PreferenceName, PreferenceSummary, PreferenceType, PreferenceDefaultValue, PreferenceEntries, PreferenceEntryValues}; - + typedef enum { LIST, DEFAULT, } Type; - + Q_ENUM(Role) explicit PreferenceItemListModel(QObject *parent = 0); @@ -57,7 +57,7 @@ public: Qt::ItemFlags flags(const QModelIndex &index) const; /* - * This function is to reset the model when there's new account added. + * This function is to reset the model when there's new plugin added or modified. */ Q_INVOKABLE void reset(); diff --git a/src/settingsview/components/PluginListPreferencesView.qml b/src/settingsview/components/PluginListPreferencesView.qml index 9b8c03afe264f765adbb87fdbb97f87ea1609db3..2bce00218540a3175c69aa0996a46e517012ed74 100644 --- a/src/settingsview/components/PluginListPreferencesView.qml +++ b/src/settingsview/components/PluginListPreferencesView.qml @@ -1,6 +1,6 @@ -/* - * Copyright (C) 2019-2020 by Savoir-faire Linux - * Author: Yang Wang <yang.wang@savoirfairelinux.com> +/** + * Copyright (C) 2020 by Savoir-faire Linux + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * 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 @@ -72,7 +72,7 @@ Rectangle { function getSize(pluginId, show){ size = 50 * ClientWrapper.pluginModel.getPluginPreferences(pluginId).length if (show) { - height = 200 + size + height = 200 + size pluginPreferenceView.height = size } else { height = 25 diff --git a/src/settingsview/components/PluginSettingsPage.qml b/src/settingsview/components/PluginSettingsPage.qml index a9d59d0ed71272b6ddf141b2d8740da5d6c9f08f..636b8106f0ec2bf689eb71de76b64a775e425168 100644 --- a/src/settingsview/components/PluginSettingsPage.qml +++ b/src/settingsview/components/PluginSettingsPage.qml @@ -128,6 +128,7 @@ Rectangle { pluginListSettingsView.visible = checked if (!checked) { pluginListPreferencesView.visible = checked + ClientWrapper.pluginModel.toggleCallMediaHandler("",true); } if (pluginListSettingsView.visible) { pluginListSettingsView.updatePluginListDisplayed() diff --git a/src/utils.cpp b/src/utils.cpp index a397cab7699c240a098b8be5df15900e87af5586..1556f9da6cf301c92c67621c64193c28e8668ec6 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -4,6 +4,7 @@ * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> * Author: Isa Nanic <isa.nanic@savoirfairelinux.com * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * 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 @@ -1080,3 +1081,10 @@ UtilsAdapter::getCurrentPath() { return QDir::currentPath(); } + +bool +UtilsAdapter::checkShowPluginsButton() +{ + return LRCInstance::pluginModel().getPluginsEnabled() + && (LRCInstance::pluginModel().listLoadedPlugins().size() > 0); +} \ No newline at end of file diff --git a/src/utils.h b/src/utils.h index 64db4517c022ccb0b3be05f67bc41efb0d6285c8..28f3ef01eb17fca1e77ba7ca0c5db212f06566b4 100644 --- a/src/utils.h +++ b/src/utils.h @@ -4,6 +4,7 @@ * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> * Author: Isa Nanic <isa.nanic@savoirfairelinux.com> * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * 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 @@ -554,6 +555,8 @@ public: return QString::fromLatin1(Utils::QImageToByteArray(croppedImage).toBase64().data()); } + Q_INVOKABLE bool checkShowPluginsButton(); + private: QClipboard *clipboard_; };