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 "locationsearchpanel.h"
44 #include "logindialog.h"
46 #include "panelcommon.h"
47 #include "routingpanel.h"
48 #include "tabbedpanel.h"
49 #include "searchdialog.h"
50 #include "settingsdialog.h"
51 #include "userinfopanel.h"
52 #include "zoombuttonpanel.h"
54 #include "mainwindow.h"
56 // These MUST BE HERE, compiling for Maemo fails if moved
58 #include <QtMaemo5/QMaemo5InformationBox>
59 #include <QtGui/QX11Info>
60 #include <X11/Xatom.h>
62 #endif // Q_WS_MAEMO_5
64 MainWindow::MainWindow(QWidget *parent)
65 : QMainWindow(parent),
69 m_mapCenterHorizontalShifting(0),
70 m_progressIndicatorCount(0),
72 m_email(), ///< @todo WTF?!?!?!?
75 m_fullScreenButton(0),
76 m_indicatorButtonPanel(0),
80 qDebug() << __PRETTY_FUNCTION__;
84 // map view is the only widget which size & location is handled automatically by the system
85 // default functionality
86 setCentralWidget(m_mapView);
91 setWindowTitle(tr("Situare"));
93 // set stacking order of widgets (from top to bottom)
94 // m_tabbedPanel is the topmost one
95 if (m_fullScreenButton) {
96 m_fullScreenButton->stackUnder(m_tabbedPanel);
97 m_crosshair->stackUnder(m_fullScreenButton);
99 m_crosshair->stackUnder(m_tabbedPanel);
101 m_zoomButtonPanel->stackUnder(m_crosshair);
102 m_indicatorButtonPanel->stackUnder(m_zoomButtonPanel);
103 m_osmLicense->stackUnder(m_indicatorButtonPanel);
104 m_mapScale->stackUnder(m_osmLicense);
105 m_mapView->stackUnder(m_mapScale);
109 // Set default screen size
110 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
112 setAttribute(Qt::WA_Maemo5StackedWindow);
116 MainWindow::~MainWindow()
118 qDebug() << __PRETTY_FUNCTION__;
125 qDeleteAll(m_queue.begin(), m_queue.end());
128 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
129 m_error_queue.clear();
132 void MainWindow::automaticUpdateDialogFinished(int result)
134 qDebug() << __PRETTY_FUNCTION__;
136 if (result == QMessageBox::Yes) {
137 readAutomaticLocationUpdateSettings();
139 QSettings settings(DIRECTORY_NAME, FILE_NAME);
140 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
141 readAutomaticLocationUpdateSettings();
144 m_automaticUpdateLocationDialog->deleteLater();
147 void MainWindow::buildCrosshair()
149 qDebug() << __PRETTY_FUNCTION__;
151 m_crosshair = new QLabel(this);
152 QPixmap crosshairImage(":/res/images/sight.png");
153 m_crosshair->setPixmap(crosshairImage);
154 m_crosshair->setFixedSize(crosshairImage.size());
156 m_crosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
158 connect(m_mapView, SIGNAL(viewResized(QSize)),
159 this, SLOT(moveCrosshair()));
161 connect(m_mapView, SIGNAL(horizontalShiftingChanged(int)),
162 this, SLOT(mapCenterHorizontalShiftingChanged(int)));
165 void MainWindow::buildFriendListPanel()
167 qDebug() << __PRETTY_FUNCTION__;
169 m_friendsListPanel = new FriendListPanel(this);
171 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
172 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
174 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
175 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
177 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
178 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
180 connect(this, SIGNAL(friendImageReady(User*)),
181 m_friendsListPanel, SLOT(friendImageReady(User*)));
183 connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
184 this, SIGNAL(routeTo(const GeoCoordinate&)));
187 void MainWindow::buildFullScreenButton()
189 qDebug() << __PRETTY_FUNCTION__;
192 m_fullScreenButton = new FullScreenButton(this);
194 if (m_fullScreenButton) {
195 connect(m_fullScreenButton, SIGNAL(clicked()),
196 this, SLOT(toggleFullScreen()));
198 connect(qApp, SIGNAL(showFullScreenButton()),
199 m_fullScreenButton, SLOT(invoke()));
201 #endif // Q_WS_MAEMO_5
204 void MainWindow::buildIndicatorButtonPanel()
206 qDebug() << __PRETTY_FUNCTION__;
208 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
210 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
211 this, SIGNAL(autoCenteringTriggered(bool)));
213 connect(m_mapView, SIGNAL(viewResized(QSize)),
214 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
216 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
217 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
219 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
220 this, SIGNAL(draggingModeTriggered()));
223 void MainWindow::buildInformationBox(const QString &message, bool modal)
225 qDebug() << __PRETTY_FUNCTION__;
227 QString errorMessage = message;
231 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
234 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
235 // extra line changes are needed to make error notes broader
236 errorMessage.prepend("\n");
237 errorMessage.append("\n");
239 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
241 QLabel *label = new QLabel(msgBox);
242 label->setAlignment(Qt::AlignCenter);
243 label->setText(errorMessage);
244 msgBox->setWidget(label);
246 QMessageBox *msgBox = new QMessageBox(this);
247 msgBox->button(QMessageBox::Ok);
248 msgBox->setText(errorMessage);
249 msgBox->setModal(modal);
255 void MainWindow::buildLocationSearchPanel()
257 qDebug() << __PRETTY_FUNCTION__;
259 m_locationSearchPanel = new LocationSearchPanel(this);
261 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
262 m_locationSearchPanel, SLOT(populateLocationListView(const QList<Location>&)));
264 connect(m_locationSearchPanel, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
265 this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
267 connect(m_locationSearchPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
268 this, SIGNAL(routeTo(const GeoCoordinate&)));
270 connect(m_locationSearchPanel, SIGNAL(requestSearchLocation()),
271 this, SLOT(startLocationSearch()));
273 connect(this, SIGNAL(searchForLocation(QString)),
274 m_locationSearchPanel, SLOT(appendSearchHistory(QString)));
277 void MainWindow::buildMap()
279 qDebug() << __PRETTY_FUNCTION__;
281 m_mapView = new MapView(this);
283 buildZoomButtonPanel();
286 buildFullScreenButton();
287 buildIndicatorButtonPanel();
290 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
291 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
293 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
294 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
296 connect(m_mapView, SIGNAL(viewResized(QSize)),
297 this, SIGNAL(mapViewResized(QSize)));
299 connect(m_mapView, SIGNAL(viewResized(QSize)),
300 this, SLOT(drawFullScreenButton(QSize)));
302 connect(m_mapView, SIGNAL(viewResized(QSize)),
303 this, SLOT(drawMapScale(QSize)));
305 connect(m_mapView, SIGNAL(viewResized(QSize)),
306 this, SLOT(moveCrosshair()));
308 connect(this, SIGNAL(zoomLevelChanged(int)),
309 m_mapView, SLOT(setZoomLevel(int)));
311 connect(m_mapView, SIGNAL(viewZoomFinished()),
312 this, SIGNAL(viewZoomFinished()));
314 connect(m_mapView, SIGNAL(zoomIn()),
315 this, SIGNAL(zoomIn()));
318 void MainWindow::buildMapScale()
320 m_mapScale = new MapScale(this);
321 connect(this, SIGNAL(newMapResolution(qreal)),
322 m_mapScale, SLOT(updateMapResolution(qreal)));
325 void MainWindow::buildOsmLicense()
327 qDebug() << __PRETTY_FUNCTION__;
329 m_osmLicense = new QLabel(this);
330 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
331 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
332 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
333 m_osmLicense->setFont(QFont("Nokia Sans", 9));
334 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
335 m_osmLicense->fontMetrics().height());
337 connect(m_mapView, SIGNAL(viewResized(QSize)),
338 this, SLOT(drawOsmLicense(QSize)));
341 void MainWindow::buildPanels()
343 qDebug() << __PRETTY_FUNCTION__;
345 buildUserInfoPanel();
346 buildFriendListPanel();
347 buildLocationSearchPanel();
350 m_tabbedPanel = new TabbedPanel(this);
352 //Save Situare related tab indexes so tabs can be enabled/disabled when logged in/out
353 m_situareTabsIndexes.append(
354 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png")));
355 m_situareTabsIndexes.append(
356 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png")));
358 m_tabbedPanel->addTab(m_locationSearchPanel, QIcon(":/res/images/location_search.png"));
359 m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
361 connect(m_mapView, SIGNAL(viewResized(QSize)),
362 m_tabbedPanel, SLOT(resizePanel(QSize)));
364 connect(m_friendsListPanel, SIGNAL(openPanelRequested(QWidget*)),
365 m_tabbedPanel, SLOT(openPanel(QWidget*)));
367 connect(m_routingPanel, SIGNAL(openPanelRequested(QWidget*)),
368 m_tabbedPanel, SLOT(openPanel(QWidget*)));
370 connect(m_tabbedPanel, SIGNAL(panelClosed()),
371 m_friendsListPanel, SLOT(anyPanelClosed()));
373 connect(m_tabbedPanel, SIGNAL(panelOpened()),
374 m_friendsListPanel, SLOT(anyPanelOpened()));
376 connect(m_tabbedPanel, SIGNAL(panelClosed()),
377 m_routingPanel, SLOT(clearListsSelections()));
379 connect(m_tabbedPanel, SIGNAL(panelClosed()),
380 m_mapView, SLOT(disableCenterShift()));
382 connect(m_tabbedPanel, SIGNAL(panelOpened()),
383 m_mapView, SLOT(enableCenterShift()));
385 connect(m_tabbedPanel, SIGNAL(panelClosed()),
386 m_userInfoPanel, SIGNAL(collapse()));
388 connect(m_tabbedPanel, SIGNAL(currentChanged(int)),
389 m_userInfoPanel, SIGNAL(collapse()));
392 void MainWindow::buildRoutingPanel()
394 qDebug() << __PRETTY_FUNCTION__;
396 m_routingPanel = new RoutingPanel(this);
398 connect(m_routingPanel, SIGNAL(routeToCursor()),
399 this, SIGNAL(routeToCursor()));
401 connect(this, SIGNAL(routeParsed(Route&)),
402 m_routingPanel, SLOT(setRoute(Route&)));
404 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
405 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
407 connect(m_routingPanel, SIGNAL(clearRoute()),
408 this, SIGNAL(clearRoute()));
411 void MainWindow::buildUserInfoPanel()
413 qDebug() << __PRETTY_FUNCTION__;
415 m_userInfoPanel = new UserInfoPanel(this);
417 connect(this, SIGNAL(userLocationReady(User*)),
418 m_userInfoPanel, SLOT(userDataReceived(User*)));
420 connect(this, SIGNAL(reverseGeoReady(QString)),
421 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
423 connect(this, SIGNAL(clearUpdateLocationDialogData()),
424 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
426 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
427 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
429 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
430 this, SIGNAL(requestReverseGeo()));
432 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
433 this, SIGNAL(statusUpdate(QString,bool)));
435 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
436 this, SIGNAL(refreshUserData()));
438 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
439 this, SLOT(buildInformationBox(QString, bool)));
442 void MainWindow::buildWebView()
444 qDebug() << __PRETTY_FUNCTION__;
447 m_webView = new QWebView;
450 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
452 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
454 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
455 this, SLOT(webViewRequestFinished(QNetworkReply*)));
456 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
457 this, SIGNAL(updateCredentials(QUrl)));
458 connect(m_webView, SIGNAL(loadFinished(bool)),
459 this, SLOT(loadDone(bool)));
465 void MainWindow::buildZoomButtonPanel()
467 qDebug() << __PRETTY_FUNCTION__;
469 m_zoomButtonPanel = new ZoomButtonPanel(this);
471 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
472 this, SIGNAL(zoomIn()));
474 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
475 this, SIGNAL(zoomOut()));
477 connect(this, SIGNAL(zoomLevelChanged(int)),
478 m_zoomButtonPanel, SLOT(resetButtons()));
480 connect(this, SIGNAL(maxZoomLevelReached()),
481 m_zoomButtonPanel, SLOT(disableZoomInButton()));
483 connect(this, SIGNAL(minZoomLevelReached()),
484 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
486 connect(m_mapView, SIGNAL(viewResized(QSize)),
487 m_zoomButtonPanel, SLOT(screenResized(QSize)));
489 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
490 this, SIGNAL(draggingModeTriggered()));
493 void MainWindow::clearCookieJar()
495 qDebug() << __PRETTY_FUNCTION__;
502 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
504 QList<QNetworkCookie> emptyList;
507 m_cookieJar->setAllCookies(emptyList);
508 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
511 void MainWindow::createMenus()
513 qDebug() << __PRETTY_FUNCTION__;
516 m_loginAct = new QAction(tr("Login"), this);
517 connect(m_loginAct, SIGNAL(triggered()),
518 this, SIGNAL(loginActionPressed()));
521 m_toSettingsAct = new QAction(tr("Settings"), this);
522 connect(m_toSettingsAct, SIGNAL(triggered()),
523 this, SLOT(openSettingsDialog()));
526 m_gpsToggleAct = new QAction(tr("GPS"), this);
527 m_gpsToggleAct->setCheckable(true);
529 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
530 this, SIGNAL(gpsTriggered(bool)));
532 // build the actual menu
533 m_viewMenu = menuBar()->addMenu(tr("Main"));
534 m_viewMenu->addAction(m_loginAct);
535 m_viewMenu->addAction(m_toSettingsAct);
536 m_viewMenu->addAction(m_gpsToggleAct);
537 m_viewMenu->setObjectName(tr("Menu"));
540 void MainWindow::dialogFinished(int status)
542 qDebug() << __PRETTY_FUNCTION__;
544 QDialog *dialog = m_queue.takeFirst();
545 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
546 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
550 loginDialog->userInput(m_email, m_password);
552 QStringList urlParts;
553 urlParts.append(FACEBOOK_LOGINBASE);
554 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
555 urlParts.append(INTERVAL1);
556 urlParts.append(SITUARE_LOGIN_SUCCESS);
557 urlParts.append(INTERVAL2);
558 urlParts.append(SITUARE_LOGIN_FAILURE);
559 urlParts.append(FACEBOOK_LOGIN_ENDING);
561 emit saveUsername(m_email);
563 m_webView->load(QUrl(urlParts.join(EMPTY)));
564 toggleProgressIndicator(true);
566 emit cancelLoginProcess();
568 } else if(searchDialog) {
570 emit searchForLocation(searchDialog->input());
574 dialog->deleteLater();
576 if(!m_error_queue.isEmpty() && m_errorShown == false) {
577 showErrorInformationBox();
579 if(!m_queue.isEmpty()) {
580 showInformationBox();
585 void MainWindow::drawFullScreenButton(const QSize &size)
587 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
589 if (m_fullScreenButton) {
590 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
591 size.height() - m_fullScreenButton->size().height());
595 void MainWindow::drawMapScale(const QSize &size)
597 qDebug() << __PRETTY_FUNCTION__;
599 const int LEFT_SCALE_MARGIN = 10;
600 const int BOTTOM_SCALE_MARGIN = 2;
602 m_mapScale->move(LEFT_SCALE_MARGIN,
603 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
606 void MainWindow::drawOsmLicense(const QSize &size)
608 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
610 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
612 size.height() - m_osmLicense->fontMetrics().height());
615 void MainWindow::errorDialogFinished(int status)
617 qDebug() << __PRETTY_FUNCTION__;
620 QDialog *dialog = m_error_queue.takeFirst();
622 dialog->deleteLater();
623 m_errorShown = false;
625 if(!m_error_queue.isEmpty())
626 showErrorInformationBox();
627 else if(!m_queue.isEmpty())
628 showInformationBox();
631 void MainWindow::gpsTimeout()
633 qDebug() << __PRETTY_FUNCTION__;
635 buildInformationBox(tr("GPS timeout"));
638 void MainWindow::grabZoomKeys(bool grab)
640 qDebug() << __PRETTY_FUNCTION__;
643 // Can't grab keys unless we have a window id
647 unsigned long val = (grab) ? 1 : 0;
648 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
652 XChangeProperty (QX11Info::display(),
658 reinterpret_cast<unsigned char *>(&val),
662 #endif // Q_WS_MAEMO_5
665 void MainWindow::keyPressEvent(QKeyEvent* event)
667 qDebug() << __PRETTY_FUNCTION__;
669 switch (event->key()) {
680 QWidget::keyPressEvent(event);
683 void MainWindow::loadCookies()
685 qDebug() << __PRETTY_FUNCTION__;
687 QSettings settings(DIRECTORY_NAME, FILE_NAME);
689 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
691 if(!list.isEmpty()) {
692 QList<QNetworkCookie> cookieList;
693 for(int i=0;i<list.count();i++) {
694 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
698 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
700 m_cookieJar->setAllCookies(cookieList);
701 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
705 void MainWindow::loadDone(bool done)
707 qDebug() << __PRETTY_FUNCTION__;
709 // for the first time the login page is opened, we need to refresh it to get cookies working
717 QWebFrame* frame = m_webView->page()->currentFrame();
721 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
723 foreach (QWebElement element, emailCollection) {
724 element.setAttribute("value", m_email.toAscii());
727 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
728 foreach (QWebElement element, passwordCollection) {
729 element.setAttribute("value", m_password.toAscii());
731 // find connect button
732 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
733 foreach (QWebElement element, buttonCollection)
735 QPoint pos(element.geometry().center());
737 // send a mouse click event to the web page
738 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
740 QApplication::sendEvent(m_webView->page(), &event0);
741 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
743 QApplication::sendEvent(m_webView->page(), &event1);
749 void MainWindow::loggedIn(bool logged)
751 qDebug() << __PRETTY_FUNCTION__;
756 m_loginAct->setText(tr("Logout"));
762 m_loginAct->setText(tr("Login"));
764 updateItemVisibility();
767 void MainWindow::loginFailed()
769 qDebug() << __PRETTY_FUNCTION__;
775 bool MainWindow::loginState()
777 qDebug() << __PRETTY_FUNCTION__;
782 void MainWindow::loginUsingCookies()
784 qDebug() << __PRETTY_FUNCTION__;
786 toggleProgressIndicator(true);
791 QStringList urlParts;
792 urlParts.append(FACEBOOK_LOGINBASE);
793 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
794 urlParts.append(INTERVAL1);
795 urlParts.append(SITUARE_LOGIN_SUCCESS);
796 urlParts.append(INTERVAL2);
797 urlParts.append(SITUARE_LOGIN_FAILURE);
798 urlParts.append(FACEBOOK_LOGIN_ENDING);
800 m_webView->load(QUrl(urlParts.join(EMPTY)));
804 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
806 m_mapCenterHorizontalShifting = shifting;
810 void MainWindow::moveCrosshair()
812 qDebug() << __PRETTY_FUNCTION__;
815 int mapHeight = m_mapView->size().height();
816 int mapWidth = m_mapView->size().width();
817 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
818 - m_mapCenterHorizontalShifting,
819 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
823 void MainWindow::openSettingsDialog()
825 qDebug() << __PRETTY_FUNCTION__;
827 SettingsDialog *settingsDialog = new SettingsDialog(this);
828 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
829 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
831 settingsDialog->show();
834 void MainWindow::queueDialog(QDialog *dialog)
836 qDebug() << __PRETTY_FUNCTION__;
838 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
839 if(dialog->isModal()) {
840 m_error_queue.append(dialog);
842 m_queue.append(dialog);
845 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
846 if(m_error_queue.count() == 1 && m_errorShown == false)
847 showErrorInformationBox();
848 else if(m_queue.count() == 1 && m_errorShown == false)
849 showInformationBox();
852 void MainWindow::readAutomaticLocationUpdateSettings()
854 qDebug() << __PRETTY_FUNCTION__;
856 QSettings settings(DIRECTORY_NAME, FILE_NAME);
857 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
858 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
861 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
863 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
865 emit enableAutomaticLocationUpdate(false);
869 void MainWindow::saveCookies()
871 qDebug() << __PRETTY_FUNCTION__;
874 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
876 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
879 for(int i=0;i<cookieList.count();i++) {
880 QNetworkCookie cookie = cookieList.at(i);
881 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
882 list.append(QString(byteArray));
884 list.removeDuplicates();
886 QSettings settings(DIRECTORY_NAME, FILE_NAME);
887 settings.setValue(COOKIES, list);
890 void MainWindow::setCrosshairVisibility(bool visibility)
892 qDebug() << __PRETTY_FUNCTION__;
902 void MainWindow::setGPSButtonEnabled(bool enabled)
904 qDebug() << __PRETTY_FUNCTION__;
906 m_gpsToggleAct->setChecked(enabled);
909 void MainWindow::setIndicatorButtonEnabled(bool enabled)
911 qDebug() << __PRETTY_FUNCTION__;
913 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
916 void MainWindow::setMapViewScene(QGraphicsScene *scene)
918 qDebug() << __PRETTY_FUNCTION__;
920 m_mapView->setScene(scene);
923 void MainWindow::settingsDialogAccepted()
925 qDebug() << __PRETTY_FUNCTION__;
927 readAutomaticLocationUpdateSettings();
930 void MainWindow::setUsername(const QString &username)
932 qDebug() << __PRETTY_FUNCTION__;
937 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
939 qDebug() << __PRETTY_FUNCTION__;
941 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
942 tr("Automatic location update"), text,
943 QMessageBox::Yes | QMessageBox::No |
944 QMessageBox::Cancel, this);
945 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
946 this, SLOT(automaticUpdateDialogFinished(int)));
948 m_automaticUpdateLocationDialog->show();
951 void MainWindow::showErrorInformationBox()
953 qDebug() << __PRETTY_FUNCTION__;
955 if(m_error_queue.count()) {
957 QDialog *dialog = m_error_queue.first();
958 connect(dialog, SIGNAL(finished(int)),
959 this, SLOT(errorDialogFinished(int)));
964 void MainWindow::showInformationBox()
966 qDebug() << __PRETTY_FUNCTION__;
968 if(m_queue.count()) {
969 QDialog *dialog = m_queue.first();
970 connect(dialog, SIGNAL(finished(int)),
971 this, SLOT(dialogFinished(int)));
976 void MainWindow::startLocationSearch()
978 qDebug() << __PRETTY_FUNCTION__;
980 SearchDialog *searchDialog = new SearchDialog();
981 queueDialog(searchDialog);
984 void MainWindow::startLoginProcess()
986 qDebug() << __PRETTY_FUNCTION__;
988 LoginDialog *loginDialog = new LoginDialog();
990 emit fetchUsernameFromSettings();
992 loginDialog->clearTextFields();
994 if(!m_email.isEmpty())
995 loginDialog->setEmailField(m_email);
997 queueDialog(loginDialog);
1000 void MainWindow::toggleFullScreen()
1002 qDebug() << __PRETTY_FUNCTION__;
1004 if(windowState() == Qt::WindowNoState)
1010 void MainWindow::toggleProgressIndicator(bool value)
1012 qDebug() << __PRETTY_FUNCTION__;
1016 m_progressIndicatorCount++;
1017 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1019 if(m_progressIndicatorCount > 0)
1020 m_progressIndicatorCount--;
1022 if(m_progressIndicatorCount == 0)
1023 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1027 #endif // Q_WS_MAEMO_5
1030 void MainWindow::updateItemVisibility()
1032 qDebug() << __PRETTY_FUNCTION__;
1034 m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, m_loggedIn);
1037 const QString MainWindow::username()
1039 qDebug() << __PRETTY_FUNCTION__;
1044 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1046 qDebug() << __PRETTY_FUNCTION__;
1048 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1049 // qwebview starts to load a new page while the current page loading is not finished
1050 if(reply->error() != QNetworkReply::OperationCanceledError &&
1051 reply->error() != QNetworkReply::NoError) {
1052 emit error(ErrorContext::NETWORK, reply->error());