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 #include <navigation.h>
24 #define NAVI_CONFIG_FILEPATH "/etc/naviconfig.ini"
26 #define DEFAULT_TEXT "Select your destination with Yelp !"
27 #define URL_AUTH "https://api.yelp.com/oauth2/token"
28 #define URL_AUTOCOMPLETE "https://api.yelp.com/v3/autocomplete"
29 #define URL_SEARCH "https://api.yelp.com/v3/businesses/search"
31 #define LEFT_OFFSET 28
32 #define FONT_SIZE_LINEDIT 20
33 #define FONT_SIZE_LIST 18
34 #define TEXT_INPUT_WIDTH 800
35 #define SEARCH_BTN_SIZE 105
37 #define WIDGET_WIDTH (SEARCH_BTN_SIZE + SPACER + TEXT_INPUT_WIDTH)
38 #define DISPLAY_WIDTH TEXT_INPUT_WIDTH
39 #define DISPLAY_HEIGHT 480
40 #define COMPLETE_W_WITH_KB 1080
41 #define COMPLETE_H_WITH_KB 1488
42 #define RESULT_ITEM_HEIGHT 80
44 #define AGL_REFRESH_DELAY 75 /* milliseconds */
46 #define SCROLLBAR_STYLE \
47 "QScrollBar:vertical {" \
48 " border: 2px solid grey;" \
49 " background: gray;" \
55 MainApp::MainApp(Navigation *navigation):QMainWindow(Q_NULLPTR, Qt::FramelessWindowHint),
56 networkManager(this),searchBtn(QIcon(tr(":/images/loupe-90.png")), tr(""), this),
57 lineEdit(this),keyboard(QRect(0, 688, COMPLETE_W_WITH_KB, 720), this),
58 mutex(QMutex::Recursive),token(""),currentSearchingText(""),currentSearchedText(""),
59 pSearchReply(NULL),pInfoPanel(NULL),pResultList(NULL),currentLatitude(36.136261),currentLongitude(-115.151254),
60 navicoreSession(0),currentIndex(0),fontId(-1),isInfoScreen(false),
61 isInputDisplayed(false),isKeyboard(false),isAglNavi(false), naviapi(navigation)
63 //this->setAttribute(Qt::WA_TranslucentBackground);
64 this->setStyleSheet("border: none;");
66 searchBtn.setStyleSheet("border: none; color: #FFFFFF;");
67 searchBtn.setMinimumSize(QSize(SEARCH_BTN_SIZE, SEARCH_BTN_SIZE));
68 searchBtn.setIconSize(searchBtn.size());
69 searchBtn.setGeometry(QRect(LEFT_OFFSET, 0, searchBtn.width(), searchBtn.height()));
71 lineEdit.setStyleSheet("border: none; color: #FFFFFF;");
72 lineEdit.setMinimumSize(QSize(TEXT_INPUT_WIDTH, SEARCH_BTN_SIZE));
74 lineEdit.setPlaceholderText(QString(DEFAULT_TEXT));
75 font = lineEdit.font();
76 font.setPointSize(FONT_SIZE_LINEDIT);
77 lineEdit.setFont(font);
78 lineEdit.setTextMargins(MARGINS/2, 0, 0, 0);
79 lineEdit.installEventFilter(this);
80 lineEdit.setGeometry(QRect(LEFT_OFFSET + searchBtn.width() + SPACER, 0, lineEdit.width(), lineEdit.height()));
81 lineEdit.setVisible(false);
83 QFile file(NAVI_CONFIG_FILEPATH);
84 if (file.open(QIODevice::ReadOnly | QIODevice::Text))
86 QByteArray data = file.readAll();
87 QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
88 QJsonObject jsonObj(jsonDoc.object());
90 if (jsonObj.contains("latitude"))
91 currentLatitude = jsonObj["latitude"].toDouble();
93 if (jsonObj.contains("longitude"))
94 currentLongitude = jsonObj["longitude"].toDouble();
97 /* We might need a Japanese font: */
98 QFile fontFile(":/fonts/DroidSansJapanese.ttf");
99 if (!fontFile.open(QIODevice::ReadOnly))
101 TRACE_ERROR("failed to open font file");
105 QByteArray fontData = fontFile.readAll();
106 fontId = QFontDatabase::addApplicationFontFromData(fontData);
109 TRACE_ERROR("QFontDatabase::addApplicationFontFromData failed");
113 /* Check if "AGL_NAVI" env variable is set. If yes, we must notify
114 * AGL environment when surface needs to be resized */
115 if (getenv("AGL_NAVI"))
118 connect(this, SIGNAL(positionGotSignal()), this, SLOT(positionGot()));
120 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
121 this->setStyleSheet("background-image: url(:/images/AGL_POI_Background.png);");
129 QFontDatabase::removeApplicationFont(fontId);
131 searchBtn.disconnect();
132 lineEdit.disconnect();
133 networkManager.disconnect();
134 keyboard.disconnect();
141 void MainApp::searchBtnClicked()
143 isInputDisplayed = !isInputDisplayed;
144 TRACE_DEBUG("isInputDisplayed = %d", isInputDisplayed);
145 DisplayLineEdit(isInputDisplayed);
148 void MainApp::DisplayLineEdit(bool display)
154 lineEdit.setVisible(true);
161 pResultList->removeEventFilter(this);
162 pResultList->setVisible(false);
166 pInfoPanel->setVisible(false);
168 lineEdit.setText(tr(""));
169 lineEdit.setVisible(false);
171 isInputDisplayed = display;
176 void MainApp::UpdateAglSurfaces()
180 TRACE_DEBUG("handle AGL demo surfaces (new surface is bigger)");
181 snprintf(cmd, 1023, "/usr/bin/LayerManagerControl set surface $SURFACE_ID_CLIENT source region 0 0 %d %d",
182 this->width(), this->height());
183 TRACE_DEBUG("%s", cmd);
185 snprintf(cmd, 1023, "/usr/bin/LayerManagerControl set surface $SURFACE_ID_CLIENT destination region $CLIENT_X $CLIENT_Y %d %d",
186 this->width(), this->height());
187 TRACE_DEBUG("%s", cmd);
191 void MainApp::DisplayResultList(bool display)
199 pResultList = new QTreeWidget(this);
200 pResultList->setStyleSheet("border: none; color: #FFFFFF;");
201 pResultList->setRootIsDecorated(false);
202 pResultList->setEditTriggers(QTreeWidget::NoEditTriggers);
203 pResultList->setSelectionBehavior(QTreeWidget::SelectRows);
204 pResultList->setFrameStyle(QFrame::Box | QFrame::Plain);
205 pResultList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
206 //pResultList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
207 pResultList->setAttribute(Qt::WA_AcceptTouchEvents);
208 pResultList->verticalScrollBar()->setStyleSheet(SCROLLBAR_STYLE);
209 pResultList->header()->hide();
210 //font.setPointSize(FONT_SIZE_LIST);
211 //pResultList->setFont(font);
212 pResultList->installEventFilter(this);
214 pResultList->setGeometry(QRect(LEFT_OFFSET + searchBtn.width() + SPACER,
215 searchBtn.height() + SPACER,
219 pResultList->setVisible(true);
220 pResultList->setFocus();
221 pResultList->update();
227 pResultList->removeEventFilter(this);
228 pResultList->setVisible(false);
229 pResultList->update();
237 void MainApp::textChanged(const QString & text)
239 TRACE_INFO("New text is: %s", qPrintable(text));
241 /* do not handle text input if info panel is displayed: */
242 if (pInfoPanel && pInfoPanel->isVisible())
247 delete pSearchReply; /* cancel current search */
250 if (text.length() == 0) /* if empty text -> no search */
252 DisplayResultList(false);
257 /* if text is the same as previous search -> no need to search again */
258 if (text == currentSearchedText)
260 DisplayResultList(true);
261 FillResultList(Businesses, currentIndex);
265 this->currentSearchingText = text;
267 emit positionGotSignal();
272 void MainApp::textAdded(const QString & text)
275 lineEdit.setText(lineEdit.text() + text);
277 // be sure any text is visible on initial input
278 lineEdit.setVisible(true);
283 void MainApp::keyPressed(int key)
286 if (key == '\b') /* backspace */
288 int len = lineEdit.text().length();
290 lineEdit.setText(lineEdit.text().remove(len-1, 1));
295 void MainApp::itemClicked()
300 DisplayInformation(true);
305 DisplayLineEdit(false);
310 void MainApp::ParseJsonBusinessList(const char* buf, std::vector<Business> & Output)
312 json_object *jobj = json_tokener_parse(buf);
315 TRACE_ERROR("json_tokener_parse failed");
316 cerr << "json_tokener_parse failed: " << buf << endl;
320 json_object_object_foreach(jobj, key, val)
325 if (json_object_get_type(val) == json_type_array)
327 TRACE_DEBUG_JSON("an array was found");
329 if(json_object_object_get_ex(jobj, "businesses", &value))
331 TRACE_DEBUG_JSON("an business was found");
333 int arraylen = json_object_array_length(value);
335 for (int i = 0; i < arraylen; i++)
337 Business NewBusiness;
339 json_object* medi_array_obj, *medi_array_obj_elem;
340 medi_array_obj = json_object_array_get_idx(value, i);
343 if (json_object_object_get_ex(medi_array_obj, "rating", &medi_array_obj_elem))
345 NewBusiness.Rating = json_object_get_double(medi_array_obj_elem);
346 TRACE_DEBUG_JSON("got Rating : %f", NewBusiness.Rating);
349 if (json_object_object_get_ex(medi_array_obj, "distance", &medi_array_obj_elem))
351 NewBusiness.Distance = json_object_get_double(medi_array_obj_elem);
352 TRACE_DEBUG_JSON("got Distance : %f", NewBusiness.Distance);
355 if (json_object_object_get_ex(medi_array_obj, "review_count", &medi_array_obj_elem))
357 NewBusiness.ReviewCount = json_object_get_int(medi_array_obj_elem);
358 TRACE_DEBUG_JSON("got ReviewCount : %u", NewBusiness.ReviewCount);
361 if (json_object_object_get_ex(medi_array_obj, "name", &medi_array_obj_elem))
363 NewBusiness.Name = QString(json_object_get_string(medi_array_obj_elem));
364 TRACE_DEBUG_JSON("got Name : %s", qPrintable(NewBusiness.Name));
367 if (json_object_object_get_ex(medi_array_obj, "image_url", &medi_array_obj_elem))
369 NewBusiness.ImageUrl = QString(json_object_get_string(medi_array_obj_elem));
370 TRACE_DEBUG_JSON("got ImageUrl : %s", qPrintable(NewBusiness.ImageUrl));
373 if (json_object_object_get_ex(medi_array_obj, "phone", &medi_array_obj_elem))
375 NewBusiness.Phone = QString(json_object_get_string(medi_array_obj_elem));
376 TRACE_DEBUG_JSON("got Phone : %s", qPrintable(NewBusiness.Phone));
379 if (json_object_object_get_ex(medi_array_obj, "coordinates", &medi_array_obj_elem))
383 TRACE_DEBUG_JSON("coordinates were found");
385 if(json_object_object_get_ex(medi_array_obj_elem, "latitude", &value2))
387 NewBusiness.Latitude = json_object_get_double(value2);
388 TRACE_DEBUG_JSON("got Latitude : %f", NewBusiness.Latitude);
391 if(json_object_object_get_ex(medi_array_obj_elem, "longitude", &value2))
393 NewBusiness.Longitude = json_object_get_double(value2);
394 TRACE_DEBUG_JSON("got Longitude : %f", NewBusiness.Longitude);
398 if (json_object_object_get_ex(medi_array_obj, "location", &medi_array_obj_elem))
402 TRACE_DEBUG_JSON("a location was found");
404 /* TODO: how do we deal with address2 and address3 ? */
405 if(json_object_object_get_ex(medi_array_obj_elem, "address1", &value2))
407 NewBusiness.Address = QString(json_object_get_string(value2));
408 TRACE_DEBUG_JSON("got Address : %s", qPrintable(NewBusiness.Address));
411 if(json_object_object_get_ex(medi_array_obj_elem, "city", &value2))
413 NewBusiness.City = QString(json_object_get_string(value2));
414 TRACE_DEBUG_JSON("got City : %s", qPrintable(NewBusiness.City));
417 if(json_object_object_get_ex(medi_array_obj_elem, "state", &value2))
419 NewBusiness.State = QString(json_object_get_string(value2));
420 TRACE_DEBUG_JSON("got State : %s", qPrintable(NewBusiness.State));
423 if(json_object_object_get_ex(medi_array_obj_elem, "zip_code", &value2))
425 NewBusiness.ZipCode = QString(json_object_get_string(value2));
426 TRACE_DEBUG_JSON("got ZipCode : %s", qPrintable(NewBusiness.ZipCode));
429 if(json_object_object_get_ex(medi_array_obj_elem, "country", &value2))
431 NewBusiness.Country = QString(json_object_get_string(value2));
432 TRACE_DEBUG_JSON("got Country : %s", qPrintable(NewBusiness.Country));
436 /* TODO: parse categories */
438 /* Add business in our list: */
439 Businesses.push_back(NewBusiness);
446 json_object_put(jobj);
449 bool MainApp::eventFilter(QObject *obj, QEvent *ev)
455 if (obj == pResultList)
457 //TRACE_DEBUG("ev->type() = %d", (int)ev->type());
459 if (ev->type() == QEvent::KeyPress)
461 bool consumed = false;
462 int key = static_cast<QKeyEvent*>(ev)->key();
463 TRACE_DEBUG("key pressed (%d)", key);
467 TRACE_DEBUG("enter or return");
470 DisplayInformation(true);
475 DisplayLineEdit(false);
481 TRACE_DEBUG("escape");
482 DisplayResultList(false);
491 case Qt::Key_PageDown:
492 TRACE_DEBUG("arrows");
496 TRACE_DEBUG("default");
505 else if (obj == &lineEdit)
507 if (pInfoPanel && ev->type() == QEvent::KeyPress)
509 switch(static_cast<QKeyEvent*>(ev)->key())
512 TRACE_DEBUG("Escape !");
513 DisplayInformation(false);
514 DisplayResultList(true);
515 FillResultList(Businesses, currentIndex);
520 SetDestination(currentIndex);
521 DisplayLineEdit(false);
529 ret = QMainWindow::eventFilter(obj, ev);
535 void MainApp::resizeEvent(QResizeEvent* event)
537 QMainWindow::resizeEvent(event);
540 QTimer::singleShot(AGL_REFRESH_DELAY, Qt::CoarseTimer, this, SLOT(UpdateAglSurfaces()));
544 void MainApp::SetDestination(int index)
548 /* if pResultList exists, take the selected index
549 * otherwise, take the index given as parameter */
552 QList<QTreeWidgetItem *> SelectedItems = pResultList->selectedItems();
553 if (SelectedItems.size() > 0)
555 /* select the first selected item : */
556 index = pResultList->indexOfTopLevelItem(*SelectedItems.begin());
560 TRACE_DEBUG("index is: %d", index);
562 /* retrieve the coordinates of this item : */
563 this->destinationLatitude = Businesses[index].Latitude;
564 this->destinationLongitude = Businesses[index].Longitude;
571 // Attempt to let any outstanding repaints finish by flushing
572 // and then waiting slightly before raising the nav window.
573 // It's currently unclear why repaints can be missed if this
575 qApp->processEvents();
577 //TRACE_DEBUG("Calling nav window raise callback");
578 QTimer::singleShot(100, this, SLOT(callNavWinRaiseCb()));
582 void MainApp::DisplayInformation(bool display)
587 /* pResultList must exist, so that we can retrieve the selected index: */
590 TRACE_ERROR("pResultList is null");
595 QList<QTreeWidgetItem *> SelectedItems = pResultList->selectedItems();
596 if (SelectedItems.size() <= 0)
598 TRACE_ERROR("no item is selected");
603 /* select the first selected item : */
604 currentIndex = pResultList->indexOfTopLevelItem(*SelectedItems.begin());
607 DisplayResultList(false);
609 /* Display info for the selected item: */
611 QRect rect(LEFT_OFFSET + searchBtn.width() + SPACER,
615 pInfoPanel = new InfoPanel(this, rect);
617 pInfoPanel->populateInfo(Businesses[currentIndex]);
618 pInfoPanel->setVisible(true);
619 pInfoPanel->update();
621 connect(pInfoPanel->getGoButton(), SIGNAL(clicked(bool)), this, SLOT(goClicked()));
622 connect(pInfoPanel->getCancelButton(), SIGNAL(clicked(bool)), this, SLOT(cancelClicked()));
628 pInfoPanel->setVisible(false);
629 pInfoPanel->getGoButton()->disconnect();
630 pInfoPanel->getCancelButton()->disconnect();
631 pInfoPanel->update();
639 void MainApp::networkReplySearch(QNetworkReply* reply)
645 /* memorize the text which gave this result: */
646 currentSearchedText = lineEdit.text();
648 if (reply->error() == QNetworkReply::NoError)
650 // we only handle this callback if it matches the last search request:
651 if (reply != pSearchReply)
653 TRACE_INFO("this reply is already too late (or about a different network request)");
658 buf = reply->readAll();
668 ParseJsonBusinessList(buf.data(), Businesses);
669 DisplayResultList(true);
670 FillResultList(Businesses);
674 fprintf(stderr,"POI: reply error network please check to poikey and system time (adjusted?)\n");
680 /* pResultList must be allocated at this point ! */
681 int MainApp::FillResultList(vector<Business> & list, int focusIndex)
687 pResultList->setUpdatesEnabled(false);
688 pResultList->clear();
690 /* filling the dropdown menu: */
691 for (vector<Business>::iterator it = list.begin(); it != list.end(); it++)
693 /* workaround to avoid entries with wrong coordinates returned by Yelp: */
694 if (IsCoordinatesConsistent(*it) == false)
700 QTreeWidgetItem * item = new QTreeWidgetItem(pResultList);
702 ClickableLabel *label = new ClickableLabel("<b>"+(*it).Name+
703 "</b><br>"+(*it).Address+", "+(*it).City+", "+(*it).State+
704 " "+(*it).ZipCode+", "+(*it).Country, pResultList);
705 label->setTextFormat(Qt::RichText);
706 font.setPointSize(FONT_SIZE_LIST);
707 label->setFont(font);
708 label->setIndent(MARGINS);
709 label->setAttribute(Qt::WA_AcceptTouchEvents);
710 item->setSizeHint(0, QSize(TEXT_INPUT_WIDTH, RESULT_ITEM_HEIGHT));
711 pResultList->setItemWidget(item, 0, label);
712 connect(label, SIGNAL(clicked()), this, SLOT(itemClicked()));
714 //item->setText(0, (*it).Name);
716 if (nbElem == focusIndex)
718 pResultList->setCurrentItem(item);
723 pResultList->setUpdatesEnabled(true);
729 /* Well... some of the POI returned by Yelp have coordinates which are
730 * completely inconsistent with the distance at which the POI is
732 * https://github.com/Yelp/yelp-fusion/issues/104
733 * Let's skip them for the moment: */
734 #define PI 3.14159265
735 #define EARTH_RADIUS 6371000
736 static inline double toRadians(double a) { return a * PI / 180.0; }
737 bool MainApp::IsCoordinatesConsistent(Business & business)
739 double lat1 = toRadians(currentLatitude);
740 double lon1 = toRadians(currentLongitude);
741 double lat2 = toRadians(business.Latitude);
742 double lon2 = toRadians(business.Longitude);
743 double x = (lon2 - lon1) * cos((lat1 + lat2)/2);
744 double y = lat2 - lat1;
745 double DistanceFromCoords = EARTH_RADIUS * sqrt(pow(x, 2) + pow(y, 2));
747 /* if calculated distance is not between +/- 10% of the announced
748 * distance -> skip this POI: */
749 if (DistanceFromCoords < business.Distance * 0.9 ||
750 DistanceFromCoords > business.Distance * 1.1)
752 TRACE_ERROR("Announced distance: %f, calculated distance: %f", business.Distance, DistanceFromCoords);
758 /* end of workaround */
760 int MainApp::AuthenticatePOI(const QString & CredentialsFile)
765 QString ProxyHostName;
771 /* First, read AppId and AppSecret from credentials file: */
772 FILE* filep = fopen(qPrintable(CredentialsFile), "r");
775 fprintf(stderr,"Failed to open credentials file \"%s\": %m", qPrintable(CredentialsFile));
779 if (!fgets(buf, 512, filep))
781 fprintf(stderr,"Failed to read AppId from credentials file \"%s\"", qPrintable(CredentialsFile));
785 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
786 buf[strlen(buf)-1] = '\0';
787 AppId = QString(buf);
789 if (!fgets(buf, 512, filep))
791 fprintf(stderr,"Failed to read AppSecret from credentials file \"%s\"", qPrintable(CredentialsFile));
795 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
796 buf[strlen(buf)-1] = '\0';
797 AppSecret = QString(buf);
802 if (!fgets(buf, 512, filep))
804 TRACE_INFO("Failed to read ProxyHostName from credentials file \"%s\"", qPrintable(CredentialsFile));
808 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
809 buf[strlen(buf)-1] = '\0';
810 ProxyHostName = QString(buf);
811 ProxyHostName.replace(0, 14, tr(""));
814 if (!fgets(buf, 512, filep))
816 TRACE_ERROR("Failed to read Port from credentials file \"%s\"", qPrintable(CredentialsFile));
820 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
821 buf[strlen(buf)-1] = '\0';
822 PortStr = QString(buf);
823 PortStr.replace(0, 5, tr(""));
824 portnum = PortStr.toInt();
827 if (!fgets(buf, 512, filep))
829 TRACE_ERROR("Failed to read User from credentials file \"%s\"", qPrintable(CredentialsFile));
833 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
834 buf[strlen(buf)-1] = '\0';
836 User.replace(0, 5, tr(""));
839 if (!fgets(buf, 512, filep))
841 TRACE_ERROR("Failed to read Password from credentials file \"%s\"", qPrintable(CredentialsFile));
845 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
846 buf[strlen(buf)-1] = '\0';
847 Password = QString(buf);
848 Password.replace(0, 9, tr(""));
850 proxy.setType(QNetworkProxy::HttpProxy);
851 proxy.setHostName(qPrintable(ProxyHostName));
852 proxy.setPort(portnum);
853 proxy.setUser(qPrintable(User));
854 proxy.setPassword(qPrintable(Password));
855 QNetworkProxy::setApplicationProxy(proxy);
860 TRACE_INFO("Found credentials");
862 /* Then, send a HTTP request to get the token and wait for answer (synchronously): */
868 int MainApp::StartMonitoringUserInput()
870 connect(&searchBtn, SIGNAL(clicked(bool)), this, SLOT(searchBtnClicked()));
871 connect(&lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &)));
872 connect(&networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkReplySearch(QNetworkReply*)));
873 connect(&keyboard, SIGNAL(keyClicked(const QString &)), this, SLOT(textAdded(const QString &)));
874 connect(&keyboard, SIGNAL(specialKeyClicked(int)), this, SLOT(keyPressed(int)));
878 void MainApp::SetWayPoints(uint32_t myRoute)
880 /* set the destination : */
881 naviapi->broadcastStatus("stop");
882 naviapi->sendWaypoint(this->destinationLatitude, this->destinationLongitude);
885 void MainApp::goClicked()
887 TRACE_DEBUG("Go clicked !");
888 DisplayInformation(false);
889 DisplayResultList(true);
891 SetDestination(currentIndex);
894 void MainApp::cancelClicked()
896 TRACE_DEBUG("Cancel clicked !");
897 DisplayInformation(false);
898 DisplayResultList(true);
901 void MainApp::getAllSessions_reply(const std::map< uint32_t, std::string >& allSessions)
905 if (allSessions.empty())
907 TRACE_ERROR("Error: could not find an instance of Navicore");
912 this->navicoreSession = allSessions.begin()->first;
914 TRACE_INFO("Current session: %d", this->navicoreSession);
919 void MainApp::positionGot()
923 /* let's generate a search request : */
924 QString myUrlStr = URL_SEARCH + tr("?") + tr("term=") + currentSearchingText +
925 tr("&latitude=") + QString::number(currentLatitude) +
926 tr("&longitude=") + QString::number(currentLongitude);
928 TRACE_DEBUG("URL: %s", qPrintable(myUrlStr));
930 QUrl myUrl = QUrl(myUrlStr);
931 QNetworkRequest req(myUrl);
932 req.setRawHeader(QByteArray("Authorization"), (tr("bearer ") + token).toLocal8Bit());
934 /* Then, send a HTTP request to get the token and wait for answer (synchronously): */
936 pSearchReply = networkManager.get(req);