File: pydoc.cpp

package info (click to toggle)
kdevelop3 4%3A3.2.0-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 58,220 kB
  • ctags: 33,997
  • sloc: cpp: 278,404; ansic: 48,238; sh: 23,721; tcl: 19,882; perl: 5,498; makefile: 4,717; ruby: 1,610; python: 1,549; awk: 1,484; xml: 563; java: 359; php: 20; asm: 14; ada: 5; pascal: 4; fortran: 4; haskell: 2; sql: 1
file content (121 lines) | stat: -rw-r--r-- 2,424 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "pydoc.h"

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>

#include <qtextstream.h>
#include <kstandarddirs.h>
#include <kinstance.h>
#include <kprocess.h>
#include <kdeversion.h>
#include <kglobal.h>
#include <klocale.h>

using namespace KIO;


PydocProtocol::PydocProtocol(const QCString &pool, const QCString &app)
    : SlaveBase("pydoc", pool, app), key()
{
    python = KGlobal::dirs()->findExe("python");
    script = locate("data", "kio_pydoc/kde_pydoc.py");
}


PydocProtocol::~PydocProtocol()
{}


void PydocProtocol::get(const KURL& url)
{
    mimeType("text/html");
    key = url.path();

#if (KDE_VERSION > 305)
    QString cmd = KProcess::quote(python);
    cmd += " ";
    cmd += KProcess::quote(script);
    cmd += " -w ";
    cmd += KProcess::quote(key);
#else
    QString cmd = KShellProcess::quote(python);
    cmd += " ";
    cmd += KShellProcess::quote(script);
    cmd += " -w ";
    cmd += KShellProcess::quote(key);
#endif

    FILE *fd = popen(cmd.local8Bit().data(), "r");
    char buffer[4096];
    QByteArray array;

    while (!feof(fd)) {
        int n = fread(buffer, 1, 2048, fd);
        if (n == -1) {
            pclose(fd);
            return;
        }
        array.setRawData(buffer, n);
        data(array);
        array.resetRawData(buffer, n);
    }

    pclose(fd);
    finished();
}


void PydocProtocol::mimetype(const KURL&)
{
    mimeType( "text/html" );
    finished();
}


QCString PydocProtocol::errorMessage()
{
    return QCString( "<html><body bgcolor=\"#FFFFFF\">" + i18n("Error in pydoc").local8Bit() + "</body></html>" );
}


void PydocProtocol::stat(const KURL &/*url*/)
{
    UDSAtom uds_atom;
    uds_atom.m_uds = KIO::UDS_FILE_TYPE;
    uds_atom.m_long = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;

    UDSEntry uds_entry;
    uds_entry.append(uds_atom);

    statEntry(uds_entry);
    finished();
}


void PydocProtocol::listDir(const KURL &url)
{
    error( KIO::ERR_CANNOT_ENTER_DIRECTORY, url.path() );
}


extern "C" {

    int kdemain(int argc, char **argv)
    {
        KInstance instance( "kio_pydoc" );
        KGlobal::locale()->setMainCatalogue("kdevelop");

        if (argc != 4) {
            fprintf(stderr, "Usage: kio_pydoc protocol domain-socket1 domain-socket2\n");
            exit(-1);
        }

        PydocProtocol slave(argv[2], argv[3]);
        slave.dispatchLoop();

        return 0;
    }

}