Esempio n. 1
0
void LoginManager::loginInteractive()
      {
      QWebEngineView* webView = new QWebEngineView;
      webView->setWindowModality(Qt::ApplicationModal);
      webView->setAttribute(Qt::WA_DeleteOnClose);

      QWebEnginePage* page = webView->page();
      QWebEngineProfile* profile = page->profile();
      // TODO: logout in editor does not log out in web view
      profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
      profile->setRequestInterceptor(new ApiWebEngineRequestInterceptor(profile));

      //workaround for the crashes sometimes happend in Chromium on macOS with Qt 5.12
      connect(webView, &QWebEngineView::renderProcessTerminated, this, [profile, webView](QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode)
              {
              qDebug() << "Login page loading terminated" << terminationStatus << " " << exitCode;
              profile->clearHttpCache();
              webView->show();
              });
      
      connect(page, &QWebEnginePage::loadFinished, this, [this, page, webView](bool ok) {
            if (!ok)
                  return;
            constexpr QUrl::FormattingOptions cmpOpt = QUrl::RemoveQuery | QUrl::RemoveFragment | QUrl::StripTrailingSlash;
            if (!page->url().matches(ApiInfo::loginSuccessUrl, cmpOpt))
                  return;

            page->runJavaScript("JSON.stringify(muGetAuthInfo())", [this, page, webView](const QVariant& v) {
                  onLoginReply(nullptr, HTTP_OK, QJsonDocument::fromJson(v.toString().toUtf8()).object());
                  // We have retrieved an access token, do not remain logged
                  // in with web view profile.
                  page->profile()->cookieStore()->deleteAllCookies();
                  webView->close();
                  });
            });

      webView->load(ApiInfo::loginUrl);
      webView->show();
      }
Esempio n. 2
0
void MainWindow::openPDFWindow(QString url){
    QWebEngineView * pdfView;
    if(!pdfViewList.contains(url)){
        pdfView = new QWebEngineView(0);
        QUrl theurl = QUrl(url);
        pdfView->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);

        pdfView->load( theurl );
        pdfView->show();
        pdfViewList.insert(url, pdfView);
        pdfView->setAttribute(Qt::WA_DeleteOnClose);
        pdfView->showNormal();

        int frameHeight = pdfView->frameGeometry().height()-pdfView->geometry().height();
        pdfView->move( (screenRect.width() - 640)/2, screenRect.y() );
        pdfView->resize( 640, screenRect.height()-frameHeight );

        connect(pdfView, SIGNAL(destroyed(QObject*)), this, SLOT(onPDFViewClose(QObject*)) );
        //pdfView->settings()->enablePersistentStorage(QDir::tempPath());
        QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);

    }else{
Esempio n. 3
-1
void QRestClient::displayHtml(QByteArray html)
{
    QWebEngineView *view = new QWebEngineView();
    view->setAttribute(Qt::WA_DeleteOnClose);
    view->setHtml(html);
    view->show();
}