2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Henri Lampela - henri.lampela@ixonos.com
6 Kaj Wallin - kaj.wallin@ixonos.com
7 Jussi Laitinen - jussi.laitinen@ixonos.com
8 Sami Rämö - sami.ramo@ixonos.com
9 Ville Tiensuu - ville.tiensuu@ixonos.com
10 Katri Kaikkonen - katri.kaikkonen@ixonos.com
12 Situare is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 version 2 as published by the Free Software Foundation.
16 Situare is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with Situare; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
29 #include <QtAlgorithms>
31 #include "facebookservice/facebookauthentication.h"
32 #include "map/mapcommon.h"
33 #include "map/mapview.h"
36 #include "friendlistpanel.h"
37 #include "fullscreenbutton.h"
38 #include "indicatorbuttonpanel.h"
39 #include "logindialog.h"
41 #include "panelcommon.h"
42 #include "tabbedpanel.h"
43 #include "searchdialog.h"
44 #include "settingsdialog.h"
45 #include "userinfopanel.h"
46 #include "zoombuttonpanel.h"
48 #include "mainwindow.h"
50 // These MUST BE HERE, compiling for Maemo fails if moved
52 #include <QtMaemo5/QMaemo5InformationBox>
53 #include <QtGui/QX11Info>
54 #include <X11/Xatom.h>
56 #endif // Q_WS_MAEMO_5
58 MainWindow::MainWindow(QWidget *parent)
59 : QMainWindow(parent),
63 m_progressIndicatorCount(0),
64 m_ownLocationCrosshair(0),
68 m_fullScreenButton(0),
69 m_indicatorButtonPanel(0),
73 qDebug() << __PRETTY_FUNCTION__;
78 QHBoxLayout *layout = new QHBoxLayout;
79 layout->addWidget(m_mapView);
81 layout->setSpacing(0);
83 setCentralWidget(new QWidget());
84 centralWidget()->setLayout(layout);
89 setWindowTitle(tr("Situare"));
91 // set stacking order of widgets
92 m_zoomButtonPanel->stackUnder(m_tabbedPanel);
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__;
149 m_fullScreenButton = new FullScreenButton(this);
151 if (m_fullScreenButton) {
152 connect(m_fullScreenButton, SIGNAL(clicked()),
153 this, SLOT(toggleFullScreen()));
155 connect(qApp, SIGNAL(showFullScreenButton()),
156 m_fullScreenButton, SLOT(invoke()));
158 #endif // Q_WS_MAEMO_5
161 void MainWindow::buildFriendListPanel()
163 qDebug() << __PRETTY_FUNCTION__;
165 m_friendsListPanel = new FriendListPanel(this);
167 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
168 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
170 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
171 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
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::buildIndicatorButtonPanel()
182 qDebug() << __PRETTY_FUNCTION__;
184 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
186 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
187 this, SIGNAL(autoCenteringTriggered(bool)));
189 connect(m_mapView, SIGNAL(viewResized(QSize)),
190 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
192 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
193 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
195 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
196 this, SIGNAL(draggingModeTriggered()));
199 void MainWindow::buildInformationBox(const QString &message, bool modal)
201 qDebug() << __PRETTY_FUNCTION__;
203 QString errorMessage = message;
207 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
210 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
211 // extra line changes are needed to make error notes broader
212 errorMessage.prepend("\n");
213 errorMessage.append("\n");
215 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
217 QLabel *label = new QLabel(msgBox);
218 label->setAlignment(Qt::AlignCenter);
219 label->setText(errorMessage);
220 msgBox->setWidget(label);
222 QMessageBox *msgBox = new QMessageBox(this);
223 msgBox->button(QMessageBox::Ok);
224 msgBox->setText(errorMessage);
225 msgBox->setModal(modal);
231 void MainWindow::buildManualLocationCrosshair()
233 qDebug() << __PRETTY_FUNCTION__;
235 m_ownLocationCrosshair = new QLabel(this);
236 QPixmap crosshairImage(":/res/images/sight.png");
237 m_ownLocationCrosshair->setPixmap(crosshairImage);
238 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
239 m_ownLocationCrosshair->hide();
240 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
242 connect(m_mapView, SIGNAL(viewResized(QSize)),
243 this, SLOT(drawOwnLocationCrosshair(QSize)));
246 void MainWindow::buildMap()
248 qDebug() << __PRETTY_FUNCTION__;
250 m_mapView = new MapView(this);
252 buildZoomButtonPanel();
254 buildManualLocationCrosshair();
255 buildFullScreenButton();
256 buildIndicatorButtonPanel();
259 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
260 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
262 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
263 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
265 connect(m_mapView, SIGNAL(viewResized(QSize)),
266 this, SIGNAL(mapViewResized(QSize)));
268 connect(m_mapView, SIGNAL(viewResized(QSize)),
269 this, SLOT(drawFullScreenButton(QSize)));
271 connect(m_mapView, SIGNAL(viewResized(QSize)),
272 this, SLOT(drawMapScale(QSize)));
274 connect(m_mapView, SIGNAL(viewResized(QSize)),
275 this, SLOT(setViewPortSize(QSize)));
277 connect(this, SIGNAL(zoomLevelChanged(int)),
278 m_mapView, SLOT(setZoomLevel(int)));
280 connect(m_mapView, SIGNAL(viewZoomFinished()),
281 this, SIGNAL(viewZoomFinished()));
283 connect(m_mapView, SIGNAL(zoomIn()),
284 this, SIGNAL(zoomIn()));
287 void MainWindow::buildMapScale()
289 m_mapScale = new MapScale(this);
290 connect(this, SIGNAL(newMapResolution(qreal)),
291 m_mapScale, SLOT(updateMapResolution(qreal)));
294 void MainWindow::buildOsmLicense()
296 qDebug() << __PRETTY_FUNCTION__;
298 m_osmLicense = new QLabel(this);
299 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
300 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
301 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
302 m_osmLicense->setFont(QFont("Nokia Sans", 9));
303 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
304 m_osmLicense->fontMetrics().height());
306 connect(m_mapView, SIGNAL(viewResized(QSize)),
307 this, SLOT(drawOsmLicense(QSize)));
310 void MainWindow::buildPanels()
312 qDebug() << __PRETTY_FUNCTION__;
314 buildUserInfoPanel();
315 buildFriendListPanel();
317 m_tabbedPanel = new TabbedPanel(this);
318 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
319 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
321 connect(m_tabbedPanel, SIGNAL(tabChanged()),
322 m_friendsListPanel, SLOT(clearFriendListFilter()));
324 connect(m_mapView, SIGNAL(viewResized(QSize)),
325 m_tabbedPanel, SLOT(resizePanel(QSize)));
328 void MainWindow::buildUserInfoPanel()
330 qDebug() << __PRETTY_FUNCTION__;
332 m_userInfoPanel = new UserInfoPanel(this);
334 connect(this, SIGNAL(userLocationReady(User*)),
335 m_userInfoPanel, SLOT(userDataReceived(User*)));
337 connect(this, SIGNAL(reverseGeoReady(QString)),
338 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
340 connect(this, SIGNAL(clearUpdateLocationDialogData()),
341 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
343 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
344 this, SIGNAL(findUser(GeoCoordinate)));
346 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
347 this, SIGNAL(requestReverseGeo()));
349 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
350 this, SIGNAL(statusUpdate(QString,bool)));
352 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
353 this, SIGNAL(refreshUserData()));
355 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
356 this, SLOT(buildInformationBox(QString, bool)));
359 void MainWindow::buildWebView()
361 qDebug() << __PRETTY_FUNCTION__;
364 m_webView = new QWebView;
367 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
369 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
371 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
372 this, SLOT(webViewRequestFinished(QNetworkReply*)));
373 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
374 this, SIGNAL(updateCredentials(QUrl)));
375 connect(m_webView, SIGNAL(loadFinished(bool)),
376 this, SLOT(loadDone(bool)));
382 void MainWindow::buildZoomButtonPanel()
384 qDebug() << __PRETTY_FUNCTION__;
386 m_zoomButtonPanel = new ZoomButtonPanel(this);
388 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
389 this, SIGNAL(zoomIn()));
391 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
392 this, SIGNAL(zoomOut()));
394 connect(this, SIGNAL(zoomLevelChanged(int)),
395 m_zoomButtonPanel, SLOT(resetButtons()));
397 connect(this, SIGNAL(maxZoomLevelReached()),
398 m_zoomButtonPanel, SLOT(disableZoomInButton()));
400 connect(this, SIGNAL(minZoomLevelReached()),
401 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
403 connect(m_mapView, SIGNAL(viewResized(QSize)),
404 m_zoomButtonPanel, SLOT(screenResized(QSize)));
406 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
407 this, SIGNAL(draggingModeTriggered()));
410 void MainWindow::clearCookieJar()
412 qDebug() << __PRETTY_FUNCTION__;
419 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
421 QList<QNetworkCookie> emptyList;
424 m_cookieJar->setAllCookies(emptyList);
425 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
428 void MainWindow::createMenus()
430 qDebug() << __PRETTY_FUNCTION__;
433 m_loginAct = new QAction(tr("Login"), this);
434 connect(m_loginAct, SIGNAL(triggered()),
435 this, SIGNAL(loginActionPressed()));
438 m_toSettingsAct = new QAction(tr("Settings"), this);
439 connect(m_toSettingsAct, SIGNAL(triggered()),
440 this, SLOT(openSettingsDialog()));
443 m_gpsToggleAct = new QAction(tr("GPS"), this);
444 m_gpsToggleAct->setCheckable(true);
446 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
447 this, SIGNAL(gpsTriggered(bool)));
449 /// @todo remove when not needed!
450 m_searchLocationAct = new QAction(tr("Location search"), this);
451 connect(m_searchLocationAct, SIGNAL(triggered()),
452 this, SLOT(startLocationSearch()));
454 // build the actual menu
455 m_viewMenu = menuBar()->addMenu(tr("Main"));
456 m_viewMenu->addAction(m_loginAct);
457 m_viewMenu->addAction(m_toSettingsAct);
458 m_viewMenu->addAction(m_gpsToggleAct);
459 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
460 m_viewMenu->setObjectName(tr("Menu"));
463 void MainWindow::dialogFinished(int status)
465 qDebug() << __PRETTY_FUNCTION__;
467 QDialog *dialog = m_queue.takeFirst();
468 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
469 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
473 loginDialog->userInput(m_email, m_password);
475 QStringList urlParts;
476 urlParts.append(FACEBOOK_LOGINBASE);
477 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
478 urlParts.append(INTERVAL1);
479 urlParts.append(SITUARE_LOGIN_SUCCESS);
480 urlParts.append(INTERVAL2);
481 urlParts.append(SITUARE_LOGIN_FAILURE);
482 urlParts.append(FACEBOOK_LOGIN_ENDING);
484 emit saveUsername(m_email);
486 m_webView->load(QUrl(urlParts.join(EMPTY)));
487 toggleProgressIndicator(true);
489 emit cancelLoginProcess();
491 } else if(searchDialog) {
493 emit searchForLocation(searchDialog->input());
497 dialog->deleteLater();
499 if(!m_error_queue.isEmpty() && m_errorShown == false) {
500 showErrorInformationBox();
502 if(!m_queue.isEmpty()) {
503 showInformationBox();
508 void MainWindow::drawFullScreenButton(const QSize &size)
510 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
512 if(m_fullScreenButton)
513 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
514 size.height() - m_fullScreenButton->size().height());
517 void MainWindow::drawMapScale(const QSize &size)
519 qDebug() << __PRETTY_FUNCTION__;
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(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_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);
638 void MainWindow::loadDone(bool done)
640 qDebug() << __PRETTY_FUNCTION__;
642 // for the first time the login page is opened, we need to refresh it to get cookies working
650 QWebFrame* frame = m_webView->page()->currentFrame();
654 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
656 foreach (QWebElement element, emailCollection) {
657 element.setAttribute("value", m_email.toAscii());
660 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
661 foreach (QWebElement element, passwordCollection) {
662 element.setAttribute("value", m_password.toAscii());
664 // find connect button
665 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
666 foreach (QWebElement element, buttonCollection)
668 QPoint pos(element.geometry().center());
670 // send a mouse click event to the web page
671 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
673 QApplication::sendEvent(m_webView->page(), &event0);
674 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
676 QApplication::sendEvent(m_webView->page(), &event1);
682 void MainWindow::loggedIn(bool logged)
684 qDebug() << __PRETTY_FUNCTION__;
689 m_loginAct->setText(tr("Logout"));
695 m_loginAct->setText(tr("Login"));
697 updateItemVisibility();
700 void MainWindow::loginFailed()
702 qDebug() << __PRETTY_FUNCTION__;
708 bool MainWindow::loginState()
710 qDebug() << __PRETTY_FUNCTION__;
715 void MainWindow::loginUsingCookies()
717 qDebug() << __PRETTY_FUNCTION__;
719 toggleProgressIndicator(true);
724 QStringList urlParts;
725 urlParts.append(FACEBOOK_LOGINBASE);
726 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
727 urlParts.append(INTERVAL1);
728 urlParts.append(SITUARE_LOGIN_SUCCESS);
729 urlParts.append(INTERVAL2);
730 urlParts.append(SITUARE_LOGIN_FAILURE);
731 urlParts.append(FACEBOOK_LOGIN_ENDING);
733 m_webView->load(QUrl(urlParts.join(EMPTY)));
737 void MainWindow::openSettingsDialog()
739 qDebug() << __PRETTY_FUNCTION__;
741 SettingsDialog *settingsDialog = new SettingsDialog(this);
742 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
743 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
745 settingsDialog->show();
748 void MainWindow::readAutomaticLocationUpdateSettings()
750 qDebug() << __PRETTY_FUNCTION__;
752 QSettings settings(DIRECTORY_NAME, FILE_NAME);
753 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
754 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
757 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
759 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
761 emit enableAutomaticLocationUpdate(false);
765 void MainWindow::queueDialog(QDialog *dialog)
767 qDebug() << __PRETTY_FUNCTION__;
769 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
770 if(dialog->isModal()) {
771 m_error_queue.append(dialog);
773 m_queue.append(dialog);
776 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
777 if(m_error_queue.count() == 1 && m_errorShown == false)
778 showErrorInformationBox();
779 else if(m_queue.count() == 1 && m_errorShown == false)
780 showInformationBox();
783 void MainWindow::saveCookies()
785 qDebug() << __PRETTY_FUNCTION__;
788 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
790 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
793 for(int i=0;i<cookieList.count();i++) {
794 QNetworkCookie cookie = cookieList.at(i);
795 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
796 list.append(QString(byteArray));
798 list.removeDuplicates();
800 QSettings settings(DIRECTORY_NAME, FILE_NAME);
801 settings.setValue(COOKIES, list);
804 void MainWindow::setGPSButtonEnabled(bool enabled)
806 qDebug() << __PRETTY_FUNCTION__;
808 m_gpsToggleAct->setChecked(enabled);
811 void MainWindow::setIndicatorButtonEnabled(bool enabled)
813 qDebug() << __PRETTY_FUNCTION__;
815 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
818 void MainWindow::setMapViewScene(QGraphicsScene *scene)
820 qDebug() << __PRETTY_FUNCTION__;
822 m_mapView->setScene(scene);
825 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
827 qDebug() << __PRETTY_FUNCTION__;
830 m_ownLocationCrosshair->show();
831 drawOwnLocationCrosshair(m_viewPortSize);
833 m_ownLocationCrosshair->hide();
837 void MainWindow::settingsDialogAccepted()
839 qDebug() << __PRETTY_FUNCTION__;
841 readAutomaticLocationUpdateSettings();
844 void MainWindow::setUsername(const QString &username)
846 qDebug() << __PRETTY_FUNCTION__;
851 void MainWindow::setViewPortSize(const QSize &size)
853 qDebug() << __PRETTY_FUNCTION__;
855 m_viewPortSize = size;
858 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
860 qDebug() << __PRETTY_FUNCTION__;
862 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
863 tr("Automatic location update"), text,
864 QMessageBox::Yes | QMessageBox::No |
865 QMessageBox::Cancel, this);
866 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
867 this, SLOT(automaticUpdateDialogFinished(int)));
869 m_automaticUpdateLocationDialog->show();
872 void MainWindow::toggleFullScreen()
874 qDebug() << __PRETTY_FUNCTION__;
876 if(windowState() == Qt::WindowNoState)
882 void MainWindow::showErrorInformationBox()
884 qDebug() << __PRETTY_FUNCTION__;
886 if(m_error_queue.count()) {
888 QDialog *dialog = m_error_queue.first();
889 connect(dialog, SIGNAL(finished(int)),
890 this, SLOT(errorDialogFinished(int)));
895 void MainWindow::showInformationBox()
897 qDebug() << __PRETTY_FUNCTION__;
899 if(m_queue.count()) {
900 QDialog *dialog = m_queue.first();
901 connect(dialog, SIGNAL(finished(int)),
902 this, SLOT(dialogFinished(int)));
907 void MainWindow::showPanels()
909 qDebug() << __PRETTY_FUNCTION__;
911 drawFullScreenButton(m_viewPortSize);
914 // if(!m_friendsListPanel->isVisible()) {
915 // m_friendsListPanel->show();
916 // m_friendsListPanelSidebar->show();
919 // if(!m_userPanel->isVisible()) {
920 // m_userPanel->show();
921 // m_userPanelSidebar->show();
926 void MainWindow::startLocationSearch()
928 qDebug() << __PRETTY_FUNCTION__;
930 SearchDialog *searchDialog = new SearchDialog();
931 queueDialog(searchDialog);
934 void MainWindow::startLoginProcess()
936 qDebug() << __PRETTY_FUNCTION__;
938 LoginDialog *loginDialog = new LoginDialog();
940 emit fetchUsernameFromSettings();
942 loginDialog->clearTextFields();
944 if(!m_email.isEmpty())
945 loginDialog->setEmailField(m_email);
947 queueDialog(loginDialog);
950 void MainWindow::toggleProgressIndicator(bool value)
952 qDebug() << __PRETTY_FUNCTION__;
956 m_progressIndicatorCount++;
957 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
959 if(m_progressIndicatorCount > 0)
960 m_progressIndicatorCount--;
962 if(m_progressIndicatorCount == 0)
963 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
967 #endif // Q_WS_MAEMO_5
970 void MainWindow::updateItemVisibility()
972 qDebug() << __PRETTY_FUNCTION__;
975 // m_friendsListPanel->closePanel();
976 // m_friendsListPanel->hide();
977 // m_friendsListPanelSidebar->hide();
979 // m_userPanel->closePanel();
980 // m_userPanel->hide();
981 // m_userPanelSidebar->hide();
985 const QString MainWindow::username()
987 qDebug() << __PRETTY_FUNCTION__;
992 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
994 qDebug() << __PRETTY_FUNCTION__;
996 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
997 // qwebview starts to load a new page while the current page loading is not finished
998 if(reply->error() != QNetworkReply::OperationCanceledError &&
999 reply->error() != QNetworkReply::NoError) {
1000 emit error(ErrorContext::NETWORK, reply->error());