pydoc.cpp
Go to the documentation of this file.00001 #include "pydoc.h"
00002
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <sys/stat.h>
00006 #include <unistd.h>
00007
00008 #include <qtextstream.h>
00009 #include <kstandarddirs.h>
00010 #include <kinstance.h>
00011 #include <kprocess.h>
00012 #include <kdeversion.h>
00013 #include <kglobal.h>
00014 #include <klocale.h>
00015
00016 using namespace KIO;
00017
00018
00019 PydocProtocol::PydocProtocol(const QCString &pool, const QCString &app)
00020 : SlaveBase("pydoc", pool, app), key()
00021 {
00022 python = KGlobal::dirs()->findExe("python");
00023 script = locate("data", "kio_pydoc/kde_pydoc.py");
00024 }
00025
00026
00027 PydocProtocol::~PydocProtocol()
00028 {}
00029
00030
00031 void PydocProtocol::get(const KURL& url)
00032 {
00033 mimeType("text/html");
00034 key = url.path();
00035
00036 #if (KDE_VERSION > 305)
00037 QString cmd = KProcess::quote(python);
00038 cmd += " ";
00039 cmd += KProcess::quote(script);
00040 cmd += " -w ";
00041 cmd += KProcess::quote(key);
00042 #else
00043 QString cmd = KShellProcess::quote(python);
00044 cmd += " ";
00045 cmd += KShellProcess::quote(script);
00046 cmd += " -w ";
00047 cmd += KShellProcess::quote(key);
00048 #endif
00049
00050 FILE *fd = popen(cmd.local8Bit().data(), "r");
00051 char buffer[4096];
00052 QByteArray array;
00053
00054 while (!feof(fd)) {
00055 int n = fread(buffer, 1, 2048, fd);
00056 if (n == -1) {
00057 pclose(fd);
00058 return;
00059 }
00060 array.setRawData(buffer, n);
00061 data(array);
00062 array.resetRawData(buffer, n);
00063 }
00064
00065 pclose(fd);
00066 finished();
00067 }
00068
00069
00070 void PydocProtocol::mimetype(const KURL&)
00071 {
00072 mimeType( "text/html" );
00073 finished();
00074 }
00075
00076
00077 QCString PydocProtocol::errorMessage()
00078 {
00079 return QCString( "<html><body bgcolor=\"#FFFFFF\">" + i18n("Error in pydoc").local8Bit() + "</body></html>" );
00080 }
00081
00082
00083 void PydocProtocol::stat(const KURL &)
00084 {
00085 UDSAtom uds_atom;
00086 uds_atom.m_uds = KIO::UDS_FILE_TYPE;
00087 uds_atom.m_long = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
00088
00089 UDSEntry uds_entry;
00090 uds_entry.append(uds_atom);
00091
00092 statEntry(uds_entry);
00093 finished();
00094 }
00095
00096
00097 void PydocProtocol::listDir(const KURL &url)
00098 {
00099 error( KIO::ERR_CANNOT_ENTER_DIRECTORY, url.path() );
00100 }
00101
00102
00103 extern "C" {
00104
00105 int kdemain(int argc, char **argv)
00106 {
00107 KInstance instance( "kio_pydoc" );
00108 KGlobal::locale()->setMainCatalogue("kdevelop");
00109
00110 if (argc != 4) {
00111 fprintf(stderr, "Usage: kio_pydoc protocol domain-socket1 domain-socket2\n");
00112 exit(-1);
00113 }
00114
00115 PydocProtocol slave(argv[2], argv[3]);
00116 slave.dispatchLoop();
00117
00118 return 0;
00119 }
00120
00121 }
This file is part of the documentation for KDevelop Version 3.1.2.