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_progressIndicatorCount(0),
59 m_ownLocationCrosshair(0),
62 m_fullScreenButton(0),
67 qDebug() << __PRETTY_FUNCTION__;
72 QHBoxLayout *layout = new QHBoxLayout;
73 layout->addWidget(m_mapView);
75 layout->setSpacing(0);
77 setCentralWidget(new QWidget());
78 centralWidget()->setLayout(layout);
80 buildFriendListPanel();
84 setWindowTitle(tr("Situare"));
86 // set stacking order of widgets
87 m_zoomButtonPanel->stackUnder(m_userPanel);
88 if(m_fullScreenButton) {
89 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
90 m_osmLicense->stackUnder(m_fullScreenButton);
92 m_osmLicense->stackUnder(m_zoomButtonPanel);
94 m_ownLocationCrosshair->stackUnder(m_osmLicense);
95 m_mapScale->stackUnder(m_ownLocationCrosshair);
96 m_mapView->stackUnder(m_mapScale);
98 this->toggleProgressIndicator(true);
102 // Set default screen size
103 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
105 setAttribute(Qt::WA_Maemo5StackedWindow);
109 MainWindow::~MainWindow()
111 qDebug() << __PRETTY_FUNCTION__;
118 qDeleteAll(m_queue.begin(), m_queue.end());
121 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
122 m_error_queue.clear();
125 void MainWindow::automaticUpdateDialogFinished(int result)
127 qDebug() << __PRETTY_FUNCTION__;
129 if (result == QMessageBox::Yes) {
130 readAutomaticLocationUpdateSettings();
132 QSettings settings(DIRECTORY_NAME, FILE_NAME);
133 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
134 readAutomaticLocationUpdateSettings();
137 m_automaticUpdateLocationDialog->deleteLater();
140 void MainWindow::buildFullScreenButton()
142 qDebug() << __PRETTY_FUNCTION__;
144 m_fullScreenButton = new FullScreenButton(this);
145 connect(m_fullScreenButton, SIGNAL(clicked()),
146 this, SLOT(toggleFullScreen()));
147 #endif // Q_WS_MAEMO_5
150 void MainWindow::buildFriendListPanel()
152 qDebug() << __PRETTY_FUNCTION__;
154 m_friendsListPanel = new FriendListPanel(this);
156 m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
158 m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
160 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
161 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
163 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
164 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
166 connect(m_mapView, SIGNAL(viewResized(QSize)),
167 m_friendsListPanel, SLOT(resizePanel(QSize)));
169 connect(m_mapView, SIGNAL(viewResized(QSize)),
170 m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
172 connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
173 this, SIGNAL(findFriend(QPointF)));
176 void MainWindow::buildInformationBox(const QString &message, bool modal)
178 qDebug() << __PRETTY_FUNCTION__;
180 QString errorMessage = message;
184 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
187 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
188 // extra line changes are needed to make error notes broader
189 errorMessage.prepend("\n");
190 errorMessage.append("\n");
192 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
194 QLabel *label = new QLabel(msgBox);
195 label->setAlignment(Qt::AlignCenter);
196 label->setText(errorMessage);
197 msgBox->setWidget(label);
199 QMessageBox *msgBox = new QMessageBox(this);
200 msgBox->button(QMessageBox::Ok);
201 msgBox->setText(errorMessage);
202 msgBox->setModal(modal);
208 void MainWindow::buildManualLocationCrosshair()
210 qDebug() << __PRETTY_FUNCTION__;
212 m_ownLocationCrosshair = new QLabel(this);
213 QPixmap crosshairImage(":/res/images/sight.png");
214 m_ownLocationCrosshair->setPixmap(crosshairImage);
215 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
216 m_ownLocationCrosshair->hide();
217 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
219 connect(m_mapView, SIGNAL(viewResized(QSize)),
220 this, SLOT(drawOwnLocationCrosshair(QSize)));
223 void MainWindow::buildMap()
225 qDebug() << __PRETTY_FUNCTION__;
227 m_mapView = new MapView(this);
229 buildZoomButtonPanel();
231 buildManualLocationCrosshair();
232 buildFullScreenButton();
235 connect(m_mapView, SIGNAL(viewScrolled(QPoint)),
236 this, SIGNAL(mapViewScrolled(QPoint)));
238 connect(this, SIGNAL(centerToSceneCoordinates(QPoint)),
239 m_mapView, SLOT(centerToSceneCoordinates(QPoint)));
241 connect(m_mapView, SIGNAL(viewResized(QSize)),
242 this, SIGNAL(mapViewResized(QSize)));
244 connect(m_mapView, SIGNAL(viewResized(QSize)),
245 this, SLOT(drawFullScreenButton(QSize)));
247 connect(m_mapView, SIGNAL(viewResized(QSize)),
248 this, SLOT(drawMapScale(QSize)));
250 connect(m_mapView, SIGNAL(viewResized(QSize)),
251 this, SLOT(setViewPortSize(QSize)));
253 connect(this, SIGNAL(zoomLevelChanged(int)),
254 m_mapView, SLOT(setZoomLevel(int)));
256 connect(m_mapView, SIGNAL(viewZoomFinished()),
257 this, SIGNAL(viewZoomFinished()));
260 void MainWindow::buildMapScale()
262 m_mapScale = new MapScale(this);
263 connect(this, SIGNAL(newMapResolution(qreal)),
264 m_mapScale, SLOT(updateMapResolution(qreal)));
267 void MainWindow::buildOsmLicense()
269 qDebug() << __PRETTY_FUNCTION__;
271 m_osmLicense = new QLabel(this);
272 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
273 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
274 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
275 m_osmLicense->setFont(QFont("Nokia Sans", 9));
276 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
277 m_osmLicense->fontMetrics().height());
279 connect(m_mapView, SIGNAL(viewResized(QSize)),
280 this, SLOT(drawOsmLicense(QSize)));
283 void MainWindow::buildUserInfoPanel()
285 qDebug() << __PRETTY_FUNCTION__;
287 m_userPanel = new UserInfoPanel(this);
289 m_userPanelSidebar = new PanelSideBar(this, LEFT);
291 m_userPanelSidebar->stackUnder(m_friendsListPanel);
292 m_userPanel->stackUnder(m_userPanelSidebar);
294 connect(this, SIGNAL(userLocationReady(User*)),
295 m_userPanel, SLOT(userDataReceived(User*)));
297 connect(this, SIGNAL(reverseGeoReady(QString)),
298 m_userPanel, SIGNAL(reverseGeoReady(QString)));
300 connect(this, SIGNAL(clearUpdateLocationDialogData()),
301 m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
303 connect(this, SIGNAL(messageSendingFailed(int)),
304 m_userPanel, SIGNAL(messageSendingFailed(int)));
306 connect(m_mapView, SIGNAL(viewResized(QSize)),
307 m_userPanel, SLOT(resizePanel(QSize)));
309 connect(m_mapView, SIGNAL(viewResized(QSize)),
310 m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
312 connect(m_userPanel, SIGNAL(findUser(QPointF)),
313 this, SIGNAL(findUser(QPointF)));
315 connect(m_userPanel, SIGNAL(requestReverseGeo()),
316 this, SIGNAL(requestReverseGeo()));
318 connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
319 this, SIGNAL(statusUpdate(QString,bool)));
321 connect(m_userPanel, SIGNAL(refreshUserData()),
322 this, SIGNAL(refreshUserData()));
324 connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
325 this, SLOT(buildInformationBox(QString, bool)));
328 void MainWindow::buildWebView()
330 qDebug() << __PRETTY_FUNCTION__;
333 m_webView = new QWebView;
336 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
338 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
340 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
341 this, SLOT(webViewRequestFinished(QNetworkReply*)));
342 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
343 this, SIGNAL(updateCredentials(QUrl)));
344 connect(m_webView, SIGNAL(loadFinished(bool)),
345 this, SLOT(loadDone(bool)));
351 void MainWindow::buildZoomButtonPanel()
353 qDebug() << __PRETTY_FUNCTION__;
355 m_zoomButtonPanel = new ZoomButtonPanel(this);
357 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
358 this, SIGNAL(zoomIn()));
360 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
361 this, SIGNAL(zoomOut()));
363 connect(this, SIGNAL(zoomLevelChanged(int)),
364 m_zoomButtonPanel, SLOT(resetButtons()));
366 connect(this, SIGNAL(maxZoomLevelReached()),
367 m_zoomButtonPanel, SLOT(disableZoomInButton()));
369 connect(this, SIGNAL(minZoomLevelReached()),
370 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
372 connect(m_mapView, SIGNAL(viewResized(QSize)),
373 m_zoomButtonPanel, SLOT(screenResized(QSize)));
376 void MainWindow::clearCookieJar()
378 qDebug() << __PRETTY_FUNCTION__;
385 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
387 QList<QNetworkCookie> emptyList;
390 m_cookieJar->setAllCookies(emptyList);
391 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
394 void MainWindow::createMenus()
396 qDebug() << __PRETTY_FUNCTION__;
399 m_loginAct = new QAction(tr("Login"), this);
400 connect(m_loginAct, SIGNAL(triggered()),
401 this, SIGNAL(loginActionPressed()));
404 m_toSettingsAct = new QAction(tr("Settings"), this);
405 connect(m_toSettingsAct, SIGNAL(triggered()),
406 this, SLOT(openSettingsDialog()));
409 m_gpsToggleAct = new QAction(tr("GPS"), this);
410 m_gpsToggleAct->setCheckable(true);
412 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
413 this, SIGNAL(gpsTriggered(bool)));
415 // automatic centering
416 m_autoCenteringAct = new QAction(tr("Auto centering"), this);
417 m_autoCenteringAct->setCheckable(true);
418 connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
419 this, SIGNAL(autoCenteringTriggered(bool)));
421 // build the actual menu
422 m_viewMenu = menuBar()->addMenu(tr("Main"));
423 m_viewMenu->addAction(m_loginAct);
424 m_viewMenu->addAction(m_toSettingsAct);
425 m_viewMenu->addAction(m_gpsToggleAct);
426 m_viewMenu->addAction(m_autoCenteringAct);
427 m_viewMenu->setObjectName(tr("Menu"));
430 void MainWindow::dialogFinished(int status)
432 qDebug() << __PRETTY_FUNCTION__;
434 QDialog *dialog = m_queue.takeFirst();
435 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
439 loginDialog->userInput(m_email, m_password);
441 QStringList urlParts;
442 urlParts.append(FACEBOOK_LOGINBASE);
443 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
444 urlParts.append(INTERVAL1);
445 urlParts.append(SITUARE_LOGIN_SUCCESS);
446 urlParts.append(INTERVAL2);
447 urlParts.append(SITUARE_LOGIN_FAILURE);
448 urlParts.append(FACEBOOK_LOGIN_ENDING);
450 emit saveUsername(m_email);
452 m_webView->load(QUrl(urlParts.join(EMPTY)));
453 toggleProgressIndicator(true);
455 emit cancelLoginProcess();
459 dialog->deleteLater();
461 if(!m_error_queue.isEmpty() && m_errorShown == false) {
462 showErrorInformationBox();
464 if(!m_queue.isEmpty()) {
465 showInformationBox();
470 void MainWindow::drawFullScreenButton(const QSize &size)
472 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
474 if(m_fullScreenButton) {
476 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
478 size.height() - m_fullScreenButton->size().height());
480 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
481 size.height() - m_fullScreenButton->size().height());
486 void MainWindow::drawMapScale(const QSize &size)
488 const int LEFT_SCALE_MARGIN = 10;
489 const int BOTTOM_SCALE_MARGIN = 2;
490 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
492 m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
493 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
496 void MainWindow::drawOsmLicense(const QSize &size)
498 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
500 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
502 size.height() - m_osmLicense->fontMetrics().height());
505 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
507 qDebug() << __PRETTY_FUNCTION__;
509 if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
510 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
511 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
515 void MainWindow::errorDialogFinished(int status)
517 qDebug() << __PRETTY_FUNCTION__;
520 QDialog *dialog = m_error_queue.takeFirst();
522 dialog->deleteLater();
523 m_errorShown = false;
525 if(!m_error_queue.isEmpty())
526 showErrorInformationBox();
527 else if(!m_queue.isEmpty())
528 showInformationBox();
531 void MainWindow::gpsTimeout()
533 qDebug() << __PRETTY_FUNCTION__;
535 buildInformationBox(tr("GPS timeout"));
538 void MainWindow::grabZoomKeys(bool grab)
540 qDebug() << __PRETTY_FUNCTION__;
543 // Can't grab keys unless we have a window id
547 unsigned long val = (grab) ? 1 : 0;
548 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
552 XChangeProperty (QX11Info::display(),
558 reinterpret_cast<unsigned char *>(&val),
562 #endif // Q_WS_MAEMO_5
565 void MainWindow::keyPressEvent(QKeyEvent* event)
567 qDebug() << __PRETTY_FUNCTION__;
569 switch (event->key()) {
580 QWidget::keyPressEvent(event);
583 void MainWindow::loadCookies()
585 qDebug() << __PRETTY_FUNCTION__;
587 QSettings settings(DIRECTORY_NAME, FILE_NAME);
589 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
591 if(!list.isEmpty()) {
592 QList<QNetworkCookie> cookieList;
593 for(int i=0;i<list.count();i++) {
594 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
598 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
600 m_cookieJar->setAllCookies(cookieList);
601 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
606 void MainWindow::loadDone(bool done)
608 qDebug() << __PRETTY_FUNCTION__;
610 // for the first time the login page is opened, we need to refresh it to get cookies working
618 QWebFrame* frame = m_webView->page()->currentFrame();
622 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
624 foreach (QWebElement element, emailCollection) {
625 element.setAttribute("value", m_email.toAscii());
628 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
629 foreach (QWebElement element, passwordCollection) {
630 element.setAttribute("value", m_password.toAscii());
632 // find connect button
633 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
634 foreach (QWebElement element, buttonCollection)
636 QPoint pos(element.geometry().center());
638 // send a mouse click event to the web page
639 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
641 QApplication::sendEvent(m_webView->page(), &event0);
642 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
644 QApplication::sendEvent(m_webView->page(), &event1);
650 void MainWindow::loggedIn(bool logged)
652 qDebug() << __PRETTY_FUNCTION__;
657 m_loginAct->setText(tr("Logout"));
663 m_loginAct->setText(tr("Login"));
665 updateItemVisibility();
668 void MainWindow::loginFailed()
670 qDebug() << __PRETTY_FUNCTION__;
676 bool MainWindow::loginState()
678 qDebug() << __PRETTY_FUNCTION__;
683 void MainWindow::loginUsingCookies()
685 qDebug() << __PRETTY_FUNCTION__;
690 QStringList urlParts;
691 urlParts.append(FACEBOOK_LOGINBASE);
692 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
693 urlParts.append(INTERVAL1);
694 urlParts.append(SITUARE_LOGIN_SUCCESS);
695 urlParts.append(INTERVAL2);
696 urlParts.append(SITUARE_LOGIN_FAILURE);
697 urlParts.append(FACEBOOK_LOGIN_ENDING);
699 m_webView->load(QUrl(urlParts.join(EMPTY)));
703 void MainWindow::openSettingsDialog()
705 qDebug() << __PRETTY_FUNCTION__;
707 SettingsDialog *settingsDialog = new SettingsDialog(this);
708 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
709 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
711 settingsDialog->show();
714 void MainWindow::readAutomaticLocationUpdateSettings()
716 qDebug() << __PRETTY_FUNCTION__;
718 QSettings settings(DIRECTORY_NAME, FILE_NAME);
719 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
720 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
723 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
725 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
727 emit enableAutomaticLocationUpdate(false);
731 void MainWindow::queueDialog(QDialog *dialog)
733 qDebug() << __PRETTY_FUNCTION__;
735 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
736 if(dialog->isModal()) {
737 m_error_queue.append(dialog);
739 m_queue.append(dialog);
742 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
743 if(m_error_queue.count() == 1 && m_errorShown == false)
744 showErrorInformationBox();
745 else if(m_queue.count() == 1 && m_errorShown == false)
746 showInformationBox();
749 void MainWindow::saveCookies()
751 qDebug() << __PRETTY_FUNCTION__;
754 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
756 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
759 for(int i=0;i<cookieList.count();i++) {
760 QNetworkCookie cookie = cookieList.at(i);
761 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
762 list.append(QString(byteArray));
764 list.removeDuplicates();
766 QSettings settings(DIRECTORY_NAME, FILE_NAME);
767 settings.setValue(COOKIES, list);
770 void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
772 qDebug() << __PRETTY_FUNCTION__;
774 m_autoCenteringAct->setChecked(enabled);
777 void MainWindow::setGPSButtonEnabled(bool enabled)
779 qDebug() << __PRETTY_FUNCTION__;
781 m_gpsToggleAct->setChecked(enabled);
783 setOwnLocationCrosshairVisibility(!enabled);
785 m_autoCenteringAct->setVisible(enabled);
788 void MainWindow::setMapViewScene(QGraphicsScene *scene)
790 qDebug() << __PRETTY_FUNCTION__;
792 m_mapView->setScene(scene);
795 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
797 qDebug() << __PRETTY_FUNCTION__;
799 if (visibility && m_loggedIn) {
800 m_ownLocationCrosshair->show();
801 m_drawOwnLocationCrosshair = true;
802 drawOwnLocationCrosshair(m_viewPortSize);
804 m_ownLocationCrosshair->hide();
805 m_drawOwnLocationCrosshair = false;
809 void MainWindow::settingsDialogAccepted()
811 qDebug() << __PRETTY_FUNCTION__;
813 readAutomaticLocationUpdateSettings();
816 void MainWindow::setUsername(const QString &username)
818 qDebug() << __PRETTY_FUNCTION__;
823 void MainWindow::setViewPortSize(const QSize &size)
825 qDebug() << __PRETTY_FUNCTION__;
827 m_viewPortSize = size;
830 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
832 qDebug() << __PRETTY_FUNCTION__;
834 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
835 tr("Automatic location update"), text,
836 QMessageBox::Yes | QMessageBox::No |
837 QMessageBox::Cancel, this);
838 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
839 this, SLOT(automaticUpdateDialogFinished(int)));
841 m_automaticUpdateLocationDialog->show();
844 void MainWindow::toggleFullScreen()
846 qDebug() << __PRETTY_FUNCTION__;
848 if(windowState() == Qt::WindowNoState)
854 void MainWindow::showErrorInformationBox()
856 qDebug() << __PRETTY_FUNCTION__;
858 if(m_error_queue.count()) {
860 QDialog *dialog = m_error_queue.first();
861 connect(dialog, SIGNAL(finished(int)),
862 this, SLOT(errorDialogFinished(int)));
867 void MainWindow::showInformationBox()
869 qDebug() << __PRETTY_FUNCTION__;
871 if(m_queue.count()) {
872 QDialog *dialog = m_queue.first();
873 connect(dialog, SIGNAL(finished(int)),
874 this, SLOT(dialogFinished(int)));
879 void MainWindow::showPanels()
881 qDebug() << __PRETTY_FUNCTION__;
884 if(!m_friendsListPanel->isVisible()) {
885 m_friendsListPanel->show();
886 m_friendsListPanelSidebar->show();
889 if(!m_userPanel->isVisible()) {
891 m_userPanelSidebar->show();
896 void MainWindow::startLoginProcess()
898 qDebug() << __PRETTY_FUNCTION__;
900 LoginDialog *loginDialog = new LoginDialog();
902 emit fetchUsernameFromSettings();
904 loginDialog->clearTextFields();
906 if(!m_email.isEmpty())
907 loginDialog->setEmailField(m_email);
909 queueDialog(loginDialog);
912 void MainWindow::toggleProgressIndicator(bool value)
914 qDebug() << __PRETTY_FUNCTION__;
918 m_progressIndicatorCount++;
919 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
921 if(m_progressIndicatorCount > 0)
922 m_progressIndicatorCount--;
924 if(m_progressIndicatorCount == 0)
925 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
929 #endif // Q_WS_MAEMO_5
932 void MainWindow::updateItemVisibility()
934 qDebug() << __PRETTY_FUNCTION__;
938 if(!m_gpsToggleAct->isChecked())
939 setOwnLocationCrosshairVisibility(true);
941 m_friendsListPanel->closePanel();
942 m_friendsListPanel->hide();
943 m_friendsListPanelSidebar->hide();
944 m_userPanel->closePanel();
946 m_userPanelSidebar->hide();
947 setOwnLocationCrosshairVisibility(false);
949 drawFullScreenButton(m_viewPortSize);
952 const QString MainWindow::username()
954 qDebug() << __PRETTY_FUNCTION__;
959 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
961 qDebug() << __PRETTY_FUNCTION__;
963 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
964 // qwebview starts to load a new page while the current page loading is not finished
965 if(reply->error() != QNetworkReply::OperationCanceledError &&
966 reply->error() != QNetworkReply::NoError) {
967 emit error(reply->error());