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,
29 #include <QtAlgorithms>
31 #include "facebookservice/facebookauthentication.h"
32 #include "map/mapcommon.h"
33 #include "map/mapview.h"
36 #include "friendlistpanel.h"
37 #include "fullscreenbutton.h"
38 #include "indicatorbuttonpanel.h"
39 #include "logindialog.h"
41 #include "panelcommon.h"
42 #include "routingpanel.h"
43 #include "tabbedpanel.h"
44 #include "searchdialog.h"
45 #include "settingsdialog.h"
46 #include "userinfopanel.h"
47 #include "zoombuttonpanel.h"
49 #include "mainwindow.h"
51 // These MUST BE HERE, compiling for Maemo fails if moved
53 #include <QtMaemo5/QMaemo5InformationBox>
54 #include <QtGui/QX11Info>
55 #include <X11/Xatom.h>
57 #endif // Q_WS_MAEMO_5
59 MainWindow::MainWindow(QWidget *parent)
60 : QMainWindow(parent),
64 m_progressIndicatorCount(0),
65 m_ownLocationCrosshair(0),
69 m_fullScreenButton(0),
70 m_indicatorButtonPanel(0),
74 qDebug() << __PRETTY_FUNCTION__;
79 QHBoxLayout *layout = new QHBoxLayout;
80 layout->addWidget(m_mapView);
82 layout->setSpacing(0);
84 setCentralWidget(new QWidget());
85 centralWidget()->setLayout(layout);
90 setWindowTitle(tr("Situare"));
92 // set stacking order of widgets
93 m_zoomButtonPanel->stackUnder(m_tabbedPanel);
94 if(m_fullScreenButton) {
95 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
96 m_osmLicense->stackUnder(m_fullScreenButton);
98 m_osmLicense->stackUnder(m_zoomButtonPanel);
100 m_ownLocationCrosshair->stackUnder(m_osmLicense);
101 m_indicatorButtonPanel->stackUnder(m_ownLocationCrosshair);
102 m_mapScale->stackUnder(m_indicatorButtonPanel);
103 m_mapView->stackUnder(m_mapScale);
107 // Set default screen size
108 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
110 setAttribute(Qt::WA_Maemo5StackedWindow);
114 MainWindow::~MainWindow()
116 qDebug() << __PRETTY_FUNCTION__;
123 qDeleteAll(m_queue.begin(), m_queue.end());
126 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
127 m_error_queue.clear();
130 void MainWindow::automaticUpdateDialogFinished(int result)
132 qDebug() << __PRETTY_FUNCTION__;
134 if (result == QMessageBox::Yes) {
135 readAutomaticLocationUpdateSettings();
137 QSettings settings(DIRECTORY_NAME, FILE_NAME);
138 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
139 readAutomaticLocationUpdateSettings();
142 m_automaticUpdateLocationDialog->deleteLater();
145 void MainWindow::buildFullScreenButton()
147 qDebug() << __PRETTY_FUNCTION__;
150 m_fullScreenButton = new FullScreenButton(this);
152 if (m_fullScreenButton) {
153 connect(m_fullScreenButton, SIGNAL(clicked()),
154 this, SLOT(toggleFullScreen()));
156 connect(qApp, SIGNAL(showFullScreenButton()),
157 m_fullScreenButton, SLOT(invoke()));
159 #endif // Q_WS_MAEMO_5
162 void MainWindow::buildFriendListPanel()
164 qDebug() << __PRETTY_FUNCTION__;
166 m_friendsListPanel = new FriendListPanel(this);
168 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
169 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
171 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
172 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
174 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
175 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
177 connect(this, SIGNAL(friendImageReady(User*)),
178 m_friendsListPanel, SLOT(friendImageReady(User*)));
180 connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
181 this, SIGNAL(routeTo(const GeoCoordinate&)));
184 void MainWindow::buildIndicatorButtonPanel()
186 qDebug() << __PRETTY_FUNCTION__;
188 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
190 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
191 this, SIGNAL(autoCenteringTriggered(bool)));
193 connect(m_mapView, SIGNAL(viewResized(QSize)),
194 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
196 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
197 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
199 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
200 this, SIGNAL(draggingModeTriggered()));
203 void MainWindow::buildInformationBox(const QString &message, bool modal)
205 qDebug() << __PRETTY_FUNCTION__;
207 QString errorMessage = message;
211 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
214 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
215 // extra line changes are needed to make error notes broader
216 errorMessage.prepend("\n");
217 errorMessage.append("\n");
219 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
221 QLabel *label = new QLabel(msgBox);
222 label->setAlignment(Qt::AlignCenter);
223 label->setText(errorMessage);
224 msgBox->setWidget(label);
226 QMessageBox *msgBox = new QMessageBox(this);
227 msgBox->button(QMessageBox::Ok);
228 msgBox->setText(errorMessage);
229 msgBox->setModal(modal);
235 void MainWindow::buildManualLocationCrosshair()
237 qDebug() << __PRETTY_FUNCTION__;
239 m_ownLocationCrosshair = new QLabel(this);
240 QPixmap crosshairImage(":/res/images/sight.png");
241 m_ownLocationCrosshair->setPixmap(crosshairImage);
242 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
243 m_ownLocationCrosshair->hide();
244 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
246 connect(m_mapView, SIGNAL(viewResized(QSize)),
247 this, SLOT(drawOwnLocationCrosshair(QSize)));
250 void MainWindow::buildMap()
252 qDebug() << __PRETTY_FUNCTION__;
254 m_mapView = new MapView(this);
256 buildZoomButtonPanel();
258 buildManualLocationCrosshair();
259 buildFullScreenButton();
260 buildIndicatorButtonPanel();
263 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
264 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
266 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
267 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
269 connect(m_mapView, SIGNAL(viewResized(QSize)),
270 this, SIGNAL(mapViewResized(QSize)));
272 connect(m_mapView, SIGNAL(viewResized(QSize)),
273 this, SLOT(drawFullScreenButton(QSize)));
275 connect(m_mapView, SIGNAL(viewResized(QSize)),
276 this, SLOT(drawMapScale(QSize)));
278 connect(m_mapView, SIGNAL(viewResized(QSize)),
279 this, SLOT(setViewPortSize(QSize)));
281 connect(this, SIGNAL(zoomLevelChanged(int)),
282 m_mapView, SLOT(setZoomLevel(int)));
284 connect(m_mapView, SIGNAL(viewZoomFinished()),
285 this, SIGNAL(viewZoomFinished()));
287 connect(m_mapView, SIGNAL(zoomIn()),
288 this, SIGNAL(zoomIn()));
291 void MainWindow::buildMapScale()
293 m_mapScale = new MapScale(this);
294 connect(this, SIGNAL(newMapResolution(qreal)),
295 m_mapScale, SLOT(updateMapResolution(qreal)));
298 void MainWindow::buildOsmLicense()
300 qDebug() << __PRETTY_FUNCTION__;
302 m_osmLicense = new QLabel(this);
303 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
304 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
305 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
306 m_osmLicense->setFont(QFont("Nokia Sans", 9));
307 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
308 m_osmLicense->fontMetrics().height());
310 connect(m_mapView, SIGNAL(viewResized(QSize)),
311 this, SLOT(drawOsmLicense(QSize)));
314 void MainWindow::buildPanels()
316 qDebug() << __PRETTY_FUNCTION__;
318 buildUserInfoPanel();
319 buildFriendListPanel();
322 m_tabbedPanel = new TabbedPanel(this);
323 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
324 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
325 m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
327 connect(m_tabbedPanel, SIGNAL(tabChanged()),
328 m_friendsListPanel, SLOT(clearFriendListFilter()));
330 connect(m_mapView, SIGNAL(viewResized(QSize)),
331 m_tabbedPanel, SLOT(resizePanel(QSize)));
334 void MainWindow::buildRoutingPanel()
336 qDebug() << __PRETTY_FUNCTION__;
338 m_routingPanel = new RoutingPanel(this);
340 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
341 m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
343 connect(m_routingPanel,
344 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
346 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
348 connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
349 this, SIGNAL(routeTo(const GeoCoordinate&)));
351 connect(this, SIGNAL(routeParsed(Route&)),
352 m_routingPanel, SLOT(setRoute(Route&)));
354 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
355 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
358 void MainWindow::buildUserInfoPanel()
360 qDebug() << __PRETTY_FUNCTION__;
362 m_userInfoPanel = new UserInfoPanel(this);
364 connect(this, SIGNAL(userLocationReady(User*)),
365 m_userInfoPanel, SLOT(userDataReceived(User*)));
367 connect(this, SIGNAL(reverseGeoReady(QString)),
368 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
370 connect(this, SIGNAL(clearUpdateLocationDialogData()),
371 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
373 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
374 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
376 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
377 this, SIGNAL(requestReverseGeo()));
379 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
380 this, SIGNAL(statusUpdate(QString,bool)));
382 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
383 this, SIGNAL(refreshUserData()));
385 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
386 this, SLOT(buildInformationBox(QString, bool)));
389 void MainWindow::buildWebView()
391 qDebug() << __PRETTY_FUNCTION__;
394 m_webView = new QWebView;
397 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
399 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
401 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
402 this, SLOT(webViewRequestFinished(QNetworkReply*)));
403 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
404 this, SIGNAL(updateCredentials(QUrl)));
405 connect(m_webView, SIGNAL(loadFinished(bool)),
406 this, SLOT(loadDone(bool)));
412 void MainWindow::buildZoomButtonPanel()
414 qDebug() << __PRETTY_FUNCTION__;
416 m_zoomButtonPanel = new ZoomButtonPanel(this);
418 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
419 this, SIGNAL(zoomIn()));
421 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
422 this, SIGNAL(zoomOut()));
424 connect(this, SIGNAL(zoomLevelChanged(int)),
425 m_zoomButtonPanel, SLOT(resetButtons()));
427 connect(this, SIGNAL(maxZoomLevelReached()),
428 m_zoomButtonPanel, SLOT(disableZoomInButton()));
430 connect(this, SIGNAL(minZoomLevelReached()),
431 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
433 connect(m_mapView, SIGNAL(viewResized(QSize)),
434 m_zoomButtonPanel, SLOT(screenResized(QSize)));
436 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
437 this, SIGNAL(draggingModeTriggered()));
440 void MainWindow::clearCookieJar()
442 qDebug() << __PRETTY_FUNCTION__;
449 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
451 QList<QNetworkCookie> emptyList;
454 m_cookieJar->setAllCookies(emptyList);
455 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
458 void MainWindow::createMenus()
460 qDebug() << __PRETTY_FUNCTION__;
463 m_loginAct = new QAction(tr("Login"), this);
464 connect(m_loginAct, SIGNAL(triggered()),
465 this, SIGNAL(loginActionPressed()));
468 m_toSettingsAct = new QAction(tr("Settings"), this);
469 connect(m_toSettingsAct, SIGNAL(triggered()),
470 this, SLOT(openSettingsDialog()));
473 m_gpsToggleAct = new QAction(tr("GPS"), this);
474 m_gpsToggleAct->setCheckable(true);
476 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
477 this, SIGNAL(gpsTriggered(bool)));
479 /// @todo remove when not needed!
480 m_searchLocationAct = new QAction(tr("Location search"), this);
481 connect(m_searchLocationAct, SIGNAL(triggered()),
482 this, SLOT(startLocationSearch()));
484 // build the actual menu
485 m_viewMenu = menuBar()->addMenu(tr("Main"));
486 m_viewMenu->addAction(m_loginAct);
487 m_viewMenu->addAction(m_toSettingsAct);
488 m_viewMenu->addAction(m_gpsToggleAct);
489 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
490 m_viewMenu->setObjectName(tr("Menu"));
493 void MainWindow::dialogFinished(int status)
495 qDebug() << __PRETTY_FUNCTION__;
497 QDialog *dialog = m_queue.takeFirst();
498 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
499 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
503 loginDialog->userInput(m_email, m_password);
505 QStringList urlParts;
506 urlParts.append(FACEBOOK_LOGINBASE);
507 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
508 urlParts.append(INTERVAL1);
509 urlParts.append(SITUARE_LOGIN_SUCCESS);
510 urlParts.append(INTERVAL2);
511 urlParts.append(SITUARE_LOGIN_FAILURE);
512 urlParts.append(FACEBOOK_LOGIN_ENDING);
514 emit saveUsername(m_email);
516 m_webView->load(QUrl(urlParts.join(EMPTY)));
517 toggleProgressIndicator(true);
519 emit cancelLoginProcess();
521 } else if(searchDialog) {
523 emit searchForLocation(searchDialog->input());
527 dialog->deleteLater();
529 if(!m_error_queue.isEmpty() && m_errorShown == false) {
530 showErrorInformationBox();
532 if(!m_queue.isEmpty()) {
533 showInformationBox();
538 void MainWindow::drawFullScreenButton(const QSize &size)
540 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
542 if(m_fullScreenButton)
543 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
544 size.height() - m_fullScreenButton->size().height());
547 void MainWindow::drawMapScale(const QSize &size)
549 qDebug() << __PRETTY_FUNCTION__;
551 const int LEFT_SCALE_MARGIN = 10;
552 const int BOTTOM_SCALE_MARGIN = 2;
553 // qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
555 m_mapScale->move(LEFT_SCALE_MARGIN,
556 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
559 void MainWindow::drawOsmLicense(const QSize &size)
561 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
563 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
565 size.height() - m_osmLicense->fontMetrics().height());
568 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
570 qDebug() << __PRETTY_FUNCTION__;
572 if (m_ownLocationCrosshair != 0) {
573 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
574 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
578 void MainWindow::errorDialogFinished(int status)
580 qDebug() << __PRETTY_FUNCTION__;
583 QDialog *dialog = m_error_queue.takeFirst();
585 dialog->deleteLater();
586 m_errorShown = false;
588 if(!m_error_queue.isEmpty())
589 showErrorInformationBox();
590 else if(!m_queue.isEmpty())
591 showInformationBox();
594 void MainWindow::gpsTimeout()
596 qDebug() << __PRETTY_FUNCTION__;
598 buildInformationBox(tr("GPS timeout"));
601 void MainWindow::grabZoomKeys(bool grab)
603 qDebug() << __PRETTY_FUNCTION__;
606 // Can't grab keys unless we have a window id
610 unsigned long val = (grab) ? 1 : 0;
611 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
615 XChangeProperty (QX11Info::display(),
621 reinterpret_cast<unsigned char *>(&val),
625 #endif // Q_WS_MAEMO_5
628 void MainWindow::keyPressEvent(QKeyEvent* event)
630 qDebug() << __PRETTY_FUNCTION__;
632 switch (event->key()) {
643 QWidget::keyPressEvent(event);
646 void MainWindow::loadCookies()
648 qDebug() << __PRETTY_FUNCTION__;
650 QSettings settings(DIRECTORY_NAME, FILE_NAME);
652 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
654 if(!list.isEmpty()) {
655 QList<QNetworkCookie> cookieList;
656 for(int i=0;i<list.count();i++) {
657 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
661 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
663 m_cookieJar->setAllCookies(cookieList);
664 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
668 void MainWindow::loadDone(bool done)
670 qDebug() << __PRETTY_FUNCTION__;
672 // for the first time the login page is opened, we need to refresh it to get cookies working
680 QWebFrame* frame = m_webView->page()->currentFrame();
684 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
686 foreach (QWebElement element, emailCollection) {
687 element.setAttribute("value", m_email.toAscii());
690 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
691 foreach (QWebElement element, passwordCollection) {
692 element.setAttribute("value", m_password.toAscii());
694 // find connect button
695 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
696 foreach (QWebElement element, buttonCollection)
698 QPoint pos(element.geometry().center());
700 // send a mouse click event to the web page
701 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
703 QApplication::sendEvent(m_webView->page(), &event0);
704 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
706 QApplication::sendEvent(m_webView->page(), &event1);
712 void MainWindow::loggedIn(bool logged)
714 qDebug() << __PRETTY_FUNCTION__;
719 m_loginAct->setText(tr("Logout"));
725 m_loginAct->setText(tr("Login"));
727 updateItemVisibility();
730 void MainWindow::loginFailed()
732 qDebug() << __PRETTY_FUNCTION__;
738 bool MainWindow::loginState()
740 qDebug() << __PRETTY_FUNCTION__;
745 void MainWindow::loginUsingCookies()
747 qDebug() << __PRETTY_FUNCTION__;
749 toggleProgressIndicator(true);
754 QStringList urlParts;
755 urlParts.append(FACEBOOK_LOGINBASE);
756 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
757 urlParts.append(INTERVAL1);
758 urlParts.append(SITUARE_LOGIN_SUCCESS);
759 urlParts.append(INTERVAL2);
760 urlParts.append(SITUARE_LOGIN_FAILURE);
761 urlParts.append(FACEBOOK_LOGIN_ENDING);
763 m_webView->load(QUrl(urlParts.join(EMPTY)));
767 void MainWindow::openSettingsDialog()
769 qDebug() << __PRETTY_FUNCTION__;
771 SettingsDialog *settingsDialog = new SettingsDialog(this);
772 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
773 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
775 settingsDialog->show();
778 void MainWindow::readAutomaticLocationUpdateSettings()
780 qDebug() << __PRETTY_FUNCTION__;
782 QSettings settings(DIRECTORY_NAME, FILE_NAME);
783 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
784 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
787 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
789 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
791 emit enableAutomaticLocationUpdate(false);
795 void MainWindow::queueDialog(QDialog *dialog)
797 qDebug() << __PRETTY_FUNCTION__;
799 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
800 if(dialog->isModal()) {
801 m_error_queue.append(dialog);
803 m_queue.append(dialog);
806 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
807 if(m_error_queue.count() == 1 && m_errorShown == false)
808 showErrorInformationBox();
809 else if(m_queue.count() == 1 && m_errorShown == false)
810 showInformationBox();
813 void MainWindow::saveCookies()
815 qDebug() << __PRETTY_FUNCTION__;
818 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
820 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
823 for(int i=0;i<cookieList.count();i++) {
824 QNetworkCookie cookie = cookieList.at(i);
825 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
826 list.append(QString(byteArray));
828 list.removeDuplicates();
830 QSettings settings(DIRECTORY_NAME, FILE_NAME);
831 settings.setValue(COOKIES, list);
834 void MainWindow::setGPSButtonEnabled(bool enabled)
836 qDebug() << __PRETTY_FUNCTION__;
838 m_gpsToggleAct->setChecked(enabled);
841 void MainWindow::setIndicatorButtonEnabled(bool enabled)
843 qDebug() << __PRETTY_FUNCTION__;
845 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
848 void MainWindow::setMapViewScene(QGraphicsScene *scene)
850 qDebug() << __PRETTY_FUNCTION__;
852 m_mapView->setScene(scene);
855 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
857 qDebug() << __PRETTY_FUNCTION__;
860 m_ownLocationCrosshair->show();
861 drawOwnLocationCrosshair(m_viewPortSize);
863 m_ownLocationCrosshair->hide();
867 void MainWindow::settingsDialogAccepted()
869 qDebug() << __PRETTY_FUNCTION__;
871 readAutomaticLocationUpdateSettings();
874 void MainWindow::setUsername(const QString &username)
876 qDebug() << __PRETTY_FUNCTION__;
881 void MainWindow::setViewPortSize(const QSize &size)
883 qDebug() << __PRETTY_FUNCTION__;
885 m_viewPortSize = size;
888 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
890 qDebug() << __PRETTY_FUNCTION__;
892 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
893 tr("Automatic location update"), text,
894 QMessageBox::Yes | QMessageBox::No |
895 QMessageBox::Cancel, this);
896 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
897 this, SLOT(automaticUpdateDialogFinished(int)));
899 m_automaticUpdateLocationDialog->show();
902 void MainWindow::toggleFullScreen()
904 qDebug() << __PRETTY_FUNCTION__;
906 if(windowState() == Qt::WindowNoState)
912 void MainWindow::showErrorInformationBox()
914 qDebug() << __PRETTY_FUNCTION__;
916 if(m_error_queue.count()) {
918 QDialog *dialog = m_error_queue.first();
919 connect(dialog, SIGNAL(finished(int)),
920 this, SLOT(errorDialogFinished(int)));
925 void MainWindow::showInformationBox()
927 qDebug() << __PRETTY_FUNCTION__;
929 if(m_queue.count()) {
930 QDialog *dialog = m_queue.first();
931 connect(dialog, SIGNAL(finished(int)),
932 this, SLOT(dialogFinished(int)));
937 void MainWindow::showPanels()
939 qDebug() << __PRETTY_FUNCTION__;
941 drawFullScreenButton(m_viewPortSize);
944 // if(!m_friendsListPanel->isVisible()) {
945 // m_friendsListPanel->show();
946 // m_friendsListPanelSidebar->show();
949 // if(!m_userPanel->isVisible()) {
950 // m_userPanel->show();
951 // m_userPanelSidebar->show();
956 void MainWindow::startLocationSearch()
958 qDebug() << __PRETTY_FUNCTION__;
960 SearchDialog *searchDialog = new SearchDialog();
961 queueDialog(searchDialog);
964 void MainWindow::startLoginProcess()
966 qDebug() << __PRETTY_FUNCTION__;
968 LoginDialog *loginDialog = new LoginDialog();
970 emit fetchUsernameFromSettings();
972 loginDialog->clearTextFields();
974 if(!m_email.isEmpty())
975 loginDialog->setEmailField(m_email);
977 queueDialog(loginDialog);
980 void MainWindow::toggleProgressIndicator(bool value)
982 qDebug() << __PRETTY_FUNCTION__;
986 m_progressIndicatorCount++;
987 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
989 if(m_progressIndicatorCount > 0)
990 m_progressIndicatorCount--;
992 if(m_progressIndicatorCount == 0)
993 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
997 #endif // Q_WS_MAEMO_5
1000 void MainWindow::updateItemVisibility()
1002 qDebug() << __PRETTY_FUNCTION__;
1004 // if(!m_loggedIn) {
1005 // m_friendsListPanel->closePanel();
1006 // m_friendsListPanel->hide();
1007 // m_friendsListPanelSidebar->hide();
1009 // m_userPanel->closePanel();
1010 // m_userPanel->hide();
1011 // m_userPanelSidebar->hide();
1015 const QString MainWindow::username()
1017 qDebug() << __PRETTY_FUNCTION__;
1022 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1024 qDebug() << __PRETTY_FUNCTION__;
1026 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1027 // qwebview starts to load a new page while the current page loading is not finished
1028 if(reply->error() != QNetworkReply::OperationCanceledError &&
1029 reply->error() != QNetworkReply::NoError) {
1030 emit error(ErrorContext::NETWORK, reply->error());