From ebc07155448963115cd8daed43e08967c0c2ae14 Mon Sep 17 00:00:00 2001
From: agsantos <aline.gondimsantos@savoirfairelinux.com>
Date: Fri, 11 Dec 2020 15:41:20 -0500
Subject: [PATCH] settings: improve plugins view

GitLab: #52
Change-Id: I4ee232092da3b26e4471ccc7c46e57d2d0562856
---
 .../PreferenceItemDelegate.qml                |   1 +
 src/pluginadapter.h                           |   1 +
 src/preferenceitemlistmodel.cpp               |   7 +-
 .../components/PluginItemDelegate.qml         | 164 +++++++++++-------
 .../components/PluginListPreferencesView.qml  |  18 +-
 .../components/PluginListSettingsView.qml     |  41 +----
 .../components/PluginSettingsPage.qml         |  18 +-
 7 files changed, 125 insertions(+), 125 deletions(-)

diff --git a/src/commoncomponents/PreferenceItemDelegate.qml b/src/commoncomponents/PreferenceItemDelegate.qml
index 97c8af5d0..7bfcd5115 100644
--- a/src/commoncomponents/PreferenceItemDelegate.qml
+++ b/src/commoncomponents/PreferenceItemDelegate.qml
@@ -65,6 +65,7 @@ ItemDelegate {
                 if (index === 0) {
                     preferenceFilePathDialog.title = qsTr("Select An Image to " + preferenceName)
                     preferenceFilePathDialog.nameFilters = fileFilters
+                    preferenceFilePathDialog.selectedNameFilter.index = fileFilters.length - 1
                     preferenceFilePathDialog.open()
                 }
                 else
diff --git a/src/pluginadapter.h b/src/pluginadapter.h
index bf2371244..5cc0f53ef 100644
--- a/src/pluginadapter.h
+++ b/src/pluginadapter.h
@@ -48,6 +48,7 @@ protected:
 signals:
     void pluginHandlersUpdateStatus();
     void preferenceChanged(QString pluginId);
+    void pluginUninstalled();
 
 private:
     std::unique_ptr<PluginHandlerItemListModel> pluginHandlerListModel_;
diff --git a/src/preferenceitemlistmodel.cpp b/src/preferenceitemlistmodel.cpp
index bd4e35e5d..a2c8aeb41 100644
--- a/src/preferenceitemlistmodel.cpp
+++ b/src/preferenceitemlistmodel.cpp
@@ -74,10 +74,11 @@ PreferenceItemListModel::data(const QModelIndex& index, int role) const
             currentPath.truncate(preferenceCurrent.lastIndexOf("/"));
             QStringList mimeTypeList = details["mimeType"].split(',');
             for (auto& mimeType : mimeTypeList) {
-                QString fileExt = mimeType.mid(mimeType.lastIndexOf("/") + 1);
-                acceptedFiles.append((fileExt.toUpper() + " Files") + " (*." + fileExt + ")");
-                checkImage = Utils::isImage(fileExt);
+                mimeType = mimeType.mid(mimeType.lastIndexOf("/") + 1);
+                acceptedFiles.append((mimeType.toUpper() + " Files") + " (*." + mimeType + ")");
+                checkImage |= Utils::isImage(mimeType);
             }
+            acceptedFiles.append(QString("All (*.%1)").arg(mimeTypeList.join(" *.")));
         }
     }
     switch (role) {
diff --git a/src/settingsview/components/PluginItemDelegate.qml b/src/settingsview/components/PluginItemDelegate.qml
index a07a36d13..a50966fc7 100644
--- a/src/settingsview/components/PluginItemDelegate.qml
+++ b/src/settingsview/components/PluginItemDelegate.qml
@@ -36,85 +36,127 @@ ItemDelegate {
     property bool isLoaded: false
 
     signal btnLoadPluginToggled
-    signal btnPreferencesPluginClicked
 
-    RowLayout {
-        anchors.fill: parent
+    function btnPreferencesPluginClicked() {
+        pluginListPreferencesView.pluginName = pluginName
+        pluginListPreferencesView.pluginIcon = pluginIcon
+        pluginListPreferencesView.pluginId = pluginId
+        pluginListPreferencesView.isLoaded = isLoaded
+        if (!pluginListPreferencesView.visible) {
+            pluginListPreferencesView.visible = !pluginListPreferencesView.visible
+            root.height += pluginListPreferencesView.childrenRect.height
+        } else {
+            root.height -= pluginListPreferencesView.childrenRect.height
+            pluginListPreferencesView.visible = !pluginListPreferencesView.visible
+        }
+    }
 
-        Label {
-            id: pluginImage
-            Layout.leftMargin: 8
-            Layout.alignment: Qt.AlignLeft | Qt.AlingVCenter
-            width: 30
-
-            background: Rectangle {
-                color: "transparent"
-                Image {
-                    anchors.centerIn: parent
-                    source: "file:" + pluginIcon
-                    sourceSize: Qt.size(256, 256)
-                    mipmap: true
-                    width: 32
-                    height: 32
-                }
-            }
+    Connections {
+        target: enabledplugin
+
+        function onHidePreferences() {
+            root.height = 50
+            pluginListPreferencesView.visible = false
         }
+    }
+
+    ColumnLayout {
+        anchors.fill: parent
+        Layout.preferredHeight: childrenRect.height
 
-        Label {
-            id: labelDeviceId
+        RowLayout {
             Layout.fillWidth: true
-            Layout.leftMargin: 8
-            color: JamiTheme.textColor
 
-            font.pointSize: JamiTheme.settingsFontSize
-            font.kerning: true
-            text: pluginName === "" ? pluginId : pluginName
-        }
+            Label {
+                id: pluginImage
+                Layout.leftMargin: 8
+                Layout.alignment: Qt.AlignLeft | Qt.AlingVCenter
+                width: 30
+
+                background: Rectangle {
+                    color: "transparent"
+                    Image {
+                        anchors.centerIn: parent
+                        source: "file:" + pluginIcon
+                        sourceSize: Qt.size(256, 256)
+                        mipmap: true
+                        width: 32
+                        height: 32
+                    }
+                }
+            }
 
-        Switch {
-            id: loadSwitch
-            property bool isHovering: false
-            Layout.rightMargin: 8
-            width: 20
+            Label {
+                id: labelDeviceId
+                Layout.fillWidth: true
+                Layout.leftMargin: 8
+                color: JamiTheme.textColor
 
-            ToolTip.visible: hovered
-            ToolTip.text: qsTr("Load/Unload")
+                font.pointSize: JamiTheme.settingsFontSize
+                font.kerning: true
+                text: pluginName === "" ? pluginId : pluginName
+            }
 
-            checked: isLoaded
-            onClicked: btnLoadPluginToggled()
+            Switch {
+                id: loadSwitch
+                property bool isHovering: false
+                Layout.rightMargin: 8
+                width: 20
 
-            background: Rectangle {
-                id: switchBackground
+                ToolTip.visible: hovered
+                ToolTip.text: qsTr("Load/Unload")
 
-                color: "transparent"
-                MouseArea {
-                    id: btnMouseArea
-                    hoverEnabled: true
-                    onReleased: {
-                        loadSwitch.clicked()
-                    }
-                    onEntered: {
-                        loadSwitch.isHovering = true
-                    }
-                    onExited: {
-                        loadSwitch.isHovering = false
+                checked: isLoaded
+                onClicked: {
+                    btnLoadPluginToggled()
+                    pluginListPreferencesView.isLoaded = root.isLoaded
+                }
+
+                background: Rectangle {
+                    id: switchBackground
+
+                    color: "transparent"
+                    MouseArea {
+                        id: btnMouseArea
+                        hoverEnabled: true
+                        onReleased: {
+                            loadSwitch.clicked()
+                        }
+                        onEntered: {
+                            loadSwitch.isHovering = true
+                        }
+                        onExited: {
+                            loadSwitch.isHovering = false
+                        }
                     }
                 }
             }
-        }
 
-        PushButton {
-            id: btnPreferencesPlugin
+            PushButton {
+                id: btnPreferencesPlugin
+
+                Layout.alignment: Qt.AlingVCenter | Qt.AlignRight
+                Layout.rightMargin: 8
+
+                source: "qrc:/images/icons/round-settings-24px.svg"
+                normalColor: JamiTheme.primaryBackgroundColor
+                imageColor: JamiTheme.textColor
+                toolTipText: JamiStrings.showHidePrefs
 
-            Layout.alignment: Qt.AlingVCenter | Qt.AlignRight
-            Layout.rightMargin: 8
+                onClicked: btnPreferencesPluginClicked()
+            }
+        }
 
-            source: "qrc:/images/icons/round-settings-24px.svg"
-            normalColor: JamiTheme.primaryBackgroundColor
-            imageColor: JamiTheme.textColor
-            toolTipText: JamiStrings.showHidePrefs
+        PluginListPreferencesView {
+            id: pluginListPreferencesView
 
-            onClicked: btnPreferencesPluginClicked()
+            Layout.topMargin: 10
+            Layout.fillWidth: true
+            Layout.leftMargin: JamiTheme.preferredMarginSize
+            Layout.rightMargin: JamiTheme.preferredMarginSize
+            Layout.bottomMargin: JamiTheme.preferredMarginSize
+            Layout.minimumHeight: 1
+            Layout.preferredHeight: childrenRect.height
         }
     }
 }
diff --git a/src/settingsview/components/PluginListPreferencesView.qml b/src/settingsview/components/PluginListPreferencesView.qml
index 04629484f..4ad61a06b 100644
--- a/src/settingsview/components/PluginListPreferencesView.qml
+++ b/src/settingsview/components/PluginListPreferencesView.qml
@@ -48,7 +48,7 @@ Rectangle {
 
     signal uninstalled
 
-    Connections{
+    Connections {
         target: PluginAdapter
 
         function onPreferenceChanged(pluginId) {
@@ -58,7 +58,9 @@ Rectangle {
     }
 
     function resetPluginSlot() {
-        msgDialog.buttonCallBacks = [function () {resetPlugin()}]
+        msgDialog.buttonCallBacks = [function () {
+            resetPlugin()
+        }]
         msgDialog.openWithParameters(qsTr("Reset preferences"),
                                      qsTr("Are you sure you wish to reset "+ pluginName +
                                           " preferences?"))
@@ -79,17 +81,16 @@ Rectangle {
     function uninstallPluginSlot() {
         msgDialog.buttonCallBacks = [function () {
             uninstallPlugin()
-            root.visible = false
         }]
         msgDialog.openWithParameters(qsTr("Uninstall plugin"),
                                      qsTr("Are you sure you wish to uninstall " + pluginName + " ?"))
-        PluginAdapter.pluginHandlersUpdateStatus()
     }
 
     function uninstallPlugin() {
         PluginModel.uninstallPlugin(pluginId)
-        uninstalled()
+        PluginAdapter.pluginUninstalled()
         PluginAdapter.pluginHandlersUpdateStatus()
+        root.visible = false
     }
 
     function setPreference(pluginId, preferenceKey, preferenceNewValue)
@@ -109,11 +110,6 @@ Rectangle {
         buttonTitles: [qsTr("Ok"), qsTr("Cancel")]
         buttonStyles: [SimpleMessageDialog.ButtonStyle.TintedBlue,
                        SimpleMessageDialog.ButtonStyle.TintedBlack]
-
-        onAccepted: {
-            uninstallPlugin()
-            root.visible = false
-        }
     }
 
     ColumnLayout {
@@ -192,7 +188,7 @@ Rectangle {
             id: pluginPreferenceView
 
             Layout.fillWidth: true
-            Layout.minimumHeight: 0
+            Layout.minimumHeight: 1
             Layout.preferredHeight: childrenRect.height + 30
 
             model: PluginAdapter.getPluginPreferencesModel(pluginId)
diff --git a/src/settingsview/components/PluginListSettingsView.qml b/src/settingsview/components/PluginListSettingsView.qml
index 96dbd33c7..9b053eafa 100644
--- a/src/settingsview/components/PluginListSettingsView.qml
+++ b/src/settingsview/components/PluginListSettingsView.qml
@@ -31,12 +31,10 @@ import "../../commoncomponents"
 Rectangle {
     id: root
 
-    property PluginListPreferencesView pluginListPreferencesView
-
     Connections {
-        target: pluginListPreferencesView
+        target: PluginAdapter
 
-        function onUninstalled() {
+        function onPluginUninstalled() {
             pluginListView.model = PluginAdapter.getPluginSelectableModel()
         }
     }
@@ -54,28 +52,8 @@ Rectangle {
             PluginModel.unloadPlugin(pluginId)
         else
             loaded = PluginModel.loadPlugin(pluginId)
-        if (pluginListPreferencesView.pluginId === pluginId)
-            pluginListPreferencesView.isLoaded = loaded
         PluginAdapter.pluginHandlersUpdateStatus()
-    }
-
-    function openPreferencesPluginSlot(pluginName, pluginIcon, pluginId, isLoaded) {
-        if (pluginListPreferencesView.pluginId == pluginId || pluginListPreferencesView.pluginId == "")
-            pluginListPreferencesView.visible = !pluginListPreferencesView.visible
-
-        if (!pluginListPreferencesView.visible) {
-            pluginListPreferencesView.pluginId = ""
-        } else {
-            pluginListPreferencesView.pluginName = pluginName
-            pluginListPreferencesView.pluginIcon = pluginIcon
-            pluginListPreferencesView.pluginId = pluginId
-            pluginListPreferencesView.isLoaded = isLoaded
-        }
-    }
-
-    function hidePreferences() {
-        pluginListPreferencesView.pluginId = ""
-        pluginListPreferencesView.visible = false
+        return loaded
     }
 
     JamiFileDialog {
@@ -140,6 +118,7 @@ Rectangle {
             Layout.fillWidth: true
             Layout.minimumHeight: 0
             Layout.preferredHeight: childrenRect.height
+            Layout.bottomMargin: 10
 
             model: PluginAdapter.getPluginSelectableModel()
             interactive: false
@@ -148,7 +127,7 @@ Rectangle {
                 id: pluginItemDelegate
 
                 width: pluginListView.width
-                height: 50
+                implicitHeight: 50
 
                 pluginName: PluginName
                 pluginId: PluginId
@@ -156,15 +135,7 @@ Rectangle {
                 isLoaded: IsLoaded
 
                 onBtnLoadPluginToggled: {
-                    loadPluginSlot(pluginId, isLoaded)
-                    pluginListView.model = PluginAdapter.getPluginSelectableModel()
-                }
-
-                onBtnPreferencesPluginClicked: openPreferencesPluginSlot(pluginName, pluginIcon, pluginId, isLoaded)
-
-                background: Rectangle {
-                    anchors.fill: parent
-                    color: JamiTheme.secondaryBackgroundColor
+                    isLoaded = loadPluginSlot(pluginId, isLoaded)
                 }
             }
         }
diff --git a/src/settingsview/components/PluginSettingsPage.qml b/src/settingsview/components/PluginSettingsPage.qml
index 286637d14..91242913a 100644
--- a/src/settingsview/components/PluginSettingsPage.qml
+++ b/src/settingsview/components/PluginSettingsPage.qml
@@ -55,6 +55,8 @@ Rectangle {
         ToggleSwitch {
             id: enabledplugin
 
+            signal hidePreferences
+
             Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
             Layout.fillWidth: true
             Layout.topMargin: JamiTheme.preferredMarginSize
@@ -69,7 +71,7 @@ Rectangle {
 
                 pluginListSettingsView.visible = checked
                 if (!pluginListSettingsView.visible) {
-                    pluginListSettingsView.hidePreferences()
+                    hidePreferences()
                 }
             }
         }
@@ -82,23 +84,9 @@ Rectangle {
             Layout.leftMargin: JamiTheme.preferredMarginSize
             Layout.rightMargin: JamiTheme.preferredMarginSize
 
-            pluginListPreferencesView: pluginListPreferencesView
-
             Layout.topMargin: JamiTheme.preferredMarginSize
             Layout.minimumHeight: 0
             Layout.preferredHeight: childrenRect.height
         }
-
-        PluginListPreferencesView {
-            id: pluginListPreferencesView
-
-            Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
-            Layout.fillWidth: true
-            Layout.leftMargin: JamiTheme.preferredMarginSize
-            Layout.rightMargin: JamiTheme.preferredMarginSize
-            Layout.bottomMargin: JamiTheme.preferredMarginSize
-            Layout.minimumHeight: 0
-            Layout.preferredHeight: childrenRect.height
-        }
     }
 }
-- 
GitLab