2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Henri Lampela - henri.lampela@ixonos.com
6 Kaj Wallin - kaj.wallin@ixonos.com
7 Jussi Laitinen jussi.laitinen@ixonos.com
8 Sami Rämö - sami.ramo@ixonos.com
9 Ville Tiensuu - ville.tiensuu@ixonos.com
11 Situare is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 version 2 as published by the Free Software Foundation.
15 Situare is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with Situare; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 #include <QtAlgorithms>
30 #include "facebookservice/facebookauthentication.h"
31 #include "map/mapcommon.h"
32 #include "map/mapview.h"
34 #include "friendlistpanel.h"
35 #include "fullscreenbutton.h"
36 #include "indicatorbutton.h"
37 #include "logindialog.h"
39 #include "searchdialog.h"
40 #include "settingsdialog.h"
41 #include "userinfopanel.h"
42 #include "zoombuttonpanel.h"
43 #include "indicatorbuttonpanel.h"
45 #include "mainwindow.h"
47 // These MUST BE HERE, compiling for Maemo fails if moved
49 #include <QtMaemo5/QMaemo5InformationBox>
50 #include <QtGui/QX11Info>
51 #include <X11/Xatom.h>
53 #endif // Q_WS_MAEMO_5
55 MainWindow::MainWindow(QWidget *parent)
56 : QMainWindow(parent),
60 m_progressIndicatorCount(0),
61 m_ownLocationCrosshair(0),
65 m_fullScreenButton(0),
66 // m_indicatorButton(0),
67 m_indicatorButtonPanel(0),
71 qDebug() << __PRETTY_FUNCTION__;
76 QHBoxLayout *layout = new QHBoxLayout;
77 layout->addWidget(m_mapView);
79 layout->setSpacing(0);
81 setCentralWidget(new QWidget());
82 centralWidget()->setLayout(layout);
84 buildFriendListPanel();
88 setWindowTitle(tr("Situare"));
90 // set stacking order of widgets
91 m_zoomButtonPanel->stackUnder(m_userPanel);
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_indicatorButtonPanel->stackUnder(m_ownLocationCrosshair);
100 m_mapScale->stackUnder(m_indicatorButtonPanel);
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 m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
161 m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
163 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
164 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
166 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
167 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
169 connect(m_mapView, SIGNAL(viewResized(QSize)),
170 m_friendsListPanel, SLOT(resizePanel(QSize)));
172 connect(m_mapView, SIGNAL(viewResized(QSize)),
173 m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
175 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
176 this, SIGNAL(findFriend(GeoCoordinate)));
178 connect(this, SIGNAL(friendImageReady(User*)),
179 m_friendsListPanel, SLOT(friendImageReady(User*)));
182 void MainWindow::buildIndicatorButtonPanel()
184 qDebug() << __PRETTY_FUNCTION__;
186 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
188 // connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
189 // this, SIGNAL(autoCenteringTriggered(bool)));
191 // connect(m_mapView, SIGNAL(viewResized(QSize)),
192 // m_indicatorButton, SLOT(screenResized(QSize)));
194 // connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
195 // m_indicatorButton, SLOT(updateValues(qreal, qreal, bool)));
197 // connect(m_indicatorButton, SIGNAL(draggingModeTriggered()),
198 // this, SIGNAL(draggingModeTriggered()));
201 void MainWindow::buildInformationBox(const QString &message, bool modal)
203 qDebug() << __PRETTY_FUNCTION__;
205 QString errorMessage = message;
209 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
212 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
213 // extra line changes are needed to make error notes broader
214 errorMessage.prepend("\n");
215 errorMessage.append("\n");
217 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
219 QLabel *label = new QLabel(msgBox);
220 label->setAlignment(Qt::AlignCenter);
221 label->setText(errorMessage);
222 msgBox->setWidget(label);
224 QMessageBox *msgBox = new QMessageBox(this);
225 msgBox->button(QMessageBox::Ok);
226 msgBox->setText(errorMessage);
227 msgBox->setModal(modal);
233 void MainWindow::buildManualLocationCrosshair()
235 qDebug() << __PRETTY_FUNCTION__;
237 m_ownLocationCrosshair = new QLabel(this);
238 QPixmap crosshairImage(":/res/images/sight.png");
239 m_ownLocationCrosshair->setPixmap(crosshairImage);
240 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
241 m_ownLocationCrosshair->hide();
242 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
244 connect(m_mapView, SIGNAL(viewResized(QSize)),
245 this, SLOT(drawOwnLocationCrosshair(QSize)));
248 void MainWindow::buildMap()
250 qDebug() << __PRETTY_FUNCTION__;
252 m_mapView = new MapView(this);
254 buildZoomButtonPanel();
256 buildManualLocationCrosshair();
257 buildFullScreenButton();
258 buildIndicatorButtonPanel();
261 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
262 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
264 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
265 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
267 connect(m_mapView, SIGNAL(viewResized(QSize)),
268 this, SIGNAL(mapViewResized(QSize)));
270 connect(m_mapView, SIGNAL(viewResized(QSize)),
271 this, SLOT(drawFullScreenButton(QSize)));
273 connect(m_mapView, SIGNAL(viewResized(QSize)),
274 this, SLOT(drawMapScale(QSize)));
276 connect(m_mapView, SIGNAL(viewResized(QSize)),
277 this, SLOT(setViewPortSize(QSize)));
279 connect(this, SIGNAL(zoomLevelChanged(int)),
280 m_mapView, SLOT(setZoomLevel(int)));
282 connect(m_mapView, SIGNAL(viewZoomFinished()),
283 this, SIGNAL(viewZoomFinished()));
285 connect(m_mapView, SIGNAL(zoomIn()),
286 this, SIGNAL(zoomIn()));
289 void MainWindow::buildMapScale()
291 m_mapScale = new MapScale(this);
292 connect(this, SIGNAL(newMapResolution(qreal)),
293 m_mapScale, SLOT(updateMapResolution(qreal)));
296 void MainWindow::buildOsmLicense()
298 qDebug() << __PRETTY_FUNCTION__;
300 m_osmLicense = new QLabel(this);
301 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
302 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
303 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
304 m_osmLicense->setFont(QFont("Nokia Sans", 9));
305 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
306 m_osmLicense->fontMetrics().height());
308 connect(m_mapView, SIGNAL(viewResized(QSize)),
309 this, SLOT(drawOsmLicense(QSize)));
312 void MainWindow::buildUserInfoPanel()
314 qDebug() << __PRETTY_FUNCTION__;
316 m_userPanel = new UserInfoPanel(this);
318 m_userPanelSidebar = new PanelSideBar(this, LEFT);
320 m_userPanelSidebar->stackUnder(m_friendsListPanel);
321 m_userPanel->stackUnder(m_userPanelSidebar);
323 connect(this, SIGNAL(userLocationReady(User*)),
324 m_userPanel, SLOT(userDataReceived(User*)));
326 connect(this, SIGNAL(reverseGeoReady(QString)),
327 m_userPanel, SIGNAL(reverseGeoReady(QString)));
329 connect(this, SIGNAL(clearUpdateLocationDialogData()),
330 m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
332 connect(m_mapView, SIGNAL(viewResized(QSize)),
333 m_userPanel, SLOT(resizePanel(QSize)));
335 connect(m_mapView, SIGNAL(viewResized(QSize)),
336 m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
338 connect(m_userPanel, SIGNAL(findUser(GeoCoordinate)),
339 this, SIGNAL(findUser(GeoCoordinate)));
341 connect(m_userPanel, SIGNAL(requestReverseGeo()),
342 this, SIGNAL(requestReverseGeo()));
344 connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
345 this, SIGNAL(statusUpdate(QString,bool)));
347 connect(m_userPanel, SIGNAL(refreshUserData()),
348 this, SIGNAL(refreshUserData()));
350 connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
351 this, SLOT(buildInformationBox(QString, bool)));
354 void MainWindow::buildWebView()
356 qDebug() << __PRETTY_FUNCTION__;
359 m_webView = new QWebView;
362 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
364 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
366 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
367 this, SLOT(webViewRequestFinished(QNetworkReply*)));
368 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
369 this, SIGNAL(updateCredentials(QUrl)));
370 connect(m_webView, SIGNAL(loadFinished(bool)),
371 this, SLOT(loadDone(bool)));
377 void MainWindow::buildZoomButtonPanel()
379 qDebug() << __PRETTY_FUNCTION__;
381 m_zoomButtonPanel = new ZoomButtonPanel(this);
383 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
384 this, SIGNAL(zoomIn()));
386 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
387 this, SIGNAL(zoomOut()));
389 connect(this, SIGNAL(zoomLevelChanged(int)),
390 m_zoomButtonPanel, SLOT(resetButtons()));
392 connect(this, SIGNAL(maxZoomLevelReached()),
393 m_zoomButtonPanel, SLOT(disableZoomInButton()));
395 connect(this, SIGNAL(minZoomLevelReached()),
396 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
398 connect(m_mapView, SIGNAL(viewResized(QSize)),
399 m_zoomButtonPanel, SLOT(screenResized(QSize)));
401 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
402 this, SIGNAL(draggingModeTriggered()));
405 void MainWindow::clearCookieJar()
407 qDebug() << __PRETTY_FUNCTION__;
414 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
416 QList<QNetworkCookie> emptyList;
419 m_cookieJar->setAllCookies(emptyList);
420 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
423 void MainWindow::createMenus()
425 qDebug() << __PRETTY_FUNCTION__;
428 m_loginAct = new QAction(tr("Login"), this);
429 connect(m_loginAct, SIGNAL(triggered()),
430 this, SIGNAL(loginActionPressed()));
433 m_toSettingsAct = new QAction(tr("Settings"), this);
434 connect(m_toSettingsAct, SIGNAL(triggered()),
435 this, SLOT(openSettingsDialog()));
438 m_gpsToggleAct = new QAction(tr("GPS"), this);
439 m_gpsToggleAct->setCheckable(true);
441 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
442 this, SIGNAL(gpsTriggered(bool)));
444 /// @todo remove when not needed!
445 m_searchLocationAct = new QAction(tr("Location search"), this);
446 connect(m_searchLocationAct, SIGNAL(triggered()),
447 this, SLOT(startLocationSearch()));
449 // build the actual menu
450 m_viewMenu = menuBar()->addMenu(tr("Main"));
451 m_viewMenu->addAction(m_loginAct);
452 m_viewMenu->addAction(m_toSettingsAct);
453 m_viewMenu->addAction(m_gpsToggleAct);
454 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
455 m_viewMenu->setObjectName(tr("Menu"));
458 void MainWindow::dialogFinished(int status)
460 qDebug() << __PRETTY_FUNCTION__;
462 QDialog *dialog = m_queue.takeFirst();
463 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
464 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
468 loginDialog->userInput(m_email, m_password);
470 QStringList urlParts;
471 urlParts.append(FACEBOOK_LOGINBASE);
472 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
473 urlParts.append(INTERVAL1);
474 urlParts.append(SITUARE_LOGIN_SUCCESS);
475 urlParts.append(INTERVAL2);
476 urlParts.append(SITUARE_LOGIN_FAILURE);
477 urlParts.append(FACEBOOK_LOGIN_ENDING);
479 emit saveUsername(m_email);
481 m_webView->load(QUrl(urlParts.join(EMPTY)));
482 toggleProgressIndicator(true);
484 emit cancelLoginProcess();
486 } else if(searchDialog) {
488 emit searchForLocation(searchDialog->input());
492 dialog->deleteLater();
494 if(!m_error_queue.isEmpty() && m_errorShown == false) {
495 showErrorInformationBox();
497 if(!m_queue.isEmpty()) {
498 showInformationBox();
503 void MainWindow::drawFullScreenButton(const QSize &size)
505 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
507 if(m_fullScreenButton) {
509 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
511 size.height() - m_fullScreenButton->size().height());
513 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
514 size.height() - m_fullScreenButton->size().height());
519 void MainWindow::drawMapScale(const QSize &size)
521 qDebug() << __PRETTY_FUNCTION__;
523 const int LEFT_SCALE_MARGIN = 10;
524 const int BOTTOM_SCALE_MARGIN = 2;
525 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
527 m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
528 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
531 void MainWindow::drawOsmLicense(const QSize &size)
533 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
535 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
537 size.height() - m_osmLicense->fontMetrics().height());
540 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
542 qDebug() << __PRETTY_FUNCTION__;
544 if (m_ownLocationCrosshair != 0) {
545 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
546 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
550 void MainWindow::errorDialogFinished(int status)
552 qDebug() << __PRETTY_FUNCTION__;
555 QDialog *dialog = m_error_queue.takeFirst();
557 dialog->deleteLater();
558 m_errorShown = false;
560 if(!m_error_queue.isEmpty())
561 showErrorInformationBox();
562 else if(!m_queue.isEmpty())
563 showInformationBox();
566 void MainWindow::gpsTimeout()
568 qDebug() << __PRETTY_FUNCTION__;
570 buildInformationBox(tr("GPS timeout"));
573 void MainWindow::grabZoomKeys(bool grab)
575 qDebug() << __PRETTY_FUNCTION__;
578 // Can't grab keys unless we have a window id
582 unsigned long val = (grab) ? 1 : 0;
583 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
587 XChangeProperty (QX11Info::display(),
593 reinterpret_cast<unsigned char *>(&val),
597 #endif // Q_WS_MAEMO_5
600 void MainWindow::keyPressEvent(QKeyEvent* event)
602 qDebug() << __PRETTY_FUNCTION__;
604 switch (event->key()) {
615 QWidget::keyPressEvent(event);
618 void MainWindow::loadCookies()
620 qDebug() << __PRETTY_FUNCTION__;
622 QSettings settings(DIRECTORY_NAME, FILE_NAME);
624 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
626 if(!list.isEmpty()) {
627 QList<QNetworkCookie> cookieList;
628 for(int i=0;i<list.count();i++) {
629 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
633 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
635 m_cookieJar->setAllCookies(cookieList);
636 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
640 void MainWindow::loadDone(bool done)
642 qDebug() << __PRETTY_FUNCTION__;
644 // for the first time the login page is opened, we need to refresh it to get cookies working
652 QWebFrame* frame = m_webView->page()->currentFrame();
656 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
658 foreach (QWebElement element, emailCollection) {
659 element.setAttribute("value", m_email.toAscii());
662 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
663 foreach (QWebElement element, passwordCollection) {
664 element.setAttribute("value", m_password.toAscii());
666 // find connect button
667 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
668 foreach (QWebElement element, buttonCollection)
670 QPoint pos(element.geometry().center());
672 // send a mouse click event to the web page
673 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
675 QApplication::sendEvent(m_webView->page(), &event0);
676 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
678 QApplication::sendEvent(m_webView->page(), &event1);
684 void MainWindow::loggedIn(bool logged)
686 qDebug() << __PRETTY_FUNCTION__;
691 m_loginAct->setText(tr("Logout"));
697 m_loginAct->setText(tr("Login"));
699 updateItemVisibility();
702 void MainWindow::loginFailed()
704 qDebug() << __PRETTY_FUNCTION__;
710 bool MainWindow::loginState()
712 qDebug() << __PRETTY_FUNCTION__;
717 void MainWindow::loginUsingCookies()
719 qDebug() << __PRETTY_FUNCTION__;
721 toggleProgressIndicator(true);
726 QStringList urlParts;
727 urlParts.append(FACEBOOK_LOGINBASE);
728 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
729 urlParts.append(INTERVAL1);
730 urlParts.append(SITUARE_LOGIN_SUCCESS);
731 urlParts.append(INTERVAL2);
732 urlParts.append(SITUARE_LOGIN_FAILURE);
733 urlParts.append(FACEBOOK_LOGIN_ENDING);
735 m_webView->load(QUrl(urlParts.join(EMPTY)));
739 void MainWindow::openSettingsDialog()
741 qDebug() << __PRETTY_FUNCTION__;
743 SettingsDialog *settingsDialog = new SettingsDialog(this);
744 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
745 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
747 settingsDialog->show();
750 void MainWindow::readAutomaticLocationUpdateSettings()
752 qDebug() << __PRETTY_FUNCTION__;
754 QSettings settings(DIRECTORY_NAME, FILE_NAME);
755 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
756 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
759 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
761 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
763 emit enableAutomaticLocationUpdate(false);
767 void MainWindow::queueDialog(QDialog *dialog)
769 qDebug() << __PRETTY_FUNCTION__;
771 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
772 if(dialog->isModal()) {
773 m_error_queue.append(dialog);
775 m_queue.append(dialog);
778 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
779 if(m_error_queue.count() == 1 && m_errorShown == false)
780 showErrorInformationBox();
781 else if(m_queue.count() == 1 && m_errorShown == false)
782 showInformationBox();
785 void MainWindow::saveCookies()
787 qDebug() << __PRETTY_FUNCTION__;
790 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
792 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
795 for(int i=0;i<cookieList.count();i++) {
796 QNetworkCookie cookie = cookieList.at(i);
797 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
798 list.append(QString(byteArray));
800 list.removeDuplicates();
802 QSettings settings(DIRECTORY_NAME, FILE_NAME);
803 settings.setValue(COOKIES, list);
806 void MainWindow::setGPSButtonEnabled(bool enabled)
808 qDebug() << __PRETTY_FUNCTION__;
810 m_gpsToggleAct->setChecked(enabled);
813 void MainWindow::setIndicatorButtonEnabled(bool enabled)
815 qDebug() << __PRETTY_FUNCTION__;
817 // m_indicatorButton->setChecked(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());