00001
#include "kio_kdeapi.h"
00002
00003
#include "../../config.h"
00004
00005
#include <fcntl.h>
00006
#include <stdio.h>
00007
#include <stdlib.h>
00008
#include <sys/stat.h>
00009
#include <sys/types.h>
00010
#include <unistd.h>
00011
00012
#include <qfile.h>
00013
#include <qregexp.h>
00014
#include <qtextstream.h>
00015
#include <kconfig.h>
00016
#include <kdebug.h>
00017
#include <kstandarddirs.h>
00018
#include <kinstance.h>
00019
00020
using namespace KIO;
00021
00022
00023 KdeapiProtocol::KdeapiProtocol(
const QCString &pool,
const QCString &app)
00024 :
SlaveBase("pydoc", pool, app)
00025 {
00026
KConfig *config =
KGlobal::config();
00027 config->
setGroup(
"General");
00028
00029
qtdocdir = config->
readPathEntry(
"qtdocdir", QT_DOCDIR);
00030
kdedocdir = config->
readPathEntry(
"kdelibsdocdir", KDELIBS_DOXYDIR);
00031 }
00032
00033
00034 KdeapiProtocol::~KdeapiProtocol()
00035 {}
00036
00037
00038 void KdeapiProtocol::get(
const KURL &url)
00039 {
00040 mimeType(
"text/html");
00041
QString path = url.
path();
00042
int pos = path.find(
'/');
00043
if (pos == -1) {
00044 error(KIO::ERR_DOES_NOT_EXIST, path);
00045
return;
00046 }
00047
00048
QString dirName = path.left(pos);
00049
QString className = path.mid(pos+1);
00050
kdDebug() <<
"path: " << path <<
", dirName: " << dirName <<
", className: " << className <<
endl;
00051
00052
QString fileName;
00053
00054
if (dirName ==
"qt") {
00055
if (className ==
"index.html")
00056 fileName =
qtdocdir +
"/index.html";
00057
else
00058 fileName = qtdocdir +
"/" + className.lower() +
".html";
00059 }
else {
00060
if (className ==
"index.html")
00061 fileName =
kdedocdir +
"/" + dirName +
"/html/index.html";
00062
else {
00063 className.replace(
QRegExp(
"::"),
"_1_1");
00064 fileName =
kdedocdir +
"/" + dirName +
"/html/class" + className +
".html";
00065
if (!QFile::exists(fileName))
00066 fileName =
kdedocdir +
"/" + dirName +
"/html/struct" + className +
".html";
00067 }
00068 }
00069
00070
kdDebug() <<
"Trying filename " << fileName <<
endl;
00071
00072
int fd = ::open(QFile::encodeName(fileName), O_RDONLY);
00073
char buffer[4096];
00074
QByteArray array;
00075
00076
for ( ;; ) {
00077
int n = read(fd, buffer,
sizeof buffer);
00078
if (n == -1) {
00079 error(KIO::ERR_COULD_NOT_READ, fileName);
00080 ::close(fd);
00081
return;
00082 }
else if (n == 0) {
00083
break;
00084 }
00085
00086 array.setRawData(buffer, n);
00087
data(array);
00088 array.resetRawData(buffer, n);
00089 }
00090
00091 ::close(fd);
00092
finished();
00093 }
00094
00095
00096 void KdeapiProtocol::mimetype(
const KURL&)
00097 {
00098 mimeType(
"text/html");
00099
finished();
00100 }
00101
00102
00103 void KdeapiProtocol::stat(
const KURL &)
00104 {
00105 UDSAtom uds_atom;
00106 uds_atom.m_uds = KIO::UDS_FILE_TYPE;
00107 uds_atom.m_long = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
00108
00109
UDSEntry uds_entry;
00110 uds_entry.append(uds_atom);
00111
00112 statEntry(uds_entry);
00113
finished();
00114 }
00115
00116
00117 void KdeapiProtocol::listDir(
const KURL &url)
00118 {
00119 error(KIO::ERR_CANNOT_ENTER_DIRECTORY, url.
path());
00120 }
00121
00122
00123
extern "C" {
00124
00125 int kdemain(
int argc,
char **argv)
00126 {
00127
KInstance instance(
"kio_kdeapi" );
00128
00129
if (argc != 4) {
00130 fprintf(stderr,
"Usage: kio_kdeapi protocol domain-socket1 domain-socket2\n");
00131 exit(-1);
00132 }
00133
00134
KdeapiProtocol slave(argv[2], argv[3]);
00135 slave.
dispatchLoop();
00136
00137
return 0;
00138 }
00139
00140 }