qml: use history calls without the Go parameter as this is the default now
[vlc.git] / modules / gui / qt / medialibrary / qml / MainDisplay.qml
blob07c8ba5681bc87b7e3d1d64aa44ced66d1334519
1 /*****************************************************************************
2  * Copyright (C) 2019 VLC authors and VideoLAN
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * ( at your option ) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
17  *****************************************************************************/
18 import QtQuick 2.11
19 import QtQuick.Controls 2.4
20 import QtQuick.Layouts 1.3
21 import org.videolan.medialib 0.1
22 import org.videolan.vlc 0.1
24 import "qrc:///style/"
25 import "qrc:///main/" as Main
26 import "qrc:///widgets/" as Widgets
27 import "qrc:///util/KeyHelper.js" as KeyHelper
28 import "qrc:///playlist/" as PL
29 import "qrc:///player/" as Player
30 import "qrc:///network/" as Network
32 Widgets.NavigableFocusScope {
33     id: root
35     //name and properties of the tab to be initially loaded
36     property string view: ""
37     property var viewProperties: ({})
39     onViewChanged: loadView()
40     onViewPropertiesChanged: loadView()
41     Component.onCompleted: {
42         loadView()
43         medialib.reload()
44     }
46     function loadView() {
47         var found = stackView.loadView(root.pageModel, root.view, root.viewProperties)
49         sourcesBanner.subTabModel = stackView.currentItem.tabModel
50         sourcesBanner.sortModel = stackView.currentItem.sortModel
51         sourcesBanner.contentModel = stackView.currentItem.contentModel
52         sourcesBanner.extraLocalActions = stackView.currentItem.extraLocalActions
53         // Restore sourcesBanner state
54         sourcesBanner.selectedIndex = pageModel.findIndex(function (e) {
55             return e.name === root.view
56         })
57         if (stackView.currentItem.pageModel !== undefined)
58             sourcesBanner.subSelectedIndex = stackView.currentItem.pageModel.findIndex(function (e) {
59                 return e.name === stackView.currentItem.view
60             })
61     }
63     navigationCancel: function() {
64         history.previous()
65     }
67     Keys.onPressed: {
68         if (KeyHelper.matchSearch(event)) {
69             sourcesBanner.search()
70             event.accepted = true
71         }
72         //unhandled keys are forwarded as hotkeys
73         if (!event.accepted)
74             rootWindow.sendHotkey(event.key, event.modifiers);
75     }
77     Component {
78         id: musicComp
79         MusicDisplay {
80             navigationParent: medialibId
81             navigationUpItem: sourcesBanner
82             navigationRightItem: playlist
83             navigationDownItem: miniPlayer.expanded ? miniPlayer : medialibId
84         }
85     }
87     Component {
88         id: videoComp
89         VideoDisplay {
90             navigationParent: medialibId
91             navigationUpItem: sourcesBanner
92             navigationRightItem: playlist
93             navigationDownItem: miniPlayer.expanded ? miniPlayer : medialibId
94         }
95     }
97     Component {
98         id: networkComp
99         Network.NetworkDisplay {
100             navigationParent: medialibId
101             navigationUpItem: sourcesBanner
102             navigationRightItem: playlist
103             navigationDownItem: miniPlayer.expanded ? miniPlayer : medialibId
104         }
105     }
107     readonly property var pageModel: [
108         {
109             displayText: i18n.qtr("Video"),
110             icon: VLCIcons.topbar_video,
111             name: "video",
112             component: videoComp
113         }, {
114             displayText: i18n.qtr("Music"),
115             icon: VLCIcons.topbar_music,
116             name: "music",
117             component: musicComp
118         }, {
119             displayText: i18n.qtr("Network"),
120             icon: VLCIcons.topbar_network,
121             name: "network",
122             component: networkComp
123         }
124     ]
126     property var tabModel: ListModel {
127         id: tabModelid
128         Component.onCompleted: {
129             pageModel.forEach(function(e) {
130                 append({
131                            displayText: e.displayText,
132                            icon: e.icon,
133                            name: e.name,
134                        })
135             })
136         }
137     }
139     Rectangle {
140         color: VLCStyle.colors.bg
141         anchors.fill: parent
143         Widgets.NavigableFocusScope {
144             focus: true
145             id: medialibId
146             anchors.fill: parent
148             navigationParent: root
150             ColumnLayout {
151                 id: column
152                 anchors.fill: parent
154                 Layout.minimumWidth: VLCStyle.minWindowWidth
155                 spacing: 0
157                 /* Source selection*/
158                 Main.BannerSources {
159                     id: sourcesBanner
161                     Layout.preferredHeight: height
162                     Layout.minimumHeight: height
163                     Layout.maximumHeight: height
164                     Layout.fillWidth: true
166                     focus: true
167                     model: root.tabModel
169                     onItemClicked: {
170                         sourcesBanner.subTabModel = undefined
171                         var name = root.tabModel.get(index).name
172                         selectedIndex = index
173                         history.push(["mc", name])
174                     }
176                     onSubItemClicked: {
177                         subSelectedIndex = index
178                         stackView.currentItem.loadIndex(index)
179                         sortModel = stackView.currentItem.sortModel
180                         contentModel = stackView.currentItem.contentModel
181                         extraLocalActions = stackView.currentItem.extraLocalActions
182                     }
184                     navigationParent: medialibId
185                     navigationDownItem: stackView
186                 }
188                 Item {
189                     Layout.fillWidth: true
190                     Layout.fillHeight: true
192                     Widgets.StackViewExt {
193                         id: stackView
194                         anchors {
195                             top: parent.top
196                             left: parent.left
197                             bottom: parent.bottom
198                             right: playlist.visible ? playlist.left : parent.right
199                             rightMargin: (rootWindow.playlistDocked && rootWindow.playlistVisible)
200                                          ? 0
201                                          : VLCStyle.applicationHorizontalMargin
202                             leftMargin: VLCStyle.applicationHorizontalMargin
203                         }
205                         Widgets.ScanProgressBar {
206                             z: 1
207                             anchors {
208                                 left: parent.left
209                                 right: parent.right
210                                 bottom: parent.bottom
211                                 rightMargin: VLCStyle.margin_small
212                                 leftMargin: VLCStyle.margin_small
213                             }
214                         }
215                     }
218                     PL.PlaylistListView {
219                         id: playlist
220                         focus: true
221                         width: root.width/4
222                         visible: rootWindow.playlistDocked && rootWindow.playlistVisible
223                         anchors {
224                             top: parent.top
225                             right: parent.right
226                             bottom: parent.bottom
227                         }
229                         rightPadding: VLCStyle.applicationHorizontalMargin
231                         navigationParent: medialibId
232                         navigationLeftItem: stackView
233                         navigationUpItem: sourcesBanner
234                         navigationDownItem: miniPlayer.expanded ? miniPlayer : undefined
236                         Rectangle {
237                             anchors {
238                                 top: parent.top
239                                 left: parent.left
240                                 bottom: parent.bottom
241                             }
242                             width: VLCStyle.margin_xxsmall
243                             color: VLCStyle.colors.banner
244                         }
245                     }
246                 }
248                 Player.MiniPlayer {
249                     id: miniPlayer
251                     navigationParent: medialibId
252                     navigationUpItem: stackView
253                     navigationCancelItem:sourcesBanner
254                     onExpandedChanged: {
255                         if (!expanded && miniPlayer.activeFocus)
256                             stackView.forceActiveFocus()
257                     }
258                 }
259             }
260         }
262     }