#include <QMessageBox>
#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"
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__;
#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()
grabZoomKeys(false);
- if(m_webView)
- delete m_webView;
-
qDeleteAll(m_queue.begin(), m_queue.end());
m_queue.clear();
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();
}
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__;
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)));
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<QSslError>)),
- this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));
-
- m_webView->hide();
- }
-}
-
void MainWindow::buildZoomButtonPanel()
{
qDebug() << __PRETTY_FUNCTION__;
this, SIGNAL(draggingModeTriggered()));
}
-void MainWindow::clearCookieJar()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- buildWebView();
-
- m_webView->stop();
-
- if(!m_cookieJar) {
- m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
- }
- QList<QNetworkCookie> emptyList;
- emptyList.clear();
-
- m_cookieJar->setAllCookies(emptyList);
- m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
-}
-
void MainWindow::createMenus()
{
qDebug() << __PRETTY_FUNCTION__;
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<LoginDialog *>(dialog);
SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
- MessageDialog *messageDialog = qobject_cast<MessageDialog *>(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<MessageDialog *>(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();
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<QNetworkCookie> cookieList;
- for(int i=0;i<list.count();i++) {
- cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
- }
-
- if(!m_cookieJar)
- m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
-
- m_cookieJar->setAllCookies(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__;
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)
{
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();
}
}
-void MainWindow::saveCookies()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- if(!m_cookieJar)
- m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
-
- QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
- QStringList list;
-
- for(int i=0;i<cookieList.count();i++) {
- QNetworkCookie cookie = cookieList.at(i);
- QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
- list.append(QString(byteArray));
- }
- list.removeDuplicates();
-
- QSettings settings(DIRECTORY_NAME, FILE_NAME);
- settings.setValue(COOKIES, list);
-}
-
void MainWindow::setCrosshairVisibility(bool visibility)
{
qDebug() << __PRETTY_FUNCTION__;
readAutomaticLocationUpdateSettings();
}
-void MainWindow::setUsername(const QString &username)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_email = username;
-}
-
void MainWindow::showContactDialog(const QString &guid)
{
qDebug() << __PRETTY_FUNCTION__;
}
}
+void MainWindow::showUpdateLocationDialog()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ UpdateLocationDialog *updateLocationDialog
+ = new UpdateLocationDialog(m_updateLocationController, this);
+
+ connect(this, SIGNAL(reverseGeoReady(QString)),
+ updateLocationDialog, SLOT(setAddress(QString)));
+
+ updateLocationDialog->show();
+
+ emit requestReverseGeo();
+}
+
void MainWindow::startLocationSearch()
{
qDebug() << __PRETTY_FUNCTION__;
queueDialog(searchDialog);
}
-void MainWindow::startLoginProcess()
+void MainWindow::sslErrors(QNetworkReply *reply, const QList<QSslError> &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()
#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<QSslError> &errors)
-{
- qWarning() << __PRETTY_FUNCTION__;
-
- reply->ignoreSslErrors();
+ m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, loggedIn);
}