1 #include <QNetworkReply>
2 #include <QNetworkRequest>
5 #include <QNetworkProxy>
9 #include <json-c/json.h>
12 #define __STDC_FORMAT_MACROS
17 #include "InfoPanel.h"
18 #include "ClickableLabel.h"
22 #define DEFAULT_TEXT "Select your destination with Yelp !"
23 #define URL_AUTH "https://api.yelp.com/oauth2/token"
24 #define URL_AUTOCOMPLETE "https://api.yelp.com/v3/autocomplete"
25 #define URL_SEARCH "https://api.yelp.com/v3/businesses/search"
27 #define BIG_BUFFER_SIZE (1024*1024)
28 #define LEFT_OFFSET 28
29 #define FONT_SIZE_LINEDIT 20
30 #define FONT_SIZE_LIST 18
31 #define TEXT_INPUT_WIDTH 800
32 #define SEARCH_BTN_SIZE 105
34 #define WIDGET_WIDTH (SEARCH_BTN_SIZE + SPACER + TEXT_INPUT_WIDTH)
35 #define DISPLAY_WIDTH TEXT_INPUT_WIDTH
36 #define DISPLAY_HEIGHT 480
37 #define COMPLETE_W_WITH_KB 1080
38 #define COMPLETE_H_WITH_KB 1488
39 #define RESULT_ITEM_HEIGHT 80
41 #define AGL_REFRESH_DELAY 75 /* milliseconds */
43 #define SCROLLBAR_STYLE \
44 "QScrollBar:vertical {" \
45 " border: 2px solid grey;" \
46 " background: gray;" \
52 MainApp::MainApp():QMainWindow(Q_NULLPTR, Qt::FramelessWindowHint),
53 networkManager(this),searchBtn(QIcon(tr(":/images/loupe-90.png")), tr(""), this),
54 lineEdit(this),keyboard(QRect(0, 688, COMPLETE_W_WITH_KB, 720), this),
55 mutex(QMutex::Recursive),token(""),currentSearchingText(""),currentSearchedText(""),
56 pSearchReply(NULL),pInfoPanel(NULL),pResultList(NULL),currentLatitude(0.0),currentLongitude(0.0),
57 navicoreSession(0),currentIndex(0),fontId(-1),isInfoScreen(false),
58 isInputDisplayed(false),isKeyboard(false),isAglNavi(false)
60 //this->setAttribute(Qt::WA_TranslucentBackground);
61 this->setStyleSheet("border: none;");
63 searchBtn.setStyleSheet("border: none; color: #FFFFFF;");
64 searchBtn.setMinimumSize(QSize(SEARCH_BTN_SIZE, SEARCH_BTN_SIZE));
65 searchBtn.setIconSize(searchBtn.size());
66 searchBtn.setGeometry(QRect(LEFT_OFFSET, 0, searchBtn.width(), searchBtn.height()));
68 lineEdit.setStyleSheet("border: none; color: #FFFFFF;");
69 lineEdit.setMinimumSize(QSize(TEXT_INPUT_WIDTH, SEARCH_BTN_SIZE));
71 lineEdit.setPlaceholderText(QString(DEFAULT_TEXT));
72 font = lineEdit.font();
73 font.setPointSize(FONT_SIZE_LINEDIT);
74 lineEdit.setFont(font);
75 lineEdit.setTextMargins(MARGINS/2, 0, 0, 0);
76 lineEdit.installEventFilter(this);
77 lineEdit.setGeometry(QRect(LEFT_OFFSET + searchBtn.width() + SPACER, 0, lineEdit.width(), lineEdit.height()));
78 lineEdit.setVisible(false);
80 /* We might need a Japanese font: */
81 QFile fontFile(":/fonts/DroidSansJapanese.ttf");
82 if (!fontFile.open(QIODevice::ReadOnly))
84 TRACE_ERROR("failed to open font file");
88 QByteArray fontData = fontFile.readAll();
89 fontId = QFontDatabase::addApplicationFontFromData(fontData);
92 TRACE_ERROR("QFontDatabase::addApplicationFontFromData failed");
96 /* Check if "AGL_NAVI" env variable is set. If yes, we must notify
97 * AGL environment when surface needs to be resized */
98 if (getenv("AGL_NAVI"))
101 connect(this, SIGNAL(positionGotSignal()), this, SLOT(positionGot()));
102 connect(this, SIGNAL(allRoutesGotSignal()), this, SLOT(allRoutesGot()));
103 connect(this, SIGNAL(routeCreatedSignal()), this, SLOT(routeCreated()));
105 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
106 this->setStyleSheet("background-image: url(:/images/AGL_POI_Background.png);");
114 QFontDatabase::removeApplicationFont(fontId);
116 searchBtn.disconnect();
117 lineEdit.disconnect();
118 networkManager.disconnect();
119 keyboard.disconnect();
126 void MainApp::searchBtnClicked()
128 isInputDisplayed = !isInputDisplayed;
129 TRACE_DEBUG("isInputDisplayed = %d", isInputDisplayed);
130 DisplayLineEdit(isInputDisplayed);
133 void MainApp::DisplayLineEdit(bool display)
137 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
141 lineEdit.setVisible(true);
148 pResultList->removeEventFilter(this);
157 lineEdit.setText(tr(""));
158 lineEdit.setVisible(false);
160 isInputDisplayed = display;
165 void MainApp::UpdateAglSurfaces()
169 TRACE_DEBUG("handle AGL demo surfaces (new surface is bigger)");
170 snprintf(cmd, 1023, "/usr/bin/LayerManagerControl set surface $SURFACE_ID_CLIENT source region 0 0 %d %d",
171 this->width(), this->height());
172 TRACE_DEBUG("%s", cmd);
174 snprintf(cmd, 1023, "/usr/bin/LayerManagerControl set surface $SURFACE_ID_CLIENT destination region $CLIENT_X $CLIENT_Y %d %d",
175 this->width(), this->height());
176 TRACE_DEBUG("%s", cmd);
180 void MainApp::DisplayResultList(bool display, bool RefreshDisplay)
188 pResultList = new QTreeWidget(this);
189 pResultList->setStyleSheet("border: none; color: #FFFFFF;");
190 pResultList->setRootIsDecorated(false);
191 pResultList->setEditTriggers(QTreeWidget::NoEditTriggers);
192 pResultList->setSelectionBehavior(QTreeWidget::SelectRows);
193 pResultList->setFrameStyle(QFrame::Box | QFrame::Plain);
194 pResultList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
195 //pResultList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
196 pResultList->setAttribute(Qt::WA_AcceptTouchEvents);
197 pResultList->verticalScrollBar()->setStyleSheet(SCROLLBAR_STYLE);
198 pResultList->header()->hide();
199 //font.setPointSize(FONT_SIZE_LIST);
200 //pResultList->setFont(font);
201 pResultList->installEventFilter(this);
204 pResultList->setGeometry(QRect( LEFT_OFFSET+searchBtn.width()+SPACER, searchBtn.height()+SPACER,
205 DISPLAY_WIDTH, DISPLAY_HEIGHT));
208 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
210 pResultList->setVisible(true);
211 pResultList->setFocus();
217 pResultList->removeEventFilter(this);
218 pResultList->deleteLater();
226 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
233 void MainApp::textChanged(const QString & text)
235 TRACE_INFO("New text is: %s", qPrintable(text));
237 /* do not handle text input if info panel is displayed: */
238 if (pInfoPanel) return;
242 delete pSearchReply; /* cancel current search */
245 if (text.length() == 0) /* if empty text -> no search */
247 DisplayResultList(false);
252 /* if text is the same as previous search -> no need to search again */
253 if (text == currentSearchedText)
255 DisplayResultList(true);
256 FillResultList(Businesses, currentIndex);
260 this->currentSearchingText = text;
262 /* we need to know our current position */
263 std::vector<int32_t> Params;
264 Params.push_back(naviapi::NAVICORE_LONGITUDE);
265 Params.push_back(naviapi::NAVICORE_LATITUDE);
266 naviapi.getPosition(Params);
271 void MainApp::textAdded(const QString & text)
274 lineEdit.setText(lineEdit.text() + text);
276 // be sure any text is visible on initial input
277 lineEdit.setVisible(true);
282 void MainApp::keyPressed(int key)
285 if (key == '\b') /* backspace */
287 int len = lineEdit.text().length();
289 lineEdit.setText(lineEdit.text().remove(len-1, 1));
294 void MainApp::itemClicked()
299 DisplayInformation(true, false);
304 DisplayLineEdit(false);
309 void MainApp::ParseJsonBusinessList(const char* buf, std::vector<Business> & Output)
311 json_object *jobj = json_tokener_parse(buf);
314 TRACE_ERROR("json_tokener_parse failed");
315 cerr << "json_tokener_parse failed: " << buf << endl;
319 json_object_object_foreach(jobj, key, val)
324 if (json_object_get_type(val) == json_type_array)
326 TRACE_DEBUG_JSON("an array was found");
328 if(json_object_object_get_ex(jobj, "businesses", &value))
330 TRACE_DEBUG_JSON("an business was found");
332 int arraylen = json_object_array_length(value);
334 for (int i = 0; i < arraylen; i++)
336 Business NewBusiness;
338 json_object* medi_array_obj, *medi_array_obj_elem;
339 medi_array_obj = json_object_array_get_idx(value, i);
342 if (json_object_object_get_ex(medi_array_obj, "rating", &medi_array_obj_elem))
344 NewBusiness.Rating = json_object_get_double(medi_array_obj_elem);
345 TRACE_DEBUG_JSON("got Rating : %f", NewBusiness.Rating);
348 if (json_object_object_get_ex(medi_array_obj, "distance", &medi_array_obj_elem))
350 NewBusiness.Distance = json_object_get_double(medi_array_obj_elem);
351 TRACE_DEBUG_JSON("got Distance : %f", NewBusiness.Distance);
354 if (json_object_object_get_ex(medi_array_obj, "review_count", &medi_array_obj_elem))
356 NewBusiness.ReviewCount = json_object_get_int(medi_array_obj_elem);
357 TRACE_DEBUG_JSON("got ReviewCount : %u", NewBusiness.ReviewCount);
360 if (json_object_object_get_ex(medi_array_obj, "name", &medi_array_obj_elem))
362 NewBusiness.Name = QString(json_object_get_string(medi_array_obj_elem));
363 TRACE_DEBUG_JSON("got Name : %s", qPrintable(NewBusiness.Name));
366 if (json_object_object_get_ex(medi_array_obj, "image_url", &medi_array_obj_elem))
368 NewBusiness.ImageUrl = QString(json_object_get_string(medi_array_obj_elem));
369 TRACE_DEBUG_JSON("got ImageUrl : %s", qPrintable(NewBusiness.ImageUrl));
372 if (json_object_object_get_ex(medi_array_obj, "phone", &medi_array_obj_elem))
374 NewBusiness.Phone = QString(json_object_get_string(medi_array_obj_elem));
375 TRACE_DEBUG_JSON("got Phone : %s", qPrintable(NewBusiness.Phone));
378 if (json_object_object_get_ex(medi_array_obj, "coordinates", &medi_array_obj_elem))
382 TRACE_DEBUG_JSON("coordinates were found");
384 if(json_object_object_get_ex(medi_array_obj_elem, "latitude", &value2))
386 NewBusiness.Latitude = json_object_get_double(value2);
387 TRACE_DEBUG_JSON("got Latitude : %f", NewBusiness.Latitude);
390 if(json_object_object_get_ex(medi_array_obj_elem, "longitude", &value2))
392 NewBusiness.Longitude = json_object_get_double(value2);
393 TRACE_DEBUG_JSON("got Longitude : %f", NewBusiness.Longitude);
397 if (json_object_object_get_ex(medi_array_obj, "location", &medi_array_obj_elem))
401 TRACE_DEBUG_JSON("a location was found");
403 /* TODO: how do we deal with address2 and address3 ? */
404 if(json_object_object_get_ex(medi_array_obj_elem, "address1", &value2))
406 NewBusiness.Address = QString(json_object_get_string(value2));
407 TRACE_DEBUG_JSON("got Address : %s", qPrintable(NewBusiness.Address));
410 if(json_object_object_get_ex(medi_array_obj_elem, "city", &value2))
412 NewBusiness.City = QString(json_object_get_string(value2));
413 TRACE_DEBUG_JSON("got City : %s", qPrintable(NewBusiness.City));
416 if(json_object_object_get_ex(medi_array_obj_elem, "state", &value2))
418 NewBusiness.State = QString(json_object_get_string(value2));
419 TRACE_DEBUG_JSON("got State : %s", qPrintable(NewBusiness.State));
422 if(json_object_object_get_ex(medi_array_obj_elem, "zip_code", &value2))
424 NewBusiness.ZipCode = QString(json_object_get_string(value2));
425 TRACE_DEBUG_JSON("got ZipCode : %s", qPrintable(NewBusiness.ZipCode));
428 if(json_object_object_get_ex(medi_array_obj_elem, "country", &value2))
430 NewBusiness.Country = QString(json_object_get_string(value2));
431 TRACE_DEBUG_JSON("got Country : %s", qPrintable(NewBusiness.Country));
435 /* TODO: parse categories */
437 /* Add business in our list: */
438 Businesses.push_back(NewBusiness);
445 json_object_put(jobj);
448 bool MainApp::eventFilter(QObject *obj, QEvent *ev)
454 if (obj == pResultList)
456 //TRACE_DEBUG("ev->type() = %d", (int)ev->type());
458 if (ev->type() == QEvent::KeyPress)
460 bool consumed = false;
461 int key = static_cast<QKeyEvent*>(ev)->key();
462 TRACE_DEBUG("key pressed (%d)", key);
466 TRACE_DEBUG("enter or return");
469 DisplayInformation(true);
474 DisplayLineEdit(false);
480 TRACE_DEBUG("escape");
481 DisplayResultList(false);
490 case Qt::Key_PageDown:
491 TRACE_DEBUG("arrows");
495 TRACE_DEBUG("default");
504 else if (obj == &lineEdit)
506 if (pInfoPanel && ev->type() == QEvent::KeyPress)
508 switch(static_cast<QKeyEvent*>(ev)->key())
511 TRACE_DEBUG("Escape !");
512 DisplayInformation(false, false);
513 DisplayResultList(true);
514 FillResultList(Businesses, currentIndex);
519 SetDestination(currentIndex);
520 DisplayLineEdit(false);
528 ret = QMainWindow::eventFilter(obj, ev);
534 void MainApp::resizeEvent(QResizeEvent* event)
536 QMainWindow::resizeEvent(event);
539 QTimer::singleShot(AGL_REFRESH_DELAY, Qt::CoarseTimer, this, SLOT(UpdateAglSurfaces()));
543 void MainApp::SetDestination(int index)
547 /* if pResultList exists, take the selected index
548 * otherwise, take the index given as parameter */
551 QList<QTreeWidgetItem *> SelectedItems = pResultList->selectedItems();
552 if (SelectedItems.size() > 0)
554 /* select the first selected item : */
555 index = pResultList->indexOfTopLevelItem(*SelectedItems.begin());
559 TRACE_DEBUG("index is: %d", index);
561 /* retrieve the coordinates of this item : */
562 this->destinationLatitude = Businesses[index].Latitude;
563 this->destinationLongitude = Businesses[index].Longitude;
565 naviapi.getAllRoutes();
570 void MainApp::DisplayInformation(bool display, bool RefreshDisplay)
575 /* pResultList must exist, so that we can retrieve the selected index: */
578 TRACE_ERROR("pResultList is null");
583 QList<QTreeWidgetItem *> SelectedItems = pResultList->selectedItems();
584 if (SelectedItems.size() <= 0)
586 TRACE_ERROR("no item is selected");
591 /* select the first selected item : */
592 currentIndex = pResultList->indexOfTopLevelItem(*SelectedItems.begin());
595 DisplayResultList(false, false);
597 /* Display info for the selected item: */
598 QRect rect( LEFT_OFFSET+searchBtn.width()+SPACER, searchBtn.height()+SPACER,
599 DISPLAY_WIDTH, DISPLAY_HEIGHT);
600 pInfoPanel = new InfoPanel(this, Businesses[currentIndex], rect);
604 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
607 connect(pInfoPanel->getGoButton(), SIGNAL(clicked(bool)), this, SLOT(goClicked()));
608 connect(pInfoPanel->getCancelButton(), SIGNAL(clicked(bool)), this, SLOT(cancelClicked()));
614 pInfoPanel->getGoButton()->disconnect();
615 pInfoPanel->getCancelButton()->disconnect();
623 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
630 void MainApp::networkReplySearch(QNetworkReply* reply)
632 char buf[BIG_BUFFER_SIZE];
637 /* memorize the text which gave this result: */
638 currentSearchedText = lineEdit.text();
640 if (reply->error() == QNetworkReply::NoError)
642 // we only handle this callback if it matches the last search request:
643 if (reply != pSearchReply)
645 TRACE_INFO("this reply is already too late (or about a different network request)");
650 buflen = reply->read(buf, BIG_BUFFER_SIZE-1);
663 ParseJsonBusinessList(buf, Businesses);
664 DisplayResultList(true);
665 FillResultList(Businesses);
669 fprintf(stderr,"POI: reply error network please check to poikey and system time (adjusted?)\n");
675 /* pResultList must be allocated at this point ! */
676 int MainApp::FillResultList(vector<Business> & list, int focusIndex)
682 pResultList->setUpdatesEnabled(false);
683 pResultList->clear();
685 /* filling the dropdown menu: */
686 for (vector<Business>::iterator it = list.begin(); it != list.end(); it++)
688 /* workaround to avoid entries with wrong coordinates returned by Yelp: */
689 if (IsCoordinatesConsistent(*it) == false)
695 QTreeWidgetItem * item = new QTreeWidgetItem(pResultList);
697 ClickableLabel *label = new ClickableLabel("<b>"+(*it).Name+
698 "</b><br>"+(*it).Address+", "+(*it).City+", "+(*it).State+
699 " "+(*it).ZipCode+", "+(*it).Country, pResultList);
700 label->setTextFormat(Qt::RichText);
701 font.setPointSize(FONT_SIZE_LIST);
702 label->setFont(font);
703 label->setIndent(MARGINS);
704 label->setAttribute(Qt::WA_AcceptTouchEvents);
705 item->setSizeHint(0, QSize(TEXT_INPUT_WIDTH, RESULT_ITEM_HEIGHT));
706 pResultList->setItemWidget(item, 0, label);
707 connect(label, SIGNAL(clicked()), this, SLOT(itemClicked()));
709 //item->setText(0, (*it).Name);
711 if (nbElem == focusIndex)
713 pResultList->setCurrentItem(item);
718 pResultList->setUpdatesEnabled(true);
724 /* Well... some of the POI returned by Yelp have coordinates which are
725 * completely inconsistent with the distance at which the POI is
727 * https://github.com/Yelp/yelp-fusion/issues/104
728 * Let's skip them for the moment: */
729 #define PI 3.14159265
730 #define EARTH_RADIUS 6371000
731 static inline double toRadians(double a) { return a * PI / 180.0; }
732 bool MainApp::IsCoordinatesConsistent(Business & business)
734 double lat1 = toRadians(currentLatitude);
735 double lon1 = toRadians(currentLongitude);
736 double lat2 = toRadians(business.Latitude);
737 double lon2 = toRadians(business.Longitude);
738 double x = (lon2 - lon1) * cos((lat1 + lat2)/2);
739 double y = lat2 - lat1;
740 double DistanceFromCoords = EARTH_RADIUS * sqrt(pow(x, 2) + pow(y, 2));
742 /* if calculated distance is not between +/- 10% of the announced
743 * distance -> skip this POI: */
744 if (DistanceFromCoords < business.Distance * 0.9 ||
745 DistanceFromCoords > business.Distance * 1.1)
747 TRACE_ERROR("Announced distance: %f, calculated distance: %f", business.Distance, DistanceFromCoords);
753 /* end of workaround */
755 bool MainApp::CheckNaviApi(int argc, char *argv[])
757 bool ret = naviapi.connect(argc, argv, this);
761 naviapi.getAllSessions();
767 int MainApp::AuthenticatePOI(const QString & CredentialsFile)
772 QString ProxyHostName;
778 /* First, read AppId and AppSecret from credentials file: */
779 FILE* filep = fopen(qPrintable(CredentialsFile), "r");
782 fprintf(stderr,"Failed to open credentials file \"%s\": %m", qPrintable(CredentialsFile));
786 if (!fgets(buf, 512, filep))
788 fprintf(stderr,"Failed to read AppId from credentials file \"%s\"", qPrintable(CredentialsFile));
792 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
793 buf[strlen(buf)-1] = '\0';
794 AppId = QString(buf);
796 if (!fgets(buf, 512, filep))
798 fprintf(stderr,"Failed to read AppSecret from credentials file \"%s\"", qPrintable(CredentialsFile));
802 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
803 buf[strlen(buf)-1] = '\0';
804 AppSecret = QString(buf);
809 if (!fgets(buf, 512, filep))
811 TRACE_INFO("Failed to read ProxyHostName from credentials file \"%s\"", qPrintable(CredentialsFile));
815 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
816 buf[strlen(buf)-1] = '\0';
817 ProxyHostName = QString(buf);
818 ProxyHostName.replace(0, 14, tr(""));
821 if (!fgets(buf, 512, filep))
823 TRACE_ERROR("Failed to read Port from credentials file \"%s\"", qPrintable(CredentialsFile));
827 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
828 buf[strlen(buf)-1] = '\0';
829 PortStr = QString(buf);
830 PortStr.replace(0, 5, tr(""));
831 portnum = PortStr.toInt();
834 if (!fgets(buf, 512, filep))
836 TRACE_ERROR("Failed to read User from credentials file \"%s\"", qPrintable(CredentialsFile));
840 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
841 buf[strlen(buf)-1] = '\0';
843 User.replace(0, 5, tr(""));
846 if (!fgets(buf, 512, filep))
848 TRACE_ERROR("Failed to read Password from credentials file \"%s\"", qPrintable(CredentialsFile));
852 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
853 buf[strlen(buf)-1] = '\0';
854 Password = QString(buf);
855 Password.replace(0, 9, tr(""));
857 proxy.setType(QNetworkProxy::HttpProxy);
858 proxy.setHostName(qPrintable(ProxyHostName));
859 proxy.setPort(portnum);
860 proxy.setUser(qPrintable(User));
861 proxy.setPassword(qPrintable(Password));
862 QNetworkProxy::setApplicationProxy(proxy);
867 TRACE_INFO("Found credentials");
869 /* Then, send a HTTP request to get the token and wait for answer (synchronously): */
875 int MainApp::StartMonitoringUserInput()
877 connect(&searchBtn, SIGNAL(clicked(bool)), this, SLOT(searchBtnClicked()));
878 connect(&lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &)));
879 connect(&networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkReplySearch(QNetworkReply*)));
880 connect(&keyboard, SIGNAL(keyClicked(const QString &)), this, SLOT(textAdded(const QString &)));
881 connect(&keyboard, SIGNAL(specialKeyClicked(int)), this, SLOT(keyPressed(int)));
885 void MainApp::SetWayPoints(uint32_t myRoute)
887 /* set the destination : */
888 naviapi::Waypoint destWp(this->destinationLatitude, this->destinationLongitude);
889 std::vector<naviapi::Waypoint> myWayPoints;
890 myWayPoints.push_back(destWp);
891 naviapi.setWaypoints(navicoreSession, myRoute, true, myWayPoints);
893 naviapi.calculateRoute(navicoreSession, myRoute);
896 currentSearchingText = tr("");
897 currentSearchedText = tr("");
902 void MainApp::goClicked()
904 TRACE_DEBUG("Go clicked !");
905 SetDestination(currentIndex);
906 DisplayLineEdit(false);
909 void MainApp::cancelClicked()
911 TRACE_DEBUG("Cancel clicked !");
912 DisplayInformation(false, false);
913 DisplayResultList(true, false);
914 FillResultList(Businesses, currentIndex);
917 void MainApp::getAllSessions_reply(const std::map< uint32_t, std::string >& allSessions)
921 if (allSessions.empty())
923 TRACE_ERROR("Error: could not find an instance of Navicore");
928 this->navicoreSession = allSessions.begin()->first;
930 TRACE_INFO("Current session: %d", this->navicoreSession);
936 void MainApp::getPosition_reply(std::map< int32_t, naviapi::variant > position)
940 std::map< int32_t, naviapi::variant >::iterator it;
941 for (it = position.begin(); it != position.end(); it++)
943 if (it->first == naviapi::NAVICORE_LATITUDE)
945 currentLatitude = it->second._double;
947 else if (it->first == naviapi::NAVICORE_LONGITUDE)
949 currentLongitude = it->second._double;
953 TRACE_INFO("Current position: %f, %f", currentLatitude, currentLongitude);
957 emit positionGotSignal();
960 void MainApp::getAllRoutes_reply(std::vector< uint32_t > allRoutes)
964 uint32_t routeHandle = 0;
966 if (allRoutes.size() != 0)
968 routeHandle = allRoutes[0];
971 this->currentRouteHandle = routeHandle;
975 emit allRoutesGotSignal();
978 void MainApp::createRoute_reply(uint32_t routeHandle)
982 this->currentRouteHandle = routeHandle;
986 emit routeCreatedSignal();
989 void MainApp::positionGot()
993 /* let's generate a search request : */
994 QString myUrlStr = URL_SEARCH + tr("?") + tr("term=") + currentSearchingText +
995 tr("&latitude=") + QString::number(currentLatitude) +
996 tr("&longitude=") + QString::number(currentLongitude);
998 TRACE_DEBUG("URL: %s", qPrintable(myUrlStr));
1000 QUrl myUrl = QUrl(myUrlStr);
1001 QNetworkRequest req(myUrl);
1002 req.setRawHeader(QByteArray("Authorization"), (tr("bearer ") + token).toLocal8Bit());
1004 /* Then, send a HTTP request to get the token and wait for answer (synchronously): */
1006 pSearchReply = networkManager.get(req);
1011 void MainApp::allRoutesGot()
1015 /* check if a route already exists, if not create it : */
1016 if (this->currentRouteHandle == 0)
1018 naviapi.createRoute(navicoreSession);
1022 naviapi.pauseSimulation(navicoreSession);
1023 naviapi.setSimulationMode(navicoreSession, false);
1024 naviapi.cancelRouteCalculation(navicoreSession, this->currentRouteHandle);
1027 SetWayPoints(this->currentRouteHandle);
1033 void MainApp::routeCreated()
1037 SetWayPoints(this->currentRouteHandle);