Added confirmation dialog to automatic location update feature.
[situare] / src / ui / mainwindow.cpp
index 040a936..80dd084 100644 (file)
 #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 "mainwindow.h"
 
-// These MUST BE HERE, compiling fails under scratchbox if moved
+// 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;
@@ -55,8 +54,10 @@ MainWindow::MainWindow(QWidget *parent)
     m_drawOwnLocationCrosshair(false),
     m_loggedIn(false),
     m_refresh(false),
+    m_ownLocationCrosshair(0),
     m_email(),    
     m_password(),
+    m_fullScreenButton(0),
     m_webView(0),
     m_cookieJar(0)
 {
@@ -84,7 +85,11 @@ MainWindow::MainWindow(QWidget *parent)
 
     // 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);
 
@@ -106,6 +111,24 @@ MainWindow::~MainWindow()
         delete m_webView;
 }
 
+void MainWindow::automaticLocationUpdateEnabled(bool enabled)
+{
+    m_settingsDialog->setAutomaticLocationUpdateSettings(enabled);
+}
+
+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__;
@@ -153,10 +176,9 @@ void MainWindow::buildMap()
     m_mapView = new MapView(this);
 
     buildZoomButtonPanel();
-
-    m_ownLocationCrosshair = 0;
     buildOsmLicense();
     buildManualLocationCrosshair();
+    buildFullScreenButton();
 
     connect(m_mapView, SIGNAL(viewScrolled(QPoint)),
             this, SIGNAL(mapViewScrolled(QPoint)));
@@ -167,6 +189,9 @@ void MainWindow::buildMap()
     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)));
 
@@ -318,6 +343,17 @@ void MainWindow::createMenus()
     m_viewMenu->setObjectName(tr("Menu"));
 }
 
+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__ << size.width() << "x" << size.height();
@@ -325,7 +361,6 @@ void MainWindow::drawOsmLicense(const QSize &size)
     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)
@@ -338,13 +373,6 @@ void MainWindow::drawOwnLocationCrosshair(int width, int height)
     }
 }
 
-void MainWindow::gpsError(const QString &message)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    showMaemoInformationBox(message);
-}
-
 void MainWindow::gpsTimeout()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -491,8 +519,6 @@ void MainWindow::loginFailed()
 
     toggleProgressIndicator(false);
 
-    showMaemoInformationBox(tr("Invalid E-mail address or password"), true);
-
     QStringList urlParts;
     urlParts.append(FACEBOOK_LOGINBASE);
     urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
@@ -610,6 +636,20 @@ void MainWindow::setViewPortSize(int width, int height)
     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__;
@@ -627,6 +667,16 @@ void MainWindow::showMaemoInformationBox(const QString &message, bool modal)
 #endif
 }
 
+void MainWindow::toggleFullScreen()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if(windowState() == Qt::WindowNoState)
+        showFullScreen();
+    else
+        showNormal();
+}
+
 void MainWindow::startLoginProcess(const QUrl &url)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -655,6 +705,7 @@ void MainWindow::startLoginProcess(const QUrl &url)
     }
     else {
         loginDialog.userInput(m_email, m_password);
+        emit saveUsername(m_email);
         m_webView->load(url);
         toggleProgressIndicator(true);
         m_refresh = true;