Debian Codegraph @

src/qml/Haruna/Components/SubtitlesFolders.qml

raw
1 /*
2 * SPDX-FileCopyrightText: 2020 George Florea Bănuș <[email protected]>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7 pragma ComponentBehavior: Bound
8
9 import QtQuick
10 import QtQuick.Layouts
11 import QtQuick.Controls
12
13 import org.kde.kirigami as Kirigami
14 import org.kde.haruna
15 import org.kde.haruna.settings
16
17 // Subtitles Folders
18 ColumnLayout {
19 id: root
20
21 // prevent creating multiple empty items
22 // until the new one has been saved
23 property bool canAddFolder: true
24
25 implicitHeight: sectionTitle.height + sfListView.implicitHeight + sfAddFolder.height + 25
26
27 RowLayout {
28 Label {
29 id: sectionTitle
30
31 text: i18nc("@label; Below is a list of folders containing subtitles", "Load subtitles from")
32 }
33 ToolTipButton {
34 toolTipText: i18nc("@info:tooltip;", "When a relative folder name starts with * (asterisk) "+
35 "and recursive search is enabled, all folders containing that name will be searched.\n"+
36 "Relative folders are relative to the playing file's folder.")
37 }
38 }
39
40 ScrollView {
41 Layout.preferredHeight: Math.min(Math.max(sfListView.contentHeight, 50), 200)
42 Layout.fillWidth: true
43
44 ListView {
45 id: sfListView
46
47 ScrollBar.vertical: ScrollBar { id: scrollBar }
48
49 anchors.fill: parent
50 spacing: Kirigami.Units.smallSpacing
51 clip: true
52 model: SubtitlesFoldersModel {
53 id: subtitlesFoldersModel
54 }
55
56 delegate: ItemDelegate {
57 id: sfDelegate
58
59 required property int index
60 required property string path
61
62 width: ListView.view.width
63
64 contentItem: Loader {
65 id: sfLoader
66 anchors.fill: parent
67 sourceComponent: sfDelegate.path === "" ? sfEditComponent : sfDisplayComponent
68 }
69 Component {
70 id: sfDisplayComponent
71
72 RowLayout {
73
74 Label {
75 id: sfLabel
76 text: sfDelegate.path
77 leftPadding: 10
78 Layout.fillWidth: true
79 }
80
81 Button {
82 icon.name: "edit-entry"
83 flat: true
84 onClicked: {
85 sfLoader.sourceComponent = sfEditComponent
86 }
87 }
88
89 Item { width: scrollBar.width }
90 }
91 } // Component: display
92
93 Component {
94 id: sfEditComponent
95
96 RowLayout {
97
98 TextField {
99 id: editField
100 leftPadding: 10
101 text: sfDelegate.path
102 Layout.leftMargin: 5
103 Layout.fillWidth: true
104 Component.onCompleted: editField.forceActiveFocus(Qt.MouseFocusReason)
105 }
106
107 Button {
108 property bool canDelete: editField.text === ""
109 icon.name: "delete"
110 flat: true
111 onClicked: {
112 if (!canDelete) {
113 text = i18nc("@action:button", "Confirm Deletion")
114 canDelete = true
115 return
116 }
117
118 if (sfDelegate.index === sfListView.count - 1) {
119 root.canAddFolder = true
120 }
121 subtitlesFoldersModel.deleteFolder(sfDelegate.index)
122 }
123 ToolTip {
124 text: i18nc("@info:tooltip", "Delete this folder from list")
125 }
126 }
127
128 Button {
129 icon.name: "dialog-ok"
130 flat: true
131 enabled: editField.text !== "" ? true : false
132 onClicked: {
133 subtitlesFoldersModel.updateFolder(editField.text, sfDelegate.index)
134 sfLoader.sourceComponent = sfDisplayComponent
135 if (sfDelegate.index === sfListView.count - 1) {
136 root.canAddFolder = true
137 }
138 }
139 ToolTip {
140 text: i18nc("@info:tooltip", "Save changes")
141 }
142 }
143
144 Item { width: scrollBar.width }
145 }
146 } // Component: edit
147 } // ItemDelegate
148
149 Label {
150 text: i18n("No folder set")
151 anchors.verticalCenter: parent.verticalCenter
152 visible: sfListView.count === 0
153 opacity: 0.7
154 }
155 }
156 }
157
158 Item {
159 id: spacer
160
161 Layout.preferredHeight: 5
162 }
163
164 Button {
165 id: sfAddFolder
166
167 icon.name: "list-add"
168 text: i18nc("@action:button", "Add New Folder")
169 enabled: root.canAddFolder
170 onClicked: {
171 subtitlesFoldersModel.addFolder()
172 root.canAddFolder = false
173 }
174
175 ToolTip.text: i18nc("@info:tooltip add new subtitle folder setting",
176 "Add a folder in which to look for subtitles.")
177 ToolTip.visible: hovered
178 ToolTip.delay: 700
179 }
180
181 RowLayout {
182 CheckBox {
183 id: recursiveSubtitlesSearch
184
185 text: i18nc("@label:check", "Search subtitles recursively")
186 checked: SubtitlesSettings.recursiveSubtitlesSearch
187
188 onClicked: {
189 SubtitlesSettings.recursiveSubtitlesSearch = checked
190 SubtitlesSettings.save()
191 }
192 }
193
194 ToolButton {
195 icon.name: "documentinfo"
196 checkable: true
197 checked: false
198 Layout.preferredHeight: Kirigami.Units.iconSizes.medium
199
200 ToolTip {
201 text: i18nc("@info:tooltip",
202 "Subtitles are searched recursively in the folders defined by the “%1” setting.\n" +
203 "Only relative folders are searched.", sectionTitle.text)
204 visible: (parent as ToolButton).checked
205 delay: 0
206 timeout: -1
207 closePolicy: Popup.NoAutoClose
208 }
209 }
210 }
211 Item { Layout.preferredWidth: 1; Layout.preferredHeight: 10 }
212 }