Hi all,
I'm trying to devellop my own "widget assistant" using QtHelp to manage some software documentation. To be able to show the ressources (png, css & co) of the html pages I overloaded some QNetworkAccessManager Method and QNetworkRequest Method :
QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/,
const QNetworkRequest
&request,
QIODevice* /*outgoingData*/) {
qDebug("dbt");
const QUrl& url = request.url();
} else {
}
const QByteArray &data
= helpEngine
->findFile
(url
).
isValid() ? helpEngine
->fileData
(url
) : QByteArray("File not found!");
qDebug(url.toString());
qDebug("fin");
return new HelpNetworkReply(request, data, mimeType);
}
QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/,
const QNetworkRequest &request, QIODevice* /*outgoingData*/)
{
qDebug("dbt");
const QUrl& url = request.url();
QString mimeType = url.toString();
if (mimeType.endsWith(QLatin1String(".svg"))
|| mimeType.endsWith(QLatin1String(".svgz"))) {
mimeType = QLatin1String("image/svg+xml");
} else if (mimeType.endsWith(QLatin1String(".css"))) {
mimeType = QLatin1String("text/css");
} else if (mimeType.endsWith(QLatin1String(".js"))) {
mimeType = QLatin1String("text/javascript");
} else if (mimeType.endsWith(QLatin1String(".txt"))) {
mimeType = QLatin1String("text/plain");
} else if (mimeType.endsWith(QLatin1String(".swf"))) {
mimeType = QLatin1String("application/x-shockwave-flash");
} else {
mimeType = QLatin1String("text/html");
}
const QByteArray &data = helpEngine->findFile(url).isValid()
? helpEngine->fileData(url) : QByteArray("File not found!");
qDebug(url.toString());
qDebug("fin");
return new HelpNetworkReply(request, data, mimeType);
}
To copy to clipboard, switch view to plain text mode
HelpNetworkReply::HelpNetworkReply(const QNetworkRequest &request,
const QByteArray &fileData,
const QString
& mimeType
) : data(fileData), origLen(fileData.length())
{
qDebug("DBT NETWORK REPLY");
setRequest(request);
setHeader(QNetworkRequest::ContentTypeHeader, mimeType);
setHeader
(QNetworkRequest
::ContentLengthHeader,
QByteArray::number(origLen
));
QTimer::singleShot(0,
this,
SIGNAL(metaDataChanged
()));
QTimer::singleShot(0,
this,
SIGNAL(readyRead
()));
qDebug("FIN NETWORK REPLY");
}
HelpNetworkReply::HelpNetworkReply(const QNetworkRequest &request,
const QByteArray &fileData, const QString& mimeType)
: data(fileData), origLen(fileData.length())
{
qDebug("DBT NETWORK REPLY");
setRequest(request);
setOpenMode(QIODevice::ReadOnly);
setHeader(QNetworkRequest::ContentTypeHeader, mimeType);
setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(origLen));
QTimer::singleShot(0, this, SIGNAL(metaDataChanged()));
QTimer::singleShot(0, this, SIGNAL(readyRead()));
qDebug("FIN NETWORK REPLY");
}
To copy to clipboard, switch view to plain text mode
qint64 HelpNetworkReply::readData(char *buffer, qint64 maxlen)
{
qDebug("DBT READ DATA");
qint64 len = qMin(qint64(data.length()), maxlen);
if (len) {
qMemCopy(buffer, data.constData(), len);
data.remove(0, len);
}
if (!data.length())
QTimer::singleShot(0,
this,
SIGNAL(finished
()));
qDebug("FIN READ DATA");
return len;
}
qint64 HelpNetworkReply::readData(char *buffer, qint64 maxlen)
{
qDebug("DBT READ DATA");
qint64 len = qMin(qint64(data.length()), maxlen);
if (len) {
qMemCopy(buffer, data.constData(), len);
data.remove(0, len);
}
if (!data.length())
QTimer::singleShot(0, this, SIGNAL(finished()));
qDebug("FIN READ DATA");
return len;
}
To copy to clipboard, switch view to plain text mode
It works well and now I can display all my qhc documentation with pictures and other ressources. Nevertheless I'm not able to display well swf video. On my page, instead of the flash video there is a white box. The plugin seems not be able to load the .swf file but I dont understand why.
Is there someone who could help me to understand ?
Thanks in advance for you response,
Sebboh.
PS : i'm not a native english speaker, sorry if there are any mistakes
Bookmarks