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_progressIndicatorCount(0),
69 m_ownLocationCrosshair(0),
70 m_email(), ///< @todo WTF?!?!?!?
73 m_fullScreenButton(0),
74 m_indicatorButtonPanel(0),
78 qDebug() << __PRETTY_FUNCTION__;
83 QHBoxLayout *layout = new QHBoxLayout;
84 layout->addWidget(m_mapView);
86 layout->setSpacing(0);
88 setCentralWidget(new QWidget());
89 centralWidget()->setLayout(layout);
94 setWindowTitle(tr("Situare"));
96 // set stacking order of widgets
97 m_zoomButtonPanel->stackUnder(m_tabbedPanel);
98 if(m_fullScreenButton) {
99 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
100 m_osmLicense->stackUnder(m_fullScreenButton);
102 m_osmLicense->stackUnder(m_zoomButtonPanel);
104 m_ownLocationCrosshair->stackUnder(m_osmLicense);
105 m_indicatorButtonPanel->stackUnder(m_ownLocationCrosshair);
106 m_mapScale->stackUnder(m_indicatorButtonPanel);
107 m_mapView->stackUnder(m_mapScale);
111 // Set default screen size
112 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
114 setAttribute(Qt::WA_Maemo5StackedWindow);
118 MainWindow::~MainWindow()
120 qDebug() << __PRETTY_FUNCTION__;
127 qDeleteAll(m_queue.begin(), m_queue.end());
130 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
131 m_error_queue.clear();
134 void MainWindow::automaticUpdateDialogFinished(int result)
136 qDebug() << __PRETTY_FUNCTION__;
138 if (result == QMessageBox::Yes) {
139 readAutomaticLocationUpdateSettings();
141 QSettings settings(DIRECTORY_NAME, FILE_NAME);
142 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
143 readAutomaticLocationUpdateSettings();
146 m_automaticUpdateLocationDialog->deleteLater();
149 void MainWindow::buildFullScreenButton()
151 qDebug() << __PRETTY_FUNCTION__;
154 m_fullScreenButton = new FullScreenButton(this);
156 if (m_fullScreenButton) {
157 connect(m_fullScreenButton, SIGNAL(clicked()),
158 this, SLOT(toggleFullScreen()));
160 connect(qApp, SIGNAL(showFullScreenButton()),
161 m_fullScreenButton, SLOT(invoke()));
163 #endif // Q_WS_MAEMO_5
166 void MainWindow::buildFriendListPanel()
168 qDebug() << __PRETTY_FUNCTION__;
170 m_friendsListPanel = new FriendListPanel(this);
172 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
173 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
175 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
176 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
178 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
179 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
181 connect(this, SIGNAL(friendImageReady(User*)),
182 m_friendsListPanel, SLOT(friendImageReady(User*)));
184 connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
185 this, SIGNAL(routeTo(const GeoCoordinate&)));
188 void MainWindow::buildIndicatorButtonPanel()
190 qDebug() << __PRETTY_FUNCTION__;
192 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
194 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
195 this, SIGNAL(autoCenteringTriggered(bool)));
197 connect(m_mapView, SIGNAL(viewResized(QSize)),
198 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
200 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
201 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
203 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
204 this, SIGNAL(draggingModeTriggered()));
207 void MainWindow::buildInformationBox(const QString &message, bool modal)
209 qDebug() << __PRETTY_FUNCTION__;
211 QString errorMessage = message;
215 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
218 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
219 // extra line changes are needed to make error notes broader
220 errorMessage.prepend("\n");
221 errorMessage.append("\n");
223 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
225 QLabel *label = new QLabel(msgBox);
226 label->setAlignment(Qt::AlignCenter);
227 label->setText(errorMessage);
228 msgBox->setWidget(label);
230 QMessageBox *msgBox = new QMessageBox(this);
231 msgBox->button(QMessageBox::Ok);
232 msgBox->setText(errorMessage);
233 msgBox->setModal(modal);
239 void MainWindow::buildManualLocationCrosshair()
241 qDebug() << __PRETTY_FUNCTION__;
243 m_ownLocationCrosshair = new QLabel(this);
244 QPixmap crosshairImage(":/res/images/sight.png");
245 m_ownLocationCrosshair->setPixmap(crosshairImage);
246 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
247 m_ownLocationCrosshair->hide();
248 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
250 connect(m_mapView, SIGNAL(viewResized(QSize)),
251 this, SLOT(drawOwnLocationCrosshair(QSize)));
254 void MainWindow::buildMap()
256 qDebug() << __PRETTY_FUNCTION__;
258 m_mapView = new MapView(this);
260 buildZoomButtonPanel();
262 buildManualLocationCrosshair();
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(setViewPortSize(QSize)));
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_tabbedPanel, SIGNAL(panelClosed()),
332 m_friendsListPanel, SLOT(clearFriendListFilter()));
334 connect(m_mapView, SIGNAL(viewResized(QSize)),
335 m_tabbedPanel, SLOT(resizePanel(QSize)));
337 connect(m_friendsListPanel, SIGNAL(showPanelRequested(QWidget*)),
338 m_tabbedPanel, SLOT(showPanel(QWidget*)));
341 void MainWindow::buildRoutingPanel()
343 qDebug() << __PRETTY_FUNCTION__;
345 m_routingPanel = new RoutingPanel(this);
347 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
348 m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
350 connect(m_routingPanel,
351 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
353 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
355 connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
356 this, SIGNAL(routeTo(const GeoCoordinate&)));
358 connect(this, SIGNAL(routeParsed(Route&)),
359 m_routingPanel, SLOT(setRoute(Route&)));
361 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
362 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
364 connect(m_routingPanel, SIGNAL(requestSearchLocation()),
365 this, SLOT(startLocationSearch()));
368 void MainWindow::buildUserInfoPanel()
370 qDebug() << __PRETTY_FUNCTION__;
372 m_userInfoPanel = new UserInfoPanel(this);
374 connect(this, SIGNAL(userLocationReady(User*)),
375 m_userInfoPanel, SLOT(userDataReceived(User*)));
377 connect(this, SIGNAL(reverseGeoReady(QString)),
378 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
380 connect(this, SIGNAL(clearUpdateLocationDialogData()),
381 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
383 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
384 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
386 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
387 this, SIGNAL(requestReverseGeo()));
389 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
390 this, SIGNAL(statusUpdate(QString,bool)));
392 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
393 this, SIGNAL(refreshUserData()));
395 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
396 this, SLOT(buildInformationBox(QString, bool)));
399 void MainWindow::buildWebView()
401 qDebug() << __PRETTY_FUNCTION__;
404 m_webView = new QWebView;
407 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
409 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
411 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
412 this, SLOT(webViewRequestFinished(QNetworkReply*)));
413 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
414 this, SIGNAL(updateCredentials(QUrl)));
415 connect(m_webView, SIGNAL(loadFinished(bool)),
416 this, SLOT(loadDone(bool)));
422 void MainWindow::buildZoomButtonPanel()
424 qDebug() << __PRETTY_FUNCTION__;
426 m_zoomButtonPanel = new ZoomButtonPanel(this);
428 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
429 this, SIGNAL(zoomIn()));
431 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
432 this, SIGNAL(zoomOut()));
434 connect(this, SIGNAL(zoomLevelChanged(int)),
435 m_zoomButtonPanel, SLOT(resetButtons()));
437 connect(this, SIGNAL(maxZoomLevelReached()),
438 m_zoomButtonPanel, SLOT(disableZoomInButton()));
440 connect(this, SIGNAL(minZoomLevelReached()),
441 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
443 connect(m_mapView, SIGNAL(viewResized(QSize)),
444 m_zoomButtonPanel, SLOT(screenResized(QSize)));
446 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
447 this, SIGNAL(draggingModeTriggered()));
450 void MainWindow::clearCookieJar()
452 qDebug() << __PRETTY_FUNCTION__;
459 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
461 QList<QNetworkCookie> emptyList;
464 m_cookieJar->setAllCookies(emptyList);
465 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
468 void MainWindow::createMenus()
470 qDebug() << __PRETTY_FUNCTION__;
473 m_loginAct = new QAction(tr("Login"), this);
474 connect(m_loginAct, SIGNAL(triggered()),
475 this, SIGNAL(loginActionPressed()));
478 m_toSettingsAct = new QAction(tr("Settings"), this);
479 connect(m_toSettingsAct, SIGNAL(triggered()),
480 this, SLOT(openSettingsDialog()));
483 m_gpsToggleAct = new QAction(tr("GPS"), this);
484 m_gpsToggleAct->setCheckable(true);
486 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
487 this, SIGNAL(gpsTriggered(bool)));
489 // build the actual menu
490 m_viewMenu = menuBar()->addMenu(tr("Main"));
491 m_viewMenu->addAction(m_loginAct);
492 m_viewMenu->addAction(m_toSettingsAct);
493 m_viewMenu->addAction(m_gpsToggleAct);
494 m_viewMenu->setObjectName(tr("Menu"));
497 void MainWindow::dialogFinished(int status)
499 qDebug() << __PRETTY_FUNCTION__;
501 QDialog *dialog = m_queue.takeFirst();
502 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
503 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
507 loginDialog->userInput(m_email, m_password);
509 QStringList urlParts;
510 urlParts.append(FACEBOOK_LOGINBASE);
511 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
512 urlParts.append(INTERVAL1);
513 urlParts.append(SITUARE_LOGIN_SUCCESS);
514 urlParts.append(INTERVAL2);
515 urlParts.append(SITUARE_LOGIN_FAILURE);
516 urlParts.append(FACEBOOK_LOGIN_ENDING);
518 emit saveUsername(m_email);
520 m_webView->load(QUrl(urlParts.join(EMPTY)));
521 toggleProgressIndicator(true);
523 emit cancelLoginProcess();
525 } else if(searchDialog) {
527 emit searchForLocation(searchDialog->input());
531 dialog->deleteLater();
533 if(!m_error_queue.isEmpty() && m_errorShown == false) {
534 showErrorInformationBox();
536 if(!m_queue.isEmpty()) {
537 showInformationBox();
542 void MainWindow::drawFullScreenButton(const QSize &size)
544 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
546 if (m_fullScreenButton) {
547 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
548 size.height() - m_fullScreenButton->size().height());
552 void MainWindow::drawMapScale(const QSize &size)
554 qDebug() << __PRETTY_FUNCTION__;
556 const int LEFT_SCALE_MARGIN = 10;
557 const int BOTTOM_SCALE_MARGIN = 2;
559 m_mapScale->move(LEFT_SCALE_MARGIN,
560 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
563 void MainWindow::drawOsmLicense(const QSize &size)
565 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
567 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
569 size.height() - m_osmLicense->fontMetrics().height());
572 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
574 qDebug() << __PRETTY_FUNCTION__;
576 if (m_ownLocationCrosshair != 0) {
577 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
578 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
582 void MainWindow::errorDialogFinished(int status)
584 qDebug() << __PRETTY_FUNCTION__;
587 QDialog *dialog = m_error_queue.takeFirst();
589 dialog->deleteLater();
590 m_errorShown = false;
592 if(!m_error_queue.isEmpty())
593 showErrorInformationBox();
594 else if(!m_queue.isEmpty())
595 showInformationBox();
598 void MainWindow::gpsTimeout()
600 qDebug() << __PRETTY_FUNCTION__;
602 buildInformationBox(tr("GPS timeout"));
605 void MainWindow::grabZoomKeys(bool grab)
607 qDebug() << __PRETTY_FUNCTION__;
610 // Can't grab keys unless we have a window id
614 unsigned long val = (grab) ? 1 : 0;
615 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
619 XChangeProperty (QX11Info::display(),
625 reinterpret_cast<unsigned char *>(&val),
629 #endif // Q_WS_MAEMO_5
632 void MainWindow::keyPressEvent(QKeyEvent* event)
634 qDebug() << __PRETTY_FUNCTION__;
636 switch (event->key()) {
647 QWidget::keyPressEvent(event);
650 void MainWindow::loadCookies()
652 qDebug() << __PRETTY_FUNCTION__;
654 QSettings settings(DIRECTORY_NAME, FILE_NAME);
656 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
658 if(!list.isEmpty()) {
659 QList<QNetworkCookie> cookieList;
660 for(int i=0;i<list.count();i++) {
661 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
665 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
667 m_cookieJar->setAllCookies(cookieList);
668 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
672 void MainWindow::loadDone(bool done)
674 qDebug() << __PRETTY_FUNCTION__;
676 // for the first time the login page is opened, we need to refresh it to get cookies working
684 QWebFrame* frame = m_webView->page()->currentFrame();
688 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
690 foreach (QWebElement element, emailCollection) {
691 element.setAttribute("value", m_email.toAscii());
694 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
695 foreach (QWebElement element, passwordCollection) {
696 element.setAttribute("value", m_password.toAscii());
698 // find connect button
699 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
700 foreach (QWebElement element, buttonCollection)
702 QPoint pos(element.geometry().center());
704 // send a mouse click event to the web page
705 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
707 QApplication::sendEvent(m_webView->page(), &event0);
708 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
710 QApplication::sendEvent(m_webView->page(), &event1);
716 void MainWindow::loggedIn(bool logged)
718 qDebug() << __PRETTY_FUNCTION__;
723 m_loginAct->setText(tr("Logout"));
729 m_loginAct->setText(tr("Login"));
731 updateItemVisibility();
734 void MainWindow::loginFailed()
736 qDebug() << __PRETTY_FUNCTION__;
742 bool MainWindow::loginState()
744 qDebug() << __PRETTY_FUNCTION__;
749 void MainWindow::loginUsingCookies()
751 qDebug() << __PRETTY_FUNCTION__;
753 toggleProgressIndicator(true);
758 QStringList urlParts;
759 urlParts.append(FACEBOOK_LOGINBASE);
760 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
761 urlParts.append(INTERVAL1);
762 urlParts.append(SITUARE_LOGIN_SUCCESS);
763 urlParts.append(INTERVAL2);
764 urlParts.append(SITUARE_LOGIN_FAILURE);
765 urlParts.append(FACEBOOK_LOGIN_ENDING);
767 m_webView->load(QUrl(urlParts.join(EMPTY)));
771 void MainWindow::openSettingsDialog()
773 qDebug() << __PRETTY_FUNCTION__;
775 SettingsDialog *settingsDialog = new SettingsDialog(this);
776 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
777 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
779 settingsDialog->show();
782 void MainWindow::readAutomaticLocationUpdateSettings()
784 qDebug() << __PRETTY_FUNCTION__;
786 QSettings settings(DIRECTORY_NAME, FILE_NAME);
787 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
788 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
791 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
793 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
795 emit enableAutomaticLocationUpdate(false);
799 void MainWindow::queueDialog(QDialog *dialog)
801 qDebug() << __PRETTY_FUNCTION__;
803 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
804 if(dialog->isModal()) {
805 m_error_queue.append(dialog);
807 m_queue.append(dialog);
810 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
811 if(m_error_queue.count() == 1 && m_errorShown == false)
812 showErrorInformationBox();
813 else if(m_queue.count() == 1 && m_errorShown == false)
814 showInformationBox();
817 void MainWindow::saveCookies()
819 qDebug() << __PRETTY_FUNCTION__;
822 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
824 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
827 for(int i=0;i<cookieList.count();i++) {
828 QNetworkCookie cookie = cookieList.at(i);
829 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
830 list.append(QString(byteArray));
832 list.removeDuplicates();
834 QSettings settings(DIRECTORY_NAME, FILE_NAME);
835 settings.setValue(COOKIES, list);
838 void MainWindow::setGPSButtonEnabled(bool enabled)
840 qDebug() << __PRETTY_FUNCTION__;
842 m_gpsToggleAct->setChecked(enabled);
845 void MainWindow::setIndicatorButtonEnabled(bool enabled)
847 qDebug() << __PRETTY_FUNCTION__;
849 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
852 void MainWindow::setMapViewScene(QGraphicsScene *scene)
854 qDebug() << __PRETTY_FUNCTION__;
856 m_mapView->setScene(scene);
859 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
861 qDebug() << __PRETTY_FUNCTION__;
864 m_ownLocationCrosshair->show();
865 drawOwnLocationCrosshair(m_viewPortSize);
867 m_ownLocationCrosshair->hide();
871 void MainWindow::settingsDialogAccepted()
873 qDebug() << __PRETTY_FUNCTION__;
875 readAutomaticLocationUpdateSettings();
878 void MainWindow::setUsername(const QString &username)
880 qDebug() << __PRETTY_FUNCTION__;
885 void MainWindow::setViewPortSize(const QSize &size)
887 qDebug() << __PRETTY_FUNCTION__;
889 m_viewPortSize = size;
892 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
894 qDebug() << __PRETTY_FUNCTION__;
896 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
897 tr("Automatic location update"), text,
898 QMessageBox::Yes | QMessageBox::No |
899 QMessageBox::Cancel, this);
900 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
901 this, SLOT(automaticUpdateDialogFinished(int)));
903 m_automaticUpdateLocationDialog->show();
906 void MainWindow::toggleFullScreen()
908 qDebug() << __PRETTY_FUNCTION__;
910 if(windowState() == Qt::WindowNoState)
916 void MainWindow::showErrorInformationBox()
918 qDebug() << __PRETTY_FUNCTION__;
920 if(m_error_queue.count()) {
922 QDialog *dialog = m_error_queue.first();
923 connect(dialog, SIGNAL(finished(int)),
924 this, SLOT(errorDialogFinished(int)));
929 void MainWindow::showInformationBox()
931 qDebug() << __PRETTY_FUNCTION__;
933 if(m_queue.count()) {
934 QDialog *dialog = m_queue.first();
935 connect(dialog, SIGNAL(finished(int)),
936 this, SLOT(dialogFinished(int)));
941 void MainWindow::showPanels()
943 qDebug() << __PRETTY_FUNCTION__;
945 ///< @todo check how this is called and can this method be removed
947 drawFullScreenButton(m_viewPortSize);
950 // if(!m_friendsListPanel->isVisible()) {
951 // m_friendsListPanel->show();
952 // m_friendsListPanelSidebar->show();
955 // if(!m_userPanel->isVisible()) {
956 // m_userPanel->show();
957 // m_userPanelSidebar->show();
962 void MainWindow::startLocationSearch()
964 qDebug() << __PRETTY_FUNCTION__;
966 SearchDialog *searchDialog = new SearchDialog();
967 queueDialog(searchDialog);
970 void MainWindow::startLoginProcess()
972 qDebug() << __PRETTY_FUNCTION__;
974 LoginDialog *loginDialog = new LoginDialog();
976 emit fetchUsernameFromSettings();
978 loginDialog->clearTextFields();
980 if(!m_email.isEmpty())
981 loginDialog->setEmailField(m_email);
983 queueDialog(loginDialog);
986 void MainWindow::toggleProgressIndicator(bool value)
988 qDebug() << __PRETTY_FUNCTION__;
992 m_progressIndicatorCount++;
993 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
995 if(m_progressIndicatorCount > 0)
996 m_progressIndicatorCount--;
998 if(m_progressIndicatorCount == 0)
999 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1003 #endif // Q_WS_MAEMO_5
1006 void MainWindow::updateItemVisibility()
1008 qDebug() << __PRETTY_FUNCTION__;
1010 ///< @todo can this be removed?
1012 // if(!m_loggedIn) {
1013 // m_friendsListPanel->closePanel();
1014 // m_friendsListPanel->hide();
1015 // m_friendsListPanelSidebar->hide();
1017 // m_userPanel->closePanel();
1018 // m_userPanel->hide();
1019 // m_userPanelSidebar->hide();
1023 const QString MainWindow::username()
1025 qDebug() << __PRETTY_FUNCTION__;
1030 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1032 qDebug() << __PRETTY_FUNCTION__;
1034 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1035 // qwebview starts to load a new page while the current page loading is not finished
1036 if(reply->error() != QNetworkReply::OperationCanceledError &&
1037 reply->error() != QNetworkReply::NoError) {
1038 emit error(ErrorContext::NETWORK, reply->error());