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);
100 // Set default screen size
101 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
103 setAttribute(Qt::WA_Maemo5StackedWindow);
107 MainWindow::~MainWindow()
109 qDebug() << __PRETTY_FUNCTION__;
116 qDeleteAll(m_queue.begin(), m_queue.end());
119 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
120 m_error_queue.clear();
123 void MainWindow::automaticUpdateDialogFinished(int result)
125 qDebug() << __PRETTY_FUNCTION__;
127 if (result == QMessageBox::Yes) {
128 readAutomaticLocationUpdateSettings();
130 QSettings settings(DIRECTORY_NAME, FILE_NAME);
131 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
132 readAutomaticLocationUpdateSettings();
135 m_automaticUpdateLocationDialog->deleteLater();
138 void MainWindow::buildFullScreenButton()
140 qDebug() << __PRETTY_FUNCTION__;
142 m_fullScreenButton = new FullScreenButton(this);
143 connect(m_fullScreenButton, SIGNAL(clicked()),
144 this, SLOT(toggleFullScreen()));
145 #endif // Q_WS_MAEMO_5
148 void MainWindow::buildFriendListPanel()
150 qDebug() << __PRETTY_FUNCTION__;
152 m_friendsListPanel = new FriendListPanel(this);
154 m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
156 m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
158 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
159 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
161 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
162 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
164 connect(m_mapView, SIGNAL(viewResized(QSize)),
165 m_friendsListPanel, SLOT(resizePanel(QSize)));
167 connect(m_mapView, SIGNAL(viewResized(QSize)),
168 m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
170 connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
171 this, SIGNAL(findFriend(QPointF)));
174 void MainWindow::buildInformationBox(const QString &message, bool modal)
176 qDebug() << __PRETTY_FUNCTION__;
178 QString errorMessage = message;
182 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
185 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
186 // extra line changes are needed to make error notes broader
187 errorMessage.prepend("\n");
188 errorMessage.append("\n");
190 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
192 QLabel *label = new QLabel(msgBox);
193 label->setAlignment(Qt::AlignCenter);
194 label->setText(errorMessage);
195 msgBox->setWidget(label);
197 QMessageBox *msgBox = new QMessageBox(this);
198 msgBox->button(QMessageBox::Ok);
199 msgBox->setText(errorMessage);
200 msgBox->setModal(modal);
206 void MainWindow::buildManualLocationCrosshair()
208 qDebug() << __PRETTY_FUNCTION__;
210 m_ownLocationCrosshair = new QLabel(this);
211 QPixmap crosshairImage(":/res/images/sight.png");
212 m_ownLocationCrosshair->setPixmap(crosshairImage);
213 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
214 m_ownLocationCrosshair->hide();
215 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
217 connect(m_mapView, SIGNAL(viewResized(QSize)),
218 this, SLOT(drawOwnLocationCrosshair(QSize)));
221 void MainWindow::buildMap()
223 qDebug() << __PRETTY_FUNCTION__;
225 m_mapView = new MapView(this);
227 buildZoomButtonPanel();
229 buildManualLocationCrosshair();
230 buildFullScreenButton();
233 connect(m_mapView, SIGNAL(viewScrolled(QPoint)),
234 this, SIGNAL(mapViewScrolled(QPoint)));
236 connect(this, SIGNAL(centerToSceneCoordinates(QPoint)),
237 m_mapView, SLOT(centerToSceneCoordinates(QPoint)));
239 connect(m_mapView, SIGNAL(viewResized(QSize)),
240 this, SIGNAL(mapViewResized(QSize)));
242 connect(m_mapView, SIGNAL(viewResized(QSize)),
243 this, SLOT(drawFullScreenButton(QSize)));
245 connect(m_mapView, SIGNAL(viewResized(QSize)),
246 this, SLOT(drawMapScale(QSize)));
248 connect(m_mapView, SIGNAL(viewResized(QSize)),
249 this, SLOT(setViewPortSize(QSize)));
251 connect(this, SIGNAL(zoomLevelChanged(int)),
252 m_mapView, SLOT(setZoomLevel(int)));
254 connect(m_mapView, SIGNAL(viewZoomFinished()),
255 this, SIGNAL(viewZoomFinished()));
257 connect(m_mapView, SIGNAL(zoomIn()),
258 this, SIGNAL(zoomIn()));
261 void MainWindow::buildMapScale()
263 m_mapScale = new MapScale(this);
264 connect(this, SIGNAL(newMapResolution(qreal)),
265 m_mapScale, SLOT(updateMapResolution(qreal)));
268 void MainWindow::buildOsmLicense()
270 qDebug() << __PRETTY_FUNCTION__;
272 m_osmLicense = new QLabel(this);
273 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
274 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
275 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
276 m_osmLicense->setFont(QFont("Nokia Sans", 9));
277 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
278 m_osmLicense->fontMetrics().height());
280 connect(m_mapView, SIGNAL(viewResized(QSize)),
281 this, SLOT(drawOsmLicense(QSize)));
284 void MainWindow::buildUserInfoPanel()
286 qDebug() << __PRETTY_FUNCTION__;
288 m_userPanel = new UserInfoPanel(this);
290 m_userPanelSidebar = new PanelSideBar(this, LEFT);
292 m_userPanelSidebar->stackUnder(m_friendsListPanel);
293 m_userPanel->stackUnder(m_userPanelSidebar);
295 connect(this, SIGNAL(userLocationReady(User*)),
296 m_userPanel, SLOT(userDataReceived(User*)));
298 connect(this, SIGNAL(reverseGeoReady(QString)),
299 m_userPanel, SIGNAL(reverseGeoReady(QString)));
301 connect(this, SIGNAL(clearUpdateLocationDialogData()),
302 m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
304 connect(this, SIGNAL(messageSendingFailed(int)),
305 m_userPanel, SIGNAL(messageSendingFailed(int)));
307 connect(m_mapView, SIGNAL(viewResized(QSize)),
308 m_userPanel, SLOT(resizePanel(QSize)));
310 connect(m_mapView, SIGNAL(viewResized(QSize)),
311 m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
313 connect(m_userPanel, SIGNAL(findUser(QPointF)),
314 this, SIGNAL(findUser(QPointF)));
316 connect(m_userPanel, SIGNAL(requestReverseGeo()),
317 this, SIGNAL(requestReverseGeo()));
319 connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
320 this, SIGNAL(statusUpdate(QString,bool)));
322 connect(m_userPanel, SIGNAL(refreshUserData()),
323 this, SIGNAL(refreshUserData()));
325 connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
326 this, SLOT(buildInformationBox(QString, bool)));
329 void MainWindow::buildWebView()
331 qDebug() << __PRETTY_FUNCTION__;
334 m_webView = new QWebView;
337 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
339 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
341 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
342 this, SLOT(webViewRequestFinished(QNetworkReply*)));
343 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
344 this, SIGNAL(updateCredentials(QUrl)));
345 connect(m_webView, SIGNAL(loadFinished(bool)),
346 this, SLOT(loadDone(bool)));
352 void MainWindow::buildZoomButtonPanel()
354 qDebug() << __PRETTY_FUNCTION__;
356 m_zoomButtonPanel = new ZoomButtonPanel(this);
358 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
359 this, SIGNAL(zoomIn()));
361 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
362 this, SIGNAL(zoomOut()));
364 connect(this, SIGNAL(zoomLevelChanged(int)),
365 m_zoomButtonPanel, SLOT(resetButtons()));
367 connect(this, SIGNAL(maxZoomLevelReached()),
368 m_zoomButtonPanel, SLOT(disableZoomInButton()));
370 connect(this, SIGNAL(minZoomLevelReached()),
371 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
373 connect(m_mapView, SIGNAL(viewResized(QSize)),
374 m_zoomButtonPanel, SLOT(screenResized(QSize)));
377 void MainWindow::clearCookieJar()
379 qDebug() << __PRETTY_FUNCTION__;
386 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
388 QList<QNetworkCookie> emptyList;
391 m_cookieJar->setAllCookies(emptyList);
392 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
395 void MainWindow::createMenus()
397 qDebug() << __PRETTY_FUNCTION__;
400 m_loginAct = new QAction(tr("Login"), this);
401 connect(m_loginAct, SIGNAL(triggered()),
402 this, SIGNAL(loginActionPressed()));
405 m_toSettingsAct = new QAction(tr("Settings"), this);
406 connect(m_toSettingsAct, SIGNAL(triggered()),
407 this, SLOT(openSettingsDialog()));
410 m_gpsToggleAct = new QAction(tr("GPS"), this);
411 m_gpsToggleAct->setCheckable(true);
413 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
414 this, SIGNAL(gpsTriggered(bool)));
416 // automatic centering
417 m_autoCenteringAct = new QAction(tr("Auto centering"), this);
418 m_autoCenteringAct->setCheckable(true);
419 connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
420 this, SIGNAL(autoCenteringTriggered(bool)));
422 // build the actual menu
423 m_viewMenu = menuBar()->addMenu(tr("Main"));
424 m_viewMenu->addAction(m_loginAct);
425 m_viewMenu->addAction(m_toSettingsAct);
426 m_viewMenu->addAction(m_gpsToggleAct);
427 m_viewMenu->addAction(m_autoCenteringAct);
428 m_viewMenu->setObjectName(tr("Menu"));
431 void MainWindow::dialogFinished(int status)
433 qDebug() << __PRETTY_FUNCTION__;
435 QDialog *dialog = m_queue.takeFirst();
436 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
440 loginDialog->userInput(m_email, m_password);
442 QStringList urlParts;
443 urlParts.append(FACEBOOK_LOGINBASE);
444 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
445 urlParts.append(INTERVAL1);
446 urlParts.append(SITUARE_LOGIN_SUCCESS);
447 urlParts.append(INTERVAL2);
448 urlParts.append(SITUARE_LOGIN_FAILURE);
449 urlParts.append(FACEBOOK_LOGIN_ENDING);
451 emit saveUsername(m_email);
453 m_webView->load(QUrl(urlParts.join(EMPTY)));
454 toggleProgressIndicator(true);
456 emit cancelLoginProcess();
460 dialog->deleteLater();
462 if(!m_error_queue.isEmpty() && m_errorShown == false) {
463 showErrorInformationBox();
465 if(!m_queue.isEmpty()) {
466 showInformationBox();
471 void MainWindow::drawFullScreenButton(const QSize &size)
473 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
475 if(m_fullScreenButton) {
477 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
479 size.height() - m_fullScreenButton->size().height());
481 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
482 size.height() - m_fullScreenButton->size().height());
487 void MainWindow::drawMapScale(const QSize &size)
489 const int LEFT_SCALE_MARGIN = 10;
490 const int BOTTOM_SCALE_MARGIN = 2;
491 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
493 m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
494 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
497 void MainWindow::drawOsmLicense(const QSize &size)
499 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
501 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
503 size.height() - m_osmLicense->fontMetrics().height());
506 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
508 qDebug() << __PRETTY_FUNCTION__;
510 if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
511 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
512 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
516 void MainWindow::errorDialogFinished(int status)
518 qDebug() << __PRETTY_FUNCTION__;
521 QDialog *dialog = m_error_queue.takeFirst();
523 dialog->deleteLater();
524 m_errorShown = false;
526 if(!m_error_queue.isEmpty())
527 showErrorInformationBox();
528 else if(!m_queue.isEmpty())
529 showInformationBox();
532 void MainWindow::gpsTimeout()
534 qDebug() << __PRETTY_FUNCTION__;
536 buildInformationBox(tr("GPS timeout"));
539 void MainWindow::grabZoomKeys(bool grab)
541 qDebug() << __PRETTY_FUNCTION__;
544 // Can't grab keys unless we have a window id
548 unsigned long val = (grab) ? 1 : 0;
549 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
553 XChangeProperty (QX11Info::display(),
559 reinterpret_cast<unsigned char *>(&val),
563 #endif // Q_WS_MAEMO_5
566 void MainWindow::keyPressEvent(QKeyEvent* event)
568 qDebug() << __PRETTY_FUNCTION__;
570 switch (event->key()) {
581 QWidget::keyPressEvent(event);
584 void MainWindow::loadCookies()
586 qDebug() << __PRETTY_FUNCTION__;
588 QSettings settings(DIRECTORY_NAME, FILE_NAME);
590 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
592 if(!list.isEmpty()) {
593 QList<QNetworkCookie> cookieList;
594 for(int i=0;i<list.count();i++) {
595 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
599 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
601 m_cookieJar->setAllCookies(cookieList);
602 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
607 void MainWindow::loadDone(bool done)
609 qDebug() << __PRETTY_FUNCTION__;
611 // for the first time the login page is opened, we need to refresh it to get cookies working
619 QWebFrame* frame = m_webView->page()->currentFrame();
623 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
625 foreach (QWebElement element, emailCollection) {
626 element.setAttribute("value", m_email.toAscii());
629 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
630 foreach (QWebElement element, passwordCollection) {
631 element.setAttribute("value", m_password.toAscii());
633 // find connect button
634 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
635 foreach (QWebElement element, buttonCollection)
637 QPoint pos(element.geometry().center());
639 // send a mouse click event to the web page
640 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
642 QApplication::sendEvent(m_webView->page(), &event0);
643 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
645 QApplication::sendEvent(m_webView->page(), &event1);
651 void MainWindow::loggedIn(bool logged)
653 qDebug() << __PRETTY_FUNCTION__;
658 m_loginAct->setText(tr("Logout"));
664 m_loginAct->setText(tr("Login"));
666 updateItemVisibility();
669 void MainWindow::loginFailed()
671 qDebug() << __PRETTY_FUNCTION__;
677 bool MainWindow::loginState()
679 qDebug() << __PRETTY_FUNCTION__;
684 void MainWindow::loginUsingCookies()
686 qDebug() << __PRETTY_FUNCTION__;
688 toggleProgressIndicator(true);
693 QStringList urlParts;
694 urlParts.append(FACEBOOK_LOGINBASE);
695 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
696 urlParts.append(INTERVAL1);
697 urlParts.append(SITUARE_LOGIN_SUCCESS);
698 urlParts.append(INTERVAL2);
699 urlParts.append(SITUARE_LOGIN_FAILURE);
700 urlParts.append(FACEBOOK_LOGIN_ENDING);
702 m_webView->load(QUrl(urlParts.join(EMPTY)));
706 void MainWindow::openSettingsDialog()
708 qDebug() << __PRETTY_FUNCTION__;
710 SettingsDialog *settingsDialog = new SettingsDialog(this);
711 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
712 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
714 settingsDialog->show();
717 void MainWindow::readAutomaticLocationUpdateSettings()
719 qDebug() << __PRETTY_FUNCTION__;
721 QSettings settings(DIRECTORY_NAME, FILE_NAME);
722 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
723 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
726 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
728 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
730 emit enableAutomaticLocationUpdate(false);
734 void MainWindow::queueDialog(QDialog *dialog)
736 qDebug() << __PRETTY_FUNCTION__;
738 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
739 if(dialog->isModal()) {
740 m_error_queue.append(dialog);
742 m_queue.append(dialog);
745 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
746 if(m_error_queue.count() == 1 && m_errorShown == false)
747 showErrorInformationBox();
748 else if(m_queue.count() == 1 && m_errorShown == false)
749 showInformationBox();
752 void MainWindow::saveCookies()
754 qDebug() << __PRETTY_FUNCTION__;
757 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
759 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
762 for(int i=0;i<cookieList.count();i++) {
763 QNetworkCookie cookie = cookieList.at(i);
764 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
765 list.append(QString(byteArray));
767 list.removeDuplicates();
769 QSettings settings(DIRECTORY_NAME, FILE_NAME);
770 settings.setValue(COOKIES, list);
773 void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
775 qDebug() << __PRETTY_FUNCTION__;
777 m_autoCenteringAct->setChecked(enabled);
780 void MainWindow::setGPSButtonEnabled(bool enabled)
782 qDebug() << __PRETTY_FUNCTION__;
784 m_gpsToggleAct->setChecked(enabled);
786 setOwnLocationCrosshairVisibility(!enabled);
788 m_autoCenteringAct->setVisible(enabled);
791 void MainWindow::setMapViewScene(QGraphicsScene *scene)
793 qDebug() << __PRETTY_FUNCTION__;
795 m_mapView->setScene(scene);
798 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
800 qDebug() << __PRETTY_FUNCTION__;
802 if (visibility && m_loggedIn) {
803 m_ownLocationCrosshair->show();
804 m_drawOwnLocationCrosshair = true;
805 drawOwnLocationCrosshair(m_viewPortSize);
807 m_ownLocationCrosshair->hide();
808 m_drawOwnLocationCrosshair = false;
812 void MainWindow::settingsDialogAccepted()
814 qDebug() << __PRETTY_FUNCTION__;
816 readAutomaticLocationUpdateSettings();
819 void MainWindow::setUsername(const QString &username)
821 qDebug() << __PRETTY_FUNCTION__;
826 void MainWindow::setViewPortSize(const QSize &size)
828 qDebug() << __PRETTY_FUNCTION__;
830 m_viewPortSize = size;
833 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
835 qDebug() << __PRETTY_FUNCTION__;
837 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
838 tr("Automatic location update"), text,
839 QMessageBox::Yes | QMessageBox::No |
840 QMessageBox::Cancel, this);
841 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
842 this, SLOT(automaticUpdateDialogFinished(int)));
844 m_automaticUpdateLocationDialog->show();
847 void MainWindow::toggleFullScreen()
849 qDebug() << __PRETTY_FUNCTION__;
851 if(windowState() == Qt::WindowNoState)
857 void MainWindow::showErrorInformationBox()
859 qDebug() << __PRETTY_FUNCTION__;
861 if(m_error_queue.count()) {
863 QDialog *dialog = m_error_queue.first();
864 connect(dialog, SIGNAL(finished(int)),
865 this, SLOT(errorDialogFinished(int)));
870 void MainWindow::showInformationBox()
872 qDebug() << __PRETTY_FUNCTION__;
874 if(m_queue.count()) {
875 QDialog *dialog = m_queue.first();
876 connect(dialog, SIGNAL(finished(int)),
877 this, SLOT(dialogFinished(int)));
882 void MainWindow::showPanels()
884 qDebug() << __PRETTY_FUNCTION__;
886 drawFullScreenButton(m_viewPortSize);
889 if(!m_friendsListPanel->isVisible()) {
890 m_friendsListPanel->show();
891 m_friendsListPanelSidebar->show();
894 if(!m_userPanel->isVisible()) {
896 m_userPanelSidebar->show();
901 void MainWindow::startLoginProcess()
903 qDebug() << __PRETTY_FUNCTION__;
905 LoginDialog *loginDialog = new LoginDialog();
907 emit fetchUsernameFromSettings();
909 loginDialog->clearTextFields();
911 if(!m_email.isEmpty())
912 loginDialog->setEmailField(m_email);
914 queueDialog(loginDialog);
917 void MainWindow::toggleProgressIndicator(bool value)
919 qDebug() << __PRETTY_FUNCTION__;
923 m_progressIndicatorCount++;
924 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
926 if(m_progressIndicatorCount > 0)
927 m_progressIndicatorCount--;
929 if(m_progressIndicatorCount == 0)
930 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
934 #endif // Q_WS_MAEMO_5
937 void MainWindow::updateItemVisibility()
939 qDebug() << __PRETTY_FUNCTION__;
943 if(!m_gpsToggleAct->isChecked())
944 setOwnLocationCrosshairVisibility(true);
946 m_friendsListPanel->closePanel();
947 m_friendsListPanel->hide();
948 m_friendsListPanelSidebar->hide();
949 m_userPanel->closePanel();
951 m_userPanelSidebar->hide();
952 setOwnLocationCrosshairVisibility(false);
956 const QString MainWindow::username()
958 qDebug() << __PRETTY_FUNCTION__;
963 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
965 qDebug() << __PRETTY_FUNCTION__;
967 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
968 // qwebview starts to load a new page while the current page loading is not finished
969 if(reply->error() != QNetworkReply::OperationCanceledError &&
970 reply->error() != QNetworkReply::NoError) {
971 emit error(ErrorContext::NETWORK, reply->error());