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"
44 #include "mainwindow.h"
46 // These MUST BE HERE, compiling for Maemo fails if moved
48 #include <QtMaemo5/QMaemo5InformationBox>
49 #include <QtGui/QX11Info>
50 #include <X11/Xatom.h>
52 #endif // Q_WS_MAEMO_5
54 MainWindow::MainWindow(QWidget *parent)
55 : QMainWindow(parent),
59 m_progressIndicatorCount(0),
60 m_ownLocationCrosshair(0),
64 m_fullScreenButton(0),
69 qDebug() << __PRETTY_FUNCTION__;
74 QHBoxLayout *layout = new QHBoxLayout;
75 layout->addWidget(m_mapView);
77 layout->setSpacing(0);
79 setCentralWidget(new QWidget());
80 centralWidget()->setLayout(layout);
82 buildFriendListPanel();
86 setWindowTitle(tr("Situare"));
88 // set stacking order of widgets
89 m_zoomButtonPanel->stackUnder(m_userPanel);
90 if(m_fullScreenButton) {
91 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
92 m_osmLicense->stackUnder(m_fullScreenButton);
94 m_osmLicense->stackUnder(m_zoomButtonPanel);
96 m_ownLocationCrosshair->stackUnder(m_osmLicense);
97 m_indicatorButton->stackUnder(m_ownLocationCrosshair);
98 m_mapScale->stackUnder(m_indicatorButton);
99 m_mapView->stackUnder(m_mapScale);
103 // Set default screen size
104 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
106 setAttribute(Qt::WA_Maemo5StackedWindow);
110 MainWindow::~MainWindow()
112 qDebug() << __PRETTY_FUNCTION__;
119 qDeleteAll(m_queue.begin(), m_queue.end());
122 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
123 m_error_queue.clear();
126 void MainWindow::automaticUpdateDialogFinished(int result)
128 qDebug() << __PRETTY_FUNCTION__;
130 if (result == QMessageBox::Yes) {
131 readAutomaticLocationUpdateSettings();
133 QSettings settings(DIRECTORY_NAME, FILE_NAME);
134 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
135 readAutomaticLocationUpdateSettings();
138 m_automaticUpdateLocationDialog->deleteLater();
141 void MainWindow::buildFullScreenButton()
143 qDebug() << __PRETTY_FUNCTION__;
145 m_fullScreenButton = new FullScreenButton(this);
146 connect(m_fullScreenButton, SIGNAL(clicked()),
147 this, SLOT(toggleFullScreen()));
148 #endif // Q_WS_MAEMO_5
151 void MainWindow::buildFriendListPanel()
153 qDebug() << __PRETTY_FUNCTION__;
155 m_friendsListPanel = new FriendListPanel(this);
157 m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
159 m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
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_mapView, SIGNAL(viewResized(QSize)),
168 m_friendsListPanel, SLOT(resizePanel(QSize)));
170 connect(m_mapView, SIGNAL(viewResized(QSize)),
171 m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
173 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
174 this, SIGNAL(findFriend(GeoCoordinate)));
176 connect(this, SIGNAL(friendImageReady(User*)),
177 m_friendsListPanel, SLOT(friendImageReady(User*)));
180 void MainWindow::buildIndicatorButton()
182 qDebug() << __PRETTY_FUNCTION__;
184 m_indicatorButton = new IndicatorButton(this);
186 connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
187 this, SIGNAL(autoCenteringTriggered(bool)));
189 connect(m_mapView, SIGNAL(viewResized(QSize)),
190 m_indicatorButton, SLOT(screenResized(QSize)));
192 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
193 m_indicatorButton, SLOT(updateValues(qreal, qreal, bool)));
196 void MainWindow::buildInformationBox(const QString &message, bool modal)
198 qDebug() << __PRETTY_FUNCTION__;
200 QString errorMessage = message;
204 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
207 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
208 // extra line changes are needed to make error notes broader
209 errorMessage.prepend("\n");
210 errorMessage.append("\n");
212 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
214 QLabel *label = new QLabel(msgBox);
215 label->setAlignment(Qt::AlignCenter);
216 label->setText(errorMessage);
217 msgBox->setWidget(label);
219 QMessageBox *msgBox = new QMessageBox(this);
220 msgBox->button(QMessageBox::Ok);
221 msgBox->setText(errorMessage);
222 msgBox->setModal(modal);
228 void MainWindow::buildManualLocationCrosshair()
230 qDebug() << __PRETTY_FUNCTION__;
232 m_ownLocationCrosshair = new QLabel(this);
233 QPixmap crosshairImage(":/res/images/sight.png");
234 m_ownLocationCrosshair->setPixmap(crosshairImage);
235 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
236 m_ownLocationCrosshair->hide();
237 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
239 connect(m_mapView, SIGNAL(viewResized(QSize)),
240 this, SLOT(drawOwnLocationCrosshair(QSize)));
243 void MainWindow::buildMap()
245 qDebug() << __PRETTY_FUNCTION__;
247 m_mapView = new MapView(this);
249 buildZoomButtonPanel();
251 buildManualLocationCrosshair();
252 buildFullScreenButton();
253 buildIndicatorButton();
256 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
257 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
259 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
260 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
262 connect(m_mapView, SIGNAL(viewResized(QSize)),
263 this, SIGNAL(mapViewResized(QSize)));
265 connect(m_mapView, SIGNAL(viewResized(QSize)),
266 this, SLOT(drawFullScreenButton(QSize)));
268 connect(m_mapView, SIGNAL(viewResized(QSize)),
269 this, SLOT(drawMapScale(QSize)));
271 connect(m_mapView, SIGNAL(viewResized(QSize)),
272 this, SLOT(setViewPortSize(QSize)));
274 connect(this, SIGNAL(zoomLevelChanged(int)),
275 m_mapView, SLOT(setZoomLevel(int)));
277 connect(m_mapView, SIGNAL(viewZoomFinished()),
278 this, SIGNAL(viewZoomFinished()));
280 connect(m_mapView, SIGNAL(zoomIn()),
281 this, SIGNAL(zoomIn()));
284 void MainWindow::buildMapScale()
286 m_mapScale = new MapScale(this);
287 connect(this, SIGNAL(newMapResolution(qreal)),
288 m_mapScale, SLOT(updateMapResolution(qreal)));
291 void MainWindow::buildOsmLicense()
293 qDebug() << __PRETTY_FUNCTION__;
295 m_osmLicense = new QLabel(this);
296 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
297 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
298 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
299 m_osmLicense->setFont(QFont("Nokia Sans", 9));
300 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
301 m_osmLicense->fontMetrics().height());
303 connect(m_mapView, SIGNAL(viewResized(QSize)),
304 this, SLOT(drawOsmLicense(QSize)));
307 void MainWindow::buildUserInfoPanel()
309 qDebug() << __PRETTY_FUNCTION__;
311 m_userPanel = new UserInfoPanel(this);
313 m_userPanelSidebar = new PanelSideBar(this, LEFT);
315 m_userPanelSidebar->stackUnder(m_friendsListPanel);
316 m_userPanel->stackUnder(m_userPanelSidebar);
318 connect(this, SIGNAL(userLocationReady(User*)),
319 m_userPanel, SLOT(userDataReceived(User*)));
321 connect(this, SIGNAL(reverseGeoReady(QString)),
322 m_userPanel, SIGNAL(reverseGeoReady(QString)));
324 connect(this, SIGNAL(clearUpdateLocationDialogData()),
325 m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
327 connect(m_mapView, SIGNAL(viewResized(QSize)),
328 m_userPanel, SLOT(resizePanel(QSize)));
330 connect(m_mapView, SIGNAL(viewResized(QSize)),
331 m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
333 connect(m_userPanel, SIGNAL(findUser(GeoCoordinate)),
334 this, SIGNAL(findUser(GeoCoordinate)));
336 connect(m_userPanel, SIGNAL(requestReverseGeo()),
337 this, SIGNAL(requestReverseGeo()));
339 connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
340 this, SIGNAL(statusUpdate(QString,bool)));
342 connect(m_userPanel, SIGNAL(refreshUserData()),
343 this, SIGNAL(refreshUserData()));
345 connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
346 this, SLOT(buildInformationBox(QString, bool)));
349 void MainWindow::buildWebView()
351 qDebug() << __PRETTY_FUNCTION__;
354 m_webView = new QWebView;
357 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
359 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
361 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
362 this, SLOT(webViewRequestFinished(QNetworkReply*)));
363 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
364 this, SIGNAL(updateCredentials(QUrl)));
365 connect(m_webView, SIGNAL(loadFinished(bool)),
366 this, SLOT(loadDone(bool)));
372 void MainWindow::buildZoomButtonPanel()
374 qDebug() << __PRETTY_FUNCTION__;
376 m_zoomButtonPanel = new ZoomButtonPanel(this);
378 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
379 this, SIGNAL(zoomIn()));
381 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
382 this, SIGNAL(zoomOut()));
384 connect(this, SIGNAL(zoomLevelChanged(int)),
385 m_zoomButtonPanel, SLOT(resetButtons()));
387 connect(this, SIGNAL(maxZoomLevelReached()),
388 m_zoomButtonPanel, SLOT(disableZoomInButton()));
390 connect(this, SIGNAL(minZoomLevelReached()),
391 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
393 connect(m_mapView, SIGNAL(viewResized(QSize)),
394 m_zoomButtonPanel, SLOT(screenResized(QSize)));
398 void MainWindow::clearCookieJar()
400 qDebug() << __PRETTY_FUNCTION__;
407 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
409 QList<QNetworkCookie> emptyList;
412 m_cookieJar->setAllCookies(emptyList);
413 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
416 void MainWindow::createMenus()
418 qDebug() << __PRETTY_FUNCTION__;
421 m_loginAct = new QAction(tr("Login"), this);
422 connect(m_loginAct, SIGNAL(triggered()),
423 this, SIGNAL(loginActionPressed()));
426 m_toSettingsAct = new QAction(tr("Settings"), this);
427 connect(m_toSettingsAct, SIGNAL(triggered()),
428 this, SLOT(openSettingsDialog()));
431 m_gpsToggleAct = new QAction(tr("GPS"), this);
432 m_gpsToggleAct->setCheckable(true);
434 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
435 this, SIGNAL(gpsTriggered(bool)));
437 /// @todo remove when not needed!
438 m_searchLocationAct = new QAction(tr("Location search"), this);
439 connect(m_searchLocationAct, SIGNAL(triggered()),
440 this, SLOT(startLocationSearch()));
442 // build the actual menu
443 m_viewMenu = menuBar()->addMenu(tr("Main"));
444 m_viewMenu->addAction(m_loginAct);
445 m_viewMenu->addAction(m_toSettingsAct);
446 m_viewMenu->addAction(m_gpsToggleAct);
447 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
448 m_viewMenu->setObjectName(tr("Menu"));
451 void MainWindow::dialogFinished(int status)
453 qDebug() << __PRETTY_FUNCTION__;
455 QDialog *dialog = m_queue.takeFirst();
456 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
457 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
461 loginDialog->userInput(m_email, m_password);
463 QStringList urlParts;
464 urlParts.append(FACEBOOK_LOGINBASE);
465 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
466 urlParts.append(INTERVAL1);
467 urlParts.append(SITUARE_LOGIN_SUCCESS);
468 urlParts.append(INTERVAL2);
469 urlParts.append(SITUARE_LOGIN_FAILURE);
470 urlParts.append(FACEBOOK_LOGIN_ENDING);
472 emit saveUsername(m_email);
474 m_webView->load(QUrl(urlParts.join(EMPTY)));
475 toggleProgressIndicator(true);
477 emit cancelLoginProcess();
479 } else if(searchDialog) {
481 emit searchForLocation(searchDialog->input());
485 dialog->deleteLater();
487 if(!m_error_queue.isEmpty() && m_errorShown == false) {
488 showErrorInformationBox();
490 if(!m_queue.isEmpty()) {
491 showInformationBox();
496 void MainWindow::drawFullScreenButton(const QSize &size)
498 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
500 if(m_fullScreenButton) {
502 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
504 size.height() - m_fullScreenButton->size().height());
506 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
507 size.height() - m_fullScreenButton->size().height());
512 void MainWindow::drawMapScale(const QSize &size)
514 qDebug() << __PRETTY_FUNCTION__;
516 const int LEFT_SCALE_MARGIN = 10;
517 const int BOTTOM_SCALE_MARGIN = 2;
518 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
520 m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
521 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
524 void MainWindow::drawOsmLicense(const QSize &size)
526 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
528 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
530 size.height() - m_osmLicense->fontMetrics().height());
533 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
535 qDebug() << __PRETTY_FUNCTION__;
537 if (m_ownLocationCrosshair != 0) {
538 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
539 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
543 void MainWindow::errorDialogFinished(int status)
545 qDebug() << __PRETTY_FUNCTION__;
548 QDialog *dialog = m_error_queue.takeFirst();
550 dialog->deleteLater();
551 m_errorShown = false;
553 if(!m_error_queue.isEmpty())
554 showErrorInformationBox();
555 else if(!m_queue.isEmpty())
556 showInformationBox();
559 void MainWindow::gpsTimeout()
561 qDebug() << __PRETTY_FUNCTION__;
563 buildInformationBox(tr("GPS timeout"));
566 void MainWindow::grabZoomKeys(bool grab)
568 qDebug() << __PRETTY_FUNCTION__;
571 // Can't grab keys unless we have a window id
575 unsigned long val = (grab) ? 1 : 0;
576 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
580 XChangeProperty (QX11Info::display(),
586 reinterpret_cast<unsigned char *>(&val),
590 #endif // Q_WS_MAEMO_5
593 void MainWindow::keyPressEvent(QKeyEvent* event)
595 qDebug() << __PRETTY_FUNCTION__;
597 switch (event->key()) {
608 QWidget::keyPressEvent(event);
611 void MainWindow::loadCookies()
613 qDebug() << __PRETTY_FUNCTION__;
615 QSettings settings(DIRECTORY_NAME, FILE_NAME);
617 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
619 if(!list.isEmpty()) {
620 QList<QNetworkCookie> cookieList;
621 for(int i=0;i<list.count();i++) {
622 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
626 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
628 m_cookieJar->setAllCookies(cookieList);
629 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
633 void MainWindow::loadDone(bool done)
635 qDebug() << __PRETTY_FUNCTION__;
637 // for the first time the login page is opened, we need to refresh it to get cookies working
645 QWebFrame* frame = m_webView->page()->currentFrame();
649 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
651 foreach (QWebElement element, emailCollection) {
652 element.setAttribute("value", m_email.toAscii());
655 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
656 foreach (QWebElement element, passwordCollection) {
657 element.setAttribute("value", m_password.toAscii());
659 // find connect button
660 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
661 foreach (QWebElement element, buttonCollection)
663 QPoint pos(element.geometry().center());
665 // send a mouse click event to the web page
666 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
668 QApplication::sendEvent(m_webView->page(), &event0);
669 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
671 QApplication::sendEvent(m_webView->page(), &event1);
677 void MainWindow::loggedIn(bool logged)
679 qDebug() << __PRETTY_FUNCTION__;
684 m_loginAct->setText(tr("Logout"));
690 m_loginAct->setText(tr("Login"));
692 updateItemVisibility();
695 void MainWindow::loginFailed()
697 qDebug() << __PRETTY_FUNCTION__;
703 bool MainWindow::loginState()
705 qDebug() << __PRETTY_FUNCTION__;
710 void MainWindow::loginUsingCookies()
712 qDebug() << __PRETTY_FUNCTION__;
714 toggleProgressIndicator(true);
719 QStringList urlParts;
720 urlParts.append(FACEBOOK_LOGINBASE);
721 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
722 urlParts.append(INTERVAL1);
723 urlParts.append(SITUARE_LOGIN_SUCCESS);
724 urlParts.append(INTERVAL2);
725 urlParts.append(SITUARE_LOGIN_FAILURE);
726 urlParts.append(FACEBOOK_LOGIN_ENDING);
728 m_webView->load(QUrl(urlParts.join(EMPTY)));
732 void MainWindow::openSettingsDialog()
734 qDebug() << __PRETTY_FUNCTION__;
736 SettingsDialog *settingsDialog = new SettingsDialog(this);
737 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
738 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
740 settingsDialog->show();
743 void MainWindow::readAutomaticLocationUpdateSettings()
745 qDebug() << __PRETTY_FUNCTION__;
747 QSettings settings(DIRECTORY_NAME, FILE_NAME);
748 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
749 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
752 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
754 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
756 emit enableAutomaticLocationUpdate(false);
760 void MainWindow::queueDialog(QDialog *dialog)
762 qDebug() << __PRETTY_FUNCTION__;
764 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
765 if(dialog->isModal()) {
766 m_error_queue.append(dialog);
768 m_queue.append(dialog);
771 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
772 if(m_error_queue.count() == 1 && m_errorShown == false)
773 showErrorInformationBox();
774 else if(m_queue.count() == 1 && m_errorShown == false)
775 showInformationBox();
778 void MainWindow::saveCookies()
780 qDebug() << __PRETTY_FUNCTION__;
783 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
785 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
788 for(int i=0;i<cookieList.count();i++) {
789 QNetworkCookie cookie = cookieList.at(i);
790 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
791 list.append(QString(byteArray));
793 list.removeDuplicates();
795 QSettings settings(DIRECTORY_NAME, FILE_NAME);
796 settings.setValue(COOKIES, list);
799 void MainWindow::setGPSButtonEnabled(bool enabled)
801 qDebug() << __PRETTY_FUNCTION__;
803 m_gpsToggleAct->setChecked(enabled);
806 void MainWindow::setIndicatorButtonEnabled(bool enabled)
808 qDebug() << __PRETTY_FUNCTION__;
810 m_indicatorButton->setChecked(enabled);
814 void MainWindow::setMapViewScene(QGraphicsScene *scene)
816 qDebug() << __PRETTY_FUNCTION__;
818 m_mapView->setScene(scene);
821 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
823 qDebug() << __PRETTY_FUNCTION__;
826 m_ownLocationCrosshair->show();
827 drawOwnLocationCrosshair(m_viewPortSize);
829 m_ownLocationCrosshair->hide();
833 void MainWindow::settingsDialogAccepted()
835 qDebug() << __PRETTY_FUNCTION__;
837 readAutomaticLocationUpdateSettings();
840 void MainWindow::setUsername(const QString &username)
842 qDebug() << __PRETTY_FUNCTION__;
847 void MainWindow::setViewPortSize(const QSize &size)
849 qDebug() << __PRETTY_FUNCTION__;
851 m_viewPortSize = size;
854 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
856 qDebug() << __PRETTY_FUNCTION__;
858 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
859 tr("Automatic location update"), text,
860 QMessageBox::Yes | QMessageBox::No |
861 QMessageBox::Cancel, this);
862 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
863 this, SLOT(automaticUpdateDialogFinished(int)));
865 m_automaticUpdateLocationDialog->show();
868 void MainWindow::toggleFullScreen()
870 qDebug() << __PRETTY_FUNCTION__;
872 if(windowState() == Qt::WindowNoState)
878 void MainWindow::showErrorInformationBox()
880 qDebug() << __PRETTY_FUNCTION__;
882 if(m_error_queue.count()) {
884 QDialog *dialog = m_error_queue.first();
885 connect(dialog, SIGNAL(finished(int)),
886 this, SLOT(errorDialogFinished(int)));
891 void MainWindow::showInformationBox()
893 qDebug() << __PRETTY_FUNCTION__;
895 if(m_queue.count()) {
896 QDialog *dialog = m_queue.first();
897 connect(dialog, SIGNAL(finished(int)),
898 this, SLOT(dialogFinished(int)));
903 void MainWindow::showPanels()
905 qDebug() << __PRETTY_FUNCTION__;
907 drawFullScreenButton(m_viewPortSize);
910 if(!m_friendsListPanel->isVisible()) {
911 m_friendsListPanel->show();
912 m_friendsListPanelSidebar->show();
915 if(!m_userPanel->isVisible()) {
917 m_userPanelSidebar->show();
922 void MainWindow::startLocationSearch()
924 qDebug() << __PRETTY_FUNCTION__;
926 SearchDialog *searchDialog = new SearchDialog();
927 queueDialog(searchDialog);
930 void MainWindow::startLoginProcess()
932 qDebug() << __PRETTY_FUNCTION__;
934 LoginDialog *loginDialog = new LoginDialog();
936 emit fetchUsernameFromSettings();
938 loginDialog->clearTextFields();
940 if(!m_email.isEmpty())
941 loginDialog->setEmailField(m_email);
943 queueDialog(loginDialog);
946 void MainWindow::toggleProgressIndicator(bool value)
948 qDebug() << __PRETTY_FUNCTION__;
952 m_progressIndicatorCount++;
953 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
955 if(m_progressIndicatorCount > 0)
956 m_progressIndicatorCount--;
958 if(m_progressIndicatorCount == 0)
959 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
963 #endif // Q_WS_MAEMO_5
966 void MainWindow::updateItemVisibility()
968 qDebug() << __PRETTY_FUNCTION__;
971 m_friendsListPanel->closePanel();
972 m_friendsListPanel->hide();
973 m_friendsListPanelSidebar->hide();
974 m_userPanel->closePanel();
976 m_userPanelSidebar->hide();
980 const QString MainWindow::username()
982 qDebug() << __PRETTY_FUNCTION__;
987 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
989 qDebug() << __PRETTY_FUNCTION__;
991 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
992 // qwebview starts to load a new page while the current page loading is not finished
993 if(reply->error() != QNetworkReply::OperationCanceledError &&
994 reply->error() != QNetworkReply::NoError) {
995 emit error(ErrorContext::NETWORK, reply->error());