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
10 Katri Kaikkonen - katri.kaikkonen@ixonos.com
12 Situare is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 version 2 as published by the Free Software Foundation.
16 Situare is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with Situare; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
29 #include <QtAlgorithms>
31 #include "facebookservice/facebookauthentication.h"
32 #include "map/mapcommon.h"
33 #include "map/mapview.h"
36 #include "friendlistpanel.h"
37 #include "fullscreenbutton.h"
38 #include "indicatorbuttonpanel.h"
39 #include "logindialog.h"
41 #include "panelcommon.h"
42 #include "routingpanel.h"
43 #include "tabbedpanel.h"
44 #include "searchdialog.h"
45 #include "settingsdialog.h"
46 #include "userinfopanel.h"
47 #include "zoombuttonpanel.h"
49 #include "mainwindow.h"
51 // These MUST BE HERE, compiling for Maemo fails if moved
53 #include <QtMaemo5/QMaemo5InformationBox>
54 #include <QtGui/QX11Info>
55 #include <X11/Xatom.h>
57 #endif // Q_WS_MAEMO_5
59 MainWindow::MainWindow(QWidget *parent)
60 : QMainWindow(parent),
64 m_progressIndicatorCount(0),
65 m_ownLocationCrosshair(0),
69 m_fullScreenButton(0),
70 m_indicatorButtonPanel(0),
74 qDebug() << __PRETTY_FUNCTION__;
79 QHBoxLayout *layout = new QHBoxLayout;
80 layout->addWidget(m_mapView);
82 layout->setSpacing(0);
84 setCentralWidget(new QWidget());
85 centralWidget()->setLayout(layout);
90 setWindowTitle(tr("Situare"));
92 // set stacking order of widgets
93 m_zoomButtonPanel->stackUnder(m_tabbedPanel);
94 if(m_fullScreenButton) {
95 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
96 m_osmLicense->stackUnder(m_fullScreenButton);
98 m_osmLicense->stackUnder(m_zoomButtonPanel);
100 m_ownLocationCrosshair->stackUnder(m_osmLicense);
101 m_indicatorButtonPanel->stackUnder(m_ownLocationCrosshair);
102 m_mapScale->stackUnder(m_indicatorButtonPanel);
103 m_mapView->stackUnder(m_mapScale);
107 // Set default screen size
108 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
110 setAttribute(Qt::WA_Maemo5StackedWindow);
114 MainWindow::~MainWindow()
116 qDebug() << __PRETTY_FUNCTION__;
123 qDeleteAll(m_queue.begin(), m_queue.end());
126 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
127 m_error_queue.clear();
130 void MainWindow::automaticUpdateDialogFinished(int result)
132 qDebug() << __PRETTY_FUNCTION__;
134 if (result == QMessageBox::Yes) {
135 readAutomaticLocationUpdateSettings();
137 QSettings settings(DIRECTORY_NAME, FILE_NAME);
138 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
139 readAutomaticLocationUpdateSettings();
142 m_automaticUpdateLocationDialog->deleteLater();
145 void MainWindow::buildFullScreenButton()
147 qDebug() << __PRETTY_FUNCTION__;
149 m_fullScreenButton = new FullScreenButton(this);
150 connect(m_fullScreenButton, SIGNAL(clicked()),
151 this, SLOT(toggleFullScreen()));
152 #endif // Q_WS_MAEMO_5
155 void MainWindow::buildFriendListPanel()
157 qDebug() << __PRETTY_FUNCTION__;
159 m_friendsListPanel = new FriendListPanel(this);
161 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
162 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
164 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
165 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
167 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
168 this, SIGNAL(findFriend(GeoCoordinate)));
170 connect(this, SIGNAL(friendImageReady(User*)),
171 m_friendsListPanel, SLOT(friendImageReady(User*)));
174 void MainWindow::buildIndicatorButtonPanel()
176 qDebug() << __PRETTY_FUNCTION__;
178 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
180 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
181 this, SIGNAL(autoCenteringTriggered(bool)));
183 connect(m_mapView, SIGNAL(viewResized(QSize)),
184 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
186 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
187 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
189 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
190 this, SIGNAL(draggingModeTriggered()));
193 void MainWindow::buildInformationBox(const QString &message, bool modal)
195 qDebug() << __PRETTY_FUNCTION__;
197 QString errorMessage = message;
201 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
204 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
205 // extra line changes are needed to make error notes broader
206 errorMessage.prepend("\n");
207 errorMessage.append("\n");
209 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
211 QLabel *label = new QLabel(msgBox);
212 label->setAlignment(Qt::AlignCenter);
213 label->setText(errorMessage);
214 msgBox->setWidget(label);
216 QMessageBox *msgBox = new QMessageBox(this);
217 msgBox->button(QMessageBox::Ok);
218 msgBox->setText(errorMessage);
219 msgBox->setModal(modal);
225 void MainWindow::buildManualLocationCrosshair()
227 qDebug() << __PRETTY_FUNCTION__;
229 m_ownLocationCrosshair = new QLabel(this);
230 QPixmap crosshairImage(":/res/images/sight.png");
231 m_ownLocationCrosshair->setPixmap(crosshairImage);
232 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
233 m_ownLocationCrosshair->hide();
234 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
236 connect(m_mapView, SIGNAL(viewResized(QSize)),
237 this, SLOT(drawOwnLocationCrosshair(QSize)));
240 void MainWindow::buildMap()
242 qDebug() << __PRETTY_FUNCTION__;
244 m_mapView = new MapView(this);
246 buildZoomButtonPanel();
248 buildManualLocationCrosshair();
249 buildFullScreenButton();
250 buildIndicatorButtonPanel();
253 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
254 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
256 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
257 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
259 connect(m_mapView, SIGNAL(viewResized(QSize)),
260 this, SIGNAL(mapViewResized(QSize)));
262 connect(m_mapView, SIGNAL(viewResized(QSize)),
263 this, SLOT(drawFullScreenButton(QSize)));
265 connect(m_mapView, SIGNAL(viewResized(QSize)),
266 this, SLOT(drawMapScale(QSize)));
268 connect(m_mapView, SIGNAL(viewResized(QSize)),
269 this, SLOT(setViewPortSize(QSize)));
271 connect(this, SIGNAL(zoomLevelChanged(int)),
272 m_mapView, SLOT(setZoomLevel(int)));
274 connect(m_mapView, SIGNAL(viewZoomFinished()),
275 this, SIGNAL(viewZoomFinished()));
277 connect(m_mapView, SIGNAL(zoomIn()),
278 this, SIGNAL(zoomIn()));
281 void MainWindow::buildMapScale()
283 m_mapScale = new MapScale(this);
284 connect(this, SIGNAL(newMapResolution(qreal)),
285 m_mapScale, SLOT(updateMapResolution(qreal)));
288 void MainWindow::buildOsmLicense()
290 qDebug() << __PRETTY_FUNCTION__;
292 m_osmLicense = new QLabel(this);
293 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
294 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
295 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
296 m_osmLicense->setFont(QFont("Nokia Sans", 9));
297 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
298 m_osmLicense->fontMetrics().height());
300 connect(m_mapView, SIGNAL(viewResized(QSize)),
301 this, SLOT(drawOsmLicense(QSize)));
304 void MainWindow::buildPanels()
306 qDebug() << __PRETTY_FUNCTION__;
308 buildUserInfoPanel();
309 buildFriendListPanel();
312 m_tabbedPanel = new TabbedPanel(this);
313 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
314 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
315 m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
317 connect(m_tabbedPanel, SIGNAL(panelOpened()),
318 m_friendsListPanel, SLOT(clearFriendListFilter()));
320 connect(m_mapView, SIGNAL(viewResized(QSize)),
321 m_tabbedPanel, SLOT(resizePanel(QSize)));
324 void MainWindow::buildRoutingPanel()
326 qDebug() << __PRETTY_FUNCTION__;
328 m_routingPanel = new RoutingPanel(this);
330 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
331 m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
333 connect(m_routingPanel,
334 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
336 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
339 void MainWindow::buildUserInfoPanel()
341 qDebug() << __PRETTY_FUNCTION__;
343 m_userInfoPanel = new UserInfoPanel(this);
345 connect(this, SIGNAL(userLocationReady(User*)),
346 m_userInfoPanel, SLOT(userDataReceived(User*)));
348 connect(this, SIGNAL(reverseGeoReady(QString)),
349 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
351 connect(this, SIGNAL(clearUpdateLocationDialogData()),
352 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
354 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
355 this, SIGNAL(findUser(GeoCoordinate)));
357 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
358 this, SIGNAL(requestReverseGeo()));
360 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
361 this, SIGNAL(statusUpdate(QString,bool)));
363 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
364 this, SIGNAL(refreshUserData()));
366 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
367 this, SLOT(buildInformationBox(QString, bool)));
370 void MainWindow::buildWebView()
372 qDebug() << __PRETTY_FUNCTION__;
375 m_webView = new QWebView;
378 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
380 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
382 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
383 this, SLOT(webViewRequestFinished(QNetworkReply*)));
384 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
385 this, SIGNAL(updateCredentials(QUrl)));
386 connect(m_webView, SIGNAL(loadFinished(bool)),
387 this, SLOT(loadDone(bool)));
393 void MainWindow::buildZoomButtonPanel()
395 qDebug() << __PRETTY_FUNCTION__;
397 m_zoomButtonPanel = new ZoomButtonPanel(this);
399 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
400 this, SIGNAL(zoomIn()));
402 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
403 this, SIGNAL(zoomOut()));
405 connect(this, SIGNAL(zoomLevelChanged(int)),
406 m_zoomButtonPanel, SLOT(resetButtons()));
408 connect(this, SIGNAL(maxZoomLevelReached()),
409 m_zoomButtonPanel, SLOT(disableZoomInButton()));
411 connect(this, SIGNAL(minZoomLevelReached()),
412 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
414 connect(m_mapView, SIGNAL(viewResized(QSize)),
415 m_zoomButtonPanel, SLOT(screenResized(QSize)));
417 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
418 this, SIGNAL(draggingModeTriggered()));
421 void MainWindow::clearCookieJar()
423 qDebug() << __PRETTY_FUNCTION__;
430 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
432 QList<QNetworkCookie> emptyList;
435 m_cookieJar->setAllCookies(emptyList);
436 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
439 void MainWindow::createMenus()
441 qDebug() << __PRETTY_FUNCTION__;
444 m_loginAct = new QAction(tr("Login"), this);
445 connect(m_loginAct, SIGNAL(triggered()),
446 this, SIGNAL(loginActionPressed()));
449 m_toSettingsAct = new QAction(tr("Settings"), this);
450 connect(m_toSettingsAct, SIGNAL(triggered()),
451 this, SLOT(openSettingsDialog()));
454 m_gpsToggleAct = new QAction(tr("GPS"), this);
455 m_gpsToggleAct->setCheckable(true);
457 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
458 this, SIGNAL(gpsTriggered(bool)));
460 /// @todo remove when not needed!
461 m_searchLocationAct = new QAction(tr("Location search"), this);
462 connect(m_searchLocationAct, SIGNAL(triggered()),
463 this, SLOT(startLocationSearch()));
465 // build the actual menu
466 m_viewMenu = menuBar()->addMenu(tr("Main"));
467 m_viewMenu->addAction(m_loginAct);
468 m_viewMenu->addAction(m_toSettingsAct);
469 m_viewMenu->addAction(m_gpsToggleAct);
470 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
471 m_viewMenu->setObjectName(tr("Menu"));
474 void MainWindow::dialogFinished(int status)
476 qDebug() << __PRETTY_FUNCTION__;
478 QDialog *dialog = m_queue.takeFirst();
479 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
480 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
484 loginDialog->userInput(m_email, m_password);
486 QStringList urlParts;
487 urlParts.append(FACEBOOK_LOGINBASE);
488 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
489 urlParts.append(INTERVAL1);
490 urlParts.append(SITUARE_LOGIN_SUCCESS);
491 urlParts.append(INTERVAL2);
492 urlParts.append(SITUARE_LOGIN_FAILURE);
493 urlParts.append(FACEBOOK_LOGIN_ENDING);
495 emit saveUsername(m_email);
497 m_webView->load(QUrl(urlParts.join(EMPTY)));
498 toggleProgressIndicator(true);
500 emit cancelLoginProcess();
502 } else if(searchDialog) {
504 emit searchForLocation(searchDialog->input());
508 dialog->deleteLater();
510 if(!m_error_queue.isEmpty() && m_errorShown == false) {
511 showErrorInformationBox();
513 if(!m_queue.isEmpty()) {
514 showInformationBox();
519 void MainWindow::drawFullScreenButton(const QSize &size)
521 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
523 if(m_fullScreenButton)
524 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
525 size.height() - m_fullScreenButton->size().height());
528 void MainWindow::drawMapScale(const QSize &size)
530 qDebug() << __PRETTY_FUNCTION__;
532 const int LEFT_SCALE_MARGIN = 10;
533 const int BOTTOM_SCALE_MARGIN = 2;
534 // qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
536 m_mapScale->move(LEFT_SCALE_MARGIN,
537 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
540 void MainWindow::drawOsmLicense(const QSize &size)
542 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
544 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
546 size.height() - m_osmLicense->fontMetrics().height());
549 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
551 qDebug() << __PRETTY_FUNCTION__;
553 if (m_ownLocationCrosshair != 0) {
554 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
555 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
559 void MainWindow::errorDialogFinished(int status)
561 qDebug() << __PRETTY_FUNCTION__;
564 QDialog *dialog = m_error_queue.takeFirst();
566 dialog->deleteLater();
567 m_errorShown = false;
569 if(!m_error_queue.isEmpty())
570 showErrorInformationBox();
571 else if(!m_queue.isEmpty())
572 showInformationBox();
575 void MainWindow::gpsTimeout()
577 qDebug() << __PRETTY_FUNCTION__;
579 buildInformationBox(tr("GPS timeout"));
582 void MainWindow::grabZoomKeys(bool grab)
584 qDebug() << __PRETTY_FUNCTION__;
587 // Can't grab keys unless we have a window id
591 unsigned long val = (grab) ? 1 : 0;
592 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
596 XChangeProperty (QX11Info::display(),
602 reinterpret_cast<unsigned char *>(&val),
606 #endif // Q_WS_MAEMO_5
609 void MainWindow::keyPressEvent(QKeyEvent* event)
611 qDebug() << __PRETTY_FUNCTION__;
613 switch (event->key()) {
624 QWidget::keyPressEvent(event);
627 void MainWindow::loadCookies()
629 qDebug() << __PRETTY_FUNCTION__;
631 QSettings settings(DIRECTORY_NAME, FILE_NAME);
633 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
635 if(!list.isEmpty()) {
636 QList<QNetworkCookie> cookieList;
637 for(int i=0;i<list.count();i++) {
638 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
642 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
644 m_cookieJar->setAllCookies(cookieList);
645 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
649 void MainWindow::loadDone(bool done)
651 qDebug() << __PRETTY_FUNCTION__;
653 // for the first time the login page is opened, we need to refresh it to get cookies working
661 QWebFrame* frame = m_webView->page()->currentFrame();
665 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
667 foreach (QWebElement element, emailCollection) {
668 element.setAttribute("value", m_email.toAscii());
671 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
672 foreach (QWebElement element, passwordCollection) {
673 element.setAttribute("value", m_password.toAscii());
675 // find connect button
676 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
677 foreach (QWebElement element, buttonCollection)
679 QPoint pos(element.geometry().center());
681 // send a mouse click event to the web page
682 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
684 QApplication::sendEvent(m_webView->page(), &event0);
685 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
687 QApplication::sendEvent(m_webView->page(), &event1);
693 void MainWindow::loggedIn(bool logged)
695 qDebug() << __PRETTY_FUNCTION__;
700 m_loginAct->setText(tr("Logout"));
706 m_loginAct->setText(tr("Login"));
708 updateItemVisibility();
711 void MainWindow::loginFailed()
713 qDebug() << __PRETTY_FUNCTION__;
719 bool MainWindow::loginState()
721 qDebug() << __PRETTY_FUNCTION__;
726 void MainWindow::loginUsingCookies()
728 qDebug() << __PRETTY_FUNCTION__;
730 toggleProgressIndicator(true);
735 QStringList urlParts;
736 urlParts.append(FACEBOOK_LOGINBASE);
737 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
738 urlParts.append(INTERVAL1);
739 urlParts.append(SITUARE_LOGIN_SUCCESS);
740 urlParts.append(INTERVAL2);
741 urlParts.append(SITUARE_LOGIN_FAILURE);
742 urlParts.append(FACEBOOK_LOGIN_ENDING);
744 m_webView->load(QUrl(urlParts.join(EMPTY)));
748 void MainWindow::openSettingsDialog()
750 qDebug() << __PRETTY_FUNCTION__;
752 SettingsDialog *settingsDialog = new SettingsDialog(this);
753 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
754 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
756 settingsDialog->show();
759 void MainWindow::readAutomaticLocationUpdateSettings()
761 qDebug() << __PRETTY_FUNCTION__;
763 QSettings settings(DIRECTORY_NAME, FILE_NAME);
764 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
765 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
768 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
770 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
772 emit enableAutomaticLocationUpdate(false);
776 void MainWindow::queueDialog(QDialog *dialog)
778 qDebug() << __PRETTY_FUNCTION__;
780 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
781 if(dialog->isModal()) {
782 m_error_queue.append(dialog);
784 m_queue.append(dialog);
787 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
788 if(m_error_queue.count() == 1 && m_errorShown == false)
789 showErrorInformationBox();
790 else if(m_queue.count() == 1 && m_errorShown == false)
791 showInformationBox();
794 void MainWindow::saveCookies()
796 qDebug() << __PRETTY_FUNCTION__;
799 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
801 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
804 for(int i=0;i<cookieList.count();i++) {
805 QNetworkCookie cookie = cookieList.at(i);
806 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
807 list.append(QString(byteArray));
809 list.removeDuplicates();
811 QSettings settings(DIRECTORY_NAME, FILE_NAME);
812 settings.setValue(COOKIES, list);
815 void MainWindow::setGPSButtonEnabled(bool enabled)
817 qDebug() << __PRETTY_FUNCTION__;
819 m_gpsToggleAct->setChecked(enabled);
822 void MainWindow::setIndicatorButtonEnabled(bool enabled)
824 qDebug() << __PRETTY_FUNCTION__;
826 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
829 void MainWindow::setMapViewScene(QGraphicsScene *scene)
831 qDebug() << __PRETTY_FUNCTION__;
833 m_mapView->setScene(scene);
836 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
838 qDebug() << __PRETTY_FUNCTION__;
841 m_ownLocationCrosshair->show();
842 drawOwnLocationCrosshair(m_viewPortSize);
844 m_ownLocationCrosshair->hide();
848 void MainWindow::settingsDialogAccepted()
850 qDebug() << __PRETTY_FUNCTION__;
852 readAutomaticLocationUpdateSettings();
855 void MainWindow::setUsername(const QString &username)
857 qDebug() << __PRETTY_FUNCTION__;
862 void MainWindow::setViewPortSize(const QSize &size)
864 qDebug() << __PRETTY_FUNCTION__;
866 m_viewPortSize = size;
869 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
871 qDebug() << __PRETTY_FUNCTION__;
873 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
874 tr("Automatic location update"), text,
875 QMessageBox::Yes | QMessageBox::No |
876 QMessageBox::Cancel, this);
877 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
878 this, SLOT(automaticUpdateDialogFinished(int)));
880 m_automaticUpdateLocationDialog->show();
883 void MainWindow::toggleFullScreen()
885 qDebug() << __PRETTY_FUNCTION__;
887 if(windowState() == Qt::WindowNoState)
893 void MainWindow::showErrorInformationBox()
895 qDebug() << __PRETTY_FUNCTION__;
897 if(m_error_queue.count()) {
899 QDialog *dialog = m_error_queue.first();
900 connect(dialog, SIGNAL(finished(int)),
901 this, SLOT(errorDialogFinished(int)));
906 void MainWindow::showInformationBox()
908 qDebug() << __PRETTY_FUNCTION__;
910 if(m_queue.count()) {
911 QDialog *dialog = m_queue.first();
912 connect(dialog, SIGNAL(finished(int)),
913 this, SLOT(dialogFinished(int)));
918 void MainWindow::showPanels()
920 qDebug() << __PRETTY_FUNCTION__;
922 drawFullScreenButton(m_viewPortSize);
925 // if(!m_friendsListPanel->isVisible()) {
926 // m_friendsListPanel->show();
927 // m_friendsListPanelSidebar->show();
930 // if(!m_userPanel->isVisible()) {
931 // m_userPanel->show();
932 // m_userPanelSidebar->show();
937 void MainWindow::startLocationSearch()
939 qDebug() << __PRETTY_FUNCTION__;
941 SearchDialog *searchDialog = new SearchDialog();
942 queueDialog(searchDialog);
945 void MainWindow::startLoginProcess()
947 qDebug() << __PRETTY_FUNCTION__;
949 LoginDialog *loginDialog = new LoginDialog();
951 emit fetchUsernameFromSettings();
953 loginDialog->clearTextFields();
955 if(!m_email.isEmpty())
956 loginDialog->setEmailField(m_email);
958 queueDialog(loginDialog);
961 void MainWindow::toggleProgressIndicator(bool value)
963 qDebug() << __PRETTY_FUNCTION__;
967 m_progressIndicatorCount++;
968 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
970 if(m_progressIndicatorCount > 0)
971 m_progressIndicatorCount--;
973 if(m_progressIndicatorCount == 0)
974 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
978 #endif // Q_WS_MAEMO_5
981 void MainWindow::updateItemVisibility()
983 qDebug() << __PRETTY_FUNCTION__;
986 // m_friendsListPanel->closePanel();
987 // m_friendsListPanel->hide();
988 // m_friendsListPanelSidebar->hide();
990 // m_userPanel->closePanel();
991 // m_userPanel->hide();
992 // m_userPanelSidebar->hide();
996 const QString MainWindow::username()
998 qDebug() << __PRETTY_FUNCTION__;
1003 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1005 qDebug() << __PRETTY_FUNCTION__;
1007 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1008 // qwebview starts to load a new page while the current page loading is not finished
1009 if(reply->error() != QNetworkReply::OperationCanceledError &&
1010 reply->error() != QNetworkReply::NoError) {
1011 emit error(ErrorContext::NETWORK, reply->error());