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"
35 #include "friendlistpanel.h"
36 #include "fullscreenbutton.h"
37 #include "indicatorbutton.h"
38 #include "logindialog.h"
40 #include "panelcommon.h"
41 #include "tabbedpanel.h"
42 #include "searchdialog.h"
43 #include "settingsdialog.h"
44 #include "userinfopanel.h"
45 #include "zoombuttonpanel.h"
47 #include "mainwindow.h"
49 // These MUST BE HERE, compiling for Maemo fails if moved
51 #include <QtMaemo5/QMaemo5InformationBox>
52 #include <QtGui/QX11Info>
53 #include <X11/Xatom.h>
55 #endif // Q_WS_MAEMO_5
57 MainWindow::MainWindow(QWidget *parent)
58 : QMainWindow(parent),
62 m_progressIndicatorCount(0),
63 m_ownLocationCrosshair(0),
67 m_fullScreenButton(0),
72 qDebug() << __PRETTY_FUNCTION__;
77 QHBoxLayout *layout = new QHBoxLayout;
78 layout->addWidget(m_mapView);
80 layout->setSpacing(0);
82 setCentralWidget(new QWidget());
83 centralWidget()->setLayout(layout);
88 setWindowTitle(tr("Situare"));
90 // set stacking order of widgets
91 m_zoomButtonPanel->stackUnder(m_tabbedPanel);
92 if(m_fullScreenButton) {
93 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
94 m_osmLicense->stackUnder(m_fullScreenButton);
96 m_osmLicense->stackUnder(m_zoomButtonPanel);
98 m_ownLocationCrosshair->stackUnder(m_osmLicense);
99 m_indicatorButton->stackUnder(m_ownLocationCrosshair);
100 m_mapScale->stackUnder(m_indicatorButton);
101 m_mapView->stackUnder(m_mapScale);
105 // Set default screen size
106 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
108 setAttribute(Qt::WA_Maemo5StackedWindow);
112 MainWindow::~MainWindow()
114 qDebug() << __PRETTY_FUNCTION__;
121 qDeleteAll(m_queue.begin(), m_queue.end());
124 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
125 m_error_queue.clear();
128 void MainWindow::automaticUpdateDialogFinished(int result)
130 qDebug() << __PRETTY_FUNCTION__;
132 if (result == QMessageBox::Yes) {
133 readAutomaticLocationUpdateSettings();
135 QSettings settings(DIRECTORY_NAME, FILE_NAME);
136 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
137 readAutomaticLocationUpdateSettings();
140 m_automaticUpdateLocationDialog->deleteLater();
143 void MainWindow::buildFullScreenButton()
145 qDebug() << __PRETTY_FUNCTION__;
147 m_fullScreenButton = new FullScreenButton(this);
148 connect(m_fullScreenButton, SIGNAL(clicked()),
149 this, SLOT(toggleFullScreen()));
150 #endif // Q_WS_MAEMO_5
153 void MainWindow::buildFriendListPanel()
155 qDebug() << __PRETTY_FUNCTION__;
157 m_friendsListPanel = new FriendListPanel(this);
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_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
166 this, SIGNAL(findFriend(GeoCoordinate)));
168 connect(this, SIGNAL(friendImageReady(User*)),
169 m_friendsListPanel, SLOT(friendImageReady(User*)));
172 void MainWindow::buildIndicatorButton()
174 qDebug() << __PRETTY_FUNCTION__;
176 m_indicatorButton = new IndicatorButton(this);
178 connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
179 this, SIGNAL(autoCenteringTriggered(bool)));
181 connect(m_mapView, SIGNAL(viewResized(QSize)),
182 m_indicatorButton, SLOT(screenResized(QSize)));
184 connect(m_indicatorButton, SIGNAL(draggingModeTriggered()),
185 this, SIGNAL(draggingModeTriggered()));
188 void MainWindow::buildInformationBox(const QString &message, bool modal)
190 qDebug() << __PRETTY_FUNCTION__;
192 QString errorMessage = message;
196 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
199 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
200 // extra line changes are needed to make error notes broader
201 errorMessage.prepend("\n");
202 errorMessage.append("\n");
204 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
206 QLabel *label = new QLabel(msgBox);
207 label->setAlignment(Qt::AlignCenter);
208 label->setText(errorMessage);
209 msgBox->setWidget(label);
211 QMessageBox *msgBox = new QMessageBox(this);
212 msgBox->button(QMessageBox::Ok);
213 msgBox->setText(errorMessage);
214 msgBox->setModal(modal);
220 void MainWindow::buildManualLocationCrosshair()
222 qDebug() << __PRETTY_FUNCTION__;
224 m_ownLocationCrosshair = new QLabel(this);
225 QPixmap crosshairImage(":/res/images/sight.png");
226 m_ownLocationCrosshair->setPixmap(crosshairImage);
227 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
228 m_ownLocationCrosshair->hide();
229 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
231 connect(m_mapView, SIGNAL(viewResized(QSize)),
232 this, SLOT(drawOwnLocationCrosshair(QSize)));
235 void MainWindow::buildMap()
237 qDebug() << __PRETTY_FUNCTION__;
239 m_mapView = new MapView(this);
241 buildZoomButtonPanel();
243 buildManualLocationCrosshair();
244 buildFullScreenButton();
245 buildIndicatorButton();
248 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
249 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
251 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
252 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
254 connect(m_mapView, SIGNAL(viewResized(QSize)),
255 this, SIGNAL(mapViewResized(QSize)));
257 connect(m_mapView, SIGNAL(viewResized(QSize)),
258 this, SLOT(drawFullScreenButton(QSize)));
260 connect(m_mapView, SIGNAL(viewResized(QSize)),
261 this, SLOT(drawMapScale(QSize)));
263 connect(m_mapView, SIGNAL(viewResized(QSize)),
264 this, SLOT(setViewPortSize(QSize)));
266 connect(this, SIGNAL(zoomLevelChanged(int)),
267 m_mapView, SLOT(setZoomLevel(int)));
269 connect(m_mapView, SIGNAL(viewZoomFinished()),
270 this, SIGNAL(viewZoomFinished()));
272 connect(m_mapView, SIGNAL(zoomIn()),
273 this, SIGNAL(zoomIn()));
276 void MainWindow::buildMapScale()
278 m_mapScale = new MapScale(this);
279 connect(this, SIGNAL(newMapResolution(qreal)),
280 m_mapScale, SLOT(updateMapResolution(qreal)));
283 void MainWindow::buildOsmLicense()
285 qDebug() << __PRETTY_FUNCTION__;
287 m_osmLicense = new QLabel(this);
288 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
289 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
290 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
291 m_osmLicense->setFont(QFont("Nokia Sans", 9));
292 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
293 m_osmLicense->fontMetrics().height());
295 connect(m_mapView, SIGNAL(viewResized(QSize)),
296 this, SLOT(drawOsmLicense(QSize)));
299 void MainWindow::buildPanels()
301 qDebug() << __PRETTY_FUNCTION__;
303 buildUserInfoPanel();
304 buildFriendListPanel();
306 m_tabbedPanel = new TabbedPanel(this);
307 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
308 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
310 connect(m_tabbedPanel, SIGNAL(panelOpened()),
311 m_friendsListPanel, SLOT(clearFriendListFilter()));
313 connect(m_mapView, SIGNAL(viewResized(QSize)),
314 m_tabbedPanel, SLOT(resizePanel(QSize)));
317 void MainWindow::buildUserInfoPanel()
319 qDebug() << __PRETTY_FUNCTION__;
321 m_userInfoPanel = new UserInfoPanel(this);
323 connect(this, SIGNAL(userLocationReady(User*)),
324 m_userInfoPanel, SLOT(userDataReceived(User*)));
326 connect(this, SIGNAL(reverseGeoReady(QString)),
327 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
329 connect(this, SIGNAL(clearUpdateLocationDialogData()),
330 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
332 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
333 this, SIGNAL(findUser(GeoCoordinate)));
335 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
336 this, SIGNAL(requestReverseGeo()));
338 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
339 this, SIGNAL(statusUpdate(QString,bool)));
341 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
342 this, SIGNAL(refreshUserData()));
344 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
345 this, SLOT(buildInformationBox(QString, bool)));
348 void MainWindow::buildWebView()
350 qDebug() << __PRETTY_FUNCTION__;
353 m_webView = new QWebView;
356 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
358 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
360 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
361 this, SLOT(webViewRequestFinished(QNetworkReply*)));
362 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
363 this, SIGNAL(updateCredentials(QUrl)));
364 connect(m_webView, SIGNAL(loadFinished(bool)),
365 this, SLOT(loadDone(bool)));
371 void MainWindow::buildZoomButtonPanel()
373 qDebug() << __PRETTY_FUNCTION__;
375 m_zoomButtonPanel = new ZoomButtonPanel(this);
377 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
378 this, SIGNAL(zoomIn()));
380 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
381 this, SIGNAL(zoomOut()));
383 connect(this, SIGNAL(zoomLevelChanged(int)),
384 m_zoomButtonPanel, SLOT(resetButtons()));
386 connect(this, SIGNAL(maxZoomLevelReached()),
387 m_zoomButtonPanel, SLOT(disableZoomInButton()));
389 connect(this, SIGNAL(minZoomLevelReached()),
390 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
392 connect(m_mapView, SIGNAL(viewResized(QSize)),
393 m_zoomButtonPanel, SLOT(screenResized(QSize)));
395 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
396 this, SIGNAL(draggingModeTriggered()));
399 void MainWindow::clearCookieJar()
401 qDebug() << __PRETTY_FUNCTION__;
408 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
410 QList<QNetworkCookie> emptyList;
413 m_cookieJar->setAllCookies(emptyList);
414 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
417 void MainWindow::createMenus()
419 qDebug() << __PRETTY_FUNCTION__;
422 m_loginAct = new QAction(tr("Login"), this);
423 connect(m_loginAct, SIGNAL(triggered()),
424 this, SIGNAL(loginActionPressed()));
427 m_toSettingsAct = new QAction(tr("Settings"), this);
428 connect(m_toSettingsAct, SIGNAL(triggered()),
429 this, SLOT(openSettingsDialog()));
432 m_gpsToggleAct = new QAction(tr("GPS"), this);
433 m_gpsToggleAct->setCheckable(true);
435 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
436 this, SIGNAL(gpsTriggered(bool)));
438 /// @todo remove when not needed!
439 m_searchLocationAct = new QAction(tr("Location search"), this);
440 connect(m_searchLocationAct, SIGNAL(triggered()),
441 this, SLOT(startLocationSearch()));
443 // build the actual menu
444 m_viewMenu = menuBar()->addMenu(tr("Main"));
445 m_viewMenu->addAction(m_loginAct);
446 m_viewMenu->addAction(m_toSettingsAct);
447 m_viewMenu->addAction(m_gpsToggleAct);
448 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
449 m_viewMenu->setObjectName(tr("Menu"));
452 void MainWindow::dialogFinished(int status)
454 qDebug() << __PRETTY_FUNCTION__;
456 QDialog *dialog = m_queue.takeFirst();
457 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
458 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
462 loginDialog->userInput(m_email, m_password);
464 QStringList urlParts;
465 urlParts.append(FACEBOOK_LOGINBASE);
466 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
467 urlParts.append(INTERVAL1);
468 urlParts.append(SITUARE_LOGIN_SUCCESS);
469 urlParts.append(INTERVAL2);
470 urlParts.append(SITUARE_LOGIN_FAILURE);
471 urlParts.append(FACEBOOK_LOGIN_ENDING);
473 emit saveUsername(m_email);
475 m_webView->load(QUrl(urlParts.join(EMPTY)));
476 toggleProgressIndicator(true);
478 emit cancelLoginProcess();
480 } else if(searchDialog) {
482 emit searchForLocation(searchDialog->input());
486 dialog->deleteLater();
488 if(!m_error_queue.isEmpty() && m_errorShown == false) {
489 showErrorInformationBox();
491 if(!m_queue.isEmpty()) {
492 showInformationBox();
497 void MainWindow::drawFullScreenButton(const QSize &size)
499 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
501 if(m_fullScreenButton)
502 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
503 size.height() - m_fullScreenButton->size().height());
506 void MainWindow::drawMapScale(const QSize &size)
508 qDebug() << __PRETTY_FUNCTION__;
510 const int LEFT_SCALE_MARGIN = 10;
511 const int BOTTOM_SCALE_MARGIN = 2;
512 // qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
514 m_mapScale->move(LEFT_SCALE_MARGIN,
515 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
518 void MainWindow::drawOsmLicense(const QSize &size)
520 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
522 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
524 size.height() - m_osmLicense->fontMetrics().height());
527 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
529 qDebug() << __PRETTY_FUNCTION__;
531 if (m_ownLocationCrosshair != 0) {
532 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
533 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
537 void MainWindow::errorDialogFinished(int status)
539 qDebug() << __PRETTY_FUNCTION__;
542 QDialog *dialog = m_error_queue.takeFirst();
544 dialog->deleteLater();
545 m_errorShown = false;
547 if(!m_error_queue.isEmpty())
548 showErrorInformationBox();
549 else if(!m_queue.isEmpty())
550 showInformationBox();
553 void MainWindow::gpsTimeout()
555 qDebug() << __PRETTY_FUNCTION__;
557 buildInformationBox(tr("GPS timeout"));
560 void MainWindow::grabZoomKeys(bool grab)
562 qDebug() << __PRETTY_FUNCTION__;
565 // Can't grab keys unless we have a window id
569 unsigned long val = (grab) ? 1 : 0;
570 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
574 XChangeProperty (QX11Info::display(),
580 reinterpret_cast<unsigned char *>(&val),
584 #endif // Q_WS_MAEMO_5
587 void MainWindow::keyPressEvent(QKeyEvent* event)
589 qDebug() << __PRETTY_FUNCTION__;
591 switch (event->key()) {
602 QWidget::keyPressEvent(event);
605 void MainWindow::loadCookies()
607 qDebug() << __PRETTY_FUNCTION__;
609 QSettings settings(DIRECTORY_NAME, FILE_NAME);
611 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
613 if(!list.isEmpty()) {
614 QList<QNetworkCookie> cookieList;
615 for(int i=0;i<list.count();i++) {
616 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
620 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
622 m_cookieJar->setAllCookies(cookieList);
623 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
627 void MainWindow::loadDone(bool done)
629 qDebug() << __PRETTY_FUNCTION__;
631 // for the first time the login page is opened, we need to refresh it to get cookies working
639 QWebFrame* frame = m_webView->page()->currentFrame();
643 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
645 foreach (QWebElement element, emailCollection) {
646 element.setAttribute("value", m_email.toAscii());
649 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
650 foreach (QWebElement element, passwordCollection) {
651 element.setAttribute("value", m_password.toAscii());
653 // find connect button
654 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
655 foreach (QWebElement element, buttonCollection)
657 QPoint pos(element.geometry().center());
659 // send a mouse click event to the web page
660 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
662 QApplication::sendEvent(m_webView->page(), &event0);
663 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
665 QApplication::sendEvent(m_webView->page(), &event1);
671 void MainWindow::loggedIn(bool logged)
673 qDebug() << __PRETTY_FUNCTION__;
678 m_loginAct->setText(tr("Logout"));
684 m_loginAct->setText(tr("Login"));
686 updateItemVisibility();
689 void MainWindow::loginFailed()
691 qDebug() << __PRETTY_FUNCTION__;
697 bool MainWindow::loginState()
699 qDebug() << __PRETTY_FUNCTION__;
704 void MainWindow::loginUsingCookies()
706 qDebug() << __PRETTY_FUNCTION__;
708 toggleProgressIndicator(true);
713 QStringList urlParts;
714 urlParts.append(FACEBOOK_LOGINBASE);
715 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
716 urlParts.append(INTERVAL1);
717 urlParts.append(SITUARE_LOGIN_SUCCESS);
718 urlParts.append(INTERVAL2);
719 urlParts.append(SITUARE_LOGIN_FAILURE);
720 urlParts.append(FACEBOOK_LOGIN_ENDING);
722 m_webView->load(QUrl(urlParts.join(EMPTY)));
726 void MainWindow::openSettingsDialog()
728 qDebug() << __PRETTY_FUNCTION__;
730 SettingsDialog *settingsDialog = new SettingsDialog(this);
731 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
732 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
734 settingsDialog->show();
737 void MainWindow::readAutomaticLocationUpdateSettings()
739 qDebug() << __PRETTY_FUNCTION__;
741 QSettings settings(DIRECTORY_NAME, FILE_NAME);
742 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
743 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
746 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
748 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
750 emit enableAutomaticLocationUpdate(false);
754 void MainWindow::queueDialog(QDialog *dialog)
756 qDebug() << __PRETTY_FUNCTION__;
758 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
759 if(dialog->isModal()) {
760 m_error_queue.append(dialog);
762 m_queue.append(dialog);
765 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
766 if(m_error_queue.count() == 1 && m_errorShown == false)
767 showErrorInformationBox();
768 else if(m_queue.count() == 1 && m_errorShown == false)
769 showInformationBox();
772 void MainWindow::saveCookies()
774 qDebug() << __PRETTY_FUNCTION__;
777 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
779 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
782 for(int i=0;i<cookieList.count();i++) {
783 QNetworkCookie cookie = cookieList.at(i);
784 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
785 list.append(QString(byteArray));
787 list.removeDuplicates();
789 QSettings settings(DIRECTORY_NAME, FILE_NAME);
790 settings.setValue(COOKIES, list);
793 void MainWindow::setGPSButtonEnabled(bool enabled)
795 qDebug() << __PRETTY_FUNCTION__;
797 m_gpsToggleAct->setChecked(enabled);
800 void MainWindow::setIndicatorButtonEnabled(bool enabled)
802 qDebug() << __PRETTY_FUNCTION__;
804 m_indicatorButton->setChecked(enabled);
808 void MainWindow::setMapViewScene(QGraphicsScene *scene)
810 qDebug() << __PRETTY_FUNCTION__;
812 m_mapView->setScene(scene);
815 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
817 qDebug() << __PRETTY_FUNCTION__;
820 m_ownLocationCrosshair->show();
821 drawOwnLocationCrosshair(m_viewPortSize);
823 m_ownLocationCrosshair->hide();
827 void MainWindow::settingsDialogAccepted()
829 qDebug() << __PRETTY_FUNCTION__;
831 readAutomaticLocationUpdateSettings();
834 void MainWindow::setUsername(const QString &username)
836 qDebug() << __PRETTY_FUNCTION__;
841 void MainWindow::setViewPortSize(const QSize &size)
843 qDebug() << __PRETTY_FUNCTION__;
845 m_viewPortSize = size;
848 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
850 qDebug() << __PRETTY_FUNCTION__;
852 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
853 tr("Automatic location update"), text,
854 QMessageBox::Yes | QMessageBox::No |
855 QMessageBox::Cancel, this);
856 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
857 this, SLOT(automaticUpdateDialogFinished(int)));
859 m_automaticUpdateLocationDialog->show();
862 void MainWindow::toggleFullScreen()
864 qDebug() << __PRETTY_FUNCTION__;
866 if(windowState() == Qt::WindowNoState)
872 void MainWindow::showErrorInformationBox()
874 qDebug() << __PRETTY_FUNCTION__;
876 if(m_error_queue.count()) {
878 QDialog *dialog = m_error_queue.first();
879 connect(dialog, SIGNAL(finished(int)),
880 this, SLOT(errorDialogFinished(int)));
885 void MainWindow::showInformationBox()
887 qDebug() << __PRETTY_FUNCTION__;
889 if(m_queue.count()) {
890 QDialog *dialog = m_queue.first();
891 connect(dialog, SIGNAL(finished(int)),
892 this, SLOT(dialogFinished(int)));
897 void MainWindow::showPanels()
899 qDebug() << __PRETTY_FUNCTION__;
901 drawFullScreenButton(m_viewPortSize);
904 // if(!m_friendsListPanel->isVisible()) {
905 // m_friendsListPanel->show();
906 // m_friendsListPanelSidebar->show();
909 // if(!m_userPanel->isVisible()) {
910 // m_userPanel->show();
911 // m_userPanelSidebar->show();
916 void MainWindow::startLocationSearch()
918 qDebug() << __PRETTY_FUNCTION__;
920 SearchDialog *searchDialog = new SearchDialog();
921 queueDialog(searchDialog);
924 void MainWindow::startLoginProcess()
926 qDebug() << __PRETTY_FUNCTION__;
928 LoginDialog *loginDialog = new LoginDialog();
930 emit fetchUsernameFromSettings();
932 loginDialog->clearTextFields();
934 if(!m_email.isEmpty())
935 loginDialog->setEmailField(m_email);
937 queueDialog(loginDialog);
940 void MainWindow::toggleProgressIndicator(bool value)
942 qDebug() << __PRETTY_FUNCTION__;
946 m_progressIndicatorCount++;
947 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
949 if(m_progressIndicatorCount > 0)
950 m_progressIndicatorCount--;
952 if(m_progressIndicatorCount == 0)
953 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
957 #endif // Q_WS_MAEMO_5
960 void MainWindow::updateItemVisibility()
962 qDebug() << __PRETTY_FUNCTION__;
965 // m_friendsListPanel->closePanel();
966 // m_friendsListPanel->hide();
967 // m_friendsListPanelSidebar->hide();
969 // m_userPanel->closePanel();
970 // m_userPanel->hide();
971 // m_userPanelSidebar->hide();
975 const QString MainWindow::username()
977 qDebug() << __PRETTY_FUNCTION__;
982 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
984 qDebug() << __PRETTY_FUNCTION__;
986 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
987 // qwebview starts to load a new page while the current page loading is not finished
988 if(reply->error() != QNetworkReply::OperationCanceledError &&
989 reply->error() != QNetworkReply::NoError) {
990 emit error(ErrorContext::NETWORK, reply->error());