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_mapCenterHorizontalShifting(0),
69 m_progressIndicatorCount(0),
71 m_email(), ///< @todo WTF?!?!?!?
74 m_fullScreenButton(0),
75 m_indicatorButtonPanel(0),
79 qDebug() << __PRETTY_FUNCTION__;
83 // map view is the only widget which size & location is handled automatically by the system
84 // default functionality
85 setCentralWidget(m_mapView);
90 setWindowTitle(tr("Situare"));
92 // set stacking order of widgets (from top to bottom)
93 // if the fullscreen button exists, then it is the topmost one, otherwise the tabbed panel is
94 if (m_fullScreenButton) {
95 m_tabbedPanel->stackUnder(m_fullScreenButton);
97 m_crosshair->stackUnder(m_tabbedPanel);
98 m_zoomButtonPanel->stackUnder(m_crosshair);
99 m_indicatorButtonPanel->stackUnder(m_zoomButtonPanel);
100 m_osmLicense->stackUnder(m_indicatorButtonPanel);
101 m_mapScale->stackUnder(m_osmLicense);
102 m_mapView->stackUnder(m_mapScale);
106 // Set default screen size
107 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
109 setAttribute(Qt::WA_Maemo5StackedWindow);
113 MainWindow::~MainWindow()
115 qDebug() << __PRETTY_FUNCTION__;
122 qDeleteAll(m_queue.begin(), m_queue.end());
125 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
126 m_error_queue.clear();
129 void MainWindow::automaticUpdateDialogFinished(int result)
131 qDebug() << __PRETTY_FUNCTION__;
133 if (result == QMessageBox::Yes) {
134 readAutomaticLocationUpdateSettings();
136 QSettings settings(DIRECTORY_NAME, FILE_NAME);
137 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
138 readAutomaticLocationUpdateSettings();
141 m_automaticUpdateLocationDialog->deleteLater();
144 void MainWindow::buildCrosshair()
146 qDebug() << __PRETTY_FUNCTION__;
148 m_crosshair = new QLabel(this);
149 QPixmap crosshairImage(":/res/images/sight.png");
150 m_crosshair->setPixmap(crosshairImage);
151 m_crosshair->setFixedSize(crosshairImage.size());
153 m_crosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
155 connect(m_mapView, SIGNAL(viewResized(QSize)),
156 this, SLOT(moveCrosshair()));
158 connect(m_mapView, SIGNAL(horizontalShiftingChanged(int)),
159 this, SLOT(mapCenterHorizontalShiftingChanged(int)));
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(centerToCoordinates(GeoCoordinate)));
177 connect(this, SIGNAL(friendImageReady(User*)),
178 m_friendsListPanel, SLOT(friendImageReady(User*)));
180 connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
181 this, SIGNAL(routeTo(const GeoCoordinate&)));
184 void MainWindow::buildFullScreenButton()
186 qDebug() << __PRETTY_FUNCTION__;
189 m_fullScreenButton = new FullScreenButton(this);
191 if (m_fullScreenButton) {
192 connect(m_fullScreenButton, SIGNAL(clicked()),
193 this, SLOT(toggleFullScreen()));
195 connect(qApp, SIGNAL(showFullScreenButton()),
196 m_fullScreenButton, SLOT(invoke()));
198 #endif // Q_WS_MAEMO_5
201 void MainWindow::buildIndicatorButtonPanel()
203 qDebug() << __PRETTY_FUNCTION__;
205 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
207 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
208 this, SIGNAL(autoCenteringTriggered(bool)));
210 connect(m_mapView, SIGNAL(viewResized(QSize)),
211 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
213 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
214 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
216 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
217 this, SIGNAL(draggingModeTriggered()));
220 void MainWindow::buildInformationBox(const QString &message, bool modal)
222 qDebug() << __PRETTY_FUNCTION__;
224 QString errorMessage = message;
228 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
231 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
232 // extra line changes are needed to make error notes broader
233 errorMessage.prepend("\n");
234 errorMessage.append("\n");
236 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
238 QLabel *label = new QLabel(msgBox);
239 label->setAlignment(Qt::AlignCenter);
240 label->setText(errorMessage);
241 msgBox->setWidget(label);
243 QMessageBox *msgBox = new QMessageBox(this);
244 msgBox->button(QMessageBox::Ok);
245 msgBox->setText(errorMessage);
246 msgBox->setModal(modal);
252 void MainWindow::buildMap()
254 qDebug() << __PRETTY_FUNCTION__;
256 m_mapView = new MapView(this);
258 buildZoomButtonPanel();
261 buildFullScreenButton();
262 buildIndicatorButtonPanel();
265 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate, bool)),
266 this, SIGNAL(mapViewScrolled(SceneCoordinate, bool)));
268 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate, bool)),
269 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate, bool)));
271 connect(m_mapView, SIGNAL(viewResized(QSize)),
272 this, SIGNAL(mapViewResized(QSize)));
274 connect(m_mapView, SIGNAL(viewResized(QSize)),
275 this, SLOT(drawFullScreenButton(QSize)));
277 connect(m_mapView, SIGNAL(viewResized(QSize)),
278 this, SLOT(drawMapScale(QSize)));
280 connect(m_mapView, SIGNAL(viewResized(QSize)),
281 this, SLOT(moveCrosshair()));
283 connect(this, SIGNAL(zoomLevelChanged(int)),
284 m_mapView, SLOT(setZoomLevel(int)));
286 connect(m_mapView, SIGNAL(viewZoomFinished()),
287 this, SIGNAL(viewZoomFinished()));
289 connect(m_mapView, SIGNAL(zoomIn()),
290 this, SIGNAL(zoomIn()));
293 void MainWindow::buildMapScale()
295 m_mapScale = new MapScale(this);
296 connect(this, SIGNAL(newMapResolution(qreal)),
297 m_mapScale, SLOT(updateMapResolution(qreal)));
300 void MainWindow::buildOsmLicense()
302 qDebug() << __PRETTY_FUNCTION__;
304 m_osmLicense = new QLabel(this);
305 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
306 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
307 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
308 m_osmLicense->setFont(QFont("Nokia Sans", 9));
309 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
310 m_osmLicense->fontMetrics().height());
312 connect(m_mapView, SIGNAL(viewResized(QSize)),
313 this, SLOT(drawOsmLicense(QSize)));
316 void MainWindow::buildPanels()
318 qDebug() << __PRETTY_FUNCTION__;
320 buildUserInfoPanel();
321 buildFriendListPanel();
324 m_tabbedPanel = new TabbedPanel(this);
325 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
326 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
327 m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
329 connect(m_mapView, SIGNAL(viewResized(QSize)),
330 m_tabbedPanel, SLOT(resizePanel(QSize)));
332 connect(m_friendsListPanel, SIGNAL(showPanelRequested(QWidget*)),
333 m_tabbedPanel, SLOT(showPanel(QWidget*)));
335 connect(m_routingPanel, SIGNAL(showPanelRequested(QWidget*)),
336 m_tabbedPanel, SLOT(showPanel(QWidget*)));
338 connect(m_tabbedPanel, SIGNAL(panelClosed()),
339 m_friendsListPanel, SLOT(anyPanelClosed()));
341 connect(m_tabbedPanel, SIGNAL(panelOpened()),
342 m_friendsListPanel, SLOT(anyPanelOpened()));
344 connect(m_tabbedPanel, SIGNAL(panelClosed()),
345 m_routingPanel, SLOT(clearListsSelections()));
347 connect(m_tabbedPanel, SIGNAL(panelClosed()),
348 m_mapView, SLOT(disableCenterShift()));
350 connect(m_tabbedPanel, SIGNAL(panelOpened()),
351 m_mapView, SLOT(enableCenterShift()));
354 void MainWindow::buildRoutingPanel()
356 qDebug() << __PRETTY_FUNCTION__;
358 m_routingPanel = new RoutingPanel(this);
360 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
361 m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
363 connect(m_routingPanel,
364 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
366 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
368 connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
369 this, SIGNAL(routeTo(const GeoCoordinate&)));
371 connect(this, SIGNAL(routeParsed(Route&)),
372 m_routingPanel, SLOT(setRoute(Route&)));
374 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
375 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
377 connect(m_routingPanel, SIGNAL(requestSearchLocation()),
378 this, SLOT(startLocationSearch()));
381 void MainWindow::buildUserInfoPanel()
383 qDebug() << __PRETTY_FUNCTION__;
385 m_userInfoPanel = new UserInfoPanel(this);
387 connect(this, SIGNAL(userLocationReady(User*)),
388 m_userInfoPanel, SLOT(userDataReceived(User*)));
390 connect(this, SIGNAL(reverseGeoReady(QString)),
391 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
393 connect(this, SIGNAL(clearUpdateLocationDialogData()),
394 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
396 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
397 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
399 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
400 this, SIGNAL(requestReverseGeo()));
402 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
403 this, SIGNAL(statusUpdate(QString,bool)));
405 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
406 this, SIGNAL(refreshUserData()));
408 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
409 this, SLOT(buildInformationBox(QString, bool)));
412 void MainWindow::buildWebView()
414 qDebug() << __PRETTY_FUNCTION__;
417 m_webView = new QWebView;
420 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
422 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
424 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
425 this, SLOT(webViewRequestFinished(QNetworkReply*)));
426 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
427 this, SIGNAL(updateCredentials(QUrl)));
428 connect(m_webView, SIGNAL(loadFinished(bool)),
429 this, SLOT(loadDone(bool)));
435 void MainWindow::buildZoomButtonPanel()
437 qDebug() << __PRETTY_FUNCTION__;
439 m_zoomButtonPanel = new ZoomButtonPanel(this);
441 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
442 this, SIGNAL(zoomIn()));
444 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
445 this, SIGNAL(zoomOut()));
447 connect(this, SIGNAL(zoomLevelChanged(int)),
448 m_zoomButtonPanel, SLOT(resetButtons()));
450 connect(this, SIGNAL(maxZoomLevelReached()),
451 m_zoomButtonPanel, SLOT(disableZoomInButton()));
453 connect(this, SIGNAL(minZoomLevelReached()),
454 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
456 connect(m_mapView, SIGNAL(viewResized(QSize)),
457 m_zoomButtonPanel, SLOT(screenResized(QSize)));
459 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
460 this, SIGNAL(draggingModeTriggered()));
463 void MainWindow::clearCookieJar()
465 qDebug() << __PRETTY_FUNCTION__;
472 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
474 QList<QNetworkCookie> emptyList;
477 m_cookieJar->setAllCookies(emptyList);
478 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
481 void MainWindow::createMenus()
483 qDebug() << __PRETTY_FUNCTION__;
486 m_loginAct = new QAction(tr("Login"), this);
487 connect(m_loginAct, SIGNAL(triggered()),
488 this, SIGNAL(loginActionPressed()));
491 m_toSettingsAct = new QAction(tr("Settings"), this);
492 connect(m_toSettingsAct, SIGNAL(triggered()),
493 this, SLOT(openSettingsDialog()));
496 m_gpsToggleAct = new QAction(tr("GPS"), this);
497 m_gpsToggleAct->setCheckable(true);
499 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
500 this, SIGNAL(gpsTriggered(bool)));
502 // build the actual menu
503 m_viewMenu = menuBar()->addMenu(tr("Main"));
504 m_viewMenu->addAction(m_loginAct);
505 m_viewMenu->addAction(m_toSettingsAct);
506 m_viewMenu->addAction(m_gpsToggleAct);
507 m_viewMenu->setObjectName(tr("Menu"));
510 void MainWindow::dialogFinished(int status)
512 qDebug() << __PRETTY_FUNCTION__;
514 QDialog *dialog = m_queue.takeFirst();
515 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
516 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
520 loginDialog->userInput(m_email, m_password);
522 QStringList urlParts;
523 urlParts.append(FACEBOOK_LOGINBASE);
524 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
525 urlParts.append(INTERVAL1);
526 urlParts.append(SITUARE_LOGIN_SUCCESS);
527 urlParts.append(INTERVAL2);
528 urlParts.append(SITUARE_LOGIN_FAILURE);
529 urlParts.append(FACEBOOK_LOGIN_ENDING);
531 emit saveUsername(m_email);
533 m_webView->load(QUrl(urlParts.join(EMPTY)));
534 toggleProgressIndicator(true);
536 emit cancelLoginProcess();
538 } else if(searchDialog) {
540 emit searchForLocation(searchDialog->input());
544 dialog->deleteLater();
546 if(!m_error_queue.isEmpty() && m_errorShown == false) {
547 showErrorInformationBox();
549 if(!m_queue.isEmpty()) {
550 showInformationBox();
555 void MainWindow::drawFullScreenButton(const QSize &size)
557 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
559 if (m_fullScreenButton) {
560 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
561 size.height() - m_fullScreenButton->size().height());
565 void MainWindow::drawMapScale(const QSize &size)
567 qDebug() << __PRETTY_FUNCTION__;
569 const int LEFT_SCALE_MARGIN = 10;
570 const int BOTTOM_SCALE_MARGIN = 2;
572 m_mapScale->move(LEFT_SCALE_MARGIN,
573 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
576 void MainWindow::drawOsmLicense(const QSize &size)
578 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
580 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
582 size.height() - m_osmLicense->fontMetrics().height());
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::mapCenterHorizontalShiftingChanged(int shifting)
776 m_mapCenterHorizontalShifting = shifting;
780 void MainWindow::moveCrosshair()
782 qDebug() << __PRETTY_FUNCTION__;
785 int mapHeight = m_mapView->size().height();
786 int mapWidth = m_mapView->size().width();
787 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
788 - m_mapCenterHorizontalShifting,
789 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
793 void MainWindow::openSettingsDialog()
795 qDebug() << __PRETTY_FUNCTION__;
797 SettingsDialog *settingsDialog = new SettingsDialog(this);
798 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
799 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
801 settingsDialog->show();
804 void MainWindow::queueDialog(QDialog *dialog)
806 qDebug() << __PRETTY_FUNCTION__;
808 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
809 if(dialog->isModal()) {
810 m_error_queue.append(dialog);
812 m_queue.append(dialog);
815 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
816 if(m_error_queue.count() == 1 && m_errorShown == false)
817 showErrorInformationBox();
818 else if(m_queue.count() == 1 && m_errorShown == false)
819 showInformationBox();
822 void MainWindow::readAutomaticLocationUpdateSettings()
824 qDebug() << __PRETTY_FUNCTION__;
826 QSettings settings(DIRECTORY_NAME, FILE_NAME);
827 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
828 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
831 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
833 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
835 emit enableAutomaticLocationUpdate(false);
839 void MainWindow::saveCookies()
841 qDebug() << __PRETTY_FUNCTION__;
844 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
846 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
849 for(int i=0;i<cookieList.count();i++) {
850 QNetworkCookie cookie = cookieList.at(i);
851 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
852 list.append(QString(byteArray));
854 list.removeDuplicates();
856 QSettings settings(DIRECTORY_NAME, FILE_NAME);
857 settings.setValue(COOKIES, list);
860 void MainWindow::setCrosshairVisibility(bool visibility)
862 qDebug() << __PRETTY_FUNCTION__;
872 void MainWindow::setGPSButtonEnabled(bool enabled)
874 qDebug() << __PRETTY_FUNCTION__;
876 m_gpsToggleAct->setChecked(enabled);
879 void MainWindow::setIndicatorButtonEnabled(bool enabled)
881 qDebug() << __PRETTY_FUNCTION__;
883 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
886 void MainWindow::setMapViewScene(QGraphicsScene *scene)
888 qDebug() << __PRETTY_FUNCTION__;
890 m_mapView->setScene(scene);
893 void MainWindow::settingsDialogAccepted()
895 qDebug() << __PRETTY_FUNCTION__;
897 readAutomaticLocationUpdateSettings();
900 void MainWindow::setUsername(const QString &username)
902 qDebug() << __PRETTY_FUNCTION__;
907 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
909 qDebug() << __PRETTY_FUNCTION__;
911 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
912 tr("Automatic location update"), text,
913 QMessageBox::Yes | QMessageBox::No |
914 QMessageBox::Cancel, this);
915 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
916 this, SLOT(automaticUpdateDialogFinished(int)));
918 m_automaticUpdateLocationDialog->show();
921 void MainWindow::showErrorInformationBox()
923 qDebug() << __PRETTY_FUNCTION__;
925 if(m_error_queue.count()) {
927 QDialog *dialog = m_error_queue.first();
928 connect(dialog, SIGNAL(finished(int)),
929 this, SLOT(errorDialogFinished(int)));
934 void MainWindow::showInformationBox()
936 qDebug() << __PRETTY_FUNCTION__;
938 if(m_queue.count()) {
939 QDialog *dialog = m_queue.first();
940 connect(dialog, SIGNAL(finished(int)),
941 this, SLOT(dialogFinished(int)));
946 void MainWindow::showPanels()
948 qDebug() << __PRETTY_FUNCTION__;
950 ///< @todo check how this is called and can this method be removed
953 // if(!m_friendsListPanel->isVisible()) {
954 // m_friendsListPanel->show();
955 // m_friendsListPanelSidebar->show();
958 // if(!m_userPanel->isVisible()) {
959 // m_userPanel->show();
960 // m_userPanelSidebar->show();
965 void MainWindow::startLocationSearch()
967 qDebug() << __PRETTY_FUNCTION__;
969 SearchDialog *searchDialog = new SearchDialog();
970 queueDialog(searchDialog);
973 void MainWindow::startLoginProcess()
975 qDebug() << __PRETTY_FUNCTION__;
977 LoginDialog *loginDialog = new LoginDialog();
979 emit fetchUsernameFromSettings();
981 loginDialog->clearTextFields();
983 if(!m_email.isEmpty())
984 loginDialog->setEmailField(m_email);
986 queueDialog(loginDialog);
989 void MainWindow::toggleFullScreen()
991 qDebug() << __PRETTY_FUNCTION__;
993 if(windowState() == Qt::WindowNoState)
999 void MainWindow::toggleProgressIndicator(bool value)
1001 qDebug() << __PRETTY_FUNCTION__;
1005 m_progressIndicatorCount++;
1006 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1008 if(m_progressIndicatorCount > 0)
1009 m_progressIndicatorCount--;
1011 if(m_progressIndicatorCount == 0)
1012 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1016 #endif // Q_WS_MAEMO_5
1019 void MainWindow::updateItemVisibility()
1021 qDebug() << __PRETTY_FUNCTION__;
1023 ///< @todo can this be removed?
1025 // if(!m_loggedIn) {
1026 // m_friendsListPanel->closePanel();
1027 // m_friendsListPanel->hide();
1028 // m_friendsListPanelSidebar->hide();
1030 // m_userPanel->closePanel();
1031 // m_userPanel->hide();
1032 // m_userPanelSidebar->hide();
1036 const QString MainWindow::username()
1038 qDebug() << __PRETTY_FUNCTION__;
1043 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1045 qDebug() << __PRETTY_FUNCTION__;
1047 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1048 // qwebview starts to load a new page while the current page loading is not finished
1049 if(reply->error() != QNetworkReply::OperationCanceledError &&
1050 reply->error() != QNetworkReply::NoError) {
1051 emit error(ErrorContext::NETWORK, reply->error());