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(allSessionsGotSignal()), this, SLOT(allSessionsGot()));
102 connect(this, SIGNAL(positionGotSignal()), this, SLOT(positionGot()));
103 connect(this, SIGNAL(allRoutesGotSignal()), this, SLOT(allRoutesGot()));
104 connect(this, SIGNAL(routeCreatedSignal()), this, SLOT(routeCreated()));
106 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
107 this->setStyleSheet("background-image: url(:/images/AGL_POI_Background.png);");
115 QFontDatabase::removeApplicationFont(fontId);
117 searchBtn.disconnect();
118 lineEdit.disconnect();
119 networkManager.disconnect();
120 keyboard.disconnect();
127 void MainApp::searchBtnClicked()
129 isInputDisplayed = !isInputDisplayed;
130 TRACE_DEBUG("isInputDisplayed = %d", isInputDisplayed);
131 DisplayLineEdit(isInputDisplayed);
134 void MainApp::DisplayLineEdit(bool display)
138 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
142 lineEdit.setVisible(true);
149 pResultList->removeEventFilter(this);
158 lineEdit.setText(tr(""));
159 lineEdit.setVisible(false);
161 isInputDisplayed = display;
166 void MainApp::UpdateAglSurfaces()
170 TRACE_DEBUG("handle AGL demo surfaces (new surface is bigger)");
171 snprintf(cmd, 1023, "/usr/bin/LayerManagerControl set surface $SURFACE_ID_CLIENT source region 0 0 %d %d",
172 this->width(), this->height());
173 TRACE_DEBUG("%s", cmd);
175 snprintf(cmd, 1023, "/usr/bin/LayerManagerControl set surface $SURFACE_ID_CLIENT destination region $CLIENT_X $CLIENT_Y %d %d",
176 this->width(), this->height());
177 TRACE_DEBUG("%s", cmd);
181 void MainApp::DisplayResultList(bool display, bool RefreshDisplay)
189 pResultList = new QTreeWidget(this);
190 pResultList->setStyleSheet("border: none; color: #FFFFFF;");
191 pResultList->setRootIsDecorated(false);
192 pResultList->setEditTriggers(QTreeWidget::NoEditTriggers);
193 pResultList->setSelectionBehavior(QTreeWidget::SelectRows);
194 pResultList->setFrameStyle(QFrame::Box | QFrame::Plain);
195 pResultList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
196 //pResultList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
197 pResultList->setAttribute(Qt::WA_AcceptTouchEvents);
198 pResultList->verticalScrollBar()->setStyleSheet(SCROLLBAR_STYLE);
199 pResultList->header()->hide();
200 //font.setPointSize(FONT_SIZE_LIST);
201 //pResultList->setFont(font);
202 pResultList->installEventFilter(this);
205 pResultList->setGeometry(QRect( LEFT_OFFSET+searchBtn.width()+SPACER, searchBtn.height()+SPACER,
206 DISPLAY_WIDTH, DISPLAY_HEIGHT));
209 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
211 pResultList->setVisible(true);
212 pResultList->setFocus();
218 pResultList->removeEventFilter(this);
219 pResultList->deleteLater();
227 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
234 void MainApp::textChanged(const QString & text)
236 TRACE_INFO("New text is: %s", qPrintable(text));
238 /* do not handle text input if info panel is displayed: */
239 if (pInfoPanel) return;
243 delete pSearchReply; /* cancel current search */
246 if (text.length() == 0) /* if empty text -> no search */
248 DisplayResultList(false);
253 /* if text is the same as previous search -> no need to search again */
254 if (text == currentSearchedText)
256 DisplayResultList(true);
257 FillResultList(Businesses, currentIndex);
261 this->currentSearchingText = text;
263 /* we need to know our current position */
264 std::vector<int32_t> Params;
265 Params.push_back(naviapi::NAVICORE_LONGITUDE);
266 Params.push_back(naviapi::NAVICORE_LATITUDE);
267 naviapi.getPosition(Params);
272 void MainApp::textAdded(const QString & text)
275 lineEdit.setText(lineEdit.text() + text);
279 void MainApp::keyPressed(int key)
282 if (key == '\b') /* backspace */
284 int len = lineEdit.text().length();
286 lineEdit.setText(lineEdit.text().remove(len-1, 1));
291 void MainApp::itemClicked()
296 DisplayInformation(true, false);
301 DisplayLineEdit(false);
306 void MainApp::ParseJsonBusinessList(const char* buf, std::vector<Business> & Output)
308 json_object *jobj = json_tokener_parse(buf);
311 TRACE_ERROR("json_tokener_parse failed");
312 cerr << "json_tokener_parse failed: " << buf << endl;
316 json_object_object_foreach(jobj, key, val)
321 if (json_object_get_type(val) == json_type_array)
323 TRACE_DEBUG_JSON("an array was found");
325 if(json_object_object_get_ex(jobj, "businesses", &value))
327 TRACE_DEBUG_JSON("an business was found");
329 int arraylen = json_object_array_length(value);
331 for (int i = 0; i < arraylen; i++)
333 Business NewBusiness;
335 json_object* medi_array_obj, *medi_array_obj_elem;
336 medi_array_obj = json_object_array_get_idx(value, i);
339 if (json_object_object_get_ex(medi_array_obj, "rating", &medi_array_obj_elem))
341 NewBusiness.Rating = json_object_get_double(medi_array_obj_elem);
342 TRACE_DEBUG_JSON("got Rating : %f", NewBusiness.Rating);
345 if (json_object_object_get_ex(medi_array_obj, "distance", &medi_array_obj_elem))
347 NewBusiness.Distance = json_object_get_double(medi_array_obj_elem);
348 TRACE_DEBUG_JSON("got Distance : %f", NewBusiness.Distance);
351 if (json_object_object_get_ex(medi_array_obj, "review_count", &medi_array_obj_elem))
353 NewBusiness.ReviewCount = json_object_get_int(medi_array_obj_elem);
354 TRACE_DEBUG_JSON("got ReviewCount : %u", NewBusiness.ReviewCount);
357 if (json_object_object_get_ex(medi_array_obj, "name", &medi_array_obj_elem))
359 NewBusiness.Name = QString(json_object_get_string(medi_array_obj_elem));
360 TRACE_DEBUG_JSON("got Name : %s", qPrintable(NewBusiness.Name));
363 if (json_object_object_get_ex(medi_array_obj, "image_url", &medi_array_obj_elem))
365 NewBusiness.ImageUrl = QString(json_object_get_string(medi_array_obj_elem));
366 TRACE_DEBUG_JSON("got ImageUrl : %s", qPrintable(NewBusiness.ImageUrl));
369 if (json_object_object_get_ex(medi_array_obj, "phone", &medi_array_obj_elem))
371 NewBusiness.Phone = QString(json_object_get_string(medi_array_obj_elem));
372 TRACE_DEBUG_JSON("got Phone : %s", qPrintable(NewBusiness.Phone));
375 if (json_object_object_get_ex(medi_array_obj, "coordinates", &medi_array_obj_elem))
379 TRACE_DEBUG_JSON("coordinates were found");
381 if(json_object_object_get_ex(medi_array_obj_elem, "latitude", &value2))
383 NewBusiness.Latitude = json_object_get_double(value2);
384 TRACE_DEBUG_JSON("got Latitude : %f", NewBusiness.Latitude);
387 if(json_object_object_get_ex(medi_array_obj_elem, "longitude", &value2))
389 NewBusiness.Longitude = json_object_get_double(value2);
390 TRACE_DEBUG_JSON("got Longitude : %f", NewBusiness.Longitude);
394 if (json_object_object_get_ex(medi_array_obj, "location", &medi_array_obj_elem))
398 TRACE_DEBUG_JSON("a location was found");
400 /* TODO: how do we deal with address2 and address3 ? */
401 if(json_object_object_get_ex(medi_array_obj_elem, "address1", &value2))
403 NewBusiness.Address = QString(json_object_get_string(value2));
404 TRACE_DEBUG_JSON("got Address : %s", qPrintable(NewBusiness.Address));
407 if(json_object_object_get_ex(medi_array_obj_elem, "city", &value2))
409 NewBusiness.City = QString(json_object_get_string(value2));
410 TRACE_DEBUG_JSON("got City : %s", qPrintable(NewBusiness.City));
413 if(json_object_object_get_ex(medi_array_obj_elem, "state", &value2))
415 NewBusiness.State = QString(json_object_get_string(value2));
416 TRACE_DEBUG_JSON("got State : %s", qPrintable(NewBusiness.State));
419 if(json_object_object_get_ex(medi_array_obj_elem, "zip_code", &value2))
421 NewBusiness.ZipCode = QString(json_object_get_string(value2));
422 TRACE_DEBUG_JSON("got ZipCode : %s", qPrintable(NewBusiness.ZipCode));
425 if(json_object_object_get_ex(medi_array_obj_elem, "country", &value2))
427 NewBusiness.Country = QString(json_object_get_string(value2));
428 TRACE_DEBUG_JSON("got Country : %s", qPrintable(NewBusiness.Country));
432 /* TODO: parse categories */
434 /* Add business in our list: */
435 Businesses.push_back(NewBusiness);
442 json_object_put(jobj);
445 bool MainApp::eventFilter(QObject *obj, QEvent *ev)
451 if (obj == pResultList)
453 //TRACE_DEBUG("ev->type() = %d", (int)ev->type());
455 if (ev->type() == QEvent::KeyPress)
457 bool consumed = false;
458 int key = static_cast<QKeyEvent*>(ev)->key();
459 TRACE_DEBUG("key pressed (%d)", key);
463 TRACE_DEBUG("enter or return");
466 DisplayInformation(true);
471 DisplayLineEdit(false);
477 TRACE_DEBUG("escape");
478 DisplayResultList(false);
487 case Qt::Key_PageDown:
488 TRACE_DEBUG("arrows");
492 TRACE_DEBUG("default");
501 else if (obj == &lineEdit)
503 if (pInfoPanel && ev->type() == QEvent::KeyPress)
505 switch(static_cast<QKeyEvent*>(ev)->key())
508 TRACE_DEBUG("Escape !");
509 DisplayInformation(false, false);
510 DisplayResultList(true);
511 FillResultList(Businesses, currentIndex);
516 SetDestination(currentIndex);
517 DisplayLineEdit(false);
525 ret = QMainWindow::eventFilter(obj, ev);
531 void MainApp::resizeEvent(QResizeEvent* event)
533 QMainWindow::resizeEvent(event);
536 QTimer::singleShot(AGL_REFRESH_DELAY, Qt::CoarseTimer, this, SLOT(UpdateAglSurfaces()));
540 void MainApp::SetDestination(int index)
544 /* if pResultList exists, take the selected index
545 * otherwise, take the index given as parameter */
548 QList<QTreeWidgetItem *> SelectedItems = pResultList->selectedItems();
549 if (SelectedItems.size() > 0)
551 /* select the first selected item : */
552 index = pResultList->indexOfTopLevelItem(*SelectedItems.begin());
556 TRACE_DEBUG("index is: %d", index);
558 /* retrieve the coordinates of this item : */
559 this->destinationLatitude = Businesses[index].Latitude;
560 this->destinationLongitude = Businesses[index].Longitude;
562 naviapi.getAllRoutes();
567 void MainApp::DisplayInformation(bool display, bool RefreshDisplay)
572 /* pResultList must exist, so that we can retrieve the selected index: */
575 TRACE_ERROR("pResultList is null");
580 QList<QTreeWidgetItem *> SelectedItems = pResultList->selectedItems();
581 if (SelectedItems.size() <= 0)
583 TRACE_ERROR("no item is selected");
588 /* select the first selected item : */
589 currentIndex = pResultList->indexOfTopLevelItem(*SelectedItems.begin());
592 DisplayResultList(false, false);
594 /* Display info for the selected item: */
595 QRect rect( LEFT_OFFSET+searchBtn.width()+SPACER, searchBtn.height()+SPACER,
596 DISPLAY_WIDTH, DISPLAY_HEIGHT);
597 pInfoPanel = new InfoPanel(this, Businesses[currentIndex], rect);
601 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
604 connect(pInfoPanel->getGoButton(), SIGNAL(clicked(bool)), this, SLOT(goClicked()));
605 connect(pInfoPanel->getCancelButton(), SIGNAL(clicked(bool)), this, SLOT(cancelClicked()));
611 pInfoPanel->getGoButton()->disconnect();
612 pInfoPanel->getCancelButton()->disconnect();
620 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
627 void MainApp::networkReplySearch(QNetworkReply* reply)
629 char buf[BIG_BUFFER_SIZE];
634 /* memorize the text which gave this result: */
635 currentSearchedText = lineEdit.text();
637 if (reply->error() == QNetworkReply::NoError)
639 // we only handle this callback if it matches the last search request:
640 if (reply != pSearchReply)
642 TRACE_INFO("this reply is already too late (or about a different network request)");
647 buflen = reply->read(buf, BIG_BUFFER_SIZE-1);
660 ParseJsonBusinessList(buf, Businesses);
661 DisplayResultList(true);
662 FillResultList(Businesses);
666 fprintf(stderr,"POI: reply error network please check to poikey and system time (adjusted?)\n");
672 /* pResultList must be allocated at this point ! */
673 int MainApp::FillResultList(vector<Business> & list, int focusIndex)
679 pResultList->setUpdatesEnabled(false);
680 pResultList->clear();
682 /* filling the dropdown menu: */
683 for (vector<Business>::iterator it = list.begin(); it != list.end(); it++)
685 /* workaround to avoid entries with wrong coordinates returned by Yelp: */
686 if (IsCoordinatesConsistent(*it) == false)
692 QTreeWidgetItem * item = new QTreeWidgetItem(pResultList);
694 ClickableLabel *label = new ClickableLabel("<b>"+(*it).Name+
695 "</b><br>"+(*it).Address+", "+(*it).City+", "+(*it).State+
696 " "+(*it).ZipCode+", "+(*it).Country, pResultList);
697 label->setTextFormat(Qt::RichText);
698 font.setPointSize(FONT_SIZE_LIST);
699 label->setFont(font);
700 label->setIndent(MARGINS);
701 label->setAttribute(Qt::WA_AcceptTouchEvents);
702 item->setSizeHint(0, QSize(TEXT_INPUT_WIDTH, RESULT_ITEM_HEIGHT));
703 pResultList->setItemWidget(item, 0, label);
704 connect(label, SIGNAL(clicked()), this, SLOT(itemClicked()));
706 //item->setText(0, (*it).Name);
708 if (nbElem == focusIndex)
710 pResultList->setCurrentItem(item);
715 pResultList->setUpdatesEnabled(true);
721 /* Well... some of the POI returned by Yelp have coordinates which are
722 * completely inconsistent with the distance at which the POI is
724 * https://github.com/Yelp/yelp-fusion/issues/104
725 * Let's skip them for the moment: */
726 #define PI 3.14159265
727 #define EARTH_RADIUS 6371000
728 static inline double toRadians(double a) { return a * PI / 180.0; }
729 bool MainApp::IsCoordinatesConsistent(Business & business)
731 double lat1 = toRadians(currentLatitude);
732 double lon1 = toRadians(currentLongitude);
733 double lat2 = toRadians(business.Latitude);
734 double lon2 = toRadians(business.Longitude);
735 double x = (lon2 - lon1) * cos((lat1 + lat2)/2);
736 double y = lat2 - lat1;
737 double DistanceFromCoords = EARTH_RADIUS * sqrt(pow(x, 2) + pow(y, 2));
739 /* if calculated distance is not between +/- 10% of the announced
740 * distance -> skip this POI: */
741 if (DistanceFromCoords < business.Distance * 0.9 ||
742 DistanceFromCoords > business.Distance * 1.1)
744 TRACE_ERROR("Announced distance: %f, calculated distance: %f", business.Distance, DistanceFromCoords);
750 /* end of workaround */
752 bool MainApp::CheckNaviApi(int argc, char *argv[])
754 bool ret = naviapi.connect(argc, argv, this);
758 naviapi.getAllSessions();
764 int MainApp::AuthenticatePOI(const QString & CredentialsFile)
769 QString ProxyHostName;
775 /* First, read AppId and AppSecret from credentials file: */
776 FILE* filep = fopen(qPrintable(CredentialsFile), "r");
779 fprintf(stderr,"Failed to open credentials file \"%s\": %m", qPrintable(CredentialsFile));
783 if (!fgets(buf, 512, filep))
785 fprintf(stderr,"Failed to read AppId from credentials file \"%s\"", qPrintable(CredentialsFile));
789 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
790 buf[strlen(buf)-1] = '\0';
791 AppId = QString(buf);
793 if (!fgets(buf, 512, filep))
795 fprintf(stderr,"Failed to read AppSecret from credentials file \"%s\"", qPrintable(CredentialsFile));
799 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
800 buf[strlen(buf)-1] = '\0';
801 AppSecret = QString(buf);
806 if (!fgets(buf, 512, filep))
808 TRACE_INFO("Failed to read ProxyHostName from credentials file \"%s\"", qPrintable(CredentialsFile));
812 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
813 buf[strlen(buf)-1] = '\0';
814 ProxyHostName = QString(buf);
815 ProxyHostName.replace(0, 14, tr(""));
818 if (!fgets(buf, 512, filep))
820 TRACE_ERROR("Failed to read Port from credentials file \"%s\"", qPrintable(CredentialsFile));
824 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
825 buf[strlen(buf)-1] = '\0';
826 PortStr = QString(buf);
827 PortStr.replace(0, 5, tr(""));
828 portnum = PortStr.toInt();
831 if (!fgets(buf, 512, filep))
833 TRACE_ERROR("Failed to read User from credentials file \"%s\"", qPrintable(CredentialsFile));
837 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
838 buf[strlen(buf)-1] = '\0';
840 User.replace(0, 5, tr(""));
843 if (!fgets(buf, 512, filep))
845 TRACE_ERROR("Failed to read Password from credentials file \"%s\"", qPrintable(CredentialsFile));
849 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
850 buf[strlen(buf)-1] = '\0';
851 Password = QString(buf);
852 Password.replace(0, 9, tr(""));
854 proxy.setType(QNetworkProxy::HttpProxy);
855 proxy.setHostName(qPrintable(ProxyHostName));
856 proxy.setPort(portnum);
857 proxy.setUser(qPrintable(User));
858 proxy.setPassword(qPrintable(Password));
859 QNetworkProxy::setApplicationProxy(proxy);
864 TRACE_INFO("Found credentials");
866 /* Then, send a HTTP request to get the token and wait for answer (synchronously): */
872 int MainApp::StartMonitoringUserInput()
874 connect(&searchBtn, SIGNAL(clicked(bool)), this, SLOT(searchBtnClicked()));
875 connect(&lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &)));
876 connect(&networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkReplySearch(QNetworkReply*)));
877 connect(&keyboard, SIGNAL(keyClicked(const QString &)), this, SLOT(textAdded(const QString &)));
878 connect(&keyboard, SIGNAL(specialKeyClicked(int)), this, SLOT(keyPressed(int)));
882 void MainApp::SetWayPoints(uint32_t myRoute)
884 /* set the destination : */
885 naviapi::Waypoint destWp(this->destinationLatitude, this->destinationLongitude);
886 std::vector<naviapi::Waypoint> myWayPoints;
887 myWayPoints.push_back(destWp);
888 naviapi.setWaypoints(navicoreSession, myRoute, true, myWayPoints);
890 naviapi.calculateRoute(navicoreSession, myRoute);
893 currentSearchingText = tr("");
894 currentSearchedText = tr("");
899 void MainApp::goClicked()
901 TRACE_DEBUG("Go clicked !");
902 SetDestination(currentIndex);
903 DisplayLineEdit(false);
906 void MainApp::cancelClicked()
908 TRACE_DEBUG("Cancel clicked !");
909 DisplayInformation(false, false);
910 DisplayResultList(true, false);
911 FillResultList(Businesses, currentIndex);
914 void MainApp::getAllSessions_reply(const std::map< uint32_t, std::string >& allSessions)
918 if (allSessions.empty())
920 TRACE_ERROR("Error: could not find an instance of Navicore");
925 this->navicoreSession = allSessions.begin()->first;
927 TRACE_INFO("Current session: %d", this->navicoreSession);
931 emit allSessionsGotSignal();
935 void MainApp::getPosition_reply(std::map< int32_t, naviapi::variant > position)
939 std::map< int32_t, naviapi::variant >::iterator it;
940 for (it = position.begin(); it != position.end(); it++)
942 if (it->first == naviapi::NAVICORE_LATITUDE)
944 currentLatitude = it->second._double;
946 else if (it->first == naviapi::NAVICORE_LONGITUDE)
948 currentLongitude = it->second._double;
952 TRACE_INFO("Current position: %f, %f", currentLatitude, currentLongitude);
956 emit positionGotSignal();
959 void MainApp::getAllRoutes_reply(std::vector< uint32_t > allRoutes)
963 uint32_t routeHandle = 0;
965 if (allRoutes.size() != 0)
967 routeHandle = allRoutes[0];
970 this->currentRouteHandle = routeHandle;
974 emit allRoutesGotSignal();
977 void MainApp::createRoute_reply(uint32_t routeHandle)
981 this->currentRouteHandle = routeHandle;
985 emit routeCreatedSignal();
988 void MainApp::allSessionsGot()
997 void MainApp::positionGot()
1001 /* let's generate a search request : */
1002 QString myUrlStr = URL_SEARCH + tr("?") + tr("term=") + currentSearchingText +
1003 tr("&latitude=") + QString::number(currentLatitude) +
1004 tr("&longitude=") + QString::number(currentLongitude);
1006 TRACE_DEBUG("URL: %s", qPrintable(myUrlStr));
1008 QUrl myUrl = QUrl(myUrlStr);
1009 QNetworkRequest req(myUrl);
1010 req.setRawHeader(QByteArray("Authorization"), (tr("bearer ") + token).toLocal8Bit());
1012 /* Then, send a HTTP request to get the token and wait for answer (synchronously): */
1014 pSearchReply = networkManager.get(req);
1019 void MainApp::allRoutesGot()
1023 /* check if a route already exists, if not create it : */
1024 if (this->currentRouteHandle == 0)
1026 naviapi.createRoute(navicoreSession);
1030 naviapi.pauseSimulation(navicoreSession);
1031 naviapi.setSimulationMode(navicoreSession, false);
1032 naviapi.cancelRouteCalculation(navicoreSession, this->currentRouteHandle);
1035 SetWayPoints(this->currentRouteHandle);
1041 void MainApp::routeCreated()
1045 SetWayPoints(this->currentRouteHandle);