Henri Lampela - henri.lampela@ixonos.com
Kaj Wallin - kaj.wallin@ixonos.com
Jussi Laitinen jussi.laitinen@ixonos.com
+ Sami Rämö - sami.ramo@ixonos.com
+ Ville Tiensuu - ville.tiensuu@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
*/
#include <QtGui>
+#include <QtWebKit>
-#ifdef Q_WS_MAEMO_5
-#include <QtMaemo5/QMaemo5InformationBox>
-#endif // Q_WS_MAEMO_5
+#include "common.h"
+#include "facebookservice/facebookauthentication.h"
+#include "friendlistpanel.h"
+#include "logindialog.h"
+#include "map/mapview.h"
+#include "settingsdialog.h"
+#include "userinfopanel.h"
+#include "zoombuttonpanel.h"
#include "mainwindow.h"
-#include "mapviewscreen.h"
-#include "settingsdialog.h"
-#include "facebookservice/facebookauthentication.h"
-#include "situarecommon.h"
+// These MUST BE HERE, compiling for Maemo fails if moved
+#ifdef Q_WS_MAEMO_5
+#include <QtMaemo5/QMaemo5InformationBox>
#include <QtGui/QX11Info>
-#include <X11/Xlib.h>
#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+#endif // Q_WS_MAEMO_5
+
+// values for setting screen size in desktop matching N900 screen size
+const int N900_APP_WIDTH = 800;
+const int N900_APP_HEIGHT = 449;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
- m_email(),
- m_loginUrl(),
+ m_drawOwnLocationCrosshair(false),
+ m_loggedIn(false),
+ m_refresh(false),
+ m_ownLocationCrosshair(0),
+ m_email(),
m_password(),
- m_refresh(0),
- m_webView(0)
+ m_fullScreenButton(0),
+ m_webView(0),
+ m_cookieJar(0)
{
qDebug() << __PRETTY_FUNCTION__;
- m_mapViewScreen = new MapViewScreen(this);
- setCentralWidget(m_mapViewScreen);
- createMenus();
- setWindowTitle(tr("Situare"));
- show();
+ buildMap();
- m_locationDialog = new UpdateLocationDialog(this);
+ // build main layout
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(m_mapView);
+ layout->setMargin(0);
+ setCentralWidget(new QWidget());
+ centralWidget()->setLayout(layout);
- connect(this, SIGNAL(reverseGeoReady(QString)),
- m_locationDialog, SLOT(setAddress(QString)));
- connect(m_locationDialog, SIGNAL(statusUpdate(QString, bool)),
- this, SIGNAL(statusUpdate(QString, bool)));
+ buildFriendListPanel();
+ buildUserInfoPanel();
- connect(this, SIGNAL(userLocationReady(User*)),
- m_mapViewScreen, SIGNAL(userLocationReady(User*)));
- connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
- m_mapViewScreen, SIGNAL(friendsLocationsReady(QList<User*>&)));
+ m_settingsDialog = new SettingsDialog(this);
+ m_settingsDialog->hide();
+ connect(m_settingsDialog, SIGNAL(enableAutomaticLocationUpdate(bool,int)),
+ this, SIGNAL(enableAutomaticLocationUpdate(bool,int)));
- connect(this, SIGNAL(autoCentering(bool)),
- m_mapViewScreen, SLOT(enableAutoCentering(bool)));
- connect(this, SIGNAL(positionReceived(QPointF, qreal)),
- m_mapViewScreen, SLOT(positionReceived(QPointF, qreal)));
- connect(m_mapViewScreen, SIGNAL(mapLocationChanged()),
- this, SLOT(mapLocationChanged()));
+ createMenus();
+ setWindowTitle(tr("Situare"));
- connect(this, SIGNAL(zoomInKeyPressed()),
- m_mapViewScreen, SIGNAL(zoomInKeyPressed()));
- connect(this, SIGNAL(zoomOutKeyPressed()),
- m_mapViewScreen, SIGNAL(zoomOutKeyPressed()));
+ // set stacking order of widgets
+ m_zoomButtonPanel->stackUnder(m_userPanel);
+ if(m_fullScreenButton) {
+ m_fullScreenButton->stackUnder(m_zoomButtonPanel);
+ m_osmLicense->stackUnder(m_fullScreenButton);
+ } else
+ m_osmLicense->stackUnder(m_zoomButtonPanel);
+ m_ownLocationCrosshair->stackUnder(m_osmLicense);
+ m_mapView->stackUnder(m_ownLocationCrosshair);
this->toggleProgressIndicator(true);
grabZoomKeys(true);
+
+ // set screen size in desktop matching N900 screen size
+ resize(N900_APP_WIDTH, N900_APP_HEIGHT);
}
MainWindow::~MainWindow()
delete m_webView;
}
-void MainWindow::toggleProgressIndicator(bool value)
+void MainWindow::automaticLocationUpdateEnabled(bool enabled)
+{
+ m_settingsDialog->setAutomaticLocationUpdateSettings(enabled);
+}
+
+void MainWindow::buildFullScreenButton()
{
qDebug() << __PRETTY_FUNCTION__;
#ifdef Q_WS_MAEMO_5
- setAttribute(Qt::WA_Maemo5ShowProgressIndicator, value);
-#else
- Q_UNUSED(value);
+ m_fullScreenButton = new QToolButton(this);
+ m_fullScreenButton->setIcon(QIcon::fromTheme(QLatin1String("general_fullsize")));
+ m_fullScreenButton->setFixedSize(m_fullScreenButton->sizeHint());
+ connect(m_fullScreenButton, SIGNAL(clicked()),
+ this, SLOT(toggleFullScreen()));
#endif // Q_WS_MAEMO_5
+
}
-void MainWindow::createMenus()
+void MainWindow::buildFriendListPanel()
{
qDebug() << __PRETTY_FUNCTION__;
- m_toSettingsAct = new QAction(tr("Settings"), this);
- m_toSettingsAct->setObjectName(tr("Settings"));
- connect(m_toSettingsAct, SIGNAL(triggered()),
- this, SLOT(openSettingsDialog()));
- m_gpsToggleAct = new QAction(tr("GPS"), this);
- m_gpsToggleAct->setCheckable(true);
- m_gpsToggleAct->setChecked(true);
- connect(m_gpsToggleAct, SIGNAL(toggled(bool)),
- this, SLOT(gpsActionToggled(bool)));
- m_autoCenteringAct = new QAction(tr("Auto centering"), this);
- m_autoCenteringAct->setCheckable(true);
- m_autoCenteringAct->setChecked(true);
- connect(m_autoCenteringAct, SIGNAL(toggled(bool)),
- this, SLOT(autoCenteringToggled(bool)));
-
- m_viewMenu = menuBar()->addMenu(tr("Main"));
+ m_friendsListPanel = new FriendListPanel(this);
+ m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
- m_viewMenu->addAction(m_toSettingsAct);
- m_viewMenu->addAction(m_gpsToggleAct);
- m_viewMenu->addAction(m_autoCenteringAct);
- m_viewMenu->setObjectName(tr("Menu"));
+ m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
+
+ connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
+ m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
+
+ connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
+ this, SIGNAL(findFriend(QPointF)));
+
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ m_friendsListPanel, SLOT(screenResized(QSize)));
+
+ connect(this, SIGNAL(locationItemClicked(QList<QString>)),
+ m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
+
+ connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
+ m_friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
}
-void MainWindow::openLocationUpdateDialog()
+void MainWindow::buildManualLocationCrosshair()
{
qDebug() << __PRETTY_FUNCTION__;
- emit requestReverseGeo();
- m_locationDialog->exec();
+ m_ownLocationCrosshair = new QLabel(this);
+ QPixmap crosshairImage(":/res/images/sight.png");
+ m_ownLocationCrosshair->setPixmap(crosshairImage);
+ m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
+ m_ownLocationCrosshair->hide();
+ m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
+
+ connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
+ this, SLOT(drawOwnLocationCrosshair(int, int)));
}
-void MainWindow::openSettingsDialog()
+void MainWindow::buildMap()
{
qDebug() << __PRETTY_FUNCTION__;
- SettingsDialog *dialog = new SettingsDialog(this);
- dialog->show();
+
+ m_mapView = new MapView(this);
+
+ buildZoomButtonPanel();
+ buildOsmLicense();
+ buildManualLocationCrosshair();
+ buildFullScreenButton();
+
+ connect(m_mapView, SIGNAL(viewScrolled(QPoint)),
+ this, SIGNAL(mapViewScrolled(QPoint)));
+
+ connect(this, SIGNAL(centerToSceneCoordinates(QPoint)),
+ m_mapView, SLOT(centerToSceneCoordinates(QPoint)));
+
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ this, SIGNAL(mapViewResized(QSize)));
+
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ this, SLOT(drawFullScreenButton(QSize)));
+
+ connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
+ this, SLOT(setViewPortSize(int, int)));
+
+ connect(this, SIGNAL(zoomLevelChanged(int)),
+ m_mapView, SLOT(setZoomLevel(int)));
+
+ connect(m_mapView, SIGNAL(viewZoomFinished()),
+ this, SIGNAL(viewZoomFinished()));
}
-void MainWindow::gpsToggled(bool checked)
+void MainWindow::buildOsmLicense()
{
qDebug() << __PRETTY_FUNCTION__;
- if (checked)
- emit enableGPS(true);
- else
- emit enableGPS(false);
+ m_osmLicense = new QLabel(this);
+ m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
+ m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
+ m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
+ m_osmLicense->setFont(QFont("Nokia Sans", 9));
+ m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
+ m_osmLicense->fontMetrics().height());
+
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ this, SLOT(drawOsmLicense(QSize)));
}
-void MainWindow::setGPSButton(bool enabled)
+void MainWindow::buildUserInfoPanel()
{
qDebug() << __PRETTY_FUNCTION__;
- if (enabled) {
- showMaemoInformationBox(tr("GPS enabled"));
- m_gpsToggleAct->setChecked(true);
- m_autoCenteringAct->setVisible(true);
- }
- else {
- showMaemoInformationBox(tr("GPS disabled"));
- m_gpsToggleAct->setChecked(false);
- m_autoCenteringAct->setVisible(false);
- }
+ m_userPanel = new UserInfoPanel(this);
+ m_userPanelSidebar = new PanelSideBar(this, LEFT);
+
+ m_userPanelSidebar->stackUnder(m_friendsListPanel);
+ m_userPanel->stackUnder(m_userPanelSidebar);
+
+ connect(m_userPanel, SIGNAL(findUser(QPointF)),
+ this, SIGNAL(findUser(QPointF)));
+
+ connect(this, SIGNAL(userLocationReady(User*)),
+ m_userPanel, SLOT(userDataReceived(User*)));
+
+ connect(m_userPanel, SIGNAL(requestReverseGeo()),
+ this, SIGNAL(requestReverseGeo()));
+
+ connect(this, SIGNAL(reverseGeoReady(QString)),
+ m_userPanel, SIGNAL(reverseGeoReady(QString)));
+
+ connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
+ this, SIGNAL(statusUpdate(QString,bool)));
+
+ connect(m_userPanel, SIGNAL(refreshUserData()),
+ this, SIGNAL(refreshUserData()));
+
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ m_userPanel, SLOT(screenResized(QSize)));
}
-void MainWindow::setAutoCenteringButton(bool enabled)
+void MainWindow::buildWebView()
{
- if (enabled) {
- showMaemoInformationBox(tr("Auto centering enabled"));
- m_autoCenteringAct->setChecked(true);
- }
- else {
- showMaemoInformationBox(tr("Auto centering disabled"));
- m_autoCenteringAct->setChecked(false);
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if(!m_webView) {
+ m_webView = new QWebView;
+
+ connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
+ this, SIGNAL(updateCredentials(QUrl)));
+ connect(m_webView, SIGNAL(loadFinished(bool)),
+ this, SLOT(loadDone(bool)));
+
+ m_webView->hide();
}
}
-void MainWindow::gpsTimeout()
+void MainWindow::buildZoomButtonPanel()
{
qDebug() << __PRETTY_FUNCTION__;
- showMaemoInformationBox(tr("GPS timeout"));
+ m_zoomButtonPanel = new ZoomButtonPanel(this);
+
+ connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
+ this, SIGNAL(zoomIn()));
+
+ connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
+ this, SIGNAL(zoomOut()));
+
+ connect(this, SIGNAL(zoomLevelChanged(int)),
+ m_zoomButtonPanel, SLOT(resetButtons()));
+
+ connect(this, SIGNAL(maxZoomLevelReached()),
+ m_zoomButtonPanel, SLOT(disableZoomInButton()));
+
+ connect(this, SIGNAL(minZoomLevelReached()),
+ m_zoomButtonPanel, SLOT(disableZoomOutButton()));
+
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ m_zoomButtonPanel, SLOT(screenResized(QSize)));
}
-void MainWindow::gpsError(const QString &message)
+void MainWindow::clearCookieJar()
{
qDebug() << __PRETTY_FUNCTION__;
- showMaemoInformationBox(message);
+ buildWebView();
+
+ if(!m_cookieJar) {
+ m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+ }
+ QList<QNetworkCookie> emptyList;
+ emptyList.clear();
+
+ m_cookieJar->setAllCookies(emptyList);
+ m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
}
-void MainWindow::mapLocationChanged()
+void MainWindow::createMenus()
{
qDebug() << __PRETTY_FUNCTION__;
- emit enableAutoCentering(false);
+ // login/logout
+ m_loginAct = new QAction(tr("Login"), this);
+ connect(m_loginAct, SIGNAL(triggered()),
+ this, SIGNAL(loginActionPressed()));
+
+ // settings
+ m_toSettingsAct = new QAction(tr("Settings"), this);
+ connect(m_toSettingsAct, SIGNAL(triggered()),
+ this, SLOT(openSettingsDialog()));
+
+ // GPS
+ m_gpsToggleAct = new QAction(tr("GPS"), this);
+ m_gpsToggleAct->setCheckable(true);
+
+ connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
+ this, SIGNAL(gpsTriggered(bool)));
+
+ // automatic centering
+ m_autoCenteringAct = new QAction(tr("Auto centering"), this);
+ m_autoCenteringAct->setCheckable(true);
+ connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
+ this, SIGNAL(autoCenteringTriggered(bool)));
+
+ // build the actual menu
+ m_viewMenu = menuBar()->addMenu(tr("Main"));
+ m_viewMenu->addAction(m_loginAct);
+ m_viewMenu->addAction(m_toSettingsAct);
+ m_viewMenu->addAction(m_gpsToggleAct);
+ m_viewMenu->addAction(m_autoCenteringAct);
+ m_viewMenu->setObjectName(tr("Menu"));
}
-void MainWindow::autoCenteringToggled(bool checked)
+void MainWindow::drawFullScreenButton(const QSize &size)
{
- qDebug() << __PRETTY_FUNCTION__ << checked;
+ qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
- if (checked)
- emit enableAutoCentering(true);
- else
- emit enableAutoCentering(false);
+ if(m_fullScreenButton) {
+ m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
+ - PANEL_PEEK_AMOUNT,
+ size.height() - m_fullScreenButton->size().height());
+ }
}
-void MainWindow::autoCenteringEnabled(bool enabled)
+void MainWindow::drawOsmLicense(const QSize &size)
{
- qDebug() << __PRETTY_FUNCTION__ << enabled;
+ qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
- emit autoCentering(enabled);
+ m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
+ - PANEL_PEEK_AMOUNT,
+ size.height() - m_osmLicense->fontMetrics().height());
}
-void MainWindow::showMaemoInformationBox(const QString &message)
+void MainWindow::drawOwnLocationCrosshair(int width, int height)
{
qDebug() << __PRETTY_FUNCTION__;
-#ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::DefaultTimeout);
-#else
- Q_UNUSED(message);
-#endif
+ if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
+ m_ownLocationCrosshair->move(width/2 - m_ownLocationCrosshair->pixmap()->width()/2,
+ height/2 - m_ownLocationCrosshair->pixmap()->height()/2);
+ }
}
-void MainWindow::startLoginProcess(const QUrl &url)
+void MainWindow::gpsTimeout()
{
qDebug() << __PRETTY_FUNCTION__;
- m_loginUrl = url;
- m_webView = new QWebView;
- m_loginDialog = new LoginDialog(this);
-
- connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
- this, SIGNAL(updateCredentials(QUrl)));
- connect(m_webView, SIGNAL(loadFinished(bool)),
- this, SLOT(loadDone(bool)));
+ showMaemoInformationBox(tr("GPS timeout"));
+}
- connect(m_loginDialog, SIGNAL(loginDialogDone(QString,QString)),
- this, SLOT(loginDialogDone(QString,QString)));
+void MainWindow::grabZoomKeys(bool grab)
+{
+ qDebug() << __PRETTY_FUNCTION__;
- m_webView->hide();
+#ifdef Q_WS_MAEMO_5
+ // Can't grab keys unless we have a window id
+ if (!winId())
+ return;
- if(m_loginDialog->exec() != QDialog::Accepted) {
- // if login dialog was canceled we need to stop processing webview
- // stop and disconnect m_webView;
- m_webView->stop();
- disconnect(m_webView, SIGNAL(loadFinished(bool)),
- this, SLOT(loadDone(bool)));
- disconnect(m_webView, SIGNAL(urlChanged(const QUrl &)),
- this, SLOT(updateCredentials(const QUrl &)));
+ unsigned long val = (grab) ? 1 : 0;
+ Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
+ if (!atom)
+ return;
- emit cancelLoginProcess();
- }
- else {
- m_webView->load(m_loginUrl);
- toggleProgressIndicator(true);
- m_refresh = true;
- }
+ XChangeProperty (QX11Info::display(),
+ winId(),
+ atom,
+ XA_INTEGER,
+ 32,
+ PropModeReplace,
+ reinterpret_cast<unsigned char *>(&val),
+ 1);
+#else
+ Q_UNUSED(grab);
+#endif // Q_WS_MAEMO_5
}
-void MainWindow::loginDialogDone(const QString &email, const QString &password)
+void MainWindow::keyPressEvent(QKeyEvent* event)
{
qDebug() << __PRETTY_FUNCTION__;
- m_email = email;
- m_password = password;
+ switch (event->key()) {
+ case Qt::Key_F7:
+ event->accept();
+ emit zoomIn();
+ break;
+
+ case Qt::Key_F8:
+ event->accept();
+ emit zoomOut();
+ break;
+ }
+ QWidget::keyPressEvent(event);
}
-void MainWindow::loginFailed()
+void MainWindow::loadCookies()
{
qDebug() << __PRETTY_FUNCTION__;
- m_email.clear();
- m_password.clear();
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
- toggleProgressIndicator(false);
+ QStringList list = settings.value(COOKIES, EMPTY).toStringList();
-#ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::information(this, tr("Invalid E-mail address or password"),
- QMaemo5InformationBox::NoTimeout);
+ if(!list.isEmpty()) {
+ QList<QNetworkCookie> cookieList;
+ for(int i=0;i<list.count();i++) {
+ cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
+ }
-#endif // Q_WS_MAEMO_5
+ if(!m_cookieJar)
+ m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
- if(m_loginDialog->exec() != QDialog::Accepted) {
- // if login dialog was canceled we need to stop processing webview
- // stop and disconnect m_webView;
- m_webView->stop();
- disconnect(m_webView, SIGNAL(loadFinished(bool)),
- this, SLOT(loadDone(bool)));
- disconnect(m_webView, SIGNAL(urlChanged(const QUrl &)),
- this, SLOT(updateCredentials(const QUrl &)));
+ m_cookieJar->setAllCookies(cookieList);
+ m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
- emit cancelLoginProcess();
- }
- else {
- // re-load login page for webview
- toggleProgressIndicator(true);
- m_webView->load(m_loginUrl);
}
}
}
}
-void MainWindow::grabZoomKeys(bool grab)
+void MainWindow::loggedIn(bool logged)
{
qDebug() << __PRETTY_FUNCTION__;
-#ifdef Q_WS_MAEMO_5
- // Can't grab keys unless we have a window id
- if (!winId())
- return;
- unsigned long val = (grab) ? 1 : 0;
- Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
- if (!atom)
- return;
+ m_loggedIn = logged;
- XChangeProperty (QX11Info::display(),
- winId(),
- atom,
- XA_INTEGER,
- 32,
- PropModeReplace,
- reinterpret_cast<unsigned char *>(&val),
- 1);
+ if(logged) {
+ m_loginAct->setText(tr("Logout"));
+ }
+ else {
+ clearCookieJar();
+ m_email.clear();
+ m_password.clear();
+
+ m_loginAct->setText(tr("Login"));
+ }
+ updateItemVisibility(m_loggedIn);
+}
+
+void MainWindow::loginFailed()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ clearCookieJar();
+
+ toggleProgressIndicator(false);
+
+ QStringList urlParts;
+ urlParts.append(FACEBOOK_LOGINBASE);
+ urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
+ urlParts.append(INTERVAL1);
+ urlParts.append(SITUARE_LOGIN_SUCCESS);
+ urlParts.append(INTERVAL2);
+ urlParts.append(SITUARE_LOGIN_FAILURE);
+ urlParts.append(FACEBOOK_LOGIN_ENDING);
+
+ startLoginProcess(urlParts.join(EMPTY));
+}
+
+void MainWindow::loginUsingCookies()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ buildWebView();
+ loadCookies();
+
+ QStringList urlParts;
+ urlParts.append(FACEBOOK_LOGINBASE);
+ urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
+ urlParts.append(INTERVAL1);
+ urlParts.append(SITUARE_LOGIN_SUCCESS);
+ urlParts.append(INTERVAL2);
+ urlParts.append(SITUARE_LOGIN_FAILURE);
+ urlParts.append(FACEBOOK_LOGIN_ENDING);
+
+ m_webView->load(QUrl(urlParts.join(EMPTY)));
+
+}
+
+void MainWindow::openSettingsDialog()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_settingsDialog->enableSituareSettings(m_gpsToggleAct->isChecked() && m_loggedIn);
+ m_settingsDialog->show();
+}
+
+void MainWindow::saveCookies()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if(!m_cookieJar)
+ m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+
+ QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
+ QStringList list;
+
+ for(int i=0;i<cookieList.count();i++) {
+ QNetworkCookie cookie = cookieList.at(i);
+ QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
+ list.append(QString(byteArray));
+ }
+ list.removeDuplicates();
+
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ settings.setValue(COOKIES, list);
+}
+
+void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_autoCenteringAct->setChecked(enabled);
+}
+
+void MainWindow::setGPSButtonEnabled(bool enabled)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_gpsToggleAct->setChecked(enabled);
+
+ if(m_loggedIn)
+ setOwnLocationCrosshairVisibility(!enabled);
+
+ m_autoCenteringAct->setVisible(enabled);
+}
+
+void MainWindow::setMapViewScene(QGraphicsScene *scene)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_mapView->setScene(scene);
+}
+
+void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (visibility) {
+ m_ownLocationCrosshair->show();
+ m_drawOwnLocationCrosshair = true;
+ drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
+ }
+ else {
+ m_ownLocationCrosshair->hide();
+ m_drawOwnLocationCrosshair = false;
+ }
+}
+
+void MainWindow::setUsername(const QString &username)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_email = username;
+}
+
+void MainWindow::setViewPortSize(int width, int height)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_viewPortWidth = width;
+ m_viewPortHeight = height;
+}
+
+bool MainWindow::showEnableAutomaticUpdateLocationDialog()
+{
+ QMessageBox msgBox(QMessageBox::Warning, tr("Automatic location update"),
+ tr("Are you sure you want to enable automatic location update?"),
+ QMessageBox::Ok | QMessageBox::Cancel, 0);
+ msgBox.button(QMessageBox::Ok)->setText(tr("Ok"));
+ int ret = msgBox.exec();
+
+ if (ret == QMessageBox::Ok)
+ return true;
+ else
+ return false;
+}
+
+void MainWindow::showMaemoInformationBox(const QString &message, bool modal)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+#ifdef Q_WS_MAEMO_5
+ if(modal) {
+ QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::NoTimeout);
+ }
+ else {
+ QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::DefaultTimeout);
+ }
#else
- Q_UNUSED(grab);
-#endif // Q_WS_MAEMO_5
+ Q_UNUSED(modal);
+ QMessageBox::information(this, tr("Situare"), message, QMessageBox::Ok);
+#endif
}
-void MainWindow::keyPressEvent(QKeyEvent* event)
+void MainWindow::toggleFullScreen()
{
qDebug() << __PRETTY_FUNCTION__;
- switch (event->key()) {
- case Qt::Key_F7:
- event->accept();
- emit zoomInKeyPressed();
- break;
+ if(windowState() == Qt::WindowNoState)
+ showFullScreen();
+ else
+ showNormal();
+}
- case Qt::Key_F8:
- event->accept();
- emit zoomOutKeyPressed();
- break;
+void MainWindow::startLoginProcess(const QUrl &url)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ buildWebView();
+
+ LoginDialog loginDialog;
+
+ emit fetchUsernameFromSettings();
+
+ if(!m_cookieJar)
+ m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+
+ m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
+
+ loginDialog.clearTextFields();
+
+ if(!m_email.isEmpty())
+ loginDialog.setEmailField(m_email);
+
+ if(loginDialog.exec() != QDialog::Accepted) {
+ // if login dialog was canceled we need to stop processing webview
+ m_webView->stop();
+
+ emit cancelLoginProcess();
}
- QWidget::keyPressEvent(event);
+ else {
+ loginDialog.userInput(m_email, m_password);
+ emit saveUsername(m_email);
+ m_webView->load(url);
+ toggleProgressIndicator(true);
+ m_refresh = true;
+ }
+}
+
+void MainWindow::toggleProgressIndicator(bool value)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+#ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_Maemo5ShowProgressIndicator, value);
+#else
+ Q_UNUSED(value);
+#endif // Q_WS_MAEMO_5
+}
+
+void MainWindow::updateItemVisibility(bool show)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if(show) {
+ m_friendsListPanel->show();
+ m_friendsListPanelSidebar->show();
+ m_userPanel->show();
+ m_userPanelSidebar->show();
+
+ if(m_drawOwnLocationCrosshair) {
+ m_ownLocationCrosshair->show();
+ setGPSButtonEnabled(false);
+ emit gpsTriggered(false);
+ }
+ }
+ else {
+ m_friendsListPanel->closePanel();
+ m_friendsListPanel->hide();
+ m_friendsListPanelSidebar->hide();
+ m_userPanel->closePanel();
+ m_userPanel->hide();
+ m_userPanelSidebar->hide();
+ m_ownLocationCrosshair->hide();
+ }
+}
+
+const QString MainWindow::username()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ return m_email;
}