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__;
82 // map view is the only widget which size & location is handled automatically by the system
83 // default functionality
84 setCentralWidget(m_mapView);
89 setWindowTitle(tr("Situare"));
91 // set stacking order of widgets (from top to bottom)
92 // if the fullscreen button exists, then it is the topmost one, otherwise the tabbed panel is
93 if (m_fullScreenButton) {
94 m_tabbedPanel->stackUnder(m_fullScreenButton);
96 m_ownLocationCrosshair->stackUnder(m_tabbedPanel);
97 m_zoomButtonPanel->stackUnder(m_ownLocationCrosshair);
98 m_indicatorButtonPanel->stackUnder(m_zoomButtonPanel);
99 m_osmLicense->stackUnder(m_indicatorButtonPanel);
100 m_mapScale->stackUnder(m_osmLicense);
101 m_mapView->stackUnder(m_mapScale);
105 // Set default screen size
106 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
108 setAttribute(Qt::WA_Maemo5StackedWindow);
112 MainWindow::~MainWindow()
114 qDebug() << __PRETTY_FUNCTION__;
121 qDeleteAll(m_queue.begin(), m_queue.end());
124 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
125 m_error_queue.clear();
128 void MainWindow::automaticUpdateDialogFinished(int result)
130 qDebug() << __PRETTY_FUNCTION__;
132 if (result == QMessageBox::Yes) {
133 readAutomaticLocationUpdateSettings();
135 QSettings settings(DIRECTORY_NAME, FILE_NAME);
136 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
137 readAutomaticLocationUpdateSettings();
140 m_automaticUpdateLocationDialog->deleteLater();
143 void MainWindow::buildFullScreenButton()
145 qDebug() << __PRETTY_FUNCTION__;
148 m_fullScreenButton = new FullScreenButton(this);
150 if (m_fullScreenButton) {
151 connect(m_fullScreenButton, SIGNAL(clicked()),
152 this, SLOT(toggleFullScreen()));
154 connect(qApp, SIGNAL(showFullScreenButton()),
155 m_fullScreenButton, SLOT(invoke()));
157 #endif // Q_WS_MAEMO_5
160 void MainWindow::buildFriendListPanel()
162 qDebug() << __PRETTY_FUNCTION__;
164 m_friendsListPanel = new FriendListPanel(this);
166 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
167 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
169 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
170 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
172 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
173 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
175 connect(this, SIGNAL(friendImageReady(User*)),
176 m_friendsListPanel, SLOT(friendImageReady(User*)));
178 connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
179 this, SIGNAL(routeTo(const GeoCoordinate&)));
182 void MainWindow::buildIndicatorButtonPanel()
184 qDebug() << __PRETTY_FUNCTION__;
186 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
188 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
189 this, SIGNAL(autoCenteringTriggered(bool)));
191 connect(m_mapView, SIGNAL(viewResized(QSize)),
192 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
194 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
195 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
197 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
198 this, SIGNAL(draggingModeTriggered()));
201 void MainWindow::buildInformationBox(const QString &message, bool modal)
203 qDebug() << __PRETTY_FUNCTION__;
205 QString errorMessage = message;
209 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
212 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
213 // extra line changes are needed to make error notes broader
214 errorMessage.prepend("\n");
215 errorMessage.append("\n");
217 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
219 QLabel *label = new QLabel(msgBox);
220 label->setAlignment(Qt::AlignCenter);
221 label->setText(errorMessage);
222 msgBox->setWidget(label);
224 QMessageBox *msgBox = new QMessageBox(this);
225 msgBox->button(QMessageBox::Ok);
226 msgBox->setText(errorMessage);
227 msgBox->setModal(modal);
233 void MainWindow::buildManualLocationCrosshair()
235 qDebug() << __PRETTY_FUNCTION__;
237 m_ownLocationCrosshair = new QLabel(this);
238 QPixmap crosshairImage(":/res/images/sight.png");
239 m_ownLocationCrosshair->setPixmap(crosshairImage);
240 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
241 m_ownLocationCrosshair->hide();
242 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
244 connect(m_mapView, SIGNAL(viewResized(QSize)),
245 this, SLOT(drawOwnLocationCrosshair(QSize)));
248 void MainWindow::buildMap()
250 qDebug() << __PRETTY_FUNCTION__;
252 m_mapView = new MapView(this);
254 buildZoomButtonPanel();
256 buildManualLocationCrosshair();
257 buildFullScreenButton();
258 buildIndicatorButtonPanel();
261 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
262 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
264 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
265 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
267 connect(m_mapView, SIGNAL(viewResized(QSize)),
268 this, SIGNAL(mapViewResized(QSize)));
270 connect(m_mapView, SIGNAL(viewResized(QSize)),
271 this, SLOT(drawFullScreenButton(QSize)));
273 connect(m_mapView, SIGNAL(viewResized(QSize)),
274 this, SLOT(drawMapScale(QSize)));
276 connect(m_mapView, SIGNAL(viewResized(QSize)),
277 this, SLOT(setViewPortSize(QSize)));
279 connect(this, SIGNAL(zoomLevelChanged(int)),
280 m_mapView, SLOT(setZoomLevel(int)));
282 connect(m_mapView, SIGNAL(viewZoomFinished()),
283 this, SIGNAL(viewZoomFinished()));
285 connect(m_mapView, SIGNAL(zoomIn()),
286 this, SIGNAL(zoomIn()));
289 void MainWindow::buildMapScale()
291 m_mapScale = new MapScale(this);
292 connect(this, SIGNAL(newMapResolution(qreal)),
293 m_mapScale, SLOT(updateMapResolution(qreal)));
296 void MainWindow::buildOsmLicense()
298 qDebug() << __PRETTY_FUNCTION__;
300 m_osmLicense = new QLabel(this);
301 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
302 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
303 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
304 m_osmLicense->setFont(QFont("Nokia Sans", 9));
305 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
306 m_osmLicense->fontMetrics().height());
308 connect(m_mapView, SIGNAL(viewResized(QSize)),
309 this, SLOT(drawOsmLicense(QSize)));
312 void MainWindow::buildPanels()
314 qDebug() << __PRETTY_FUNCTION__;
316 buildUserInfoPanel();
317 buildFriendListPanel();
320 m_tabbedPanel = new TabbedPanel(this);
321 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
322 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
323 m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
325 connect(m_mapView, SIGNAL(viewResized(QSize)),
326 m_tabbedPanel, SLOT(resizePanel(QSize)));
328 connect(m_friendsListPanel, SIGNAL(showPanelRequested(QWidget*)),
329 m_tabbedPanel, SLOT(showPanel(QWidget*)));
331 connect(m_routingPanel, SIGNAL(showPanelRequested(QWidget*)),
332 m_tabbedPanel, SLOT(showPanel(QWidget*)));
334 connect(m_tabbedPanel, SIGNAL(panelClosed()),
335 m_friendsListPanel, SLOT(anyPanelClosed()));
337 connect(m_tabbedPanel, SIGNAL(panelOpened()),
338 m_friendsListPanel, SLOT(anyPanelOpened()));
340 connect(m_tabbedPanel, SIGNAL(panelClosed()),
341 m_routingPanel, SLOT(clearListsSelections()));
344 void MainWindow::buildRoutingPanel()
346 qDebug() << __PRETTY_FUNCTION__;
348 m_routingPanel = new RoutingPanel(this);
350 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
351 m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
353 connect(m_routingPanel,
354 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
356 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
358 connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
359 this, SIGNAL(routeTo(const GeoCoordinate&)));
361 connect(this, SIGNAL(routeParsed(Route&)),
362 m_routingPanel, SLOT(setRoute(Route&)));
364 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
365 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
367 connect(m_routingPanel, SIGNAL(requestSearchLocation()),
368 this, SLOT(startLocationSearch()));
371 void MainWindow::buildUserInfoPanel()
373 qDebug() << __PRETTY_FUNCTION__;
375 m_userInfoPanel = new UserInfoPanel(this);
377 connect(this, SIGNAL(userLocationReady(User*)),
378 m_userInfoPanel, SLOT(userDataReceived(User*)));
380 connect(this, SIGNAL(reverseGeoReady(QString)),
381 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
383 connect(this, SIGNAL(clearUpdateLocationDialogData()),
384 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
386 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
387 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
389 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
390 this, SIGNAL(requestReverseGeo()));
392 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
393 this, SIGNAL(statusUpdate(QString,bool)));
395 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
396 this, SIGNAL(refreshUserData()));
398 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
399 this, SLOT(buildInformationBox(QString, bool)));
402 void MainWindow::buildWebView()
404 qDebug() << __PRETTY_FUNCTION__;
407 m_webView = new QWebView;
410 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
412 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
414 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
415 this, SLOT(webViewRequestFinished(QNetworkReply*)));
416 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
417 this, SIGNAL(updateCredentials(QUrl)));
418 connect(m_webView, SIGNAL(loadFinished(bool)),
419 this, SLOT(loadDone(bool)));
425 void MainWindow::buildZoomButtonPanel()
427 qDebug() << __PRETTY_FUNCTION__;
429 m_zoomButtonPanel = new ZoomButtonPanel(this);
431 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
432 this, SIGNAL(zoomIn()));
434 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
435 this, SIGNAL(zoomOut()));
437 connect(this, SIGNAL(zoomLevelChanged(int)),
438 m_zoomButtonPanel, SLOT(resetButtons()));
440 connect(this, SIGNAL(maxZoomLevelReached()),
441 m_zoomButtonPanel, SLOT(disableZoomInButton()));
443 connect(this, SIGNAL(minZoomLevelReached()),
444 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
446 connect(m_mapView, SIGNAL(viewResized(QSize)),
447 m_zoomButtonPanel, SLOT(screenResized(QSize)));
449 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
450 this, SIGNAL(draggingModeTriggered()));
453 void MainWindow::clearCookieJar()
455 qDebug() << __PRETTY_FUNCTION__;
462 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
464 QList<QNetworkCookie> emptyList;
467 m_cookieJar->setAllCookies(emptyList);
468 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
471 void MainWindow::createMenus()
473 qDebug() << __PRETTY_FUNCTION__;
476 m_loginAct = new QAction(tr("Login"), this);
477 connect(m_loginAct, SIGNAL(triggered()),
478 this, SIGNAL(loginActionPressed()));
481 m_toSettingsAct = new QAction(tr("Settings"), this);
482 connect(m_toSettingsAct, SIGNAL(triggered()),
483 this, SLOT(openSettingsDialog()));
486 m_gpsToggleAct = new QAction(tr("GPS"), this);
487 m_gpsToggleAct->setCheckable(true);
489 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
490 this, SIGNAL(gpsTriggered(bool)));
492 // build the actual menu
493 m_viewMenu = menuBar()->addMenu(tr("Main"));
494 m_viewMenu->addAction(m_loginAct);
495 m_viewMenu->addAction(m_toSettingsAct);
496 m_viewMenu->addAction(m_gpsToggleAct);
497 m_viewMenu->setObjectName(tr("Menu"));
500 void MainWindow::dialogFinished(int status)
502 qDebug() << __PRETTY_FUNCTION__;
504 QDialog *dialog = m_queue.takeFirst();
505 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
506 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
510 loginDialog->userInput(m_email, m_password);
512 QStringList urlParts;
513 urlParts.append(FACEBOOK_LOGINBASE);
514 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
515 urlParts.append(INTERVAL1);
516 urlParts.append(SITUARE_LOGIN_SUCCESS);
517 urlParts.append(INTERVAL2);
518 urlParts.append(SITUARE_LOGIN_FAILURE);
519 urlParts.append(FACEBOOK_LOGIN_ENDING);
521 emit saveUsername(m_email);
523 m_webView->load(QUrl(urlParts.join(EMPTY)));
524 toggleProgressIndicator(true);
526 emit cancelLoginProcess();
528 } else if(searchDialog) {
530 emit searchForLocation(searchDialog->input());
534 dialog->deleteLater();
536 if(!m_error_queue.isEmpty() && m_errorShown == false) {
537 showErrorInformationBox();
539 if(!m_queue.isEmpty()) {
540 showInformationBox();
545 void MainWindow::drawFullScreenButton(const QSize &size)
547 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
549 if (m_fullScreenButton) {
550 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
551 size.height() - m_fullScreenButton->size().height());
555 void MainWindow::drawMapScale(const QSize &size)
557 qDebug() << __PRETTY_FUNCTION__;
559 const int LEFT_SCALE_MARGIN = 10;
560 const int BOTTOM_SCALE_MARGIN = 2;
562 m_mapScale->move(LEFT_SCALE_MARGIN,
563 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
566 void MainWindow::drawOsmLicense(const QSize &size)
568 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
570 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
572 size.height() - m_osmLicense->fontMetrics().height());
575 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
577 qDebug() << __PRETTY_FUNCTION__;
579 if (m_ownLocationCrosshair != 0) {
580 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
581 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
585 void MainWindow::errorDialogFinished(int status)
587 qDebug() << __PRETTY_FUNCTION__;
590 QDialog *dialog = m_error_queue.takeFirst();
592 dialog->deleteLater();
593 m_errorShown = false;
595 if(!m_error_queue.isEmpty())
596 showErrorInformationBox();
597 else if(!m_queue.isEmpty())
598 showInformationBox();
601 void MainWindow::gpsTimeout()
603 qDebug() << __PRETTY_FUNCTION__;
605 buildInformationBox(tr("GPS timeout"));
608 void MainWindow::grabZoomKeys(bool grab)
610 qDebug() << __PRETTY_FUNCTION__;
613 // Can't grab keys unless we have a window id
617 unsigned long val = (grab) ? 1 : 0;
618 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
622 XChangeProperty (QX11Info::display(),
628 reinterpret_cast<unsigned char *>(&val),
632 #endif // Q_WS_MAEMO_5
635 void MainWindow::keyPressEvent(QKeyEvent* event)
637 qDebug() << __PRETTY_FUNCTION__;
639 switch (event->key()) {
650 QWidget::keyPressEvent(event);
653 void MainWindow::loadCookies()
655 qDebug() << __PRETTY_FUNCTION__;
657 QSettings settings(DIRECTORY_NAME, FILE_NAME);
659 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
661 if(!list.isEmpty()) {
662 QList<QNetworkCookie> cookieList;
663 for(int i=0;i<list.count();i++) {
664 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
668 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
670 m_cookieJar->setAllCookies(cookieList);
671 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
675 void MainWindow::loadDone(bool done)
677 qDebug() << __PRETTY_FUNCTION__;
679 // for the first time the login page is opened, we need to refresh it to get cookies working
687 QWebFrame* frame = m_webView->page()->currentFrame();
691 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
693 foreach (QWebElement element, emailCollection) {
694 element.setAttribute("value", m_email.toAscii());
697 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
698 foreach (QWebElement element, passwordCollection) {
699 element.setAttribute("value", m_password.toAscii());
701 // find connect button
702 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
703 foreach (QWebElement element, buttonCollection)
705 QPoint pos(element.geometry().center());
707 // send a mouse click event to the web page
708 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
710 QApplication::sendEvent(m_webView->page(), &event0);
711 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
713 QApplication::sendEvent(m_webView->page(), &event1);
719 void MainWindow::loggedIn(bool logged)
721 qDebug() << __PRETTY_FUNCTION__;
726 m_loginAct->setText(tr("Logout"));
732 m_loginAct->setText(tr("Login"));
734 updateItemVisibility();
737 void MainWindow::loginFailed()
739 qDebug() << __PRETTY_FUNCTION__;
745 bool MainWindow::loginState()
747 qDebug() << __PRETTY_FUNCTION__;
752 void MainWindow::loginUsingCookies()
754 qDebug() << __PRETTY_FUNCTION__;
756 toggleProgressIndicator(true);
761 QStringList urlParts;
762 urlParts.append(FACEBOOK_LOGINBASE);
763 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
764 urlParts.append(INTERVAL1);
765 urlParts.append(SITUARE_LOGIN_SUCCESS);
766 urlParts.append(INTERVAL2);
767 urlParts.append(SITUARE_LOGIN_FAILURE);
768 urlParts.append(FACEBOOK_LOGIN_ENDING);
770 m_webView->load(QUrl(urlParts.join(EMPTY)));
774 void MainWindow::openSettingsDialog()
776 qDebug() << __PRETTY_FUNCTION__;
778 SettingsDialog *settingsDialog = new SettingsDialog(this);
779 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
780 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
782 settingsDialog->show();
785 void MainWindow::readAutomaticLocationUpdateSettings()
787 qDebug() << __PRETTY_FUNCTION__;
789 QSettings settings(DIRECTORY_NAME, FILE_NAME);
790 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
791 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
794 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
796 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
798 emit enableAutomaticLocationUpdate(false);
802 void MainWindow::queueDialog(QDialog *dialog)
804 qDebug() << __PRETTY_FUNCTION__;
806 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
807 if(dialog->isModal()) {
808 m_error_queue.append(dialog);
810 m_queue.append(dialog);
813 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
814 if(m_error_queue.count() == 1 && m_errorShown == false)
815 showErrorInformationBox();
816 else if(m_queue.count() == 1 && m_errorShown == false)
817 showInformationBox();
820 void MainWindow::saveCookies()
822 qDebug() << __PRETTY_FUNCTION__;
825 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
827 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
830 for(int i=0;i<cookieList.count();i++) {
831 QNetworkCookie cookie = cookieList.at(i);
832 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
833 list.append(QString(byteArray));
835 list.removeDuplicates();
837 QSettings settings(DIRECTORY_NAME, FILE_NAME);
838 settings.setValue(COOKIES, list);
841 void MainWindow::setGPSButtonEnabled(bool enabled)
843 qDebug() << __PRETTY_FUNCTION__;
845 m_gpsToggleAct->setChecked(enabled);
848 void MainWindow::setIndicatorButtonEnabled(bool enabled)
850 qDebug() << __PRETTY_FUNCTION__;
852 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
855 void MainWindow::setMapViewScene(QGraphicsScene *scene)
857 qDebug() << __PRETTY_FUNCTION__;
859 m_mapView->setScene(scene);
862 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
864 qDebug() << __PRETTY_FUNCTION__;
867 m_ownLocationCrosshair->show();
868 drawOwnLocationCrosshair(m_viewPortSize);
870 m_ownLocationCrosshair->hide();
874 void MainWindow::settingsDialogAccepted()
876 qDebug() << __PRETTY_FUNCTION__;
878 readAutomaticLocationUpdateSettings();
881 void MainWindow::setUsername(const QString &username)
883 qDebug() << __PRETTY_FUNCTION__;
888 void MainWindow::setViewPortSize(const QSize &size)
890 qDebug() << __PRETTY_FUNCTION__;
892 m_viewPortSize = size;
895 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
897 qDebug() << __PRETTY_FUNCTION__;
899 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
900 tr("Automatic location update"), text,
901 QMessageBox::Yes | QMessageBox::No |
902 QMessageBox::Cancel, this);
903 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
904 this, SLOT(automaticUpdateDialogFinished(int)));
906 m_automaticUpdateLocationDialog->show();
909 void MainWindow::toggleFullScreen()
911 qDebug() << __PRETTY_FUNCTION__;
913 if(windowState() == Qt::WindowNoState)
919 void MainWindow::showErrorInformationBox()
921 qDebug() << __PRETTY_FUNCTION__;
923 if(m_error_queue.count()) {
925 QDialog *dialog = m_error_queue.first();
926 connect(dialog, SIGNAL(finished(int)),
927 this, SLOT(errorDialogFinished(int)));
932 void MainWindow::showInformationBox()
934 qDebug() << __PRETTY_FUNCTION__;
936 if(m_queue.count()) {
937 QDialog *dialog = m_queue.first();
938 connect(dialog, SIGNAL(finished(int)),
939 this, SLOT(dialogFinished(int)));
944 void MainWindow::showPanels()
946 qDebug() << __PRETTY_FUNCTION__;
948 ///< @todo check how this is called and can this method be removed
951 // if(!m_friendsListPanel->isVisible()) {
952 // m_friendsListPanel->show();
953 // m_friendsListPanelSidebar->show();
956 // if(!m_userPanel->isVisible()) {
957 // m_userPanel->show();
958 // m_userPanelSidebar->show();
963 void MainWindow::startLocationSearch()
965 qDebug() << __PRETTY_FUNCTION__;
967 SearchDialog *searchDialog = new SearchDialog();
968 queueDialog(searchDialog);
971 void MainWindow::startLoginProcess()
973 qDebug() << __PRETTY_FUNCTION__;
975 LoginDialog *loginDialog = new LoginDialog();
977 emit fetchUsernameFromSettings();
979 loginDialog->clearTextFields();
981 if(!m_email.isEmpty())
982 loginDialog->setEmailField(m_email);
984 queueDialog(loginDialog);
987 void MainWindow::toggleProgressIndicator(bool value)
989 qDebug() << __PRETTY_FUNCTION__;
993 m_progressIndicatorCount++;
994 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
996 if(m_progressIndicatorCount > 0)
997 m_progressIndicatorCount--;
999 if(m_progressIndicatorCount == 0)
1000 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1004 #endif // Q_WS_MAEMO_5
1007 void MainWindow::updateItemVisibility()
1009 qDebug() << __PRETTY_FUNCTION__;
1011 ///< @todo can this be removed?
1013 // if(!m_loggedIn) {
1014 // m_friendsListPanel->closePanel();
1015 // m_friendsListPanel->hide();
1016 // m_friendsListPanelSidebar->hide();
1018 // m_userPanel->closePanel();
1019 // m_userPanel->hide();
1020 // m_userPanelSidebar->hide();
1024 const QString MainWindow::username()
1026 qDebug() << __PRETTY_FUNCTION__;
1031 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1033 qDebug() << __PRETTY_FUNCTION__;
1035 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1036 // qwebview starts to load a new page while the current page loading is not finished
1037 if(reply->error() != QNetworkReply::OperationCanceledError &&
1038 reply->error() != QNetworkReply::NoError) {
1039 emit error(ErrorContext::NETWORK, reply->error());