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_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
328 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
329 m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
331 connect(m_mapView, SIGNAL(viewResized(QSize)),
332 m_tabbedPanel, SLOT(resizePanel(QSize)));
334 connect(m_friendsListPanel, SIGNAL(openPanelRequested(QWidget*)),
335 m_tabbedPanel, SLOT(openPanel(QWidget*)));
337 connect(m_routingPanel, SIGNAL(openPanelRequested(QWidget*)),
338 m_tabbedPanel, SLOT(openPanel(QWidget*)));
340 connect(m_tabbedPanel, SIGNAL(panelClosed()),
341 m_friendsListPanel, SLOT(anyPanelClosed()));
343 connect(m_tabbedPanel, SIGNAL(panelOpened()),
344 m_friendsListPanel, SLOT(anyPanelOpened()));
346 connect(m_tabbedPanel, SIGNAL(panelClosed()),
347 m_routingPanel, SLOT(clearListsSelections()));
349 connect(m_tabbedPanel, SIGNAL(panelClosed()),
350 m_mapView, SLOT(disableCenterShift()));
352 connect(m_tabbedPanel, SIGNAL(panelOpened()),
353 m_mapView, SLOT(enableCenterShift()));
355 connect(m_tabbedPanel, SIGNAL(panelClosed()),
356 m_userInfoPanel, SIGNAL(collapse()));
358 connect(m_tabbedPanel, SIGNAL(currentChanged(int)),
359 m_userInfoPanel, SIGNAL(collapse()));
362 void MainWindow::buildRoutingPanel()
364 qDebug() << __PRETTY_FUNCTION__;
366 m_routingPanel = new RoutingPanel(this);
368 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
369 m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
371 connect(m_routingPanel, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
372 this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
374 connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
375 this, SIGNAL(routeTo(const GeoCoordinate&)));
377 connect(this, SIGNAL(routeParsed(Route&)),
378 m_routingPanel, SLOT(setRoute(Route&)));
380 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
381 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
383 connect(m_routingPanel, SIGNAL(requestSearchLocation()),
384 this, SLOT(startLocationSearch()));
386 connect(m_routingPanel, SIGNAL(clearRoute()),
387 this, SIGNAL(clearRoute()));
390 void MainWindow::buildUserInfoPanel()
392 qDebug() << __PRETTY_FUNCTION__;
394 m_userInfoPanel = new UserInfoPanel(this);
396 connect(this, SIGNAL(userLocationReady(User*)),
397 m_userInfoPanel, SLOT(userDataReceived(User*)));
399 connect(this, SIGNAL(reverseGeoReady(QString)),
400 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
402 connect(this, SIGNAL(clearUpdateLocationDialogData()),
403 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
405 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
406 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
408 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
409 this, SIGNAL(requestReverseGeo()));
411 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
412 this, SIGNAL(statusUpdate(QString,bool)));
414 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
415 this, SIGNAL(refreshUserData()));
417 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
418 this, SLOT(buildInformationBox(QString, bool)));
421 void MainWindow::buildWebView()
423 qDebug() << __PRETTY_FUNCTION__;
426 m_webView = new QWebView;
429 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
431 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
433 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
434 this, SLOT(webViewRequestFinished(QNetworkReply*)));
435 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
436 this, SIGNAL(updateCredentials(QUrl)));
437 connect(m_webView, SIGNAL(loadFinished(bool)),
438 this, SLOT(loadDone(bool)));
444 void MainWindow::buildZoomButtonPanel()
446 qDebug() << __PRETTY_FUNCTION__;
448 m_zoomButtonPanel = new ZoomButtonPanel(this);
450 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
451 this, SIGNAL(zoomIn()));
453 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
454 this, SIGNAL(zoomOut()));
456 connect(this, SIGNAL(zoomLevelChanged(int)),
457 m_zoomButtonPanel, SLOT(resetButtons()));
459 connect(this, SIGNAL(maxZoomLevelReached()),
460 m_zoomButtonPanel, SLOT(disableZoomInButton()));
462 connect(this, SIGNAL(minZoomLevelReached()),
463 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
465 connect(m_mapView, SIGNAL(viewResized(QSize)),
466 m_zoomButtonPanel, SLOT(screenResized(QSize)));
468 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
469 this, SIGNAL(draggingModeTriggered()));
472 void MainWindow::clearCookieJar()
474 qDebug() << __PRETTY_FUNCTION__;
481 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
483 QList<QNetworkCookie> emptyList;
486 m_cookieJar->setAllCookies(emptyList);
487 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
490 void MainWindow::createMenus()
492 qDebug() << __PRETTY_FUNCTION__;
495 m_loginAct = new QAction(tr("Login"), this);
496 connect(m_loginAct, SIGNAL(triggered()),
497 this, SIGNAL(loginActionPressed()));
500 m_toSettingsAct = new QAction(tr("Settings"), this);
501 connect(m_toSettingsAct, SIGNAL(triggered()),
502 this, SLOT(openSettingsDialog()));
505 m_gpsToggleAct = new QAction(tr("GPS"), this);
506 m_gpsToggleAct->setCheckable(true);
508 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
509 this, SIGNAL(gpsTriggered(bool)));
511 // build the actual menu
512 m_viewMenu = menuBar()->addMenu(tr("Main"));
513 m_viewMenu->addAction(m_loginAct);
514 m_viewMenu->addAction(m_toSettingsAct);
515 m_viewMenu->addAction(m_gpsToggleAct);
516 m_viewMenu->setObjectName(tr("Menu"));
519 void MainWindow::dialogFinished(int status)
521 qDebug() << __PRETTY_FUNCTION__;
523 QDialog *dialog = m_queue.takeFirst();
524 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
525 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
529 loginDialog->userInput(m_email, m_password);
531 QStringList urlParts;
532 urlParts.append(FACEBOOK_LOGINBASE);
533 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
534 urlParts.append(INTERVAL1);
535 urlParts.append(SITUARE_LOGIN_SUCCESS);
536 urlParts.append(INTERVAL2);
537 urlParts.append(SITUARE_LOGIN_FAILURE);
538 urlParts.append(FACEBOOK_LOGIN_ENDING);
540 emit saveUsername(m_email);
542 m_webView->load(QUrl(urlParts.join(EMPTY)));
543 toggleProgressIndicator(true);
545 emit cancelLoginProcess();
547 } else if(searchDialog) {
549 emit searchForLocation(searchDialog->input());
553 dialog->deleteLater();
555 if(!m_error_queue.isEmpty() && m_errorShown == false) {
556 showErrorInformationBox();
558 if(!m_queue.isEmpty()) {
559 showInformationBox();
564 void MainWindow::drawFullScreenButton(const QSize &size)
566 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
568 if (m_fullScreenButton) {
569 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
570 size.height() - m_fullScreenButton->size().height());
574 void MainWindow::drawMapScale(const QSize &size)
576 qDebug() << __PRETTY_FUNCTION__;
578 const int LEFT_SCALE_MARGIN = 10;
579 const int BOTTOM_SCALE_MARGIN = 2;
581 m_mapScale->move(LEFT_SCALE_MARGIN,
582 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
585 void MainWindow::drawOsmLicense(const QSize &size)
587 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
589 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
591 size.height() - m_osmLicense->fontMetrics().height());
594 void MainWindow::errorDialogFinished(int status)
596 qDebug() << __PRETTY_FUNCTION__;
599 QDialog *dialog = m_error_queue.takeFirst();
601 dialog->deleteLater();
602 m_errorShown = false;
604 if(!m_error_queue.isEmpty())
605 showErrorInformationBox();
606 else if(!m_queue.isEmpty())
607 showInformationBox();
610 void MainWindow::gpsTimeout()
612 qDebug() << __PRETTY_FUNCTION__;
614 buildInformationBox(tr("GPS timeout"));
617 void MainWindow::grabZoomKeys(bool grab)
619 qDebug() << __PRETTY_FUNCTION__;
622 // Can't grab keys unless we have a window id
626 unsigned long val = (grab) ? 1 : 0;
627 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
631 XChangeProperty (QX11Info::display(),
637 reinterpret_cast<unsigned char *>(&val),
641 #endif // Q_WS_MAEMO_5
644 void MainWindow::keyPressEvent(QKeyEvent* event)
646 qDebug() << __PRETTY_FUNCTION__;
648 switch (event->key()) {
659 QWidget::keyPressEvent(event);
662 void MainWindow::loadCookies()
664 qDebug() << __PRETTY_FUNCTION__;
666 QSettings settings(DIRECTORY_NAME, FILE_NAME);
668 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
670 if(!list.isEmpty()) {
671 QList<QNetworkCookie> cookieList;
672 for(int i=0;i<list.count();i++) {
673 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
677 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
679 m_cookieJar->setAllCookies(cookieList);
680 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
684 void MainWindow::loadDone(bool done)
686 qDebug() << __PRETTY_FUNCTION__;
688 // for the first time the login page is opened, we need to refresh it to get cookies working
696 QWebFrame* frame = m_webView->page()->currentFrame();
700 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
702 foreach (QWebElement element, emailCollection) {
703 element.setAttribute("value", m_email.toAscii());
706 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
707 foreach (QWebElement element, passwordCollection) {
708 element.setAttribute("value", m_password.toAscii());
710 // find connect button
711 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
712 foreach (QWebElement element, buttonCollection)
714 QPoint pos(element.geometry().center());
716 // send a mouse click event to the web page
717 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
719 QApplication::sendEvent(m_webView->page(), &event0);
720 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
722 QApplication::sendEvent(m_webView->page(), &event1);
728 void MainWindow::loggedIn(bool logged)
730 qDebug() << __PRETTY_FUNCTION__;
735 m_loginAct->setText(tr("Logout"));
741 m_loginAct->setText(tr("Login"));
743 updateItemVisibility();
746 void MainWindow::loginFailed()
748 qDebug() << __PRETTY_FUNCTION__;
754 bool MainWindow::loginState()
756 qDebug() << __PRETTY_FUNCTION__;
761 void MainWindow::loginUsingCookies()
763 qDebug() << __PRETTY_FUNCTION__;
765 toggleProgressIndicator(true);
770 QStringList urlParts;
771 urlParts.append(FACEBOOK_LOGINBASE);
772 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
773 urlParts.append(INTERVAL1);
774 urlParts.append(SITUARE_LOGIN_SUCCESS);
775 urlParts.append(INTERVAL2);
776 urlParts.append(SITUARE_LOGIN_FAILURE);
777 urlParts.append(FACEBOOK_LOGIN_ENDING);
779 m_webView->load(QUrl(urlParts.join(EMPTY)));
783 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
785 m_mapCenterHorizontalShifting = shifting;
789 void MainWindow::moveCrosshair()
791 qDebug() << __PRETTY_FUNCTION__;
794 int mapHeight = m_mapView->size().height();
795 int mapWidth = m_mapView->size().width();
796 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
797 - m_mapCenterHorizontalShifting,
798 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
802 void MainWindow::openSettingsDialog()
804 qDebug() << __PRETTY_FUNCTION__;
806 SettingsDialog *settingsDialog = new SettingsDialog(this);
807 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
808 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
810 settingsDialog->show();
813 void MainWindow::queueDialog(QDialog *dialog)
815 qDebug() << __PRETTY_FUNCTION__;
817 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
818 if(dialog->isModal()) {
819 m_error_queue.append(dialog);
821 m_queue.append(dialog);
824 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
825 if(m_error_queue.count() == 1 && m_errorShown == false)
826 showErrorInformationBox();
827 else if(m_queue.count() == 1 && m_errorShown == false)
828 showInformationBox();
831 void MainWindow::readAutomaticLocationUpdateSettings()
833 qDebug() << __PRETTY_FUNCTION__;
835 QSettings settings(DIRECTORY_NAME, FILE_NAME);
836 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
837 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
840 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
842 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
844 emit enableAutomaticLocationUpdate(false);
848 void MainWindow::saveCookies()
850 qDebug() << __PRETTY_FUNCTION__;
853 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
855 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
858 for(int i=0;i<cookieList.count();i++) {
859 QNetworkCookie cookie = cookieList.at(i);
860 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
861 list.append(QString(byteArray));
863 list.removeDuplicates();
865 QSettings settings(DIRECTORY_NAME, FILE_NAME);
866 settings.setValue(COOKIES, list);
869 void MainWindow::setCrosshairVisibility(bool visibility)
871 qDebug() << __PRETTY_FUNCTION__;
881 void MainWindow::setGPSButtonEnabled(bool enabled)
883 qDebug() << __PRETTY_FUNCTION__;
885 m_gpsToggleAct->setChecked(enabled);
888 void MainWindow::setIndicatorButtonEnabled(bool enabled)
890 qDebug() << __PRETTY_FUNCTION__;
892 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
895 void MainWindow::setMapViewScene(QGraphicsScene *scene)
897 qDebug() << __PRETTY_FUNCTION__;
899 m_mapView->setScene(scene);
902 void MainWindow::settingsDialogAccepted()
904 qDebug() << __PRETTY_FUNCTION__;
906 readAutomaticLocationUpdateSettings();
909 void MainWindow::setUsername(const QString &username)
911 qDebug() << __PRETTY_FUNCTION__;
916 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
918 qDebug() << __PRETTY_FUNCTION__;
920 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
921 tr("Automatic location update"), text,
922 QMessageBox::Yes | QMessageBox::No |
923 QMessageBox::Cancel, this);
924 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
925 this, SLOT(automaticUpdateDialogFinished(int)));
927 m_automaticUpdateLocationDialog->show();
930 void MainWindow::showErrorInformationBox()
932 qDebug() << __PRETTY_FUNCTION__;
934 if(m_error_queue.count()) {
936 QDialog *dialog = m_error_queue.first();
937 connect(dialog, SIGNAL(finished(int)),
938 this, SLOT(errorDialogFinished(int)));
943 void MainWindow::showInformationBox()
945 qDebug() << __PRETTY_FUNCTION__;
947 if(m_queue.count()) {
948 QDialog *dialog = m_queue.first();
949 connect(dialog, SIGNAL(finished(int)),
950 this, SLOT(dialogFinished(int)));
955 void MainWindow::showPanels()
957 qDebug() << __PRETTY_FUNCTION__;
959 ///< @todo check how this is called and can this method be removed
962 // if(!m_friendsListPanel->isVisible()) {
963 // m_friendsListPanel->show();
964 // m_friendsListPanelSidebar->show();
967 // if(!m_userPanel->isVisible()) {
968 // m_userPanel->show();
969 // m_userPanelSidebar->show();
974 void MainWindow::startLocationSearch()
976 qDebug() << __PRETTY_FUNCTION__;
978 SearchDialog *searchDialog = new SearchDialog();
979 queueDialog(searchDialog);
982 void MainWindow::startLoginProcess()
984 qDebug() << __PRETTY_FUNCTION__;
986 LoginDialog *loginDialog = new LoginDialog();
988 emit fetchUsernameFromSettings();
990 loginDialog->clearTextFields();
992 if(!m_email.isEmpty())
993 loginDialog->setEmailField(m_email);
995 queueDialog(loginDialog);
998 void MainWindow::toggleFullScreen()
1000 qDebug() << __PRETTY_FUNCTION__;
1002 if(windowState() == Qt::WindowNoState)
1008 void MainWindow::toggleProgressIndicator(bool value)
1010 qDebug() << __PRETTY_FUNCTION__;
1014 m_progressIndicatorCount++;
1015 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1017 if(m_progressIndicatorCount > 0)
1018 m_progressIndicatorCount--;
1020 if(m_progressIndicatorCount == 0)
1021 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1025 #endif // Q_WS_MAEMO_5
1028 void MainWindow::updateItemVisibility()
1030 qDebug() << __PRETTY_FUNCTION__;
1032 ///< @todo can this be removed?
1034 // if(!m_loggedIn) {
1035 // m_friendsListPanel->closePanel();
1036 // m_friendsListPanel->hide();
1037 // m_friendsListPanelSidebar->hide();
1039 // m_userPanel->closePanel();
1040 // m_userPanel->hide();
1041 // m_userPanelSidebar->hide();
1045 const QString MainWindow::username()
1047 qDebug() << __PRETTY_FUNCTION__;
1052 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1054 qDebug() << __PRETTY_FUNCTION__;
1056 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1057 // qwebview starts to load a new page while the current page loading is not finished
1058 if(reply->error() != QNetworkReply::OperationCanceledError &&
1059 reply->error() != QNetworkReply::NoError) {
1060 emit error(ErrorContext::NETWORK, reply->error());