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,
27 #include <QtAlgorithms>
31 #include <QApplication>
33 #include <QMessageBox>
37 #include "facebookservice/facebookauthentication.h"
38 #include "friendlistpanel.h"
39 #include "fullscreenbutton.h"
40 #include "indicatorbuttonpanel.h"
41 #include "locationsearchpanel.h"
42 #include "logindialog.h"
43 #include "map/mapcommon.h"
44 #include "map/mapview.h"
46 #include "meetpeoplepanel.h"
47 #include "panelcommon.h"
48 #include "routingpanel.h"
49 #include "searchdialog.h"
50 #include "settingsdialog.h"
51 #include "tabbedpanel.h"
52 #include "userinfopanel.h"
53 #include "zoombuttonpanel.h"
56 #include "mainwindow.h"
58 // These MUST BE HERE, compiling for Maemo fails if moved
60 #include <QtMaemo5/QMaemo5InformationBox>
61 #include <QtGui/QX11Info>
62 #include <X11/Xatom.h>
64 #endif // Q_WS_MAEMO_5
66 #if defined(Q_WS_MAEMO_5) & defined(ARMEL)
67 #include "ossoabookdialog.h"
70 MainWindow::MainWindow(QWidget *parent)
71 : QMainWindow(parent),
75 m_mapCenterHorizontalShifting(0),
76 m_progressIndicatorCount(0),
78 m_email(), ///< @todo WTF?!?!?!?
81 m_fullScreenButton(0),
82 m_indicatorButtonPanel(0),
86 qDebug() << __PRETTY_FUNCTION__;
90 // map view is the only widget which size & location is handled automatically by the system
91 // default functionality
92 setCentralWidget(m_mapView);
97 setWindowTitle(tr("Situare"));
99 // set stacking order of widgets (from top to bottom)
100 // m_tabbedPanel is the topmost one
101 if (m_fullScreenButton) {
102 m_fullScreenButton->stackUnder(m_tabbedPanel);
103 m_crosshair->stackUnder(m_fullScreenButton);
105 m_crosshair->stackUnder(m_tabbedPanel);
107 m_zoomButtonPanel->stackUnder(m_crosshair);
108 m_indicatorButtonPanel->stackUnder(m_zoomButtonPanel);
109 m_osmLicense->stackUnder(m_indicatorButtonPanel);
110 m_mapScale->stackUnder(m_osmLicense);
111 m_mapView->stackUnder(m_mapScale);
115 // Set default screen size
116 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
118 setAttribute(Qt::WA_Maemo5StackedWindow);
122 MainWindow::~MainWindow()
124 qDebug() << __PRETTY_FUNCTION__;
131 qDeleteAll(m_queue.begin(), m_queue.end());
134 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
135 m_error_queue.clear();
138 void MainWindow::automaticUpdateDialogFinished(int result)
140 qDebug() << __PRETTY_FUNCTION__;
142 if (result == QMessageBox::Yes) {
143 readAutomaticLocationUpdateSettings();
145 QSettings settings(DIRECTORY_NAME, FILE_NAME);
146 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
147 readAutomaticLocationUpdateSettings();
150 m_automaticUpdateLocationDialog->deleteLater();
153 void MainWindow::buildCrosshair()
155 qDebug() << __PRETTY_FUNCTION__;
157 m_crosshair = new QLabel(this);
158 QPixmap crosshairImage(":/res/images/sight.png");
159 m_crosshair->setPixmap(crosshairImage);
160 m_crosshair->setFixedSize(crosshairImage.size());
162 m_crosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
164 connect(m_mapView, SIGNAL(viewResized(QSize)),
165 this, SLOT(moveCrosshair()));
167 connect(m_mapView, SIGNAL(horizontalShiftingChanged(int)),
168 this, SLOT(mapCenterHorizontalShiftingChanged(int)));
171 void MainWindow::buildFriendListPanel()
173 qDebug() << __PRETTY_FUNCTION__;
175 m_friendsListPanel = new FriendListPanel(this);
177 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
178 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
180 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
181 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
183 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
184 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
186 connect(this, SIGNAL(friendImageReady(User*)),
187 m_friendsListPanel, SLOT(friendImageReady(User*)));
189 connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
190 this, SIGNAL(routeTo(const GeoCoordinate&)));
192 connect(m_friendsListPanel, SIGNAL(requestContactDialog(const QString &)),
193 this, SIGNAL(requestContactDialog(const QString &)));
196 void MainWindow::buildFullScreenButton()
198 qDebug() << __PRETTY_FUNCTION__;
201 m_fullScreenButton = new FullScreenButton(this);
203 if (m_fullScreenButton) {
204 connect(m_fullScreenButton, SIGNAL(clicked()),
205 this, SLOT(toggleFullScreen()));
207 connect(qApp, SIGNAL(showFullScreenButton()),
208 m_fullScreenButton, SLOT(invoke()));
210 #endif // Q_WS_MAEMO_5
213 void MainWindow::buildIndicatorButtonPanel()
215 qDebug() << __PRETTY_FUNCTION__;
217 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
219 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
220 this, SIGNAL(autoCenteringTriggered(bool)));
222 connect(m_mapView, SIGNAL(viewResized(QSize)),
223 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
225 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
226 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
228 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
229 this, SIGNAL(draggingModeTriggered()));
232 void MainWindow::buildInformationBox(const QString &message, bool modal)
234 qDebug() << __PRETTY_FUNCTION__;
236 QString errorMessage = message;
240 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
243 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
244 // extra line changes are needed to make error notes broader
245 errorMessage.prepend("\n");
246 errorMessage.append("\n");
248 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
250 QLabel *label = new QLabel(msgBox);
251 label->setAlignment(Qt::AlignCenter);
252 label->setText(errorMessage);
253 msgBox->setWidget(label);
255 QMessageBox *msgBox = new QMessageBox(this);
256 msgBox->button(QMessageBox::Ok);
257 msgBox->setText(errorMessage);
258 msgBox->setModal(modal);
264 void MainWindow::buildLocationSearchPanel()
266 qDebug() << __PRETTY_FUNCTION__;
268 m_locationSearchPanel = new LocationSearchPanel(this);
270 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
271 m_locationSearchPanel, SLOT(populateLocationListView(const QList<Location>&)));
273 connect(m_locationSearchPanel, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
274 this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
276 connect(m_locationSearchPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
277 this, SIGNAL(routeTo(const GeoCoordinate&)));
279 connect(m_locationSearchPanel, SIGNAL(requestSearchLocation()),
280 this, SLOT(startLocationSearch()));
282 connect(this, SIGNAL(searchForLocation(QString)),
283 m_locationSearchPanel, SLOT(prependSearchHistory(QString)));
285 connect(m_locationSearchPanel, SIGNAL(searchHistoryItemClicked(QString)),
286 this, SIGNAL(searchHistoryItemClicked(QString)));
289 void MainWindow::buildMap()
291 qDebug() << __PRETTY_FUNCTION__;
293 m_mapView = new MapView(this);
295 buildZoomButtonPanel();
298 buildFullScreenButton();
299 buildIndicatorButtonPanel();
302 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
303 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
305 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
306 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
308 connect(m_mapView, SIGNAL(viewResized(QSize)),
309 this, SIGNAL(mapViewResized(QSize)));
311 connect(m_mapView, SIGNAL(viewResized(QSize)),
312 this, SLOT(drawFullScreenButton(QSize)));
314 connect(m_mapView, SIGNAL(viewResized(QSize)),
315 this, SLOT(drawMapScale(QSize)));
317 connect(m_mapView, SIGNAL(viewResized(QSize)),
318 this, SLOT(moveCrosshair()));
320 connect(this, SIGNAL(zoomLevelChanged(int)),
321 m_mapView, SLOT(setZoomLevel(int)));
323 connect(m_mapView, SIGNAL(viewZoomFinished()),
324 this, SIGNAL(viewZoomFinished()));
326 connect(m_mapView, SIGNAL(zoomIn()),
327 this, SIGNAL(zoomIn()));
330 void MainWindow::buildMapScale()
332 m_mapScale = new MapScale(this);
333 connect(this, SIGNAL(newMapResolution(qreal)),
334 m_mapScale, SLOT(updateMapResolution(qreal)));
337 void MainWindow::buildMeetPeoplePanel()
339 m_meetPeoplePanel = new MeetPeoplePanel(this);
341 connect(this, SIGNAL(friendImageReady(User*)),
342 m_meetPeoplePanel, SLOT(friendImageReady(User*)));
344 connect(this, SIGNAL(interestingPeopleReceived(QList<User*>&)),
345 m_meetPeoplePanel, SLOT(populateInterestingPeopleListView(QList<User*>&)));
347 connect(m_meetPeoplePanel, SIGNAL(requestInterestingPeople()),
348 this, SIGNAL(requestInterestingPeople()));
350 connect(this, SIGNAL(messagesReceived(QList<Message>&)),
351 m_meetPeoplePanel, SLOT(populateMessageListView(QList<Message>&)));
354 void MainWindow::buildOsmLicense()
356 qDebug() << __PRETTY_FUNCTION__;
358 m_osmLicense = new QLabel(this);
359 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
360 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
361 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
362 m_osmLicense->setFont(QFont("Nokia Sans", 9));
363 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
364 m_osmLicense->fontMetrics().height());
366 connect(m_mapView, SIGNAL(viewResized(QSize)),
367 this, SLOT(drawOsmLicense(QSize)));
370 void MainWindow::buildPanels()
372 qDebug() << __PRETTY_FUNCTION__;
374 buildUserInfoPanel();
375 buildFriendListPanel();
376 buildLocationSearchPanel();
378 buildMeetPeoplePanel();
380 m_tabbedPanel = new TabbedPanel(this);
382 //Save Situare related tab indexes so tabs can be enabled/disabled when logged in/out
383 m_situareTabsIndexes.append(
384 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png")));
385 m_situareTabsIndexes.append(
386 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png")));
388 // m_tabbedPanel->addTab(m_locationSearchPanel, QIcon(":/res/images/location_search.png"));
389 // m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
390 m_situareTabsIndexes.append(
391 m_tabbedPanel->addTab(m_meetPeoplePanel, QIcon(":/res/images/meet_people.png")));
393 connect(m_mapView, SIGNAL(viewResized(QSize)),
394 m_tabbedPanel, SLOT(resizePanel(QSize)));
396 connect(m_friendsListPanel, SIGNAL(openPanelRequested(QWidget*)),
397 m_tabbedPanel, SLOT(openPanel(QWidget*)));
399 connect(m_routingPanel, SIGNAL(openPanelRequested(QWidget*)),
400 m_tabbedPanel, SLOT(openPanel(QWidget*)));
402 connect(m_tabbedPanel, SIGNAL(panelClosed()),
403 m_friendsListPanel, SLOT(anyPanelClosed()));
405 connect(m_tabbedPanel, SIGNAL(panelOpened()),
406 m_friendsListPanel, SLOT(anyPanelOpened()));
408 connect(m_tabbedPanel, SIGNAL(panelClosed()),
409 m_routingPanel, SLOT(clearListsSelections()));
411 connect(m_tabbedPanel, SIGNAL(panelClosed()),
412 m_mapView, SLOT(disableCenterShift()));
414 connect(m_tabbedPanel, SIGNAL(panelOpened()),
415 m_mapView, SLOT(enableCenterShift()));
417 connect(m_tabbedPanel, SIGNAL(panelClosed()),
418 m_userInfoPanel, SIGNAL(collapse()));
420 connect(m_tabbedPanel, SIGNAL(currentChanged(int)),
421 m_userInfoPanel, SIGNAL(collapse()));
423 // signals for showing and hiding list item context buttons
424 connect(m_friendsListPanel, SIGNAL(listItemSelectionChanged(bool)),
425 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
427 connect(m_locationSearchPanel, SIGNAL(listItemSelectionChanged(bool)),
428 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
430 connect(m_routingPanel, SIGNAL(listItemSelectionChanged(bool)),
431 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
434 void MainWindow::buildRoutingPanel()
436 qDebug() << __PRETTY_FUNCTION__;
438 m_routingPanel = new RoutingPanel(this);
440 connect(m_routingPanel, SIGNAL(routeToCursor()),
441 this, SIGNAL(routeToCursor()));
443 connect(this, SIGNAL(routeParsed(Route&)),
444 m_routingPanel, SLOT(setRoute(Route&)));
446 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
447 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
449 connect(m_routingPanel, SIGNAL(clearRoute()),
450 this, SIGNAL(clearRoute()));
453 void MainWindow::buildUserInfoPanel()
455 qDebug() << __PRETTY_FUNCTION__;
457 m_userInfoPanel = new UserInfoPanel(this);
459 connect(this, SIGNAL(userLocationReady(User*)),
460 m_userInfoPanel, SLOT(userDataReceived(User*)));
462 connect(this, SIGNAL(reverseGeoReady(QString)),
463 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
465 connect(this, SIGNAL(clearUpdateLocationDialogData()),
466 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
468 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
469 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
471 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
472 this, SIGNAL(requestReverseGeo()));
474 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
475 this, SIGNAL(statusUpdate(QString,bool)));
477 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
478 this, SIGNAL(refreshUserData()));
480 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
481 this, SLOT(buildInformationBox(QString, bool)));
484 void MainWindow::buildWebView()
486 qDebug() << __PRETTY_FUNCTION__;
489 m_webView = new QWebView;
492 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
494 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
496 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
497 this, SLOT(webViewRequestFinished(QNetworkReply*)));
498 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
499 this, SIGNAL(updateCredentials(QUrl)));
500 connect(m_webView, SIGNAL(loadFinished(bool)),
501 this, SLOT(loadDone(bool)));
507 void MainWindow::buildZoomButtonPanel()
509 qDebug() << __PRETTY_FUNCTION__;
511 m_zoomButtonPanel = new ZoomButtonPanel(this);
513 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
514 this, SIGNAL(zoomIn()));
516 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
517 this, SIGNAL(zoomOut()));
519 connect(this, SIGNAL(zoomLevelChanged(int)),
520 m_zoomButtonPanel, SLOT(resetButtons()));
522 connect(this, SIGNAL(maxZoomLevelReached()),
523 m_zoomButtonPanel, SLOT(disableZoomInButton()));
525 connect(this, SIGNAL(minZoomLevelReached()),
526 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
528 connect(m_mapView, SIGNAL(viewResized(QSize)),
529 m_zoomButtonPanel, SLOT(screenResized(QSize)));
531 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
532 this, SIGNAL(draggingModeTriggered()));
535 void MainWindow::clearCookieJar()
537 qDebug() << __PRETTY_FUNCTION__;
544 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
546 QList<QNetworkCookie> emptyList;
549 m_cookieJar->setAllCookies(emptyList);
550 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
553 void MainWindow::createMenus()
555 qDebug() << __PRETTY_FUNCTION__;
558 m_loginAct = new QAction(tr("Login"), this);
559 connect(m_loginAct, SIGNAL(triggered()),
560 this, SIGNAL(loginActionPressed()));
563 m_toSettingsAct = new QAction(tr("Settings"), this);
564 connect(m_toSettingsAct, SIGNAL(triggered()),
565 this, SLOT(openSettingsDialog()));
568 m_gpsToggleAct = new QAction(tr("GPS"), this);
569 m_gpsToggleAct->setCheckable(true);
571 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
572 this, SIGNAL(gpsTriggered(bool)));
574 // build the actual menu
575 m_viewMenu = menuBar()->addMenu(tr("Main"));
576 m_viewMenu->addAction(m_loginAct);
577 m_viewMenu->addAction(m_toSettingsAct);
578 m_viewMenu->addAction(m_gpsToggleAct);
579 m_viewMenu->setObjectName(tr("Menu"));
582 void MainWindow::dialogFinished(int status)
584 qDebug() << __PRETTY_FUNCTION__;
586 QDialog *dialog = m_queue.takeFirst();
587 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
588 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
592 loginDialog->userInput(m_email, m_password);
594 QStringList urlParts;
595 urlParts.append(FACEBOOK_LOGINBASE);
596 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
597 urlParts.append(INTERVAL1);
598 urlParts.append(SITUARE_LOGIN_SUCCESS);
599 urlParts.append(INTERVAL2);
600 urlParts.append(SITUARE_LOGIN_FAILURE);
601 urlParts.append(FACEBOOK_LOGIN_ENDING);
603 emit saveUsername(m_email);
605 m_webView->load(QUrl(urlParts.join(EMPTY)));
606 toggleProgressIndicator(true);
608 emit cancelLoginProcess();
610 } else if(searchDialog) {
612 emit searchForLocation(searchDialog->input());
616 dialog->deleteLater();
618 if(!m_error_queue.isEmpty() && m_errorShown == false) {
619 showErrorInformationBox();
621 if(!m_queue.isEmpty()) {
622 showInformationBox();
627 void MainWindow::drawFullScreenButton(const QSize &size)
629 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
631 if (m_fullScreenButton) {
632 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
633 size.height() - m_fullScreenButton->size().height());
637 void MainWindow::drawMapScale(const QSize &size)
639 qDebug() << __PRETTY_FUNCTION__;
641 const int LEFT_SCALE_MARGIN = 10;
642 const int BOTTOM_SCALE_MARGIN = 2;
644 m_mapScale->move(LEFT_SCALE_MARGIN,
645 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
648 void MainWindow::drawOsmLicense(const QSize &size)
650 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
652 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
654 size.height() - m_osmLicense->fontMetrics().height());
657 void MainWindow::errorDialogFinished(int status)
659 qDebug() << __PRETTY_FUNCTION__;
662 QDialog *dialog = m_error_queue.takeFirst();
664 dialog->deleteLater();
665 m_errorShown = false;
667 if(!m_error_queue.isEmpty())
668 showErrorInformationBox();
669 else if(!m_queue.isEmpty())
670 showInformationBox();
673 void MainWindow::gpsTimeout()
675 qDebug() << __PRETTY_FUNCTION__;
677 buildInformationBox(tr("GPS timeout"));
680 void MainWindow::grabZoomKeys(bool grab)
682 qDebug() << __PRETTY_FUNCTION__;
685 // Can't grab keys unless we have a window id
689 unsigned long val = (grab) ? 1 : 0;
690 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
694 XChangeProperty (QX11Info::display(),
700 reinterpret_cast<unsigned char *>(&val),
704 #endif // Q_WS_MAEMO_5
707 void MainWindow::keyPressEvent(QKeyEvent* event)
709 qDebug() << __PRETTY_FUNCTION__;
711 switch (event->key()) {
722 QWidget::keyPressEvent(event);
725 void MainWindow::loadCookies()
727 qDebug() << __PRETTY_FUNCTION__;
729 QSettings settings(DIRECTORY_NAME, FILE_NAME);
731 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
733 if(!list.isEmpty()) {
734 QList<QNetworkCookie> cookieList;
735 for(int i=0;i<list.count();i++) {
736 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
740 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
742 m_cookieJar->setAllCookies(cookieList);
743 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
747 void MainWindow::loadDone(bool done)
749 qDebug() << __PRETTY_FUNCTION__;
751 // for the first time the login page is opened, we need to refresh it to get cookies working
759 QWebFrame* frame = m_webView->page()->currentFrame();
763 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
765 foreach (QWebElement element, emailCollection) {
766 element.setAttribute("value", m_email.toAscii());
769 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
770 foreach (QWebElement element, passwordCollection) {
771 element.setAttribute("value", m_password.toAscii());
773 // find connect button
774 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
775 foreach (QWebElement element, buttonCollection)
777 QPoint pos(element.geometry().center());
779 // send a mouse click event to the web page
780 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
782 QApplication::sendEvent(m_webView->page(), &event0);
783 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
785 QApplication::sendEvent(m_webView->page(), &event1);
791 void MainWindow::loggedIn(bool logged)
793 qDebug() << __PRETTY_FUNCTION__;
798 m_loginAct->setText(tr("Logout"));
804 m_loginAct->setText(tr("Login"));
805 m_userInfoPanel->showUserInfo(false);
807 updateItemVisibility();
810 void MainWindow::loginFailed()
812 qDebug() << __PRETTY_FUNCTION__;
818 bool MainWindow::loginState()
820 qDebug() << __PRETTY_FUNCTION__;
825 void MainWindow::loginUsingCookies()
827 qDebug() << __PRETTY_FUNCTION__;
829 toggleProgressIndicator(true);
834 QStringList urlParts;
835 urlParts.append(FACEBOOK_LOGINBASE);
836 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
837 urlParts.append(INTERVAL1);
838 urlParts.append(SITUARE_LOGIN_SUCCESS);
839 urlParts.append(INTERVAL2);
840 urlParts.append(SITUARE_LOGIN_FAILURE);
841 urlParts.append(FACEBOOK_LOGIN_ENDING);
843 m_webView->load(QUrl(urlParts.join(EMPTY)));
847 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
849 m_mapCenterHorizontalShifting = shifting;
853 void MainWindow::moveCrosshair()
855 qDebug() << __PRETTY_FUNCTION__;
858 int mapHeight = m_mapView->size().height();
859 int mapWidth = m_mapView->size().width();
860 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
861 - m_mapCenterHorizontalShifting,
862 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
866 void MainWindow::openSettingsDialog()
868 qDebug() << __PRETTY_FUNCTION__;
870 SettingsDialog *settingsDialog = new SettingsDialog(this);
871 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
872 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
874 settingsDialog->show();
877 void MainWindow::queueDialog(QDialog *dialog)
879 qDebug() << __PRETTY_FUNCTION__;
881 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
882 if(dialog->isModal()) {
883 m_error_queue.append(dialog);
885 m_queue.append(dialog);
888 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
889 if(m_error_queue.count() == 1 && m_errorShown == false)
890 showErrorInformationBox();
891 else if(m_queue.count() == 1 && m_errorShown == false)
892 showInformationBox();
895 void MainWindow::readAutomaticLocationUpdateSettings()
897 qDebug() << __PRETTY_FUNCTION__;
899 QSettings settings(DIRECTORY_NAME, FILE_NAME);
900 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
901 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
904 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
906 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
908 emit enableAutomaticLocationUpdate(false);
912 void MainWindow::saveCookies()
914 qDebug() << __PRETTY_FUNCTION__;
917 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
919 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
922 for(int i=0;i<cookieList.count();i++) {
923 QNetworkCookie cookie = cookieList.at(i);
924 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
925 list.append(QString(byteArray));
927 list.removeDuplicates();
929 QSettings settings(DIRECTORY_NAME, FILE_NAME);
930 settings.setValue(COOKIES, list);
933 void MainWindow::setCrosshairVisibility(bool visibility)
935 qDebug() << __PRETTY_FUNCTION__;
945 void MainWindow::setGPSButtonEnabled(bool enabled)
947 qDebug() << __PRETTY_FUNCTION__;
949 m_gpsToggleAct->setChecked(enabled);
952 void MainWindow::setIndicatorButtonEnabled(bool enabled)
954 qDebug() << __PRETTY_FUNCTION__;
956 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
959 void MainWindow::setMapViewScene(QGraphicsScene *scene)
961 qDebug() << __PRETTY_FUNCTION__;
963 m_mapView->setScene(scene);
966 void MainWindow::settingsDialogAccepted()
968 qDebug() << __PRETTY_FUNCTION__;
970 readAutomaticLocationUpdateSettings();
973 void MainWindow::setUsername(const QString &username)
975 qDebug() << __PRETTY_FUNCTION__;
980 void MainWindow::showContactDialog(const QString &guid)
982 qDebug() << __PRETTY_FUNCTION__;
984 #if defined(Q_WS_MAEMO_5) & defined(ARMEL)
985 OssoABookDialog::showContactDialog(guid);
988 buildInformationBox(tr("Contact dialog works only on phone!"), true);
992 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
994 qDebug() << __PRETTY_FUNCTION__;
996 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
997 tr("Automatic location update"), text,
998 QMessageBox::Yes | QMessageBox::No |
999 QMessageBox::Cancel, this);
1000 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
1001 this, SLOT(automaticUpdateDialogFinished(int)));
1003 m_automaticUpdateLocationDialog->show();
1006 void MainWindow::showErrorInformationBox()
1008 qDebug() << __PRETTY_FUNCTION__;
1010 if(m_error_queue.count()) {
1011 m_errorShown = true;
1012 QDialog *dialog = m_error_queue.first();
1013 connect(dialog, SIGNAL(finished(int)),
1014 this, SLOT(errorDialogFinished(int)));
1019 void MainWindow::showInformationBox()
1021 qDebug() << __PRETTY_FUNCTION__;
1023 if(m_queue.count()) {
1024 QDialog *dialog = m_queue.first();
1025 connect(dialog, SIGNAL(finished(int)),
1026 this, SLOT(dialogFinished(int)));
1031 void MainWindow::startLocationSearch()
1033 qDebug() << __PRETTY_FUNCTION__;
1035 SearchDialog *searchDialog = new SearchDialog();
1036 queueDialog(searchDialog);
1039 void MainWindow::startLoginProcess()
1041 qDebug() << __PRETTY_FUNCTION__;
1043 LoginDialog *loginDialog = new LoginDialog();
1045 emit fetchUsernameFromSettings();
1047 loginDialog->clearTextFields();
1049 if(!m_email.isEmpty())
1050 loginDialog->setEmailField(m_email);
1052 queueDialog(loginDialog);
1055 void MainWindow::toggleFullScreen()
1057 qDebug() << __PRETTY_FUNCTION__;
1059 if(windowState() == Qt::WindowNoState)
1065 void MainWindow::toggleProgressIndicator(bool value)
1067 qDebug() << __PRETTY_FUNCTION__;
1071 m_progressIndicatorCount++;
1072 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1074 if(m_progressIndicatorCount > 0)
1075 m_progressIndicatorCount--;
1077 if(m_progressIndicatorCount == 0)
1078 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1082 #endif // Q_WS_MAEMO_5
1085 void MainWindow::updateItemVisibility()
1087 qDebug() << __PRETTY_FUNCTION__;
1089 m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, m_loggedIn);
1092 const QString MainWindow::username()
1094 qDebug() << __PRETTY_FUNCTION__;
1099 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1101 qDebug() << __PRETTY_FUNCTION__;
1103 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1104 // qwebview starts to load a new page while the current page loading is not finished
1105 if(reply->error() != QNetworkReply::OperationCanceledError &&
1106 reply->error() != QNetworkReply::NoError) {
1107 emit error(ErrorContext::NETWORK, reply->error());