| 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.Window |
| 11 |
import QtQuick.Controls |
| 12 |
|
| 13 |
import org.kde.kirigami as Kirigami |
| 14 |
import org.kde.coreaddons as KCoreAddons |
| 15 |
import org.kde.haruna |
| 16 |
|
| 17 |
Loader { |
| 18 |
id: root |
| 19 |
|
| 20 |
required property MpvVideo m_mpv |
| 21 |
required property ProxyActionsModel m_proxyActionsModel |
| 22 |
required property CustomCommandsModel m_customCommandsModel |
| 23 |
required property MouseActionsModel m_mouseActionsModel |
| 24 |
|
| 25 |
property int activePage: SettingsWindow.Page.General |
| 26 |
|
| 27 |
enum Page { |
| 28 |
General = 0, |
| 29 |
Playback, |
| 30 |
Video, |
| 31 |
Audio, |
| 32 |
Subtitles, |
| 33 |
Playlist, |
| 34 |
Mouse, |
| 35 |
Shortcuts, |
| 36 |
CustomCommands, |
| 37 |
Debug, |
| 38 |
About |
| 39 |
} |
| 40 |
|
| 41 |
function openSettingPage(page: int) : void { |
| 42 |
if (!root.active) { |
| 43 |
root.active = true |
| 44 |
root.loaded.connect(function() { |
| 45 |
root.openSettingPage(page) |
| 46 |
}) |
| 47 |
return |
| 48 |
} |
| 49 |
|
| 50 |
const settingsWindow = root.item as Kirigami.ApplicationWindow |
| 51 |
root.activePage = page |
| 52 |
if (settingsWindow.visible) { |
| 53 |
settingsWindow.raise() |
| 54 |
} else { |
| 55 |
settingsWindow.visible = true |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
active: false |
| 60 |
asynchronous: true |
| 61 |
sourceComponent: Kirigami.ApplicationWindow { |
| 62 |
id: settingsWindow |
| 63 |
|
| 64 |
property string settingsPath: "qrc:/qt/qml/org/kde/haruna/qml/Settings" |
| 65 |
|
| 66 |
width: 800 |
| 67 |
height: 600 |
| 68 |
minimumWidth: 750 |
| 69 |
minimumHeight: 400 |
| 70 |
title: i18nc("@title:window", "Settings") |
| 71 |
transientParent: null |
| 72 |
pageStack.initialPage: Kirigami.ScrollablePage { |
| 73 |
globalToolBarStyle: Kirigami.ApplicationHeaderStyle.None |
| 74 |
bottomPadding: 0 |
| 75 |
leftPadding: 0 |
| 76 |
rightPadding: 0 |
| 77 |
topPadding: 0 |
| 78 |
Kirigami.Theme.colorSet: Kirigami.Theme.View |
| 79 |
|
| 80 |
ListView { |
| 81 |
id: settingsPagesList |
| 82 |
|
| 83 |
currentIndex: root.activePage |
| 84 |
|
| 85 |
property list<Kirigami.Action> pages: [ |
| 86 |
Kirigami.Action { |
| 87 |
text: i18nc("@action", "General") |
| 88 |
icon.name: "configure" |
| 89 |
onTriggered: { |
| 90 |
root.activePage = SettingsWindow.Page.General |
| 91 |
settingsWindow.pageStack.removePage(1) |
| 92 |
settingsWindow.pageStack.push(`${settingsWindow.settingsPath}/GeneralSettings.qml`) |
| 93 |
} |
| 94 |
}, |
| 95 |
Kirigami.Action { |
| 96 |
text: i18nc("@action", "Playback") |
| 97 |
icon.name: "media-playback-start" |
| 98 |
onTriggered: { |
| 99 |
root.activePage = SettingsWindow.Page.Playback |
| 100 |
settingsWindow.pageStack.removePage(1) |
| 101 |
settingsWindow.pageStack.push(`${settingsWindow.settingsPath}/PlaybackSettings.qml`) |
| 102 |
} |
| 103 |
}, |
| 104 |
Kirigami.Action { |
| 105 |
text: i18nc("@action", "Video") |
| 106 |
icon.name: "video-x-generic" |
| 107 |
onTriggered: { |
| 108 |
root.activePage = SettingsWindow.Page.Video |
| 109 |
settingsWindow.pageStack.removePage(1) |
| 110 |
settingsWindow.pageStack.push(`${settingsWindow.settingsPath}/VideoSettings.qml`, |
| 111 |
{m_mpv: root.m_mpv}) |
| 112 |
} |
| 113 |
}, |
| 114 |
Kirigami.Action { |
| 115 |
text: i18nc("@action", "Audio") |
| 116 |
icon.name: "player-volume" |
| 117 |
onTriggered: { |
| 118 |
root.activePage = SettingsWindow.Page.Audio |
| 119 |
settingsWindow.pageStack.removePage(1) |
| 120 |
settingsWindow.pageStack.push(`${settingsWindow.settingsPath}/AudioSettings.qml`) |
| 121 |
} |
| 122 |
}, |
| 123 |
Kirigami.Action { |
| 124 |
text: i18nc("@action", "Subtitles") |
| 125 |
icon.name: "add-subtitle" |
| 126 |
onTriggered: { |
| 127 |
root.activePage = SettingsWindow.Page.Subtitles |
| 128 |
settingsWindow.pageStack.removePage(1) |
| 129 |
settingsWindow.pageStack.push(`${settingsWindow.settingsPath}/SubtitlesSettings.qml`) |
| 130 |
} |
| 131 |
}, |
| 132 |
Kirigami.Action { |
| 133 |
text: i18nc("@action", "Playlist") |
| 134 |
icon.name: "view-media-playlist" |
| 135 |
onTriggered: { |
| 136 |
root.activePage = SettingsWindow.Page.Playlist |
| 137 |
settingsWindow.pageStack.removePage(1) |
| 138 |
settingsWindow.pageStack.push(`${settingsWindow.settingsPath}/PlaylistSettings.qml`) |
| 139 |
} |
| 140 |
}, |
| 141 |
Kirigami.Action { |
| 142 |
text: i18nc("@action", "Mouse") |
| 143 |
icon.name: "input-mouse" |
| 144 |
onTriggered: { |
| 145 |
root.activePage = SettingsWindow.Page.Mouse |
| 146 |
settingsWindow.pageStack.removePage(1) |
| 147 |
settingsWindow.pageStack.push(`${settingsWindow.settingsPath}/MouseSettings.qml`, |
| 148 |
{m_mouseActionsModel: root.m_mouseActionsModel}) |
| 149 |
} |
| 150 |
}, |
| 151 |
Kirigami.Action { |
| 152 |
text: i18nc("@action", "Shortcuts") |
| 153 |
icon.name: "configure-shortcuts" |
| 154 |
onTriggered: { |
| 155 |
root.activePage = SettingsWindow.Page.Shortcuts |
| 156 |
settingsWindow.pageStack.removePage(1) |
| 157 |
settingsWindow.pageStack.push(`${settingsWindow.settingsPath}/ShortcutsSettings.qml`, |
| 158 |
{m_proxyActionsModel: root.m_proxyActionsModel}) |
| 159 |
} |
| 160 |
}, |
| 161 |
Kirigami.Action { |
| 162 |
text: i18nc("@action", "Custom Commands") |
| 163 |
icon.name: "configure" |
| 164 |
onTriggered: { |
| 165 |
root.activePage = SettingsWindow.Page.CustomCommands |
| 166 |
settingsWindow.pageStack.removePage(1) |
| 167 |
settingsWindow.pageStack.push(`${settingsWindow.settingsPath}/CustomCommandsSettings.qml`, |
| 168 |
{m_customCommandsModel: root.m_customCommandsModel}) |
| 169 |
} |
| 170 |
}, |
| 171 |
Kirigami.Action { |
| 172 |
text: i18nc("@action", "Debug") |
| 173 |
icon.name: "help-about" |
| 174 |
onTriggered: { |
| 175 |
root.activePage = SettingsWindow.Page.Debug |
| 176 |
settingsWindow.pageStack.removePage(1) |
| 177 |
settingsWindow.pageStack.push(`${settingsWindow.settingsPath}/DebugSettings.qml`, |
| 178 |
{m_mpv: root.m_mpv}) |
| 179 |
} |
| 180 |
}, |
| 181 |
Kirigami.Action { |
| 182 |
text: i18nc("@action", "About") |
| 183 |
icon.name: "help-about" |
| 184 |
onTriggered: { |
| 185 |
root.activePage = SettingsWindow.Page.About |
| 186 |
settingsWindow.pageStack.removePage(1) |
| 187 |
settingsWindow.pageStack.push(aboutPage) |
| 188 |
} |
| 189 |
} |
| 190 |
] |
| 191 |
|
| 192 |
anchors.fill: parent |
| 193 |
model: pages |
| 194 |
delegate: ItemDelegate { |
| 195 |
id: delegate |
| 196 |
|
| 197 |
required property int index |
| 198 |
required property Action modelData |
| 199 |
|
| 200 |
width: settingsPagesList.width |
| 201 |
action: delegate.modelData |
| 202 |
highlighted: delegate.index === ListView.view.currentIndex |
| 203 |
} |
| 204 |
|
| 205 |
onCurrentIndexChanged: { |
| 206 |
settingsPagesList.pages[root.activePage].trigger() |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
Component { |
| 211 |
id: aboutPage |
| 212 |
|
| 213 |
Kirigami.AboutPage { |
| 214 |
aboutData: KCoreAddons.AboutData |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
onClosing: root.active = false |
| 220 |
|
| 221 |
Component.onCompleted: pageStack.columnView.columnWidth = Kirigami.Units.gridUnit * 15 |
| 222 |
|
| 223 |
Shortcut { |
| 224 |
sequence: "Esc" |
| 225 |
enabled: HarunaApp.actionsEnabled |
| 226 |
onActivated: settingsWindow.close() |
| 227 |
} |
| 228 |
} |
| 229 |
} |