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(findFriend(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&)));
352 void MainWindow::buildUserInfoPanel()
354 qDebug() << __PRETTY_FUNCTION__;
356 m_userInfoPanel = new UserInfoPanel(this);
358 connect(this, SIGNAL(userLocationReady(User*)),
359 m_userInfoPanel, SLOT(userDataReceived(User*)));
361 connect(this, SIGNAL(reverseGeoReady(QString)),
362 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
364 connect(this, SIGNAL(clearUpdateLocationDialogData()),
365 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
367 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
368 this, SIGNAL(findUser(GeoCoordinate)));
370 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
371 this, SIGNAL(requestReverseGeo()));
373 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
374 this, SIGNAL(statusUpdate(QString,bool)));
376 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
377 this, SIGNAL(refreshUserData()));
379 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
380 this, SLOT(buildInformationBox(QString, bool)));
383 void MainWindow::buildWebView()
385 qDebug() << __PRETTY_FUNCTION__;
388 m_webView = new QWebView;
391 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
393 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
395 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
396 this, SLOT(webViewRequestFinished(QNetworkReply*)));
397 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
398 this, SIGNAL(updateCredentials(QUrl)));
399 connect(m_webView, SIGNAL(loadFinished(bool)),
400 this, SLOT(loadDone(bool)));
406 void MainWindow::buildZoomButtonPanel()
408 qDebug() << __PRETTY_FUNCTION__;
410 m_zoomButtonPanel = new ZoomButtonPanel(this);
412 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
413 this, SIGNAL(zoomIn()));
415 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
416 this, SIGNAL(zoomOut()));
418 connect(this, SIGNAL(zoomLevelChanged(int)),
419 m_zoomButtonPanel, SLOT(resetButtons()));
421 connect(this, SIGNAL(maxZoomLevelReached()),
422 m_zoomButtonPanel, SLOT(disableZoomInButton()));
424 connect(this, SIGNAL(minZoomLevelReached()),
425 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
427 connect(m_mapView, SIGNAL(viewResized(QSize)),
428 m_zoomButtonPanel, SLOT(screenResized(QSize)));
430 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
431 this, SIGNAL(draggingModeTriggered()));
434 void MainWindow::clearCookieJar()
436 qDebug() << __PRETTY_FUNCTION__;
443 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
445 QList<QNetworkCookie> emptyList;
448 m_cookieJar->setAllCookies(emptyList);
449 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
452 void MainWindow::createMenus()
454 qDebug() << __PRETTY_FUNCTION__;
457 m_loginAct = new QAction(tr("Login"), this);
458 connect(m_loginAct, SIGNAL(triggered()),
459 this, SIGNAL(loginActionPressed()));
462 m_toSettingsAct = new QAction(tr("Settings"), this);
463 connect(m_toSettingsAct, SIGNAL(triggered()),
464 this, SLOT(openSettingsDialog()));
467 m_gpsToggleAct = new QAction(tr("GPS"), this);
468 m_gpsToggleAct->setCheckable(true);
470 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
471 this, SIGNAL(gpsTriggered(bool)));
473 /// @todo remove when not needed!
474 m_searchLocationAct = new QAction(tr("Location search"), this);
475 connect(m_searchLocationAct, SIGNAL(triggered()),
476 this, SLOT(startLocationSearch()));
478 // build the actual menu
479 m_viewMenu = menuBar()->addMenu(tr("Main"));
480 m_viewMenu->addAction(m_loginAct);
481 m_viewMenu->addAction(m_toSettingsAct);
482 m_viewMenu->addAction(m_gpsToggleAct);
483 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
484 m_viewMenu->setObjectName(tr("Menu"));
487 void MainWindow::dialogFinished(int status)
489 qDebug() << __PRETTY_FUNCTION__;
491 QDialog *dialog = m_queue.takeFirst();
492 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
493 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
497 loginDialog->userInput(m_email, m_password);
499 QStringList urlParts;
500 urlParts.append(FACEBOOK_LOGINBASE);
501 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
502 urlParts.append(INTERVAL1);
503 urlParts.append(SITUARE_LOGIN_SUCCESS);
504 urlParts.append(INTERVAL2);
505 urlParts.append(SITUARE_LOGIN_FAILURE);
506 urlParts.append(FACEBOOK_LOGIN_ENDING);
508 emit saveUsername(m_email);
510 m_webView->load(QUrl(urlParts.join(EMPTY)));
511 toggleProgressIndicator(true);
513 emit cancelLoginProcess();
515 } else if(searchDialog) {
517 emit searchForLocation(searchDialog->input());
521 dialog->deleteLater();
523 if(!m_error_queue.isEmpty() && m_errorShown == false) {
524 showErrorInformationBox();
526 if(!m_queue.isEmpty()) {
527 showInformationBox();
532 void MainWindow::drawFullScreenButton(const QSize &size)
534 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
536 if(m_fullScreenButton)
537 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
538 size.height() - m_fullScreenButton->size().height());
541 void MainWindow::drawMapScale(const QSize &size)
543 qDebug() << __PRETTY_FUNCTION__;
545 const int LEFT_SCALE_MARGIN = 10;
546 const int BOTTOM_SCALE_MARGIN = 2;
547 // qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
549 m_mapScale->move(LEFT_SCALE_MARGIN,
550 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
553 void MainWindow::drawOsmLicense(const QSize &size)
555 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
557 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
559 size.height() - m_osmLicense->fontMetrics().height());
562 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
564 qDebug() << __PRETTY_FUNCTION__;
566 if (m_ownLocationCrosshair != 0) {
567 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
568 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
572 void MainWindow::errorDialogFinished(int status)
574 qDebug() << __PRETTY_FUNCTION__;
577 QDialog *dialog = m_error_queue.takeFirst();
579 dialog->deleteLater();
580 m_errorShown = false;
582 if(!m_error_queue.isEmpty())
583 showErrorInformationBox();
584 else if(!m_queue.isEmpty())
585 showInformationBox();
588 void MainWindow::gpsTimeout()
590 qDebug() << __PRETTY_FUNCTION__;
592 buildInformationBox(tr("GPS timeout"));
595 void MainWindow::grabZoomKeys(bool grab)
597 qDebug() << __PRETTY_FUNCTION__;
600 // Can't grab keys unless we have a window id
604 unsigned long val = (grab) ? 1 : 0;
605 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
609 XChangeProperty (QX11Info::display(),
615 reinterpret_cast<unsigned char *>(&val),
619 #endif // Q_WS_MAEMO_5
622 void MainWindow::keyPressEvent(QKeyEvent* event)
624 qDebug() << __PRETTY_FUNCTION__;
626 switch (event->key()) {
637 QWidget::keyPressEvent(event);
640 void MainWindow::loadCookies()
642 qDebug() << __PRETTY_FUNCTION__;
644 QSettings settings(DIRECTORY_NAME, FILE_NAME);
646 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
648 if(!list.isEmpty()) {
649 QList<QNetworkCookie> cookieList;
650 for(int i=0;i<list.count();i++) {
651 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
655 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
657 m_cookieJar->setAllCookies(cookieList);
658 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
662 void MainWindow::loadDone(bool done)
664 qDebug() << __PRETTY_FUNCTION__;
666 // for the first time the login page is opened, we need to refresh it to get cookies working
674 QWebFrame* frame = m_webView->page()->currentFrame();
678 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
680 foreach (QWebElement element, emailCollection) {
681 element.setAttribute("value", m_email.toAscii());
684 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
685 foreach (QWebElement element, passwordCollection) {
686 element.setAttribute("value", m_password.toAscii());
688 // find connect button
689 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
690 foreach (QWebElement element, buttonCollection)
692 QPoint pos(element.geometry().center());
694 // send a mouse click event to the web page
695 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
697 QApplication::sendEvent(m_webView->page(), &event0);
698 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
700 QApplication::sendEvent(m_webView->page(), &event1);
706 void MainWindow::loggedIn(bool logged)
708 qDebug() << __PRETTY_FUNCTION__;
713 m_loginAct->setText(tr("Logout"));
719 m_loginAct->setText(tr("Login"));
721 updateItemVisibility();
724 void MainWindow::loginFailed()
726 qDebug() << __PRETTY_FUNCTION__;
732 bool MainWindow::loginState()
734 qDebug() << __PRETTY_FUNCTION__;
739 void MainWindow::loginUsingCookies()
741 qDebug() << __PRETTY_FUNCTION__;
743 toggleProgressIndicator(true);
748 QStringList urlParts;
749 urlParts.append(FACEBOOK_LOGINBASE);
750 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
751 urlParts.append(INTERVAL1);
752 urlParts.append(SITUARE_LOGIN_SUCCESS);
753 urlParts.append(INTERVAL2);
754 urlParts.append(SITUARE_LOGIN_FAILURE);
755 urlParts.append(FACEBOOK_LOGIN_ENDING);
757 m_webView->load(QUrl(urlParts.join(EMPTY)));
761 void MainWindow::openSettingsDialog()
763 qDebug() << __PRETTY_FUNCTION__;
765 SettingsDialog *settingsDialog = new SettingsDialog(this);
766 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
767 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
769 settingsDialog->show();
772 void MainWindow::readAutomaticLocationUpdateSettings()
774 qDebug() << __PRETTY_FUNCTION__;
776 QSettings settings(DIRECTORY_NAME, FILE_NAME);
777 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
778 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
781 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
783 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
785 emit enableAutomaticLocationUpdate(false);
789 void MainWindow::queueDialog(QDialog *dialog)
791 qDebug() << __PRETTY_FUNCTION__;
793 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
794 if(dialog->isModal()) {
795 m_error_queue.append(dialog);
797 m_queue.append(dialog);
800 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
801 if(m_error_queue.count() == 1 && m_errorShown == false)
802 showErrorInformationBox();
803 else if(m_queue.count() == 1 && m_errorShown == false)
804 showInformationBox();
807 void MainWindow::saveCookies()
809 qDebug() << __PRETTY_FUNCTION__;
812 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
814 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
817 for(int i=0;i<cookieList.count();i++) {
818 QNetworkCookie cookie = cookieList.at(i);
819 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
820 list.append(QString(byteArray));
822 list.removeDuplicates();
824 QSettings settings(DIRECTORY_NAME, FILE_NAME);
825 settings.setValue(COOKIES, list);
828 void MainWindow::setGPSButtonEnabled(bool enabled)
830 qDebug() << __PRETTY_FUNCTION__;
832 m_gpsToggleAct->setChecked(enabled);
835 void MainWindow::setIndicatorButtonEnabled(bool enabled)
837 qDebug() << __PRETTY_FUNCTION__;
839 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
842 void MainWindow::setMapViewScene(QGraphicsScene *scene)
844 qDebug() << __PRETTY_FUNCTION__;
846 m_mapView->setScene(scene);
849 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
851 qDebug() << __PRETTY_FUNCTION__;
854 m_ownLocationCrosshair->show();
855 drawOwnLocationCrosshair(m_viewPortSize);
857 m_ownLocationCrosshair->hide();
861 void MainWindow::settingsDialogAccepted()
863 qDebug() << __PRETTY_FUNCTION__;
865 readAutomaticLocationUpdateSettings();
868 void MainWindow::setUsername(const QString &username)
870 qDebug() << __PRETTY_FUNCTION__;
875 void MainWindow::setViewPortSize(const QSize &size)
877 qDebug() << __PRETTY_FUNCTION__;
879 m_viewPortSize = size;
882 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
884 qDebug() << __PRETTY_FUNCTION__;
886 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
887 tr("Automatic location update"), text,
888 QMessageBox::Yes | QMessageBox::No |
889 QMessageBox::Cancel, this);
890 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
891 this, SLOT(automaticUpdateDialogFinished(int)));
893 m_automaticUpdateLocationDialog->show();
896 void MainWindow::toggleFullScreen()
898 qDebug() << __PRETTY_FUNCTION__;
900 if(windowState() == Qt::WindowNoState)
906 void MainWindow::showErrorInformationBox()
908 qDebug() << __PRETTY_FUNCTION__;
910 if(m_error_queue.count()) {
912 QDialog *dialog = m_error_queue.first();
913 connect(dialog, SIGNAL(finished(int)),
914 this, SLOT(errorDialogFinished(int)));
919 void MainWindow::showInformationBox()
921 qDebug() << __PRETTY_FUNCTION__;
923 if(m_queue.count()) {
924 QDialog *dialog = m_queue.first();
925 connect(dialog, SIGNAL(finished(int)),
926 this, SLOT(dialogFinished(int)));
931 void MainWindow::showPanels()
933 qDebug() << __PRETTY_FUNCTION__;
935 drawFullScreenButton(m_viewPortSize);
938 // if(!m_friendsListPanel->isVisible()) {
939 // m_friendsListPanel->show();
940 // m_friendsListPanelSidebar->show();
943 // if(!m_userPanel->isVisible()) {
944 // m_userPanel->show();
945 // m_userPanelSidebar->show();
950 void MainWindow::startLocationSearch()
952 qDebug() << __PRETTY_FUNCTION__;
954 SearchDialog *searchDialog = new SearchDialog();
955 queueDialog(searchDialog);
958 void MainWindow::startLoginProcess()
960 qDebug() << __PRETTY_FUNCTION__;
962 LoginDialog *loginDialog = new LoginDialog();
964 emit fetchUsernameFromSettings();
966 loginDialog->clearTextFields();
968 if(!m_email.isEmpty())
969 loginDialog->setEmailField(m_email);
971 queueDialog(loginDialog);
974 void MainWindow::toggleProgressIndicator(bool value)
976 qDebug() << __PRETTY_FUNCTION__;
980 m_progressIndicatorCount++;
981 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
983 if(m_progressIndicatorCount > 0)
984 m_progressIndicatorCount--;
986 if(m_progressIndicatorCount == 0)
987 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
991 #endif // Q_WS_MAEMO_5
994 void MainWindow::updateItemVisibility()
996 qDebug() << __PRETTY_FUNCTION__;
999 // m_friendsListPanel->closePanel();
1000 // m_friendsListPanel->hide();
1001 // m_friendsListPanelSidebar->hide();
1003 // m_userPanel->closePanel();
1004 // m_userPanel->hide();
1005 // m_userPanelSidebar->hide();
1009 const QString MainWindow::username()
1011 qDebug() << __PRETTY_FUNCTION__;
1016 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1018 qDebug() << __PRETTY_FUNCTION__;
1020 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1021 // qwebview starts to load a new page while the current page loading is not finished
1022 if(reply->error() != QNetworkReply::OperationCanceledError &&
1023 reply->error() != QNetworkReply::NoError) {
1024 emit error(ErrorContext::NETWORK, reply->error());