2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Henri Lampela - henri.lampela@ixonos.com
6 Kaj Wallin - kaj.wallin@ixonos.com
7 Jussi Laitinen - jussi.laitinen@ixonos.com
8 Sami Rämö - sami.ramo@ixonos.com
9 Ville Tiensuu - ville.tiensuu@ixonos.com
10 Katri Kaikkonen - katri.kaikkonen@ixonos.com
12 Situare is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 version 2 as published by the Free Software Foundation.
16 Situare is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with Situare; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 #include <QApplication>
30 #include <QMessageBox>
31 #include <QtAlgorithms>
35 #include "facebookservice/facebookauthentication.h"
36 #include "map/mapcommon.h"
37 #include "map/mapview.h"
40 #include "friendlistpanel.h"
41 #include "fullscreenbutton.h"
42 #include "indicatorbuttonpanel.h"
43 #include "logindialog.h"
45 #include "panelcommon.h"
46 #include "routingpanel.h"
47 #include "tabbedpanel.h"
48 #include "searchdialog.h"
49 #include "settingsdialog.h"
50 #include "userinfopanel.h"
51 #include "zoombuttonpanel.h"
53 #include "mainwindow.h"
55 // These MUST BE HERE, compiling for Maemo fails if moved
57 #include <QtMaemo5/QMaemo5InformationBox>
58 #include <QtGui/QX11Info>
59 #include <X11/Xatom.h>
61 #endif // Q_WS_MAEMO_5
63 MainWindow::MainWindow(QWidget *parent)
64 : QMainWindow(parent),
68 m_progressIndicatorCount(0),
69 m_ownLocationCrosshair(0),
70 m_email(), ///< @todo WTF?!?!?!?
73 m_fullScreenButton(0),
74 m_indicatorButtonPanel(0),
78 qDebug() << __PRETTY_FUNCTION__;
82 // map view is the only widget which size & location is handled automatically by the system
83 // default functionality
84 setCentralWidget(m_mapView);
89 setWindowTitle(tr("Situare"));
91 // set stacking order of widgets (from top to bottom)
92 // if the fullscreen button exists, then it is the topmost one, otherwise the tabbed panel is
93 if (m_fullScreenButton) {
94 m_tabbedPanel->stackUnder(m_fullScreenButton);
96 m_ownLocationCrosshair->stackUnder(m_tabbedPanel);
97 m_zoomButtonPanel->stackUnder(m_ownLocationCrosshair);
98 m_indicatorButtonPanel->stackUnder(m_zoomButtonPanel);
99 m_osmLicense->stackUnder(m_indicatorButtonPanel);
100 m_mapScale->stackUnder(m_osmLicense);
101 m_mapView->stackUnder(m_mapScale);
105 // Set default screen size
106 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
108 setAttribute(Qt::WA_Maemo5StackedWindow);
112 MainWindow::~MainWindow()
114 qDebug() << __PRETTY_FUNCTION__;
121 qDeleteAll(m_queue.begin(), m_queue.end());
124 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
125 m_error_queue.clear();
128 void MainWindow::automaticUpdateDialogFinished(int result)
130 qDebug() << __PRETTY_FUNCTION__;
132 if (result == QMessageBox::Yes) {
133 readAutomaticLocationUpdateSettings();
135 QSettings settings(DIRECTORY_NAME, FILE_NAME);
136 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
137 readAutomaticLocationUpdateSettings();
140 m_automaticUpdateLocationDialog->deleteLater();
143 void MainWindow::buildFullScreenButton()
145 qDebug() << __PRETTY_FUNCTION__;
148 m_fullScreenButton = new FullScreenButton(this);
150 if (m_fullScreenButton) {
151 connect(m_fullScreenButton, SIGNAL(clicked()),
152 this, SLOT(toggleFullScreen()));
154 connect(qApp, SIGNAL(showFullScreenButton()),
155 m_fullScreenButton, SLOT(invoke()));
157 #endif // Q_WS_MAEMO_5
160 void MainWindow::buildFriendListPanel()
162 qDebug() << __PRETTY_FUNCTION__;
164 m_friendsListPanel = new FriendListPanel(this);
166 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
167 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
169 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
170 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
172 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
173 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
175 connect(this, SIGNAL(friendImageReady(User*)),
176 m_friendsListPanel, SLOT(friendImageReady(User*)));
178 connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
179 this, SIGNAL(routeTo(const GeoCoordinate&)));
182 void MainWindow::buildIndicatorButtonPanel()
184 qDebug() << __PRETTY_FUNCTION__;
186 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
188 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
189 this, SIGNAL(autoCenteringTriggered(bool)));
191 connect(m_mapView, SIGNAL(viewResized(QSize)),
192 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
194 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
195 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
197 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
198 this, SIGNAL(draggingModeTriggered()));
201 void MainWindow::buildInformationBox(const QString &message, bool modal)
203 qDebug() << __PRETTY_FUNCTION__;
205 QString errorMessage = message;
209 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
212 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
213 // extra line changes are needed to make error notes broader
214 errorMessage.prepend("\n");
215 errorMessage.append("\n");
217 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
219 QLabel *label = new QLabel(msgBox);
220 label->setAlignment(Qt::AlignCenter);
221 label->setText(errorMessage);
222 msgBox->setWidget(label);
224 QMessageBox *msgBox = new QMessageBox(this);
225 msgBox->button(QMessageBox::Ok);
226 msgBox->setText(errorMessage);
227 msgBox->setModal(modal);
233 void MainWindow::buildManualLocationCrosshair()
235 qDebug() << __PRETTY_FUNCTION__;
237 m_ownLocationCrosshair = new QLabel(this);
238 QPixmap crosshairImage(":/res/images/sight.png");
239 m_ownLocationCrosshair->setPixmap(crosshairImage);
240 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
241 m_ownLocationCrosshair->hide();
242 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
244 connect(m_mapView, SIGNAL(viewResized(QSize)),
245 this, SLOT(drawOwnLocationCrosshair(QSize)));
248 void MainWindow::buildMap()
250 qDebug() << __PRETTY_FUNCTION__;
252 m_mapView = new MapView(this);
254 buildZoomButtonPanel();
256 buildManualLocationCrosshair();
257 buildFullScreenButton();
258 buildIndicatorButtonPanel();
261 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
262 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
264 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
265 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
267 connect(m_mapView, SIGNAL(viewResized(QSize)),
268 this, SIGNAL(mapViewResized(QSize)));
270 connect(m_mapView, SIGNAL(viewResized(QSize)),
271 this, SLOT(drawFullScreenButton(QSize)));
273 connect(m_mapView, SIGNAL(viewResized(QSize)),
274 this, SLOT(drawMapScale(QSize)));
276 connect(m_mapView, SIGNAL(viewResized(QSize)),
277 this, SLOT(setViewPortSize(QSize)));
279 connect(this, SIGNAL(zoomLevelChanged(int)),
280 m_mapView, SLOT(setZoomLevel(int)));
282 connect(m_mapView, SIGNAL(viewZoomFinished()),
283 this, SIGNAL(viewZoomFinished()));
285 connect(m_mapView, SIGNAL(zoomIn()),
286 this, SIGNAL(zoomIn()));
289 void MainWindow::buildMapScale()
291 m_mapScale = new MapScale(this);
292 connect(this, SIGNAL(newMapResolution(qreal)),
293 m_mapScale, SLOT(updateMapResolution(qreal)));
296 void MainWindow::buildOsmLicense()
298 qDebug() << __PRETTY_FUNCTION__;
300 m_osmLicense = new QLabel(this);
301 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
302 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
303 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
304 m_osmLicense->setFont(QFont("Nokia Sans", 9));
305 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
306 m_osmLicense->fontMetrics().height());
308 connect(m_mapView, SIGNAL(viewResized(QSize)),
309 this, SLOT(drawOsmLicense(QSize)));
312 void MainWindow::buildPanels()
314 qDebug() << __PRETTY_FUNCTION__;
316 buildUserInfoPanel();
317 buildFriendListPanel();
320 m_tabbedPanel = new TabbedPanel(this);
321 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
322 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
323 m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
325 connect(m_mapView, SIGNAL(viewResized(QSize)),
326 m_tabbedPanel, SLOT(resizePanel(QSize)));
328 connect(m_friendsListPanel, SIGNAL(showPanelRequested(QWidget*)),
329 m_tabbedPanel, SLOT(showPanel(QWidget*)));
331 connect(m_routingPanel, SIGNAL(showPanelRequested(QWidget*)),
332 m_tabbedPanel, SLOT(showPanel(QWidget*)));
334 connect(m_tabbedPanel, SIGNAL(panelClosed()),
335 m_friendsListPanel, SLOT(anyPanelClosed()));
337 connect(m_tabbedPanel, SIGNAL(panelOpened()),
338 m_friendsListPanel, SLOT(anyPanelOpened()));
340 connect(m_tabbedPanel, SIGNAL(panelClosed()),
341 m_routingPanel, SLOT(clearListsSelections()));
344 void MainWindow::buildRoutingPanel()
346 qDebug() << __PRETTY_FUNCTION__;
348 m_routingPanel = new RoutingPanel(this);
350 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
351 m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
353 connect(m_routingPanel, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
354 this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
356 connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
357 this, SIGNAL(routeTo(const GeoCoordinate&)));
359 connect(this, SIGNAL(routeParsed(Route&)),
360 m_routingPanel, SLOT(setRoute(Route&)));
362 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
363 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
365 connect(m_routingPanel, SIGNAL(requestSearchLocation()),
366 this, SLOT(startLocationSearch()));
369 void MainWindow::buildUserInfoPanel()
371 qDebug() << __PRETTY_FUNCTION__;
373 m_userInfoPanel = new UserInfoPanel(this);
375 connect(this, SIGNAL(userLocationReady(User*)),
376 m_userInfoPanel, SLOT(userDataReceived(User*)));
378 connect(this, SIGNAL(reverseGeoReady(QString)),
379 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
381 connect(this, SIGNAL(clearUpdateLocationDialogData()),
382 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
384 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
385 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
387 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
388 this, SIGNAL(requestReverseGeo()));
390 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
391 this, SIGNAL(statusUpdate(QString,bool)));
393 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
394 this, SIGNAL(refreshUserData()));
396 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
397 this, SLOT(buildInformationBox(QString, bool)));
400 void MainWindow::buildWebView()
402 qDebug() << __PRETTY_FUNCTION__;
405 m_webView = new QWebView;
408 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
410 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
412 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
413 this, SLOT(webViewRequestFinished(QNetworkReply*)));
414 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
415 this, SIGNAL(updateCredentials(QUrl)));
416 connect(m_webView, SIGNAL(loadFinished(bool)),
417 this, SLOT(loadDone(bool)));
423 void MainWindow::buildZoomButtonPanel()
425 qDebug() << __PRETTY_FUNCTION__;
427 m_zoomButtonPanel = new ZoomButtonPanel(this);
429 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
430 this, SIGNAL(zoomIn()));
432 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
433 this, SIGNAL(zoomOut()));
435 connect(this, SIGNAL(zoomLevelChanged(int)),
436 m_zoomButtonPanel, SLOT(resetButtons()));
438 connect(this, SIGNAL(maxZoomLevelReached()),
439 m_zoomButtonPanel, SLOT(disableZoomInButton()));
441 connect(this, SIGNAL(minZoomLevelReached()),
442 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
444 connect(m_mapView, SIGNAL(viewResized(QSize)),
445 m_zoomButtonPanel, SLOT(screenResized(QSize)));
447 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
448 this, SIGNAL(draggingModeTriggered()));
451 void MainWindow::clearCookieJar()
453 qDebug() << __PRETTY_FUNCTION__;
460 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
462 QList<QNetworkCookie> emptyList;
465 m_cookieJar->setAllCookies(emptyList);
466 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
469 void MainWindow::createMenus()
471 qDebug() << __PRETTY_FUNCTION__;
474 m_loginAct = new QAction(tr("Login"), this);
475 connect(m_loginAct, SIGNAL(triggered()),
476 this, SIGNAL(loginActionPressed()));
479 m_toSettingsAct = new QAction(tr("Settings"), this);
480 connect(m_toSettingsAct, SIGNAL(triggered()),
481 this, SLOT(openSettingsDialog()));
484 m_gpsToggleAct = new QAction(tr("GPS"), this);
485 m_gpsToggleAct->setCheckable(true);
487 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
488 this, SIGNAL(gpsTriggered(bool)));
490 // build the actual menu
491 m_viewMenu = menuBar()->addMenu(tr("Main"));
492 m_viewMenu->addAction(m_loginAct);
493 m_viewMenu->addAction(m_toSettingsAct);
494 m_viewMenu->addAction(m_gpsToggleAct);
495 m_viewMenu->setObjectName(tr("Menu"));
498 void MainWindow::dialogFinished(int status)
500 qDebug() << __PRETTY_FUNCTION__;
502 QDialog *dialog = m_queue.takeFirst();
503 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
504 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
508 loginDialog->userInput(m_email, m_password);
510 QStringList urlParts;
511 urlParts.append(FACEBOOK_LOGINBASE);
512 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
513 urlParts.append(INTERVAL1);
514 urlParts.append(SITUARE_LOGIN_SUCCESS);
515 urlParts.append(INTERVAL2);
516 urlParts.append(SITUARE_LOGIN_FAILURE);
517 urlParts.append(FACEBOOK_LOGIN_ENDING);
519 emit saveUsername(m_email);
521 m_webView->load(QUrl(urlParts.join(EMPTY)));
522 toggleProgressIndicator(true);
524 emit cancelLoginProcess();
526 } else if(searchDialog) {
528 emit searchForLocation(searchDialog->input());
532 dialog->deleteLater();
534 if(!m_error_queue.isEmpty() && m_errorShown == false) {
535 showErrorInformationBox();
537 if(!m_queue.isEmpty()) {
538 showInformationBox();
543 void MainWindow::drawFullScreenButton(const QSize &size)
545 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
547 if (m_fullScreenButton) {
548 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
549 size.height() - m_fullScreenButton->size().height());
553 void MainWindow::drawMapScale(const QSize &size)
555 qDebug() << __PRETTY_FUNCTION__;
557 const int LEFT_SCALE_MARGIN = 10;
558 const int BOTTOM_SCALE_MARGIN = 2;
560 m_mapScale->move(LEFT_SCALE_MARGIN,
561 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
564 void MainWindow::drawOsmLicense(const QSize &size)
566 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
568 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
570 size.height() - m_osmLicense->fontMetrics().height());
573 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
575 qDebug() << __PRETTY_FUNCTION__;
577 if (m_ownLocationCrosshair != 0) {
578 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
579 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
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::openSettingsDialog()
774 qDebug() << __PRETTY_FUNCTION__;
776 SettingsDialog *settingsDialog = new SettingsDialog(this);
777 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
778 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
780 settingsDialog->show();
783 void MainWindow::readAutomaticLocationUpdateSettings()
785 qDebug() << __PRETTY_FUNCTION__;
787 QSettings settings(DIRECTORY_NAME, FILE_NAME);
788 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
789 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
792 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
794 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
796 emit enableAutomaticLocationUpdate(false);
800 void MainWindow::queueDialog(QDialog *dialog)
802 qDebug() << __PRETTY_FUNCTION__;
804 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
805 if(dialog->isModal()) {
806 m_error_queue.append(dialog);
808 m_queue.append(dialog);
811 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
812 if(m_error_queue.count() == 1 && m_errorShown == false)
813 showErrorInformationBox();
814 else if(m_queue.count() == 1 && m_errorShown == false)
815 showInformationBox();
818 void MainWindow::saveCookies()
820 qDebug() << __PRETTY_FUNCTION__;
823 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
825 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
828 for(int i=0;i<cookieList.count();i++) {
829 QNetworkCookie cookie = cookieList.at(i);
830 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
831 list.append(QString(byteArray));
833 list.removeDuplicates();
835 QSettings settings(DIRECTORY_NAME, FILE_NAME);
836 settings.setValue(COOKIES, list);
839 void MainWindow::setGPSButtonEnabled(bool enabled)
841 qDebug() << __PRETTY_FUNCTION__;
843 m_gpsToggleAct->setChecked(enabled);
846 void MainWindow::setIndicatorButtonEnabled(bool enabled)
848 qDebug() << __PRETTY_FUNCTION__;
850 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
853 void MainWindow::setMapViewScene(QGraphicsScene *scene)
855 qDebug() << __PRETTY_FUNCTION__;
857 m_mapView->setScene(scene);
860 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
862 qDebug() << __PRETTY_FUNCTION__;
865 m_ownLocationCrosshair->show();
866 drawOwnLocationCrosshair(m_viewPortSize);
868 m_ownLocationCrosshair->hide();
872 void MainWindow::settingsDialogAccepted()
874 qDebug() << __PRETTY_FUNCTION__;
876 readAutomaticLocationUpdateSettings();
879 void MainWindow::setUsername(const QString &username)
881 qDebug() << __PRETTY_FUNCTION__;
886 void MainWindow::setViewPortSize(const QSize &size)
888 qDebug() << __PRETTY_FUNCTION__;
890 m_viewPortSize = size;
893 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
895 qDebug() << __PRETTY_FUNCTION__;
897 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
898 tr("Automatic location update"), text,
899 QMessageBox::Yes | QMessageBox::No |
900 QMessageBox::Cancel, this);
901 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
902 this, SLOT(automaticUpdateDialogFinished(int)));
904 m_automaticUpdateLocationDialog->show();
907 void MainWindow::toggleFullScreen()
909 qDebug() << __PRETTY_FUNCTION__;
911 if(windowState() == Qt::WindowNoState)
917 void MainWindow::showErrorInformationBox()
919 qDebug() << __PRETTY_FUNCTION__;
921 if(m_error_queue.count()) {
923 QDialog *dialog = m_error_queue.first();
924 connect(dialog, SIGNAL(finished(int)),
925 this, SLOT(errorDialogFinished(int)));
930 void MainWindow::showInformationBox()
932 qDebug() << __PRETTY_FUNCTION__;
934 if(m_queue.count()) {
935 QDialog *dialog = m_queue.first();
936 connect(dialog, SIGNAL(finished(int)),
937 this, SLOT(dialogFinished(int)));
942 void MainWindow::showPanels()
944 qDebug() << __PRETTY_FUNCTION__;
946 ///< @todo check how this is called and can this method be removed
949 // if(!m_friendsListPanel->isVisible()) {
950 // m_friendsListPanel->show();
951 // m_friendsListPanelSidebar->show();
954 // if(!m_userPanel->isVisible()) {
955 // m_userPanel->show();
956 // m_userPanelSidebar->show();
961 void MainWindow::startLocationSearch()
963 qDebug() << __PRETTY_FUNCTION__;
965 SearchDialog *searchDialog = new SearchDialog();
966 queueDialog(searchDialog);
969 void MainWindow::startLoginProcess()
971 qDebug() << __PRETTY_FUNCTION__;
973 LoginDialog *loginDialog = new LoginDialog();
975 emit fetchUsernameFromSettings();
977 loginDialog->clearTextFields();
979 if(!m_email.isEmpty())
980 loginDialog->setEmailField(m_email);
982 queueDialog(loginDialog);
985 void MainWindow::toggleProgressIndicator(bool value)
987 qDebug() << __PRETTY_FUNCTION__;
991 m_progressIndicatorCount++;
992 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
994 if(m_progressIndicatorCount > 0)
995 m_progressIndicatorCount--;
997 if(m_progressIndicatorCount == 0)
998 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1002 #endif // Q_WS_MAEMO_5
1005 void MainWindow::updateItemVisibility()
1007 qDebug() << __PRETTY_FUNCTION__;
1009 ///< @todo can this be removed?
1011 // if(!m_loggedIn) {
1012 // m_friendsListPanel->closePanel();
1013 // m_friendsListPanel->hide();
1014 // m_friendsListPanelSidebar->hide();
1016 // m_userPanel->closePanel();
1017 // m_userPanel->hide();
1018 // m_userPanelSidebar->hide();
1022 const QString MainWindow::username()
1024 qDebug() << __PRETTY_FUNCTION__;
1029 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1031 qDebug() << __PRETTY_FUNCTION__;
1033 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1034 // qwebview starts to load a new page while the current page loading is not finished
1035 if(reply->error() != QNetworkReply::OperationCanceledError &&
1036 reply->error() != QNetworkReply::NoError) {
1037 emit error(ErrorContext::NETWORK, reply->error());