diff --git a/javascriptzip/nativeQtClient/nativeQtClient.pro b/javascriptzip/nativeQtClient/nativeQtClient.pro index 5c99e9bb..31f84d0d 100644 --- a/javascriptzip/nativeQtClient/nativeQtClient.pro +++ b/javascriptzip/nativeQtClient/nativeQtClient.pro @@ -15,10 +15,12 @@ LIBS += -lquazip TEMPLATE = app SOURCES += main.cpp \ mainwindow.cpp \ + zipnetworkreply.cpp \ odfview.cpp \ odfcontainer.cpp \ odf.cpp HEADERS += mainwindow.h \ + zipnetworkreply.h \ odfview.h \ odfcontainer.h \ odf.h diff --git a/javascriptzip/nativeQtClient/odfview.cpp b/javascriptzip/nativeQtClient/odfview.cpp index 4c623cde..03d990f7 100644 --- a/javascriptzip/nativeQtClient/odfview.cpp +++ b/javascriptzip/nativeQtClient/odfview.cpp @@ -1,8 +1,11 @@ #include "odfview.h" -#include -#include + #include "odfcontainer.h" #include "odf.h" +#include "zipnetworkreply.h" + +#include +#include #include #include #include @@ -35,6 +38,12 @@ public: } QNetworkReply* createRequest(Operation op, const QNetworkRequest& req, QIODevice* data = 0) { + if (req.url().scheme() == "odfkit") { + //data is inside the current zip file + qDebug() << "zip! " << req.url(); + return new ZipNetworkReply(this, req, op); + } + QNetworkRequest r(req); QString path; if (dir.absolutePath().startsWith(":")) { @@ -48,8 +57,8 @@ public: || fileinfo.dir() != dir) { // changing the url seems to be the only easy way to deny // requests - qDebug() << "undeny " << req.url(); - //r.setUrl(QUrl("error:not-allowed")); + qDebug() << "deny " << req.url(); + r.setUrl(QUrl("error:not-allowed")); } return QNetworkAccessManager::createRequest(op, r, data); } diff --git a/javascriptzip/nativeQtClient/zipnetworkreply.cpp b/javascriptzip/nativeQtClient/zipnetworkreply.cpp new file mode 100644 index 00000000..06f476bf --- /dev/null +++ b/javascriptzip/nativeQtClient/zipnetworkreply.cpp @@ -0,0 +1,42 @@ +#include "zipnetworkreply.h" +#include + +ZipNetworkReply::ZipNetworkReply(QObject* parent, const QNetworkRequest &req, const QNetworkAccessManager::Operation op) + :QNetworkReply(parent), + zipFile(0) +{ + setRequest(req); + setUrl(req.url()); + setOperation(op); + open(QIODevice::ReadOnly); + + //the name of the file within the zip + qDebug() << req.url().toString(QUrl::RemoveScheme); + + //TODO get real data + int fileSize = 0; + + //setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified()); + setHeader(QNetworkRequest::ContentLengthHeader, fileSize); + + QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection); + QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection, + Q_ARG(qint64, fileSize), Q_ARG(qint64, fileSize)); + QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection); + QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); + +} + +void ZipNetworkReply::abort() +{ + QNetworkReply::close(); +} + +qint64 ZipNetworkReply::readData(char *data, qint64 maxSize) +{ + //TODO + qDebug() << "foo!"; + return -1; +} + + diff --git a/javascriptzip/nativeQtClient/zipnetworkreply.h b/javascriptzip/nativeQtClient/zipnetworkreply.h new file mode 100644 index 00000000..18e65453 --- /dev/null +++ b/javascriptzip/nativeQtClient/zipnetworkreply.h @@ -0,0 +1,21 @@ +#ifndef ZIPNETWORKREPLY_H +#define ZIPNETWORKREPLY_H + +#include + +class OdfContainer; + +class ZipNetworkReply : public QNetworkReply +{ +Q_OBJECT +public: + ZipNetworkReply(QObject* parent, const QNetworkRequest &req, const QNetworkAccessManager::Operation op); + + void abort(); +protected: + qint64 readData(char *data, qint64 maxSize) ; +private: + OdfContainer *zipFile; +}; + +#endif // ODF_H diff --git a/javascriptzip/style2css.js b/javascriptzip/style2css.js index 28588334..d169def0 100644 --- a/javascriptzip/style2css.js +++ b/javascriptzip/style2css.js @@ -64,7 +64,7 @@ function style2css(stylesheet, stylesxmldom) { ]; var bgImageSimpleMapping = [ - [ xlinkns, 'href', 'background-image' ] + [ xlinkns, 'repeat', 'background-repeat' ] ]; var paragraphPropertySimpleMapping = [ @@ -201,10 +201,11 @@ function style2css(stylesheet, stylesxmldom) { rule += applySimpleMapping(props, paragraphPropertySimpleMapping); var imageProps = props.getElementsByTagNameNS(stylens, 'background-image'); if (imageProps.length > 0) { - //var url = imageProps.item(0).getAttributeNS(xlinkns, 'href'); - var url = "http://chani.ca/avatar.png"; - rule += "background-image: url('" + url + "');"; - rule += "background-repeat: repeat;"; //FIXME test + var url = imageProps.item(0).getAttributeNS(xlinkns, 'href'); + //var url = "http://chani.ca/avatar.png"; + rule += "background-image: url('odfkit:" + url + "');"; + //rule += "background-repeat: repeat;"; //FIXME test + rule += applySimpleMapping(imageProps, bgImageSimpleMapping); } return rule; }