backup before review
[situare] / src / ui / mainwindow.cpp
index dd21e8a..fbc4d5f 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)
 {
@@ -74,12 +75,21 @@ MainWindow::MainWindow(QWidget *parent)
     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"));
 
     // 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);
 
@@ -101,6 +111,19 @@ 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__;
@@ -148,10 +171,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)));
@@ -162,6 +184,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)));
 
@@ -218,6 +243,15 @@ void MainWindow::buildUserInfoPanel()
 
     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()
@@ -313,6 +347,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();
@@ -320,7 +365,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)
@@ -333,13 +377,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__;
@@ -486,8 +523,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);
@@ -524,11 +559,8 @@ void MainWindow::openSettingsDialog()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    SettingsDialog *dialog = new SettingsDialog(this);
-    if(!m_loggedIn) {
-        dialog->disableSituareSettings();
-    }
-    dialog->show();
+    m_settingsDialog->enableSituareSettings(m_gpsToggleAct->isChecked() && m_loggedIn);
+    m_settingsDialog->show();
 }
 
 void MainWindow::saveCookies()
@@ -625,6 +657,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__;
@@ -653,6 +695,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;