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 "settingsdialog.h"
40 #include "userinfopanel.h"
41 #include "zoombuttonpanel.h"
43 #include "mainwindow.h"
45 // These MUST BE HERE, compiling for Maemo fails if moved
47 #include <QtMaemo5/QMaemo5InformationBox>
48 #include <QtGui/QX11Info>
49 #include <X11/Xatom.h>
51 #endif // Q_WS_MAEMO_5
53 MainWindow::MainWindow(QWidget *parent)
54 : QMainWindow(parent),
55 m_drawOwnLocationCrosshair(false),
59 m_progressIndicatorCount(0),
60 m_ownLocationCrosshair(0),
63 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);
104 // Set default screen size
105 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
107 setAttribute(Qt::WA_Maemo5StackedWindow);
111 MainWindow::~MainWindow()
113 qDebug() << __PRETTY_FUNCTION__;
120 qDeleteAll(m_queue.begin(), m_queue.end());
123 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
124 m_error_queue.clear();
127 void MainWindow::automaticUpdateDialogFinished(int result)
129 qDebug() << __PRETTY_FUNCTION__;
131 if (result == QMessageBox::Yes) {
132 readAutomaticLocationUpdateSettings();
134 QSettings settings(DIRECTORY_NAME, FILE_NAME);
135 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
136 readAutomaticLocationUpdateSettings();
139 m_automaticUpdateLocationDialog->deleteLater();
142 void MainWindow::buildFullScreenButton()
144 qDebug() << __PRETTY_FUNCTION__;
146 m_fullScreenButton = new FullScreenButton(this);
147 connect(m_fullScreenButton, SIGNAL(clicked()),
148 this, SLOT(toggleFullScreen()));
149 #endif // Q_WS_MAEMO_5
152 void MainWindow::buildFriendListPanel()
154 qDebug() << __PRETTY_FUNCTION__;
156 m_friendsListPanel = new FriendListPanel(this);
158 m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
160 m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
162 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
163 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
165 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
166 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
168 connect(m_mapView, SIGNAL(viewResized(QSize)),
169 m_friendsListPanel, SLOT(resizePanel(QSize)));
171 connect(m_mapView, SIGNAL(viewResized(QSize)),
172 m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
174 connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
175 this, SIGNAL(findFriend(QPointF)));
178 void MainWindow::buildIndicatorButton()
180 qDebug() << __PRETTY_FUNCTION__;
182 m_indicatorButton = new IndicatorButton(this);
184 connect(m_indicatorButton, SIGNAL(triggered(bool)),
185 this, SIGNAL(autoCenteringTriggered(bool)));
189 void MainWindow::buildInformationBox(const QString &message, bool modal)
191 qDebug() << __PRETTY_FUNCTION__;
193 QString errorMessage = message;
197 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
200 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
201 // extra line changes are needed to make error notes broader
202 errorMessage.prepend("\n");
203 errorMessage.append("\n");
205 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
207 QLabel *label = new QLabel(msgBox);
208 label->setAlignment(Qt::AlignCenter);
209 label->setText(errorMessage);
210 msgBox->setWidget(label);
212 QMessageBox *msgBox = new QMessageBox(this);
213 msgBox->button(QMessageBox::Ok);
214 msgBox->setText(errorMessage);
215 msgBox->setModal(modal);
221 void MainWindow::buildManualLocationCrosshair()
223 qDebug() << __PRETTY_FUNCTION__;
225 m_ownLocationCrosshair = new QLabel(this);
226 QPixmap crosshairImage(":/res/images/sight.png");
227 m_ownLocationCrosshair->setPixmap(crosshairImage);
228 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
229 m_ownLocationCrosshair->hide();
230 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
232 connect(m_mapView, SIGNAL(viewResized(QSize)),
233 this, SLOT(drawOwnLocationCrosshair(QSize)));
236 void MainWindow::buildMap()
238 qDebug() << __PRETTY_FUNCTION__;
240 m_mapView = new MapView(this);
242 buildZoomButtonPanel();
244 buildManualLocationCrosshair();
245 buildFullScreenButton();
246 buildIndicatorButton();
249 connect(m_mapView, SIGNAL(viewScrolled(QPoint)),
250 this, SIGNAL(mapViewScrolled(QPoint)));
252 connect(this, SIGNAL(centerToSceneCoordinates(QPoint)),
253 m_mapView, SLOT(centerToSceneCoordinates(QPoint)));
255 connect(m_mapView, SIGNAL(viewResized(QSize)),
256 this, SIGNAL(mapViewResized(QSize)));
258 connect(m_mapView, SIGNAL(viewResized(QSize)),
259 this, SLOT(drawFullScreenButton(QSize)));
261 connect(m_mapView, SIGNAL(viewResized(QSize)),
262 this, SLOT(drawMapScale(QSize)));
264 connect(m_mapView, SIGNAL(viewResized(QSize)),
265 this, SLOT(setViewPortSize(QSize)));
267 connect(this, SIGNAL(zoomLevelChanged(int)),
268 m_mapView, SLOT(setZoomLevel(int)));
270 connect(m_mapView, SIGNAL(viewZoomFinished()),
271 this, SIGNAL(viewZoomFinished()));
273 connect(m_mapView, SIGNAL(zoomIn()),
274 this, SIGNAL(zoomIn()));
277 void MainWindow::buildMapScale()
279 m_mapScale = new MapScale(this);
280 connect(this, SIGNAL(newMapResolution(qreal)),
281 m_mapScale, SLOT(updateMapResolution(qreal)));
284 void MainWindow::buildOsmLicense()
286 qDebug() << __PRETTY_FUNCTION__;
288 m_osmLicense = new QLabel(this);
289 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
290 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
291 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
292 m_osmLicense->setFont(QFont("Nokia Sans", 9));
293 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
294 m_osmLicense->fontMetrics().height());
296 connect(m_mapView, SIGNAL(viewResized(QSize)),
297 this, SLOT(drawOsmLicense(QSize)));
300 void MainWindow::buildUserInfoPanel()
302 qDebug() << __PRETTY_FUNCTION__;
304 m_userPanel = new UserInfoPanel(this);
306 m_userPanelSidebar = new PanelSideBar(this, LEFT);
308 m_userPanelSidebar->stackUnder(m_friendsListPanel);
309 m_userPanel->stackUnder(m_userPanelSidebar);
311 connect(this, SIGNAL(userLocationReady(User*)),
312 m_userPanel, SLOT(userDataReceived(User*)));
314 connect(this, SIGNAL(reverseGeoReady(QString)),
315 m_userPanel, SIGNAL(reverseGeoReady(QString)));
317 connect(this, SIGNAL(clearUpdateLocationDialogData()),
318 m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
320 connect(m_mapView, SIGNAL(viewResized(QSize)),
321 m_userPanel, SLOT(resizePanel(QSize)));
323 connect(m_mapView, SIGNAL(viewResized(QSize)),
324 m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
326 connect(m_userPanel, SIGNAL(findUser(QPointF)),
327 this, SIGNAL(findUser(QPointF)));
329 connect(m_userPanel, SIGNAL(requestReverseGeo()),
330 this, SIGNAL(requestReverseGeo()));
332 connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
333 this, SIGNAL(statusUpdate(QString,bool)));
335 connect(m_userPanel, SIGNAL(refreshUserData()),
336 this, SIGNAL(refreshUserData()));
338 connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
339 this, SLOT(buildInformationBox(QString, bool)));
342 void MainWindow::buildWebView()
344 qDebug() << __PRETTY_FUNCTION__;
347 m_webView = new QWebView;
350 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
352 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
354 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
355 this, SLOT(webViewRequestFinished(QNetworkReply*)));
356 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
357 this, SIGNAL(updateCredentials(QUrl)));
358 connect(m_webView, SIGNAL(loadFinished(bool)),
359 this, SLOT(loadDone(bool)));
365 void MainWindow::buildZoomButtonPanel()
367 qDebug() << __PRETTY_FUNCTION__;
369 m_zoomButtonPanel = new ZoomButtonPanel(this);
371 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
372 this, SIGNAL(zoomIn()));
374 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
375 this, SIGNAL(zoomOut()));
377 connect(this, SIGNAL(zoomLevelChanged(int)),
378 m_zoomButtonPanel, SLOT(resetButtons()));
380 connect(this, SIGNAL(maxZoomLevelReached()),
381 m_zoomButtonPanel, SLOT(disableZoomInButton()));
383 connect(this, SIGNAL(minZoomLevelReached()),
384 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
386 connect(m_mapView, SIGNAL(viewResized(QSize)),
387 m_zoomButtonPanel, SLOT(screenResized(QSize)));
390 void MainWindow::clearCookieJar()
392 qDebug() << __PRETTY_FUNCTION__;
399 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
401 QList<QNetworkCookie> emptyList;
404 m_cookieJar->setAllCookies(emptyList);
405 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
408 void MainWindow::createMenus()
410 qDebug() << __PRETTY_FUNCTION__;
413 m_loginAct = new QAction(tr("Login"), this);
414 connect(m_loginAct, SIGNAL(triggered()),
415 this, SIGNAL(loginActionPressed()));
418 m_toSettingsAct = new QAction(tr("Settings"), this);
419 connect(m_toSettingsAct, SIGNAL(triggered()),
420 this, SLOT(openSettingsDialog()));
423 m_gpsToggleAct = new QAction(tr("GPS"), this);
424 m_gpsToggleAct->setCheckable(true);
426 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
427 this, SIGNAL(gpsTriggered(bool)));
429 // automatic centering
430 // m_autoCenteringAct = new QAction(tr("Auto centering"), this);
431 // m_autoCenteringAct->setCheckable(true);
432 // connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
433 // this, SIGNAL(autoCenteringTriggered(bool)));
435 // build the actual menu
436 m_viewMenu = menuBar()->addMenu(tr("Main"));
437 m_viewMenu->addAction(m_loginAct);
438 m_viewMenu->addAction(m_toSettingsAct);
439 m_viewMenu->addAction(m_gpsToggleAct);
440 // m_viewMenu->addAction(m_autoCenteringAct);
441 m_viewMenu->setObjectName(tr("Menu"));
444 void MainWindow::dialogFinished(int status)
446 qDebug() << __PRETTY_FUNCTION__;
448 QDialog *dialog = m_queue.takeFirst();
449 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
453 loginDialog->userInput(m_email, m_password);
455 QStringList urlParts;
456 urlParts.append(FACEBOOK_LOGINBASE);
457 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
458 urlParts.append(INTERVAL1);
459 urlParts.append(SITUARE_LOGIN_SUCCESS);
460 urlParts.append(INTERVAL2);
461 urlParts.append(SITUARE_LOGIN_FAILURE);
462 urlParts.append(FACEBOOK_LOGIN_ENDING);
464 emit saveUsername(m_email);
466 m_webView->load(QUrl(urlParts.join(EMPTY)));
467 toggleProgressIndicator(true);
469 emit cancelLoginProcess();
473 dialog->deleteLater();
475 if(!m_error_queue.isEmpty() && m_errorShown == false) {
476 showErrorInformationBox();
478 if(!m_queue.isEmpty()) {
479 showInformationBox();
484 void MainWindow::drawFullScreenButton(const QSize &size)
486 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
488 if(m_fullScreenButton) {
490 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
492 size.height() - m_fullScreenButton->size().height());
494 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
495 size.height() - m_fullScreenButton->size().height());
500 void MainWindow::drawIndicatorButton(const QSize &size)
502 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
504 const int LEFT_SCALE_MARGIN = 10;
505 const int BOTTOM_SCALE_MARGIN = 80;
507 if(m_indicatorButton) {
509 m_indicatorButton->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
510 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
513 m_indicatorButton->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
514 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
519 void MainWindow::drawMapScale(const QSize &size)
521 const int LEFT_SCALE_MARGIN = 10;
522 const int BOTTOM_SCALE_MARGIN = 2;
523 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
525 m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
526 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
529 void MainWindow::drawOsmLicense(const QSize &size)
531 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
533 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
535 size.height() - m_osmLicense->fontMetrics().height());
538 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
540 qDebug() << __PRETTY_FUNCTION__;
542 if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
543 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
544 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
548 void MainWindow::errorDialogFinished(int status)
550 qDebug() << __PRETTY_FUNCTION__;
553 QDialog *dialog = m_error_queue.takeFirst();
555 dialog->deleteLater();
556 m_errorShown = false;
558 if(!m_error_queue.isEmpty())
559 showErrorInformationBox();
560 else if(!m_queue.isEmpty())
561 showInformationBox();
564 void MainWindow::gpsTimeout()
566 qDebug() << __PRETTY_FUNCTION__;
568 buildInformationBox(tr("GPS timeout"));
571 void MainWindow::grabZoomKeys(bool grab)
573 qDebug() << __PRETTY_FUNCTION__;
576 // Can't grab keys unless we have a window id
580 unsigned long val = (grab) ? 1 : 0;
581 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
585 XChangeProperty (QX11Info::display(),
591 reinterpret_cast<unsigned char *>(&val),
595 #endif // Q_WS_MAEMO_5
598 void MainWindow::keyPressEvent(QKeyEvent* event)
600 qDebug() << __PRETTY_FUNCTION__;
602 switch (event->key()) {
613 QWidget::keyPressEvent(event);
616 void MainWindow::loadCookies()
618 qDebug() << __PRETTY_FUNCTION__;
620 QSettings settings(DIRECTORY_NAME, FILE_NAME);
622 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
624 if(!list.isEmpty()) {
625 QList<QNetworkCookie> cookieList;
626 for(int i=0;i<list.count();i++) {
627 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
631 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
633 m_cookieJar->setAllCookies(cookieList);
634 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
639 void MainWindow::loadDone(bool done)
641 qDebug() << __PRETTY_FUNCTION__;
643 // for the first time the login page is opened, we need to refresh it to get cookies working
651 QWebFrame* frame = m_webView->page()->currentFrame();
655 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
657 foreach (QWebElement element, emailCollection) {
658 element.setAttribute("value", m_email.toAscii());
661 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
662 foreach (QWebElement element, passwordCollection) {
663 element.setAttribute("value", m_password.toAscii());
665 // find connect button
666 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
667 foreach (QWebElement element, buttonCollection)
669 QPoint pos(element.geometry().center());
671 // send a mouse click event to the web page
672 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
674 QApplication::sendEvent(m_webView->page(), &event0);
675 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
677 QApplication::sendEvent(m_webView->page(), &event1);
683 void MainWindow::loggedIn(bool logged)
685 qDebug() << __PRETTY_FUNCTION__;
690 m_loginAct->setText(tr("Logout"));
696 m_loginAct->setText(tr("Login"));
698 updateItemVisibility();
701 void MainWindow::loginFailed()
703 qDebug() << __PRETTY_FUNCTION__;
709 bool MainWindow::loginState()
711 qDebug() << __PRETTY_FUNCTION__;
716 void MainWindow::loginUsingCookies()
718 qDebug() << __PRETTY_FUNCTION__;
720 toggleProgressIndicator(true);
725 QStringList urlParts;
726 urlParts.append(FACEBOOK_LOGINBASE);
727 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
728 urlParts.append(INTERVAL1);
729 urlParts.append(SITUARE_LOGIN_SUCCESS);
730 urlParts.append(INTERVAL2);
731 urlParts.append(SITUARE_LOGIN_FAILURE);
732 urlParts.append(FACEBOOK_LOGIN_ENDING);
734 m_webView->load(QUrl(urlParts.join(EMPTY)));
738 void MainWindow::openSettingsDialog()
740 qDebug() << __PRETTY_FUNCTION__;
742 SettingsDialog *settingsDialog = new SettingsDialog(this);
743 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
744 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
746 settingsDialog->show();
749 void MainWindow::readAutomaticLocationUpdateSettings()
751 qDebug() << __PRETTY_FUNCTION__;
753 QSettings settings(DIRECTORY_NAME, FILE_NAME);
754 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
755 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
758 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
760 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
762 emit enableAutomaticLocationUpdate(false);
766 void MainWindow::queueDialog(QDialog *dialog)
768 qDebug() << __PRETTY_FUNCTION__;
770 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
771 if(dialog->isModal()) {
772 m_error_queue.append(dialog);
774 m_queue.append(dialog);
777 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
778 if(m_error_queue.count() == 1 && m_errorShown == false)
779 showErrorInformationBox();
780 else if(m_queue.count() == 1 && m_errorShown == false)
781 showInformationBox();
784 void MainWindow::saveCookies()
786 qDebug() << __PRETTY_FUNCTION__;
789 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
791 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
794 for(int i=0;i<cookieList.count();i++) {
795 QNetworkCookie cookie = cookieList.at(i);
796 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
797 list.append(QString(byteArray));
799 list.removeDuplicates();
801 QSettings settings(DIRECTORY_NAME, FILE_NAME);
802 settings.setValue(COOKIES, list);
805 //void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
807 // qDebug() << __PRETTY_FUNCTION__;
809 // m_autoCenteringAct->setChecked(enabled);
812 void MainWindow::setGPSButtonEnabled(bool enabled)
814 qDebug() << __PRETTY_FUNCTION__;
816 m_gpsToggleAct->setChecked(enabled);
818 setOwnLocationCrosshairVisibility(!enabled);
820 // m_autoCenteringAct->setVisible(enabled);
823 void MainWindow::setIndicatorButtonEnabled(bool enabled)
825 qDebug() << __PRETTY_FUNCTION__;
827 m_indicatorButton->setChecked(enabled);
829 connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
830 this, SIGNAL(autoCenteringTriggered(bool)));
833 void MainWindow::setMapViewScene(QGraphicsScene *scene)
835 qDebug() << __PRETTY_FUNCTION__;
837 m_mapView->setScene(scene);
840 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
842 qDebug() << __PRETTY_FUNCTION__;
844 if (visibility && m_loggedIn) {
845 m_ownLocationCrosshair->show();
846 m_drawOwnLocationCrosshair = true;
847 drawOwnLocationCrosshair(m_viewPortSize);
849 m_ownLocationCrosshair->hide();
850 m_drawOwnLocationCrosshair = false;
854 void MainWindow::settingsDialogAccepted()
856 qDebug() << __PRETTY_FUNCTION__;
858 readAutomaticLocationUpdateSettings();
861 void MainWindow::setUsername(const QString &username)
863 qDebug() << __PRETTY_FUNCTION__;
868 void MainWindow::setViewPortSize(const QSize &size)
870 qDebug() << __PRETTY_FUNCTION__;
872 m_viewPortSize = size;
875 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
877 qDebug() << __PRETTY_FUNCTION__;
879 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
880 tr("Automatic location update"), text,
881 QMessageBox::Yes | QMessageBox::No |
882 QMessageBox::Cancel, this);
883 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
884 this, SLOT(automaticUpdateDialogFinished(int)));
886 m_automaticUpdateLocationDialog->show();
889 void MainWindow::toggleFullScreen()
891 qDebug() << __PRETTY_FUNCTION__;
893 if(windowState() == Qt::WindowNoState)
899 void MainWindow::showErrorInformationBox()
901 qDebug() << __PRETTY_FUNCTION__;
903 if(m_error_queue.count()) {
905 QDialog *dialog = m_error_queue.first();
906 connect(dialog, SIGNAL(finished(int)),
907 this, SLOT(errorDialogFinished(int)));
912 void MainWindow::showInformationBox()
914 qDebug() << __PRETTY_FUNCTION__;
916 if(m_queue.count()) {
917 QDialog *dialog = m_queue.first();
918 connect(dialog, SIGNAL(finished(int)),
919 this, SLOT(dialogFinished(int)));
924 void MainWindow::showPanels()
926 qDebug() << __PRETTY_FUNCTION__;
928 drawFullScreenButton(m_viewPortSize);
929 drawIndicatorButton(m_viewPortSize);
932 if(!m_friendsListPanel->isVisible()) {
933 m_friendsListPanel->show();
934 m_friendsListPanelSidebar->show();
935 m_indicatorButton->show();
938 if(!m_userPanel->isVisible()) {
940 m_userPanelSidebar->show();
945 //void MainWindow::showIndicatorButton(bool gps, bool autoCentering)
947 // qDebug() << __PRETTY_FUNCTION__;
951 void MainWindow::startLoginProcess()
953 qDebug() << __PRETTY_FUNCTION__;
955 LoginDialog *loginDialog = new LoginDialog();
957 emit fetchUsernameFromSettings();
959 loginDialog->clearTextFields();
961 if(!m_email.isEmpty())
962 loginDialog->setEmailField(m_email);
964 queueDialog(loginDialog);
967 void MainWindow::toggleProgressIndicator(bool value)
969 qDebug() << __PRETTY_FUNCTION__;
973 m_progressIndicatorCount++;
974 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
976 if(m_progressIndicatorCount > 0)
977 m_progressIndicatorCount--;
979 if(m_progressIndicatorCount == 0)
980 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
984 #endif // Q_WS_MAEMO_5
987 void MainWindow::updateItemVisibility()
989 qDebug() << __PRETTY_FUNCTION__;
993 if(!m_gpsToggleAct->isChecked())
994 setOwnLocationCrosshairVisibility(true);
996 m_friendsListPanel->closePanel();
997 m_friendsListPanel->hide();
998 m_friendsListPanelSidebar->hide();
999 m_userPanel->closePanel();
1000 m_userPanel->hide();
1001 m_userPanelSidebar->hide();
1002 setOwnLocationCrosshairVisibility(false);
1006 const QString MainWindow::username()
1008 qDebug() << __PRETTY_FUNCTION__;
1013 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1015 qDebug() << __PRETTY_FUNCTION__;
1017 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1018 // qwebview starts to load a new page while the current page loading is not finished
1019 if(reply->error() != QNetworkReply::OperationCanceledError &&
1020 reply->error() != QNetworkReply::NoError) {
1021 emit error(ErrorContext::NETWORK, reply->error());