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,
28 #include <QApplication>
30 #include <QMessageBox>
31 #include <QtAlgorithms>
35 #include "facebookservice/facebookauthentication.h"
36 #include "map/mapcommon.h"
37 #include "map/mapview.h"
40 #include "friendlistpanel.h"
41 #include "fullscreenbutton.h"
42 #include "indicatorbuttonpanel.h"
43 #include "locationsearchpanel.h"
44 #include "logindialog.h"
46 #include "meetpeoplepanel.h"
47 #include "panelcommon.h"
48 #include "routingpanel.h"
49 #include "tabbedpanel.h"
50 #include "searchdialog.h"
51 #include "settingsdialog.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()));
283 void MainWindow::buildMap()
285 qDebug() << __PRETTY_FUNCTION__;
287 m_mapView = new MapView(this);
289 buildZoomButtonPanel();
292 buildFullScreenButton();
293 buildIndicatorButtonPanel();
296 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
297 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
299 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
300 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
302 connect(m_mapView, SIGNAL(viewResized(QSize)),
303 this, SIGNAL(mapViewResized(QSize)));
305 connect(m_mapView, SIGNAL(viewResized(QSize)),
306 this, SLOT(drawFullScreenButton(QSize)));
308 connect(m_mapView, SIGNAL(viewResized(QSize)),
309 this, SLOT(drawMapScale(QSize)));
311 connect(m_mapView, SIGNAL(viewResized(QSize)),
312 this, SLOT(moveCrosshair()));
314 connect(this, SIGNAL(zoomLevelChanged(int)),
315 m_mapView, SLOT(setZoomLevel(int)));
317 connect(m_mapView, SIGNAL(viewZoomFinished()),
318 this, SIGNAL(viewZoomFinished()));
320 connect(m_mapView, SIGNAL(zoomIn()),
321 this, SIGNAL(zoomIn()));
324 void MainWindow::buildMapScale()
326 m_mapScale = new MapScale(this);
327 connect(this, SIGNAL(newMapResolution(qreal)),
328 m_mapScale, SLOT(updateMapResolution(qreal)));
331 void MainWindow::buildMeetPeoplePanel()
333 m_meetPeoplePanel = new MeetPeoplePanel(this);
335 connect(this, SIGNAL(friendImageReady(User*)),
336 m_meetPeoplePanel, SLOT(friendImageReady(User*)));
338 connect(this, SIGNAL(interestingPeopleReceived(QList<User*>&)),
339 m_meetPeoplePanel, SLOT(populateInterestingPeopleListView(QList<User*>&)));
341 connect(m_meetPeoplePanel, SIGNAL(requestInterestingPeople()),
342 this, SIGNAL(requestInterestingPeople()));
344 connect(this, SIGNAL(messagesReceived(QList<Message>&)),
345 m_meetPeoplePanel, SLOT(populateMessageListView(QList<Message>&)));
348 void MainWindow::buildOsmLicense()
350 qDebug() << __PRETTY_FUNCTION__;
352 m_osmLicense = new QLabel(this);
353 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
354 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
355 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
356 m_osmLicense->setFont(QFont("Nokia Sans", 9));
357 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
358 m_osmLicense->fontMetrics().height());
360 connect(m_mapView, SIGNAL(viewResized(QSize)),
361 this, SLOT(drawOsmLicense(QSize)));
364 void MainWindow::buildPanels()
366 qDebug() << __PRETTY_FUNCTION__;
368 buildUserInfoPanel();
369 buildFriendListPanel();
370 buildLocationSearchPanel();
372 buildMeetPeoplePanel();
374 m_tabbedPanel = new TabbedPanel(this);
376 //Save Situare related tab indexes so tabs can be enabled/disabled when logged in/out
377 m_situareTabsIndexes.append(
378 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png")));
379 m_situareTabsIndexes.append(
380 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png")));
382 // m_tabbedPanel->addTab(m_locationSearchPanel, QIcon(":/res/images/location_search.png"));
383 // m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
384 m_situareTabsIndexes.append(
385 m_tabbedPanel->addTab(m_meetPeoplePanel, QIcon(":/res/images/meet_people.png")));
387 connect(m_mapView, SIGNAL(viewResized(QSize)),
388 m_tabbedPanel, SLOT(resizePanel(QSize)));
390 connect(m_friendsListPanel, SIGNAL(openPanelRequested(QWidget*)),
391 m_tabbedPanel, SLOT(openPanel(QWidget*)));
393 connect(m_routingPanel, SIGNAL(openPanelRequested(QWidget*)),
394 m_tabbedPanel, SLOT(openPanel(QWidget*)));
396 connect(m_tabbedPanel, SIGNAL(panelClosed()),
397 m_friendsListPanel, SLOT(anyPanelClosed()));
399 connect(m_tabbedPanel, SIGNAL(panelOpened()),
400 m_friendsListPanel, SLOT(anyPanelOpened()));
402 connect(m_tabbedPanel, SIGNAL(panelClosed()),
403 m_routingPanel, SLOT(clearListsSelections()));
405 connect(m_tabbedPanel, SIGNAL(panelClosed()),
406 m_mapView, SLOT(disableCenterShift()));
408 connect(m_tabbedPanel, SIGNAL(panelOpened()),
409 m_mapView, SLOT(enableCenterShift()));
411 connect(m_tabbedPanel, SIGNAL(panelClosed()),
412 m_userInfoPanel, SIGNAL(collapse()));
414 connect(m_tabbedPanel, SIGNAL(currentChanged(int)),
415 m_userInfoPanel, SIGNAL(collapse()));
418 void MainWindow::buildRoutingPanel()
420 qDebug() << __PRETTY_FUNCTION__;
422 m_routingPanel = new RoutingPanel(this);
424 connect(m_routingPanel, SIGNAL(routeToCursor()),
425 this, SIGNAL(routeToCursor()));
427 connect(this, SIGNAL(routeParsed(Route&)),
428 m_routingPanel, SLOT(setRoute(Route&)));
430 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
431 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
433 connect(m_routingPanel, SIGNAL(clearRoute()),
434 this, SIGNAL(clearRoute()));
437 void MainWindow::buildUserInfoPanel()
439 qDebug() << __PRETTY_FUNCTION__;
441 m_userInfoPanel = new UserInfoPanel(this);
443 connect(this, SIGNAL(userLocationReady(User*)),
444 m_userInfoPanel, SLOT(userDataReceived(User*)));
446 connect(this, SIGNAL(reverseGeoReady(QString)),
447 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
449 connect(this, SIGNAL(clearUpdateLocationDialogData()),
450 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
452 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
453 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
455 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
456 this, SIGNAL(requestReverseGeo()));
458 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
459 this, SIGNAL(statusUpdate(QString,bool)));
461 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
462 this, SIGNAL(refreshUserData()));
464 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
465 this, SLOT(buildInformationBox(QString, bool)));
468 void MainWindow::buildWebView()
470 qDebug() << __PRETTY_FUNCTION__;
473 m_webView = new QWebView;
476 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
478 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
480 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
481 this, SLOT(webViewRequestFinished(QNetworkReply*)));
482 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
483 this, SIGNAL(updateCredentials(QUrl)));
484 connect(m_webView, SIGNAL(loadFinished(bool)),
485 this, SLOT(loadDone(bool)));
491 void MainWindow::buildZoomButtonPanel()
493 qDebug() << __PRETTY_FUNCTION__;
495 m_zoomButtonPanel = new ZoomButtonPanel(this);
497 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
498 this, SIGNAL(zoomIn()));
500 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
501 this, SIGNAL(zoomOut()));
503 connect(this, SIGNAL(zoomLevelChanged(int)),
504 m_zoomButtonPanel, SLOT(resetButtons()));
506 connect(this, SIGNAL(maxZoomLevelReached()),
507 m_zoomButtonPanel, SLOT(disableZoomInButton()));
509 connect(this, SIGNAL(minZoomLevelReached()),
510 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
512 connect(m_mapView, SIGNAL(viewResized(QSize)),
513 m_zoomButtonPanel, SLOT(screenResized(QSize)));
515 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
516 this, SIGNAL(draggingModeTriggered()));
519 void MainWindow::clearCookieJar()
521 qDebug() << __PRETTY_FUNCTION__;
528 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
530 QList<QNetworkCookie> emptyList;
533 m_cookieJar->setAllCookies(emptyList);
534 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
537 void MainWindow::createMenus()
539 qDebug() << __PRETTY_FUNCTION__;
542 m_loginAct = new QAction(tr("Login"), this);
543 connect(m_loginAct, SIGNAL(triggered()),
544 this, SIGNAL(loginActionPressed()));
547 m_toSettingsAct = new QAction(tr("Settings"), this);
548 connect(m_toSettingsAct, SIGNAL(triggered()),
549 this, SLOT(openSettingsDialog()));
552 m_gpsToggleAct = new QAction(tr("GPS"), this);
553 m_gpsToggleAct->setCheckable(true);
555 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
556 this, SIGNAL(gpsTriggered(bool)));
558 // build the actual menu
559 m_viewMenu = menuBar()->addMenu(tr("Main"));
560 m_viewMenu->addAction(m_loginAct);
561 m_viewMenu->addAction(m_toSettingsAct);
562 m_viewMenu->addAction(m_gpsToggleAct);
563 m_viewMenu->setObjectName(tr("Menu"));
566 void MainWindow::dialogFinished(int status)
568 qDebug() << __PRETTY_FUNCTION__;
570 QDialog *dialog = m_queue.takeFirst();
571 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
572 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
576 loginDialog->userInput(m_email, m_password);
578 QStringList urlParts;
579 urlParts.append(FACEBOOK_LOGINBASE);
580 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
581 urlParts.append(INTERVAL1);
582 urlParts.append(SITUARE_LOGIN_SUCCESS);
583 urlParts.append(INTERVAL2);
584 urlParts.append(SITUARE_LOGIN_FAILURE);
585 urlParts.append(FACEBOOK_LOGIN_ENDING);
587 emit saveUsername(m_email);
589 m_webView->load(QUrl(urlParts.join(EMPTY)));
590 toggleProgressIndicator(true);
592 emit cancelLoginProcess();
594 } else if(searchDialog) {
596 emit searchForLocation(searchDialog->input());
600 dialog->deleteLater();
602 if(!m_error_queue.isEmpty() && m_errorShown == false) {
603 showErrorInformationBox();
605 if(!m_queue.isEmpty()) {
606 showInformationBox();
611 void MainWindow::drawFullScreenButton(const QSize &size)
613 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
615 if (m_fullScreenButton) {
616 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
617 size.height() - m_fullScreenButton->size().height());
621 void MainWindow::drawMapScale(const QSize &size)
623 qDebug() << __PRETTY_FUNCTION__;
625 const int LEFT_SCALE_MARGIN = 10;
626 const int BOTTOM_SCALE_MARGIN = 2;
628 m_mapScale->move(LEFT_SCALE_MARGIN,
629 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
632 void MainWindow::drawOsmLicense(const QSize &size)
634 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
636 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
638 size.height() - m_osmLicense->fontMetrics().height());
641 void MainWindow::errorDialogFinished(int status)
643 qDebug() << __PRETTY_FUNCTION__;
646 QDialog *dialog = m_error_queue.takeFirst();
648 dialog->deleteLater();
649 m_errorShown = false;
651 if(!m_error_queue.isEmpty())
652 showErrorInformationBox();
653 else if(!m_queue.isEmpty())
654 showInformationBox();
657 void MainWindow::gpsTimeout()
659 qDebug() << __PRETTY_FUNCTION__;
661 buildInformationBox(tr("GPS timeout"));
664 void MainWindow::grabZoomKeys(bool grab)
666 qDebug() << __PRETTY_FUNCTION__;
669 // Can't grab keys unless we have a window id
673 unsigned long val = (grab) ? 1 : 0;
674 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
678 XChangeProperty (QX11Info::display(),
684 reinterpret_cast<unsigned char *>(&val),
688 #endif // Q_WS_MAEMO_5
691 void MainWindow::keyPressEvent(QKeyEvent* event)
693 qDebug() << __PRETTY_FUNCTION__;
695 switch (event->key()) {
706 QWidget::keyPressEvent(event);
709 void MainWindow::loadCookies()
711 qDebug() << __PRETTY_FUNCTION__;
713 QSettings settings(DIRECTORY_NAME, FILE_NAME);
715 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
717 if(!list.isEmpty()) {
718 QList<QNetworkCookie> cookieList;
719 for(int i=0;i<list.count();i++) {
720 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
724 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
726 m_cookieJar->setAllCookies(cookieList);
727 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
731 void MainWindow::loadDone(bool done)
733 qDebug() << __PRETTY_FUNCTION__;
735 // for the first time the login page is opened, we need to refresh it to get cookies working
743 QWebFrame* frame = m_webView->page()->currentFrame();
747 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
749 foreach (QWebElement element, emailCollection) {
750 element.setAttribute("value", m_email.toAscii());
753 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
754 foreach (QWebElement element, passwordCollection) {
755 element.setAttribute("value", m_password.toAscii());
757 // find connect button
758 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
759 foreach (QWebElement element, buttonCollection)
761 QPoint pos(element.geometry().center());
763 // send a mouse click event to the web page
764 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
766 QApplication::sendEvent(m_webView->page(), &event0);
767 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
769 QApplication::sendEvent(m_webView->page(), &event1);
775 void MainWindow::loggedIn(bool logged)
777 qDebug() << __PRETTY_FUNCTION__;
782 m_loginAct->setText(tr("Logout"));
788 m_loginAct->setText(tr("Login"));
790 updateItemVisibility();
793 void MainWindow::loginFailed()
795 qDebug() << __PRETTY_FUNCTION__;
801 bool MainWindow::loginState()
803 qDebug() << __PRETTY_FUNCTION__;
808 void MainWindow::loginUsingCookies()
810 qDebug() << __PRETTY_FUNCTION__;
812 toggleProgressIndicator(true);
817 QStringList urlParts;
818 urlParts.append(FACEBOOK_LOGINBASE);
819 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
820 urlParts.append(INTERVAL1);
821 urlParts.append(SITUARE_LOGIN_SUCCESS);
822 urlParts.append(INTERVAL2);
823 urlParts.append(SITUARE_LOGIN_FAILURE);
824 urlParts.append(FACEBOOK_LOGIN_ENDING);
826 m_webView->load(QUrl(urlParts.join(EMPTY)));
830 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
832 m_mapCenterHorizontalShifting = shifting;
836 void MainWindow::moveCrosshair()
838 qDebug() << __PRETTY_FUNCTION__;
841 int mapHeight = m_mapView->size().height();
842 int mapWidth = m_mapView->size().width();
843 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
844 - m_mapCenterHorizontalShifting,
845 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
849 void MainWindow::openSettingsDialog()
851 qDebug() << __PRETTY_FUNCTION__;
853 SettingsDialog *settingsDialog = new SettingsDialog(this);
854 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
855 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
857 settingsDialog->show();
860 void MainWindow::queueDialog(QDialog *dialog)
862 qDebug() << __PRETTY_FUNCTION__;
864 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
865 if(dialog->isModal()) {
866 m_error_queue.append(dialog);
868 m_queue.append(dialog);
871 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
872 if(m_error_queue.count() == 1 && m_errorShown == false)
873 showErrorInformationBox();
874 else if(m_queue.count() == 1 && m_errorShown == false)
875 showInformationBox();
878 void MainWindow::readAutomaticLocationUpdateSettings()
880 qDebug() << __PRETTY_FUNCTION__;
882 QSettings settings(DIRECTORY_NAME, FILE_NAME);
883 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
884 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
887 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
889 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
891 emit enableAutomaticLocationUpdate(false);
895 void MainWindow::saveCookies()
897 qDebug() << __PRETTY_FUNCTION__;
900 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
902 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
905 for(int i=0;i<cookieList.count();i++) {
906 QNetworkCookie cookie = cookieList.at(i);
907 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
908 list.append(QString(byteArray));
910 list.removeDuplicates();
912 QSettings settings(DIRECTORY_NAME, FILE_NAME);
913 settings.setValue(COOKIES, list);
916 void MainWindow::setCrosshairVisibility(bool visibility)
918 qDebug() << __PRETTY_FUNCTION__;
928 void MainWindow::setGPSButtonEnabled(bool enabled)
930 qDebug() << __PRETTY_FUNCTION__;
932 m_gpsToggleAct->setChecked(enabled);
935 void MainWindow::setIndicatorButtonEnabled(bool enabled)
937 qDebug() << __PRETTY_FUNCTION__;
939 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
942 void MainWindow::setMapViewScene(QGraphicsScene *scene)
944 qDebug() << __PRETTY_FUNCTION__;
946 m_mapView->setScene(scene);
949 void MainWindow::settingsDialogAccepted()
951 qDebug() << __PRETTY_FUNCTION__;
953 readAutomaticLocationUpdateSettings();
956 void MainWindow::setUsername(const QString &username)
958 qDebug() << __PRETTY_FUNCTION__;
963 void MainWindow::showContactDialog(const QString &guid)
965 qDebug() << __PRETTY_FUNCTION__ << guid;
967 #if defined(Q_WS_MAEMO_5) & defined(ARMEL)
968 OssoABookDialog::showContactDialog(guid);
972 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
974 qDebug() << __PRETTY_FUNCTION__;
976 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
977 tr("Automatic location update"), text,
978 QMessageBox::Yes | QMessageBox::No |
979 QMessageBox::Cancel, this);
980 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
981 this, SLOT(automaticUpdateDialogFinished(int)));
983 m_automaticUpdateLocationDialog->show();
986 void MainWindow::showErrorInformationBox()
988 qDebug() << __PRETTY_FUNCTION__;
990 if(m_error_queue.count()) {
992 QDialog *dialog = m_error_queue.first();
993 connect(dialog, SIGNAL(finished(int)),
994 this, SLOT(errorDialogFinished(int)));
999 void MainWindow::showInformationBox()
1001 qDebug() << __PRETTY_FUNCTION__;
1003 if(m_queue.count()) {
1004 QDialog *dialog = m_queue.first();
1005 connect(dialog, SIGNAL(finished(int)),
1006 this, SLOT(dialogFinished(int)));
1011 void MainWindow::startLocationSearch()
1013 qDebug() << __PRETTY_FUNCTION__;
1015 SearchDialog *searchDialog = new SearchDialog();
1016 queueDialog(searchDialog);
1019 void MainWindow::startLoginProcess()
1021 qDebug() << __PRETTY_FUNCTION__;
1023 LoginDialog *loginDialog = new LoginDialog();
1025 emit fetchUsernameFromSettings();
1027 loginDialog->clearTextFields();
1029 if(!m_email.isEmpty())
1030 loginDialog->setEmailField(m_email);
1032 queueDialog(loginDialog);
1035 void MainWindow::toggleFullScreen()
1037 qDebug() << __PRETTY_FUNCTION__;
1039 if(windowState() == Qt::WindowNoState)
1045 void MainWindow::toggleProgressIndicator(bool value)
1047 qDebug() << __PRETTY_FUNCTION__;
1051 m_progressIndicatorCount++;
1052 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1054 if(m_progressIndicatorCount > 0)
1055 m_progressIndicatorCount--;
1057 if(m_progressIndicatorCount == 0)
1058 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1062 #endif // Q_WS_MAEMO_5
1065 void MainWindow::updateItemVisibility()
1067 qDebug() << __PRETTY_FUNCTION__;
1069 m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, m_loggedIn);
1072 const QString MainWindow::username()
1074 qDebug() << __PRETTY_FUNCTION__;
1079 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1081 qDebug() << __PRETTY_FUNCTION__;
1083 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1084 // qwebview starts to load a new page while the current page loading is not finished
1085 if(reply->error() != QNetworkReply::OperationCanceledError &&
1086 reply->error() != QNetworkReply::NoError) {
1087 emit error(ErrorContext::NETWORK, reply->error());