add more spacing
[personal-kdebase.git] / runtime / kioslave / finger / kio_finger.cpp
blob2ddd90566fb14f2e04d7096990ebbf89d3ad94f1
2 /***************************************************************************
3 kio_finger.cpp - description
4 -------------------
5 begin : Sun Aug 12 2000
6 copyright : (C) 2000 by Andreas Schlapbach
7 email : schlpbch@iam.unibe.ch
8 ***************************************************************************/
10 /***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
19 #include "kio_finger.h"
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <sys/stat.h>
24 #include <string.h>
26 #include <QByteArray>
27 #include <QTextStream>
28 #include <QFile>
29 #include <QRegExp>
31 #include <kdebug.h>
32 #include <kcomponentdata.h>
33 #include <kglobal.h>
34 #include <kstandarddirs.h>
35 #include <klocale.h>
36 #include <kurl.h>
37 #include <KProcess>
40 using namespace KIO;
42 static const QString defaultRefreshRate = "60";
44 extern "C"
46 KDE_EXPORT int kdemain( int argc, char **argv )
48 KComponentData componentData( "kio_finger" );
50 //kDebug() << "*** Starting kio_finger " << getpid();
52 if (argc != 4)
54 fprintf(stderr, "Usage: kio_finger protocol domain-socket1 domain-socket2\n");
55 exit(-1);
58 FingerProtocol slave(argv[2], argv[3]);
59 slave.dispatchLoop();
61 //kDebug() << "*** kio_finger Done";
62 return 0;
67 /* ---------------------------------------------------------------------------------- */
70 FingerProtocol::FingerProtocol(const QByteArray &pool_socket, const QByteArray &app_socket)
71 : QObject(), SlaveBase("finger", pool_socket, app_socket)
73 getProgramPath();
77 /* ---------------------------------------------------------------------------------- */
80 FingerProtocol::~FingerProtocol()
82 //kDebug() << "FingerProtocol::~FingerProtocol()";
83 delete myURL;
84 delete myPerlPath;
85 delete myFingerPath;
86 delete myFingerPerlScript;
87 delete myFingerCSSFile;
91 /* ---------------------------------------------------------------------------------- */
94 void FingerProtocol::get(const KUrl& url )
96 //kDebug() << "kio_finger::get(const KUrl& url)";
98 this->parseCommandLine(url);
100 //kDebug() << "myURL: " << myURL->prettyUrl();
102 QString query = myURL->query();
103 QString refreshRate = defaultRefreshRate;
105 //kDebug() << "query: " << query;
107 // Check the validity of the query
109 QRegExp regExp("?refreshRate=[0-9][0-9]*", Qt::CaseSensitive, QRegExp::Wildcard);
110 if (query.contains(regExp)) {
111 //kDebug() << "looks like a valid query";
112 QRegExp regExp( "([0-9]+)" );
113 regExp.indexIn(query);
114 refreshRate = regExp.cap(0);
117 //kDebug() << "Refresh rate: " << refreshRate;
119 KProcess proc;
120 proc << *myPerlPath << *myFingerPerlScript
121 << *myFingerPath << *myFingerCSSFile
122 << refreshRate << myURL->host() << myURL->user();
124 proc.setOutputChannelMode(KProcess::MergedChannels);
125 proc.execute();
126 data(proc.readAllStandardOutput());
127 data(QByteArray());
128 finished();
132 /* ---------------------------------------------------------------------------------- */
135 void FingerProtocol::mimetype(const KUrl & /*url*/)
137 mimeType("text/html");
138 finished();
142 /* ---------------------------------------------------------------------------------- */
145 void FingerProtocol::getProgramPath()
147 //kDebug() << "kfingerMainWindow::getProgramPath()";
148 // Not to sure whether I'm using the right error number here. - schlpbch -
150 myPerlPath = new QString(KGlobal::dirs()->findExe("perl"));
151 if (myPerlPath->isEmpty())
153 //kDebug() << "Perl command not found";
154 this->error(ERR_CANNOT_LAUNCH_PROCESS,
155 i18n("Could not find the Perl program on your system, please install."));
156 exit();
158 else
160 //kDebug() << "Perl command found:" << *myPerlPath;
163 myFingerPath = new QString(KGlobal::dirs()->findExe("finger"));
164 if ((myFingerPath->isEmpty()))
166 //kDebug() << "Finger command not found";
167 this->error(ERR_CANNOT_LAUNCH_PROCESS,
168 i18n("Could not find the Finger program on your system, please install."));
169 exit();
171 else
173 //kDebug() << "Finger command found:" << *myFingerPath;
176 myFingerPerlScript = new QString(KStandardDirs::locate("data","kio_finger/kio_finger.pl"));
177 if (myFingerPerlScript->isEmpty())
179 //kDebug() << "kio_finger.pl script not found";
180 this->error(ERR_CANNOT_LAUNCH_PROCESS,
181 i18n("kio_finger Perl script not found."));
182 exit();
184 else
186 //kDebug() << "kio_finger perl script found: " << *myFingerPerlScript;
189 myFingerCSSFile = new QString(KStandardDirs::locate("data","kio_finger/kio_finger.css"));
190 if (myFingerCSSFile->isEmpty())
192 //kDebug() << "kio_finger.css file not found";
193 this->warning(i18n("kio_finger CSS script not found. Output will look ugly."));
195 else
197 //kDebug() << "kio_finger CSS file found: " << *myFingerCSSFile;
202 /* --------------------------------------------------------------------------- */
205 void FingerProtocol::parseCommandLine(const KUrl& url)
207 myURL = new KUrl(url);
210 * Generate a valid finger url
213 if(myURL->isEmpty() || !myURL->isValid() ||
214 (myURL->user().isEmpty() && myURL->host().isEmpty()))
216 myURL->setProtocol("finger");
217 myURL->setUser("");
218 myURL->setHost("localhost");
222 * If no specific port is specified, set it to 79.
225 if(myURL->port() == 0) {
226 myURL->setPort(79);
230 * If no refresh rate is given, set it to defaultRefreshRate
233 if (myURL->query().isEmpty()) {
234 myURL->setQuery("?refreshRate="+defaultRefreshRate);
238 /* ---------------------------------------------------------------------------------- */
239 #include "kio_finger.moc"
240 /* ---------------------------------------------------------------------------------- */