2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Henri Lampela - henri.lampela@ixonos.com
6 Kaj Wallin - kaj.wallin@ixonos.com
7 Jussi Laitinen jussi.laitinen@ixonos.com
8 Sami Rämö - sami.ramo@ixonos.com
9 Ville Tiensuu - ville.tiensuu@ixonos.com
11 Situare is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 version 2 as published by the Free Software Foundation.
15 Situare is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with Situare; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 #include <QtAlgorithms>
30 #include "facebookservice/facebookauthentication.h"
31 #include "map/mapcommon.h"
32 #include "map/mapview.h"
35 #include "friendlistpanel.h"
36 #include "fullscreenbutton.h"
37 #include "indicatorbutton.h"
38 #include "logindialog.h"
40 #include "panelcommon.h"
41 #include "tabbedpanel.h"
42 #include "searchdialog.h"
43 #include "settingsdialog.h"
44 #include "userinfopanel.h"
45 #include "zoombuttonpanel.h"
47 #include "mainwindow.h"
49 // These MUST BE HERE, compiling for Maemo fails if moved
51 #include <QtMaemo5/QMaemo5InformationBox>
52 #include <QtGui/QX11Info>
53 #include <X11/Xatom.h>
55 #endif // Q_WS_MAEMO_5
57 MainWindow::MainWindow(QWidget *parent)
58 : QMainWindow(parent),
62 m_progressIndicatorCount(0),
63 m_ownLocationCrosshair(0),
67 m_fullScreenButton(0),
72 qDebug() << __PRETTY_FUNCTION__;
77 QHBoxLayout *layout = new QHBoxLayout;
78 layout->addWidget(m_mapView);
80 layout->setSpacing(0);
82 setCentralWidget(new QWidget());
83 centralWidget()->setLayout(layout);
85 // buildFriendListPanel();
89 setWindowTitle(tr("Situare"));
91 // set stacking order of widgets
92 // m_zoomButtonPanel->stackUnder(m_userInfoPanel);
93 m_zoomButtonPanel->stackUnder(m_tabbedPanel);
94 if(m_fullScreenButton) {
95 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
96 m_osmLicense->stackUnder(m_fullScreenButton);
98 m_osmLicense->stackUnder(m_zoomButtonPanel);
100 m_ownLocationCrosshair->stackUnder(m_osmLicense);
101 m_indicatorButton->stackUnder(m_ownLocationCrosshair);
102 m_mapScale->stackUnder(m_indicatorButton);
103 m_mapView->stackUnder(m_mapScale);
107 // Set default screen size
108 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
110 setAttribute(Qt::WA_Maemo5StackedWindow);
114 MainWindow::~MainWindow()
116 qDebug() << __PRETTY_FUNCTION__;
123 qDeleteAll(m_queue.begin(), m_queue.end());
126 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
127 m_error_queue.clear();
130 void MainWindow::automaticUpdateDialogFinished(int result)
132 qDebug() << __PRETTY_FUNCTION__;
134 if (result == QMessageBox::Yes) {
135 readAutomaticLocationUpdateSettings();
137 QSettings settings(DIRECTORY_NAME, FILE_NAME);
138 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
139 readAutomaticLocationUpdateSettings();
142 m_automaticUpdateLocationDialog->deleteLater();
145 void MainWindow::buildFullScreenButton()
147 qDebug() << __PRETTY_FUNCTION__;
149 m_fullScreenButton = new FullScreenButton(this);
150 connect(m_fullScreenButton, SIGNAL(clicked()),
151 this, SLOT(toggleFullScreen()));
152 #endif // Q_WS_MAEMO_5
155 void MainWindow::buildFriendListPanel()
157 qDebug() << __PRETTY_FUNCTION__;
159 m_friendsListPanel = new FriendListPanel(this);
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_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
171 this, SIGNAL(findFriend(GeoCoordinate)));
173 connect(this, SIGNAL(friendImageReady(User*)),
174 m_friendsListPanel, SLOT(friendImageReady(User*)));
177 void MainWindow::buildIndicatorButton()
179 qDebug() << __PRETTY_FUNCTION__;
181 m_indicatorButton = new IndicatorButton(this);
183 connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
184 this, SIGNAL(autoCenteringTriggered(bool)));
186 connect(m_mapView, SIGNAL(viewResized(QSize)),
187 m_indicatorButton, SLOT(screenResized(QSize)));
189 connect(m_indicatorButton, SIGNAL(draggingModeTriggered()),
190 this, SIGNAL(draggingModeTriggered()));
193 void MainWindow::buildInformationBox(const QString &message, bool modal)
195 qDebug() << __PRETTY_FUNCTION__;
197 QString errorMessage = message;
201 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
204 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
205 // extra line changes are needed to make error notes broader
206 errorMessage.prepend("\n");
207 errorMessage.append("\n");
209 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
211 QLabel *label = new QLabel(msgBox);
212 label->setAlignment(Qt::AlignCenter);
213 label->setText(errorMessage);
214 msgBox->setWidget(label);
216 QMessageBox *msgBox = new QMessageBox(this);
217 msgBox->button(QMessageBox::Ok);
218 msgBox->setText(errorMessage);
219 msgBox->setModal(modal);
225 void MainWindow::buildManualLocationCrosshair()
227 qDebug() << __PRETTY_FUNCTION__;
229 m_ownLocationCrosshair = new QLabel(this);
230 QPixmap crosshairImage(":/res/images/sight.png");
231 m_ownLocationCrosshair->setPixmap(crosshairImage);
232 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
233 m_ownLocationCrosshair->hide();
234 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
236 connect(m_mapView, SIGNAL(viewResized(QSize)),
237 this, SLOT(drawOwnLocationCrosshair(QSize)));
240 void MainWindow::buildMap()
242 qDebug() << __PRETTY_FUNCTION__;
244 m_mapView = new MapView(this);
246 buildZoomButtonPanel();
248 buildManualLocationCrosshair();
249 buildFullScreenButton();
250 buildIndicatorButton();
253 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
254 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
256 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
257 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
259 connect(m_mapView, SIGNAL(viewResized(QSize)),
260 this, SIGNAL(mapViewResized(QSize)));
262 connect(m_mapView, SIGNAL(viewResized(QSize)),
263 this, SLOT(drawFullScreenButton(QSize)));
265 connect(m_mapView, SIGNAL(viewResized(QSize)),
266 this, SLOT(drawMapScale(QSize)));
268 connect(m_mapView, SIGNAL(viewResized(QSize)),
269 this, SLOT(setViewPortSize(QSize)));
271 connect(this, SIGNAL(zoomLevelChanged(int)),
272 m_mapView, SLOT(setZoomLevel(int)));
274 connect(m_mapView, SIGNAL(viewZoomFinished()),
275 this, SIGNAL(viewZoomFinished()));
277 connect(m_mapView, SIGNAL(zoomIn()),
278 this, SIGNAL(zoomIn()));
281 void MainWindow::buildMapScale()
283 m_mapScale = new MapScale(this);
284 connect(this, SIGNAL(newMapResolution(qreal)),
285 m_mapScale, SLOT(updateMapResolution(qreal)));
288 void MainWindow::buildOsmLicense()
290 qDebug() << __PRETTY_FUNCTION__;
292 m_osmLicense = new QLabel(this);
293 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
294 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
295 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
296 m_osmLicense->setFont(QFont("Nokia Sans", 9));
297 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
298 m_osmLicense->fontMetrics().height());
300 connect(m_mapView, SIGNAL(viewResized(QSize)),
301 this, SLOT(drawOsmLicense(QSize)));
304 void MainWindow::buildUserInfoPanel()
306 qDebug() << __PRETTY_FUNCTION__;
308 m_userInfoPanel = new UserInfoPanel(this);
310 connect(this, SIGNAL(userLocationReady(User*)),
311 m_userInfoPanel, SLOT(userDataReceived(User*)));
313 connect(this, SIGNAL(reverseGeoReady(QString)),
314 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
316 connect(this, SIGNAL(clearUpdateLocationDialogData()),
317 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
319 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
320 this, SIGNAL(findUser(GeoCoordinate)));
322 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
323 this, SIGNAL(requestReverseGeo()));
325 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
326 this, SIGNAL(statusUpdate(QString,bool)));
328 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
329 this, SIGNAL(refreshUserData()));
331 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
332 this, SLOT(buildInformationBox(QString, bool)));
334 m_tabbedPanel = new TabbedPanel(this);
335 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
337 // This is just testing
338 m_tabbedPanel->addTab(new QPushButton("Friend List"), QIcon(":/res/images/friend_list.png"));
341 m_tabbedPanel->addTab(new QPushButton("Routing"), QIcon(":/res/images/routing.png"));
343 connect(m_mapView, SIGNAL(viewResized(QSize)),
344 m_tabbedPanel, SLOT(resizePanel(QSize)));
347 void MainWindow::buildWebView()
349 qDebug() << __PRETTY_FUNCTION__;
352 m_webView = new QWebView;
355 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
357 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
359 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
360 this, SLOT(webViewRequestFinished(QNetworkReply*)));
361 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
362 this, SIGNAL(updateCredentials(QUrl)));
363 connect(m_webView, SIGNAL(loadFinished(bool)),
364 this, SLOT(loadDone(bool)));
370 void MainWindow::buildZoomButtonPanel()
372 qDebug() << __PRETTY_FUNCTION__;
374 m_zoomButtonPanel = new ZoomButtonPanel(this);
376 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
377 this, SIGNAL(zoomIn()));
379 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
380 this, SIGNAL(zoomOut()));
382 connect(this, SIGNAL(zoomLevelChanged(int)),
383 m_zoomButtonPanel, SLOT(resetButtons()));
385 connect(this, SIGNAL(maxZoomLevelReached()),
386 m_zoomButtonPanel, SLOT(disableZoomInButton()));
388 connect(this, SIGNAL(minZoomLevelReached()),
389 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
391 connect(m_mapView, SIGNAL(viewResized(QSize)),
392 m_zoomButtonPanel, SLOT(screenResized(QSize)));
394 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
395 this, SIGNAL(draggingModeTriggered()));
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)
501 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
502 size.height() - m_fullScreenButton->size().height());
505 void MainWindow::drawMapScale(const QSize &size)
507 qDebug() << __PRETTY_FUNCTION__;
509 const int LEFT_SCALE_MARGIN = 10;
510 const int BOTTOM_SCALE_MARGIN = 2;
511 // qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
513 m_mapScale->move(LEFT_SCALE_MARGIN,
514 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
517 void MainWindow::drawOsmLicense(const QSize &size)
519 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
521 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
523 size.height() - m_osmLicense->fontMetrics().height());
526 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
528 qDebug() << __PRETTY_FUNCTION__;
530 if (m_ownLocationCrosshair != 0) {
531 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
532 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
536 void MainWindow::errorDialogFinished(int status)
538 qDebug() << __PRETTY_FUNCTION__;
541 QDialog *dialog = m_error_queue.takeFirst();
543 dialog->deleteLater();
544 m_errorShown = false;
546 if(!m_error_queue.isEmpty())
547 showErrorInformationBox();
548 else if(!m_queue.isEmpty())
549 showInformationBox();
552 void MainWindow::gpsTimeout()
554 qDebug() << __PRETTY_FUNCTION__;
556 buildInformationBox(tr("GPS timeout"));
559 void MainWindow::grabZoomKeys(bool grab)
561 qDebug() << __PRETTY_FUNCTION__;
564 // Can't grab keys unless we have a window id
568 unsigned long val = (grab) ? 1 : 0;
569 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
573 XChangeProperty (QX11Info::display(),
579 reinterpret_cast<unsigned char *>(&val),
583 #endif // Q_WS_MAEMO_5
586 void MainWindow::keyPressEvent(QKeyEvent* event)
588 qDebug() << __PRETTY_FUNCTION__;
590 switch (event->key()) {
601 QWidget::keyPressEvent(event);
604 void MainWindow::loadCookies()
606 qDebug() << __PRETTY_FUNCTION__;
608 QSettings settings(DIRECTORY_NAME, FILE_NAME);
610 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
612 if(!list.isEmpty()) {
613 QList<QNetworkCookie> cookieList;
614 for(int i=0;i<list.count();i++) {
615 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
619 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
621 m_cookieJar->setAllCookies(cookieList);
622 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
626 void MainWindow::loadDone(bool done)
628 qDebug() << __PRETTY_FUNCTION__;
630 // for the first time the login page is opened, we need to refresh it to get cookies working
638 QWebFrame* frame = m_webView->page()->currentFrame();
642 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
644 foreach (QWebElement element, emailCollection) {
645 element.setAttribute("value", m_email.toAscii());
648 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
649 foreach (QWebElement element, passwordCollection) {
650 element.setAttribute("value", m_password.toAscii());
652 // find connect button
653 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
654 foreach (QWebElement element, buttonCollection)
656 QPoint pos(element.geometry().center());
658 // send a mouse click event to the web page
659 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
661 QApplication::sendEvent(m_webView->page(), &event0);
662 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
664 QApplication::sendEvent(m_webView->page(), &event1);
670 void MainWindow::loggedIn(bool logged)
672 qDebug() << __PRETTY_FUNCTION__;
677 m_loginAct->setText(tr("Logout"));
683 m_loginAct->setText(tr("Login"));
685 updateItemVisibility();
688 void MainWindow::loginFailed()
690 qDebug() << __PRETTY_FUNCTION__;
696 bool MainWindow::loginState()
698 qDebug() << __PRETTY_FUNCTION__;
703 void MainWindow::loginUsingCookies()
705 qDebug() << __PRETTY_FUNCTION__;
707 toggleProgressIndicator(true);
712 QStringList urlParts;
713 urlParts.append(FACEBOOK_LOGINBASE);
714 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
715 urlParts.append(INTERVAL1);
716 urlParts.append(SITUARE_LOGIN_SUCCESS);
717 urlParts.append(INTERVAL2);
718 urlParts.append(SITUARE_LOGIN_FAILURE);
719 urlParts.append(FACEBOOK_LOGIN_ENDING);
721 m_webView->load(QUrl(urlParts.join(EMPTY)));
725 void MainWindow::openSettingsDialog()
727 qDebug() << __PRETTY_FUNCTION__;
729 SettingsDialog *settingsDialog = new SettingsDialog(this);
730 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
731 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
733 settingsDialog->show();
736 void MainWindow::readAutomaticLocationUpdateSettings()
738 qDebug() << __PRETTY_FUNCTION__;
740 QSettings settings(DIRECTORY_NAME, FILE_NAME);
741 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
742 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
745 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
747 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
749 emit enableAutomaticLocationUpdate(false);
753 void MainWindow::queueDialog(QDialog *dialog)
755 qDebug() << __PRETTY_FUNCTION__;
757 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
758 if(dialog->isModal()) {
759 m_error_queue.append(dialog);
761 m_queue.append(dialog);
764 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
765 if(m_error_queue.count() == 1 && m_errorShown == false)
766 showErrorInformationBox();
767 else if(m_queue.count() == 1 && m_errorShown == false)
768 showInformationBox();
771 void MainWindow::saveCookies()
773 qDebug() << __PRETTY_FUNCTION__;
776 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
778 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
781 for(int i=0;i<cookieList.count();i++) {
782 QNetworkCookie cookie = cookieList.at(i);
783 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
784 list.append(QString(byteArray));
786 list.removeDuplicates();
788 QSettings settings(DIRECTORY_NAME, FILE_NAME);
789 settings.setValue(COOKIES, list);
792 void MainWindow::setGPSButtonEnabled(bool enabled)
794 qDebug() << __PRETTY_FUNCTION__;
796 m_gpsToggleAct->setChecked(enabled);
799 void MainWindow::setIndicatorButtonEnabled(bool enabled)
801 qDebug() << __PRETTY_FUNCTION__;
803 m_indicatorButton->setChecked(enabled);
807 void MainWindow::setMapViewScene(QGraphicsScene *scene)
809 qDebug() << __PRETTY_FUNCTION__;
811 m_mapView->setScene(scene);
814 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
816 qDebug() << __PRETTY_FUNCTION__;
819 m_ownLocationCrosshair->show();
820 drawOwnLocationCrosshair(m_viewPortSize);
822 m_ownLocationCrosshair->hide();
826 void MainWindow::settingsDialogAccepted()
828 qDebug() << __PRETTY_FUNCTION__;
830 readAutomaticLocationUpdateSettings();
833 void MainWindow::setUsername(const QString &username)
835 qDebug() << __PRETTY_FUNCTION__;
840 void MainWindow::setViewPortSize(const QSize &size)
842 qDebug() << __PRETTY_FUNCTION__;
844 m_viewPortSize = size;
847 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
849 qDebug() << __PRETTY_FUNCTION__;
851 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
852 tr("Automatic location update"), text,
853 QMessageBox::Yes | QMessageBox::No |
854 QMessageBox::Cancel, this);
855 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
856 this, SLOT(automaticUpdateDialogFinished(int)));
858 m_automaticUpdateLocationDialog->show();
861 void MainWindow::toggleFullScreen()
863 qDebug() << __PRETTY_FUNCTION__;
865 if(windowState() == Qt::WindowNoState)
871 void MainWindow::showErrorInformationBox()
873 qDebug() << __PRETTY_FUNCTION__;
875 if(m_error_queue.count()) {
877 QDialog *dialog = m_error_queue.first();
878 connect(dialog, SIGNAL(finished(int)),
879 this, SLOT(errorDialogFinished(int)));
884 void MainWindow::showInformationBox()
886 qDebug() << __PRETTY_FUNCTION__;
888 if(m_queue.count()) {
889 QDialog *dialog = m_queue.first();
890 connect(dialog, SIGNAL(finished(int)),
891 this, SLOT(dialogFinished(int)));
896 void MainWindow::showPanels()
898 qDebug() << __PRETTY_FUNCTION__;
900 drawFullScreenButton(m_viewPortSize);
903 // if(!m_friendsListPanel->isVisible()) {
904 // m_friendsListPanel->show();
905 // m_friendsListPanelSidebar->show();
908 // if(!m_userPanel->isVisible()) {
909 // m_userPanel->show();
910 // m_userPanelSidebar->show();
915 void MainWindow::startLocationSearch()
917 qDebug() << __PRETTY_FUNCTION__;
919 SearchDialog *searchDialog = new SearchDialog();
920 queueDialog(searchDialog);
923 void MainWindow::startLoginProcess()
925 qDebug() << __PRETTY_FUNCTION__;
927 LoginDialog *loginDialog = new LoginDialog();
929 emit fetchUsernameFromSettings();
931 loginDialog->clearTextFields();
933 if(!m_email.isEmpty())
934 loginDialog->setEmailField(m_email);
936 queueDialog(loginDialog);
939 void MainWindow::toggleProgressIndicator(bool value)
941 qDebug() << __PRETTY_FUNCTION__;
945 m_progressIndicatorCount++;
946 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
948 if(m_progressIndicatorCount > 0)
949 m_progressIndicatorCount--;
951 if(m_progressIndicatorCount == 0)
952 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
956 #endif // Q_WS_MAEMO_5
959 void MainWindow::updateItemVisibility()
961 qDebug() << __PRETTY_FUNCTION__;
964 // m_friendsListPanel->closePanel();
965 // m_friendsListPanel->hide();
966 // m_friendsListPanelSidebar->hide();
967 // m_userPanel->closePanel();
968 // m_userPanel->hide();
969 // m_userPanelSidebar->hide();
973 const QString MainWindow::username()
975 qDebug() << __PRETTY_FUNCTION__;
980 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
982 qDebug() << __PRETTY_FUNCTION__;
984 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
985 // qwebview starts to load a new page while the current page loading is not finished
986 if(reply->error() != QNetworkReply::OperationCanceledError &&
987 reply->error() != QNetworkReply::NoError) {
988 emit error(ErrorContext::NETWORK, reply->error());