delete call dbus launch
[apps/launcher.git] / launcher / qml / Launcher.qml
1 /*
2  * Copyright (C) 2016 The Qt Company Ltd.
3  * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
4  * Copyright (c) 2018,2019 TOYOTA MOTOR CORPORATION
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 import QtQuick 2.6
19 import QtQuick.Layouts 1.1
20 import QtQuick.Controls 2.0
21 import AppModel 1.0
22
23 ApplicationWindow {
24     width: container.width * container.scale
25     height: container.height * container.scale
26
27     property int pid: -1
28
29     Item {
30         id: container
31         anchors.centerIn: parent
32         width: 1080
33         height: 1920
34 //        scale: screenInfo.scale_factor()
35
36         Image {
37             id: topshortcutArea
38             x: 197
39             y: 0
40             width: 588
41             height: 215
42             source: './images/top_three_shortcut_background.png'
43             TopShortcutArea {
44                 anchors.fill: parent
45             }
46         }
47
48         Image {
49             id: meterDisplay
50             x: 0
51             y: 1704
52             width: 270
53             height: 215
54             source: './images/meterdisplay.png'
55         }
56         Image {
57             id: hud
58             anchors.left: meterDisplay.right
59             anchors.top: meterDisplay.top
60             width: 270
61             height: 215
62             source: './images/hud.png'
63         }
64         Image {
65             id: rse
66             anchors.left: hud.right
67             anchors.top: hud.top
68             width: 270
69             height: 215
70             source: './images/rse.png'
71         }
72         Image {
73             id: uninstall
74             anchors.left: rse.right
75             anchors.top: rse.top
76             width: 270
77             height: 215
78             source: './images/uninstall.png'
79         }
80
81         Image {
82           anchors.fill: parent
83           source: './images/background.png'
84         }
85
86         GridView {
87             id: grid
88             anchors {
89               topMargin: 60 + 218; bottomMargin: 0
90               leftMargin: 60; rightMargin: 60
91               fill: parent
92             }
93             contentHeight: 320
94             flickableDirection: Flickable.AutoFlickDirection
95             snapMode: GridView.SnapOneRow
96             visible: true
97             cellWidth: 320
98             cellHeight: 320
99             interactive: false
100
101             model: ApplicationModel { id: applicationModel }
102             delegate: IconItem {
103                 width: grid.cellWidth
104                 height: grid.cellHeight
105             }
106
107             Connections {
108                 target: homescreenHandler
109                 onAppListUpdate: {
110                     console.warn("applist update in Launcher.qml")
111                     applicationModel.updateApplist(info);
112                 }
113             }
114             Connections {
115                 target: homescreenHandler
116                 onInitAppList: {
117                     console.warn("applist init in Launcher.qml")
118                     applicationModel.initAppList(data);
119                 }
120             }
121
122             MouseArea {
123                 id: loc
124                 anchors.fill: parent
125                 property string currentId: ''
126                 property string currentName: ''
127                 property int oldIndex: -1
128                 property int newIndex: -1
129                 property int index: grid.indexAt(loc.mouseX, loc.mouseY)
130                 x: 62
131                 y: 264
132
133                 onPressAndHold: {
134                     oldIndex = index
135                     currentId = applicationModel.id(newIndex = index)
136                     currentName = applicationModel.name(loc.index)
137                     homescreenHandler.hideWindow("homescreen")
138                 }
139                 onReleased: {
140                     if (currentId === '' && loc.index >= 0 ) {
141                         // Not long press, exec application and tapshortcut
142 //                        pid = launcher.launch(applicationModel.id(loc.index))
143 //                        if (1 < pid) {
144                             homescreenHandler.tapShortcut(applicationModel.appid(loc.index))
145
146 //                        }
147 //                        else {
148 //                            console.warn("app cannot be launched!")
149 //                        }
150                     } else if (loc.mouseY <= 0) {
151                         if (loc.mouseX >= 197 && loc.mouseX < 393) {
152 //                            shortcutAppModel.changeShortcut(currentId, currentName, "0");
153                             homescreenHandler.registerShortcut(currentId, currentName, "0");
154                         } else if (loc.mouseX >= 393 && loc.mouseX < 589) {
155 //                            shortcutAppModel.changeShortcut(currentId, currentName, "1");
156                             homescreenHandler.registerShortcut(currentId, currentName, "1");
157                         } else if (loc.mouseX >= 589 && loc.mouseX < 785) {
158 //                            shortcutAppModel.changeShortcut(currentId, currentName, "2");
159                             homescreenHandler.registerShortcut(currentId, currentName, "2");
160                         }
161                         if (oldIndex != newIndex){
162                             applicationModel.move(newIndex, newIndex = oldIndex)
163                         }
164                     } else if (loc.mouseY >= 1488) {
165                         if (loc.mouseX < 270 ) {
166                             console.log("sendAppToMeter", currentId)
167                             homescreenHandler.sendAppToMeter(currentId)
168                         } else if (loc.mouseX >= 270 && loc.mouseX < 540 ) {
169
170                         } else if (loc.mouseX >= 540 && loc.mouseX < 810 ) {
171
172                         } else if (loc.mouseX >= 810) {
173                             uninstallDialog.contents = 'Do you want to uninstall ' + currentName.toUpperCase() + '?'
174                             uninstallDialog.uninstallApp = currentId
175                             uninstallDialog.visible = true
176                         }
177                     }
178
179                     currentName = ''
180                     currentId = ''
181                     homescreenHandler.tapShortcut("homescreen")
182                 }
183                 onPositionChanged: {
184                     if (loc.currentId === '') return
185                     if (index < 0) return
186                     if (index === newIndex) return
187                         applicationModel.move(newIndex, newIndex = index)
188                 }
189             }
190         }
191         UninstallDialog {
192             id: uninstallDialog
193             anchors.fill: parent
194             visible: false
195         }
196     }
197 }