X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fui%2Fmainwindow.cpp;h=fbc4d5f17288e3dfe52f1b7df056ccc0b2a954bc;hb=2b0eaa8f6793fde2f8c946f5e7c98ee84dec8b98;hp=1b87b6ff7916bcd10401a65ad03bf9aa9feef84e;hpb=d8ab20464217c4b771945f0a6f1ca150a709396f;p=situare diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 1b87b6f..fbc4d5f 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -26,10 +26,6 @@ #include #include -#ifdef Q_WS_MAEMO_5 -#include -#endif // Q_WS_MAEMO_5 - #include "common.h" #include "facebookservice/facebookauthentication.h" #include "friendlistpanel.h" @@ -41,9 +37,13 @@ #include "mainwindow.h" +// These MUST BE HERE, compiling for Maemo fails if moved +#ifdef Q_WS_MAEMO_5 +#include #include -#include #include +#include +#endif // Q_WS_MAEMO_5 // values for setting screen size in desktop matching N900 screen size const int N900_APP_WIDTH = 800; @@ -54,10 +54,12 @@ MainWindow::MainWindow(QWidget *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__; @@ -83,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); @@ -105,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__; @@ -152,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))); @@ -166,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))); @@ -222,6 +243,31 @@ 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() +{ + 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() @@ -249,6 +295,22 @@ void MainWindow::buildZoomButtonPanel() m_zoomButtonPanel, SLOT(screenResized(QSize))); } +void MainWindow::clearCookieJar() +{ + qDebug() << __PRETTY_FUNCTION__; + + buildWebView(); + + if(!m_cookieJar) { + m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this)); + } + QList emptyList; + emptyList.clear(); + + m_cookieJar->setAllCookies(emptyList); + m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar); +} + void MainWindow::createMenus() { qDebug() << __PRETTY_FUNCTION__; @@ -285,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(); @@ -292,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) @@ -305,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__; @@ -364,6 +429,29 @@ void MainWindow::keyPressEvent(QKeyEvent* event) 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 cookieList; + for(int i=0;isetAllCookies(cookieList); + m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar); + + } +} + void MainWindow::loadDone(bool done) { qDebug() << __PRETTY_FUNCTION__; @@ -418,54 +506,53 @@ void MainWindow::loggedIn(bool logged) m_loginAct->setText(tr("Logout")); } else { + clearCookieJar(); + m_email.clear(); + m_password.clear(); + m_loginAct->setText(tr("Login")); } - showPanels(m_loggedIn); -} - -void MainWindow::loginDialogDone(const QString &email, const QString &password) -{ - qDebug() << __PRETTY_FUNCTION__; - - m_email = email; - m_password = password; + 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_email.isEmpty()) { - m_loginDialog->setEmailField(m_email); - } +void MainWindow::loginUsingCookies() +{ + qDebug() << __PRETTY_FUNCTION__; - 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 &))); + 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() @@ -476,6 +563,27 @@ void MainWindow::openSettingsDialog() m_settingsDialog->show(); } +void MainWindow::saveCookies() +{ + qDebug() << __PRETTY_FUNCTION__; + + if(!m_cookieJar) + m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this)); + + QList cookieList = m_cookieJar->allCookies(); + QStringList list; + + for(int i=0;isetChecked(enabled); - setOwnLocationCrosshairVisibility(!enabled); + + if(m_loggedIn) + setOwnLocationCrosshairVisibility(!enabled); + m_autoCenteringAct->setVisible(enabled); } @@ -517,6 +628,7 @@ void MainWindow::setOwnLocationCrosshairVisibility(bool visibility) void MainWindow::setUsername(const QString &username) { qDebug() << __PRETTY_FUNCTION__; + m_email = username; } @@ -528,73 +640,63 @@ void MainWindow::setViewPortSize(int width, int height) 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::showPanels(bool show) +void MainWindow::toggleFullScreen() { qDebug() << __PRETTY_FUNCTION__; - if(show) { - m_friendsListPanel->show(); - m_friendsListPanelSidebar->show(); - m_userPanel->show(); - m_userPanelSidebar->show(); - } - else { - m_friendsListPanel->closePanel(); - m_friendsListPanel->hide(); - m_friendsListPanelSidebar->hide(); - m_userPanel->closePanel(); - m_userPanel->hide(); - m_userPanelSidebar->hide(); - } + + 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(); - connect(m_webView, SIGNAL(urlChanged(const QUrl &)), - this, SIGNAL(updateCredentials(QUrl))); - connect(m_webView, SIGNAL(loadFinished(bool)), - this, SLOT(loadDone(bool))); + LoginDialog loginDialog; - connect(m_loginDialog, SIGNAL(loginDialogDone(QString,QString)), - this, SLOT(loginDialogDone(QString,QString))); + emit fetchUsernameFromSettings(); - m_webView->hide(); + if(!m_cookieJar) + m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this)); - emit fetchUsernameFromSettings(); + m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar); - if(!m_email.isEmpty()) { - m_loginDialog->setEmailField(m_email); - } + 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; } @@ -611,8 +713,36 @@ void MainWindow::toggleProgressIndicator(bool 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; }