2 /***************************************************************************
3 kio_finger.cpp - description
5 begin : Sun Aug 12 2000
6 copyright : (C) 2000 by Andreas Schlapbach
7 email : schlpbch@iam.unibe.ch
8 ***************************************************************************/
10 /***************************************************************************
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. *
17 ***************************************************************************/
19 #include "kio_finger.h"
27 #include <QTextStream>
32 #include <kcomponentdata.h>
34 #include <kstandarddirs.h>
42 static const QString defaultRefreshRate
= "60";
46 KDE_EXPORT
int kdemain( int argc
, char **argv
)
48 KComponentData
componentData( "kio_finger" );
50 //kDebug() << "*** Starting kio_finger " << getpid();
54 fprintf(stderr
, "Usage: kio_finger protocol domain-socket1 domain-socket2\n");
58 FingerProtocol
slave(argv
[2], argv
[3]);
61 //kDebug() << "*** kio_finger Done";
67 /* ---------------------------------------------------------------------------------- */
70 FingerProtocol::FingerProtocol(const QByteArray
&pool_socket
, const QByteArray
&app_socket
)
71 : QObject(), SlaveBase("finger", pool_socket
, app_socket
)
77 /* ---------------------------------------------------------------------------------- */
80 FingerProtocol::~FingerProtocol()
82 //kDebug() << "FingerProtocol::~FingerProtocol()";
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;
120 proc
<< *myPerlPath
<< *myFingerPerlScript
121 << *myFingerPath
<< *myFingerCSSFile
122 << refreshRate
<< myURL
->host() << myURL
->user();
124 proc
.setOutputChannelMode(KProcess::MergedChannels
);
126 data(proc
.readAllStandardOutput());
132 /* ---------------------------------------------------------------------------------- */
135 void FingerProtocol::mimetype(const KUrl
& /*url*/)
137 mimeType("text/html");
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."));
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."));
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."));
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."));
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");
218 myURL
->setHost("localhost");
222 * If no specific port is specified, set it to 79.
225 if(myURL
->port() == 0) {
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 /* ---------------------------------------------------------------------------------- */