X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fui%2Fmainwindow.cpp;fp=src%2Fui%2Fmainwindow.cpp;h=843a430df0c7bcc20ad735755907f353715c33e5;hb=5b75ad801a71bb74fc9e4dbe6377afb333ce12bf;hp=5082bdc2bb4265e2f5f28f83accb14c479138aee;hpb=0abe2f3534d092df9390ca83f3a38b4fdfceeadb;p=situare diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 5082bdc..843a430 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -33,27 +33,27 @@ #include #include "common.h" +#include "engine/updatelocation.h" #include "error.h" -#include "facebookservice/facebookauthentication.h" #include "friendlistpanel.h" #include "fullscreenbutton.h" #include "indicatorbuttonpanel.h" #include "locationsearchpanel.h" -#include "logindialog.h" #include "map/mapcommon.h" #include "map/mapview.h" #include "mapscale.h" #include "meetpeoplepanel.h" +#include "messagedialog.h" #include "messagepanel.h" #include "panelcommon.h" #include "routingpanel.h" #include "searchdialog.h" #include "settingsdialog.h" +#include "situareservice/situarecommon.h" #include "tabbedpanel.h" +#include "updatelocation/updatelocationdialog.h" #include "userinfopanel.h" #include "zoombuttonpanel.h" -#include "messagedialog.h" - #include "mainwindow.h" @@ -76,14 +76,11 @@ MainWindow::MainWindow(QWidget *parent) m_refresh(false), m_mapCenterHorizontalShifting(0), m_progressIndicatorCount(0), + m_loginDialog(0), m_crosshair(0), - m_email(), ///< @todo WTF?!?!?!? - m_password(), - m_webView(0), m_fullScreenButton(0), m_indicatorButtonPanel(0), - m_mapScale(0), - m_cookieJar(0) + m_mapScale(0) { qDebug() << __PRETTY_FUNCTION__; @@ -119,6 +116,12 @@ MainWindow::MainWindow(QWidget *parent) #ifdef Q_WS_MAEMO_5 setAttribute(Qt::WA_Maemo5StackedWindow); #endif + + m_updateLocationController = new UpdateLocation(this); + + connect(this, SIGNAL(updateWasSuccessful()), m_updateLocationController, SLOT(clear())); + connect(m_updateLocationController, SIGNAL(locationUpdate(QString,bool)), + this, SIGNAL(locationUpdate(QString,bool))); } MainWindow::~MainWindow() @@ -127,9 +130,6 @@ MainWindow::~MainWindow() grabZoomKeys(false); - if(m_webView) - delete m_webView; - qDeleteAll(m_queue.begin(), m_queue.end()); m_queue.clear(); @@ -144,7 +144,7 @@ void MainWindow::automaticUpdateDialogFinished(int result) if (result == QMessageBox::Yes) { readAutomaticLocationUpdateSettings(); } else { - QSettings settings(DIRECTORY_NAME, FILE_NAME); + QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME); settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false); readAutomaticLocationUpdateSettings(); } @@ -288,6 +288,25 @@ void MainWindow::buildLocationSearchPanel() this, SIGNAL(searchHistoryItemClicked(QString))); } +void MainWindow::buildLoginDialog(QWebView *browser) +{ + qDebug() << __PRETTY_FUNCTION__; + + if (!m_loginDialog) { + m_loginDialog = new QDialog(this); + if (m_loginDialog) { + m_loginDialog->setWindowTitle(tr("Login")); + m_loginDialog->setLayout(new QVBoxLayout()); + m_loginDialog->layout()->addWidget(browser); + m_loginDialog->layout()->setContentsMargins(QMargins()); // zero margins + connect(m_loginDialog, SIGNAL(rejected()), this, SLOT(destroyLoginDialog())); + } + } + + if (m_loginDialog) + m_loginDialog->show(); +} + void MainWindow::buildMap() { qDebug() << __PRETTY_FUNCTION__; @@ -515,27 +534,12 @@ void MainWindow::buildUserInfoPanel() connect(this, SIGNAL(userLocationReady(User*)), m_userInfoPanel, SLOT(userDataReceived(User*))); - connect(this, SIGNAL(reverseGeoReady(QString)), - m_userInfoPanel, SIGNAL(reverseGeoReady(QString))); - - connect(this, SIGNAL(clearUpdateLocationDialogData()), - m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData())); - connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)), this, SIGNAL(centerToCoordinates(GeoCoordinate))); - connect(m_userInfoPanel, SIGNAL(requestReverseGeo()), - this, SIGNAL(requestReverseGeo())); - - connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)), - this, SIGNAL(statusUpdate(QString,bool))); - connect(m_userInfoPanel, SIGNAL(refreshUserData()), this, SIGNAL(refreshUserData())); - connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)), - this, SLOT(buildInformationBox(QString, bool))); - connect(this, SIGNAL(userImageReady(QString,QPixmap)), m_userInfoPanel, SLOT(setImage(QString,QPixmap))); @@ -552,33 +556,6 @@ void MainWindow::buildUserInfoPanel() this, SIGNAL(requestPopularTags())); } -void MainWindow::buildWebView() -{ - qDebug() << __PRETTY_FUNCTION__; - - if(!m_webView) { - m_webView = new QWebView; - - if(!m_cookieJar) - m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this)); - - m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar); - - connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)), - this, SLOT(webViewRequestFinished(QNetworkReply*))); - connect(m_webView, SIGNAL(urlChanged(const QUrl &)), - this, SIGNAL(updateCredentials(QUrl))); - connect(m_webView, SIGNAL(loadFinished(bool)), - this, SLOT(loadDone(bool))); - - //Remove - connect(m_webView->page()->networkAccessManager(), SIGNAL(sslErrors(QNetworkReply*,QList)), - this, SLOT(sslErrors(QNetworkReply*,QList))); - - m_webView->hide(); - } -} - void MainWindow::buildZoomButtonPanel() { qDebug() << __PRETTY_FUNCTION__; @@ -607,24 +584,6 @@ void MainWindow::buildZoomButtonPanel() this, SIGNAL(draggingModeTriggered())); } -void MainWindow::clearCookieJar() -{ - qDebug() << __PRETTY_FUNCTION__; - - buildWebView(); - - m_webView->stop(); - - 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__; @@ -654,47 +613,33 @@ void MainWindow::createMenus() m_viewMenu->setObjectName(tr("Menu")); } +void MainWindow::destroyLoginDialog() +{ + qDebug() << __PRETTY_FUNCTION__; + + if (m_loginDialog) { + m_loginDialog->hide(); + m_loginDialog->deleteLater(); + m_loginDialog = 0; + } +} + void MainWindow::dialogFinished(int status) { qDebug() << __PRETTY_FUNCTION__; QDialog *dialog = m_queue.takeFirst(); - LoginDialog *loginDialog = qobject_cast(dialog); SearchDialog *searchDialog = qobject_cast(dialog); - MessageDialog *messageDialog = qobject_cast(dialog); - if(loginDialog) { - if(status != 0) { - buildWebView(); - loginDialog->userInput(m_email, m_password); - - 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); - - emit saveUsername(m_email); - m_refresh = true; - m_webView->load(QUrl(urlParts.join(EMPTY))); - toggleProgressIndicator(true); - } else { - emit cancelLoginProcess(); - } - } else if(searchDialog) { - if(status != 0) { - if (searchDialog->type() == SearchDialog::Location) - emit searchForLocation(searchDialog->input()); - else if (searchDialog->type() == SearchDialog::PeopleTag) - emit requestSearchPeopleByTag(searchDialog->input()); - } - } - else if (messageDialog) { - if (status != 0) - emit sendMessage(messageDialog->input().first, messageDialog->input().second, - messageDialog->isAddCoordinatesSelected()); + MessageDialog *messageDialog = qobject_cast(dialog); + + if ((searchDialog) && (status != 0)) { + if (searchDialog->type() == SearchDialog::Location) + emit searchForLocation(searchDialog->input()); + else if (searchDialog->type() == SearchDialog::PeopleTag) + emit requestSearchPeopleByTag(searchDialog->input()); + } else if ((messageDialog) && (status != 0)) { + emit sendMessage(messageDialog->input().first, messageDialog->input().second, + messageDialog->isAddCoordinatesSelected()); } dialog->deleteLater(); @@ -806,72 +751,6 @@ 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__; - - // for the first time the login page is opened, we need to refresh it to get cookies working - if(m_refresh) { - m_webView->reload(); - m_refresh = false; - } - - if (done) - { - QWebFrame* frame = m_webView->page()->currentFrame(); - if (frame!=NULL) - { - // set email box - QWebElementCollection emailCollection = frame->findAllElements("input[name=email]"); - - foreach (QWebElement element, emailCollection) { - element.setAttribute("value", m_email.toAscii()); - } - // set password box - QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]"); - foreach (QWebElement element, passwordCollection) { - element.setAttribute("value", m_password.toAscii()); - } - // find connect button - QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]"); - foreach (QWebElement element, buttonCollection) - { - QPoint pos(element.geometry().center()); - - // send a mouse click event to the web page - QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, - Qt::NoModifier); - QApplication::sendEvent(m_webView->page(), &event0); - QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton, - Qt::NoModifier); - QApplication::sendEvent(m_webView->page(), &event1); - } - } - } -} - void MainWindow::loggedIn(bool logged) { qDebug() << __PRETTY_FUNCTION__; @@ -881,51 +760,11 @@ void MainWindow::loggedIn(bool logged) if(logged) { m_loginAct->setText(tr("Logout")); } else { - clearCookieJar(); - m_email.clear(); - m_password.clear(); - m_loginAct->setText(tr("Login")); m_userInfoPanel->showUserInfo(false); + m_updateLocationController->clear(); } - updateItemVisibility(); -} - -void MainWindow::loginFailed() -{ - qDebug() << __PRETTY_FUNCTION__; - - clearCookieJar(); - startLoginProcess(); -} - -bool MainWindow::loginState() -{ - qDebug() << __PRETTY_FUNCTION__; - - 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); - 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))); - + updateItemVisibility(logged); } void MainWindow::mapCenterHorizontalShiftingChanged(int shifting) @@ -980,7 +819,7 @@ void MainWindow::readAutomaticLocationUpdateSettings() { qDebug() << __PRETTY_FUNCTION__; - QSettings settings(DIRECTORY_NAME, FILE_NAME); + QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME); bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool(); QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime()) .toTime(); @@ -993,27 +832,6 @@ void MainWindow::readAutomaticLocationUpdateSettings() } } -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;ishow(); + + emit requestReverseGeo(); +} + void MainWindow::startLocationSearch() { qDebug() << __PRETTY_FUNCTION__; @@ -1136,20 +962,12 @@ void MainWindow::startPeopleSearch() queueDialog(searchDialog); } -void MainWindow::startLoginProcess() +void MainWindow::sslErrors(QNetworkReply *reply, const QList &errors) { qDebug() << __PRETTY_FUNCTION__; - LoginDialog *loginDialog = new LoginDialog(); - - emit fetchUsernameFromSettings(); - - loginDialog->clearTextFields(); - - if(!m_email.isEmpty()) - loginDialog->setEmailField(m_email); - - queueDialog(loginDialog); + Q_UNUSED(errors) + reply->ignoreSslErrors(); } void MainWindow::toggleFullScreen() @@ -1182,36 +1000,9 @@ void MainWindow::toggleProgressIndicator(bool value) #endif // Q_WS_MAEMO_5 } -void MainWindow::updateItemVisibility() +void MainWindow::updateItemVisibility(bool loggedIn) { qDebug() << __PRETTY_FUNCTION__; - m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, m_loggedIn); -} - -const QString MainWindow::username() -{ - qDebug() << __PRETTY_FUNCTION__; - - return m_email; -} - -void MainWindow::webViewRequestFinished(QNetworkReply *reply) -{ - qDebug() << __PRETTY_FUNCTION__; - - // 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()); - } -} - -//REMOVE THIS -void MainWindow::sslErrors(QNetworkReply *reply, const QList &errors) -{ - qWarning() << __PRETTY_FUNCTION__; - - reply->ignoreSslErrors(); + m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, loggedIn); }