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 LEFT_OFFSET 28
28 #define FONT_SIZE_LINEDIT 20
29 #define FONT_SIZE_LIST 18
30 #define TEXT_INPUT_WIDTH 800
31 #define SEARCH_BTN_SIZE 105
33 #define WIDGET_WIDTH (SEARCH_BTN_SIZE + SPACER + TEXT_INPUT_WIDTH)
34 #define DISPLAY_WIDTH TEXT_INPUT_WIDTH
35 #define DISPLAY_HEIGHT 480
36 #define COMPLETE_W_WITH_KB 1080
37 #define COMPLETE_H_WITH_KB 1488
38 #define RESULT_ITEM_HEIGHT 80
40 #define AGL_REFRESH_DELAY 75 /* milliseconds */
42 #define SCROLLBAR_STYLE \
43 "QScrollBar:vertical {" \
44 " border: 2px solid grey;" \
45 " background: gray;" \
51 MainApp::MainApp():QMainWindow(Q_NULLPTR, Qt::FramelessWindowHint),
52 networkManager(this),searchBtn(QIcon(tr(":/images/loupe-90.png")), tr(""), this),
53 lineEdit(this),keyboard(QRect(0, 688, COMPLETE_W_WITH_KB, 720), this),
54 mutex(QMutex::Recursive),token(""),currentSearchingText(""),currentSearchedText(""),
55 pSearchReply(NULL),pInfoPanel(NULL),pResultList(NULL),currentLatitude(0.0),currentLongitude(0.0),
56 navicoreSession(0),currentIndex(0),fontId(-1),isInfoScreen(false),
57 isInputDisplayed(false),isKeyboard(false),isAglNavi(false)
59 //this->setAttribute(Qt::WA_TranslucentBackground);
60 this->setStyleSheet("border: none;");
62 searchBtn.setStyleSheet("border: none; color: #FFFFFF;");
63 searchBtn.setMinimumSize(QSize(SEARCH_BTN_SIZE, SEARCH_BTN_SIZE));
64 searchBtn.setIconSize(searchBtn.size());
65 searchBtn.setGeometry(QRect(LEFT_OFFSET, 0, searchBtn.width(), searchBtn.height()));
67 lineEdit.setStyleSheet("border: none; color: #FFFFFF;");
68 lineEdit.setMinimumSize(QSize(TEXT_INPUT_WIDTH, SEARCH_BTN_SIZE));
70 lineEdit.setPlaceholderText(QString(DEFAULT_TEXT));
71 font = lineEdit.font();
72 font.setPointSize(FONT_SIZE_LINEDIT);
73 lineEdit.setFont(font);
74 lineEdit.setTextMargins(MARGINS/2, 0, 0, 0);
75 lineEdit.installEventFilter(this);
76 lineEdit.setGeometry(QRect(LEFT_OFFSET + searchBtn.width() + SPACER, 0, lineEdit.width(), lineEdit.height()));
77 lineEdit.setVisible(false);
79 /* We might need a Japanese font: */
80 QFile fontFile(":/fonts/DroidSansJapanese.ttf");
81 if (!fontFile.open(QIODevice::ReadOnly))
83 TRACE_ERROR("failed to open font file");
87 QByteArray fontData = fontFile.readAll();
88 fontId = QFontDatabase::addApplicationFontFromData(fontData);
91 TRACE_ERROR("QFontDatabase::addApplicationFontFromData failed");
95 /* Check if "AGL_NAVI" env variable is set. If yes, we must notify
96 * AGL environment when surface needs to be resized */
97 if (getenv("AGL_NAVI"))
100 connect(this, SIGNAL(positionGotSignal()), this, SLOT(positionGot()));
101 connect(this, SIGNAL(allRoutesGotSignal()), this, SLOT(allRoutesGot()));
102 connect(this, SIGNAL(routeCreatedSignal()), this, SLOT(routeCreated()));
104 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
105 this->setStyleSheet("background-image: url(:/images/AGL_POI_Background.png);");
113 QFontDatabase::removeApplicationFont(fontId);
115 searchBtn.disconnect();
116 lineEdit.disconnect();
117 networkManager.disconnect();
118 keyboard.disconnect();
125 void MainApp::searchBtnClicked()
127 isInputDisplayed = !isInputDisplayed;
128 TRACE_DEBUG("isInputDisplayed = %d", isInputDisplayed);
129 DisplayLineEdit(isInputDisplayed);
132 void MainApp::DisplayLineEdit(bool display)
136 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
140 lineEdit.setVisible(true);
147 pResultList->removeEventFilter(this);
156 lineEdit.setText(tr(""));
157 lineEdit.setVisible(false);
159 isInputDisplayed = display;
164 void MainApp::UpdateAglSurfaces()
168 TRACE_DEBUG("handle AGL demo surfaces (new surface is bigger)");
169 snprintf(cmd, 1023, "/usr/bin/LayerManagerControl set surface $SURFACE_ID_CLIENT source region 0 0 %d %d",
170 this->width(), this->height());
171 TRACE_DEBUG("%s", cmd);
173 snprintf(cmd, 1023, "/usr/bin/LayerManagerControl set surface $SURFACE_ID_CLIENT destination region $CLIENT_X $CLIENT_Y %d %d",
174 this->width(), this->height());
175 TRACE_DEBUG("%s", cmd);
179 void MainApp::DisplayResultList(bool display, bool RefreshDisplay)
187 pResultList = new QTreeWidget(this);
188 pResultList->setStyleSheet("border: none; color: #FFFFFF;");
189 pResultList->setRootIsDecorated(false);
190 pResultList->setEditTriggers(QTreeWidget::NoEditTriggers);
191 pResultList->setSelectionBehavior(QTreeWidget::SelectRows);
192 pResultList->setFrameStyle(QFrame::Box | QFrame::Plain);
193 pResultList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
194 //pResultList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
195 pResultList->setAttribute(Qt::WA_AcceptTouchEvents);
196 pResultList->verticalScrollBar()->setStyleSheet(SCROLLBAR_STYLE);
197 pResultList->header()->hide();
198 //font.setPointSize(FONT_SIZE_LIST);
199 //pResultList->setFont(font);
200 pResultList->installEventFilter(this);
203 pResultList->setGeometry(QRect( LEFT_OFFSET+searchBtn.width()+SPACER, searchBtn.height()+SPACER,
204 DISPLAY_WIDTH, DISPLAY_HEIGHT));
207 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
209 pResultList->setVisible(true);
210 pResultList->setFocus();
216 pResultList->removeEventFilter(this);
217 pResultList->deleteLater();
225 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
232 void MainApp::textChanged(const QString & text)
234 TRACE_INFO("New text is: %s", qPrintable(text));
236 /* do not handle text input if info panel is displayed: */
237 if (pInfoPanel) return;
241 delete pSearchReply; /* cancel current search */
244 if (text.length() == 0) /* if empty text -> no search */
246 DisplayResultList(false);
251 /* if text is the same as previous search -> no need to search again */
252 if (text == currentSearchedText)
254 DisplayResultList(true);
255 FillResultList(Businesses, currentIndex);
259 this->currentSearchingText = text;
261 /* we need to know our current position */
262 std::vector<int32_t> Params;
263 Params.push_back(naviapi::NAVICORE_LONGITUDE);
264 Params.push_back(naviapi::NAVICORE_LATITUDE);
265 naviapi.getPosition(Params);
270 void MainApp::textAdded(const QString & text)
273 lineEdit.setText(lineEdit.text() + text);
275 // be sure any text is visible on initial input
276 lineEdit.setVisible(true);
281 void MainApp::keyPressed(int key)
284 if (key == '\b') /* backspace */
286 int len = lineEdit.text().length();
288 lineEdit.setText(lineEdit.text().remove(len-1, 1));
293 void MainApp::itemClicked()
298 DisplayInformation(true, false);
303 DisplayLineEdit(false);
308 void MainApp::ParseJsonBusinessList(const char* buf, std::vector<Business> & Output)
310 json_object *jobj = json_tokener_parse(buf);
313 TRACE_ERROR("json_tokener_parse failed");
314 cerr << "json_tokener_parse failed: " << buf << endl;
318 json_object_object_foreach(jobj, key, val)
323 if (json_object_get_type(val) == json_type_array)
325 TRACE_DEBUG_JSON("an array was found");
327 if(json_object_object_get_ex(jobj, "businesses", &value))
329 TRACE_DEBUG_JSON("an business was found");
331 int arraylen = json_object_array_length(value);
333 for (int i = 0; i < arraylen; i++)
335 Business NewBusiness;
337 json_object* medi_array_obj, *medi_array_obj_elem;
338 medi_array_obj = json_object_array_get_idx(value, i);
341 if (json_object_object_get_ex(medi_array_obj, "rating", &medi_array_obj_elem))
343 NewBusiness.Rating = json_object_get_double(medi_array_obj_elem);
344 TRACE_DEBUG_JSON("got Rating : %f", NewBusiness.Rating);
347 if (json_object_object_get_ex(medi_array_obj, "distance", &medi_array_obj_elem))
349 NewBusiness.Distance = json_object_get_double(medi_array_obj_elem);
350 TRACE_DEBUG_JSON("got Distance : %f", NewBusiness.Distance);
353 if (json_object_object_get_ex(medi_array_obj, "review_count", &medi_array_obj_elem))
355 NewBusiness.ReviewCount = json_object_get_int(medi_array_obj_elem);
356 TRACE_DEBUG_JSON("got ReviewCount : %u", NewBusiness.ReviewCount);
359 if (json_object_object_get_ex(medi_array_obj, "name", &medi_array_obj_elem))
361 NewBusiness.Name = QString(json_object_get_string(medi_array_obj_elem));
362 TRACE_DEBUG_JSON("got Name : %s", qPrintable(NewBusiness.Name));
365 if (json_object_object_get_ex(medi_array_obj, "image_url", &medi_array_obj_elem))
367 NewBusiness.ImageUrl = QString(json_object_get_string(medi_array_obj_elem));
368 TRACE_DEBUG_JSON("got ImageUrl : %s", qPrintable(NewBusiness.ImageUrl));
371 if (json_object_object_get_ex(medi_array_obj, "phone", &medi_array_obj_elem))
373 NewBusiness.Phone = QString(json_object_get_string(medi_array_obj_elem));
374 TRACE_DEBUG_JSON("got Phone : %s", qPrintable(NewBusiness.Phone));
377 if (json_object_object_get_ex(medi_array_obj, "coordinates", &medi_array_obj_elem))
381 TRACE_DEBUG_JSON("coordinates were found");
383 if(json_object_object_get_ex(medi_array_obj_elem, "latitude", &value2))
385 NewBusiness.Latitude = json_object_get_double(value2);
386 TRACE_DEBUG_JSON("got Latitude : %f", NewBusiness.Latitude);
389 if(json_object_object_get_ex(medi_array_obj_elem, "longitude", &value2))
391 NewBusiness.Longitude = json_object_get_double(value2);
392 TRACE_DEBUG_JSON("got Longitude : %f", NewBusiness.Longitude);
396 if (json_object_object_get_ex(medi_array_obj, "location", &medi_array_obj_elem))
400 TRACE_DEBUG_JSON("a location was found");
402 /* TODO: how do we deal with address2 and address3 ? */
403 if(json_object_object_get_ex(medi_array_obj_elem, "address1", &value2))
405 NewBusiness.Address = QString(json_object_get_string(value2));
406 TRACE_DEBUG_JSON("got Address : %s", qPrintable(NewBusiness.Address));
409 if(json_object_object_get_ex(medi_array_obj_elem, "city", &value2))
411 NewBusiness.City = QString(json_object_get_string(value2));
412 TRACE_DEBUG_JSON("got City : %s", qPrintable(NewBusiness.City));
415 if(json_object_object_get_ex(medi_array_obj_elem, "state", &value2))
417 NewBusiness.State = QString(json_object_get_string(value2));
418 TRACE_DEBUG_JSON("got State : %s", qPrintable(NewBusiness.State));
421 if(json_object_object_get_ex(medi_array_obj_elem, "zip_code", &value2))
423 NewBusiness.ZipCode = QString(json_object_get_string(value2));
424 TRACE_DEBUG_JSON("got ZipCode : %s", qPrintable(NewBusiness.ZipCode));
427 if(json_object_object_get_ex(medi_array_obj_elem, "country", &value2))
429 NewBusiness.Country = QString(json_object_get_string(value2));
430 TRACE_DEBUG_JSON("got Country : %s", qPrintable(NewBusiness.Country));
434 /* TODO: parse categories */
436 /* Add business in our list: */
437 Businesses.push_back(NewBusiness);
444 json_object_put(jobj);
447 bool MainApp::eventFilter(QObject *obj, QEvent *ev)
453 if (obj == pResultList)
455 //TRACE_DEBUG("ev->type() = %d", (int)ev->type());
457 if (ev->type() == QEvent::KeyPress)
459 bool consumed = false;
460 int key = static_cast<QKeyEvent*>(ev)->key();
461 TRACE_DEBUG("key pressed (%d)", key);
465 TRACE_DEBUG("enter or return");
468 DisplayInformation(true);
473 DisplayLineEdit(false);
479 TRACE_DEBUG("escape");
480 DisplayResultList(false);
489 case Qt::Key_PageDown:
490 TRACE_DEBUG("arrows");
494 TRACE_DEBUG("default");
503 else if (obj == &lineEdit)
505 if (pInfoPanel && ev->type() == QEvent::KeyPress)
507 switch(static_cast<QKeyEvent*>(ev)->key())
510 TRACE_DEBUG("Escape !");
511 DisplayInformation(false, false);
512 DisplayResultList(true);
513 FillResultList(Businesses, currentIndex);
518 SetDestination(currentIndex);
519 DisplayLineEdit(false);
527 ret = QMainWindow::eventFilter(obj, ev);
533 void MainApp::resizeEvent(QResizeEvent* event)
535 QMainWindow::resizeEvent(event);
538 QTimer::singleShot(AGL_REFRESH_DELAY, Qt::CoarseTimer, this, SLOT(UpdateAglSurfaces()));
542 void MainApp::SetDestination(int index)
546 /* if pResultList exists, take the selected index
547 * otherwise, take the index given as parameter */
550 QList<QTreeWidgetItem *> SelectedItems = pResultList->selectedItems();
551 if (SelectedItems.size() > 0)
553 /* select the first selected item : */
554 index = pResultList->indexOfTopLevelItem(*SelectedItems.begin());
558 TRACE_DEBUG("index is: %d", index);
560 /* retrieve the coordinates of this item : */
561 this->destinationLatitude = Businesses[index].Latitude;
562 this->destinationLongitude = Businesses[index].Longitude;
564 naviapi.getAllRoutes();
569 void MainApp::DisplayInformation(bool display, bool RefreshDisplay)
574 /* pResultList must exist, so that we can retrieve the selected index: */
577 TRACE_ERROR("pResultList is null");
582 QList<QTreeWidgetItem *> SelectedItems = pResultList->selectedItems();
583 if (SelectedItems.size() <= 0)
585 TRACE_ERROR("no item is selected");
590 /* select the first selected item : */
591 currentIndex = pResultList->indexOfTopLevelItem(*SelectedItems.begin());
594 DisplayResultList(false, false);
596 /* Display info for the selected item: */
597 QRect rect( LEFT_OFFSET+searchBtn.width()+SPACER, searchBtn.height()+SPACER,
598 DISPLAY_WIDTH, DISPLAY_HEIGHT);
599 pInfoPanel = new InfoPanel(this, Businesses[currentIndex], rect);
603 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
606 connect(pInfoPanel->getGoButton(), SIGNAL(clicked(bool)), this, SLOT(goClicked()));
607 connect(pInfoPanel->getCancelButton(), SIGNAL(clicked(bool)), this, SLOT(cancelClicked()));
613 pInfoPanel->getGoButton()->disconnect();
614 pInfoPanel->getCancelButton()->disconnect();
622 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
629 void MainApp::networkReplySearch(QNetworkReply* reply)
635 /* memorize the text which gave this result: */
636 currentSearchedText = lineEdit.text();
638 if (reply->error() == QNetworkReply::NoError)
640 // we only handle this callback if it matches the last search request:
641 if (reply != pSearchReply)
643 TRACE_INFO("this reply is already too late (or about a different network request)");
648 buf = reply->readAll();
660 ParseJsonBusinessList(buf.data(), 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);
933 void MainApp::getPosition_reply(std::map< int32_t, naviapi::variant > position)
937 std::map< int32_t, naviapi::variant >::iterator it;
938 for (it = position.begin(); it != position.end(); it++)
940 if (it->first == naviapi::NAVICORE_LATITUDE)
942 currentLatitude = it->second._double;
944 else if (it->first == naviapi::NAVICORE_LONGITUDE)
946 currentLongitude = it->second._double;
950 TRACE_INFO("Current position: %f, %f", currentLatitude, currentLongitude);
954 emit positionGotSignal();
957 void MainApp::getAllRoutes_reply(std::vector< uint32_t > allRoutes)
961 uint32_t routeHandle = 0;
963 if (allRoutes.size() != 0)
965 routeHandle = allRoutes[0];
968 this->currentRouteHandle = routeHandle;
972 emit allRoutesGotSignal();
975 void MainApp::createRoute_reply(uint32_t routeHandle)
979 this->currentRouteHandle = routeHandle;
983 emit routeCreatedSignal();
986 void MainApp::positionGot()
990 /* let's generate a search request : */
991 QString myUrlStr = URL_SEARCH + tr("?") + tr("term=") + currentSearchingText +
992 tr("&latitude=") + QString::number(currentLatitude) +
993 tr("&longitude=") + QString::number(currentLongitude);
995 TRACE_DEBUG("URL: %s", qPrintable(myUrlStr));
997 QUrl myUrl = QUrl(myUrlStr);
998 QNetworkRequest req(myUrl);
999 req.setRawHeader(QByteArray("Authorization"), (tr("bearer ") + token).toLocal8Bit());
1001 /* Then, send a HTTP request to get the token and wait for answer (synchronously): */
1003 pSearchReply = networkManager.get(req);
1008 void MainApp::allRoutesGot()
1012 /* check if a route already exists, if not create it : */
1013 if (this->currentRouteHandle == 0)
1015 naviapi.createRoute(navicoreSession);
1019 naviapi.pauseSimulation(navicoreSession);
1020 naviapi.setSimulationMode(navicoreSession, false);
1021 naviapi.cancelRouteCalculation(navicoreSession, this->currentRouteHandle);
1024 SetWayPoints(this->currentRouteHandle);
1030 void MainApp::routeCreated()
1034 SetWayPoints(this->currentRouteHandle);