diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -233,15 +233,10 @@ ) find_package(KF5Activities) -find_package(KF5KHtml) set_package_properties(KF5Activities PROPERTIES TYPE OPTIONAL ) -set_package_properties(KF5KHtml PROPERTIES - PURPOSE "Required for HTML2ODS import filter" - TYPE OPTIONAL - ) if(KF5Activities_FOUND) set(HAVE_KACTIVITIES TRUE) @@ -1012,7 +1007,6 @@ calligra_drop_product_on_bad_condition( FILTER_HTML_TO_ODS NOT_WIN "not supported on Windows" NOT_COCOA "not supported with Qt Cocoa" - KF5KHtml_FOUND "KF5KHtml devel not found" ) calligra_drop_product_on_bad_condition( FILTER_SHEETS_TO_HTML diff --git a/filters/sheets/html/CMakeLists.txt b/filters/sheets/html/CMakeLists.txt --- a/filters/sheets/html/CMakeLists.txt +++ b/filters/sheets/html/CMakeLists.txt @@ -10,7 +10,7 @@ set(html2ods_PART_SRCS htmlimport.cc HtmlImportDebug.cpp) add_library(calligra_filter_html2ods MODULE ${html2ods_PART_SRCS}) calligra_filter_desktop_to_json(calligra_filter_html2ods calligra_filter_html2ods.desktop) -target_link_libraries(calligra_filter_html2ods komain KF5::KHtml) +target_link_libraries(calligra_filter_html2ods komain) install(TARGETS calligra_filter_html2ods DESTINATION ${PLUGIN_INSTALL_DIR}/calligra/formatfilters) endif() diff --git a/filters/sheets/html/htmlimport.h b/filters/sheets/html/htmlimport.h --- a/filters/sheets/html/htmlimport.h +++ b/filters/sheets/html/htmlimport.h @@ -35,15 +35,11 @@ // class Sheet; // } -namespace DOM -{ - class Node; - class Element; -} - class KoOdfWriteStore; class KoXmlWriter; class KoGenStyles; +class QDomNode; +class QDomElement; class HTMLImport : public KoFilter { @@ -59,8 +55,8 @@ private: KoFilter::ConversionStatus loadUrl(const QUrl &url); - void parseNode(DOM::Node n); - bool parseTag(DOM::Element e); + void parseNode(QDomNode n); + bool parseTag(QDomElement e); bool createStyle(); bool createMeta(); private: diff --git a/filters/sheets/html/htmlimport.cc b/filters/sheets/html/htmlimport.cc --- a/filters/sheets/html/htmlimport.cc +++ b/filters/sheets/html/htmlimport.cc @@ -37,15 +37,10 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -//#include -//#include +#include +#include +#include +#include //using namespace Calligra::Sheets; @@ -182,24 +177,18 @@ QStringList sheets; { - KHTMLPart html; - html.view()->resize(600, 530); - html.setAutoloadImages(false); - html.setJScriptEnabled(false); - html.setPluginsEnabled(false); - html.setJavaEnabled(false); - html.setMetaRefreshEnabled(false); - - QEventLoop loop; - connect(&html, SIGNAL(completed()), &loop, SLOT(quit())); - QMetaObject::invokeMethod(&html,"openUrl", Qt::QueuedConnection, Q_ARG(QUrl,url)); - //if (!html.openUrl(url)) { warnHtml << "Failed loadUrl" << url; return KoFilter::StupidError; } - loop.exec(QEventLoop::ExcludeUserInputEvents); - - // body - DOM::Document doc = html.document(); - DOM::NodeList body = doc.getElementsByTagName("body"); - DOM::Node docbody = body.item(0); + QDomDocument doc("mydocument"); + QFile file(url.toLocalFile()); + if (!file.open(QIODevice::ReadOnly)) + return KoFilter::ConversionStatus::StorageCreationError; + if (!doc.setContent(&file)) { + file.close(); + return KoFilter::ConversionStatus::FileNotFound; + } + file.close(); + QDomNodeList body = doc.elementsByTagName("body"); + QDomNode docbody = body.item(0); + if (!docbody.isNull()) { m_states.push(InBody); bodyWriter->startElement("office:spreadsheet"); @@ -209,20 +198,21 @@ } // frames - DOM::NodeList frameset = doc.getElementsByTagName("frameset"); - DOM::Node frame = frameset.item(0); + QDomNodeList frameset = doc.elementsByTagName("frameset"); + QDomNode frame = frameset.item(0); + if (!frame.isNull()) { for(uint i = 0; i < frameset.length(); ++i) { - for (DOM::Node n = frameset.item(i).firstChild(); !n.isNull(); n = n.nextSibling()) { - DOM::Element f = n; - if(!f.isNull() && f.nodeName().lower() == "frame" && f.getAttribute("name").string() == "frSheet") - sheets.append(f.getAttribute("src").string()); + for (QDomNode n = frameset.item(i).firstChild(); !n.isNull(); n = n.nextSibling()) { + QDomElement f = n.toElement(); + if(!f.isNull() && f.nodeName().toLower() == "frame" && f.attribute("name") == "frSheet") + sheets.append(f.attribute("src")); } } } } - // the KHTMLPart and DOM::Document are no more and we can call us recursivly now. + // the QDOMDocument is no more and we can call us recursively now. if(!sheets.isEmpty()) { m_states.push(InFrameset); foreach(const QString &src, sheets) { @@ -235,16 +225,16 @@ return KoFilter::OK; } -void HTMLImport::parseNode(DOM::Node node) +void HTMLImport::parseNode(QDomNode node) { KoXmlWriter* bodyWriter = m_store->bodyWriter(); //KoXmlWriter* contentWriter = m_store->contentWriter(); // check if this is a text node. - DOM::Text t = node; - if (!t.isNull()) { + if (node.isText()) { + QDomText t = node.toText(); if(!m_states.isEmpty() && m_states.top() == InCell) { - const QString s = t.data().string().trimmed(); + const QString s = t.data().trimmed(); if(!s.isEmpty()) { //debugHtml<<"TEXT tagname=" << node.nodeName() << "TEXT="<addAttribute("office:value-type", "string"); @@ -254,7 +244,7 @@ return; // no children anymore... } - DOM::DOMString tag = node.nodeName().lower(); + QString tag = node.nodeName().toLower(); if(tag == "table") { m_states.push(InTable); @@ -279,14 +269,14 @@ //debugHtml<<"...START nodeName="<