2021-07-29 02:38:47 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 CutefishOS Team.
|
|
|
|
*
|
|
|
|
* Author: Reion Wong <reionwong@gmail.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
|
|
|
|
* 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.12
|
|
|
|
import QtQuick.Controls 2.4
|
|
|
|
import QtQuick.Layouts 1.3
|
|
|
|
import QtGraphicalEffects 1.0
|
|
|
|
import FishUI 1.0 as FishUI
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: control
|
|
|
|
|
|
|
|
property string url: main.url
|
|
|
|
|
|
|
|
width: 320 + FishUI.Units.largeSpacing * 2
|
|
|
|
height: _mainLayout.implicitHeight + FishUI.Units.largeSpacing * 2
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
anchors.fill: parent
|
|
|
|
color: FishUI.Theme.secondBackgroundColor
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
var items = mimeAppManager.recommendedApps(control.url)
|
|
|
|
|
|
|
|
for (var i in items) {
|
|
|
|
listView.model.append(items[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultCheckBox.checked = false
|
|
|
|
doneButton.focus = true
|
|
|
|
}
|
|
|
|
|
2021-07-29 02:45:04 -07:00
|
|
|
function openApp() {
|
|
|
|
if (defaultCheckBox.checked)
|
|
|
|
mimeAppManager.setDefaultAppForFile(control.url, listView.model.get(listView.currentIndex).desktopFile)
|
|
|
|
|
|
|
|
launcher.launchApp(listView.model.get(listView.currentIndex).desktopFile, control.url)
|
|
|
|
main.close()
|
|
|
|
}
|
|
|
|
|
2021-07-29 02:38:47 -07:00
|
|
|
Keys.enabled: true
|
|
|
|
Keys.onEscapePressed: main.close()
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
id: _mainLayout
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: FishUI.Units.largeSpacing
|
|
|
|
spacing: FishUI.Units.largeSpacing * 2
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
id: listView
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 200
|
|
|
|
model: ListModel {}
|
2021-08-07 18:29:04 -07:00
|
|
|
spacing: FishUI.Units.smallSpacing * 1.5
|
2021-07-29 02:38:47 -07:00
|
|
|
ScrollBar.vertical: ScrollBar {}
|
2021-08-07 18:29:04 -07:00
|
|
|
clip: true
|
2021-07-29 02:38:47 -07:00
|
|
|
|
|
|
|
Label {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text: qsTr("No applications")
|
|
|
|
visible: listView.count === 0
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate: Item {
|
|
|
|
id: item
|
|
|
|
width: ListView.view.width
|
2021-08-07 18:29:04 -07:00
|
|
|
height: 30 + FishUI.Units.largeSpacing
|
2021-07-29 02:38:47 -07:00
|
|
|
scale: mouseArea.pressed ? 0.95 : 1.0
|
|
|
|
|
|
|
|
Behavior on scale {
|
|
|
|
NumberAnimation {
|
|
|
|
duration: 100
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
property bool isSelected: listView.currentIndex === index
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: mouseArea
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
2021-07-29 02:45:04 -07:00
|
|
|
acceptedButtons: Qt.LeftButton
|
|
|
|
onDoubleClicked: control.openApp()
|
|
|
|
onClicked: listView.currentIndex = index
|
2021-07-29 02:38:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
anchors.fill: parent
|
|
|
|
radius: FishUI.Theme.bigRadius
|
|
|
|
color: isSelected ? FishUI.Theme.highlightColor
|
|
|
|
: mouseArea.containsMouse ? Qt.rgba(FishUI.Theme.textColor.r,
|
|
|
|
FishUI.Theme.textColor.g,
|
|
|
|
FishUI.Theme.textColor.b,
|
|
|
|
0.1) : "transparent"
|
|
|
|
smooth: true
|
|
|
|
}
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: FishUI.Units.smallSpacing
|
2021-08-07 18:29:04 -07:00
|
|
|
spacing: FishUI.Units.smallSpacing
|
2021-07-29 02:38:47 -07:00
|
|
|
|
2021-08-17 14:35:23 -07:00
|
|
|
FishUI.IconItem {
|
2021-07-29 02:38:47 -07:00
|
|
|
id: icon
|
2021-08-17 14:35:23 -07:00
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.preferredWidth: height
|
|
|
|
source: model.icon
|
2021-07-29 02:38:47 -07:00
|
|
|
Layout.alignment: Qt.AlignLeft
|
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
|
|
|
text: model.name
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.alignment: Qt.AlignLeft
|
|
|
|
color: isSelected ? FishUI.Theme.highlightedTextColor : FishUI.Theme.textColor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckBox {
|
|
|
|
id: defaultCheckBox
|
|
|
|
focusPolicy: Qt.NoFocus
|
|
|
|
text: qsTr("Set as default")
|
|
|
|
enabled: listView.count >= 1
|
|
|
|
padding: 0
|
|
|
|
}
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
spacing: FishUI.Units.largeSpacing
|
|
|
|
|
|
|
|
Button {
|
|
|
|
text: qsTr("Cancel")
|
|
|
|
Layout.fillWidth: true
|
|
|
|
onClicked: main.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: doneButton
|
|
|
|
focus: true
|
|
|
|
flat: true
|
|
|
|
text: qsTr("Open")
|
2021-08-31 14:31:38 -07:00
|
|
|
enabled: listView.count > 0
|
2021-07-29 02:38:47 -07:00
|
|
|
Layout.fillWidth: true
|
2021-07-29 02:45:04 -07:00
|
|
|
onClicked: control.openApp()
|
2021-07-29 02:38:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|