File indexing completed on 2024-04-28 04:57:49

0001 /*  This file is part of the KDE libraries
0002     SPDX-FileCopyrightText: 2000 Matthias Hoelzer-Kluepfel <mhk@caldera.de>
0003 
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 #ifndef __kio_man_h__
0008 #define __kio_man_h__
0009 
0010 #include <QBuffer>
0011 
0012 #include <KIO/Global>
0013 #include <KIO/WorkerBase>
0014 
0015 class MANProtocol : public QObject, public KIO::WorkerBase
0016 {
0017     Q_OBJECT
0018 
0019 public:
0020     explicit MANProtocol(const QByteArray &pool_socket, const QByteArray &app_socket);
0021     ~MANProtocol() override;
0022 
0023     KIO::WorkerResult get(const QUrl &url) override;
0024     KIO::WorkerResult stat(const QUrl &url) override;
0025 
0026     KIO::WorkerResult mimetype(const QUrl &url) override;
0027     KIO::WorkerResult listDir(const QUrl &url) override;
0028 
0029     // the following two functions are the interface to man2html
0030     void output(const char *insert);
0031     char *readManPage(const char *filename);
0032 
0033     static MANProtocol *self();
0034 
0035     void showIndex(const QString &section);
0036 
0037 private:
0038     void outputError(const QString &errmsg);
0039     void outputMatchingPages(const QStringList &matchingPages);
0040 
0041     void showMainIndex();
0042 
0043     void checkManPaths();
0044     QStringList manDirectories();
0045     QMap<QString, QString> buildIndexMap(const QString &section);
0046     bool addWhatIs(QMap<QString, QString> &i, const QString &f, const QString &mark);
0047     void parseWhatIs(QMap<QString, QString> &i, QTextStream &t, const QString &mark);
0048     QStringList findPages(const QString &section, const QString &title, bool full_path = true);
0049 
0050     QStringList buildSectionList(const QStringList &dirs) const;
0051     void constructPath(QStringList &constr_path, QStringList constr_catmanpath);
0052     QStringList findManPagesInSection(const QString &dir, const QString &title, bool full_path);
0053 
0054     void outputHeader(QTextStream &os, const QString &header, const QString &title = QString());
0055     void outputFooter(QTextStream &os);
0056 
0057     bool getProgramPath();
0058 
0059 private:
0060     static MANProtocol *s_self;
0061     QByteArray lastdir;
0062 
0063     QStringList m_manpath; ///< Path of man directories
0064     QStringList m_mandbpath; ///< Path of catman directories
0065     QStringList m_sectionNames;
0066 
0067     QString mySgml2RoffPath;
0068 
0069     QBuffer m_outputBuffer; ///< Buffer for the output
0070     QByteArray m_manCSSFile; ///< Path to kio_man.css
0071 };
0072 
0073 #endif