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)),
266 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
268 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
269 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
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, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
364 this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
366 connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
367 this, SIGNAL(routeTo(const GeoCoordinate&)));
369 connect(this, SIGNAL(routeParsed(Route&)),
370 m_routingPanel, SLOT(setRoute(Route&)));
372 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
373 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
375 connect(m_routingPanel, SIGNAL(requestSearchLocation()),
376 this, SLOT(startLocationSearch()));
379 void MainWindow::buildUserInfoPanel()
381 qDebug() << __PRETTY_FUNCTION__;
383 m_userInfoPanel = new UserInfoPanel(this);
385 connect(this, SIGNAL(userLocationReady(User*)),
386 m_userInfoPanel, SLOT(userDataReceived(User*)));
388 connect(this, SIGNAL(reverseGeoReady(QString)),
389 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
391 connect(this, SIGNAL(clearUpdateLocationDialogData()),
392 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
394 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
395 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
397 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
398 this, SIGNAL(requestReverseGeo()));
400 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
401 this, SIGNAL(statusUpdate(QString,bool)));
403 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
404 this, SIGNAL(refreshUserData()));
406 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
407 this, SLOT(buildInformationBox(QString, bool)));
410 void MainWindow::buildWebView()
412 qDebug() << __PRETTY_FUNCTION__;
415 m_webView = new QWebView;
418 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
420 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
422 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
423 this, SLOT(webViewRequestFinished(QNetworkReply*)));
424 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
425 this, SIGNAL(updateCredentials(QUrl)));
426 connect(m_webView, SIGNAL(loadFinished(bool)),
427 this, SLOT(loadDone(bool)));
433 void MainWindow::buildZoomButtonPanel()
435 qDebug() << __PRETTY_FUNCTION__;
437 m_zoomButtonPanel = new ZoomButtonPanel(this);
439 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
440 this, SIGNAL(zoomIn()));
442 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
443 this, SIGNAL(zoomOut()));
445 connect(this, SIGNAL(zoomLevelChanged(int)),
446 m_zoomButtonPanel, SLOT(resetButtons()));
448 connect(this, SIGNAL(maxZoomLevelReached()),
449 m_zoomButtonPanel, SLOT(disableZoomInButton()));
451 connect(this, SIGNAL(minZoomLevelReached()),
452 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
454 connect(m_mapView, SIGNAL(viewResized(QSize)),
455 m_zoomButtonPanel, SLOT(screenResized(QSize)));
457 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
458 this, SIGNAL(draggingModeTriggered()));
461 void MainWindow::clearCookieJar()
463 qDebug() << __PRETTY_FUNCTION__;
470 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
472 QList<QNetworkCookie> emptyList;
475 m_cookieJar->setAllCookies(emptyList);
476 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
479 void MainWindow::createMenus()
481 qDebug() << __PRETTY_FUNCTION__;
484 m_loginAct = new QAction(tr("Login"), this);
485 connect(m_loginAct, SIGNAL(triggered()),
486 this, SIGNAL(loginActionPressed()));
489 m_toSettingsAct = new QAction(tr("Settings"), this);
490 connect(m_toSettingsAct, SIGNAL(triggered()),
491 this, SLOT(openSettingsDialog()));
494 m_gpsToggleAct = new QAction(tr("GPS"), this);
495 m_gpsToggleAct->setCheckable(true);
497 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
498 this, SIGNAL(gpsTriggered(bool)));
500 // build the actual menu
501 m_viewMenu = menuBar()->addMenu(tr("Main"));
502 m_viewMenu->addAction(m_loginAct);
503 m_viewMenu->addAction(m_toSettingsAct);
504 m_viewMenu->addAction(m_gpsToggleAct);
505 m_viewMenu->setObjectName(tr("Menu"));
508 void MainWindow::dialogFinished(int status)
510 qDebug() << __PRETTY_FUNCTION__;
512 QDialog *dialog = m_queue.takeFirst();
513 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
514 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
518 loginDialog->userInput(m_email, m_password);
520 QStringList urlParts;
521 urlParts.append(FACEBOOK_LOGINBASE);
522 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
523 urlParts.append(INTERVAL1);
524 urlParts.append(SITUARE_LOGIN_SUCCESS);
525 urlParts.append(INTERVAL2);
526 urlParts.append(SITUARE_LOGIN_FAILURE);
527 urlParts.append(FACEBOOK_LOGIN_ENDING);
529 emit saveUsername(m_email);
531 m_webView->load(QUrl(urlParts.join(EMPTY)));
532 toggleProgressIndicator(true);
534 emit cancelLoginProcess();
536 } else if(searchDialog) {
538 emit searchForLocation(searchDialog->input());
542 dialog->deleteLater();
544 if(!m_error_queue.isEmpty() && m_errorShown == false) {
545 showErrorInformationBox();
547 if(!m_queue.isEmpty()) {
548 showInformationBox();
553 void MainWindow::drawFullScreenButton(const QSize &size)
555 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
557 if (m_fullScreenButton) {
558 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
559 size.height() - m_fullScreenButton->size().height());
563 void MainWindow::drawMapScale(const QSize &size)
565 qDebug() << __PRETTY_FUNCTION__;
567 const int LEFT_SCALE_MARGIN = 10;
568 const int BOTTOM_SCALE_MARGIN = 2;
570 m_mapScale->move(LEFT_SCALE_MARGIN,
571 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
574 void MainWindow::drawOsmLicense(const QSize &size)
576 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
578 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
580 size.height() - m_osmLicense->fontMetrics().height());
583 void MainWindow::errorDialogFinished(int status)
585 qDebug() << __PRETTY_FUNCTION__;
588 QDialog *dialog = m_error_queue.takeFirst();
590 dialog->deleteLater();
591 m_errorShown = false;
593 if(!m_error_queue.isEmpty())
594 showErrorInformationBox();
595 else if(!m_queue.isEmpty())
596 showInformationBox();
599 void MainWindow::gpsTimeout()
601 qDebug() << __PRETTY_FUNCTION__;
603 buildInformationBox(tr("GPS timeout"));
606 void MainWindow::grabZoomKeys(bool grab)
608 qDebug() << __PRETTY_FUNCTION__;
611 // Can't grab keys unless we have a window id
615 unsigned long val = (grab) ? 1 : 0;
616 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
620 XChangeProperty (QX11Info::display(),
626 reinterpret_cast<unsigned char *>(&val),
630 #endif // Q_WS_MAEMO_5
633 void MainWindow::keyPressEvent(QKeyEvent* event)
635 qDebug() << __PRETTY_FUNCTION__;
637 switch (event->key()) {
648 QWidget::keyPressEvent(event);
651 void MainWindow::loadCookies()
653 qDebug() << __PRETTY_FUNCTION__;
655 QSettings settings(DIRECTORY_NAME, FILE_NAME);
657 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
659 if(!list.isEmpty()) {
660 QList<QNetworkCookie> cookieList;
661 for(int i=0;i<list.count();i++) {
662 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
666 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
668 m_cookieJar->setAllCookies(cookieList);
669 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
673 void MainWindow::loadDone(bool done)
675 qDebug() << __PRETTY_FUNCTION__;
677 // for the first time the login page is opened, we need to refresh it to get cookies working
685 QWebFrame* frame = m_webView->page()->currentFrame();
689 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
691 foreach (QWebElement element, emailCollection) {
692 element.setAttribute("value", m_email.toAscii());
695 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
696 foreach (QWebElement element, passwordCollection) {
697 element.setAttribute("value", m_password.toAscii());
699 // find connect button
700 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
701 foreach (QWebElement element, buttonCollection)
703 QPoint pos(element.geometry().center());
705 // send a mouse click event to the web page
706 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
708 QApplication::sendEvent(m_webView->page(), &event0);
709 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
711 QApplication::sendEvent(m_webView->page(), &event1);
717 void MainWindow::loggedIn(bool logged)
719 qDebug() << __PRETTY_FUNCTION__;
724 m_loginAct->setText(tr("Logout"));
730 m_loginAct->setText(tr("Login"));
732 updateItemVisibility();
735 void MainWindow::loginFailed()
737 qDebug() << __PRETTY_FUNCTION__;
743 bool MainWindow::loginState()
745 qDebug() << __PRETTY_FUNCTION__;
750 void MainWindow::loginUsingCookies()
752 qDebug() << __PRETTY_FUNCTION__;
754 toggleProgressIndicator(true);
759 QStringList urlParts;
760 urlParts.append(FACEBOOK_LOGINBASE);
761 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
762 urlParts.append(INTERVAL1);
763 urlParts.append(SITUARE_LOGIN_SUCCESS);
764 urlParts.append(INTERVAL2);
765 urlParts.append(SITUARE_LOGIN_FAILURE);
766 urlParts.append(FACEBOOK_LOGIN_ENDING);
768 m_webView->load(QUrl(urlParts.join(EMPTY)));
772 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
774 m_mapCenterHorizontalShifting = shifting;
778 void MainWindow::moveCrosshair()
780 qDebug() << __PRETTY_FUNCTION__;
783 int mapHeight = m_mapView->size().height();
784 int mapWidth = m_mapView->size().width();
785 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
786 - m_mapCenterHorizontalShifting,
787 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
791 void MainWindow::openSettingsDialog()
793 qDebug() << __PRETTY_FUNCTION__;
795 SettingsDialog *settingsDialog = new SettingsDialog(this);
796 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
797 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
799 settingsDialog->show();
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::readAutomaticLocationUpdateSettings()
822 qDebug() << __PRETTY_FUNCTION__;
824 QSettings settings(DIRECTORY_NAME, FILE_NAME);
825 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
826 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
829 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
831 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
833 emit enableAutomaticLocationUpdate(false);
837 void MainWindow::saveCookies()
839 qDebug() << __PRETTY_FUNCTION__;
842 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
844 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
847 for(int i=0;i<cookieList.count();i++) {
848 QNetworkCookie cookie = cookieList.at(i);
849 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
850 list.append(QString(byteArray));
852 list.removeDuplicates();
854 QSettings settings(DIRECTORY_NAME, FILE_NAME);
855 settings.setValue(COOKIES, list);
858 void MainWindow::setCrosshairVisibility(bool visibility)
860 qDebug() << __PRETTY_FUNCTION__;
870 void MainWindow::setGPSButtonEnabled(bool enabled)
872 qDebug() << __PRETTY_FUNCTION__;
874 m_gpsToggleAct->setChecked(enabled);
877 void MainWindow::setIndicatorButtonEnabled(bool enabled)
879 qDebug() << __PRETTY_FUNCTION__;
881 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
884 void MainWindow::setMapViewScene(QGraphicsScene *scene)
886 qDebug() << __PRETTY_FUNCTION__;
888 m_mapView->setScene(scene);
891 void MainWindow::settingsDialogAccepted()
893 qDebug() << __PRETTY_FUNCTION__;
895 readAutomaticLocationUpdateSettings();
898 void MainWindow::setUsername(const QString &username)
900 qDebug() << __PRETTY_FUNCTION__;
905 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
907 qDebug() << __PRETTY_FUNCTION__;
909 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
910 tr("Automatic location update"), text,
911 QMessageBox::Yes | QMessageBox::No |
912 QMessageBox::Cancel, this);
913 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
914 this, SLOT(automaticUpdateDialogFinished(int)));
916 m_automaticUpdateLocationDialog->show();
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::toggleFullScreen()
989 qDebug() << __PRETTY_FUNCTION__;
991 if(windowState() == Qt::WindowNoState)
997 void MainWindow::toggleProgressIndicator(bool value)
999 qDebug() << __PRETTY_FUNCTION__;
1003 m_progressIndicatorCount++;
1004 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1006 if(m_progressIndicatorCount > 0)
1007 m_progressIndicatorCount--;
1009 if(m_progressIndicatorCount == 0)
1010 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1014 #endif // Q_WS_MAEMO_5
1017 void MainWindow::updateItemVisibility()
1019 qDebug() << __PRETTY_FUNCTION__;
1021 ///< @todo can this be removed?
1023 // if(!m_loggedIn) {
1024 // m_friendsListPanel->closePanel();
1025 // m_friendsListPanel->hide();
1026 // m_friendsListPanelSidebar->hide();
1028 // m_userPanel->closePanel();
1029 // m_userPanel->hide();
1030 // m_userPanelSidebar->hide();
1034 const QString MainWindow::username()
1036 qDebug() << __PRETTY_FUNCTION__;
1041 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1043 qDebug() << __PRETTY_FUNCTION__;
1045 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1046 // qwebview starts to load a new page while the current page loading is not finished
1047 if(reply->error() != QNetworkReply::OperationCanceledError &&
1048 reply->error() != QNetworkReply::NoError) {
1049 emit error(ErrorContext::NETWORK, reply->error());