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);
84 QFile file(NAVI_CONFIG_FILEPATH);
85 if (file.open(QIODevice::ReadOnly | QIODevice::Text))
87 QByteArray data = file.readAll();
88 QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
89 QJsonObject jsonObj(jsonDoc.object());
91 if (jsonObj.contains("latitude"))
92 currentLatitude = jsonObj["latitude"].toDouble();
94 if (jsonObj.contains("longitude"))
95 currentLongitude = jsonObj["longitude"].toDouble();
98 /* We might need a Japanese font: */
99 QFile fontFile(":/fonts/DroidSansJapanese.ttf");
100 if (!fontFile.open(QIODevice::ReadOnly))
102 TRACE_ERROR("failed to open font file");
106 QByteArray fontData = fontFile.readAll();
107 fontId = QFontDatabase::addApplicationFontFromData(fontData);
110 TRACE_ERROR("QFontDatabase::addApplicationFontFromData failed");
114 /* Check if "AGL_NAVI" env variable is set. If yes, we must notify
115 * AGL environment when surface needs to be resized */
116 if (getenv("AGL_NAVI"))
119 connect(this, SIGNAL(positionGotSignal()), this, SLOT(positionGot()));
121 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
122 this->setStyleSheet("background-image: url(:/images/AGL_POI_Background.png);");
130 QFontDatabase::removeApplicationFont(fontId);
132 searchBtn.disconnect();
133 lineEdit.disconnect();
134 networkManager.disconnect();
135 keyboard.disconnect();
142 void MainApp::searchBtnClicked()
144 isInputDisplayed = !isInputDisplayed;
145 TRACE_DEBUG("isInputDisplayed = %d", isInputDisplayed);
146 DisplayLineEdit(isInputDisplayed);
149 void MainApp::DisplayLineEdit(bool display)
153 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
157 lineEdit.setVisible(true);
164 pResultList->removeEventFilter(this);
173 lineEdit.setText(tr(""));
174 lineEdit.setVisible(false);
176 isInputDisplayed = display;
181 void MainApp::UpdateAglSurfaces()
185 TRACE_DEBUG("handle AGL demo surfaces (new surface is bigger)");
186 snprintf(cmd, 1023, "/usr/bin/LayerManagerControl set surface $SURFACE_ID_CLIENT source region 0 0 %d %d",
187 this->width(), this->height());
188 TRACE_DEBUG("%s", cmd);
190 snprintf(cmd, 1023, "/usr/bin/LayerManagerControl set surface $SURFACE_ID_CLIENT destination region $CLIENT_X $CLIENT_Y %d %d",
191 this->width(), this->height());
192 TRACE_DEBUG("%s", cmd);
196 void MainApp::DisplayResultList(bool display, bool RefreshDisplay)
204 pResultList = new QTreeWidget(this);
205 pResultList->setStyleSheet("border: none; color: #FFFFFF;");
206 pResultList->setRootIsDecorated(false);
207 pResultList->setEditTriggers(QTreeWidget::NoEditTriggers);
208 pResultList->setSelectionBehavior(QTreeWidget::SelectRows);
209 pResultList->setFrameStyle(QFrame::Box | QFrame::Plain);
210 pResultList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
211 //pResultList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
212 pResultList->setAttribute(Qt::WA_AcceptTouchEvents);
213 pResultList->verticalScrollBar()->setStyleSheet(SCROLLBAR_STYLE);
214 pResultList->header()->hide();
215 //font.setPointSize(FONT_SIZE_LIST);
216 //pResultList->setFont(font);
217 pResultList->installEventFilter(this);
220 pResultList->setGeometry(QRect( LEFT_OFFSET+searchBtn.width()+SPACER, searchBtn.height()+SPACER,
221 DISPLAY_WIDTH, DISPLAY_HEIGHT));
224 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
226 pResultList->setVisible(true);
227 pResultList->setFocus();
233 pResultList->removeEventFilter(this);
234 pResultList->deleteLater();
242 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
249 void MainApp::textChanged(const QString & text)
251 TRACE_INFO("New text is: %s", qPrintable(text));
253 /* do not handle text input if info panel is displayed: */
254 if (pInfoPanel) return;
258 delete pSearchReply; /* cancel current search */
261 if (text.length() == 0) /* if empty text -> no search */
263 DisplayResultList(false);
268 /* if text is the same as previous search -> no need to search again */
269 if (text == currentSearchedText)
271 DisplayResultList(true);
272 FillResultList(Businesses, currentIndex);
276 this->currentSearchingText = text;
278 emit positionGotSignal();
283 void MainApp::textAdded(const QString & text)
286 lineEdit.setText(lineEdit.text() + text);
288 // be sure any text is visible on initial input
289 lineEdit.setVisible(true);
294 void MainApp::keyPressed(int key)
297 if (key == '\b') /* backspace */
299 int len = lineEdit.text().length();
301 lineEdit.setText(lineEdit.text().remove(len-1, 1));
306 void MainApp::itemClicked()
311 DisplayInformation(true, false);
316 DisplayLineEdit(false);
321 void MainApp::ParseJsonBusinessList(const char* buf, std::vector<Business> & Output)
323 json_object *jobj = json_tokener_parse(buf);
326 TRACE_ERROR("json_tokener_parse failed");
327 cerr << "json_tokener_parse failed: " << buf << endl;
331 json_object_object_foreach(jobj, key, val)
336 if (json_object_get_type(val) == json_type_array)
338 TRACE_DEBUG_JSON("an array was found");
340 if(json_object_object_get_ex(jobj, "businesses", &value))
342 TRACE_DEBUG_JSON("an business was found");
344 int arraylen = json_object_array_length(value);
346 for (int i = 0; i < arraylen; i++)
348 Business NewBusiness;
350 json_object* medi_array_obj, *medi_array_obj_elem;
351 medi_array_obj = json_object_array_get_idx(value, i);
354 if (json_object_object_get_ex(medi_array_obj, "rating", &medi_array_obj_elem))
356 NewBusiness.Rating = json_object_get_double(medi_array_obj_elem);
357 TRACE_DEBUG_JSON("got Rating : %f", NewBusiness.Rating);
360 if (json_object_object_get_ex(medi_array_obj, "distance", &medi_array_obj_elem))
362 NewBusiness.Distance = json_object_get_double(medi_array_obj_elem);
363 TRACE_DEBUG_JSON("got Distance : %f", NewBusiness.Distance);
366 if (json_object_object_get_ex(medi_array_obj, "review_count", &medi_array_obj_elem))
368 NewBusiness.ReviewCount = json_object_get_int(medi_array_obj_elem);
369 TRACE_DEBUG_JSON("got ReviewCount : %u", NewBusiness.ReviewCount);
372 if (json_object_object_get_ex(medi_array_obj, "name", &medi_array_obj_elem))
374 NewBusiness.Name = QString(json_object_get_string(medi_array_obj_elem));
375 TRACE_DEBUG_JSON("got Name : %s", qPrintable(NewBusiness.Name));
378 if (json_object_object_get_ex(medi_array_obj, "image_url", &medi_array_obj_elem))
380 NewBusiness.ImageUrl = QString(json_object_get_string(medi_array_obj_elem));
381 TRACE_DEBUG_JSON("got ImageUrl : %s", qPrintable(NewBusiness.ImageUrl));
384 if (json_object_object_get_ex(medi_array_obj, "phone", &medi_array_obj_elem))
386 NewBusiness.Phone = QString(json_object_get_string(medi_array_obj_elem));
387 TRACE_DEBUG_JSON("got Phone : %s", qPrintable(NewBusiness.Phone));
390 if (json_object_object_get_ex(medi_array_obj, "coordinates", &medi_array_obj_elem))
394 TRACE_DEBUG_JSON("coordinates were found");
396 if(json_object_object_get_ex(medi_array_obj_elem, "latitude", &value2))
398 NewBusiness.Latitude = json_object_get_double(value2);
399 TRACE_DEBUG_JSON("got Latitude : %f", NewBusiness.Latitude);
402 if(json_object_object_get_ex(medi_array_obj_elem, "longitude", &value2))
404 NewBusiness.Longitude = json_object_get_double(value2);
405 TRACE_DEBUG_JSON("got Longitude : %f", NewBusiness.Longitude);
409 if (json_object_object_get_ex(medi_array_obj, "location", &medi_array_obj_elem))
413 TRACE_DEBUG_JSON("a location was found");
415 /* TODO: how do we deal with address2 and address3 ? */
416 if(json_object_object_get_ex(medi_array_obj_elem, "address1", &value2))
418 NewBusiness.Address = QString(json_object_get_string(value2));
419 TRACE_DEBUG_JSON("got Address : %s", qPrintable(NewBusiness.Address));
422 if(json_object_object_get_ex(medi_array_obj_elem, "city", &value2))
424 NewBusiness.City = QString(json_object_get_string(value2));
425 TRACE_DEBUG_JSON("got City : %s", qPrintable(NewBusiness.City));
428 if(json_object_object_get_ex(medi_array_obj_elem, "state", &value2))
430 NewBusiness.State = QString(json_object_get_string(value2));
431 TRACE_DEBUG_JSON("got State : %s", qPrintable(NewBusiness.State));
434 if(json_object_object_get_ex(medi_array_obj_elem, "zip_code", &value2))
436 NewBusiness.ZipCode = QString(json_object_get_string(value2));
437 TRACE_DEBUG_JSON("got ZipCode : %s", qPrintable(NewBusiness.ZipCode));
440 if(json_object_object_get_ex(medi_array_obj_elem, "country", &value2))
442 NewBusiness.Country = QString(json_object_get_string(value2));
443 TRACE_DEBUG_JSON("got Country : %s", qPrintable(NewBusiness.Country));
447 /* TODO: parse categories */
449 /* Add business in our list: */
450 Businesses.push_back(NewBusiness);
457 json_object_put(jobj);
460 bool MainApp::eventFilter(QObject *obj, QEvent *ev)
466 if (obj == pResultList)
468 //TRACE_DEBUG("ev->type() = %d", (int)ev->type());
470 if (ev->type() == QEvent::KeyPress)
472 bool consumed = false;
473 int key = static_cast<QKeyEvent*>(ev)->key();
474 TRACE_DEBUG("key pressed (%d)", key);
478 TRACE_DEBUG("enter or return");
481 DisplayInformation(true);
486 DisplayLineEdit(false);
492 TRACE_DEBUG("escape");
493 DisplayResultList(false);
502 case Qt::Key_PageDown:
503 TRACE_DEBUG("arrows");
507 TRACE_DEBUG("default");
516 else if (obj == &lineEdit)
518 if (pInfoPanel && ev->type() == QEvent::KeyPress)
520 switch(static_cast<QKeyEvent*>(ev)->key())
523 TRACE_DEBUG("Escape !");
524 DisplayInformation(false, false);
525 DisplayResultList(true);
526 FillResultList(Businesses, currentIndex);
531 SetDestination(currentIndex);
532 DisplayLineEdit(false);
540 ret = QMainWindow::eventFilter(obj, ev);
546 void MainApp::resizeEvent(QResizeEvent* event)
548 QMainWindow::resizeEvent(event);
551 QTimer::singleShot(AGL_REFRESH_DELAY, Qt::CoarseTimer, this, SLOT(UpdateAglSurfaces()));
555 void MainApp::SetDestination(int index)
559 /* if pResultList exists, take the selected index
560 * otherwise, take the index given as parameter */
563 QList<QTreeWidgetItem *> SelectedItems = pResultList->selectedItems();
564 if (SelectedItems.size() > 0)
566 /* select the first selected item : */
567 index = pResultList->indexOfTopLevelItem(*SelectedItems.begin());
571 TRACE_DEBUG("index is: %d", index);
573 /* retrieve the coordinates of this item : */
574 this->destinationLatitude = Businesses[index].Latitude;
575 this->destinationLongitude = Businesses[index].Longitude;
582 void MainApp::DisplayInformation(bool display, bool RefreshDisplay)
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, false);
609 /* Display info for the selected item: */
610 QRect rect( LEFT_OFFSET+searchBtn.width()+SPACER, searchBtn.height()+SPACER,
611 DISPLAY_WIDTH, DISPLAY_HEIGHT);
612 pInfoPanel = new InfoPanel(this, Businesses[currentIndex], rect);
616 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
619 connect(pInfoPanel->getGoButton(), SIGNAL(clicked(bool)), this, SLOT(goClicked()));
620 connect(pInfoPanel->getCancelButton(), SIGNAL(clicked(bool)), this, SLOT(cancelClicked()));
626 pInfoPanel->getGoButton()->disconnect();
627 pInfoPanel->getCancelButton()->disconnect();
635 this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB));
642 void MainApp::networkReplySearch(QNetworkReply* reply)
648 /* memorize the text which gave this result: */
649 currentSearchedText = lineEdit.text();
651 if (reply->error() == QNetworkReply::NoError)
653 // we only handle this callback if it matches the last search request:
654 if (reply != pSearchReply)
656 TRACE_INFO("this reply is already too late (or about a different network request)");
661 buf = reply->readAll();
673 ParseJsonBusinessList(buf.data(), Businesses);
674 DisplayResultList(true);
675 FillResultList(Businesses);
679 fprintf(stderr,"POI: reply error network please check to poikey and system time (adjusted?)\n");
685 /* pResultList must be allocated at this point ! */
686 int MainApp::FillResultList(vector<Business> & list, int focusIndex)
692 pResultList->setUpdatesEnabled(false);
693 pResultList->clear();
695 /* filling the dropdown menu: */
696 for (vector<Business>::iterator it = list.begin(); it != list.end(); it++)
698 /* workaround to avoid entries with wrong coordinates returned by Yelp: */
699 if (IsCoordinatesConsistent(*it) == false)
705 QTreeWidgetItem * item = new QTreeWidgetItem(pResultList);
707 ClickableLabel *label = new ClickableLabel("<b>"+(*it).Name+
708 "</b><br>"+(*it).Address+", "+(*it).City+", "+(*it).State+
709 " "+(*it).ZipCode+", "+(*it).Country, pResultList);
710 label->setTextFormat(Qt::RichText);
711 font.setPointSize(FONT_SIZE_LIST);
712 label->setFont(font);
713 label->setIndent(MARGINS);
714 label->setAttribute(Qt::WA_AcceptTouchEvents);
715 item->setSizeHint(0, QSize(TEXT_INPUT_WIDTH, RESULT_ITEM_HEIGHT));
716 pResultList->setItemWidget(item, 0, label);
717 connect(label, SIGNAL(clicked()), this, SLOT(itemClicked()));
719 //item->setText(0, (*it).Name);
721 if (nbElem == focusIndex)
723 pResultList->setCurrentItem(item);
728 pResultList->setUpdatesEnabled(true);
734 /* Well... some of the POI returned by Yelp have coordinates which are
735 * completely inconsistent with the distance at which the POI is
737 * https://github.com/Yelp/yelp-fusion/issues/104
738 * Let's skip them for the moment: */
739 #define PI 3.14159265
740 #define EARTH_RADIUS 6371000
741 static inline double toRadians(double a) { return a * PI / 180.0; }
742 bool MainApp::IsCoordinatesConsistent(Business & business)
744 double lat1 = toRadians(currentLatitude);
745 double lon1 = toRadians(currentLongitude);
746 double lat2 = toRadians(business.Latitude);
747 double lon2 = toRadians(business.Longitude);
748 double x = (lon2 - lon1) * cos((lat1 + lat2)/2);
749 double y = lat2 - lat1;
750 double DistanceFromCoords = EARTH_RADIUS * sqrt(pow(x, 2) + pow(y, 2));
752 /* if calculated distance is not between +/- 10% of the announced
753 * distance -> skip this POI: */
754 if (DistanceFromCoords < business.Distance * 0.9 ||
755 DistanceFromCoords > business.Distance * 1.1)
757 TRACE_ERROR("Announced distance: %f, calculated distance: %f", business.Distance, DistanceFromCoords);
763 /* end of workaround */
765 int MainApp::AuthenticatePOI(const QString & CredentialsFile)
770 QString ProxyHostName;
776 /* First, read AppId and AppSecret from credentials file: */
777 FILE* filep = fopen(qPrintable(CredentialsFile), "r");
780 fprintf(stderr,"Failed to open credentials file \"%s\": %m", qPrintable(CredentialsFile));
784 if (!fgets(buf, 512, filep))
786 fprintf(stderr,"Failed to read AppId from credentials file \"%s\"", qPrintable(CredentialsFile));
790 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
791 buf[strlen(buf)-1] = '\0';
792 AppId = QString(buf);
794 if (!fgets(buf, 512, filep))
796 fprintf(stderr,"Failed to read AppSecret from credentials file \"%s\"", qPrintable(CredentialsFile));
800 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
801 buf[strlen(buf)-1] = '\0';
802 AppSecret = QString(buf);
807 if (!fgets(buf, 512, filep))
809 TRACE_INFO("Failed to read ProxyHostName from credentials file \"%s\"", qPrintable(CredentialsFile));
813 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
814 buf[strlen(buf)-1] = '\0';
815 ProxyHostName = QString(buf);
816 ProxyHostName.replace(0, 14, tr(""));
819 if (!fgets(buf, 512, filep))
821 TRACE_ERROR("Failed to read Port from credentials file \"%s\"", qPrintable(CredentialsFile));
825 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
826 buf[strlen(buf)-1] = '\0';
827 PortStr = QString(buf);
828 PortStr.replace(0, 5, tr(""));
829 portnum = PortStr.toInt();
832 if (!fgets(buf, 512, filep))
834 TRACE_ERROR("Failed to read User from credentials file \"%s\"", qPrintable(CredentialsFile));
838 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
839 buf[strlen(buf)-1] = '\0';
841 User.replace(0, 5, tr(""));
844 if (!fgets(buf, 512, filep))
846 TRACE_ERROR("Failed to read Password from credentials file \"%s\"", qPrintable(CredentialsFile));
850 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
851 buf[strlen(buf)-1] = '\0';
852 Password = QString(buf);
853 Password.replace(0, 9, tr(""));
855 proxy.setType(QNetworkProxy::HttpProxy);
856 proxy.setHostName(qPrintable(ProxyHostName));
857 proxy.setPort(portnum);
858 proxy.setUser(qPrintable(User));
859 proxy.setPassword(qPrintable(Password));
860 QNetworkProxy::setApplicationProxy(proxy);
865 TRACE_INFO("Found credentials");
867 /* Then, send a HTTP request to get the token and wait for answer (synchronously): */
873 int MainApp::StartMonitoringUserInput()
875 connect(&searchBtn, SIGNAL(clicked(bool)), this, SLOT(searchBtnClicked()));
876 connect(&lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &)));
877 connect(&networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkReplySearch(QNetworkReply*)));
878 connect(&keyboard, SIGNAL(keyClicked(const QString &)), this, SLOT(textAdded(const QString &)));
879 connect(&keyboard, SIGNAL(specialKeyClicked(int)), this, SLOT(keyPressed(int)));
883 void MainApp::SetWayPoints(uint32_t myRoute)
885 /* set the destination : */
886 naviapi->sendWaypoint(this->destinationLatitude, this->destinationLongitude);
889 currentSearchingText = tr("");
890 currentSearchedText = tr("");
895 void MainApp::goClicked()
897 TRACE_DEBUG("Go clicked !");
898 SetDestination(currentIndex);
899 DisplayLineEdit(false);
902 void MainApp::cancelClicked()
904 TRACE_DEBUG("Cancel clicked !");
905 DisplayInformation(false, false);
906 DisplayResultList(true, false);
907 FillResultList(Businesses, currentIndex);
910 void MainApp::getAllSessions_reply(const std::map< uint32_t, std::string >& allSessions)
914 if (allSessions.empty())
916 TRACE_ERROR("Error: could not find an instance of Navicore");
921 this->navicoreSession = allSessions.begin()->first;
923 TRACE_INFO("Current session: %d", this->navicoreSession);
928 void MainApp::positionGot()
932 /* let's generate a search request : */
933 QString myUrlStr = URL_SEARCH + tr("?") + tr("term=") + currentSearchingText +
934 tr("&latitude=") + QString::number(currentLatitude) +
935 tr("&longitude=") + QString::number(currentLongitude);
937 TRACE_DEBUG("URL: %s", qPrintable(myUrlStr));
939 QUrl myUrl = QUrl(myUrlStr);
940 QNetworkRequest req(myUrl);
941 req.setRawHeader(QByteArray("Authorization"), (tr("bearer ") + token).toLocal8Bit());
943 /* Then, send a HTTP request to get the token and wait for answer (synchronously): */
945 pSearchReply = networkManager.get(req);