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 "logindialog.h"
38 #include "settingsdialog.h"
39 #include "userinfopanel.h"
40 #include "zoombuttonpanel.h"
42 #include "mainwindow.h"
44 // These MUST BE HERE, compiling for Maemo fails if moved
46 #include <QtMaemo5/QMaemo5InformationBox>
47 #include <QtGui/QX11Info>
48 #include <X11/Xatom.h>
50 #endif // Q_WS_MAEMO_5
52 MainWindow::MainWindow(QWidget *parent)
53 : QMainWindow(parent),
54 m_drawOwnLocationCrosshair(false),
58 m_ownLocationCrosshair(0),
61 m_fullScreenButton(0),
66 qDebug() << __PRETTY_FUNCTION__;
71 QHBoxLayout *layout = new QHBoxLayout;
72 layout->addWidget(m_mapView);
74 layout->setSpacing(0);
76 setCentralWidget(new QWidget());
77 centralWidget()->setLayout(layout);
79 buildFriendListPanel();
83 setWindowTitle(tr("Situare"));
85 // set stacking order of widgets
86 m_zoomButtonPanel->stackUnder(m_userPanel);
87 if(m_fullScreenButton) {
88 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
89 m_osmLicense->stackUnder(m_fullScreenButton);
91 m_osmLicense->stackUnder(m_zoomButtonPanel);
93 m_ownLocationCrosshair->stackUnder(m_osmLicense);
94 m_mapScale->stackUnder(m_ownLocationCrosshair);
95 m_mapView->stackUnder(m_mapScale);
97 this->toggleProgressIndicator(true);
101 // Set default screen size
102 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
104 setAttribute(Qt::WA_Maemo5StackedWindow);
108 MainWindow::~MainWindow()
110 qDebug() << __PRETTY_FUNCTION__;
117 qDeleteAll(m_queue.begin(), m_queue.end());
120 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
121 m_error_queue.clear();
124 void MainWindow::automaticUpdateDialogFinished(int result)
126 qDebug() << __PRETTY_FUNCTION__;
128 if (result == QMessageBox::Yes) {
129 readAutomaticLocationUpdateSettings();
131 QSettings settings(DIRECTORY_NAME, FILE_NAME);
132 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
133 readAutomaticLocationUpdateSettings();
136 m_automaticUpdateLocationDialog->deleteLater();
139 void MainWindow::buildFullScreenButton()
141 qDebug() << __PRETTY_FUNCTION__;
143 m_fullScreenButton = new FullScreenButton(this);
144 connect(m_fullScreenButton, SIGNAL(clicked()),
145 this, SLOT(toggleFullScreen()));
146 #endif // Q_WS_MAEMO_5
149 void MainWindow::buildFriendListPanel()
151 qDebug() << __PRETTY_FUNCTION__;
153 m_friendsListPanel = new FriendListPanel(this);
155 m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
157 m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
159 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
160 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
162 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
163 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
165 connect(m_mapView, SIGNAL(viewResized(QSize)),
166 m_friendsListPanel, SLOT(resizePanel(QSize)));
168 connect(m_mapView, SIGNAL(viewResized(QSize)),
169 m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
171 connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
172 this, SIGNAL(findFriend(QPointF)));
175 void MainWindow::buildInformationBox(const QString &message, bool modal)
177 qDebug() << __PRETTY_FUNCTION__;
179 QString errorMessage = message;
183 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
186 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
187 // extra line changes are needed to make error notes broader
188 errorMessage.prepend("\n");
189 errorMessage.append("\n");
191 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
193 QLabel *label = new QLabel(msgBox);
194 label->setAlignment(Qt::AlignCenter);
195 label->setText(errorMessage);
196 msgBox->setWidget(label);
198 QMessageBox *msgBox = new QMessageBox(this);
199 msgBox->button(QMessageBox::Ok);
200 msgBox->setText(errorMessage);
201 msgBox->setModal(modal);
207 void MainWindow::buildManualLocationCrosshair()
209 qDebug() << __PRETTY_FUNCTION__;
211 m_ownLocationCrosshair = new QLabel(this);
212 QPixmap crosshairImage(":/res/images/sight.png");
213 m_ownLocationCrosshair->setPixmap(crosshairImage);
214 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
215 m_ownLocationCrosshair->hide();
216 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
218 connect(m_mapView, SIGNAL(viewResized(QSize)),
219 this, SLOT(drawOwnLocationCrosshair(QSize)));
222 void MainWindow::buildMap()
224 qDebug() << __PRETTY_FUNCTION__;
226 m_mapView = new MapView(this);
228 buildZoomButtonPanel();
230 buildManualLocationCrosshair();
231 buildFullScreenButton();
234 connect(m_mapView, SIGNAL(viewScrolled(QPoint)),
235 this, SIGNAL(mapViewScrolled(QPoint)));
237 connect(this, SIGNAL(centerToSceneCoordinates(QPoint)),
238 m_mapView, SLOT(centerToSceneCoordinates(QPoint)));
240 connect(m_mapView, SIGNAL(viewResized(QSize)),
241 this, SIGNAL(mapViewResized(QSize)));
243 connect(m_mapView, SIGNAL(viewResized(QSize)),
244 this, SLOT(drawFullScreenButton(QSize)));
246 connect(m_mapView, SIGNAL(viewResized(QSize)),
247 this, SLOT(drawMapScale(QSize)));
249 connect(m_mapView, SIGNAL(viewResized(QSize)),
250 this, SLOT(setViewPortSize(QSize)));
252 connect(this, SIGNAL(zoomLevelChanged(int)),
253 m_mapView, SLOT(setZoomLevel(int)));
255 connect(m_mapView, SIGNAL(viewZoomFinished()),
256 this, SIGNAL(viewZoomFinished()));
258 connect(m_mapView, SIGNAL(zoomIn()),
259 this, SIGNAL(zoomIn()));
262 void MainWindow::buildMapScale()
264 m_mapScale = new MapScale(this);
265 connect(this, SIGNAL(newMapResolution(qreal)),
266 m_mapScale, SLOT(updateMapResolution(qreal)));
269 void MainWindow::buildOsmLicense()
271 qDebug() << __PRETTY_FUNCTION__;
273 m_osmLicense = new QLabel(this);
274 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
275 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
276 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
277 m_osmLicense->setFont(QFont("Nokia Sans", 9));
278 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
279 m_osmLicense->fontMetrics().height());
281 connect(m_mapView, SIGNAL(viewResized(QSize)),
282 this, SLOT(drawOsmLicense(QSize)));
285 void MainWindow::buildUserInfoPanel()
287 qDebug() << __PRETTY_FUNCTION__;
289 m_userPanel = new UserInfoPanel(this);
291 m_userPanelSidebar = new PanelSideBar(this, LEFT);
293 m_userPanelSidebar->stackUnder(m_friendsListPanel);
294 m_userPanel->stackUnder(m_userPanelSidebar);
296 connect(this, SIGNAL(userLocationReady(User*)),
297 m_userPanel, SLOT(userDataReceived(User*)));
299 connect(this, SIGNAL(reverseGeoReady(QString)),
300 m_userPanel, SIGNAL(reverseGeoReady(QString)));
302 connect(this, SIGNAL(clearUpdateLocationDialogData()),
303 m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
305 connect(this, SIGNAL(messageSendingFailed(int)),
306 m_userPanel, SIGNAL(messageSendingFailed(int)));
308 connect(m_mapView, SIGNAL(viewResized(QSize)),
309 m_userPanel, SLOT(resizePanel(QSize)));
311 connect(m_mapView, SIGNAL(viewResized(QSize)),
312 m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
314 connect(m_userPanel, SIGNAL(findUser(QPointF)),
315 this, SIGNAL(findUser(QPointF)));
317 connect(m_userPanel, SIGNAL(requestReverseGeo()),
318 this, SIGNAL(requestReverseGeo()));
320 connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
321 this, SIGNAL(statusUpdate(QString,bool)));
323 connect(m_userPanel, SIGNAL(refreshUserData()),
324 this, SIGNAL(refreshUserData()));
326 connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
327 this, SLOT(buildInformationBox(QString, bool)));
330 void MainWindow::buildWebView()
332 qDebug() << __PRETTY_FUNCTION__;
335 m_webView = new QWebView;
338 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
340 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
342 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
343 this, SLOT(webViewRequestFinished(QNetworkReply*)));
344 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
345 this, SIGNAL(updateCredentials(QUrl)));
346 connect(m_webView, SIGNAL(loadFinished(bool)),
347 this, SLOT(loadDone(bool)));
353 void MainWindow::buildZoomButtonPanel()
355 qDebug() << __PRETTY_FUNCTION__;
357 m_zoomButtonPanel = new ZoomButtonPanel(this);
359 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
360 this, SIGNAL(zoomIn()));
362 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
363 this, SIGNAL(zoomOut()));
365 connect(this, SIGNAL(zoomLevelChanged(int)),
366 m_zoomButtonPanel, SLOT(resetButtons()));
368 connect(this, SIGNAL(maxZoomLevelReached()),
369 m_zoomButtonPanel, SLOT(disableZoomInButton()));
371 connect(this, SIGNAL(minZoomLevelReached()),
372 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
374 connect(m_mapView, SIGNAL(viewResized(QSize)),
375 m_zoomButtonPanel, SLOT(screenResized(QSize)));
378 void MainWindow::clearCookieJar()
380 qDebug() << __PRETTY_FUNCTION__;
387 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
389 QList<QNetworkCookie> emptyList;
392 m_cookieJar->setAllCookies(emptyList);
393 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
396 void MainWindow::createMenus()
398 qDebug() << __PRETTY_FUNCTION__;
401 m_loginAct = new QAction(tr("Login"), this);
402 connect(m_loginAct, SIGNAL(triggered()),
403 this, SIGNAL(loginActionPressed()));
406 m_toSettingsAct = new QAction(tr("Settings"), this);
407 connect(m_toSettingsAct, SIGNAL(triggered()),
408 this, SLOT(openSettingsDialog()));
411 m_gpsToggleAct = new QAction(tr("GPS"), this);
412 m_gpsToggleAct->setCheckable(true);
414 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
415 this, SIGNAL(gpsTriggered(bool)));
417 // automatic centering
418 m_autoCenteringAct = new QAction(tr("Auto centering"), this);
419 m_autoCenteringAct->setCheckable(true);
420 connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
421 this, SIGNAL(autoCenteringTriggered(bool)));
423 // build the actual menu
424 m_viewMenu = menuBar()->addMenu(tr("Main"));
425 m_viewMenu->addAction(m_loginAct);
426 m_viewMenu->addAction(m_toSettingsAct);
427 m_viewMenu->addAction(m_gpsToggleAct);
428 m_viewMenu->addAction(m_autoCenteringAct);
429 m_viewMenu->setObjectName(tr("Menu"));
432 void MainWindow::dialogFinished(int status)
434 qDebug() << __PRETTY_FUNCTION__;
436 QDialog *dialog = m_queue.takeFirst();
437 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
441 loginDialog->userInput(m_email, m_password);
443 QStringList urlParts;
444 urlParts.append(FACEBOOK_LOGINBASE);
445 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
446 urlParts.append(INTERVAL1);
447 urlParts.append(SITUARE_LOGIN_SUCCESS);
448 urlParts.append(INTERVAL2);
449 urlParts.append(SITUARE_LOGIN_FAILURE);
450 urlParts.append(FACEBOOK_LOGIN_ENDING);
452 emit saveUsername(m_email);
454 m_webView->load(QUrl(urlParts.join(EMPTY)));
455 toggleProgressIndicator(true);
457 emit cancelLoginProcess();
461 dialog->deleteLater();
463 if(!m_error_queue.isEmpty() && m_errorShown == false) {
464 showErrorInformationBox();
466 if(!m_queue.isEmpty()) {
467 showInformationBox();
472 void MainWindow::drawFullScreenButton(const QSize &size)
474 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
476 if(m_fullScreenButton) {
478 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
480 size.height() - m_fullScreenButton->size().height());
482 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
483 size.height() - m_fullScreenButton->size().height());
488 void MainWindow::drawMapScale(const QSize &size)
490 const int LEFT_SCALE_MARGIN = 10;
491 const int BOTTOM_SCALE_MARGIN = 2;
492 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
494 m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
495 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
498 void MainWindow::drawOsmLicense(const QSize &size)
500 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
502 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
504 size.height() - m_osmLicense->fontMetrics().height());
507 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
509 qDebug() << __PRETTY_FUNCTION__;
511 if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
512 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
513 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
517 void MainWindow::errorDialogFinished(int status)
519 qDebug() << __PRETTY_FUNCTION__;
522 QDialog *dialog = m_error_queue.takeFirst();
524 dialog->deleteLater();
525 m_errorShown = false;
527 if(!m_error_queue.isEmpty())
528 showErrorInformationBox();
529 else if(!m_queue.isEmpty())
530 showInformationBox();
533 void MainWindow::gpsTimeout()
535 qDebug() << __PRETTY_FUNCTION__;
537 buildInformationBox(tr("GPS timeout"));
540 void MainWindow::grabZoomKeys(bool grab)
542 qDebug() << __PRETTY_FUNCTION__;
545 // Can't grab keys unless we have a window id
549 unsigned long val = (grab) ? 1 : 0;
550 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
554 XChangeProperty (QX11Info::display(),
560 reinterpret_cast<unsigned char *>(&val),
564 #endif // Q_WS_MAEMO_5
567 void MainWindow::keyPressEvent(QKeyEvent* event)
569 qDebug() << __PRETTY_FUNCTION__;
571 switch (event->key()) {
582 QWidget::keyPressEvent(event);
585 void MainWindow::loadCookies()
587 qDebug() << __PRETTY_FUNCTION__;
589 QSettings settings(DIRECTORY_NAME, FILE_NAME);
591 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
593 if(!list.isEmpty()) {
594 QList<QNetworkCookie> cookieList;
595 for(int i=0;i<list.count();i++) {
596 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
600 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
602 m_cookieJar->setAllCookies(cookieList);
603 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
608 void MainWindow::loadDone(bool done)
610 qDebug() << __PRETTY_FUNCTION__;
612 // for the first time the login page is opened, we need to refresh it to get cookies working
620 QWebFrame* frame = m_webView->page()->currentFrame();
624 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
626 foreach (QWebElement element, emailCollection) {
627 element.setAttribute("value", m_email.toAscii());
630 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
631 foreach (QWebElement element, passwordCollection) {
632 element.setAttribute("value", m_password.toAscii());
634 // find connect button
635 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
636 foreach (QWebElement element, buttonCollection)
638 QPoint pos(element.geometry().center());
640 // send a mouse click event to the web page
641 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
643 QApplication::sendEvent(m_webView->page(), &event0);
644 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
646 QApplication::sendEvent(m_webView->page(), &event1);
652 void MainWindow::loggedIn(bool logged)
654 qDebug() << __PRETTY_FUNCTION__;
659 m_loginAct->setText(tr("Logout"));
665 m_loginAct->setText(tr("Login"));
667 updateItemVisibility();
670 void MainWindow::loginFailed()
672 qDebug() << __PRETTY_FUNCTION__;
676 toggleProgressIndicator(false);
681 bool MainWindow::loginState()
683 qDebug() << __PRETTY_FUNCTION__;
688 void MainWindow::loginUsingCookies()
690 qDebug() << __PRETTY_FUNCTION__;
695 QStringList urlParts;
696 urlParts.append(FACEBOOK_LOGINBASE);
697 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
698 urlParts.append(INTERVAL1);
699 urlParts.append(SITUARE_LOGIN_SUCCESS);
700 urlParts.append(INTERVAL2);
701 urlParts.append(SITUARE_LOGIN_FAILURE);
702 urlParts.append(FACEBOOK_LOGIN_ENDING);
704 m_webView->load(QUrl(urlParts.join(EMPTY)));
708 void MainWindow::openSettingsDialog()
710 qDebug() << __PRETTY_FUNCTION__;
712 SettingsDialog *settingsDialog = new SettingsDialog(this);
713 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
714 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
716 settingsDialog->show();
719 void MainWindow::readAutomaticLocationUpdateSettings()
721 qDebug() << __PRETTY_FUNCTION__;
723 QSettings settings(DIRECTORY_NAME, FILE_NAME);
724 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
725 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
728 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
730 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
732 emit enableAutomaticLocationUpdate(false);
736 void MainWindow::queueDialog(QDialog *dialog)
738 qDebug() << __PRETTY_FUNCTION__;
740 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
741 if(dialog->isModal()) {
742 m_error_queue.append(dialog);
744 m_queue.append(dialog);
747 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
748 if(m_error_queue.count() == 1 && m_errorShown == false)
749 showErrorInformationBox();
750 else if(m_queue.count() == 1 && m_errorShown == false)
751 showInformationBox();
754 void MainWindow::saveCookies()
756 qDebug() << __PRETTY_FUNCTION__;
759 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
761 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
764 for(int i=0;i<cookieList.count();i++) {
765 QNetworkCookie cookie = cookieList.at(i);
766 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
767 list.append(QString(byteArray));
769 list.removeDuplicates();
771 QSettings settings(DIRECTORY_NAME, FILE_NAME);
772 settings.setValue(COOKIES, list);
775 void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
777 qDebug() << __PRETTY_FUNCTION__;
779 m_autoCenteringAct->setChecked(enabled);
782 void MainWindow::setGPSButtonEnabled(bool enabled)
784 qDebug() << __PRETTY_FUNCTION__;
786 m_gpsToggleAct->setChecked(enabled);
788 setOwnLocationCrosshairVisibility(!enabled);
790 m_autoCenteringAct->setVisible(enabled);
793 void MainWindow::setMapViewScene(QGraphicsScene *scene)
795 qDebug() << __PRETTY_FUNCTION__;
797 m_mapView->setScene(scene);
800 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
802 qDebug() << __PRETTY_FUNCTION__;
804 if (visibility && m_loggedIn) {
805 m_ownLocationCrosshair->show();
806 m_drawOwnLocationCrosshair = true;
807 drawOwnLocationCrosshair(m_viewPortSize);
809 m_ownLocationCrosshair->hide();
810 m_drawOwnLocationCrosshair = false;
814 void MainWindow::settingsDialogAccepted()
816 qDebug() << __PRETTY_FUNCTION__;
818 readAutomaticLocationUpdateSettings();
821 void MainWindow::setUsername(const QString &username)
823 qDebug() << __PRETTY_FUNCTION__;
828 void MainWindow::setViewPortSize(const QSize &size)
830 qDebug() << __PRETTY_FUNCTION__;
832 m_viewPortSize = size;
835 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
837 qDebug() << __PRETTY_FUNCTION__;
839 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
840 tr("Automatic location update"), text,
841 QMessageBox::Yes | QMessageBox::No |
842 QMessageBox::Cancel, this);
843 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
844 this, SLOT(automaticUpdateDialogFinished(int)));
846 m_automaticUpdateLocationDialog->show();
849 void MainWindow::toggleFullScreen()
851 qDebug() << __PRETTY_FUNCTION__;
853 if(windowState() == Qt::WindowNoState)
859 void MainWindow::showErrorInformationBox()
861 qDebug() << __PRETTY_FUNCTION__;
863 if(m_error_queue.count()) {
865 QDialog *dialog = m_error_queue.first();
866 connect(dialog, SIGNAL(finished(int)),
867 this, SLOT(errorDialogFinished(int)));
872 void MainWindow::showInformationBox()
874 qDebug() << __PRETTY_FUNCTION__;
876 if(m_queue.count()) {
877 QDialog *dialog = m_queue.first();
878 connect(dialog, SIGNAL(finished(int)),
879 this, SLOT(dialogFinished(int)));
884 void MainWindow::startLoginProcess()
886 qDebug() << __PRETTY_FUNCTION__;
888 LoginDialog *loginDialog = new LoginDialog();
890 emit fetchUsernameFromSettings();
892 loginDialog->clearTextFields();
894 if(!m_email.isEmpty())
895 loginDialog->setEmailField(m_email);
897 queueDialog(loginDialog);
900 void MainWindow::toggleProgressIndicator(bool value)
902 qDebug() << __PRETTY_FUNCTION__;
905 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, value);
908 #endif // Q_WS_MAEMO_5
911 void MainWindow::updateItemVisibility()
913 qDebug() << __PRETTY_FUNCTION__;
916 m_friendsListPanel->show();
917 m_friendsListPanelSidebar->show();
919 m_userPanelSidebar->show();
921 if(!m_gpsToggleAct->isChecked())
922 setOwnLocationCrosshairVisibility(true);
924 m_friendsListPanel->closePanel();
925 m_friendsListPanel->hide();
926 m_friendsListPanelSidebar->hide();
927 m_userPanel->closePanel();
929 m_userPanelSidebar->hide();
930 setOwnLocationCrosshairVisibility(false);
932 drawFullScreenButton(m_viewPortSize);
935 const QString MainWindow::username()
937 qDebug() << __PRETTY_FUNCTION__;
942 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
944 qDebug() << __PRETTY_FUNCTION__;
946 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
947 // qwebview starts to load a new page while the current page loading is not finished
948 if(reply->error() != QNetworkReply::OperationCanceledError &&
949 reply->error() != QNetworkReply::NoError) {
950 emit error(reply->error());
951 toggleProgressIndicator(false);