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 "searchdialog.h"
41 #include "settingsdialog.h"
42 #include "userinfopanel.h"
43 #include "zoombuttonpanel.h"
44 #include "indicatorbuttonpanel.h"
46 #include "mainwindow.h"
48 // These MUST BE HERE, compiling for Maemo fails if moved
50 #include <QtMaemo5/QMaemo5InformationBox>
51 #include <QtGui/QX11Info>
52 #include <X11/Xatom.h>
54 #endif // Q_WS_MAEMO_5
56 MainWindow::MainWindow(QWidget *parent)
57 : QMainWindow(parent),
61 m_progressIndicatorCount(0),
62 m_ownLocationCrosshair(0),
66 m_fullScreenButton(0),
67 // m_indicatorButton(0),
68 m_indicatorButtonPanel(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);
85 buildFriendListPanel();
89 setWindowTitle(tr("Situare"));
91 // set stacking order of widgets
92 m_zoomButtonPanel->stackUnder(m_userPanel);
93 if(m_fullScreenButton) {
94 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
95 m_osmLicense->stackUnder(m_fullScreenButton);
97 m_osmLicense->stackUnder(m_zoomButtonPanel);
99 m_ownLocationCrosshair->stackUnder(m_osmLicense);
100 m_indicatorButtonPanel->stackUnder(m_ownLocationCrosshair);
101 m_mapScale->stackUnder(m_indicatorButtonPanel);
102 m_mapView->stackUnder(m_mapScale);
106 // Set default screen size
107 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
109 setAttribute(Qt::WA_Maemo5StackedWindow);
113 MainWindow::~MainWindow()
115 qDebug() << __PRETTY_FUNCTION__;
122 qDeleteAll(m_queue.begin(), m_queue.end());
125 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
126 m_error_queue.clear();
129 void MainWindow::automaticUpdateDialogFinished(int result)
131 qDebug() << __PRETTY_FUNCTION__;
133 if (result == QMessageBox::Yes) {
134 readAutomaticLocationUpdateSettings();
136 QSettings settings(DIRECTORY_NAME, FILE_NAME);
137 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
138 readAutomaticLocationUpdateSettings();
141 m_automaticUpdateLocationDialog->deleteLater();
144 void MainWindow::buildFullScreenButton()
146 qDebug() << __PRETTY_FUNCTION__;
148 m_fullScreenButton = new FullScreenButton(this);
149 connect(m_fullScreenButton, SIGNAL(clicked()),
150 this, SLOT(toggleFullScreen()));
151 #endif // Q_WS_MAEMO_5
154 void MainWindow::buildFriendListPanel()
156 qDebug() << __PRETTY_FUNCTION__;
158 m_friendsListPanel = new FriendListPanel(this);
160 m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
162 m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
164 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
165 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
167 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
168 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
170 connect(m_mapView, SIGNAL(viewResized(QSize)),
171 m_friendsListPanel, SLOT(resizePanel(QSize)));
173 connect(m_mapView, SIGNAL(viewResized(QSize)),
174 m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
176 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
177 this, SIGNAL(findFriend(GeoCoordinate)));
179 connect(this, SIGNAL(friendImageReady(User*)),
180 m_friendsListPanel, SLOT(friendImageReady(User*)));
183 void MainWindow::buildIndicatorButtonPanel()
185 qDebug() << __PRETTY_FUNCTION__;
187 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
189 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
190 this, SIGNAL(autoCenteringTriggered(bool)));
192 connect(m_mapView, SIGNAL(viewResized(QSize)),
193 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
195 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
196 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
198 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
199 this, SIGNAL(draggingModeTriggered()));
202 void MainWindow::buildInformationBox(const QString &message, bool modal)
204 qDebug() << __PRETTY_FUNCTION__;
206 QString errorMessage = message;
210 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
213 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
214 // extra line changes are needed to make error notes broader
215 errorMessage.prepend("\n");
216 errorMessage.append("\n");
218 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
220 QLabel *label = new QLabel(msgBox);
221 label->setAlignment(Qt::AlignCenter);
222 label->setText(errorMessage);
223 msgBox->setWidget(label);
225 QMessageBox *msgBox = new QMessageBox(this);
226 msgBox->button(QMessageBox::Ok);
227 msgBox->setText(errorMessage);
228 msgBox->setModal(modal);
234 void MainWindow::buildManualLocationCrosshair()
236 qDebug() << __PRETTY_FUNCTION__;
238 m_ownLocationCrosshair = new QLabel(this);
239 QPixmap crosshairImage(":/res/images/sight.png");
240 m_ownLocationCrosshair->setPixmap(crosshairImage);
241 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
242 m_ownLocationCrosshair->hide();
243 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
245 connect(m_mapView, SIGNAL(viewResized(QSize)),
246 this, SLOT(drawOwnLocationCrosshair(QSize)));
249 void MainWindow::buildMap()
251 qDebug() << __PRETTY_FUNCTION__;
253 m_mapView = new MapView(this);
255 buildZoomButtonPanel();
257 buildManualLocationCrosshair();
258 buildFullScreenButton();
259 buildIndicatorButtonPanel();
262 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
263 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
265 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
266 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
268 connect(m_mapView, SIGNAL(viewResized(QSize)),
269 this, SIGNAL(mapViewResized(QSize)));
271 connect(m_mapView, SIGNAL(viewResized(QSize)),
272 this, SLOT(drawFullScreenButton(QSize)));
274 connect(m_mapView, SIGNAL(viewResized(QSize)),
275 this, SLOT(drawMapScale(QSize)));
277 connect(m_mapView, SIGNAL(viewResized(QSize)),
278 this, SLOT(setViewPortSize(QSize)));
280 connect(this, SIGNAL(zoomLevelChanged(int)),
281 m_mapView, SLOT(setZoomLevel(int)));
283 connect(m_mapView, SIGNAL(viewZoomFinished()),
284 this, SIGNAL(viewZoomFinished()));
286 connect(m_mapView, SIGNAL(zoomIn()),
287 this, SIGNAL(zoomIn()));
290 void MainWindow::buildMapScale()
292 m_mapScale = new MapScale(this);
293 connect(this, SIGNAL(newMapResolution(qreal)),
294 m_mapScale, SLOT(updateMapResolution(qreal)));
297 void MainWindow::buildOsmLicense()
299 qDebug() << __PRETTY_FUNCTION__;
301 m_osmLicense = new QLabel(this);
302 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
303 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
304 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
305 m_osmLicense->setFont(QFont("Nokia Sans", 9));
306 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
307 m_osmLicense->fontMetrics().height());
309 connect(m_mapView, SIGNAL(viewResized(QSize)),
310 this, SLOT(drawOsmLicense(QSize)));
313 void MainWindow::buildUserInfoPanel()
315 qDebug() << __PRETTY_FUNCTION__;
317 m_userPanel = new UserInfoPanel(this);
319 m_userPanelSidebar = new PanelSideBar(this, LEFT);
321 m_userPanelSidebar->stackUnder(m_friendsListPanel);
322 m_userPanel->stackUnder(m_userPanelSidebar);
324 connect(this, SIGNAL(userLocationReady(User*)),
325 m_userPanel, SLOT(userDataReceived(User*)));
327 connect(this, SIGNAL(reverseGeoReady(QString)),
328 m_userPanel, SIGNAL(reverseGeoReady(QString)));
330 connect(this, SIGNAL(clearUpdateLocationDialogData()),
331 m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
333 connect(m_mapView, SIGNAL(viewResized(QSize)),
334 m_userPanel, SLOT(resizePanel(QSize)));
336 connect(m_mapView, SIGNAL(viewResized(QSize)),
337 m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
339 connect(m_userPanel, SIGNAL(findUser(GeoCoordinate)),
340 this, SIGNAL(findUser(GeoCoordinate)));
342 connect(m_userPanel, SIGNAL(requestReverseGeo()),
343 this, SIGNAL(requestReverseGeo()));
345 connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
346 this, SIGNAL(statusUpdate(QString,bool)));
348 connect(m_userPanel, SIGNAL(refreshUserData()),
349 this, SIGNAL(refreshUserData()));
351 connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
352 this, SLOT(buildInformationBox(QString, bool)));
355 void MainWindow::buildWebView()
357 qDebug() << __PRETTY_FUNCTION__;
360 m_webView = new QWebView;
363 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
365 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
367 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
368 this, SLOT(webViewRequestFinished(QNetworkReply*)));
369 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
370 this, SIGNAL(updateCredentials(QUrl)));
371 connect(m_webView, SIGNAL(loadFinished(bool)),
372 this, SLOT(loadDone(bool)));
378 void MainWindow::buildZoomButtonPanel()
380 qDebug() << __PRETTY_FUNCTION__;
382 m_zoomButtonPanel = new ZoomButtonPanel(this);
384 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
385 this, SIGNAL(zoomIn()));
387 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
388 this, SIGNAL(zoomOut()));
390 connect(this, SIGNAL(zoomLevelChanged(int)),
391 m_zoomButtonPanel, SLOT(resetButtons()));
393 connect(this, SIGNAL(maxZoomLevelReached()),
394 m_zoomButtonPanel, SLOT(disableZoomInButton()));
396 connect(this, SIGNAL(minZoomLevelReached()),
397 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
399 connect(m_mapView, SIGNAL(viewResized(QSize)),
400 m_zoomButtonPanel, SLOT(screenResized(QSize)));
402 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
403 this, SIGNAL(draggingModeTriggered()));
406 void MainWindow::clearCookieJar()
408 qDebug() << __PRETTY_FUNCTION__;
415 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
417 QList<QNetworkCookie> emptyList;
420 m_cookieJar->setAllCookies(emptyList);
421 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
424 void MainWindow::createMenus()
426 qDebug() << __PRETTY_FUNCTION__;
429 m_loginAct = new QAction(tr("Login"), this);
430 connect(m_loginAct, SIGNAL(triggered()),
431 this, SIGNAL(loginActionPressed()));
434 m_toSettingsAct = new QAction(tr("Settings"), this);
435 connect(m_toSettingsAct, SIGNAL(triggered()),
436 this, SLOT(openSettingsDialog()));
439 m_gpsToggleAct = new QAction(tr("GPS"), this);
440 m_gpsToggleAct->setCheckable(true);
442 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
443 this, SIGNAL(gpsTriggered(bool)));
445 /// @todo remove when not needed!
446 m_searchLocationAct = new QAction(tr("Location search"), this);
447 connect(m_searchLocationAct, SIGNAL(triggered()),
448 this, SLOT(startLocationSearch()));
450 // build the actual menu
451 m_viewMenu = menuBar()->addMenu(tr("Main"));
452 m_viewMenu->addAction(m_loginAct);
453 m_viewMenu->addAction(m_toSettingsAct);
454 m_viewMenu->addAction(m_gpsToggleAct);
455 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
456 m_viewMenu->setObjectName(tr("Menu"));
459 void MainWindow::dialogFinished(int status)
461 qDebug() << __PRETTY_FUNCTION__;
463 QDialog *dialog = m_queue.takeFirst();
464 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
465 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
469 loginDialog->userInput(m_email, m_password);
471 QStringList urlParts;
472 urlParts.append(FACEBOOK_LOGINBASE);
473 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
474 urlParts.append(INTERVAL1);
475 urlParts.append(SITUARE_LOGIN_SUCCESS);
476 urlParts.append(INTERVAL2);
477 urlParts.append(SITUARE_LOGIN_FAILURE);
478 urlParts.append(FACEBOOK_LOGIN_ENDING);
480 emit saveUsername(m_email);
482 m_webView->load(QUrl(urlParts.join(EMPTY)));
483 toggleProgressIndicator(true);
485 emit cancelLoginProcess();
487 } else if(searchDialog) {
489 emit searchForLocation(searchDialog->input());
493 dialog->deleteLater();
495 if(!m_error_queue.isEmpty() && m_errorShown == false) {
496 showErrorInformationBox();
498 if(!m_queue.isEmpty()) {
499 showInformationBox();
504 void MainWindow::drawFullScreenButton(const QSize &size)
506 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
508 if(m_fullScreenButton) {
510 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
512 size.height() - m_fullScreenButton->size().height());
514 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
515 size.height() - m_fullScreenButton->size().height());
520 void MainWindow::drawMapScale(const QSize &size)
522 qDebug() << __PRETTY_FUNCTION__;
524 const int LEFT_SCALE_MARGIN = 10;
525 const int BOTTOM_SCALE_MARGIN = 2;
526 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
528 m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
529 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
532 void MainWindow::drawOsmLicense(const QSize &size)
534 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
536 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
538 size.height() - m_osmLicense->fontMetrics().height());
541 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
543 qDebug() << __PRETTY_FUNCTION__;
545 if (m_ownLocationCrosshair != 0) {
546 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
547 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
551 void MainWindow::errorDialogFinished(int status)
553 qDebug() << __PRETTY_FUNCTION__;
556 QDialog *dialog = m_error_queue.takeFirst();
558 dialog->deleteLater();
559 m_errorShown = false;
561 if(!m_error_queue.isEmpty())
562 showErrorInformationBox();
563 else if(!m_queue.isEmpty())
564 showInformationBox();
567 void MainWindow::gpsTimeout()
569 qDebug() << __PRETTY_FUNCTION__;
571 buildInformationBox(tr("GPS timeout"));
574 void MainWindow::grabZoomKeys(bool grab)
576 qDebug() << __PRETTY_FUNCTION__;
579 // Can't grab keys unless we have a window id
583 unsigned long val = (grab) ? 1 : 0;
584 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
588 XChangeProperty (QX11Info::display(),
594 reinterpret_cast<unsigned char *>(&val),
598 #endif // Q_WS_MAEMO_5
601 void MainWindow::keyPressEvent(QKeyEvent* event)
603 qDebug() << __PRETTY_FUNCTION__;
605 switch (event->key()) {
616 QWidget::keyPressEvent(event);
619 void MainWindow::loadCookies()
621 qDebug() << __PRETTY_FUNCTION__;
623 QSettings settings(DIRECTORY_NAME, FILE_NAME);
625 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
627 if(!list.isEmpty()) {
628 QList<QNetworkCookie> cookieList;
629 for(int i=0;i<list.count();i++) {
630 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
634 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
636 m_cookieJar->setAllCookies(cookieList);
637 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
641 void MainWindow::loadDone(bool done)
643 qDebug() << __PRETTY_FUNCTION__;
645 // for the first time the login page is opened, we need to refresh it to get cookies working
653 QWebFrame* frame = m_webView->page()->currentFrame();
657 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
659 foreach (QWebElement element, emailCollection) {
660 element.setAttribute("value", m_email.toAscii());
663 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
664 foreach (QWebElement element, passwordCollection) {
665 element.setAttribute("value", m_password.toAscii());
667 // find connect button
668 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
669 foreach (QWebElement element, buttonCollection)
671 QPoint pos(element.geometry().center());
673 // send a mouse click event to the web page
674 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
676 QApplication::sendEvent(m_webView->page(), &event0);
677 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
679 QApplication::sendEvent(m_webView->page(), &event1);
685 void MainWindow::loggedIn(bool logged)
687 qDebug() << __PRETTY_FUNCTION__;
692 m_loginAct->setText(tr("Logout"));
698 m_loginAct->setText(tr("Login"));
700 updateItemVisibility();
703 void MainWindow::loginFailed()
705 qDebug() << __PRETTY_FUNCTION__;
711 bool MainWindow::loginState()
713 qDebug() << __PRETTY_FUNCTION__;
718 void MainWindow::loginUsingCookies()
720 qDebug() << __PRETTY_FUNCTION__;
722 toggleProgressIndicator(true);
727 QStringList urlParts;
728 urlParts.append(FACEBOOK_LOGINBASE);
729 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
730 urlParts.append(INTERVAL1);
731 urlParts.append(SITUARE_LOGIN_SUCCESS);
732 urlParts.append(INTERVAL2);
733 urlParts.append(SITUARE_LOGIN_FAILURE);
734 urlParts.append(FACEBOOK_LOGIN_ENDING);
736 m_webView->load(QUrl(urlParts.join(EMPTY)));
740 void MainWindow::openSettingsDialog()
742 qDebug() << __PRETTY_FUNCTION__;
744 SettingsDialog *settingsDialog = new SettingsDialog(this);
745 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
746 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
748 settingsDialog->show();
751 void MainWindow::readAutomaticLocationUpdateSettings()
753 qDebug() << __PRETTY_FUNCTION__;
755 QSettings settings(DIRECTORY_NAME, FILE_NAME);
756 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
757 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
760 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
762 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
764 emit enableAutomaticLocationUpdate(false);
768 void MainWindow::queueDialog(QDialog *dialog)
770 qDebug() << __PRETTY_FUNCTION__;
772 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
773 if(dialog->isModal()) {
774 m_error_queue.append(dialog);
776 m_queue.append(dialog);
779 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
780 if(m_error_queue.count() == 1 && m_errorShown == false)
781 showErrorInformationBox();
782 else if(m_queue.count() == 1 && m_errorShown == false)
783 showInformationBox();
786 void MainWindow::saveCookies()
788 qDebug() << __PRETTY_FUNCTION__;
791 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
793 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
796 for(int i=0;i<cookieList.count();i++) {
797 QNetworkCookie cookie = cookieList.at(i);
798 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
799 list.append(QString(byteArray));
801 list.removeDuplicates();
803 QSettings settings(DIRECTORY_NAME, FILE_NAME);
804 settings.setValue(COOKIES, list);
807 void MainWindow::setGPSButtonEnabled(bool enabled)
809 qDebug() << __PRETTY_FUNCTION__;
811 m_gpsToggleAct->setChecked(enabled);
814 void MainWindow::setIndicatorButtonEnabled(bool enabled)
816 qDebug() << __PRETTY_FUNCTION__;
818 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
821 void MainWindow::setMapViewScene(QGraphicsScene *scene)
823 qDebug() << __PRETTY_FUNCTION__;
825 m_mapView->setScene(scene);
828 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
830 qDebug() << __PRETTY_FUNCTION__;
833 m_ownLocationCrosshair->show();
834 drawOwnLocationCrosshair(m_viewPortSize);
836 m_ownLocationCrosshair->hide();
840 void MainWindow::settingsDialogAccepted()
842 qDebug() << __PRETTY_FUNCTION__;
844 readAutomaticLocationUpdateSettings();
847 void MainWindow::setUsername(const QString &username)
849 qDebug() << __PRETTY_FUNCTION__;
854 void MainWindow::setViewPortSize(const QSize &size)
856 qDebug() << __PRETTY_FUNCTION__;
858 m_viewPortSize = size;
861 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
863 qDebug() << __PRETTY_FUNCTION__;
865 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
866 tr("Automatic location update"), text,
867 QMessageBox::Yes | QMessageBox::No |
868 QMessageBox::Cancel, this);
869 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
870 this, SLOT(automaticUpdateDialogFinished(int)));
872 m_automaticUpdateLocationDialog->show();
875 void MainWindow::toggleFullScreen()
877 qDebug() << __PRETTY_FUNCTION__;
879 if(windowState() == Qt::WindowNoState)
885 void MainWindow::showErrorInformationBox()
887 qDebug() << __PRETTY_FUNCTION__;
889 if(m_error_queue.count()) {
891 QDialog *dialog = m_error_queue.first();
892 connect(dialog, SIGNAL(finished(int)),
893 this, SLOT(errorDialogFinished(int)));
898 void MainWindow::showInformationBox()
900 qDebug() << __PRETTY_FUNCTION__;
902 if(m_queue.count()) {
903 QDialog *dialog = m_queue.first();
904 connect(dialog, SIGNAL(finished(int)),
905 this, SLOT(dialogFinished(int)));
910 void MainWindow::showPanels()
912 qDebug() << __PRETTY_FUNCTION__;
914 drawFullScreenButton(m_viewPortSize);
917 if(!m_friendsListPanel->isVisible()) {
918 m_friendsListPanel->show();
919 m_friendsListPanelSidebar->show();
922 if(!m_userPanel->isVisible()) {
924 m_userPanelSidebar->show();
929 void MainWindow::startLocationSearch()
931 qDebug() << __PRETTY_FUNCTION__;
933 SearchDialog *searchDialog = new SearchDialog();
934 queueDialog(searchDialog);
937 void MainWindow::startLoginProcess()
939 qDebug() << __PRETTY_FUNCTION__;
941 LoginDialog *loginDialog = new LoginDialog();
943 emit fetchUsernameFromSettings();
945 loginDialog->clearTextFields();
947 if(!m_email.isEmpty())
948 loginDialog->setEmailField(m_email);
950 queueDialog(loginDialog);
953 void MainWindow::toggleProgressIndicator(bool value)
955 qDebug() << __PRETTY_FUNCTION__;
959 m_progressIndicatorCount++;
960 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
962 if(m_progressIndicatorCount > 0)
963 m_progressIndicatorCount--;
965 if(m_progressIndicatorCount == 0)
966 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
970 #endif // Q_WS_MAEMO_5
973 void MainWindow::updateItemVisibility()
975 qDebug() << __PRETTY_FUNCTION__;
978 m_friendsListPanel->closePanel();
979 m_friendsListPanel->hide();
980 m_friendsListPanelSidebar->hide();
981 m_userPanel->closePanel();
983 m_userPanelSidebar->hide();
987 const QString MainWindow::username()
989 qDebug() << __PRETTY_FUNCTION__;
994 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
996 qDebug() << __PRETTY_FUNCTION__;
998 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
999 // qwebview starts to load a new page while the current page loading is not finished
1000 if(reply->error() != QNetworkReply::OperationCanceledError &&
1001 reply->error() != QNetworkReply::NoError) {
1002 emit error(ErrorContext::NETWORK, reply->error());