Пример #1
0
void MyTextBrowser::htmlOrSvgDump(const char *filename)
{
#ifdef NO_WEBKIT
  FILE *fout = fopen(filename,"w");
  if(fout == NULL)
  {
    printf("could not write %s\n", filename);
    return;
  }
  QString xml = toHtml();
  fputs(xml.toUtf8(), fout);
  fclose(fout);
#else
  QWebPage *p = page();
  if(p == NULL) return;
  QWebFrame *f = p->currentFrame();
  if(f == NULL) return;

  FILE *fout = fopen(filename,"w");
  if(fout == NULL)
  {
    printf("could not write %s\n", filename);
    return;
  }
  QString xml = f->toHtml();
  fputs(xml.toUtf8(), fout);
  fclose(fout);
#endif  
}
Пример #2
0
void STab::handleFinishStreamLoading(bool)
{
    qDebug("STab::handleFinishStreamLoading");

    disconnect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(handleFinishStreamLoading(bool)));

    ui->progressBar->setValue(99);

    //
    QSettings* const settings = Settings::getHostsInstance();
    settings->beginGroup(this->currentGroup);
    QString mode = settings->value("mode").toString();
    if (mode == QString("regexps")) {
        QWebFrame *frame = ui->webView->page()->mainFrame();
        QString content = frame->toHtml();

        int size = settings->beginReadArray("rule");
        for (int i = 0; i < size; ++i) {
            settings->setArrayIndex(i);

            QRegExp rx(settings->value("from").toString());
            content.replace(rx, settings->value("to").toString());
        }

        settings->endArray();

        qDebug() << content;

        ui->webView->setContent(content.toUtf8());
    }
    settings->endGroup();

    prepareUi();
}
Пример #3
0
void DumpRenderTree::dump()
{
    // Prevent any further frame load or resource load callbacks from appearing after we dump the result.
    DumpRenderTreeSupportQt::dumpFrameLoader(false);
    DumpRenderTreeSupportQt::dumpResourceLoadCallbacks(false);

    QWebFrame *mainFrame = m_page->mainFrame();

    if (isStandAloneMode()) {
        QString markup = mainFrame->toHtml();
        fprintf(stdout, "Source:\n\n%s\n", markup.toUtf8().constData());
    }

    QString mimeType = DumpRenderTreeSupportQt::responseMimeType(mainFrame);
    if (mimeType == "text/plain")
        m_controller->dumpAsText();

    // Dump render text...
    QString resultString;
    if (m_controller->shouldDumpAsText())
        resultString = dumpFramesAsText(mainFrame);
    else {
        resultString = mainFrame->renderTreeDump();
        resultString += dumpFrameScrollPosition(mainFrame);
    }
    if (!resultString.isEmpty()) {
        fprintf(stdout, "Content-Type: text/plain\n");
        fprintf(stdout, "%s", resultString.toUtf8().constData());

        if (m_controller->shouldDumpBackForwardList()) {
            fprintf(stdout, "%s", dumpBackForwardList(webPage()).toUtf8().constData());
            foreach (QObject* widget, windows) {
                QWebPage* page = qobject_cast<QWebPage*>(widget->findChild<QWebPage*>());
                fprintf(stdout, "%s", dumpBackForwardList(page).toUtf8().constData());
            }
Пример #4
0
QString QWebFrameProto::toHtml() const
{
  scriptDeprecated("QWebFrame will not be available in future versions");
  QWebFrame *item = qscriptvalue_cast<QWebFrame*>(thisObject());
  if (item)
    return item->toHtml();
  return QString();
}
Пример #5
0
//----------------------------------------------------------------
void Collection::import_paper()
{
  //we should not try to add a paper if no current library;
  if ( !_current_library )
    {
      QMessageBox::about(this, tr("Error"),
			 tr("Error: you have no Libraries defined\n"
			    "you cannot create a new paper"));
      return;
    }
  QWebPage * page = _rss_box->page();
  
  QWebFrame * frame = page->mainFrame();

  //now create a new paper and parse out the values we want.
  _parser->setData(frame->toHtml());
  _stdout << "Collection::import_paper title" << _parser->getTitle() << endl;
  _stdout << "Collection::import_paper authors" << _parser->getAuthors() << endl;

  Paper * paper = new Paper();
  paper->set_title(_parser->getTitle());
  paper->set_author(_parser->getAuthors());
  paper->set_abstract(_parser->getAbstract());
  paper->set_date(_parser->getDate());
  paper->set_arxiv_number(_parser->getNumber());

  //Download the damn thing
  _manager = new QNetworkAccessManager(this);
  _manager->get(QNetworkRequest(_parser->getDownloadLocation()));
  connect(_manager, SIGNAL(finished(QNetworkReply*)),
  	  this, SLOT(download_finished(QNetworkReply*)));

  QDir directory(_current_library->get_library_directory()+"/"+_parser->getPaperName());

  _stdout << "Collection::import_paper " <<  directory.absolutePath() << endl; 

  paper->set_file_name(directory.absolutePath());
  
  //add the entry to the library
  _current_library->add_entry(paper);

  //add the entry to the list
  add_paper_to_list(*paper,_paper_list);
  update_library_list();

}
Пример #6
0
void WebView::applyEncoding()
{
	if (m_encoding_in_progress)
		return;

	if (webPage() && webPage()->mainWindow())
	{
		QString enc = webPage()->mainWindow()->m_currentEncoding;
		if (enc.isEmpty())
			return;

		if (enc == m_current_encoding && m_current_encoding_url == url() )
			return;

		QWebPage *page = webPage();
		if (!page)
			return;

		QWebFrame *mainframe = page->mainFrame();
		if (!mainframe)
			return;

		QString html = mainframe->toHtml();

		QTextCodec *codec = QTextCodec::codecForName( enc.toAscii() );
		if (!codec)
			return;

		QTextDecoder *decoder = codec->makeDecoder();
		if (!decoder)
			return;

		m_encoding_in_progress = true;
		m_current_encoding = enc;
		m_current_encoding_url = url();
		QString output = decoder->toUnicode(html.toAscii());
		mainframe->setHtml(output, mainframe->url());

		QList<QWebFrame *> children = mainframe->childFrames();
		foreach(QWebFrame *frame, children)
		{
			html = frame->toHtml();
			output = decoder->toUnicode(html.toAscii());
			frame->setHtml(output, frame->url());
		}
Пример #7
0
void OAuthWindow::tempAuthPageLoaded(bool rc) {
    QLOG_DEBUG() << "Temporary credentials received from Evernote";
    if (!rc) {
        errorMessage = tr("Error receiving temporary credentials");
        error = true;
        QWebFrame *mainFrame = tempAuthPage.page()->mainFrame();
        QString contents = mainFrame->toHtml();
        QLOG_DEBUG() << "Reply contents:" << contents;
        close();
        return;
    }

    QWebFrame *mainFrame = tempAuthPage.page()->mainFrame();
    QString contents = mainFrame->toPlainText();
    QLOG_DEBUG() << "Temporary Cred Contents: " << contents;
    int index = contents.indexOf("&oauth_token_secret");
    contents = contents.left(index);
    QUrl accessUrl(urlBase+"/OAuth.action?" +contents);

    connect(userLoginPage.page()->networkAccessManager(),SIGNAL(finished(QNetworkReply*)),this,SLOT(userLoginReply(QNetworkReply*)));
    userLoginPage.load(accessUrl);
    grid.addWidget(&userLoginPage);
}
Пример #8
0
void ArestShopPlugin::parseProductPage()
{
#ifdef USE_WEBKIT
	QWebFrame * ptrFrame = getWebPage()->mainFrame();
	printPageContent(ptrFrame->toHtml());
	QWebElement elCompFullName = ptrFrame->findFirstElement("h1[class=nazwatowaru]");
	QWebElement elPrice = ptrFrame->findFirstElement("span[class=price]"); //div class="altFontFace price"
	QString strPrice = elPrice.toPlainText();
	for(int i = 0;i<strPrice.size();i++)
	{
		if (strPrice.at(i).isLetterOrNumber())
			continue;
		strPrice = strPrice.left(i);
		break;
	}
	m_stCompData.dPrice = strPrice.toDouble();
	m_stCompData.eSearchResult = SR_COMPFOUND;
	m_stCompData.strCompURL = getWebPage()->mainFrame()->url().toString();
#endif
#ifdef USE_XML_PARSER
	m_stCompData.dPrice = Arest::dPrice;
	m_stCompData.eSearchResult = SR_COMPFOUND;
#endif
}
Пример #9
0
void Html_Viewer::updateTextEdit()
{
   QWebFrame *mainFrame = ui->webView->page()->mainFrame();
   QString frameText = mainFrame->toHtml();
   ui->plainTextEdit->setPlainText(frameText);
}
Пример #10
0
void CutyCapt::saveSnapshot() {
  QWebFrame *mainFrame = mPage->mainFrame();
  QPainter painter;
  const char* format = NULL;

  for (int ix = 0; CutyExtMap[ix].id != OtherFormat; ++ix) {
    if (CutyExtMap[ix].id == mFormat) {
      format = CutyExtMap[ix].identifier;
    }
  }

  // TODO: sometimes contents/viewport can have size 0x0 in which case saving
  // them will fail. This is likely the result of the method being called too
  // early. So far I've been unable to find a workaround, except using --delay
  // with some substantial wait time. I've tried to resize multiple time, make
  // a fake render, check for other events... This is primarily a problem under
  // my Ubuntu virtual machine.

  mPage->setViewportSize( mainFrame->contentsSize() );

  switch (mFormat) {
    case SvgFormat: {
      QSvgGenerator svg;
      svg.setFileName(mOutput);
      svg.setSize(mPage->viewportSize());
      painter.begin(&svg);
      mainFrame->render(&painter);
      painter.end();
      break;
    }
    case PdfFormat:
    case PsFormat: {
      QPrinter printer;
      printer.setPageSize(QPrinter::A4);
      printer.setOutputFileName(mOutput);
      // TODO: change quality here?
      mainFrame->print(&printer);
      break;
    }
#if QT_VERSION < 0x050000
    case RenderTreeFormat:
      QFile file(mOutput);
      file.open(QIODevice::WriteOnly | QIODevice::Text);
      QTextStream s(&file);
      s.setCodec("utf-8");
      s << mainFrame->renderTreeDump();
      break;
    }
#endif
    case InnerTextFormat:
    case HtmlFormat: {
      QFile file(mOutput);
      file.open(QIODevice::WriteOnly | QIODevice::Text);
      QTextStream s(&file);
      s.setCodec("utf-8");
      s << (mFormat == InnerTextFormat ? mainFrame->toPlainText() : (mFormat == HtmlFormat ? mainFrame->toHtml() : "bug"));
      break;
    }
    default: {
      QImage image(mPage->viewportSize(), QImage::Format_ARGB32);
      painter.begin(&image);
      mainFrame->render(&painter);
      painter.end();
      // TODO: add quality
      image.save(mOutput, format);
    }
  };
//! [7]
void MainWindow::updateTextEdit()
{
    QWebFrame *mainFrame = centralWidget->webView->page()->mainFrame();
    QString frameText = mainFrame->toHtml();
    centralWidget->plainTextEdit->setPlainText(frameText);
}