qt: move the main interface to its own folder
[vlc.git] / modules / gui / qt / maininterface / qml / MainInterface.qml
bloba45053566d8eac7046b60a9b5147d768d0a5c648
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  *****************************************************************************/
19 import QtQuick 2.11
20 import QtQuick.Layouts 1.3
21 import QtQuick.Controls 2.4
22 import org.videolan.vlc 0.1
24 import "qrc:///utils/" as Utils
25 import "qrc:///style/"
27 import "qrc:///player/" as Player
28 import "qrc:///about/" as AB
29 import "qrc:///dialogs/" as DG
30 import "qrc:///playlist/" as PL
31 import QtQuick.Window 2.11
33 Rectangle {
34     id: root
35     color: "transparent"
37     Loader {
38         id: playlistWindowLoader
39         active: !rootWindow.playlistDocked && rootWindow.playlistVisible
40         sourceComponent: Window {
41             visible: true
42             title: qsTr("Playlist")
43             color: VLCStyle.colors.bg
44             onClosing: rootWindow.playlistVisible = false
45             PL.PlaylistListView {
46                 id: playlistView
47                 focus: true
48                 anchors.fill: parent
49             }
50         }
51     }
53     PlaylistControllerModel {
54         id: mainPlaylistController
55         playlistPtr: mainctx.playlist
56     }
58     Component {
59         id: audioplayerComp
60         Player.Player {
61             focus: true
62         }
63     }
65     Component {
66         id: aboutComp
67         AB.About {
68             focus: true
69             onActionCancel: {
70                 console.log("onActionCancel")
71                 history.previous(History.Go)
72             }
73         }
74     }
76     readonly property var pageModel: [
77         { name: "about", component: aboutComp },
78         { name: "mc", url: "qrc:///medialibrary/MainDisplay.qml" },
79         { name: "playlist", url: "qrc:///playlist/PlaylistMainView.qml" },
80         { name: "player", component: audioplayerComp },
81     ]
83     function loadCurrentHistoryView() {
84         var current = history.current
85         if ( !current || !current.view ) {
86             console.warn("unable to load requested view, undefined")
87             return
88         }
89         stackView.loadView(root.pageModel, current.view, current.viewProperties)
90     }
92     Connections {
93         target: history
94         onCurrentChanged: loadCurrentHistoryView()
95     }
97     Component.onCompleted: {
98         //set the initial view
99         if (medialib)
100             history.push(["mc", "video"], History.Go)
101         else
102             history.push(["playlist"], History.Go)
103     }
106     DropArea {
107         anchors.fill: parent
108         onEntered: console.log("drop Enter")
109         onExited: console.log("drop exit")
110         onDropped: {
111             if (drop.hasUrls) {
112                 var list = []
113                 for (var i = 0; i < drop.urls.length; i++){
114                     list.push(drop.urls[i])
115                 }
116                 mainPlaylistController.append(list, true)
117                 drop.accept()
118             }
119         }
121         Utils.StackViewExt {
122             id: stackView
123             anchors.fill: parent
124             focus: true
126             Connections {
127                 target: player
128                 onPlayingStateChanged: {
129                     if (player.playingState === PlayerController.PLAYING_STATE_STOPPED
130                             && history.current.view === "player") {
131                         history.previous(History.Go)
132                     }
133                 }
134             }
136             Connections {
137                 target: player.videoTracks
138                 onDataChanged: {
139                     if (player.videoTracks.rowCount() > 0
140                             && player.playingState === PlayerController.PLAYING_STATE_PLAYING
141                             && history.current.view !== "player") {
142                         history.push(["player"], History.Go)
143                     }
144                 }
145             }
146         }
147     }
149     DG.Dialogs {
150         anchors.fill: parent
151         bgContent: root
152         onRestoreFocus: {
153             stackView.focus = true
154         }
155     }