#include <QtWebKit>
#include <QtAlgorithms>
-#include "common.h"
#include "facebookservice/facebookauthentication.h"
+#include "map/mapcommon.h"
+#include "map/mapview.h"
+#include "common.h"
#include "friendlistpanel.h"
+#include "fullscreenbutton.h"
+#include "indicatorbutton.h"
#include "logindialog.h"
-#include "map/mapview.h"
+#include "mapscale.h"
+#include "searchdialog.h"
#include "settingsdialog.h"
#include "userinfopanel.h"
#include "zoombuttonpanel.h"
-#include "mapscale.h"
#include "mainwindow.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_errorShown(false),
m_loggedIn(false),
m_refresh(false),
+ m_progressIndicatorCount(0),
m_ownLocationCrosshair(0),
- m_email(),
+ m_email(),
m_password(),
- m_fullScreenButton(0),
m_webView(0),
+ m_fullScreenButton(0),
+ m_indicatorButton(0),
m_mapScale(0),
m_cookieJar(0)
{
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(m_mapView);
layout->setMargin(0);
+ layout->setSpacing(0);
+
setCentralWidget(new QWidget());
centralWidget()->setLayout(layout);
buildFriendListPanel();
buildUserInfoPanel();
- m_settingsDialog = new SettingsDialog(this);
- m_settingsDialog->hide();
- connect(m_settingsDialog, SIGNAL(enableAutomaticLocationUpdate(bool,int)),
- this, SIGNAL(enableAutomaticLocationUpdate(bool,int)));
- m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
- tr("Automatic location update"), "",
- QMessageBox::Yes | QMessageBox::No |
- QMessageBox::Cancel, this);
- connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
- this, SLOT(automaticUpdateDialogFinished(int)));
-
createMenus();
setWindowTitle(tr("Situare"));
m_osmLicense->stackUnder(m_zoomButtonPanel);
}
m_ownLocationCrosshair->stackUnder(m_osmLicense);
- m_mapScale->stackUnder(m_ownLocationCrosshair);
+ m_indicatorButton->stackUnder(m_ownLocationCrosshair);
+ m_mapScale->stackUnder(m_indicatorButton);
m_mapView->stackUnder(m_mapScale);
- this->toggleProgressIndicator(true);
-
grabZoomKeys(true);
- // set screen size in desktop matching N900 screen size
- resize(N900_APP_WIDTH, N900_APP_HEIGHT);
+ // Set default screen size
+ resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5StackedWindow);
#endif
qDebug() << __PRETTY_FUNCTION__;
if (result == QMessageBox::Yes) {
- m_settingsDialog->setAutomaticLocationUpdateSettings(true);
- m_settingsDialog->emitAutomaticLocationUpdateSettings();
- }
- else {
- m_settingsDialog->setAutomaticLocationUpdateSettings(false);
- m_settingsDialog->emitAutomaticLocationUpdateSettings();
+ readAutomaticLocationUpdateSettings();
+ } else {
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
+ readAutomaticLocationUpdateSettings();
}
+
+ m_automaticUpdateLocationDialog->deleteLater();
}
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());
+ m_fullScreenButton = new FullScreenButton(this);
connect(m_fullScreenButton, SIGNAL(clicked()),
this, SLOT(toggleFullScreen()));
#endif // Q_WS_MAEMO_5
-
}
void MainWindow::buildFriendListPanel()
qDebug() << __PRETTY_FUNCTION__;
m_friendsListPanel = new FriendListPanel(this);
+
m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
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(this, SIGNAL(locationItemClicked(QList<QString>)),
+ m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
connect(m_mapView, SIGNAL(viewResized(QSize)),
- m_friendsListPanel, SLOT(screenResized(QSize)));
+ m_friendsListPanel, SLOT(resizePanel(QSize)));
- connect(this, SIGNAL(locationItemClicked(QList<QString>)),
- m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
+
+ connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
+ this, SIGNAL(findFriend(GeoCoordinate)));
+
+ connect(this, SIGNAL(friendImageReady(User*)),
+ m_friendsListPanel, SLOT(friendImageReady(User*)));
+
+ connect(this, SIGNAL(locationDataParsed(QList<Location>&)),
+ m_friendsListPanel, SLOT(locationDataReady(QList<Location>&)));
+
+ connect(m_friendsListPanel, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
+ this, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
+}
+
+void MainWindow::buildIndicatorButton()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_indicatorButton = new IndicatorButton(this);
+
+ connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
+ this, SIGNAL(autoCenteringTriggered(bool)));
connect(m_mapView, SIGNAL(viewResized(QSize)),
- m_friendsListPanelSidebar, SLOT(reDrawSidebar(QSize)));
+ m_indicatorButton, SLOT(screenResized(QSize)));
}
void MainWindow::buildInformationBox(const QString &message, bool modal)
buildOsmLicense();
buildManualLocationCrosshair();
buildFullScreenButton();
+ buildIndicatorButton();
buildMapScale();
- connect(m_mapView, SIGNAL(viewScrolled(QPoint)),
- this, SIGNAL(mapViewScrolled(QPoint)));
+ connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
+ this, SIGNAL(mapViewScrolled(SceneCoordinate)));
- connect(this, SIGNAL(centerToSceneCoordinates(QPoint)),
- m_mapView, SLOT(centerToSceneCoordinates(QPoint)));
+ connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
+ m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
connect(m_mapView, SIGNAL(viewResized(QSize)),
this, SIGNAL(mapViewResized(QSize)));
connect(m_mapView, SIGNAL(viewZoomFinished()),
this, SIGNAL(viewZoomFinished()));
+
+ connect(m_mapView, SIGNAL(zoomIn()),
+ this, SIGNAL(zoomIn()));
}
void MainWindow::buildMapScale()
qDebug() << __PRETTY_FUNCTION__;
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(this, SIGNAL(clearUpdateLocationDialogData()),
+ m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
- connect(m_userPanel, SIGNAL(refreshUserData()),
- this, SIGNAL(refreshUserData()));
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ m_userPanel, SLOT(resizePanel(QSize)));
connect(m_mapView, SIGNAL(viewResized(QSize)),
- m_userPanel, SLOT(screenResized(QSize)));
+ m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
- connect(this, SIGNAL(updateWasSuccessful()),
- m_userPanel, SIGNAL(updateWasSuccessful()));
+ connect(m_userPanel, SIGNAL(findUser(GeoCoordinate)),
+ this, SIGNAL(findUser(GeoCoordinate)));
- connect(this, SIGNAL(messageSendingFailed(int)),
- m_userPanel, SIGNAL(messageSendingFailed(int)));
+ connect(m_userPanel, SIGNAL(requestReverseGeo()),
+ this, SIGNAL(requestReverseGeo()));
+
+ connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
+ this, SIGNAL(statusUpdate(QString,bool)));
+
+ connect(m_userPanel, SIGNAL(refreshUserData()),
+ this, SIGNAL(refreshUserData()));
connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
this, SLOT(buildInformationBox(QString, bool)));
connect(m_mapView, SIGNAL(viewResized(QSize)),
m_zoomButtonPanel, SLOT(screenResized(QSize)));
+
}
void MainWindow::clearCookieJar()
buildWebView();
+ m_webView->stop();
+
if(!m_cookieJar) {
m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
}
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)));
+ /// @todo remove when not needed!
+ m_searchLocationAct = new QAction(tr("Location search"), this);
+ connect(m_searchLocationAct, SIGNAL(triggered()),
+ this, SLOT(startLocationSearch()));
// 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->addAction(m_searchLocationAct); /// @todo remove when not needed!
m_viewMenu->setObjectName(tr("Menu"));
}
QDialog *dialog = m_queue.takeFirst();
LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
+ SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
if(loginDialog) {
if(status != 0) {
buildWebView();
} else {
emit cancelLoginProcess();
}
+ } else if(searchDialog) {
+ if(status != 0) {
+ emit searchForLocation(searchDialog->input());
+ }
}
dialog->deleteLater();
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());
+ if(m_loggedIn) {
+ m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
+ - PANEL_PEEK_AMOUNT,
+ size.height() - m_fullScreenButton->size().height());
+ } else {
+ m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
+ size.height() - m_fullScreenButton->size().height());
+ }
}
}
void MainWindow::drawMapScale(const QSize &size)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
const int LEFT_SCALE_MARGIN = 10;
const int BOTTOM_SCALE_MARGIN = 2;
qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
m_cookieJar->setAllCookies(cookieList);
m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
-
}
}
m_loginAct->setText(tr("Login"));
}
- updateItemVisibility(m_loggedIn);
+ updateItemVisibility();
}
void MainWindow::loginFailed()
qDebug() << __PRETTY_FUNCTION__;
clearCookieJar();
+ startLoginProcess();
+}
- toggleProgressIndicator(false);
+bool MainWindow::loginState()
+{
+ qDebug() << __PRETTY_FUNCTION__;
- startLoginProcess();
+ return m_loggedIn;
}
void MainWindow::loginUsingCookies()
{
qDebug() << __PRETTY_FUNCTION__;
+ toggleProgressIndicator(true);
+
buildWebView();
loadCookies();
-
+
QStringList urlParts;
urlParts.append(FACEBOOK_LOGINBASE);
urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
{
qDebug() << __PRETTY_FUNCTION__;
- m_settingsDialog->enableSituareSettings(m_gpsToggleAct->isChecked() && m_loggedIn);
- m_settingsDialog->readSettings();
- m_settingsDialog->show();
+ SettingsDialog *settingsDialog = new SettingsDialog(this);
+ settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
+ connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
+
+ settingsDialog->show();
}
-void MainWindow::requestAutomaticLocationUpdateSettings()
+void MainWindow::readAutomaticLocationUpdateSettings()
{
qDebug() << __PRETTY_FUNCTION__;
- m_settingsDialog->readSettings();
- m_settingsDialog->emitAutomaticLocationUpdateSettings();
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
+ QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
+ .toTime();
+
+ if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
+ QTime time;
+ emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
+ } else {
+ emit enableAutomaticLocationUpdate(false);
+ }
}
void MainWindow::queueDialog(QDialog *dialog)
settings.setValue(COOKIES, list);
}
-void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
+void MainWindow::setGPSButtonEnabled(bool enabled)
{
qDebug() << __PRETTY_FUNCTION__;
- m_autoCenteringAct->setChecked(enabled);
+ m_gpsToggleAct->setChecked(enabled);
+
+ setOwnLocationCrosshairVisibility(!enabled);
}
-void MainWindow::setGPSButtonEnabled(bool enabled)
+void MainWindow::setIndicatorButtonEnabled(bool enabled)
{
qDebug() << __PRETTY_FUNCTION__;
- m_gpsToggleAct->setChecked(enabled);
-
- setOwnLocationCrosshairVisibility(!enabled);
+ m_indicatorButton->setChecked(enabled);
- m_autoCenteringAct->setVisible(enabled);
}
void MainWindow::setMapViewScene(QGraphicsScene *scene)
if (visibility && m_loggedIn) {
m_ownLocationCrosshair->show();
m_drawOwnLocationCrosshair = true;
- drawOwnLocationCrosshair(QSize(m_viewPortWidth, m_viewPortHeight));
+ drawOwnLocationCrosshair(m_viewPortSize);
} else {
m_ownLocationCrosshair->hide();
m_drawOwnLocationCrosshair = false;
}
}
+void MainWindow::settingsDialogAccepted()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ readAutomaticLocationUpdateSettings();
+}
+
void MainWindow::setUsername(const QString &username)
{
qDebug() << __PRETTY_FUNCTION__;
{
qDebug() << __PRETTY_FUNCTION__;
- m_viewPortWidth = size.width();
- m_viewPortHeight = size.height();
+ m_viewPortSize = size;
}
void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
{
qDebug() << __PRETTY_FUNCTION__;
- m_automaticUpdateLocationDialog->setText(text);
+ m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
+ tr("Automatic location update"), text,
+ QMessageBox::Yes | QMessageBox::No |
+ QMessageBox::Cancel, this);
+ connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
+ this, SLOT(automaticUpdateDialogFinished(int)));
+
m_automaticUpdateLocationDialog->show();
}
}
}
+void MainWindow::showPanels()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ drawFullScreenButton(m_viewPortSize);
+
+ if(m_loggedIn) {
+ if(!m_friendsListPanel->isVisible()) {
+ m_friendsListPanel->show();
+ m_friendsListPanelSidebar->show();
+ }
+
+ if(!m_userPanel->isVisible()) {
+ m_userPanel->show();
+ m_userPanelSidebar->show();
+ }
+ }
+}
+
+void MainWindow::startLocationSearch()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ SearchDialog *searchDialog = new SearchDialog();
+ queueDialog(searchDialog);
+}
+
void MainWindow::startLoginProcess()
{
qDebug() << __PRETTY_FUNCTION__;
qDebug() << __PRETTY_FUNCTION__;
#ifdef Q_WS_MAEMO_5
- setAttribute(Qt::WA_Maemo5ShowProgressIndicator, value);
+ if(value) {
+ m_progressIndicatorCount++;
+ setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+ } else {
+ if(m_progressIndicatorCount > 0)
+ m_progressIndicatorCount--;
+
+ if(m_progressIndicatorCount == 0)
+ setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+ }
#else
Q_UNUSED(value);
#endif // Q_WS_MAEMO_5
}
-void MainWindow::updateItemVisibility(bool show)
+void MainWindow::updateItemVisibility()
{
qDebug() << __PRETTY_FUNCTION__;
-
- if(show) {
- m_friendsListPanel->show();
- m_friendsListPanelSidebar->show();
- m_userPanel->show();
- m_userPanelSidebar->show();
- if(!m_gpsToggleAct->isChecked())
- setOwnLocationCrosshairVisibility(show);
+ if(m_loggedIn) {
+
+ if(!m_gpsToggleAct->isChecked())
+ setOwnLocationCrosshairVisibility(true);
} else {
m_friendsListPanel->closePanel();
m_friendsListPanel->hide();
const QString MainWindow::username()
{
qDebug() << __PRETTY_FUNCTION__;
-
+
return m_email;
}
{
qDebug() << __PRETTY_FUNCTION__;
- if(reply->error()) {
- emit error(reply->error());
- toggleProgressIndicator(false);
+ // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
+ // qwebview starts to load a new page while the current page loading is not finished
+ if(reply->error() != QNetworkReply::OperationCanceledError &&
+ reply->error() != QNetworkReply::NoError) {
+ emit error(ErrorContext::NETWORK, reply->error());
}
}
-