Commit 5ee42d9a authored by Jonathan Marten's avatar Jonathan Marten
Browse files

man: Call finished() instead of error() after a HTML error message

Konqueror with the WebEnginePart sees the KIO error and displays a
generic error, ignoring the formatted HTML explanation.  KHTML
puts up a deceptive blank error box.  Only WebKit ignores the error
and displays the HTML as intended.  Call finished() so that the HTML
will be displayed whatever viewing part is in use.

Partial revert of commit d5f2beb2, as noted in
konqueror!83
parent 57453699
......@@ -446,8 +446,11 @@ void MANProtocol::get(const QUrl &url)
{
qCDebug(KIO_MAN_LOG) << "GET " << url.url();
QString title, section;
// Indicate the mimetype - this will apply to both
// formatted man pages and error pages.
mimeType("text/html");
QString title, section;
if (!parseUrl(url.path(), title, section))
{
showMainIndex();
......@@ -455,9 +458,6 @@ void MANProtocol::get(const QUrl &url)
return;
}
// tell the mimetype
mimeType("text/html");
// see if an index was requested
if (url.query().isEmpty() && (title.isEmpty() || title == "/" || title == "."))
{
......@@ -483,8 +483,6 @@ void MANProtocol::get(const QUrl &url)
"for man pages, either using the <envar>MANPATH</envar> environment "
"variable or a configuration file in the <filename>/etc</filename> "
"directory.", title.toHtmlEscaped()));
error(KIO::ERR_SLAVE_DEFINED, QString());
return;
}
......@@ -518,13 +516,8 @@ void MANProtocol::get(const QUrl &url)
m_outputBuffer.open(QIODevice::WriteOnly);
const QByteArray filename = QFile::encodeName(pageFound);
const char *buf = readManPage(filename);
if (buf==nullptr)
{
outputError(xi18nc("@info", "The man page <filename>%1</filename> was found, "
"but it could not be read or parsed.", title));
error(KIO::ERR_SLAVE_DEFINED, QString());
return;
}
if (buf==nullptr) return;
// will call output_real
scan_man_page(buf);
delete [] buf;
......@@ -534,14 +527,16 @@ void MANProtocol::get(const QUrl &url)
m_outputBuffer.close();
data(m_outputBuffer.buffer());
m_outputBuffer.setData(QByteArray());
// tell we are done
data(QByteArray());
finished();
}
//---------------------------------------------------------------------
// If this function returns nullptr to indicate a problem,
// then it must call outputError() first.
char *MANProtocol::readManPage(const char *_filename)
{
QByteArray filename = _filename;
......@@ -611,17 +606,21 @@ char *MANProtocol::readManPage(const char *_filename)
KFilterDev fd(QFile::encodeName(filename));
#endif
if ( !fd.open(QIODevice::ReadOnly))
if (!fd.open(QIODevice::ReadOnly)) {
outputError(xi18nc("@info", "The man page <filename%1</filename> could not be read.", QFile::decodeName(filename)));
return nullptr;
}
array = fd.readAll();
qCDebug(KIO_MAN_LOG) << "read " << array.size();
}
if (array.isEmpty())
if (array.isEmpty()) {
outputError(xi18nc("@info", "The man page <filename%1</filename> could not be converted.", QFile::decodeName(filename)));
return nullptr;
}
return manPageToUtf8(array, dirName);
return manPageToUtf8(array, dirName); // never returns nullptr
}
//---------------------------------------------------------------------
......@@ -645,6 +644,9 @@ void MANProtocol::outputHeader(QTextStream &os, const QString &header, const QSt
}
// This calls SlaveBase::finished(), so do not call any other
// SlaveBase functions afterwards. It is assumed that mimeType()
// has already been called at the start of get().
void MANProtocol::outputError(const QString& errmsg)
{
QByteArray array;
......@@ -657,10 +659,10 @@ void MANProtocol::outputError(const QString& errmsg)
os.flush();
data(array);
finished();
}
void MANProtocol::outputMatchingPages(const QStringList &matchingPages)
{
QByteArray array;
......@@ -1416,8 +1418,7 @@ void MANProtocol::getProgramPath()
outputError(xi18nc("@info", "Could not find the <command>sgml2roff</command> program on your system. "
"Please install it if necessary, and ensure that it can be found using "
"the environment variable <envar>PATH</envar>."));
error(KIO::ERR_SLAVE_DEFINED, QString());
exit();
return;
}
#include "kio_man.moc"
......@@ -20,8 +20,7 @@ class MANProtocol : public QObject, public KIO::SlaveBase
Q_OBJECT
public:
MANProtocol(const QByteArray &pool_socket, const QByteArray &app_socket);
explicit MANProtocol(const QByteArray &pool_socket, const QByteArray &app_socket);
~MANProtocol() override;
void get(const QUrl& url) override;
......@@ -30,12 +29,6 @@ public:
void mimetype(const QUrl &url) override;
void listDir(const QUrl &url) override;
void outputError(const QString& errmsg);
void outputMatchingPages(const QStringList &matchingPages);
void showMainIndex();
void showIndex(const QString& section);
// the following two functions are the interface to man2html
void output(const char *insert);
char *readManPage(const char *filename);
......@@ -43,6 +36,12 @@ public:
static MANProtocol *self();
private:
void outputError(const QString& errmsg);
void outputMatchingPages(const QStringList &matchingPages);
void showMainIndex();
void showIndex(const QString& section);
void checkManPaths();
QStringList manDirectories();
QMap<QString, QString> buildIndexMap(const QString& section);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment