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 "logindialog.h"
45 #include "panelcommon.h"
46 #include "routingpanel.h"
47 #include "tabbedpanel.h"
48 #include "searchdialog.h"
49 #include "settingsdialog.h"
50 #include "userinfopanel.h"
51 #include "zoombuttonpanel.h"
53 #include "mainwindow.h"
55 // These MUST BE HERE, compiling for Maemo fails if moved
57 #include <QtMaemo5/QMaemo5InformationBox>
58 #include <QtGui/QX11Info>
59 #include <X11/Xatom.h>
61 #endif // Q_WS_MAEMO_5
63 MainWindow::MainWindow(QWidget *parent)
64 : QMainWindow(parent),
68 m_mapCenterHorizontalShifting(0),
69 m_progressIndicatorCount(0),
71 m_email(), ///< @todo WTF?!?!?!?
74 m_fullScreenButton(0),
75 m_indicatorButtonPanel(0),
79 qDebug() << __PRETTY_FUNCTION__;
83 // map view is the only widget which size & location is handled automatically by the system
84 // default functionality
85 setCentralWidget(m_mapView);
90 setWindowTitle(tr("Situare"));
92 // set stacking order of widgets (from top to bottom)
93 // m_tabbedPanel is the topmost one
94 if (m_fullScreenButton) {
95 m_fullScreenButton->stackUnder(m_tabbedPanel);
96 m_crosshair->stackUnder(m_fullScreenButton);
98 m_crosshair->stackUnder(m_tabbedPanel);
100 m_zoomButtonPanel->stackUnder(m_crosshair);
101 m_indicatorButtonPanel->stackUnder(m_zoomButtonPanel);
102 m_osmLicense->stackUnder(m_indicatorButtonPanel);
103 m_mapScale->stackUnder(m_osmLicense);
104 m_mapView->stackUnder(m_mapScale);
108 // Set default screen size
109 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
111 setAttribute(Qt::WA_Maemo5StackedWindow);
115 MainWindow::~MainWindow()
117 qDebug() << __PRETTY_FUNCTION__;
124 qDeleteAll(m_queue.begin(), m_queue.end());
127 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
128 m_error_queue.clear();
131 void MainWindow::automaticUpdateDialogFinished(int result)
133 qDebug() << __PRETTY_FUNCTION__;
135 if (result == QMessageBox::Yes) {
136 readAutomaticLocationUpdateSettings();
138 QSettings settings(DIRECTORY_NAME, FILE_NAME);
139 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
140 readAutomaticLocationUpdateSettings();
143 m_automaticUpdateLocationDialog->deleteLater();
146 void MainWindow::buildCrosshair()
148 qDebug() << __PRETTY_FUNCTION__;
150 m_crosshair = new QLabel(this);
151 QPixmap crosshairImage(":/res/images/sight.png");
152 m_crosshair->setPixmap(crosshairImage);
153 m_crosshair->setFixedSize(crosshairImage.size());
155 m_crosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
157 connect(m_mapView, SIGNAL(viewResized(QSize)),
158 this, SLOT(moveCrosshair()));
160 connect(m_mapView, SIGNAL(horizontalShiftingChanged(int)),
161 this, SLOT(mapCenterHorizontalShiftingChanged(int)));
164 void MainWindow::buildFriendListPanel()
166 qDebug() << __PRETTY_FUNCTION__;
168 m_friendsListPanel = new FriendListPanel(this);
170 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
171 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
173 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
174 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
176 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
177 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
179 connect(this, SIGNAL(friendImageReady(User*)),
180 m_friendsListPanel, SLOT(friendImageReady(User*)));
182 connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
183 this, SIGNAL(routeTo(const GeoCoordinate&)));
186 void MainWindow::buildFullScreenButton()
188 qDebug() << __PRETTY_FUNCTION__;
191 m_fullScreenButton = new FullScreenButton(this);
193 if (m_fullScreenButton) {
194 connect(m_fullScreenButton, SIGNAL(clicked()),
195 this, SLOT(toggleFullScreen()));
197 connect(qApp, SIGNAL(showFullScreenButton()),
198 m_fullScreenButton, SLOT(invoke()));
200 #endif // Q_WS_MAEMO_5
203 void MainWindow::buildIndicatorButtonPanel()
205 qDebug() << __PRETTY_FUNCTION__;
207 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
209 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
210 this, SIGNAL(autoCenteringTriggered(bool)));
212 connect(m_mapView, SIGNAL(viewResized(QSize)),
213 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
215 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
216 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
218 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
219 this, SIGNAL(draggingModeTriggered()));
222 void MainWindow::buildInformationBox(const QString &message, bool modal)
224 qDebug() << __PRETTY_FUNCTION__;
226 QString errorMessage = message;
230 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
233 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
234 // extra line changes are needed to make error notes broader
235 errorMessage.prepend("\n");
236 errorMessage.append("\n");
238 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
240 QLabel *label = new QLabel(msgBox);
241 label->setAlignment(Qt::AlignCenter);
242 label->setText(errorMessage);
243 msgBox->setWidget(label);
245 QMessageBox *msgBox = new QMessageBox(this);
246 msgBox->button(QMessageBox::Ok);
247 msgBox->setText(errorMessage);
248 msgBox->setModal(modal);
254 void MainWindow::buildMap()
256 qDebug() << __PRETTY_FUNCTION__;
258 m_mapView = new MapView(this);
260 buildZoomButtonPanel();
263 buildFullScreenButton();
264 buildIndicatorButtonPanel();
267 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
268 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
270 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
271 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
273 connect(m_mapView, SIGNAL(viewResized(QSize)),
274 this, SIGNAL(mapViewResized(QSize)));
276 connect(m_mapView, SIGNAL(viewResized(QSize)),
277 this, SLOT(drawFullScreenButton(QSize)));
279 connect(m_mapView, SIGNAL(viewResized(QSize)),
280 this, SLOT(drawMapScale(QSize)));
282 connect(m_mapView, SIGNAL(viewResized(QSize)),
283 this, SLOT(moveCrosshair()));
285 connect(this, SIGNAL(zoomLevelChanged(int)),
286 m_mapView, SLOT(setZoomLevel(int)));
288 connect(m_mapView, SIGNAL(viewZoomFinished()),
289 this, SIGNAL(viewZoomFinished()));
291 connect(m_mapView, SIGNAL(zoomIn()),
292 this, SIGNAL(zoomIn()));
295 void MainWindow::buildMapScale()
297 m_mapScale = new MapScale(this);
298 connect(this, SIGNAL(newMapResolution(qreal)),
299 m_mapScale, SLOT(updateMapResolution(qreal)));
302 void MainWindow::buildOsmLicense()
304 qDebug() << __PRETTY_FUNCTION__;
306 m_osmLicense = new QLabel(this);
307 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
308 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
309 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
310 m_osmLicense->setFont(QFont("Nokia Sans", 9));
311 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
312 m_osmLicense->fontMetrics().height());
314 connect(m_mapView, SIGNAL(viewResized(QSize)),
315 this, SLOT(drawOsmLicense(QSize)));
318 void MainWindow::buildPanels()
320 qDebug() << __PRETTY_FUNCTION__;
322 buildUserInfoPanel();
323 buildFriendListPanel();
326 m_tabbedPanel = new TabbedPanel(this);
327 m_situareTabsIndexes.append(
328 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png")));
329 m_situareTabsIndexes.append(
330 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png")));
331 m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
333 connect(m_mapView, SIGNAL(viewResized(QSize)),
334 m_tabbedPanel, SLOT(resizePanel(QSize)));
336 connect(m_friendsListPanel, SIGNAL(openPanelRequested(QWidget*)),
337 m_tabbedPanel, SLOT(openPanel(QWidget*)));
339 connect(m_routingPanel, SIGNAL(openPanelRequested(QWidget*)),
340 m_tabbedPanel, SLOT(openPanel(QWidget*)));
342 connect(m_tabbedPanel, SIGNAL(panelClosed()),
343 m_friendsListPanel, SLOT(anyPanelClosed()));
345 connect(m_tabbedPanel, SIGNAL(panelOpened()),
346 m_friendsListPanel, SLOT(anyPanelOpened()));
348 connect(m_tabbedPanel, SIGNAL(panelClosed()),
349 m_routingPanel, SLOT(clearListsSelections()));
351 connect(m_tabbedPanel, SIGNAL(panelClosed()),
352 m_mapView, SLOT(disableCenterShift()));
354 connect(m_tabbedPanel, SIGNAL(panelOpened()),
355 m_mapView, SLOT(enableCenterShift()));
357 connect(m_tabbedPanel, SIGNAL(panelClosed()),
358 m_userInfoPanel, SIGNAL(collapse()));
360 connect(m_tabbedPanel, SIGNAL(currentChanged(int)),
361 m_userInfoPanel, SIGNAL(collapse()));
364 void MainWindow::buildRoutingPanel()
366 qDebug() << __PRETTY_FUNCTION__;
368 m_routingPanel = new RoutingPanel(this);
370 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
371 m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
373 connect(m_routingPanel, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
374 this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
376 connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
377 this, SIGNAL(routeTo(const GeoCoordinate&)));
379 connect(this, SIGNAL(routeParsed(Route&)),
380 m_routingPanel, SLOT(setRoute(Route&)));
382 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
383 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
385 connect(m_routingPanel, SIGNAL(requestSearchLocation()),
386 this, SLOT(startLocationSearch()));
388 connect(m_routingPanel, SIGNAL(clearRoute()),
389 this, SIGNAL(clearRoute()));
392 void MainWindow::buildUserInfoPanel()
394 qDebug() << __PRETTY_FUNCTION__;
396 m_userInfoPanel = new UserInfoPanel(this);
398 connect(this, SIGNAL(userLocationReady(User*)),
399 m_userInfoPanel, SLOT(userDataReceived(User*)));
401 connect(this, SIGNAL(reverseGeoReady(QString)),
402 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
404 connect(this, SIGNAL(clearUpdateLocationDialogData()),
405 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
407 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
408 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
410 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
411 this, SIGNAL(requestReverseGeo()));
413 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
414 this, SIGNAL(statusUpdate(QString,bool)));
416 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
417 this, SIGNAL(refreshUserData()));
419 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
420 this, SLOT(buildInformationBox(QString, bool)));
423 void MainWindow::buildWebView()
425 qDebug() << __PRETTY_FUNCTION__;
428 m_webView = new QWebView;
431 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
433 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
435 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
436 this, SLOT(webViewRequestFinished(QNetworkReply*)));
437 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
438 this, SIGNAL(updateCredentials(QUrl)));
439 connect(m_webView, SIGNAL(loadFinished(bool)),
440 this, SLOT(loadDone(bool)));
446 void MainWindow::buildZoomButtonPanel()
448 qDebug() << __PRETTY_FUNCTION__;
450 m_zoomButtonPanel = new ZoomButtonPanel(this);
452 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
453 this, SIGNAL(zoomIn()));
455 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
456 this, SIGNAL(zoomOut()));
458 connect(this, SIGNAL(zoomLevelChanged(int)),
459 m_zoomButtonPanel, SLOT(resetButtons()));
461 connect(this, SIGNAL(maxZoomLevelReached()),
462 m_zoomButtonPanel, SLOT(disableZoomInButton()));
464 connect(this, SIGNAL(minZoomLevelReached()),
465 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
467 connect(m_mapView, SIGNAL(viewResized(QSize)),
468 m_zoomButtonPanel, SLOT(screenResized(QSize)));
470 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
471 this, SIGNAL(draggingModeTriggered()));
474 void MainWindow::clearCookieJar()
476 qDebug() << __PRETTY_FUNCTION__;
483 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
485 QList<QNetworkCookie> emptyList;
488 m_cookieJar->setAllCookies(emptyList);
489 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
492 void MainWindow::createMenus()
494 qDebug() << __PRETTY_FUNCTION__;
497 m_loginAct = new QAction(tr("Login"), this);
498 connect(m_loginAct, SIGNAL(triggered()),
499 this, SIGNAL(loginActionPressed()));
502 m_toSettingsAct = new QAction(tr("Settings"), this);
503 connect(m_toSettingsAct, SIGNAL(triggered()),
504 this, SLOT(openSettingsDialog()));
507 m_gpsToggleAct = new QAction(tr("GPS"), this);
508 m_gpsToggleAct->setCheckable(true);
510 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
511 this, SIGNAL(gpsTriggered(bool)));
513 // build the actual menu
514 m_viewMenu = menuBar()->addMenu(tr("Main"));
515 m_viewMenu->addAction(m_loginAct);
516 m_viewMenu->addAction(m_toSettingsAct);
517 m_viewMenu->addAction(m_gpsToggleAct);
518 m_viewMenu->setObjectName(tr("Menu"));
521 void MainWindow::dialogFinished(int status)
523 qDebug() << __PRETTY_FUNCTION__;
525 QDialog *dialog = m_queue.takeFirst();
526 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
527 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
531 loginDialog->userInput(m_email, m_password);
533 QStringList urlParts;
534 urlParts.append(FACEBOOK_LOGINBASE);
535 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
536 urlParts.append(INTERVAL1);
537 urlParts.append(SITUARE_LOGIN_SUCCESS);
538 urlParts.append(INTERVAL2);
539 urlParts.append(SITUARE_LOGIN_FAILURE);
540 urlParts.append(FACEBOOK_LOGIN_ENDING);
542 emit saveUsername(m_email);
544 m_webView->load(QUrl(urlParts.join(EMPTY)));
545 toggleProgressIndicator(true);
547 emit cancelLoginProcess();
549 } else if(searchDialog) {
551 emit searchForLocation(searchDialog->input());
555 dialog->deleteLater();
557 if(!m_error_queue.isEmpty() && m_errorShown == false) {
558 showErrorInformationBox();
560 if(!m_queue.isEmpty()) {
561 showInformationBox();
566 void MainWindow::drawFullScreenButton(const QSize &size)
568 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
570 if (m_fullScreenButton) {
571 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
572 size.height() - m_fullScreenButton->size().height());
576 void MainWindow::drawMapScale(const QSize &size)
578 qDebug() << __PRETTY_FUNCTION__;
580 const int LEFT_SCALE_MARGIN = 10;
581 const int BOTTOM_SCALE_MARGIN = 2;
583 m_mapScale->move(LEFT_SCALE_MARGIN,
584 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
587 void MainWindow::drawOsmLicense(const QSize &size)
589 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
591 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
593 size.height() - m_osmLicense->fontMetrics().height());
596 void MainWindow::errorDialogFinished(int status)
598 qDebug() << __PRETTY_FUNCTION__;
601 QDialog *dialog = m_error_queue.takeFirst();
603 dialog->deleteLater();
604 m_errorShown = false;
606 if(!m_error_queue.isEmpty())
607 showErrorInformationBox();
608 else if(!m_queue.isEmpty())
609 showInformationBox();
612 void MainWindow::gpsTimeout()
614 qDebug() << __PRETTY_FUNCTION__;
616 buildInformationBox(tr("GPS timeout"));
619 void MainWindow::grabZoomKeys(bool grab)
621 qDebug() << __PRETTY_FUNCTION__;
624 // Can't grab keys unless we have a window id
628 unsigned long val = (grab) ? 1 : 0;
629 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
633 XChangeProperty (QX11Info::display(),
639 reinterpret_cast<unsigned char *>(&val),
643 #endif // Q_WS_MAEMO_5
646 void MainWindow::keyPressEvent(QKeyEvent* event)
648 qDebug() << __PRETTY_FUNCTION__;
650 switch (event->key()) {
661 QWidget::keyPressEvent(event);
664 void MainWindow::loadCookies()
666 qDebug() << __PRETTY_FUNCTION__;
668 QSettings settings(DIRECTORY_NAME, FILE_NAME);
670 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
672 if(!list.isEmpty()) {
673 QList<QNetworkCookie> cookieList;
674 for(int i=0;i<list.count();i++) {
675 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
679 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
681 m_cookieJar->setAllCookies(cookieList);
682 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
686 void MainWindow::loadDone(bool done)
688 qDebug() << __PRETTY_FUNCTION__;
690 // for the first time the login page is opened, we need to refresh it to get cookies working
698 QWebFrame* frame = m_webView->page()->currentFrame();
702 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
704 foreach (QWebElement element, emailCollection) {
705 element.setAttribute("value", m_email.toAscii());
708 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
709 foreach (QWebElement element, passwordCollection) {
710 element.setAttribute("value", m_password.toAscii());
712 // find connect button
713 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
714 foreach (QWebElement element, buttonCollection)
716 QPoint pos(element.geometry().center());
718 // send a mouse click event to the web page
719 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
721 QApplication::sendEvent(m_webView->page(), &event0);
722 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
724 QApplication::sendEvent(m_webView->page(), &event1);
730 void MainWindow::loggedIn(bool logged)
732 qDebug() << __PRETTY_FUNCTION__;
737 m_loginAct->setText(tr("Logout"));
743 m_loginAct->setText(tr("Login"));
745 updateItemVisibility();
748 void MainWindow::loginFailed()
750 qDebug() << __PRETTY_FUNCTION__;
756 bool MainWindow::loginState()
758 qDebug() << __PRETTY_FUNCTION__;
763 void MainWindow::loginUsingCookies()
765 qDebug() << __PRETTY_FUNCTION__;
767 toggleProgressIndicator(true);
772 QStringList urlParts;
773 urlParts.append(FACEBOOK_LOGINBASE);
774 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
775 urlParts.append(INTERVAL1);
776 urlParts.append(SITUARE_LOGIN_SUCCESS);
777 urlParts.append(INTERVAL2);
778 urlParts.append(SITUARE_LOGIN_FAILURE);
779 urlParts.append(FACEBOOK_LOGIN_ENDING);
781 m_webView->load(QUrl(urlParts.join(EMPTY)));
785 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
787 m_mapCenterHorizontalShifting = shifting;
791 void MainWindow::moveCrosshair()
793 qDebug() << __PRETTY_FUNCTION__;
796 int mapHeight = m_mapView->size().height();
797 int mapWidth = m_mapView->size().width();
798 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
799 - m_mapCenterHorizontalShifting,
800 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
804 void MainWindow::openSettingsDialog()
806 qDebug() << __PRETTY_FUNCTION__;
808 SettingsDialog *settingsDialog = new SettingsDialog(this);
809 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
810 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
812 settingsDialog->show();
815 void MainWindow::queueDialog(QDialog *dialog)
817 qDebug() << __PRETTY_FUNCTION__;
819 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
820 if(dialog->isModal()) {
821 m_error_queue.append(dialog);
823 m_queue.append(dialog);
826 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
827 if(m_error_queue.count() == 1 && m_errorShown == false)
828 showErrorInformationBox();
829 else if(m_queue.count() == 1 && m_errorShown == false)
830 showInformationBox();
833 void MainWindow::readAutomaticLocationUpdateSettings()
835 qDebug() << __PRETTY_FUNCTION__;
837 QSettings settings(DIRECTORY_NAME, FILE_NAME);
838 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
839 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
842 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
844 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
846 emit enableAutomaticLocationUpdate(false);
850 void MainWindow::saveCookies()
852 qDebug() << __PRETTY_FUNCTION__;
855 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
857 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
860 for(int i=0;i<cookieList.count();i++) {
861 QNetworkCookie cookie = cookieList.at(i);
862 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
863 list.append(QString(byteArray));
865 list.removeDuplicates();
867 QSettings settings(DIRECTORY_NAME, FILE_NAME);
868 settings.setValue(COOKIES, list);
871 void MainWindow::setCrosshairVisibility(bool visibility)
873 qDebug() << __PRETTY_FUNCTION__;
883 void MainWindow::setGPSButtonEnabled(bool enabled)
885 qDebug() << __PRETTY_FUNCTION__;
887 m_gpsToggleAct->setChecked(enabled);
890 void MainWindow::setIndicatorButtonEnabled(bool enabled)
892 qDebug() << __PRETTY_FUNCTION__;
894 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
897 void MainWindow::setMapViewScene(QGraphicsScene *scene)
899 qDebug() << __PRETTY_FUNCTION__;
901 m_mapView->setScene(scene);
904 void MainWindow::settingsDialogAccepted()
906 qDebug() << __PRETTY_FUNCTION__;
908 readAutomaticLocationUpdateSettings();
911 void MainWindow::setUsername(const QString &username)
913 qDebug() << __PRETTY_FUNCTION__;
918 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
920 qDebug() << __PRETTY_FUNCTION__;
922 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
923 tr("Automatic location update"), text,
924 QMessageBox::Yes | QMessageBox::No |
925 QMessageBox::Cancel, this);
926 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
927 this, SLOT(automaticUpdateDialogFinished(int)));
929 m_automaticUpdateLocationDialog->show();
932 void MainWindow::showErrorInformationBox()
934 qDebug() << __PRETTY_FUNCTION__;
936 if(m_error_queue.count()) {
938 QDialog *dialog = m_error_queue.first();
939 connect(dialog, SIGNAL(finished(int)),
940 this, SLOT(errorDialogFinished(int)));
945 void MainWindow::showInformationBox()
947 qDebug() << __PRETTY_FUNCTION__;
949 if(m_queue.count()) {
950 QDialog *dialog = m_queue.first();
951 connect(dialog, SIGNAL(finished(int)),
952 this, SLOT(dialogFinished(int)));
957 void MainWindow::startLocationSearch()
959 qDebug() << __PRETTY_FUNCTION__;
961 SearchDialog *searchDialog = new SearchDialog();
962 queueDialog(searchDialog);
965 void MainWindow::startLoginProcess()
967 qDebug() << __PRETTY_FUNCTION__;
969 LoginDialog *loginDialog = new LoginDialog();
971 emit fetchUsernameFromSettings();
973 loginDialog->clearTextFields();
975 if(!m_email.isEmpty())
976 loginDialog->setEmailField(m_email);
978 queueDialog(loginDialog);
981 void MainWindow::toggleFullScreen()
983 qDebug() << __PRETTY_FUNCTION__;
985 if(windowState() == Qt::WindowNoState)
991 void MainWindow::toggleProgressIndicator(bool value)
993 qDebug() << __PRETTY_FUNCTION__;
997 m_progressIndicatorCount++;
998 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1000 if(m_progressIndicatorCount > 0)
1001 m_progressIndicatorCount--;
1003 if(m_progressIndicatorCount == 0)
1004 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1008 #endif // Q_WS_MAEMO_5
1011 void MainWindow::updateItemVisibility()
1013 qDebug() << __PRETTY_FUNCTION__;
1016 m_tabbedPanel->closePanel();
1018 m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, m_loggedIn);
1021 const QString MainWindow::username()
1023 qDebug() << __PRETTY_FUNCTION__;
1028 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1030 qDebug() << __PRETTY_FUNCTION__;
1032 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1033 // qwebview starts to load a new page while the current page loading is not finished
1034 if(reply->error() != QNetworkReply::OperationCanceledError &&
1035 reply->error() != QNetworkReply::NoError) {
1036 emit error(ErrorContext::NETWORK, reply->error());