-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);
- }
- }
- }
-}
-