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"
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 #include "ossoabookdialog.h"
63 #endif // Q_WS_MAEMO_5
65 MainWindow::MainWindow(QWidget *parent)
66 : QMainWindow(parent),
70 m_mapCenterHorizontalShifting(0),
71 m_progressIndicatorCount(0),
73 m_email(), ///< @todo WTF?!?!?!?
76 m_fullScreenButton(0),
77 m_indicatorButtonPanel(0),
81 qDebug() << __PRETTY_FUNCTION__;
85 // map view is the only widget which size & location is handled automatically by the system
86 // default functionality
87 setCentralWidget(m_mapView);
92 setWindowTitle(tr("Situare"));
94 // set stacking order of widgets (from top to bottom)
95 // if the fullscreen button exists, then it is the topmost one, otherwise the tabbed panel is
96 if (m_fullScreenButton) {
97 m_tabbedPanel->stackUnder(m_fullScreenButton);
99 m_crosshair->stackUnder(m_tabbedPanel);
100 m_zoomButtonPanel->stackUnder(m_crosshair);
101 m_indicatorButtonPanel->stackUnder(m_zoomButtonPanel);
102 m_osmLicense->stackUnder(m_indicatorButtonPanel);
103 m_mapScale->stackUnder(m_osmLicense);
104 m_mapView->stackUnder(m_mapScale);
108 // Set default screen size
109 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
111 setAttribute(Qt::WA_Maemo5StackedWindow);
115 MainWindow::~MainWindow()
117 qDebug() << __PRETTY_FUNCTION__;
124 qDeleteAll(m_queue.begin(), m_queue.end());
127 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
128 m_error_queue.clear();
131 void MainWindow::automaticUpdateDialogFinished(int result)
133 qDebug() << __PRETTY_FUNCTION__;
135 if (result == QMessageBox::Yes) {
136 readAutomaticLocationUpdateSettings();
138 QSettings settings(DIRECTORY_NAME, FILE_NAME);
139 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
140 readAutomaticLocationUpdateSettings();
143 m_automaticUpdateLocationDialog->deleteLater();
146 void MainWindow::buildCrosshair()
148 qDebug() << __PRETTY_FUNCTION__;
150 m_crosshair = new QLabel(this);
151 QPixmap crosshairImage(":/res/images/sight.png");
152 m_crosshair->setPixmap(crosshairImage);
153 m_crosshair->setFixedSize(crosshairImage.size());
155 m_crosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
157 connect(m_mapView, SIGNAL(viewResized(QSize)),
158 this, SLOT(moveCrosshair()));
160 connect(m_mapView, SIGNAL(horizontalShiftingChanged(int)),
161 this, SLOT(mapCenterHorizontalShiftingChanged(int)));
164 void MainWindow::buildFriendListPanel()
166 qDebug() << __PRETTY_FUNCTION__;
168 m_friendsListPanel = new FriendListPanel(this);
170 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
171 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
173 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
174 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
176 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
177 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
179 connect(this, SIGNAL(friendImageReady(User*)),
180 m_friendsListPanel, SLOT(friendImageReady(User*)));
182 connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
183 this, SIGNAL(routeTo(const GeoCoordinate&)));
185 connect(m_friendsListPanel, SIGNAL(requestContactDialog(const QString &)),
186 this, SIGNAL(requestContactDialog(const QString &)));
189 void MainWindow::buildFullScreenButton()
191 qDebug() << __PRETTY_FUNCTION__;
194 m_fullScreenButton = new FullScreenButton(this);
196 if (m_fullScreenButton) {
197 connect(m_fullScreenButton, SIGNAL(clicked()),
198 this, SLOT(toggleFullScreen()));
200 connect(qApp, SIGNAL(showFullScreenButton()),
201 m_fullScreenButton, SLOT(invoke()));
203 #endif // Q_WS_MAEMO_5
206 void MainWindow::buildIndicatorButtonPanel()
208 qDebug() << __PRETTY_FUNCTION__;
210 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
212 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
213 this, SIGNAL(autoCenteringTriggered(bool)));
215 connect(m_mapView, SIGNAL(viewResized(QSize)),
216 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
218 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
219 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
221 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
222 this, SIGNAL(draggingModeTriggered()));
225 void MainWindow::buildInformationBox(const QString &message, bool modal)
227 qDebug() << __PRETTY_FUNCTION__;
229 QString errorMessage = message;
233 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
236 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
237 // extra line changes are needed to make error notes broader
238 errorMessage.prepend("\n");
239 errorMessage.append("\n");
241 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
243 QLabel *label = new QLabel(msgBox);
244 label->setAlignment(Qt::AlignCenter);
245 label->setText(errorMessage);
246 msgBox->setWidget(label);
248 QMessageBox *msgBox = new QMessageBox(this);
249 msgBox->button(QMessageBox::Ok);
250 msgBox->setText(errorMessage);
251 msgBox->setModal(modal);
257 void MainWindow::buildMap()
259 qDebug() << __PRETTY_FUNCTION__;
261 m_mapView = new MapView(this);
263 buildZoomButtonPanel();
266 buildFullScreenButton();
267 buildIndicatorButtonPanel();
270 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
271 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
273 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
274 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
276 connect(m_mapView, SIGNAL(viewResized(QSize)),
277 this, SIGNAL(mapViewResized(QSize)));
279 connect(m_mapView, SIGNAL(viewResized(QSize)),
280 this, SLOT(drawFullScreenButton(QSize)));
282 connect(m_mapView, SIGNAL(viewResized(QSize)),
283 this, SLOT(drawMapScale(QSize)));
285 connect(m_mapView, SIGNAL(viewResized(QSize)),
286 this, SLOT(moveCrosshair()));
288 connect(this, SIGNAL(zoomLevelChanged(int)),
289 m_mapView, SLOT(setZoomLevel(int)));
291 connect(m_mapView, SIGNAL(viewZoomFinished()),
292 this, SIGNAL(viewZoomFinished()));
294 connect(m_mapView, SIGNAL(zoomIn()),
295 this, SIGNAL(zoomIn()));
298 void MainWindow::buildMapScale()
300 m_mapScale = new MapScale(this);
301 connect(this, SIGNAL(newMapResolution(qreal)),
302 m_mapScale, SLOT(updateMapResolution(qreal)));
305 void MainWindow::buildOsmLicense()
307 qDebug() << __PRETTY_FUNCTION__;
309 m_osmLicense = new QLabel(this);
310 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
311 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
312 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
313 m_osmLicense->setFont(QFont("Nokia Sans", 9));
314 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
315 m_osmLicense->fontMetrics().height());
317 connect(m_mapView, SIGNAL(viewResized(QSize)),
318 this, SLOT(drawOsmLicense(QSize)));
321 void MainWindow::buildPanels()
323 qDebug() << __PRETTY_FUNCTION__;
325 buildUserInfoPanel();
326 buildFriendListPanel();
329 m_tabbedPanel = new TabbedPanel(this);
330 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
331 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
332 m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
334 connect(m_mapView, SIGNAL(viewResized(QSize)),
335 m_tabbedPanel, SLOT(resizePanel(QSize)));
337 connect(m_friendsListPanel, SIGNAL(showPanelRequested(QWidget*)),
338 m_tabbedPanel, SLOT(showPanel(QWidget*)));
340 connect(m_routingPanel, SIGNAL(showPanelRequested(QWidget*)),
341 m_tabbedPanel, SLOT(showPanel(QWidget*)));
343 connect(m_tabbedPanel, SIGNAL(panelClosed()),
344 m_friendsListPanel, SLOT(anyPanelClosed()));
346 connect(m_tabbedPanel, SIGNAL(panelOpened()),
347 m_friendsListPanel, SLOT(anyPanelOpened()));
349 connect(m_tabbedPanel, SIGNAL(panelClosed()),
350 m_routingPanel, SLOT(clearListsSelections()));
352 connect(m_tabbedPanel, SIGNAL(panelClosed()),
353 m_mapView, SLOT(disableCenterShift()));
355 connect(m_tabbedPanel, SIGNAL(panelOpened()),
356 m_mapView, SLOT(enableCenterShift()));
359 void MainWindow::buildRoutingPanel()
361 qDebug() << __PRETTY_FUNCTION__;
363 m_routingPanel = new RoutingPanel(this);
365 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
366 m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
368 connect(m_routingPanel,
369 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
371 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
373 connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
374 this, SIGNAL(routeTo(const GeoCoordinate&)));
376 connect(this, SIGNAL(routeParsed(Route&)),
377 m_routingPanel, SLOT(setRoute(Route&)));
379 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
380 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
382 connect(m_routingPanel, SIGNAL(requestSearchLocation()),
383 this, SLOT(startLocationSearch()));
386 void MainWindow::buildUserInfoPanel()
388 qDebug() << __PRETTY_FUNCTION__;
390 m_userInfoPanel = new UserInfoPanel(this);
392 connect(this, SIGNAL(userLocationReady(User*)),
393 m_userInfoPanel, SLOT(userDataReceived(User*)));
395 connect(this, SIGNAL(reverseGeoReady(QString)),
396 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
398 connect(this, SIGNAL(clearUpdateLocationDialogData()),
399 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
401 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
402 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
404 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
405 this, SIGNAL(requestReverseGeo()));
407 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
408 this, SIGNAL(statusUpdate(QString,bool)));
410 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
411 this, SIGNAL(refreshUserData()));
413 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
414 this, SLOT(buildInformationBox(QString, bool)));
417 void MainWindow::buildWebView()
419 qDebug() << __PRETTY_FUNCTION__;
422 m_webView = new QWebView;
425 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
427 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
429 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
430 this, SLOT(webViewRequestFinished(QNetworkReply*)));
431 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
432 this, SIGNAL(updateCredentials(QUrl)));
433 connect(m_webView, SIGNAL(loadFinished(bool)),
434 this, SLOT(loadDone(bool)));
440 void MainWindow::buildZoomButtonPanel()
442 qDebug() << __PRETTY_FUNCTION__;
444 m_zoomButtonPanel = new ZoomButtonPanel(this);
446 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
447 this, SIGNAL(zoomIn()));
449 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
450 this, SIGNAL(zoomOut()));
452 connect(this, SIGNAL(zoomLevelChanged(int)),
453 m_zoomButtonPanel, SLOT(resetButtons()));
455 connect(this, SIGNAL(maxZoomLevelReached()),
456 m_zoomButtonPanel, SLOT(disableZoomInButton()));
458 connect(this, SIGNAL(minZoomLevelReached()),
459 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
461 connect(m_mapView, SIGNAL(viewResized(QSize)),
462 m_zoomButtonPanel, SLOT(screenResized(QSize)));
464 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
465 this, SIGNAL(draggingModeTriggered()));
468 void MainWindow::clearCookieJar()
470 qDebug() << __PRETTY_FUNCTION__;
477 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
479 QList<QNetworkCookie> emptyList;
482 m_cookieJar->setAllCookies(emptyList);
483 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
486 void MainWindow::createMenus()
488 qDebug() << __PRETTY_FUNCTION__;
491 m_loginAct = new QAction(tr("Login"), this);
492 connect(m_loginAct, SIGNAL(triggered()),
493 this, SIGNAL(loginActionPressed()));
496 m_toSettingsAct = new QAction(tr("Settings"), this);
497 connect(m_toSettingsAct, SIGNAL(triggered()),
498 this, SLOT(openSettingsDialog()));
501 m_gpsToggleAct = new QAction(tr("GPS"), this);
502 m_gpsToggleAct->setCheckable(true);
504 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
505 this, SIGNAL(gpsTriggered(bool)));
507 // build the actual menu
508 m_viewMenu = menuBar()->addMenu(tr("Main"));
509 m_viewMenu->addAction(m_loginAct);
510 m_viewMenu->addAction(m_toSettingsAct);
511 m_viewMenu->addAction(m_gpsToggleAct);
512 m_viewMenu->setObjectName(tr("Menu"));
515 void MainWindow::dialogFinished(int status)
517 qDebug() << __PRETTY_FUNCTION__;
519 QDialog *dialog = m_queue.takeFirst();
520 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
521 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
525 loginDialog->userInput(m_email, m_password);
527 QStringList urlParts;
528 urlParts.append(FACEBOOK_LOGINBASE);
529 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
530 urlParts.append(INTERVAL1);
531 urlParts.append(SITUARE_LOGIN_SUCCESS);
532 urlParts.append(INTERVAL2);
533 urlParts.append(SITUARE_LOGIN_FAILURE);
534 urlParts.append(FACEBOOK_LOGIN_ENDING);
536 emit saveUsername(m_email);
538 m_webView->load(QUrl(urlParts.join(EMPTY)));
539 toggleProgressIndicator(true);
541 emit cancelLoginProcess();
543 } else if(searchDialog) {
545 emit searchForLocation(searchDialog->input());
549 dialog->deleteLater();
551 if(!m_error_queue.isEmpty() && m_errorShown == false) {
552 showErrorInformationBox();
554 if(!m_queue.isEmpty()) {
555 showInformationBox();
560 void MainWindow::drawFullScreenButton(const QSize &size)
562 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
564 if (m_fullScreenButton) {
565 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
566 size.height() - m_fullScreenButton->size().height());
570 void MainWindow::drawMapScale(const QSize &size)
572 qDebug() << __PRETTY_FUNCTION__;
574 const int LEFT_SCALE_MARGIN = 10;
575 const int BOTTOM_SCALE_MARGIN = 2;
577 m_mapScale->move(LEFT_SCALE_MARGIN,
578 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
581 void MainWindow::drawOsmLicense(const QSize &size)
583 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
585 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
587 size.height() - m_osmLicense->fontMetrics().height());
590 void MainWindow::errorDialogFinished(int status)
592 qDebug() << __PRETTY_FUNCTION__;
595 QDialog *dialog = m_error_queue.takeFirst();
597 dialog->deleteLater();
598 m_errorShown = false;
600 if(!m_error_queue.isEmpty())
601 showErrorInformationBox();
602 else if(!m_queue.isEmpty())
603 showInformationBox();
606 void MainWindow::gpsTimeout()
608 qDebug() << __PRETTY_FUNCTION__;
610 buildInformationBox(tr("GPS timeout"));
613 void MainWindow::grabZoomKeys(bool grab)
615 qDebug() << __PRETTY_FUNCTION__;
618 // Can't grab keys unless we have a window id
622 unsigned long val = (grab) ? 1 : 0;
623 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
627 XChangeProperty (QX11Info::display(),
633 reinterpret_cast<unsigned char *>(&val),
637 #endif // Q_WS_MAEMO_5
640 void MainWindow::keyPressEvent(QKeyEvent* event)
642 qDebug() << __PRETTY_FUNCTION__;
644 switch (event->key()) {
655 QWidget::keyPressEvent(event);
658 void MainWindow::loadCookies()
660 qDebug() << __PRETTY_FUNCTION__;
662 QSettings settings(DIRECTORY_NAME, FILE_NAME);
664 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
666 if(!list.isEmpty()) {
667 QList<QNetworkCookie> cookieList;
668 for(int i=0;i<list.count();i++) {
669 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
673 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
675 m_cookieJar->setAllCookies(cookieList);
676 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
680 void MainWindow::loadDone(bool done)
682 qDebug() << __PRETTY_FUNCTION__;
684 // for the first time the login page is opened, we need to refresh it to get cookies working
692 QWebFrame* frame = m_webView->page()->currentFrame();
696 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
698 foreach (QWebElement element, emailCollection) {
699 element.setAttribute("value", m_email.toAscii());
702 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
703 foreach (QWebElement element, passwordCollection) {
704 element.setAttribute("value", m_password.toAscii());
706 // find connect button
707 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
708 foreach (QWebElement element, buttonCollection)
710 QPoint pos(element.geometry().center());
712 // send a mouse click event to the web page
713 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
715 QApplication::sendEvent(m_webView->page(), &event0);
716 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
718 QApplication::sendEvent(m_webView->page(), &event1);
724 void MainWindow::loggedIn(bool logged)
726 qDebug() << __PRETTY_FUNCTION__;
731 m_loginAct->setText(tr("Logout"));
737 m_loginAct->setText(tr("Login"));
739 updateItemVisibility();
742 void MainWindow::loginFailed()
744 qDebug() << __PRETTY_FUNCTION__;
750 bool MainWindow::loginState()
752 qDebug() << __PRETTY_FUNCTION__;
757 void MainWindow::loginUsingCookies()
759 qDebug() << __PRETTY_FUNCTION__;
761 toggleProgressIndicator(true);
766 QStringList urlParts;
767 urlParts.append(FACEBOOK_LOGINBASE);
768 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
769 urlParts.append(INTERVAL1);
770 urlParts.append(SITUARE_LOGIN_SUCCESS);
771 urlParts.append(INTERVAL2);
772 urlParts.append(SITUARE_LOGIN_FAILURE);
773 urlParts.append(FACEBOOK_LOGIN_ENDING);
775 m_webView->load(QUrl(urlParts.join(EMPTY)));
779 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
781 m_mapCenterHorizontalShifting = shifting;
785 void MainWindow::moveCrosshair()
787 qDebug() << __PRETTY_FUNCTION__;
790 int mapHeight = m_mapView->size().height();
791 int mapWidth = m_mapView->size().width();
792 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
793 - m_mapCenterHorizontalShifting,
794 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
798 void MainWindow::openSettingsDialog()
800 qDebug() << __PRETTY_FUNCTION__;
802 SettingsDialog *settingsDialog = new SettingsDialog(this);
803 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
804 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
806 settingsDialog->show();
809 void MainWindow::queueDialog(QDialog *dialog)
811 qDebug() << __PRETTY_FUNCTION__;
813 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
814 if(dialog->isModal()) {
815 m_error_queue.append(dialog);
817 m_queue.append(dialog);
820 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
821 if(m_error_queue.count() == 1 && m_errorShown == false)
822 showErrorInformationBox();
823 else if(m_queue.count() == 1 && m_errorShown == false)
824 showInformationBox();
827 void MainWindow::readAutomaticLocationUpdateSettings()
829 qDebug() << __PRETTY_FUNCTION__;
831 QSettings settings(DIRECTORY_NAME, FILE_NAME);
832 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
833 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
836 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
838 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
840 emit enableAutomaticLocationUpdate(false);
844 void MainWindow::saveCookies()
846 qDebug() << __PRETTY_FUNCTION__;
849 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
851 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
854 for(int i=0;i<cookieList.count();i++) {
855 QNetworkCookie cookie = cookieList.at(i);
856 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
857 list.append(QString(byteArray));
859 list.removeDuplicates();
861 QSettings settings(DIRECTORY_NAME, FILE_NAME);
862 settings.setValue(COOKIES, list);
865 void MainWindow::setCrosshairVisibility(bool visibility)
867 qDebug() << __PRETTY_FUNCTION__;
877 void MainWindow::setGPSButtonEnabled(bool enabled)
879 qDebug() << __PRETTY_FUNCTION__;
881 m_gpsToggleAct->setChecked(enabled);
884 void MainWindow::setIndicatorButtonEnabled(bool enabled)
886 qDebug() << __PRETTY_FUNCTION__;
888 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
891 void MainWindow::setMapViewScene(QGraphicsScene *scene)
893 qDebug() << __PRETTY_FUNCTION__;
895 m_mapView->setScene(scene);
898 void MainWindow::settingsDialogAccepted()
900 qDebug() << __PRETTY_FUNCTION__;
902 readAutomaticLocationUpdateSettings();
905 void MainWindow::setUsername(const QString &username)
907 qDebug() << __PRETTY_FUNCTION__;
912 void MainWindow::showContactDialog(const QString &guid)
914 qDebug() << __PRETTY_FUNCTION__ << guid;
916 #if defined(Q_WS_MAEMO_5) & defined(ARMEL)
917 OssoABookDialog::showContactDialog(guid);
921 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
923 qDebug() << __PRETTY_FUNCTION__;
925 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
926 tr("Automatic location update"), text,
927 QMessageBox::Yes | QMessageBox::No |
928 QMessageBox::Cancel, this);
929 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
930 this, SLOT(automaticUpdateDialogFinished(int)));
932 m_automaticUpdateLocationDialog->show();
935 void MainWindow::showErrorInformationBox()
937 qDebug() << __PRETTY_FUNCTION__;
939 if(m_error_queue.count()) {
941 QDialog *dialog = m_error_queue.first();
942 connect(dialog, SIGNAL(finished(int)),
943 this, SLOT(errorDialogFinished(int)));
948 void MainWindow::showInformationBox()
950 qDebug() << __PRETTY_FUNCTION__;
952 if(m_queue.count()) {
953 QDialog *dialog = m_queue.first();
954 connect(dialog, SIGNAL(finished(int)),
955 this, SLOT(dialogFinished(int)));
960 void MainWindow::showPanels()
962 qDebug() << __PRETTY_FUNCTION__;
964 ///< @todo check how this is called and can this method be removed
967 // if(!m_friendsListPanel->isVisible()) {
968 // m_friendsListPanel->show();
969 // m_friendsListPanelSidebar->show();
972 // if(!m_userPanel->isVisible()) {
973 // m_userPanel->show();
974 // m_userPanelSidebar->show();
979 void MainWindow::startLocationSearch()
981 qDebug() << __PRETTY_FUNCTION__;
983 SearchDialog *searchDialog = new SearchDialog();
984 queueDialog(searchDialog);
987 void MainWindow::startLoginProcess()
989 qDebug() << __PRETTY_FUNCTION__;
991 LoginDialog *loginDialog = new LoginDialog();
993 emit fetchUsernameFromSettings();
995 loginDialog->clearTextFields();
997 if(!m_email.isEmpty())
998 loginDialog->setEmailField(m_email);
1000 queueDialog(loginDialog);
1003 void MainWindow::toggleFullScreen()
1005 qDebug() << __PRETTY_FUNCTION__;
1007 if(windowState() == Qt::WindowNoState)
1013 void MainWindow::toggleProgressIndicator(bool value)
1015 qDebug() << __PRETTY_FUNCTION__;
1019 m_progressIndicatorCount++;
1020 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1022 if(m_progressIndicatorCount > 0)
1023 m_progressIndicatorCount--;
1025 if(m_progressIndicatorCount == 0)
1026 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1030 #endif // Q_WS_MAEMO_5
1033 void MainWindow::updateItemVisibility()
1035 qDebug() << __PRETTY_FUNCTION__;
1037 ///< @todo can this be removed?
1039 // if(!m_loggedIn) {
1040 // m_friendsListPanel->closePanel();
1041 // m_friendsListPanel->hide();
1042 // m_friendsListPanelSidebar->hide();
1044 // m_userPanel->closePanel();
1045 // m_userPanel->hide();
1046 // m_userPanelSidebar->hide();
1050 const QString MainWindow::username()
1052 qDebug() << __PRETTY_FUNCTION__;
1057 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1059 qDebug() << __PRETTY_FUNCTION__;
1061 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1062 // qwebview starts to load a new page while the current page loading is not finished
1063 if(reply->error() != QNetworkReply::OperationCanceledError &&
1064 reply->error() != QNetworkReply::NoError) {
1065 emit error(ErrorContext::NETWORK, reply->error());