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*)));
181 void MainWindow::buildIndicatorButtonPanel()
183 qDebug() << __PRETTY_FUNCTION__;
185 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
187 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
188 this, SIGNAL(autoCenteringTriggered(bool)));
190 connect(m_mapView, SIGNAL(viewResized(QSize)),
191 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
193 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
194 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
196 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
197 this, SIGNAL(draggingModeTriggered()));
200 void MainWindow::buildInformationBox(const QString &message, bool modal)
202 qDebug() << __PRETTY_FUNCTION__;
204 QString errorMessage = message;
208 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
211 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
212 // extra line changes are needed to make error notes broader
213 errorMessage.prepend("\n");
214 errorMessage.append("\n");
216 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
218 QLabel *label = new QLabel(msgBox);
219 label->setAlignment(Qt::AlignCenter);
220 label->setText(errorMessage);
221 msgBox->setWidget(label);
223 QMessageBox *msgBox = new QMessageBox(this);
224 msgBox->button(QMessageBox::Ok);
225 msgBox->setText(errorMessage);
226 msgBox->setModal(modal);
232 void MainWindow::buildManualLocationCrosshair()
234 qDebug() << __PRETTY_FUNCTION__;
236 m_ownLocationCrosshair = new QLabel(this);
237 QPixmap crosshairImage(":/res/images/sight.png");
238 m_ownLocationCrosshair->setPixmap(crosshairImage);
239 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
240 m_ownLocationCrosshair->hide();
241 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
243 connect(m_mapView, SIGNAL(viewResized(QSize)),
244 this, SLOT(drawOwnLocationCrosshair(QSize)));
247 void MainWindow::buildMap()
249 qDebug() << __PRETTY_FUNCTION__;
251 m_mapView = new MapView(this);
253 buildZoomButtonPanel();
255 buildManualLocationCrosshair();
256 buildFullScreenButton();
257 buildIndicatorButtonPanel();
260 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
261 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
263 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
264 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
266 connect(m_mapView, SIGNAL(viewResized(QSize)),
267 this, SIGNAL(mapViewResized(QSize)));
269 connect(m_mapView, SIGNAL(viewResized(QSize)),
270 this, SLOT(drawFullScreenButton(QSize)));
272 connect(m_mapView, SIGNAL(viewResized(QSize)),
273 this, SLOT(drawMapScale(QSize)));
275 connect(m_mapView, SIGNAL(viewResized(QSize)),
276 this, SLOT(setViewPortSize(QSize)));
278 connect(this, SIGNAL(zoomLevelChanged(int)),
279 m_mapView, SLOT(setZoomLevel(int)));
281 connect(m_mapView, SIGNAL(viewZoomFinished()),
282 this, SIGNAL(viewZoomFinished()));
284 connect(m_mapView, SIGNAL(zoomIn()),
285 this, SIGNAL(zoomIn()));
288 void MainWindow::buildMapScale()
290 m_mapScale = new MapScale(this);
291 connect(this, SIGNAL(newMapResolution(qreal)),
292 m_mapScale, SLOT(updateMapResolution(qreal)));
295 void MainWindow::buildOsmLicense()
297 qDebug() << __PRETTY_FUNCTION__;
299 m_osmLicense = new QLabel(this);
300 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
301 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
302 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
303 m_osmLicense->setFont(QFont("Nokia Sans", 9));
304 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
305 m_osmLicense->fontMetrics().height());
307 connect(m_mapView, SIGNAL(viewResized(QSize)),
308 this, SLOT(drawOsmLicense(QSize)));
311 void MainWindow::buildPanels()
313 qDebug() << __PRETTY_FUNCTION__;
315 buildUserInfoPanel();
316 buildFriendListPanel();
319 m_tabbedPanel = new TabbedPanel(this);
320 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
321 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
322 m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
324 connect(m_tabbedPanel, SIGNAL(tabChanged()),
325 m_friendsListPanel, SLOT(clearFriendListFilter()));
327 connect(m_mapView, SIGNAL(viewResized(QSize)),
328 m_tabbedPanel, SLOT(resizePanel(QSize)));
331 void MainWindow::buildRoutingPanel()
333 qDebug() << __PRETTY_FUNCTION__;
335 m_routingPanel = new RoutingPanel(this);
337 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
338 m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
340 connect(m_routingPanel,
341 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
343 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
346 void MainWindow::buildUserInfoPanel()
348 qDebug() << __PRETTY_FUNCTION__;
350 m_userInfoPanel = new UserInfoPanel(this);
352 connect(this, SIGNAL(userLocationReady(User*)),
353 m_userInfoPanel, SLOT(userDataReceived(User*)));
355 connect(this, SIGNAL(reverseGeoReady(QString)),
356 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
358 connect(this, SIGNAL(clearUpdateLocationDialogData()),
359 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
361 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
362 this, SIGNAL(findUser(GeoCoordinate)));
364 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
365 this, SIGNAL(requestReverseGeo()));
367 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
368 this, SIGNAL(statusUpdate(QString,bool)));
370 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
371 this, SIGNAL(refreshUserData()));
373 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
374 this, SLOT(buildInformationBox(QString, bool)));
377 void MainWindow::buildWebView()
379 qDebug() << __PRETTY_FUNCTION__;
382 m_webView = new QWebView;
385 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
387 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
389 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
390 this, SLOT(webViewRequestFinished(QNetworkReply*)));
391 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
392 this, SIGNAL(updateCredentials(QUrl)));
393 connect(m_webView, SIGNAL(loadFinished(bool)),
394 this, SLOT(loadDone(bool)));
400 void MainWindow::buildZoomButtonPanel()
402 qDebug() << __PRETTY_FUNCTION__;
404 m_zoomButtonPanel = new ZoomButtonPanel(this);
406 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
407 this, SIGNAL(zoomIn()));
409 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
410 this, SIGNAL(zoomOut()));
412 connect(this, SIGNAL(zoomLevelChanged(int)),
413 m_zoomButtonPanel, SLOT(resetButtons()));
415 connect(this, SIGNAL(maxZoomLevelReached()),
416 m_zoomButtonPanel, SLOT(disableZoomInButton()));
418 connect(this, SIGNAL(minZoomLevelReached()),
419 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
421 connect(m_mapView, SIGNAL(viewResized(QSize)),
422 m_zoomButtonPanel, SLOT(screenResized(QSize)));
424 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
425 this, SIGNAL(draggingModeTriggered()));
428 void MainWindow::clearCookieJar()
430 qDebug() << __PRETTY_FUNCTION__;
437 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
439 QList<QNetworkCookie> emptyList;
442 m_cookieJar->setAllCookies(emptyList);
443 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
446 void MainWindow::createMenus()
448 qDebug() << __PRETTY_FUNCTION__;
451 m_loginAct = new QAction(tr("Login"), this);
452 connect(m_loginAct, SIGNAL(triggered()),
453 this, SIGNAL(loginActionPressed()));
456 m_toSettingsAct = new QAction(tr("Settings"), this);
457 connect(m_toSettingsAct, SIGNAL(triggered()),
458 this, SLOT(openSettingsDialog()));
461 m_gpsToggleAct = new QAction(tr("GPS"), this);
462 m_gpsToggleAct->setCheckable(true);
464 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
465 this, SIGNAL(gpsTriggered(bool)));
467 /// @todo remove when not needed!
468 m_searchLocationAct = new QAction(tr("Location search"), this);
469 connect(m_searchLocationAct, SIGNAL(triggered()),
470 this, SLOT(startLocationSearch()));
472 // build the actual menu
473 m_viewMenu = menuBar()->addMenu(tr("Main"));
474 m_viewMenu->addAction(m_loginAct);
475 m_viewMenu->addAction(m_toSettingsAct);
476 m_viewMenu->addAction(m_gpsToggleAct);
477 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
478 m_viewMenu->setObjectName(tr("Menu"));
481 void MainWindow::dialogFinished(int status)
483 qDebug() << __PRETTY_FUNCTION__;
485 QDialog *dialog = m_queue.takeFirst();
486 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
487 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
491 loginDialog->userInput(m_email, m_password);
493 QStringList urlParts;
494 urlParts.append(FACEBOOK_LOGINBASE);
495 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
496 urlParts.append(INTERVAL1);
497 urlParts.append(SITUARE_LOGIN_SUCCESS);
498 urlParts.append(INTERVAL2);
499 urlParts.append(SITUARE_LOGIN_FAILURE);
500 urlParts.append(FACEBOOK_LOGIN_ENDING);
502 emit saveUsername(m_email);
504 m_webView->load(QUrl(urlParts.join(EMPTY)));
505 toggleProgressIndicator(true);
507 emit cancelLoginProcess();
509 } else if(searchDialog) {
511 emit searchForLocation(searchDialog->input());
515 dialog->deleteLater();
517 if(!m_error_queue.isEmpty() && m_errorShown == false) {
518 showErrorInformationBox();
520 if(!m_queue.isEmpty()) {
521 showInformationBox();
526 void MainWindow::drawFullScreenButton(const QSize &size)
528 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
530 if(m_fullScreenButton)
531 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
532 size.height() - m_fullScreenButton->size().height());
535 void MainWindow::drawMapScale(const QSize &size)
537 qDebug() << __PRETTY_FUNCTION__;
539 const int LEFT_SCALE_MARGIN = 10;
540 const int BOTTOM_SCALE_MARGIN = 2;
541 // qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
543 m_mapScale->move(LEFT_SCALE_MARGIN,
544 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
547 void MainWindow::drawOsmLicense(const QSize &size)
549 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
551 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
553 size.height() - m_osmLicense->fontMetrics().height());
556 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
558 qDebug() << __PRETTY_FUNCTION__;
560 if (m_ownLocationCrosshair != 0) {
561 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
562 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
566 void MainWindow::errorDialogFinished(int status)
568 qDebug() << __PRETTY_FUNCTION__;
571 QDialog *dialog = m_error_queue.takeFirst();
573 dialog->deleteLater();
574 m_errorShown = false;
576 if(!m_error_queue.isEmpty())
577 showErrorInformationBox();
578 else if(!m_queue.isEmpty())
579 showInformationBox();
582 void MainWindow::gpsTimeout()
584 qDebug() << __PRETTY_FUNCTION__;
586 buildInformationBox(tr("GPS timeout"));
589 void MainWindow::grabZoomKeys(bool grab)
591 qDebug() << __PRETTY_FUNCTION__;
594 // Can't grab keys unless we have a window id
598 unsigned long val = (grab) ? 1 : 0;
599 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
603 XChangeProperty (QX11Info::display(),
609 reinterpret_cast<unsigned char *>(&val),
613 #endif // Q_WS_MAEMO_5
616 void MainWindow::keyPressEvent(QKeyEvent* event)
618 qDebug() << __PRETTY_FUNCTION__;
620 switch (event->key()) {
631 QWidget::keyPressEvent(event);
634 void MainWindow::loadCookies()
636 qDebug() << __PRETTY_FUNCTION__;
638 QSettings settings(DIRECTORY_NAME, FILE_NAME);
640 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
642 if(!list.isEmpty()) {
643 QList<QNetworkCookie> cookieList;
644 for(int i=0;i<list.count();i++) {
645 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
649 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
651 m_cookieJar->setAllCookies(cookieList);
652 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
656 void MainWindow::loadDone(bool done)
658 qDebug() << __PRETTY_FUNCTION__;
660 // for the first time the login page is opened, we need to refresh it to get cookies working
668 QWebFrame* frame = m_webView->page()->currentFrame();
672 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
674 foreach (QWebElement element, emailCollection) {
675 element.setAttribute("value", m_email.toAscii());
678 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
679 foreach (QWebElement element, passwordCollection) {
680 element.setAttribute("value", m_password.toAscii());
682 // find connect button
683 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
684 foreach (QWebElement element, buttonCollection)
686 QPoint pos(element.geometry().center());
688 // send a mouse click event to the web page
689 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
691 QApplication::sendEvent(m_webView->page(), &event0);
692 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
694 QApplication::sendEvent(m_webView->page(), &event1);
700 void MainWindow::loggedIn(bool logged)
702 qDebug() << __PRETTY_FUNCTION__;
707 m_loginAct->setText(tr("Logout"));
713 m_loginAct->setText(tr("Login"));
715 updateItemVisibility();
718 void MainWindow::loginFailed()
720 qDebug() << __PRETTY_FUNCTION__;
726 bool MainWindow::loginState()
728 qDebug() << __PRETTY_FUNCTION__;
733 void MainWindow::loginUsingCookies()
735 qDebug() << __PRETTY_FUNCTION__;
737 toggleProgressIndicator(true);
742 QStringList urlParts;
743 urlParts.append(FACEBOOK_LOGINBASE);
744 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
745 urlParts.append(INTERVAL1);
746 urlParts.append(SITUARE_LOGIN_SUCCESS);
747 urlParts.append(INTERVAL2);
748 urlParts.append(SITUARE_LOGIN_FAILURE);
749 urlParts.append(FACEBOOK_LOGIN_ENDING);
751 m_webView->load(QUrl(urlParts.join(EMPTY)));
755 void MainWindow::openSettingsDialog()
757 qDebug() << __PRETTY_FUNCTION__;
759 SettingsDialog *settingsDialog = new SettingsDialog(this);
760 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
761 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
763 settingsDialog->show();
766 void MainWindow::readAutomaticLocationUpdateSettings()
768 qDebug() << __PRETTY_FUNCTION__;
770 QSettings settings(DIRECTORY_NAME, FILE_NAME);
771 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
772 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
775 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
777 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
779 emit enableAutomaticLocationUpdate(false);
783 void MainWindow::queueDialog(QDialog *dialog)
785 qDebug() << __PRETTY_FUNCTION__;
787 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
788 if(dialog->isModal()) {
789 m_error_queue.append(dialog);
791 m_queue.append(dialog);
794 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
795 if(m_error_queue.count() == 1 && m_errorShown == false)
796 showErrorInformationBox();
797 else if(m_queue.count() == 1 && m_errorShown == false)
798 showInformationBox();
801 void MainWindow::saveCookies()
803 qDebug() << __PRETTY_FUNCTION__;
806 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
808 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
811 for(int i=0;i<cookieList.count();i++) {
812 QNetworkCookie cookie = cookieList.at(i);
813 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
814 list.append(QString(byteArray));
816 list.removeDuplicates();
818 QSettings settings(DIRECTORY_NAME, FILE_NAME);
819 settings.setValue(COOKIES, list);
822 void MainWindow::setGPSButtonEnabled(bool enabled)
824 qDebug() << __PRETTY_FUNCTION__;
826 m_gpsToggleAct->setChecked(enabled);
829 void MainWindow::setIndicatorButtonEnabled(bool enabled)
831 qDebug() << __PRETTY_FUNCTION__;
833 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
836 void MainWindow::setMapViewScene(QGraphicsScene *scene)
838 qDebug() << __PRETTY_FUNCTION__;
840 m_mapView->setScene(scene);
843 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
845 qDebug() << __PRETTY_FUNCTION__;
848 m_ownLocationCrosshair->show();
849 drawOwnLocationCrosshair(m_viewPortSize);
851 m_ownLocationCrosshair->hide();
855 void MainWindow::settingsDialogAccepted()
857 qDebug() << __PRETTY_FUNCTION__;
859 readAutomaticLocationUpdateSettings();
862 void MainWindow::setUsername(const QString &username)
864 qDebug() << __PRETTY_FUNCTION__;
869 void MainWindow::setViewPortSize(const QSize &size)
871 qDebug() << __PRETTY_FUNCTION__;
873 m_viewPortSize = size;
876 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
878 qDebug() << __PRETTY_FUNCTION__;
880 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
881 tr("Automatic location update"), text,
882 QMessageBox::Yes | QMessageBox::No |
883 QMessageBox::Cancel, this);
884 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
885 this, SLOT(automaticUpdateDialogFinished(int)));
887 m_automaticUpdateLocationDialog->show();
890 void MainWindow::toggleFullScreen()
892 qDebug() << __PRETTY_FUNCTION__;
894 if(windowState() == Qt::WindowNoState)
900 void MainWindow::showErrorInformationBox()
902 qDebug() << __PRETTY_FUNCTION__;
904 if(m_error_queue.count()) {
906 QDialog *dialog = m_error_queue.first();
907 connect(dialog, SIGNAL(finished(int)),
908 this, SLOT(errorDialogFinished(int)));
913 void MainWindow::showInformationBox()
915 qDebug() << __PRETTY_FUNCTION__;
917 if(m_queue.count()) {
918 QDialog *dialog = m_queue.first();
919 connect(dialog, SIGNAL(finished(int)),
920 this, SLOT(dialogFinished(int)));
925 void MainWindow::showPanels()
927 qDebug() << __PRETTY_FUNCTION__;
929 drawFullScreenButton(m_viewPortSize);
932 // if(!m_friendsListPanel->isVisible()) {
933 // m_friendsListPanel->show();
934 // m_friendsListPanelSidebar->show();
937 // if(!m_userPanel->isVisible()) {
938 // m_userPanel->show();
939 // m_userPanelSidebar->show();
944 void MainWindow::startLocationSearch()
946 qDebug() << __PRETTY_FUNCTION__;
948 SearchDialog *searchDialog = new SearchDialog();
949 queueDialog(searchDialog);
952 void MainWindow::startLoginProcess()
954 qDebug() << __PRETTY_FUNCTION__;
956 LoginDialog *loginDialog = new LoginDialog();
958 emit fetchUsernameFromSettings();
960 loginDialog->clearTextFields();
962 if(!m_email.isEmpty())
963 loginDialog->setEmailField(m_email);
965 queueDialog(loginDialog);
968 void MainWindow::toggleProgressIndicator(bool value)
970 qDebug() << __PRETTY_FUNCTION__;
974 m_progressIndicatorCount++;
975 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
977 if(m_progressIndicatorCount > 0)
978 m_progressIndicatorCount--;
980 if(m_progressIndicatorCount == 0)
981 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
985 #endif // Q_WS_MAEMO_5
988 void MainWindow::updateItemVisibility()
990 qDebug() << __PRETTY_FUNCTION__;
993 // m_friendsListPanel->closePanel();
994 // m_friendsListPanel->hide();
995 // m_friendsListPanelSidebar->hide();
997 // m_userPanel->closePanel();
998 // m_userPanel->hide();
999 // m_userPanelSidebar->hide();
1003 const QString MainWindow::username()
1005 qDebug() << __PRETTY_FUNCTION__;
1010 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1012 qDebug() << __PRETTY_FUNCTION__;
1014 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1015 // qwebview starts to load a new page while the current page loading is not finished
1016 if(reply->error() != QNetworkReply::OperationCanceledError &&
1017 reply->error() != QNetworkReply::NoError) {
1018 emit error(ErrorContext::NETWORK, reply->error());