2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Henri Lampela - henri.lampela@ixonos.com
6 Kaj Wallin - kaj.wallin@ixonos.com
7 Jussi Laitinen - jussi.laitinen@ixonos.com
8 Sami Rämö - sami.ramo@ixonos.com
9 Ville Tiensuu - ville.tiensuu@ixonos.com
10 Katri Kaikkonen - katri.kaikkonen@ixonos.com
12 Situare is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 version 2 as published by the Free Software Foundation.
16 Situare is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with Situare; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 #include <QApplication>
30 #include <QMessageBox>
31 #include <QtAlgorithms>
35 #include "facebookservice/facebookauthentication.h"
36 #include "map/mapcommon.h"
37 #include "map/mapview.h"
40 #include "friendlistpanel.h"
41 #include "fullscreenbutton.h"
42 #include "indicatorbuttonpanel.h"
43 #include "locationsearchpanel.h"
44 #include "logindialog.h"
46 #include "panelcommon.h"
47 #include "routingpanel.h"
48 #include "tabbedpanel.h"
49 #include "searchdialog.h"
50 #include "settingsdialog.h"
51 #include "userinfopanel.h"
52 #include "zoombuttonpanel.h"
54 #include "mainwindow.h"
56 // These MUST BE HERE, compiling for Maemo fails if moved
58 #include <QtMaemo5/QMaemo5InformationBox>
59 #include <QtGui/QX11Info>
60 #include <X11/Xatom.h>
62 #endif // Q_WS_MAEMO_5
64 MainWindow::MainWindow(QWidget *parent)
65 : QMainWindow(parent),
69 m_mapCenterHorizontalShifting(0),
70 m_progressIndicatorCount(0),
72 m_email(), ///< @todo WTF?!?!?!?
75 m_fullScreenButton(0),
76 m_indicatorButtonPanel(0),
80 qDebug() << __PRETTY_FUNCTION__;
84 // map view is the only widget which size & location is handled automatically by the system
85 // default functionality
86 setCentralWidget(m_mapView);
91 setWindowTitle(tr("Situare"));
93 // set stacking order of widgets (from top to bottom)
94 // m_tabbedPanel is the topmost one
95 if (m_fullScreenButton) {
96 m_fullScreenButton->stackUnder(m_tabbedPanel);
97 m_crosshair->stackUnder(m_fullScreenButton);
99 m_crosshair->stackUnder(m_tabbedPanel);
101 m_zoomButtonPanel->stackUnder(m_crosshair);
102 m_indicatorButtonPanel->stackUnder(m_zoomButtonPanel);
103 m_osmLicense->stackUnder(m_indicatorButtonPanel);
104 m_mapScale->stackUnder(m_osmLicense);
105 m_mapView->stackUnder(m_mapScale);
109 // Set default screen size
110 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
112 setAttribute(Qt::WA_Maemo5StackedWindow);
116 MainWindow::~MainWindow()
118 qDebug() << __PRETTY_FUNCTION__;
125 qDeleteAll(m_queue.begin(), m_queue.end());
128 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
129 m_error_queue.clear();
132 void MainWindow::automaticUpdateDialogFinished(int result)
134 qDebug() << __PRETTY_FUNCTION__;
136 if (result == QMessageBox::Yes) {
137 readAutomaticLocationUpdateSettings();
139 QSettings settings(DIRECTORY_NAME, FILE_NAME);
140 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
141 readAutomaticLocationUpdateSettings();
144 m_automaticUpdateLocationDialog->deleteLater();
147 void MainWindow::buildCrosshair()
149 qDebug() << __PRETTY_FUNCTION__;
151 m_crosshair = new QLabel(this);
152 QPixmap crosshairImage(":/res/images/sight.png");
153 m_crosshair->setPixmap(crosshairImage);
154 m_crosshair->setFixedSize(crosshairImage.size());
156 m_crosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
158 connect(m_mapView, SIGNAL(viewResized(QSize)),
159 this, SLOT(moveCrosshair()));
161 connect(m_mapView, SIGNAL(horizontalShiftingChanged(int)),
162 this, SLOT(mapCenterHorizontalShiftingChanged(int)));
165 void MainWindow::buildFriendListPanel()
167 qDebug() << __PRETTY_FUNCTION__;
169 m_friendsListPanel = new FriendListPanel(this);
171 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
172 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
174 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
175 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
177 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
178 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
180 connect(this, SIGNAL(friendImageReady(User*)),
181 m_friendsListPanel, SLOT(friendImageReady(User*)));
183 connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
184 this, SIGNAL(routeTo(const GeoCoordinate&)));
187 void MainWindow::buildFullScreenButton()
189 qDebug() << __PRETTY_FUNCTION__;
192 m_fullScreenButton = new FullScreenButton(this);
194 if (m_fullScreenButton) {
195 connect(m_fullScreenButton, SIGNAL(clicked()),
196 this, SLOT(toggleFullScreen()));
198 connect(qApp, SIGNAL(showFullScreenButton()),
199 m_fullScreenButton, SLOT(invoke()));
201 #endif // Q_WS_MAEMO_5
204 void MainWindow::buildIndicatorButtonPanel()
206 qDebug() << __PRETTY_FUNCTION__;
208 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
210 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
211 this, SIGNAL(autoCenteringTriggered(bool)));
213 connect(m_mapView, SIGNAL(viewResized(QSize)),
214 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
216 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
217 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
219 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
220 this, SIGNAL(draggingModeTriggered()));
223 void MainWindow::buildInformationBox(const QString &message, bool modal)
225 qDebug() << __PRETTY_FUNCTION__;
227 QString errorMessage = message;
231 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
234 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
235 // extra line changes are needed to make error notes broader
236 errorMessage.prepend("\n");
237 errorMessage.append("\n");
239 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
241 QLabel *label = new QLabel(msgBox);
242 label->setAlignment(Qt::AlignCenter);
243 label->setText(errorMessage);
244 msgBox->setWidget(label);
246 QMessageBox *msgBox = new QMessageBox(this);
247 msgBox->button(QMessageBox::Ok);
248 msgBox->setText(errorMessage);
249 msgBox->setModal(modal);
255 void MainWindow::buildLocationSearchPanel()
257 qDebug() << __PRETTY_FUNCTION__;
259 m_locationSearchPanel = new LocationSearchPanel(this);
261 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
262 m_locationSearchPanel, SLOT(populateLocationListView(const QList<Location>&)));
264 connect(m_locationSearchPanel, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
265 this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
267 connect(m_locationSearchPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
268 this, SIGNAL(routeTo(const GeoCoordinate&)));
270 connect(m_locationSearchPanel, SIGNAL(requestSearchLocation()),
271 this, SLOT(startLocationSearch()));
274 void MainWindow::buildMap()
276 qDebug() << __PRETTY_FUNCTION__;
278 m_mapView = new MapView(this);
280 buildZoomButtonPanel();
283 buildFullScreenButton();
284 buildIndicatorButtonPanel();
287 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
288 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
290 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
291 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
293 connect(m_mapView, SIGNAL(viewResized(QSize)),
294 this, SIGNAL(mapViewResized(QSize)));
296 connect(m_mapView, SIGNAL(viewResized(QSize)),
297 this, SLOT(drawFullScreenButton(QSize)));
299 connect(m_mapView, SIGNAL(viewResized(QSize)),
300 this, SLOT(drawMapScale(QSize)));
302 connect(m_mapView, SIGNAL(viewResized(QSize)),
303 this, SLOT(moveCrosshair()));
305 connect(this, SIGNAL(zoomLevelChanged(int)),
306 m_mapView, SLOT(setZoomLevel(int)));
308 connect(m_mapView, SIGNAL(viewZoomFinished()),
309 this, SIGNAL(viewZoomFinished()));
311 connect(m_mapView, SIGNAL(zoomIn()),
312 this, SIGNAL(zoomIn()));
315 void MainWindow::buildMapScale()
317 m_mapScale = new MapScale(this);
318 connect(this, SIGNAL(newMapResolution(qreal)),
319 m_mapScale, SLOT(updateMapResolution(qreal)));
322 void MainWindow::buildOsmLicense()
324 qDebug() << __PRETTY_FUNCTION__;
326 m_osmLicense = new QLabel(this);
327 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
328 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
329 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
330 m_osmLicense->setFont(QFont("Nokia Sans", 9));
331 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
332 m_osmLicense->fontMetrics().height());
334 connect(m_mapView, SIGNAL(viewResized(QSize)),
335 this, SLOT(drawOsmLicense(QSize)));
338 void MainWindow::buildPanels()
340 qDebug() << __PRETTY_FUNCTION__;
342 buildUserInfoPanel();
343 buildFriendListPanel();
344 buildLocationSearchPanel();
347 m_tabbedPanel = new TabbedPanel(this);
349 //Save Situare related tab indexes so tabs can be enabled/disabled when logged in/out
350 m_situareTabsIndexes.append(
351 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png")));
352 m_situareTabsIndexes.append(
353 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png")));
355 m_tabbedPanel->addTab(m_locationSearchPanel, QIcon(":/res/images/location_search.png"));
356 m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
358 connect(m_mapView, SIGNAL(viewResized(QSize)),
359 m_tabbedPanel, SLOT(resizePanel(QSize)));
361 connect(m_friendsListPanel, SIGNAL(openPanelRequested(QWidget*)),
362 m_tabbedPanel, SLOT(openPanel(QWidget*)));
364 connect(m_routingPanel, SIGNAL(openPanelRequested(QWidget*)),
365 m_tabbedPanel, SLOT(openPanel(QWidget*)));
367 connect(m_tabbedPanel, SIGNAL(panelClosed()),
368 m_friendsListPanel, SLOT(anyPanelClosed()));
370 connect(m_tabbedPanel, SIGNAL(panelOpened()),
371 m_friendsListPanel, SLOT(anyPanelOpened()));
373 connect(m_tabbedPanel, SIGNAL(panelClosed()),
374 m_routingPanel, SLOT(clearListsSelections()));
376 connect(m_tabbedPanel, SIGNAL(panelClosed()),
377 m_mapView, SLOT(disableCenterShift()));
379 connect(m_tabbedPanel, SIGNAL(panelOpened()),
380 m_mapView, SLOT(enableCenterShift()));
382 connect(m_tabbedPanel, SIGNAL(panelClosed()),
383 m_userInfoPanel, SIGNAL(collapse()));
385 connect(m_tabbedPanel, SIGNAL(currentChanged(int)),
386 m_userInfoPanel, SIGNAL(collapse()));
389 void MainWindow::buildRoutingPanel()
391 qDebug() << __PRETTY_FUNCTION__;
393 m_routingPanel = new RoutingPanel(this);
395 connect(m_routingPanel, SIGNAL(routeToCursor()),
396 this, SIGNAL(routeToCursor()));
398 connect(this, SIGNAL(routeParsed(Route&)),
399 m_routingPanel, SLOT(setRoute(Route&)));
401 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
402 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
404 connect(m_routingPanel, SIGNAL(clearRoute()),
405 this, SIGNAL(clearRoute()));
408 void MainWindow::buildUserInfoPanel()
410 qDebug() << __PRETTY_FUNCTION__;
412 m_userInfoPanel = new UserInfoPanel(this);
414 connect(this, SIGNAL(userLocationReady(User*)),
415 m_userInfoPanel, SLOT(userDataReceived(User*)));
417 connect(this, SIGNAL(reverseGeoReady(QString)),
418 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
420 connect(this, SIGNAL(clearUpdateLocationDialogData()),
421 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
423 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
424 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
426 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
427 this, SIGNAL(requestReverseGeo()));
429 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
430 this, SIGNAL(statusUpdate(QString,bool)));
432 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
433 this, SIGNAL(refreshUserData()));
435 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
436 this, SLOT(buildInformationBox(QString, bool)));
439 void MainWindow::buildWebView()
441 qDebug() << __PRETTY_FUNCTION__;
444 m_webView = new QWebView;
447 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
449 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
451 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
452 this, SLOT(webViewRequestFinished(QNetworkReply*)));
453 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
454 this, SIGNAL(updateCredentials(QUrl)));
455 connect(m_webView, SIGNAL(loadFinished(bool)),
456 this, SLOT(loadDone(bool)));
462 void MainWindow::buildZoomButtonPanel()
464 qDebug() << __PRETTY_FUNCTION__;
466 m_zoomButtonPanel = new ZoomButtonPanel(this);
468 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
469 this, SIGNAL(zoomIn()));
471 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
472 this, SIGNAL(zoomOut()));
474 connect(this, SIGNAL(zoomLevelChanged(int)),
475 m_zoomButtonPanel, SLOT(resetButtons()));
477 connect(this, SIGNAL(maxZoomLevelReached()),
478 m_zoomButtonPanel, SLOT(disableZoomInButton()));
480 connect(this, SIGNAL(minZoomLevelReached()),
481 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
483 connect(m_mapView, SIGNAL(viewResized(QSize)),
484 m_zoomButtonPanel, SLOT(screenResized(QSize)));
486 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
487 this, SIGNAL(draggingModeTriggered()));
490 void MainWindow::clearCookieJar()
492 qDebug() << __PRETTY_FUNCTION__;
499 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
501 QList<QNetworkCookie> emptyList;
504 m_cookieJar->setAllCookies(emptyList);
505 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
508 void MainWindow::createMenus()
510 qDebug() << __PRETTY_FUNCTION__;
513 m_loginAct = new QAction(tr("Login"), this);
514 connect(m_loginAct, SIGNAL(triggered()),
515 this, SIGNAL(loginActionPressed()));
518 m_toSettingsAct = new QAction(tr("Settings"), this);
519 connect(m_toSettingsAct, SIGNAL(triggered()),
520 this, SLOT(openSettingsDialog()));
523 m_gpsToggleAct = new QAction(tr("GPS"), this);
524 m_gpsToggleAct->setCheckable(true);
526 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
527 this, SIGNAL(gpsTriggered(bool)));
529 // build the actual menu
530 m_viewMenu = menuBar()->addMenu(tr("Main"));
531 m_viewMenu->addAction(m_loginAct);
532 m_viewMenu->addAction(m_toSettingsAct);
533 m_viewMenu->addAction(m_gpsToggleAct);
534 m_viewMenu->setObjectName(tr("Menu"));
537 void MainWindow::dialogFinished(int status)
539 qDebug() << __PRETTY_FUNCTION__;
541 QDialog *dialog = m_queue.takeFirst();
542 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
543 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
547 loginDialog->userInput(m_email, m_password);
549 QStringList urlParts;
550 urlParts.append(FACEBOOK_LOGINBASE);
551 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
552 urlParts.append(INTERVAL1);
553 urlParts.append(SITUARE_LOGIN_SUCCESS);
554 urlParts.append(INTERVAL2);
555 urlParts.append(SITUARE_LOGIN_FAILURE);
556 urlParts.append(FACEBOOK_LOGIN_ENDING);
558 emit saveUsername(m_email);
560 m_webView->load(QUrl(urlParts.join(EMPTY)));
561 toggleProgressIndicator(true);
563 emit cancelLoginProcess();
565 } else if(searchDialog) {
567 emit searchForLocation(searchDialog->input());
571 dialog->deleteLater();
573 if(!m_error_queue.isEmpty() && m_errorShown == false) {
574 showErrorInformationBox();
576 if(!m_queue.isEmpty()) {
577 showInformationBox();
582 void MainWindow::drawFullScreenButton(const QSize &size)
584 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
586 if (m_fullScreenButton) {
587 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
588 size.height() - m_fullScreenButton->size().height());
592 void MainWindow::drawMapScale(const QSize &size)
594 qDebug() << __PRETTY_FUNCTION__;
596 const int LEFT_SCALE_MARGIN = 10;
597 const int BOTTOM_SCALE_MARGIN = 2;
599 m_mapScale->move(LEFT_SCALE_MARGIN,
600 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
603 void MainWindow::drawOsmLicense(const QSize &size)
605 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
607 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
609 size.height() - m_osmLicense->fontMetrics().height());
612 void MainWindow::errorDialogFinished(int status)
614 qDebug() << __PRETTY_FUNCTION__;
617 QDialog *dialog = m_error_queue.takeFirst();
619 dialog->deleteLater();
620 m_errorShown = false;
622 if(!m_error_queue.isEmpty())
623 showErrorInformationBox();
624 else if(!m_queue.isEmpty())
625 showInformationBox();
628 void MainWindow::gpsTimeout()
630 qDebug() << __PRETTY_FUNCTION__;
632 buildInformationBox(tr("GPS timeout"));
635 void MainWindow::grabZoomKeys(bool grab)
637 qDebug() << __PRETTY_FUNCTION__;
640 // Can't grab keys unless we have a window id
644 unsigned long val = (grab) ? 1 : 0;
645 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
649 XChangeProperty (QX11Info::display(),
655 reinterpret_cast<unsigned char *>(&val),
659 #endif // Q_WS_MAEMO_5
662 void MainWindow::keyPressEvent(QKeyEvent* event)
664 qDebug() << __PRETTY_FUNCTION__;
666 switch (event->key()) {
677 QWidget::keyPressEvent(event);
680 void MainWindow::loadCookies()
682 qDebug() << __PRETTY_FUNCTION__;
684 QSettings settings(DIRECTORY_NAME, FILE_NAME);
686 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
688 if(!list.isEmpty()) {
689 QList<QNetworkCookie> cookieList;
690 for(int i=0;i<list.count();i++) {
691 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
695 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
697 m_cookieJar->setAllCookies(cookieList);
698 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
702 void MainWindow::loadDone(bool done)
704 qDebug() << __PRETTY_FUNCTION__;
706 // for the first time the login page is opened, we need to refresh it to get cookies working
714 QWebFrame* frame = m_webView->page()->currentFrame();
718 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
720 foreach (QWebElement element, emailCollection) {
721 element.setAttribute("value", m_email.toAscii());
724 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
725 foreach (QWebElement element, passwordCollection) {
726 element.setAttribute("value", m_password.toAscii());
728 // find connect button
729 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
730 foreach (QWebElement element, buttonCollection)
732 QPoint pos(element.geometry().center());
734 // send a mouse click event to the web page
735 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
737 QApplication::sendEvent(m_webView->page(), &event0);
738 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
740 QApplication::sendEvent(m_webView->page(), &event1);
746 void MainWindow::loggedIn(bool logged)
748 qDebug() << __PRETTY_FUNCTION__;
753 m_loginAct->setText(tr("Logout"));
759 m_loginAct->setText(tr("Login"));
761 updateItemVisibility();
764 void MainWindow::loginFailed()
766 qDebug() << __PRETTY_FUNCTION__;
772 bool MainWindow::loginState()
774 qDebug() << __PRETTY_FUNCTION__;
779 void MainWindow::loginUsingCookies()
781 qDebug() << __PRETTY_FUNCTION__;
783 toggleProgressIndicator(true);
788 QStringList urlParts;
789 urlParts.append(FACEBOOK_LOGINBASE);
790 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
791 urlParts.append(INTERVAL1);
792 urlParts.append(SITUARE_LOGIN_SUCCESS);
793 urlParts.append(INTERVAL2);
794 urlParts.append(SITUARE_LOGIN_FAILURE);
795 urlParts.append(FACEBOOK_LOGIN_ENDING);
797 m_webView->load(QUrl(urlParts.join(EMPTY)));
801 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
803 m_mapCenterHorizontalShifting = shifting;
807 void MainWindow::moveCrosshair()
809 qDebug() << __PRETTY_FUNCTION__;
812 int mapHeight = m_mapView->size().height();
813 int mapWidth = m_mapView->size().width();
814 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
815 - m_mapCenterHorizontalShifting,
816 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
820 void MainWindow::openSettingsDialog()
822 qDebug() << __PRETTY_FUNCTION__;
824 SettingsDialog *settingsDialog = new SettingsDialog(this);
825 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
826 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
828 settingsDialog->show();
831 void MainWindow::queueDialog(QDialog *dialog)
833 qDebug() << __PRETTY_FUNCTION__;
835 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
836 if(dialog->isModal()) {
837 m_error_queue.append(dialog);
839 m_queue.append(dialog);
842 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
843 if(m_error_queue.count() == 1 && m_errorShown == false)
844 showErrorInformationBox();
845 else if(m_queue.count() == 1 && m_errorShown == false)
846 showInformationBox();
849 void MainWindow::readAutomaticLocationUpdateSettings()
851 qDebug() << __PRETTY_FUNCTION__;
853 QSettings settings(DIRECTORY_NAME, FILE_NAME);
854 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
855 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
858 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
860 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
862 emit enableAutomaticLocationUpdate(false);
866 void MainWindow::saveCookies()
868 qDebug() << __PRETTY_FUNCTION__;
871 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
873 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
876 for(int i=0;i<cookieList.count();i++) {
877 QNetworkCookie cookie = cookieList.at(i);
878 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
879 list.append(QString(byteArray));
881 list.removeDuplicates();
883 QSettings settings(DIRECTORY_NAME, FILE_NAME);
884 settings.setValue(COOKIES, list);
887 void MainWindow::setCrosshairVisibility(bool visibility)
889 qDebug() << __PRETTY_FUNCTION__;
899 void MainWindow::setGPSButtonEnabled(bool enabled)
901 qDebug() << __PRETTY_FUNCTION__;
903 m_gpsToggleAct->setChecked(enabled);
906 void MainWindow::setIndicatorButtonEnabled(bool enabled)
908 qDebug() << __PRETTY_FUNCTION__;
910 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
913 void MainWindow::setMapViewScene(QGraphicsScene *scene)
915 qDebug() << __PRETTY_FUNCTION__;
917 m_mapView->setScene(scene);
920 void MainWindow::settingsDialogAccepted()
922 qDebug() << __PRETTY_FUNCTION__;
924 readAutomaticLocationUpdateSettings();
927 void MainWindow::setUsername(const QString &username)
929 qDebug() << __PRETTY_FUNCTION__;
934 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
936 qDebug() << __PRETTY_FUNCTION__;
938 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
939 tr("Automatic location update"), text,
940 QMessageBox::Yes | QMessageBox::No |
941 QMessageBox::Cancel, this);
942 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
943 this, SLOT(automaticUpdateDialogFinished(int)));
945 m_automaticUpdateLocationDialog->show();
948 void MainWindow::showErrorInformationBox()
950 qDebug() << __PRETTY_FUNCTION__;
952 if(m_error_queue.count()) {
954 QDialog *dialog = m_error_queue.first();
955 connect(dialog, SIGNAL(finished(int)),
956 this, SLOT(errorDialogFinished(int)));
961 void MainWindow::showInformationBox()
963 qDebug() << __PRETTY_FUNCTION__;
965 if(m_queue.count()) {
966 QDialog *dialog = m_queue.first();
967 connect(dialog, SIGNAL(finished(int)),
968 this, SLOT(dialogFinished(int)));
973 void MainWindow::startLocationSearch()
975 qDebug() << __PRETTY_FUNCTION__;
977 SearchDialog *searchDialog = new SearchDialog();
978 queueDialog(searchDialog);
981 void MainWindow::startLoginProcess()
983 qDebug() << __PRETTY_FUNCTION__;
985 LoginDialog *loginDialog = new LoginDialog();
987 emit fetchUsernameFromSettings();
989 loginDialog->clearTextFields();
991 if(!m_email.isEmpty())
992 loginDialog->setEmailField(m_email);
994 queueDialog(loginDialog);
997 void MainWindow::toggleFullScreen()
999 qDebug() << __PRETTY_FUNCTION__;
1001 if(windowState() == Qt::WindowNoState)
1007 void MainWindow::toggleProgressIndicator(bool value)
1009 qDebug() << __PRETTY_FUNCTION__;
1013 m_progressIndicatorCount++;
1014 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1016 if(m_progressIndicatorCount > 0)
1017 m_progressIndicatorCount--;
1019 if(m_progressIndicatorCount == 0)
1020 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1024 #endif // Q_WS_MAEMO_5
1027 void MainWindow::updateItemVisibility()
1029 qDebug() << __PRETTY_FUNCTION__;
1031 m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, m_loggedIn);
1034 const QString MainWindow::username()
1036 qDebug() << __PRETTY_FUNCTION__;
1041 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1043 qDebug() << __PRETTY_FUNCTION__;
1045 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1046 // qwebview starts to load a new page while the current page loading is not finished
1047 if(reply->error() != QNetworkReply::OperationCanceledError &&
1048 reply->error() != QNetworkReply::NoError) {
1049 emit error(ErrorContext::NETWORK, reply->error());