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, bool)),
262 this, SIGNAL(mapViewScrolled(SceneCoordinate, bool)));
264 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate, bool)),
265 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate, bool)));
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()));
343 connect(m_tabbedPanel, SIGNAL(panelClosed()),
344 m_mapView, SLOT(disableCenterShift()));
346 connect(m_tabbedPanel, SIGNAL(panelOpened()),
347 m_mapView, SLOT(enableCenterShift()));
350 void MainWindow::buildRoutingPanel()
352 qDebug() << __PRETTY_FUNCTION__;
354 m_routingPanel = new RoutingPanel(this);
356 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
357 m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
359 connect(m_routingPanel,
360 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
362 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
364 connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
365 this, SIGNAL(routeTo(const GeoCoordinate&)));
367 connect(this, SIGNAL(routeParsed(Route&)),
368 m_routingPanel, SLOT(setRoute(Route&)));
370 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
371 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
373 connect(m_routingPanel, SIGNAL(requestSearchLocation()),
374 this, SLOT(startLocationSearch()));
377 void MainWindow::buildUserInfoPanel()
379 qDebug() << __PRETTY_FUNCTION__;
381 m_userInfoPanel = new UserInfoPanel(this);
383 connect(this, SIGNAL(userLocationReady(User*)),
384 m_userInfoPanel, SLOT(userDataReceived(User*)));
386 connect(this, SIGNAL(reverseGeoReady(QString)),
387 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
389 connect(this, SIGNAL(clearUpdateLocationDialogData()),
390 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
392 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
393 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
395 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
396 this, SIGNAL(requestReverseGeo()));
398 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
399 this, SIGNAL(statusUpdate(QString,bool)));
401 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
402 this, SIGNAL(refreshUserData()));
404 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
405 this, SLOT(buildInformationBox(QString, bool)));
408 void MainWindow::buildWebView()
410 qDebug() << __PRETTY_FUNCTION__;
413 m_webView = new QWebView;
416 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
418 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
420 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
421 this, SLOT(webViewRequestFinished(QNetworkReply*)));
422 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
423 this, SIGNAL(updateCredentials(QUrl)));
424 connect(m_webView, SIGNAL(loadFinished(bool)),
425 this, SLOT(loadDone(bool)));
431 void MainWindow::buildZoomButtonPanel()
433 qDebug() << __PRETTY_FUNCTION__;
435 m_zoomButtonPanel = new ZoomButtonPanel(this);
437 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
438 this, SIGNAL(zoomIn()));
440 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
441 this, SIGNAL(zoomOut()));
443 connect(this, SIGNAL(zoomLevelChanged(int)),
444 m_zoomButtonPanel, SLOT(resetButtons()));
446 connect(this, SIGNAL(maxZoomLevelReached()),
447 m_zoomButtonPanel, SLOT(disableZoomInButton()));
449 connect(this, SIGNAL(minZoomLevelReached()),
450 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
452 connect(m_mapView, SIGNAL(viewResized(QSize)),
453 m_zoomButtonPanel, SLOT(screenResized(QSize)));
455 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
456 this, SIGNAL(draggingModeTriggered()));
459 void MainWindow::clearCookieJar()
461 qDebug() << __PRETTY_FUNCTION__;
468 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
470 QList<QNetworkCookie> emptyList;
473 m_cookieJar->setAllCookies(emptyList);
474 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
477 void MainWindow::createMenus()
479 qDebug() << __PRETTY_FUNCTION__;
482 m_loginAct = new QAction(tr("Login"), this);
483 connect(m_loginAct, SIGNAL(triggered()),
484 this, SIGNAL(loginActionPressed()));
487 m_toSettingsAct = new QAction(tr("Settings"), this);
488 connect(m_toSettingsAct, SIGNAL(triggered()),
489 this, SLOT(openSettingsDialog()));
492 m_gpsToggleAct = new QAction(tr("GPS"), this);
493 m_gpsToggleAct->setCheckable(true);
495 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
496 this, SIGNAL(gpsTriggered(bool)));
498 // build the actual menu
499 m_viewMenu = menuBar()->addMenu(tr("Main"));
500 m_viewMenu->addAction(m_loginAct);
501 m_viewMenu->addAction(m_toSettingsAct);
502 m_viewMenu->addAction(m_gpsToggleAct);
503 m_viewMenu->setObjectName(tr("Menu"));
506 void MainWindow::dialogFinished(int status)
508 qDebug() << __PRETTY_FUNCTION__;
510 QDialog *dialog = m_queue.takeFirst();
511 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
512 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
516 loginDialog->userInput(m_email, m_password);
518 QStringList urlParts;
519 urlParts.append(FACEBOOK_LOGINBASE);
520 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
521 urlParts.append(INTERVAL1);
522 urlParts.append(SITUARE_LOGIN_SUCCESS);
523 urlParts.append(INTERVAL2);
524 urlParts.append(SITUARE_LOGIN_FAILURE);
525 urlParts.append(FACEBOOK_LOGIN_ENDING);
527 emit saveUsername(m_email);
529 m_webView->load(QUrl(urlParts.join(EMPTY)));
530 toggleProgressIndicator(true);
532 emit cancelLoginProcess();
534 } else if(searchDialog) {
536 emit searchForLocation(searchDialog->input());
540 dialog->deleteLater();
542 if(!m_error_queue.isEmpty() && m_errorShown == false) {
543 showErrorInformationBox();
545 if(!m_queue.isEmpty()) {
546 showInformationBox();
551 void MainWindow::drawFullScreenButton(const QSize &size)
553 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
555 if (m_fullScreenButton) {
556 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
557 size.height() - m_fullScreenButton->size().height());
561 void MainWindow::drawMapScale(const QSize &size)
563 qDebug() << __PRETTY_FUNCTION__;
565 const int LEFT_SCALE_MARGIN = 10;
566 const int BOTTOM_SCALE_MARGIN = 2;
568 m_mapScale->move(LEFT_SCALE_MARGIN,
569 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
572 void MainWindow::drawOsmLicense(const QSize &size)
574 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
576 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
578 size.height() - m_osmLicense->fontMetrics().height());
581 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
583 qDebug() << __PRETTY_FUNCTION__;
585 if (m_ownLocationCrosshair != 0) {
586 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
587 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
591 void MainWindow::errorDialogFinished(int status)
593 qDebug() << __PRETTY_FUNCTION__;
596 QDialog *dialog = m_error_queue.takeFirst();
598 dialog->deleteLater();
599 m_errorShown = false;
601 if(!m_error_queue.isEmpty())
602 showErrorInformationBox();
603 else if(!m_queue.isEmpty())
604 showInformationBox();
607 void MainWindow::gpsTimeout()
609 qDebug() << __PRETTY_FUNCTION__;
611 buildInformationBox(tr("GPS timeout"));
614 void MainWindow::grabZoomKeys(bool grab)
616 qDebug() << __PRETTY_FUNCTION__;
619 // Can't grab keys unless we have a window id
623 unsigned long val = (grab) ? 1 : 0;
624 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
628 XChangeProperty (QX11Info::display(),
634 reinterpret_cast<unsigned char *>(&val),
638 #endif // Q_WS_MAEMO_5
641 void MainWindow::keyPressEvent(QKeyEvent* event)
643 qDebug() << __PRETTY_FUNCTION__;
645 switch (event->key()) {
656 QWidget::keyPressEvent(event);
659 void MainWindow::loadCookies()
661 qDebug() << __PRETTY_FUNCTION__;
663 QSettings settings(DIRECTORY_NAME, FILE_NAME);
665 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
667 if(!list.isEmpty()) {
668 QList<QNetworkCookie> cookieList;
669 for(int i=0;i<list.count();i++) {
670 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
674 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
676 m_cookieJar->setAllCookies(cookieList);
677 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
681 void MainWindow::loadDone(bool done)
683 qDebug() << __PRETTY_FUNCTION__;
685 // for the first time the login page is opened, we need to refresh it to get cookies working
693 QWebFrame* frame = m_webView->page()->currentFrame();
697 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
699 foreach (QWebElement element, emailCollection) {
700 element.setAttribute("value", m_email.toAscii());
703 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
704 foreach (QWebElement element, passwordCollection) {
705 element.setAttribute("value", m_password.toAscii());
707 // find connect button
708 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
709 foreach (QWebElement element, buttonCollection)
711 QPoint pos(element.geometry().center());
713 // send a mouse click event to the web page
714 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
716 QApplication::sendEvent(m_webView->page(), &event0);
717 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
719 QApplication::sendEvent(m_webView->page(), &event1);
725 void MainWindow::loggedIn(bool logged)
727 qDebug() << __PRETTY_FUNCTION__;
732 m_loginAct->setText(tr("Logout"));
738 m_loginAct->setText(tr("Login"));
740 updateItemVisibility();
743 void MainWindow::loginFailed()
745 qDebug() << __PRETTY_FUNCTION__;
751 bool MainWindow::loginState()
753 qDebug() << __PRETTY_FUNCTION__;
758 void MainWindow::loginUsingCookies()
760 qDebug() << __PRETTY_FUNCTION__;
762 toggleProgressIndicator(true);
767 QStringList urlParts;
768 urlParts.append(FACEBOOK_LOGINBASE);
769 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
770 urlParts.append(INTERVAL1);
771 urlParts.append(SITUARE_LOGIN_SUCCESS);
772 urlParts.append(INTERVAL2);
773 urlParts.append(SITUARE_LOGIN_FAILURE);
774 urlParts.append(FACEBOOK_LOGIN_ENDING);
776 m_webView->load(QUrl(urlParts.join(EMPTY)));
780 void MainWindow::openSettingsDialog()
782 qDebug() << __PRETTY_FUNCTION__;
784 SettingsDialog *settingsDialog = new SettingsDialog(this);
785 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
786 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
788 settingsDialog->show();
791 void MainWindow::readAutomaticLocationUpdateSettings()
793 qDebug() << __PRETTY_FUNCTION__;
795 QSettings settings(DIRECTORY_NAME, FILE_NAME);
796 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
797 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
800 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
802 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
804 emit enableAutomaticLocationUpdate(false);
808 void MainWindow::queueDialog(QDialog *dialog)
810 qDebug() << __PRETTY_FUNCTION__;
812 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
813 if(dialog->isModal()) {
814 m_error_queue.append(dialog);
816 m_queue.append(dialog);
819 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
820 if(m_error_queue.count() == 1 && m_errorShown == false)
821 showErrorInformationBox();
822 else if(m_queue.count() == 1 && m_errorShown == false)
823 showInformationBox();
826 void MainWindow::saveCookies()
828 qDebug() << __PRETTY_FUNCTION__;
831 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
833 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
836 for(int i=0;i<cookieList.count();i++) {
837 QNetworkCookie cookie = cookieList.at(i);
838 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
839 list.append(QString(byteArray));
841 list.removeDuplicates();
843 QSettings settings(DIRECTORY_NAME, FILE_NAME);
844 settings.setValue(COOKIES, list);
847 void MainWindow::setGPSButtonEnabled(bool enabled)
849 qDebug() << __PRETTY_FUNCTION__;
851 m_gpsToggleAct->setChecked(enabled);
854 void MainWindow::setIndicatorButtonEnabled(bool enabled)
856 qDebug() << __PRETTY_FUNCTION__;
858 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
861 void MainWindow::setMapViewScene(QGraphicsScene *scene)
863 qDebug() << __PRETTY_FUNCTION__;
865 m_mapView->setScene(scene);
868 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
870 qDebug() << __PRETTY_FUNCTION__;
873 m_ownLocationCrosshair->show();
874 drawOwnLocationCrosshair(m_viewPortSize);
876 m_ownLocationCrosshair->hide();
880 void MainWindow::settingsDialogAccepted()
882 qDebug() << __PRETTY_FUNCTION__;
884 readAutomaticLocationUpdateSettings();
887 void MainWindow::setUsername(const QString &username)
889 qDebug() << __PRETTY_FUNCTION__;
894 void MainWindow::setViewPortSize(const QSize &size)
896 qDebug() << __PRETTY_FUNCTION__;
898 m_viewPortSize = size;
901 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
903 qDebug() << __PRETTY_FUNCTION__;
905 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
906 tr("Automatic location update"), text,
907 QMessageBox::Yes | QMessageBox::No |
908 QMessageBox::Cancel, this);
909 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
910 this, SLOT(automaticUpdateDialogFinished(int)));
912 m_automaticUpdateLocationDialog->show();
915 void MainWindow::toggleFullScreen()
917 qDebug() << __PRETTY_FUNCTION__;
919 if(windowState() == Qt::WindowNoState)
925 void MainWindow::showErrorInformationBox()
927 qDebug() << __PRETTY_FUNCTION__;
929 if(m_error_queue.count()) {
931 QDialog *dialog = m_error_queue.first();
932 connect(dialog, SIGNAL(finished(int)),
933 this, SLOT(errorDialogFinished(int)));
938 void MainWindow::showInformationBox()
940 qDebug() << __PRETTY_FUNCTION__;
942 if(m_queue.count()) {
943 QDialog *dialog = m_queue.first();
944 connect(dialog, SIGNAL(finished(int)),
945 this, SLOT(dialogFinished(int)));
950 void MainWindow::showPanels()
952 qDebug() << __PRETTY_FUNCTION__;
954 ///< @todo check how this is called and can this method be removed
957 // if(!m_friendsListPanel->isVisible()) {
958 // m_friendsListPanel->show();
959 // m_friendsListPanelSidebar->show();
962 // if(!m_userPanel->isVisible()) {
963 // m_userPanel->show();
964 // m_userPanelSidebar->show();
969 void MainWindow::startLocationSearch()
971 qDebug() << __PRETTY_FUNCTION__;
973 SearchDialog *searchDialog = new SearchDialog();
974 queueDialog(searchDialog);
977 void MainWindow::startLoginProcess()
979 qDebug() << __PRETTY_FUNCTION__;
981 LoginDialog *loginDialog = new LoginDialog();
983 emit fetchUsernameFromSettings();
985 loginDialog->clearTextFields();
987 if(!m_email.isEmpty())
988 loginDialog->setEmailField(m_email);
990 queueDialog(loginDialog);
993 void MainWindow::toggleProgressIndicator(bool value)
995 qDebug() << __PRETTY_FUNCTION__;
999 m_progressIndicatorCount++;
1000 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1002 if(m_progressIndicatorCount > 0)
1003 m_progressIndicatorCount--;
1005 if(m_progressIndicatorCount == 0)
1006 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1010 #endif // Q_WS_MAEMO_5
1013 void MainWindow::updateItemVisibility()
1015 qDebug() << __PRETTY_FUNCTION__;
1017 ///< @todo can this be removed?
1019 // if(!m_loggedIn) {
1020 // m_friendsListPanel->closePanel();
1021 // m_friendsListPanel->hide();
1022 // m_friendsListPanelSidebar->hide();
1024 // m_userPanel->closePanel();
1025 // m_userPanel->hide();
1026 // m_userPanelSidebar->hide();
1030 const QString MainWindow::username()
1032 qDebug() << __PRETTY_FUNCTION__;
1037 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1039 qDebug() << __PRETTY_FUNCTION__;
1041 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1042 // qwebview starts to load a new page while the current page loading is not finished
1043 if(reply->error() != QNetworkReply::OperationCanceledError &&
1044 reply->error() != QNetworkReply::NoError) {
1045 emit error(ErrorContext::NETWORK, reply->error());