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);
348 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
349 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
350 m_tabbedPanel->addTab(m_locationSearchPanel, QIcon(":/res/images/compass.png"));
351 m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
353 connect(m_mapView, SIGNAL(viewResized(QSize)),
354 m_tabbedPanel, SLOT(resizePanel(QSize)));
356 connect(m_friendsListPanel, SIGNAL(openPanelRequested(QWidget*)),
357 m_tabbedPanel, SLOT(openPanel(QWidget*)));
359 connect(m_routingPanel, SIGNAL(openPanelRequested(QWidget*)),
360 m_tabbedPanel, SLOT(openPanel(QWidget*)));
362 connect(m_tabbedPanel, SIGNAL(panelClosed()),
363 m_friendsListPanel, SLOT(anyPanelClosed()));
365 connect(m_tabbedPanel, SIGNAL(panelOpened()),
366 m_friendsListPanel, SLOT(anyPanelOpened()));
368 connect(m_tabbedPanel, SIGNAL(panelClosed()),
369 m_routingPanel, SLOT(clearListsSelections()));
371 connect(m_tabbedPanel, SIGNAL(panelClosed()),
372 m_mapView, SLOT(disableCenterShift()));
374 connect(m_tabbedPanel, SIGNAL(panelOpened()),
375 m_mapView, SLOT(enableCenterShift()));
377 connect(m_tabbedPanel, SIGNAL(panelClosed()),
378 m_userInfoPanel, SIGNAL(collapse()));
380 connect(m_tabbedPanel, SIGNAL(currentChanged(int)),
381 m_userInfoPanel, SIGNAL(collapse()));
384 void MainWindow::buildRoutingPanel()
386 qDebug() << __PRETTY_FUNCTION__;
388 m_routingPanel = new RoutingPanel(this);
390 connect(m_routingPanel, SIGNAL(routeToCursor()),
391 this, SIGNAL(routeToCursor()));
393 connect(this, SIGNAL(routeParsed(Route&)),
394 m_routingPanel, SLOT(setRoute(Route&)));
396 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
397 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
399 connect(m_routingPanel, SIGNAL(clearRoute()),
400 this, SIGNAL(clearRoute()));
403 void MainWindow::buildUserInfoPanel()
405 qDebug() << __PRETTY_FUNCTION__;
407 m_userInfoPanel = new UserInfoPanel(this);
409 connect(this, SIGNAL(userLocationReady(User*)),
410 m_userInfoPanel, SLOT(userDataReceived(User*)));
412 connect(this, SIGNAL(reverseGeoReady(QString)),
413 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
415 connect(this, SIGNAL(clearUpdateLocationDialogData()),
416 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
418 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
419 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
421 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
422 this, SIGNAL(requestReverseGeo()));
424 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
425 this, SIGNAL(statusUpdate(QString,bool)));
427 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
428 this, SIGNAL(refreshUserData()));
430 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
431 this, SLOT(buildInformationBox(QString, bool)));
434 void MainWindow::buildWebView()
436 qDebug() << __PRETTY_FUNCTION__;
439 m_webView = new QWebView;
442 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
444 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
446 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
447 this, SLOT(webViewRequestFinished(QNetworkReply*)));
448 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
449 this, SIGNAL(updateCredentials(QUrl)));
450 connect(m_webView, SIGNAL(loadFinished(bool)),
451 this, SLOT(loadDone(bool)));
457 void MainWindow::buildZoomButtonPanel()
459 qDebug() << __PRETTY_FUNCTION__;
461 m_zoomButtonPanel = new ZoomButtonPanel(this);
463 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
464 this, SIGNAL(zoomIn()));
466 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
467 this, SIGNAL(zoomOut()));
469 connect(this, SIGNAL(zoomLevelChanged(int)),
470 m_zoomButtonPanel, SLOT(resetButtons()));
472 connect(this, SIGNAL(maxZoomLevelReached()),
473 m_zoomButtonPanel, SLOT(disableZoomInButton()));
475 connect(this, SIGNAL(minZoomLevelReached()),
476 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
478 connect(m_mapView, SIGNAL(viewResized(QSize)),
479 m_zoomButtonPanel, SLOT(screenResized(QSize)));
481 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
482 this, SIGNAL(draggingModeTriggered()));
485 void MainWindow::clearCookieJar()
487 qDebug() << __PRETTY_FUNCTION__;
494 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
496 QList<QNetworkCookie> emptyList;
499 m_cookieJar->setAllCookies(emptyList);
500 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
503 void MainWindow::createMenus()
505 qDebug() << __PRETTY_FUNCTION__;
508 m_loginAct = new QAction(tr("Login"), this);
509 connect(m_loginAct, SIGNAL(triggered()),
510 this, SIGNAL(loginActionPressed()));
513 m_toSettingsAct = new QAction(tr("Settings"), this);
514 connect(m_toSettingsAct, SIGNAL(triggered()),
515 this, SLOT(openSettingsDialog()));
518 m_gpsToggleAct = new QAction(tr("GPS"), this);
519 m_gpsToggleAct->setCheckable(true);
521 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
522 this, SIGNAL(gpsTriggered(bool)));
524 // build the actual menu
525 m_viewMenu = menuBar()->addMenu(tr("Main"));
526 m_viewMenu->addAction(m_loginAct);
527 m_viewMenu->addAction(m_toSettingsAct);
528 m_viewMenu->addAction(m_gpsToggleAct);
529 m_viewMenu->setObjectName(tr("Menu"));
532 void MainWindow::dialogFinished(int status)
534 qDebug() << __PRETTY_FUNCTION__;
536 QDialog *dialog = m_queue.takeFirst();
537 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
538 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
542 loginDialog->userInput(m_email, m_password);
544 QStringList urlParts;
545 urlParts.append(FACEBOOK_LOGINBASE);
546 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
547 urlParts.append(INTERVAL1);
548 urlParts.append(SITUARE_LOGIN_SUCCESS);
549 urlParts.append(INTERVAL2);
550 urlParts.append(SITUARE_LOGIN_FAILURE);
551 urlParts.append(FACEBOOK_LOGIN_ENDING);
553 emit saveUsername(m_email);
555 m_webView->load(QUrl(urlParts.join(EMPTY)));
556 toggleProgressIndicator(true);
558 emit cancelLoginProcess();
560 } else if(searchDialog) {
562 emit searchForLocation(searchDialog->input());
566 dialog->deleteLater();
568 if(!m_error_queue.isEmpty() && m_errorShown == false) {
569 showErrorInformationBox();
571 if(!m_queue.isEmpty()) {
572 showInformationBox();
577 void MainWindow::drawFullScreenButton(const QSize &size)
579 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
581 if (m_fullScreenButton) {
582 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
583 size.height() - m_fullScreenButton->size().height());
587 void MainWindow::drawMapScale(const QSize &size)
589 qDebug() << __PRETTY_FUNCTION__;
591 const int LEFT_SCALE_MARGIN = 10;
592 const int BOTTOM_SCALE_MARGIN = 2;
594 m_mapScale->move(LEFT_SCALE_MARGIN,
595 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
598 void MainWindow::drawOsmLicense(const QSize &size)
600 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
602 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
604 size.height() - m_osmLicense->fontMetrics().height());
607 void MainWindow::errorDialogFinished(int status)
609 qDebug() << __PRETTY_FUNCTION__;
612 QDialog *dialog = m_error_queue.takeFirst();
614 dialog->deleteLater();
615 m_errorShown = false;
617 if(!m_error_queue.isEmpty())
618 showErrorInformationBox();
619 else if(!m_queue.isEmpty())
620 showInformationBox();
623 void MainWindow::gpsTimeout()
625 qDebug() << __PRETTY_FUNCTION__;
627 buildInformationBox(tr("GPS timeout"));
630 void MainWindow::grabZoomKeys(bool grab)
632 qDebug() << __PRETTY_FUNCTION__;
635 // Can't grab keys unless we have a window id
639 unsigned long val = (grab) ? 1 : 0;
640 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
644 XChangeProperty (QX11Info::display(),
650 reinterpret_cast<unsigned char *>(&val),
654 #endif // Q_WS_MAEMO_5
657 void MainWindow::keyPressEvent(QKeyEvent* event)
659 qDebug() << __PRETTY_FUNCTION__;
661 switch (event->key()) {
672 QWidget::keyPressEvent(event);
675 void MainWindow::loadCookies()
677 qDebug() << __PRETTY_FUNCTION__;
679 QSettings settings(DIRECTORY_NAME, FILE_NAME);
681 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
683 if(!list.isEmpty()) {
684 QList<QNetworkCookie> cookieList;
685 for(int i=0;i<list.count();i++) {
686 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
690 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
692 m_cookieJar->setAllCookies(cookieList);
693 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
697 void MainWindow::loadDone(bool done)
699 qDebug() << __PRETTY_FUNCTION__;
701 // for the first time the login page is opened, we need to refresh it to get cookies working
709 QWebFrame* frame = m_webView->page()->currentFrame();
713 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
715 foreach (QWebElement element, emailCollection) {
716 element.setAttribute("value", m_email.toAscii());
719 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
720 foreach (QWebElement element, passwordCollection) {
721 element.setAttribute("value", m_password.toAscii());
723 // find connect button
724 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
725 foreach (QWebElement element, buttonCollection)
727 QPoint pos(element.geometry().center());
729 // send a mouse click event to the web page
730 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
732 QApplication::sendEvent(m_webView->page(), &event0);
733 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
735 QApplication::sendEvent(m_webView->page(), &event1);
741 void MainWindow::loggedIn(bool logged)
743 qDebug() << __PRETTY_FUNCTION__;
748 m_loginAct->setText(tr("Logout"));
754 m_loginAct->setText(tr("Login"));
756 updateItemVisibility();
759 void MainWindow::loginFailed()
761 qDebug() << __PRETTY_FUNCTION__;
767 bool MainWindow::loginState()
769 qDebug() << __PRETTY_FUNCTION__;
774 void MainWindow::loginUsingCookies()
776 qDebug() << __PRETTY_FUNCTION__;
778 toggleProgressIndicator(true);
783 QStringList urlParts;
784 urlParts.append(FACEBOOK_LOGINBASE);
785 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
786 urlParts.append(INTERVAL1);
787 urlParts.append(SITUARE_LOGIN_SUCCESS);
788 urlParts.append(INTERVAL2);
789 urlParts.append(SITUARE_LOGIN_FAILURE);
790 urlParts.append(FACEBOOK_LOGIN_ENDING);
792 m_webView->load(QUrl(urlParts.join(EMPTY)));
796 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
798 m_mapCenterHorizontalShifting = shifting;
802 void MainWindow::moveCrosshair()
804 qDebug() << __PRETTY_FUNCTION__;
807 int mapHeight = m_mapView->size().height();
808 int mapWidth = m_mapView->size().width();
809 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
810 - m_mapCenterHorizontalShifting,
811 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
815 void MainWindow::openSettingsDialog()
817 qDebug() << __PRETTY_FUNCTION__;
819 SettingsDialog *settingsDialog = new SettingsDialog(this);
820 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
821 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
823 settingsDialog->show();
826 void MainWindow::queueDialog(QDialog *dialog)
828 qDebug() << __PRETTY_FUNCTION__;
830 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
831 if(dialog->isModal()) {
832 m_error_queue.append(dialog);
834 m_queue.append(dialog);
837 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
838 if(m_error_queue.count() == 1 && m_errorShown == false)
839 showErrorInformationBox();
840 else if(m_queue.count() == 1 && m_errorShown == false)
841 showInformationBox();
844 void MainWindow::readAutomaticLocationUpdateSettings()
846 qDebug() << __PRETTY_FUNCTION__;
848 QSettings settings(DIRECTORY_NAME, FILE_NAME);
849 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
850 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
853 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
855 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
857 emit enableAutomaticLocationUpdate(false);
861 void MainWindow::saveCookies()
863 qDebug() << __PRETTY_FUNCTION__;
866 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
868 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
871 for(int i=0;i<cookieList.count();i++) {
872 QNetworkCookie cookie = cookieList.at(i);
873 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
874 list.append(QString(byteArray));
876 list.removeDuplicates();
878 QSettings settings(DIRECTORY_NAME, FILE_NAME);
879 settings.setValue(COOKIES, list);
882 void MainWindow::setCrosshairVisibility(bool visibility)
884 qDebug() << __PRETTY_FUNCTION__;
894 void MainWindow::setGPSButtonEnabled(bool enabled)
896 qDebug() << __PRETTY_FUNCTION__;
898 m_gpsToggleAct->setChecked(enabled);
901 void MainWindow::setIndicatorButtonEnabled(bool enabled)
903 qDebug() << __PRETTY_FUNCTION__;
905 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
908 void MainWindow::setMapViewScene(QGraphicsScene *scene)
910 qDebug() << __PRETTY_FUNCTION__;
912 m_mapView->setScene(scene);
915 void MainWindow::settingsDialogAccepted()
917 qDebug() << __PRETTY_FUNCTION__;
919 readAutomaticLocationUpdateSettings();
922 void MainWindow::setUsername(const QString &username)
924 qDebug() << __PRETTY_FUNCTION__;
929 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
931 qDebug() << __PRETTY_FUNCTION__;
933 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
934 tr("Automatic location update"), text,
935 QMessageBox::Yes | QMessageBox::No |
936 QMessageBox::Cancel, this);
937 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
938 this, SLOT(automaticUpdateDialogFinished(int)));
940 m_automaticUpdateLocationDialog->show();
943 void MainWindow::showErrorInformationBox()
945 qDebug() << __PRETTY_FUNCTION__;
947 if(m_error_queue.count()) {
949 QDialog *dialog = m_error_queue.first();
950 connect(dialog, SIGNAL(finished(int)),
951 this, SLOT(errorDialogFinished(int)));
956 void MainWindow::showInformationBox()
958 qDebug() << __PRETTY_FUNCTION__;
960 if(m_queue.count()) {
961 QDialog *dialog = m_queue.first();
962 connect(dialog, SIGNAL(finished(int)),
963 this, SLOT(dialogFinished(int)));
968 void MainWindow::showPanels()
970 qDebug() << __PRETTY_FUNCTION__;
972 ///< @todo check how this is called and can this method be removed
975 // if(!m_friendsListPanel->isVisible()) {
976 // m_friendsListPanel->show();
977 // m_friendsListPanelSidebar->show();
980 // if(!m_userPanel->isVisible()) {
981 // m_userPanel->show();
982 // m_userPanelSidebar->show();
987 void MainWindow::startLocationSearch()
989 qDebug() << __PRETTY_FUNCTION__;
991 SearchDialog *searchDialog = new SearchDialog();
992 queueDialog(searchDialog);
995 void MainWindow::startLoginProcess()
997 qDebug() << __PRETTY_FUNCTION__;
999 LoginDialog *loginDialog = new LoginDialog();
1001 emit fetchUsernameFromSettings();
1003 loginDialog->clearTextFields();
1005 if(!m_email.isEmpty())
1006 loginDialog->setEmailField(m_email);
1008 queueDialog(loginDialog);
1011 void MainWindow::toggleFullScreen()
1013 qDebug() << __PRETTY_FUNCTION__;
1015 if(windowState() == Qt::WindowNoState)
1021 void MainWindow::toggleProgressIndicator(bool value)
1023 qDebug() << __PRETTY_FUNCTION__;
1027 m_progressIndicatorCount++;
1028 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1030 if(m_progressIndicatorCount > 0)
1031 m_progressIndicatorCount--;
1033 if(m_progressIndicatorCount == 0)
1034 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1038 #endif // Q_WS_MAEMO_5
1041 void MainWindow::updateItemVisibility()
1043 qDebug() << __PRETTY_FUNCTION__;
1045 ///< @todo can this be removed?
1047 // if(!m_loggedIn) {
1048 // m_friendsListPanel->closePanel();
1049 // m_friendsListPanel->hide();
1050 // m_friendsListPanelSidebar->hide();
1052 // m_userPanel->closePanel();
1053 // m_userPanel->hide();
1054 // m_userPanelSidebar->hide();
1058 const QString MainWindow::username()
1060 qDebug() << __PRETTY_FUNCTION__;
1065 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1067 qDebug() << __PRETTY_FUNCTION__;
1069 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1070 // qwebview starts to load a new page while the current page loading is not finished
1071 if(reply->error() != QNetworkReply::OperationCanceledError &&
1072 reply->error() != QNetworkReply::NoError) {
1073 emit error(ErrorContext::NETWORK, reply->error());