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_mapView, SIGNAL(viewResized(QSize)),
311 m_tabbedPanel, SLOT(resizePanel(QSize)));
314 void MainWindow::buildUserInfoPanel()
316 qDebug() << __PRETTY_FUNCTION__;
318 m_userInfoPanel = new UserInfoPanel(this);
320 connect(this, SIGNAL(userLocationReady(User*)),
321 m_userInfoPanel, SLOT(userDataReceived(User*)));
323 connect(this, SIGNAL(reverseGeoReady(QString)),
324 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
326 connect(this, SIGNAL(clearUpdateLocationDialogData()),
327 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
329 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
330 this, SIGNAL(findUser(GeoCoordinate)));
332 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
333 this, SIGNAL(requestReverseGeo()));
335 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
336 this, SIGNAL(statusUpdate(QString,bool)));
338 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
339 this, SIGNAL(refreshUserData()));
341 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
342 this, SLOT(buildInformationBox(QString, bool)));
345 void MainWindow::buildWebView()
347 qDebug() << __PRETTY_FUNCTION__;
350 m_webView = new QWebView;
353 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
355 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
357 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
358 this, SLOT(webViewRequestFinished(QNetworkReply*)));
359 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
360 this, SIGNAL(updateCredentials(QUrl)));
361 connect(m_webView, SIGNAL(loadFinished(bool)),
362 this, SLOT(loadDone(bool)));
368 void MainWindow::buildZoomButtonPanel()
370 qDebug() << __PRETTY_FUNCTION__;
372 m_zoomButtonPanel = new ZoomButtonPanel(this);
374 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
375 this, SIGNAL(zoomIn()));
377 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
378 this, SIGNAL(zoomOut()));
380 connect(this, SIGNAL(zoomLevelChanged(int)),
381 m_zoomButtonPanel, SLOT(resetButtons()));
383 connect(this, SIGNAL(maxZoomLevelReached()),
384 m_zoomButtonPanel, SLOT(disableZoomInButton()));
386 connect(this, SIGNAL(minZoomLevelReached()),
387 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
389 connect(m_mapView, SIGNAL(viewResized(QSize)),
390 m_zoomButtonPanel, SLOT(screenResized(QSize)));
392 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
393 this, SIGNAL(draggingModeTriggered()));
396 void MainWindow::clearCookieJar()
398 qDebug() << __PRETTY_FUNCTION__;
405 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
407 QList<QNetworkCookie> emptyList;
410 m_cookieJar->setAllCookies(emptyList);
411 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
414 void MainWindow::createMenus()
416 qDebug() << __PRETTY_FUNCTION__;
419 m_loginAct = new QAction(tr("Login"), this);
420 connect(m_loginAct, SIGNAL(triggered()),
421 this, SIGNAL(loginActionPressed()));
424 m_toSettingsAct = new QAction(tr("Settings"), this);
425 connect(m_toSettingsAct, SIGNAL(triggered()),
426 this, SLOT(openSettingsDialog()));
429 m_gpsToggleAct = new QAction(tr("GPS"), this);
430 m_gpsToggleAct->setCheckable(true);
432 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
433 this, SIGNAL(gpsTriggered(bool)));
435 /// @todo remove when not needed!
436 m_searchLocationAct = new QAction(tr("Location search"), this);
437 connect(m_searchLocationAct, SIGNAL(triggered()),
438 this, SLOT(startLocationSearch()));
440 // build the actual menu
441 m_viewMenu = menuBar()->addMenu(tr("Main"));
442 m_viewMenu->addAction(m_loginAct);
443 m_viewMenu->addAction(m_toSettingsAct);
444 m_viewMenu->addAction(m_gpsToggleAct);
445 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
446 m_viewMenu->setObjectName(tr("Menu"));
449 void MainWindow::dialogFinished(int status)
451 qDebug() << __PRETTY_FUNCTION__;
453 QDialog *dialog = m_queue.takeFirst();
454 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
455 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
459 loginDialog->userInput(m_email, m_password);
461 QStringList urlParts;
462 urlParts.append(FACEBOOK_LOGINBASE);
463 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
464 urlParts.append(INTERVAL1);
465 urlParts.append(SITUARE_LOGIN_SUCCESS);
466 urlParts.append(INTERVAL2);
467 urlParts.append(SITUARE_LOGIN_FAILURE);
468 urlParts.append(FACEBOOK_LOGIN_ENDING);
470 emit saveUsername(m_email);
472 m_webView->load(QUrl(urlParts.join(EMPTY)));
473 toggleProgressIndicator(true);
475 emit cancelLoginProcess();
477 } else if(searchDialog) {
479 emit searchForLocation(searchDialog->input());
483 dialog->deleteLater();
485 if(!m_error_queue.isEmpty() && m_errorShown == false) {
486 showErrorInformationBox();
488 if(!m_queue.isEmpty()) {
489 showInformationBox();
494 void MainWindow::drawFullScreenButton(const QSize &size)
496 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
498 if(m_fullScreenButton)
499 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
500 size.height() - m_fullScreenButton->size().height());
503 void MainWindow::drawMapScale(const QSize &size)
505 qDebug() << __PRETTY_FUNCTION__;
507 const int LEFT_SCALE_MARGIN = 10;
508 const int BOTTOM_SCALE_MARGIN = 2;
509 // qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
511 m_mapScale->move(LEFT_SCALE_MARGIN,
512 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
515 void MainWindow::drawOsmLicense(const QSize &size)
517 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
519 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
521 size.height() - m_osmLicense->fontMetrics().height());
524 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
526 qDebug() << __PRETTY_FUNCTION__;
528 if (m_ownLocationCrosshair != 0) {
529 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
530 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
534 void MainWindow::errorDialogFinished(int status)
536 qDebug() << __PRETTY_FUNCTION__;
539 QDialog *dialog = m_error_queue.takeFirst();
541 dialog->deleteLater();
542 m_errorShown = false;
544 if(!m_error_queue.isEmpty())
545 showErrorInformationBox();
546 else if(!m_queue.isEmpty())
547 showInformationBox();
550 void MainWindow::gpsTimeout()
552 qDebug() << __PRETTY_FUNCTION__;
554 buildInformationBox(tr("GPS timeout"));
557 void MainWindow::grabZoomKeys(bool grab)
559 qDebug() << __PRETTY_FUNCTION__;
562 // Can't grab keys unless we have a window id
566 unsigned long val = (grab) ? 1 : 0;
567 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
571 XChangeProperty (QX11Info::display(),
577 reinterpret_cast<unsigned char *>(&val),
581 #endif // Q_WS_MAEMO_5
584 void MainWindow::keyPressEvent(QKeyEvent* event)
586 qDebug() << __PRETTY_FUNCTION__;
588 switch (event->key()) {
599 QWidget::keyPressEvent(event);
602 void MainWindow::loadCookies()
604 qDebug() << __PRETTY_FUNCTION__;
606 QSettings settings(DIRECTORY_NAME, FILE_NAME);
608 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
610 if(!list.isEmpty()) {
611 QList<QNetworkCookie> cookieList;
612 for(int i=0;i<list.count();i++) {
613 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
617 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
619 m_cookieJar->setAllCookies(cookieList);
620 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
624 void MainWindow::loadDone(bool done)
626 qDebug() << __PRETTY_FUNCTION__;
628 // for the first time the login page is opened, we need to refresh it to get cookies working
636 QWebFrame* frame = m_webView->page()->currentFrame();
640 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
642 foreach (QWebElement element, emailCollection) {
643 element.setAttribute("value", m_email.toAscii());
646 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
647 foreach (QWebElement element, passwordCollection) {
648 element.setAttribute("value", m_password.toAscii());
650 // find connect button
651 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
652 foreach (QWebElement element, buttonCollection)
654 QPoint pos(element.geometry().center());
656 // send a mouse click event to the web page
657 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
659 QApplication::sendEvent(m_webView->page(), &event0);
660 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
662 QApplication::sendEvent(m_webView->page(), &event1);
668 void MainWindow::loggedIn(bool logged)
670 qDebug() << __PRETTY_FUNCTION__;
675 m_loginAct->setText(tr("Logout"));
681 m_loginAct->setText(tr("Login"));
683 updateItemVisibility();
686 void MainWindow::loginFailed()
688 qDebug() << __PRETTY_FUNCTION__;
694 bool MainWindow::loginState()
696 qDebug() << __PRETTY_FUNCTION__;
701 void MainWindow::loginUsingCookies()
703 qDebug() << __PRETTY_FUNCTION__;
705 toggleProgressIndicator(true);
710 QStringList urlParts;
711 urlParts.append(FACEBOOK_LOGINBASE);
712 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
713 urlParts.append(INTERVAL1);
714 urlParts.append(SITUARE_LOGIN_SUCCESS);
715 urlParts.append(INTERVAL2);
716 urlParts.append(SITUARE_LOGIN_FAILURE);
717 urlParts.append(FACEBOOK_LOGIN_ENDING);
719 m_webView->load(QUrl(urlParts.join(EMPTY)));
723 void MainWindow::openSettingsDialog()
725 qDebug() << __PRETTY_FUNCTION__;
727 SettingsDialog *settingsDialog = new SettingsDialog(this);
728 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
729 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
731 settingsDialog->show();
734 void MainWindow::readAutomaticLocationUpdateSettings()
736 qDebug() << __PRETTY_FUNCTION__;
738 QSettings settings(DIRECTORY_NAME, FILE_NAME);
739 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
740 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
743 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
745 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
747 emit enableAutomaticLocationUpdate(false);
751 void MainWindow::queueDialog(QDialog *dialog)
753 qDebug() << __PRETTY_FUNCTION__;
755 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
756 if(dialog->isModal()) {
757 m_error_queue.append(dialog);
759 m_queue.append(dialog);
762 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
763 if(m_error_queue.count() == 1 && m_errorShown == false)
764 showErrorInformationBox();
765 else if(m_queue.count() == 1 && m_errorShown == false)
766 showInformationBox();
769 void MainWindow::saveCookies()
771 qDebug() << __PRETTY_FUNCTION__;
774 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
776 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
779 for(int i=0;i<cookieList.count();i++) {
780 QNetworkCookie cookie = cookieList.at(i);
781 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
782 list.append(QString(byteArray));
784 list.removeDuplicates();
786 QSettings settings(DIRECTORY_NAME, FILE_NAME);
787 settings.setValue(COOKIES, list);
790 void MainWindow::setGPSButtonEnabled(bool enabled)
792 qDebug() << __PRETTY_FUNCTION__;
794 m_gpsToggleAct->setChecked(enabled);
797 void MainWindow::setIndicatorButtonEnabled(bool enabled)
799 qDebug() << __PRETTY_FUNCTION__;
801 m_indicatorButton->setChecked(enabled);
805 void MainWindow::setMapViewScene(QGraphicsScene *scene)
807 qDebug() << __PRETTY_FUNCTION__;
809 m_mapView->setScene(scene);
812 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
814 qDebug() << __PRETTY_FUNCTION__;
817 m_ownLocationCrosshair->show();
818 drawOwnLocationCrosshair(m_viewPortSize);
820 m_ownLocationCrosshair->hide();
824 void MainWindow::settingsDialogAccepted()
826 qDebug() << __PRETTY_FUNCTION__;
828 readAutomaticLocationUpdateSettings();
831 void MainWindow::setUsername(const QString &username)
833 qDebug() << __PRETTY_FUNCTION__;
838 void MainWindow::setViewPortSize(const QSize &size)
840 qDebug() << __PRETTY_FUNCTION__;
842 m_viewPortSize = size;
845 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
847 qDebug() << __PRETTY_FUNCTION__;
849 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
850 tr("Automatic location update"), text,
851 QMessageBox::Yes | QMessageBox::No |
852 QMessageBox::Cancel, this);
853 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
854 this, SLOT(automaticUpdateDialogFinished(int)));
856 m_automaticUpdateLocationDialog->show();
859 void MainWindow::toggleFullScreen()
861 qDebug() << __PRETTY_FUNCTION__;
863 if(windowState() == Qt::WindowNoState)
869 void MainWindow::showErrorInformationBox()
871 qDebug() << __PRETTY_FUNCTION__;
873 if(m_error_queue.count()) {
875 QDialog *dialog = m_error_queue.first();
876 connect(dialog, SIGNAL(finished(int)),
877 this, SLOT(errorDialogFinished(int)));
882 void MainWindow::showInformationBox()
884 qDebug() << __PRETTY_FUNCTION__;
886 if(m_queue.count()) {
887 QDialog *dialog = m_queue.first();
888 connect(dialog, SIGNAL(finished(int)),
889 this, SLOT(dialogFinished(int)));
894 void MainWindow::showPanels()
896 qDebug() << __PRETTY_FUNCTION__;
898 drawFullScreenButton(m_viewPortSize);
901 // if(!m_friendsListPanel->isVisible()) {
902 // m_friendsListPanel->show();
903 // m_friendsListPanelSidebar->show();
906 // if(!m_userPanel->isVisible()) {
907 // m_userPanel->show();
908 // m_userPanelSidebar->show();
913 void MainWindow::startLocationSearch()
915 qDebug() << __PRETTY_FUNCTION__;
917 SearchDialog *searchDialog = new SearchDialog();
918 queueDialog(searchDialog);
921 void MainWindow::startLoginProcess()
923 qDebug() << __PRETTY_FUNCTION__;
925 LoginDialog *loginDialog = new LoginDialog();
927 emit fetchUsernameFromSettings();
929 loginDialog->clearTextFields();
931 if(!m_email.isEmpty())
932 loginDialog->setEmailField(m_email);
934 queueDialog(loginDialog);
937 void MainWindow::toggleProgressIndicator(bool value)
939 qDebug() << __PRETTY_FUNCTION__;
943 m_progressIndicatorCount++;
944 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
946 if(m_progressIndicatorCount > 0)
947 m_progressIndicatorCount--;
949 if(m_progressIndicatorCount == 0)
950 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
954 #endif // Q_WS_MAEMO_5
957 void MainWindow::updateItemVisibility()
959 qDebug() << __PRETTY_FUNCTION__;
962 // m_friendsListPanel->closePanel();
963 // m_friendsListPanel->hide();
964 // m_friendsListPanelSidebar->hide();
966 // m_userPanel->closePanel();
967 // m_userPanel->hide();
968 // m_userPanelSidebar->hide();
972 const QString MainWindow::username()
974 qDebug() << __PRETTY_FUNCTION__;
979 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
981 qDebug() << __PRETTY_FUNCTION__;
983 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
984 // qwebview starts to load a new page while the current page loading is not finished
985 if(reply->error() != QNetworkReply::OperationCanceledError &&
986 reply->error() != QNetworkReply::NoError) {
987 emit error(ErrorContext::NETWORK, reply->error());