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
11 Situare is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 version 2 as published by the Free Software Foundation.
15 Situare is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with Situare; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 #include <QtAlgorithms>
30 #include "facebookservice/facebookauthentication.h"
31 #include "map/mapcommon.h"
32 #include "map/mapview.h"
34 #include "friendlistpanel.h"
35 #include "fullscreenbutton.h"
36 #include "indicatorbutton.h"
37 #include "logindialog.h"
39 #include "searchdialog.h"
40 #include "settingsdialog.h"
41 #include "userinfopanel.h"
42 #include "zoombuttonpanel.h"
44 #include "mainwindow.h"
46 // These MUST BE HERE, compiling for Maemo fails if moved
48 #include <QtMaemo5/QMaemo5InformationBox>
49 #include <QtGui/QX11Info>
50 #include <X11/Xatom.h>
52 #endif // Q_WS_MAEMO_5
54 MainWindow::MainWindow(QWidget *parent)
55 : QMainWindow(parent),
56 m_drawOwnLocationCrosshair(false),
60 m_progressIndicatorCount(0),
61 m_ownLocationCrosshair(0),
65 m_fullScreenButton(0),
70 qDebug() << __PRETTY_FUNCTION__;
75 QHBoxLayout *layout = new QHBoxLayout;
76 layout->addWidget(m_mapView);
78 layout->setSpacing(0);
80 setCentralWidget(new QWidget());
81 centralWidget()->setLayout(layout);
83 buildFriendListPanel();
87 setWindowTitle(tr("Situare"));
89 // set stacking order of widgets
90 m_zoomButtonPanel->stackUnder(m_userPanel);
91 if(m_fullScreenButton) {
92 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
93 m_osmLicense->stackUnder(m_fullScreenButton);
95 m_osmLicense->stackUnder(m_zoomButtonPanel);
97 m_ownLocationCrosshair->stackUnder(m_osmLicense);
98 m_indicatorButton->stackUnder(m_ownLocationCrosshair);
99 m_mapScale->stackUnder(m_indicatorButton);
100 m_mapView->stackUnder(m_mapScale);
104 // Set default screen size
105 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
107 setAttribute(Qt::WA_Maemo5StackedWindow);
111 MainWindow::~MainWindow()
113 qDebug() << __PRETTY_FUNCTION__;
120 qDeleteAll(m_queue.begin(), m_queue.end());
123 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
124 m_error_queue.clear();
127 void MainWindow::automaticUpdateDialogFinished(int result)
129 qDebug() << __PRETTY_FUNCTION__;
131 if (result == QMessageBox::Yes) {
132 readAutomaticLocationUpdateSettings();
134 QSettings settings(DIRECTORY_NAME, FILE_NAME);
135 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
136 readAutomaticLocationUpdateSettings();
139 m_automaticUpdateLocationDialog->deleteLater();
142 void MainWindow::buildFullScreenButton()
144 qDebug() << __PRETTY_FUNCTION__;
146 m_fullScreenButton = new FullScreenButton(this);
147 connect(m_fullScreenButton, SIGNAL(clicked()),
148 this, SLOT(toggleFullScreen()));
149 #endif // Q_WS_MAEMO_5
152 void MainWindow::buildFriendListPanel()
154 qDebug() << __PRETTY_FUNCTION__;
156 m_friendsListPanel = new FriendListPanel(this);
158 m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
160 m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
162 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
163 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
165 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
166 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
168 connect(m_mapView, SIGNAL(viewResized(QSize)),
169 m_friendsListPanel, SLOT(resizePanel(QSize)));
171 connect(m_mapView, SIGNAL(viewResized(QSize)),
172 m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
174 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
175 this, SIGNAL(findFriend(GeoCoordinate)));
177 connect(this, SIGNAL(friendImageReady(User*)),
178 m_friendsListPanel, SLOT(friendImageReady(User*)));
181 void MainWindow::buildIndicatorButton()
183 qDebug() << __PRETTY_FUNCTION__;
185 m_indicatorButton = new IndicatorButton(this);
187 connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
188 this, SIGNAL(autoCenteringTriggered(bool)));
190 connect(m_mapView, SIGNAL(viewResized(QSize)),
191 m_indicatorButton, SLOT(screenResized(QSize)));
194 void MainWindow::buildInformationBox(const QString &message, bool modal)
196 qDebug() << __PRETTY_FUNCTION__;
198 QString errorMessage = message;
202 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
205 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
206 // extra line changes are needed to make error notes broader
207 errorMessage.prepend("\n");
208 errorMessage.append("\n");
210 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
212 QLabel *label = new QLabel(msgBox);
213 label->setAlignment(Qt::AlignCenter);
214 label->setText(errorMessage);
215 msgBox->setWidget(label);
217 QMessageBox *msgBox = new QMessageBox(this);
218 msgBox->button(QMessageBox::Ok);
219 msgBox->setText(errorMessage);
220 msgBox->setModal(modal);
226 void MainWindow::buildManualLocationCrosshair()
228 qDebug() << __PRETTY_FUNCTION__;
230 m_ownLocationCrosshair = new QLabel(this);
231 QPixmap crosshairImage(":/res/images/sight.png");
232 m_ownLocationCrosshair->setPixmap(crosshairImage);
233 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
234 m_ownLocationCrosshair->hide();
235 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
237 connect(m_mapView, SIGNAL(viewResized(QSize)),
238 this, SLOT(drawOwnLocationCrosshair(QSize)));
241 void MainWindow::buildMap()
243 qDebug() << __PRETTY_FUNCTION__;
245 m_mapView = new MapView(this);
247 buildZoomButtonPanel();
249 buildManualLocationCrosshair();
250 buildFullScreenButton();
251 buildIndicatorButton();
254 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
255 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
257 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
258 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
260 connect(m_mapView, SIGNAL(viewResized(QSize)),
261 this, SIGNAL(mapViewResized(QSize)));
263 connect(m_mapView, SIGNAL(viewResized(QSize)),
264 this, SLOT(drawFullScreenButton(QSize)));
266 connect(m_mapView, SIGNAL(viewResized(QSize)),
267 this, SLOT(drawMapScale(QSize)));
269 connect(m_mapView, SIGNAL(viewResized(QSize)),
270 this, SLOT(setViewPortSize(QSize)));
272 connect(this, SIGNAL(zoomLevelChanged(int)),
273 m_mapView, SLOT(setZoomLevel(int)));
275 connect(m_mapView, SIGNAL(viewZoomFinished()),
276 this, SIGNAL(viewZoomFinished()));
278 connect(m_mapView, SIGNAL(zoomIn()),
279 this, SIGNAL(zoomIn()));
282 void MainWindow::buildMapScale()
284 m_mapScale = new MapScale(this);
285 connect(this, SIGNAL(newMapResolution(qreal)),
286 m_mapScale, SLOT(updateMapResolution(qreal)));
289 void MainWindow::buildOsmLicense()
291 qDebug() << __PRETTY_FUNCTION__;
293 m_osmLicense = new QLabel(this);
294 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
295 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
296 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
297 m_osmLicense->setFont(QFont("Nokia Sans", 9));
298 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
299 m_osmLicense->fontMetrics().height());
301 connect(m_mapView, SIGNAL(viewResized(QSize)),
302 this, SLOT(drawOsmLicense(QSize)));
305 void MainWindow::buildUserInfoPanel()
307 qDebug() << __PRETTY_FUNCTION__;
309 m_userPanel = new UserInfoPanel(this);
311 m_userPanelSidebar = new PanelSideBar(this, LEFT);
313 m_userPanelSidebar->stackUnder(m_friendsListPanel);
314 m_userPanel->stackUnder(m_userPanelSidebar);
316 connect(this, SIGNAL(userLocationReady(User*)),
317 m_userPanel, SLOT(userDataReceived(User*)));
319 connect(this, SIGNAL(reverseGeoReady(QString)),
320 m_userPanel, SIGNAL(reverseGeoReady(QString)));
322 connect(this, SIGNAL(clearUpdateLocationDialogData()),
323 m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
325 connect(m_mapView, SIGNAL(viewResized(QSize)),
326 m_userPanel, SLOT(resizePanel(QSize)));
328 connect(m_mapView, SIGNAL(viewResized(QSize)),
329 m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
331 connect(m_userPanel, SIGNAL(findUser(GeoCoordinate)),
332 this, SIGNAL(findUser(GeoCoordinate)));
334 connect(m_userPanel, SIGNAL(requestReverseGeo()),
335 this, SIGNAL(requestReverseGeo()));
337 connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
338 this, SIGNAL(statusUpdate(QString,bool)));
340 connect(m_userPanel, SIGNAL(refreshUserData()),
341 this, SIGNAL(refreshUserData()));
343 connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
344 this, SLOT(buildInformationBox(QString, bool)));
347 void MainWindow::buildWebView()
349 qDebug() << __PRETTY_FUNCTION__;
352 m_webView = new QWebView;
355 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
357 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
359 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
360 this, SLOT(webViewRequestFinished(QNetworkReply*)));
361 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
362 this, SIGNAL(updateCredentials(QUrl)));
363 connect(m_webView, SIGNAL(loadFinished(bool)),
364 this, SLOT(loadDone(bool)));
370 void MainWindow::buildZoomButtonPanel()
372 qDebug() << __PRETTY_FUNCTION__;
374 m_zoomButtonPanel = new ZoomButtonPanel(this);
376 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
377 this, SIGNAL(zoomIn()));
379 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
380 this, SIGNAL(zoomOut()));
382 connect(this, SIGNAL(zoomLevelChanged(int)),
383 m_zoomButtonPanel, SLOT(resetButtons()));
385 connect(this, SIGNAL(maxZoomLevelReached()),
386 m_zoomButtonPanel, SLOT(disableZoomInButton()));
388 connect(this, SIGNAL(minZoomLevelReached()),
389 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
391 connect(m_mapView, SIGNAL(viewResized(QSize)),
392 m_zoomButtonPanel, SLOT(screenResized(QSize)));
396 void MainWindow::clearCookieJar()
398 qDebug() << __PRETTY_FUNCTION__;
405 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
407 QList<QNetworkCookie> emptyList;
410 m_cookieJar->setAllCookies(emptyList);
411 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
414 void MainWindow::createMenus()
416 qDebug() << __PRETTY_FUNCTION__;
419 m_loginAct = new QAction(tr("Login"), this);
420 connect(m_loginAct, SIGNAL(triggered()),
421 this, SIGNAL(loginActionPressed()));
424 m_toSettingsAct = new QAction(tr("Settings"), this);
425 connect(m_toSettingsAct, SIGNAL(triggered()),
426 this, SLOT(openSettingsDialog()));
429 m_gpsToggleAct = new QAction(tr("GPS"), this);
430 m_gpsToggleAct->setCheckable(true);
432 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
433 this, SIGNAL(gpsTriggered(bool)));
435 /// @todo remove when not needed!
436 m_searchLocationAct = new QAction(tr("Location search"), this);
437 connect(m_searchLocationAct, SIGNAL(triggered()),
438 this, SLOT(startLocationSearch()));
440 // build the actual menu
441 m_viewMenu = menuBar()->addMenu(tr("Main"));
442 m_viewMenu->addAction(m_loginAct);
443 m_viewMenu->addAction(m_toSettingsAct);
444 m_viewMenu->addAction(m_gpsToggleAct);
445 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
446 m_viewMenu->setObjectName(tr("Menu"));
449 void MainWindow::dialogFinished(int status)
451 qDebug() << __PRETTY_FUNCTION__;
453 QDialog *dialog = m_queue.takeFirst();
454 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
455 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
459 loginDialog->userInput(m_email, m_password);
461 QStringList urlParts;
462 urlParts.append(FACEBOOK_LOGINBASE);
463 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
464 urlParts.append(INTERVAL1);
465 urlParts.append(SITUARE_LOGIN_SUCCESS);
466 urlParts.append(INTERVAL2);
467 urlParts.append(SITUARE_LOGIN_FAILURE);
468 urlParts.append(FACEBOOK_LOGIN_ENDING);
470 emit saveUsername(m_email);
472 m_webView->load(QUrl(urlParts.join(EMPTY)));
473 toggleProgressIndicator(true);
475 emit cancelLoginProcess();
477 } else if(searchDialog) {
479 emit searchForLocation(searchDialog->input());
483 dialog->deleteLater();
485 if(!m_error_queue.isEmpty() && m_errorShown == false) {
486 showErrorInformationBox();
488 if(!m_queue.isEmpty()) {
489 showInformationBox();
494 void MainWindow::drawFullScreenButton(const QSize &size)
496 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
498 if(m_fullScreenButton) {
500 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
502 size.height() - m_fullScreenButton->size().height());
504 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
505 size.height() - m_fullScreenButton->size().height());
510 void MainWindow::drawMapScale(const QSize &size)
512 qDebug() << __PRETTY_FUNCTION__;
514 const int LEFT_SCALE_MARGIN = 10;
515 const int BOTTOM_SCALE_MARGIN = 2;
516 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
518 m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
519 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
522 void MainWindow::drawOsmLicense(const QSize &size)
524 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
526 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
528 size.height() - m_osmLicense->fontMetrics().height());
531 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
533 qDebug() << __PRETTY_FUNCTION__;
535 if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
536 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
537 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
541 void MainWindow::errorDialogFinished(int status)
543 qDebug() << __PRETTY_FUNCTION__;
546 QDialog *dialog = m_error_queue.takeFirst();
548 dialog->deleteLater();
549 m_errorShown = false;
551 if(!m_error_queue.isEmpty())
552 showErrorInformationBox();
553 else if(!m_queue.isEmpty())
554 showInformationBox();
557 void MainWindow::gpsTimeout()
559 qDebug() << __PRETTY_FUNCTION__;
561 buildInformationBox(tr("GPS timeout"));
564 void MainWindow::grabZoomKeys(bool grab)
566 qDebug() << __PRETTY_FUNCTION__;
569 // Can't grab keys unless we have a window id
573 unsigned long val = (grab) ? 1 : 0;
574 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
578 XChangeProperty (QX11Info::display(),
584 reinterpret_cast<unsigned char *>(&val),
588 #endif // Q_WS_MAEMO_5
591 void MainWindow::keyPressEvent(QKeyEvent* event)
593 qDebug() << __PRETTY_FUNCTION__;
595 switch (event->key()) {
606 QWidget::keyPressEvent(event);
609 void MainWindow::loadCookies()
611 qDebug() << __PRETTY_FUNCTION__;
613 QSettings settings(DIRECTORY_NAME, FILE_NAME);
615 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
617 if(!list.isEmpty()) {
618 QList<QNetworkCookie> cookieList;
619 for(int i=0;i<list.count();i++) {
620 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
624 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
626 m_cookieJar->setAllCookies(cookieList);
627 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
631 void MainWindow::loadDone(bool done)
633 qDebug() << __PRETTY_FUNCTION__;
635 // for the first time the login page is opened, we need to refresh it to get cookies working
643 QWebFrame* frame = m_webView->page()->currentFrame();
647 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
649 foreach (QWebElement element, emailCollection) {
650 element.setAttribute("value", m_email.toAscii());
653 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
654 foreach (QWebElement element, passwordCollection) {
655 element.setAttribute("value", m_password.toAscii());
657 // find connect button
658 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
659 foreach (QWebElement element, buttonCollection)
661 QPoint pos(element.geometry().center());
663 // send a mouse click event to the web page
664 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
666 QApplication::sendEvent(m_webView->page(), &event0);
667 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
669 QApplication::sendEvent(m_webView->page(), &event1);
675 void MainWindow::loggedIn(bool logged)
677 qDebug() << __PRETTY_FUNCTION__;
682 m_loginAct->setText(tr("Logout"));
688 m_loginAct->setText(tr("Login"));
690 updateItemVisibility();
693 void MainWindow::loginFailed()
695 qDebug() << __PRETTY_FUNCTION__;
701 bool MainWindow::loginState()
703 qDebug() << __PRETTY_FUNCTION__;
708 void MainWindow::loginUsingCookies()
710 qDebug() << __PRETTY_FUNCTION__;
712 toggleProgressIndicator(true);
717 QStringList urlParts;
718 urlParts.append(FACEBOOK_LOGINBASE);
719 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
720 urlParts.append(INTERVAL1);
721 urlParts.append(SITUARE_LOGIN_SUCCESS);
722 urlParts.append(INTERVAL2);
723 urlParts.append(SITUARE_LOGIN_FAILURE);
724 urlParts.append(FACEBOOK_LOGIN_ENDING);
726 m_webView->load(QUrl(urlParts.join(EMPTY)));
730 void MainWindow::openSettingsDialog()
732 qDebug() << __PRETTY_FUNCTION__;
734 SettingsDialog *settingsDialog = new SettingsDialog(this);
735 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
736 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
738 settingsDialog->show();
741 void MainWindow::readAutomaticLocationUpdateSettings()
743 qDebug() << __PRETTY_FUNCTION__;
745 QSettings settings(DIRECTORY_NAME, FILE_NAME);
746 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
747 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
750 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
752 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
754 emit enableAutomaticLocationUpdate(false);
758 void MainWindow::queueDialog(QDialog *dialog)
760 qDebug() << __PRETTY_FUNCTION__;
762 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
763 if(dialog->isModal()) {
764 m_error_queue.append(dialog);
766 m_queue.append(dialog);
769 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
770 if(m_error_queue.count() == 1 && m_errorShown == false)
771 showErrorInformationBox();
772 else if(m_queue.count() == 1 && m_errorShown == false)
773 showInformationBox();
776 void MainWindow::saveCookies()
778 qDebug() << __PRETTY_FUNCTION__;
781 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
783 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
786 for(int i=0;i<cookieList.count();i++) {
787 QNetworkCookie cookie = cookieList.at(i);
788 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
789 list.append(QString(byteArray));
791 list.removeDuplicates();
793 QSettings settings(DIRECTORY_NAME, FILE_NAME);
794 settings.setValue(COOKIES, list);
797 void MainWindow::setGPSButtonEnabled(bool enabled)
799 qDebug() << __PRETTY_FUNCTION__;
801 m_gpsToggleAct->setChecked(enabled);
803 setOwnLocationCrosshairVisibility(!enabled);
806 void MainWindow::setIndicatorButtonEnabled(bool enabled)
808 qDebug() << __PRETTY_FUNCTION__;
810 m_indicatorButton->setChecked(enabled);
814 void MainWindow::setMapViewScene(QGraphicsScene *scene)
816 qDebug() << __PRETTY_FUNCTION__;
818 m_mapView->setScene(scene);
821 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
823 qDebug() << __PRETTY_FUNCTION__;
825 if (visibility && m_loggedIn) {
826 m_ownLocationCrosshair->show();
827 m_drawOwnLocationCrosshair = true;
828 drawOwnLocationCrosshair(m_viewPortSize);
830 m_ownLocationCrosshair->hide();
831 m_drawOwnLocationCrosshair = false;
835 void MainWindow::settingsDialogAccepted()
837 qDebug() << __PRETTY_FUNCTION__;
839 readAutomaticLocationUpdateSettings();
842 void MainWindow::setUsername(const QString &username)
844 qDebug() << __PRETTY_FUNCTION__;
849 void MainWindow::setViewPortSize(const QSize &size)
851 qDebug() << __PRETTY_FUNCTION__;
853 m_viewPortSize = size;
856 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
858 qDebug() << __PRETTY_FUNCTION__;
860 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
861 tr("Automatic location update"), text,
862 QMessageBox::Yes | QMessageBox::No |
863 QMessageBox::Cancel, this);
864 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
865 this, SLOT(automaticUpdateDialogFinished(int)));
867 m_automaticUpdateLocationDialog->show();
870 void MainWindow::toggleFullScreen()
872 qDebug() << __PRETTY_FUNCTION__;
874 if(windowState() == Qt::WindowNoState)
880 void MainWindow::showErrorInformationBox()
882 qDebug() << __PRETTY_FUNCTION__;
884 if(m_error_queue.count()) {
886 QDialog *dialog = m_error_queue.first();
887 connect(dialog, SIGNAL(finished(int)),
888 this, SLOT(errorDialogFinished(int)));
893 void MainWindow::showInformationBox()
895 qDebug() << __PRETTY_FUNCTION__;
897 if(m_queue.count()) {
898 QDialog *dialog = m_queue.first();
899 connect(dialog, SIGNAL(finished(int)),
900 this, SLOT(dialogFinished(int)));
905 void MainWindow::showPanels()
907 qDebug() << __PRETTY_FUNCTION__;
909 drawFullScreenButton(m_viewPortSize);
912 if(!m_friendsListPanel->isVisible()) {
913 m_friendsListPanel->show();
914 m_friendsListPanelSidebar->show();
917 if(!m_userPanel->isVisible()) {
919 m_userPanelSidebar->show();
924 void MainWindow::startLocationSearch()
926 qDebug() << __PRETTY_FUNCTION__;
928 SearchDialog *searchDialog = new SearchDialog();
929 queueDialog(searchDialog);
932 void MainWindow::startLoginProcess()
934 qDebug() << __PRETTY_FUNCTION__;
936 LoginDialog *loginDialog = new LoginDialog();
938 emit fetchUsernameFromSettings();
940 loginDialog->clearTextFields();
942 if(!m_email.isEmpty())
943 loginDialog->setEmailField(m_email);
945 queueDialog(loginDialog);
948 void MainWindow::toggleProgressIndicator(bool value)
950 qDebug() << __PRETTY_FUNCTION__;
954 m_progressIndicatorCount++;
955 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
957 if(m_progressIndicatorCount > 0)
958 m_progressIndicatorCount--;
960 if(m_progressIndicatorCount == 0)
961 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
965 #endif // Q_WS_MAEMO_5
968 void MainWindow::updateItemVisibility()
970 qDebug() << __PRETTY_FUNCTION__;
974 if(!m_gpsToggleAct->isChecked())
975 setOwnLocationCrosshairVisibility(true);
977 m_friendsListPanel->closePanel();
978 m_friendsListPanel->hide();
979 m_friendsListPanelSidebar->hide();
980 m_userPanel->closePanel();
982 m_userPanelSidebar->hide();
983 setOwnLocationCrosshairVisibility(false);
987 const QString MainWindow::username()
989 qDebug() << __PRETTY_FUNCTION__;
994 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
996 qDebug() << __PRETTY_FUNCTION__;
998 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
999 // qwebview starts to load a new page while the current page loading is not finished
1000 if(reply->error() != QNetworkReply::OperationCanceledError &&
1001 reply->error() != QNetworkReply::NoError) {
1002 emit error(ErrorContext::NETWORK, reply->error());