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 "mainwindow.h"
-#include "settingsdialog.h"
-#include "facebookservice/facebookauthentication.h"
#include "common.h"
-
+#include "facebookservice/facebookauthentication.h"
#include "friendlistpanel.h"
+#include "logindialog.h"
#include "map/mapview.h"
-#include "panelsidebar.h"
-#include "userpanel.h"
+#include "settingsdialog.h"
+#include "userinfopanel.h"
#include "zoombuttonpanel.h"
+#include "mainwindow.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_drawOwnLocationCrosshair(false),
+ m_loggedIn(false),
m_refresh(false),
+ m_ownLocationCrosshair(0),
m_email(),
m_password(),
- m_loginUrl(),
- m_webView(0)
+ m_fullScreenButton(0),
+ m_webView(0),
+ m_cookieJar(0)
{
qDebug() << __PRETTY_FUNCTION__;
buildFriendListPanel();
buildUserInfoPanel();
+ m_settingsDialog = new SettingsDialog(this);
+ m_settingsDialog->hide();
+ connect(m_settingsDialog, SIGNAL(enableAutomaticLocationUpdate(bool,int)),
+ this, SIGNAL(enableAutomaticLocationUpdate(bool,int)));
+
createMenus();
setWindowTitle(tr("Situare"));
- show();
-
- m_locationDialog = new UpdateLocationDialog(this);
// set stacking order of widgets
m_zoomButtonPanel->stackUnder(m_userPanel);
- m_osmLicense->stackUnder(m_zoomButtonPanel);
+ 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::buildFullScreenButton()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+#ifdef Q_WS_MAEMO_5
+ 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::buildFriendListPanel()
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_friendsListPanel = new FriendListPanel(this);
- PanelSideBar *friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
+ m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
- m_friendsListPanel->stackUnder(friendsListPanelSidebar);
+ 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(viewResizedNewSize(int, int)),
- m_friendsListPanel, SLOT(reDrawFriendsPanel(int, int)));
+ 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)),
- friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
+ m_friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
}
void MainWindow::buildManualLocationCrosshair()
{
+ qDebug() << __PRETTY_FUNCTION__;
+
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::buildMap()
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_mapView = new MapView(this);
buildZoomButtonPanel();
-
- m_ownLocationCrosshair = 0;
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)));
void MainWindow::buildOsmLicense()
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_osmLicense = new QLabel(this);
m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
m_osmLicense->fontMetrics().height());
- connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
- this, SLOT(drawOsmLicense(int, int)));
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ this, SLOT(drawOsmLicense(QSize)));
}
void MainWindow::buildUserInfoPanel()
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_userPanel = new UserInfoPanel(this);
- PanelSideBar *userPanelSidebar = new PanelSideBar(this, LEFT);
+ m_userPanelSidebar = new PanelSideBar(this, LEFT);
+
+ m_userPanelSidebar->stackUnder(m_friendsListPanel);
+ m_userPanel->stackUnder(m_userPanelSidebar);
- userPanelSidebar->stackUnder(m_friendsListPanel);
- m_userPanel->stackUnder(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(refreshUserData()),
this, SIGNAL(refreshUserData()));
- connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
- m_userPanel, SLOT(reDrawUserPanel(int, int)));
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ m_userPanel, SLOT(screenResized(QSize)));
+
+ connect(this, SIGNAL(updateWasSuccessful()),
+ m_userPanel, SIGNAL(updateWasSuccessful()));
+
+ connect(this, SIGNAL(messageSendingFailed(QString)),
+ m_userPanel, SIGNAL(messageSendingFailed(QString)));
+
+ connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString)),
+ this, SIGNAL(notificateUpdateFailing(QString)));
+}
+
+void MainWindow::buildWebView()
+{
+ 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::buildZoomButtonPanel()
{
- m_zoomButtonPanel = new ZoomButtonPanel(this, ZOOM_BUTTON_PANEL_POSITION_X,
- ZOOM_BUTTON_PANEL_POSITION_Y);
+ qDebug() << __PRETTY_FUNCTION__;
- connect(m_zoomButtonPanel->m_zoomInButton, SIGNAL(clicked()),
+ m_zoomButtonPanel = new ZoomButtonPanel(this);
+
+ connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
this, SIGNAL(zoomIn()));
- connect(m_zoomButtonPanel->m_zoomOutButton, SIGNAL(clicked()),
+ connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
this, SIGNAL(zoomOut()));
connect(this, SIGNAL(zoomLevelChanged(int)),
connect(this, SIGNAL(minZoomLevelReached()),
m_zoomButtonPanel, SLOT(disableZoomOutButton()));
+
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ m_zoomButtonPanel, SLOT(screenResized(QSize)));
+}
+
+void MainWindow::clearCookieJar()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ 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::createMenus()
{
qDebug() << __PRETTY_FUNCTION__;
+ // 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);
- m_toSettingsAct->setObjectName(tr("Settings"));
connect(m_toSettingsAct, SIGNAL(triggered()),
this, SLOT(openSettingsDialog()));
// 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::drawOsmLicense(int width, int height)
+void MainWindow::drawFullScreenButton(const QSize &size)
+{
+ qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
+
+ if(m_fullScreenButton) {
+ m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
+ - PANEL_PEEK_AMOUNT,
+ size.height() - m_fullScreenButton->size().height());
+ }
+}
+
+void MainWindow::drawOsmLicense(const QSize &size)
{
- qDebug() << __PRETTY_FUNCTION__ << width << "x" << height;
- m_osmLicense->move(width - m_osmLicense->fontMetrics().width(OSM_LICENSE) - PANEL_PEEK_AMOUNT,
- height - m_osmLicense->fontMetrics().height());
+ qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
+
+ m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
+ - PANEL_PEEK_AMOUNT,
+ size.height() - m_osmLicense->fontMetrics().height());
}
void MainWindow::drawOwnLocationCrosshair(int width, int height)
}
}
-void MainWindow::gpsError(const QString &message)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- showMaemoInformationBox(message);
-}
-
void MainWindow::gpsTimeout()
{
qDebug() << __PRETTY_FUNCTION__;
void MainWindow::grabZoomKeys(bool grab)
{
qDebug() << __PRETTY_FUNCTION__;
+
#ifdef Q_WS_MAEMO_5
// Can't grab keys unless we have a window id
if (!winId())
QWidget::keyPressEvent(event);
}
+void MainWindow::loadCookies()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+
+ QStringList list = settings.value(COOKIES, EMPTY).toStringList();
+
+ if(!list.isEmpty()) {
+ QList<QNetworkCookie> cookieList;
+ for(int i=0;i<list.count();i++) {
+ cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
+ }
+
+ if(!m_cookieJar)
+ m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+
+ m_cookieJar->setAllCookies(cookieList);
+ m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
+
+ }
+}
+
void MainWindow::loadDone(bool done)
{
qDebug() << __PRETTY_FUNCTION__;
}
}
-void MainWindow::loginDialogDone(const QString &email, const QString &password)
+void MainWindow::loggedIn(bool logged)
{
qDebug() << __PRETTY_FUNCTION__;
- m_email = email;
- m_password = password;
+ m_loggedIn = logged;
+
+ 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__;
- m_email.clear();
- m_password.clear();
+ clearCookieJar();
toggleProgressIndicator(false);
-#ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::information(this, tr("Invalid E-mail address or password"),
- QMaemo5InformationBox::NoTimeout);
+ 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);
-#endif // Q_WS_MAEMO_5
+ startLoginProcess(urlParts.join(EMPTY));
+}
- 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 &)));
+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)));
- emit cancelLoginProcess();
- }
- else {
- // re-load login page for webview
- toggleProgressIndicator(true);
- m_webView->load(m_loginUrl);
- }
}
void MainWindow::openSettingsDialog()
{
qDebug() << __PRETTY_FUNCTION__;
- SettingsDialog *dialog = new SettingsDialog(this);
- dialog->show();
+
+ 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)
m_gpsToggleAct->setChecked(enabled);
- if (enabled)
- setOwnLocationCrosshairVisibility(false);
- else
- setOwnLocationCrosshairVisibility(true);
+ 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;
}
}
+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;
}
-void MainWindow::showMaemoInformationBox(const QString &message)
+void MainWindow::showMaemoInformationBox(const QString &message, bool modal)
{
qDebug() << __PRETTY_FUNCTION__;
#ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::DefaultTimeout);
+ if(modal) {
+ QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::NoTimeout);
+ }
+ else {
+ QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::DefaultTimeout);
+ }
#else
- Q_UNUSED(message);
+ Q_UNUSED(modal);
+ QMessageBox::information(this, tr("Situare"), message, QMessageBox::Ok);
#endif
}
+void MainWindow::toggleFullScreen()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if(windowState() == Qt::WindowNoState)
+ showFullScreen();
+ else
+ showNormal();
+}
+
void MainWindow::startLoginProcess(const QUrl &url)
{
qDebug() << __PRETTY_FUNCTION__;
- m_loginUrl = url;
- m_webView = new QWebView;
- m_loginDialog = new LoginDialog(this);
+ buildWebView();
+
+ LoginDialog loginDialog;
+
+ emit fetchUsernameFromSettings();
- connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
- this, SIGNAL(updateCredentials(QUrl)));
- connect(m_webView, SIGNAL(loadFinished(bool)),
- this, SLOT(loadDone(bool)));
+ if(!m_cookieJar)
+ m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
- connect(m_loginDialog, SIGNAL(loginDialogDone(QString,QString)),
- this, SLOT(loginDialogDone(QString,QString)));
+ m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
- m_webView->hide();
+ loginDialog.clearTextFields();
- if(m_loginDialog->exec() != QDialog::Accepted) {
+ if(!m_email.isEmpty())
+ loginDialog.setEmailField(m_email);
+
+ if(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 &)));
emit cancelLoginProcess();
}
else {
- m_webView->load(m_loginUrl);
+ 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;
+}