summaryrefslogtreecommitdiff
path: root/src/hmi/qml/NavigationSearchAddress.qml
blob: 475007e46309343b67deb9449b82f7a84d166cc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/**
* @licence app begin@
* SPDX-License-Identifier: MPL-2.0
*
* \copyright Copyright (C) 2013-2014, PCA Peugeot Citroen
*
* \file NavigationSearchAddress.qml
*
* \brief This file is part of the navigation hmi.
*
* \author Martin Schaller <martin.schaller@it-schaller.de>
* \author Philippe Colliot <philippe.colliot@mpsa.com>
*
* \version 1.1
*
* This Source Code Form is subject to the terms of the
* Mozilla Public License (MPL), v. 2.0.
* If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* For further information see http://www.genivi.org/.
*
* List of changes:
* 2014-03-05, Philippe Colliot, migration to the new HMI design
* <date>, <name>, <description of change>
*
* @licence end@
*/
import QtQuick 2.1 
import "Core"
import "Core/genivi.js" as Genivi;
import "Core/style-sheets/style-constants.js" as Constants;
import "Core/style-sheets/navigation-search-address-menu-css.js" as StyleSheet;
import lbs.plugin.dbusif 1.0

HMIMenu {
	id: menu
	property string pagefile:"NavigationSearchAddress"
	property Item currentSelectionCriterionSignal;
	property Item searchStatusSignal;
	property Item searchResultListSignal;
	property Item contentUpdatedSignal;
	property real lat
	property real lon

    function loadWithCountry()
    {
        //load the field with saved values
        if (Genivi.address[Genivi.NAVIGATIONCORE_COUNTRY] !== "")
        {//need to test empty string
            countryValue.text=Genivi.address[Genivi.NAVIGATIONCORE_COUNTRY];
            accept(countryValue);
            cityValue.disabled=false;
        }
        else
            Genivi.preloadMode=false;
    }

	function currentSelectionCriterion(args)
    {// locationInputHandle 1, selectionCriterion 3
        Genivi.hookSignal("currentSelectionCriterion");
        var selectionCriterion=args[3];
        Genivi.entrycriterion = selectionCriterion;
	}

	function searchStatus(args)
    { //locationInputHandle 1, statusValue 3
        Genivi.hookSignal("searchStatus");
        var statusValue=args[3];
        if (statusValue === Genivi.NAVIGATIONCORE_FINISHED)
        {
            Genivi.locationinput_SelectEntry(dbusIf,Genivi.entryselectedentry);
            if (Genivi.preloadMode === true)
            {
                if (Genivi.entrycriterion === countryValue.criterion)
                {
                    if (Genivi.address[Genivi.NAVIGATIONCORE_CITY] !== "")
                    {
                        cityValue.text=Genivi.address[Genivi.NAVIGATIONCORE_CITY];
                        accept(cityValue);
                        streetValue.disabled=false;
                    }
                    else
                        Genivi.preloadMode=false;
                }
                else
                {
                    if (Genivi.entrycriterion === cityValue.criterion)
                    {
                        if (Genivi.address[Genivi.NAVIGATIONCORE_STREET] !== "")
                        {
                            streetValue.text=Genivi.address[Genivi.NAVIGATIONCORE_STREET];
                            accept(streetValue);
                            numberValue.disabled=false;
                        }

                    }
                    else
                    {
                        if (Genivi.entrycriterion === streetValue.criterion)
                        {
                           Genivi.preloadMode=false;
                        }
                        else
                        {
                            Genivi.preloadMode=false;
                            console.log("Error when load a preloaded address");
                        }
                    }
                }
            }
        }
    }

	function searchResultList(args)
	{
        Genivi.hookSignal("searchResultList");
    }

	function contentUpdated(args)
    { //locationInputHandle 1, guidable 3, availableSelectionCriteria 5, address 7
        Genivi.hookSignal("contentUpdated");
        // Check if the destination is guidable
        var guidable=args[3];
        if (guidable) {
            ok.disabled=false;
        }
        else
        {
            //to do something is it's not guidable
        }

        // Manage the available entries
        var availableSelectionCriteria=args[5];
        countryValue.disabled=true;
        cityValue.disabled=true;
        streetValue.disabled=true;
        numberValue.disabled=true;
        for (var i=0 ; i < args.length ; i++) {
            if (availableSelectionCriteria[i] == Genivi.NAVIGATIONCORE_COUNTRY) countryValue.disabled=false;
            if (availableSelectionCriteria[i] == Genivi.NAVIGATIONCORE_CITY) cityValue.disabled=false;
            if (availableSelectionCriteria[i] == Genivi.NAVIGATIONCORE_STREET) streetValue.disabled=false;
            if (availableSelectionCriteria[i] == Genivi.NAVIGATIONCORE_HOUSENUMBER) numberValue.disabled=false;
        }
        if (countryValue.disabled)
            countryValue.text="";
        if (cityValue.disabled)
            cityValue.text="";
        if (streetValue.disabled)
            streetValue.text="";
        if (numberValue.disabled)
            numberValue.text="";

        // Manage the content
        var address=args[7];
        countryValue.text="";
        cityValue.text="";
        streetValue.text="";
        numberValue.text="";
        for (var i=0 ; i < address.length ; i+=4) {
            if (address[i+1] == Genivi.NAVIGATIONCORE_LATITUDE) lat=address[i+3][3][1];
            if (address[i+1] == Genivi.NAVIGATIONCORE_LONGITUDE) lon=address[i+3][3][1];
            if (address[i+1] == Genivi.NAVIGATIONCORE_COUNTRY) countryValue.text=address[i+3][3][1];
            if (address[i+1] == Genivi.NAVIGATIONCORE_CITY) cityValue.text=address[i+3][3][1];
            if (address[i+1] == Genivi.NAVIGATIONCORE_STREET) streetValue.text=address[i+3][3][1];
            if (address[i+1] == Genivi.NAVIGATIONCORE_HOUSENUMBER) numberValue.text=address[i+3][3][1];
        }

        // Manage the focus
        var focus;
        if (!countryValue.disabled)
            focus=countryValue;
        if (!cityValue.disabled)
            focus=cityValue;
        if (!streetValue.disabled)
            focus=streetValue;
        if (!numberValue.disabled)
            focus=numberValue;
        focus.takeFocus();
    }

	function connectSignals()
	{
        currentSelectionCriterionSignal=Genivi.connect_currentSelectionCriterionSignal(dbusIf,menu);
        searchStatusSignal=Genivi.connect_searchStatusSignal(dbusIf,menu);
        searchResultListSignal=Genivi.connect_searchResultListSignal(dbusIf,menu);
        contentUpdatedSignal=Genivi.connect_contentUpdatedSignal(dbusIf,menu);
	}
	
	function disconnectSignals()
	{
		currentSelectionCriterionSignal.destroy();
		searchStatusSignal.destroy();
		searchResultListSignal.destroy();
		contentUpdatedSignal.destroy();
	}

	function accept(what)
	{
		ok.disabled=true;
        Genivi.locationinput_SetSelectionCriterion(dbusIf,what.criterion);
        Genivi.locationinput_Search(dbusIf,what.text,10);
    }


	function leave(toOtherMenu)
	{
		disconnectSignals();
		if (toOtherMenu) {
			Genivi.locationinput_handle_clear(dbusIf);
		}
		//Genivi.navigationcore_session_clear(dbusIf);
	}

	DBusIf {
        id: dbusIf
    }

    HMIBgImage {
        image:StyleSheet.navigation_search_by_address_menu_background[Constants.SOURCE];
        anchors { fill: parent; topMargin: parent.headlineHeight}
        id: content

        Text {
            x:StyleSheet.countryTitle[Constants.X]; y:StyleSheet.countryTitle[Constants.Y]; width:StyleSheet.countryTitle[Constants.WIDTH]; height:StyleSheet.countryTitle[Constants.HEIGHT];color:StyleSheet.countryTitle[Constants.TEXTCOLOR];styleColor:StyleSheet.countryTitle[Constants.STYLECOLOR]; font.pixelSize:StyleSheet.countryTitle[Constants.PIXELSIZE];
            style: Text.Sunken;
            smooth: true;
            id: countryTitle
            text: Genivi.gettext("Country");
        }
        EntryField {
            x:StyleSheet.countryValue[Constants.X]; y:StyleSheet.countryValue[Constants.Y]; width: StyleSheet.countryValue[Constants.WIDTH]; height: StyleSheet.countryValue[Constants.HEIGHT];
            id: countryValue
			criterion: Genivi.NAVIGATIONCORE_COUNTRY
            globaldata: 'countryValue'
			textfocus: true
            next: cityValue
			prev: back
			onLeave:{menu.leave(0)}
		}
        Text {
            x:StyleSheet.streetTitle[Constants.X]; y:StyleSheet.streetTitle[Constants.Y]; width:StyleSheet.streetTitle[Constants.WIDTH]; height:StyleSheet.streetTitle[Constants.HEIGHT];color:StyleSheet.streetTitle[Constants.TEXTCOLOR];styleColor:StyleSheet.streetTitle[Constants.STYLECOLOR]; font.pixelSize:StyleSheet.streetTitle[Constants.PIXELSIZE];
            style: Text.Sunken;
            smooth: true;
            id:streetTitle
            text: Genivi.gettext("Street");
        }
		EntryField {
            x:StyleSheet.streetValue[Constants.X]; y:StyleSheet.streetValue[Constants.Y]; width: StyleSheet.streetValue[Constants.WIDTH]; height: StyleSheet.streetValue[Constants.HEIGHT];
            id:streetValue
			criterion: Genivi.NAVIGATIONCORE_STREET
            globaldata: 'streetValue'
            next: numberValue
            prev: cityValue
			disabled: true
			onLeave:{menu.leave(0)}
		}
        Text {
            x:StyleSheet.cityTitle[Constants.X]; y:StyleSheet.cityTitle[Constants.Y]; width:StyleSheet.cityTitle[Constants.WIDTH]; height:StyleSheet.cityTitle[Constants.HEIGHT];color:StyleSheet.cityTitle[Constants.TEXTCOLOR];styleColor:StyleSheet.cityTitle[Constants.STYLECOLOR]; font.pixelSize:StyleSheet.cityTitle[Constants.PIXELSIZE];
            style: Text.Sunken;
            smooth: true;
            id:cityTitle
            text: Genivi.gettext("City");
        }
        EntryField {
            x:StyleSheet.cityValue[Constants.X]; y:StyleSheet.cityValue[Constants.Y]; width: StyleSheet.cityValue[Constants.WIDTH]; height: StyleSheet.cityValue[Constants.HEIGHT];
            id:cityValue
			criterion: Genivi.NAVIGATIONCORE_CITY
            globaldata: 'cityValue'
            next:streetValue
            prev:countryValue
			disabled: true
			onLeave:{menu.leave(0)}
		}
        Text {
            x:StyleSheet.numberTitle[Constants.X]; y:StyleSheet.numberTitle[Constants.Y]; width:StyleSheet.numberTitle[Constants.WIDTH]; height:StyleSheet.numberTitle[Constants.HEIGHT];color:StyleSheet.numberTitle[Constants.TEXTCOLOR];styleColor:StyleSheet.numberTitle[Constants.STYLECOLOR]; font.pixelSize:StyleSheet.numberTitle[Constants.PIXELSIZE];
            style: Text.Sunken;
            smooth: true;
            id:numberTitle
            text: Genivi.gettext("Number");
        }
        EntryField {
            x:StyleSheet.numberValue[Constants.X]; y:StyleSheet.numberValue[Constants.Y]; width: StyleSheet.numberValue[Constants.WIDTH]; height: StyleSheet.numberValue[Constants.HEIGHT];
            id:numberValue
			criterion: Genivi.NAVIGATIONCORE_HOUSENUMBER
            globaldata: 'numberValue'
			next: ok
            prev: streetValue
			disabled: true
			onLeave:{menu.leave(0)}
		}

        StdButton { source:StyleSheet.ok[Constants.SOURCE]; x:StyleSheet.ok[Constants.X]; y:StyleSheet.ok[Constants.Y]; width:StyleSheet.ok[Constants.WIDTH]; height:StyleSheet.ok[Constants.HEIGHT];textColor:StyleSheet.okText[Constants.TEXTCOLOR]; pixelSize:StyleSheet.okText[Constants.PIXELSIZE];
            id:ok
            next:back
            prev:numberValue
            text:Genivi.gettext("Ok")
            disabled: true
            onClicked:{
                leave(1);
                //save address for next time
                Genivi.address[Genivi.NAVIGATIONCORE_COUNTRY]=countryValue.text;
                Genivi.address[Genivi.NAVIGATIONCORE_CITY]=cityValue.text;
                Genivi.address[Genivi.NAVIGATIONCORE_STREET]=streetValue.text;
                Genivi.address[Genivi.NAVIGATIONCORE_HOUSENUMBER]=numberValue.text;
                Genivi.data['lat']=menu.lat;
                Genivi.data['lon']=menu.lon;
                Genivi.data['description']=countryValue.text;
                if (!cityValue.disabled)
                    Genivi.data['description']+=' '+cityValue.text;
                if (!streetValue.disabled)
                    Genivi.data['description']+=' '+streetValue.text;
                if (!numberValue.disabled)
                    Genivi.data['description']+=' '+numberValue.text;
                //save entered location into the history
                Genivi.updateHistoryOfLastEnteredLocation(Genivi.data['description'],Genivi.data['lat'],Genivi.data['lon']);
                routeMenu();
            }
        }

        StdButton { source:StyleSheet.back[Constants.SOURCE]; x:StyleSheet.back[Constants.X]; y:StyleSheet.back[Constants.Y]; width:StyleSheet.back[Constants.WIDTH]; height:StyleSheet.back[Constants.HEIGHT];textColor:StyleSheet.backText[Constants.TEXTCOLOR]; pixelSize:StyleSheet.backText[Constants.PIXELSIZE];
            id:back; text: Genivi.gettext("Back");  next:countryValue; prev:ok;
            onClicked:{leave(1); leaveMenu();}
        }
	}
    Component.onCompleted: {
        connectSignals();

        var res=Genivi.navigationcore_session_GetVersion(dbusIf);
        if (res[0] != "error") {
            res=Genivi.navigationcore_session(dbusIf);
            res=Genivi.locationinput_handle(dbusIf);
        } else {
            Genivi.dump("",res);
        }
        if (Genivi.entryselectedentry) {
            Genivi.locationinput_SelectEntry(dbusIf,Genivi.entryselectedentry-1);
        }
        if (Genivi.entrydest == 'countryValue')
        {
            accept(countryValue);
        }
        if (Genivi.entrydest == 'cityValue')
        {
            accept(cityValue);
        }
        if (Genivi.entrydest == 'streetValue')
        {
            accept(streetValue);
        }
        if (Genivi.entrydest == 'numberValue')
        {
            accept(numberValue);
        }
        Genivi.entrydest=null;

        if (Genivi.preloadMode==true)
        {
            loadWithCountry();
        }
    }
}