From 4aed2c8219774f5d797760606b8489a92ddc5163 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kioslave/finger/Makefile.am | 27 ++++ kioslave/finger/finger.protocol | 9 ++ kioslave/finger/kio_finger.cpp | 266 ++++++++++++++++++++++++++++++++++++++++ kioslave/finger/kio_finger.css | 69 +++++++++++ kioslave/finger/kio_finger.h | 64 ++++++++++ kioslave/finger/kio_finger.pl | 175 ++++++++++++++++++++++++++ 6 files changed, 610 insertions(+) create mode 100644 kioslave/finger/Makefile.am create mode 100644 kioslave/finger/finger.protocol create mode 100644 kioslave/finger/kio_finger.cpp create mode 100644 kioslave/finger/kio_finger.css create mode 100644 kioslave/finger/kio_finger.h create mode 100644 kioslave/finger/kio_finger.pl (limited to 'kioslave/finger') diff --git a/kioslave/finger/Makefile.am b/kioslave/finger/Makefile.am new file mode 100644 index 000000000..6ddf78726 --- /dev/null +++ b/kioslave/finger/Makefile.am @@ -0,0 +1,27 @@ +## Makfile.am for kio_finger +## Edit from Makefile.am of kdebase/kioslave/man + +INCLUDES= $(all_includes) +AM_LDFLAGS = $(all_libraries) $(KDE_RPATH) + +####### Files + +kde_module_LTLIBRARIES = kio_finger.la + +kio_finger_la_SOURCES = kio_finger.cpp +kio_finger_la_LIBADD = -lkio +kio_finger_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) + +noinst_HEADERS = kio_finger.h + +kdelnk_DATA = finger.protocol +kdelnkdir = $(kde_servicesdir) + +kio_finger_data_DATA = kio_finger.pl kio_finger.css +kio_finger_datadir = $(kde_datadir)/kio_finger +EXTRA_DIST=$(kio_finger_data_DATA) + +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/kio_finger.pot diff --git a/kioslave/finger/finger.protocol b/kioslave/finger/finger.protocol new file mode 100644 index 000000000..71d1b8e93 --- /dev/null +++ b/kioslave/finger/finger.protocol @@ -0,0 +1,9 @@ +[Protocol] +exec=kio_finger +protocol=finger +input=none +output=stream +reading=true +defaultMimetype=text/html +DocPath=kioslave/finger.html +Icon=kdmconfig diff --git a/kioslave/finger/kio_finger.cpp b/kioslave/finger/kio_finger.cpp new file mode 100644 index 000000000..c940998b9 --- /dev/null +++ b/kioslave/finger/kio_finger.cpp @@ -0,0 +1,266 @@ + +/*************************************************************************** + kio_finger.cpp - description + ------------------- + begin : Sun Aug 12 2000 + copyright : (C) 2000 by Andreas Schlapbach + email : schlpbch@iam.unibe.ch + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "kio_finger.h" + + +using namespace KIO; + +static const QString defaultRefreshRate = "60"; + +extern "C" +{ + KDE_EXPORT int kdemain( int argc, char **argv ) + { + KInstance instance( "kio_finger" ); + + //kdDebug() << "*** Starting kio_finger " << getpid() << endl; + + if (argc != 4) + { + fprintf(stderr, "Usage: kio_finger protocol domain-socket1 domain-socket2\n"); + exit(-1); + } + + FingerProtocol slave(argv[2], argv[3]); + slave.dispatchLoop(); + + //kdDebug() << "*** kio_finger Done" << endl; + return 0; + } +} + + +/* ---------------------------------------------------------------------------------- */ + + +FingerProtocol::FingerProtocol(const QCString &pool_socket, const QCString &app_socket) + : QObject(), SlaveBase("finger", pool_socket, app_socket) +{ + myStdStream = new QString(); + getProgramPath(); +} + + +/* ---------------------------------------------------------------------------------- */ + + +FingerProtocol::~FingerProtocol() +{ + //kdDebug() << "FingerProtocol::~FingerProtocol()" << endl; + delete myURL; + delete myPerlPath; + delete myFingerPath; + delete myFingerPerlScript; + delete myFingerCSSFile; + delete myStdStream; +} + + +/* ---------------------------------------------------------------------------------- */ + + +void FingerProtocol::get(const KURL& url ) +{ + //kdDebug() << "kio_finger::get(const KURL& url)" << endl ; + + this->parseCommandLine(url); + + //kdDebug() << "myURL: " << myURL->prettyURL() << endl; + + // Reset the stream + *myStdStream=""; + + QString query = myURL->query(); + QString refreshRate = defaultRefreshRate; + + //kdDebug() << "query: " << query << endl; + + // Check the validity of the query + + QRegExp regExp("?refreshRate=[0-9][0-9]*", true, true); + if (query.contains(regExp)) { + //kdDebug() << "looks like a valid query" << endl; + QRegExp regExp( "([0-9]+)" ); + regExp.search(query); + refreshRate = regExp.cap(0); + } + + //kdDebug() << "Refresh rate: " << refreshRate << endl; + + myKProcess = new KProcess(); + *myKProcess << *myPerlPath << *myFingerPerlScript + << *myFingerPath << *myFingerCSSFile + << refreshRate << myURL->host() << myURL->user() ; + + connect(myKProcess, SIGNAL(receivedStdout(KProcess *, char *, int)), + this, SLOT(slotGetStdOutput(KProcess *, char *, int))); + //connect(myKProcess, SIGNAL(receivedStderr(KProcess *, char *, int)), + // this, SLOT(slotGetStdOutput(KProcess *, char *, int))); + + myKProcess->start(KProcess::Block, KProcess::All); + + data(QCString(myStdStream->local8Bit())); + + data(QByteArray()); + finished(); + + //clean up + + delete myKProcess; +} + + +/* ---------------------------------------------------------------------------------- */ + + +void FingerProtocol::slotGetStdOutput(KProcess* /* p */, char *s, int len) +{ + //kdDebug() << "void FingerProtocol::slotGetStdoutOutput()" << endl; + *myStdStream += QString::fromLocal8Bit(s, len); +} + + +/* ---------------------------------------------------------------------------------- */ + + +void FingerProtocol::mimetype(const KURL & /*url*/) +{ + mimeType("text/html"); + finished(); +} + + +/* ---------------------------------------------------------------------------------- */ + + +void FingerProtocol::getProgramPath() +{ + //kdDebug() << "kfingerMainWindow::getProgramPath()" << endl; + // Not to sure wether I'm using the right error number here. - schlpbch - + + myPerlPath = new QString(KGlobal::dirs()->findExe("perl")); + if (myPerlPath->isEmpty()) + { + //kdDebug() << "Perl command not found" << endl; + this->error(ERR_CANNOT_LAUNCH_PROCESS, + i18n("Could not find the Perl program on your system, please install.")); + exit(); + } + else + { + //kdDebug() << "Perl command found:" << *myPerlPath << endl; + } + + myFingerPath = new QString(KGlobal::dirs()->findExe("finger")); + if ((myFingerPath->isEmpty())) + { + //kdDebug() << "Finger command not found" << endl; + this->error(ERR_CANNOT_LAUNCH_PROCESS, + i18n("Could not find the Finger program on your system, please install.")); + exit(); + } + else + { + //kdDebug() << "Finger command found:" << *myFingerPath << endl; + } + + myFingerPerlScript = new QString(locate("data","kio_finger/kio_finger.pl")); + if (myFingerPerlScript->isEmpty()) + { + //kdDebug() << "kio_finger.pl script not found" << endl; + this->error(ERR_CANNOT_LAUNCH_PROCESS, + i18n("kio_finger Perl script not found.")); + exit(); + } + else + { + //kdDebug() << "kio_finger perl script found: " << *myFingerPerlScript << endl; + } + + myFingerCSSFile = new QString(locate("data","kio_finger/kio_finger.css")); + if (myFingerCSSFile->isEmpty()) + { + //kdDebug() << "kio_finger.css file not found" << endl; + this->warning(i18n("kio_finger CSS script not found. Output will look ugly.")); + } + else + { + //kdDebug() << "kio_finger CSS file found: " << *myFingerCSSFile << endl; + } +} + + +/* --------------------------------------------------------------------------- */ + + +void FingerProtocol::parseCommandLine(const KURL& url) +{ + myURL = new KURL(url); + + /* + * Generate a valid finger url + */ + + if(myURL->isEmpty() || !myURL->isValid() || + (myURL->user().isEmpty() && myURL->host().isEmpty())) + { + myURL->setProtocol("finger"); + myURL->setUser(""); + myURL->setHost("localhost"); + } + + /* + * If no specific port is specified, set it to 79. + */ + + if(myURL->port() == 0) { + myURL->setPort(79); + } + + /* + * If no refresh rate is given, set it to defaultRefreshRate + */ + + if (myURL->query().isEmpty()) { + myURL->setQuery("?refreshRate="+defaultRefreshRate); + } +} + +/* ---------------------------------------------------------------------------------- */ +#include "kio_finger.moc" +/* ---------------------------------------------------------------------------------- */ + diff --git a/kioslave/finger/kio_finger.css b/kioslave/finger/kio_finger.css new file mode 100644 index 000000000..06deb81aa --- /dev/null +++ b/kioslave/finger/kio_finger.css @@ -0,0 +1,69 @@ +BODY { + color: #FFFFCC; + background-color: #000000; + padding: 2em; + margin: auto; +} + +A:link {color: #82A7D0} +A:visited {color: #999999} +A:active {color: #999999} + +H1 { + color: #999999; + background-color: #000000; + font: 200% Helvetica, sans-serif; + font-variant: normal; + padding: 1em; + margin: auto; +} + +.mainTable { + background-color: #000000; + border: thin solid; + margin: auto; +} + + +.courierText { + color: #FFFFCC; + background-color: #000000; + font: 120% Courier, sans-serif; + font-variant: normal; + text-align: left; + padding: 0em; +} + +.commandText { + color: #FFFFCC; + background-color: #000000; + font: 120% Courier, sans-serif; + font-variant: normal; + text-align: center; + padding: 0.5em; +} + +.niceText { + color: #009999; + background-color: #000000; + font: 120% Arial, sans-serif; + font-variant: normal; + text-align: center; + padding: 0.5em; +} + +.finger { color: #82A7D0} +.domainName { color: #D0A000} +.ipNumber { color: #D0A000} +.os { color: #82A7D0} +.username { color: #82A7D0} +.directory { color: #D0A000} +.shell { color: #D0A000} +.notLoggedIn { color: #00A000} +.loggedIn { color: #B00000} +.newMail { color: #82A7D0} +.plan { color: #D0A000} +.noNewMail { color: #BB0000} +.noPlan { color: #BB0000} + + diff --git a/kioslave/finger/kio_finger.h b/kioslave/finger/kio_finger.h new file mode 100644 index 000000000..8d63236d4 --- /dev/null +++ b/kioslave/finger/kio_finger.h @@ -0,0 +1,64 @@ + +/*************************************************************************** + kio_finger.h - description + ------------------- + begin : Sun Aug 12 2000 + copyright : (C) 2000 by Andreas Schlapbach + email : schlpbch@iam.unibe.ch + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + + +#ifndef __kio_finger_h__ +#define __kio_finger_h__ + +#include +#include + +#include +#include +#include +#include + +class FingerProtocol : public QObject, public KIO::SlaveBase +{ + Q_OBJECT + +public: + + FingerProtocol(const QCString &pool_socket, const QCString &app_socket); + virtual ~FingerProtocol(); + + virtual void mimetype(const KURL& url); + virtual void get(const KURL& url); + +private slots: + void slotGetStdOutput(KProcess*, char*, int); + +private: + KURL *myURL; + + QString *myPerlPath; + QString *myFingerPath; + QString *myFingerPerlScript; + QString *myFingerCSSFile; + + QString *myStdStream; + + + KProcess *myKProcess; + + void getProgramPath(); + void parseCommandLine(const KURL& url); +}; + + +#endif diff --git a/kioslave/finger/kio_finger.pl b/kioslave/finger/kio_finger.pl new file mode 100644 index 000000000..8965ea523 --- /dev/null +++ b/kioslave/finger/kio_finger.pl @@ -0,0 +1,175 @@ +##!/usr/bin/perl +# +# Copyright Andreas Schlapbach, schlpbch@iam.unibe.ch, 2001 +# http://iamexwiwww.unibe.ch/studenten/kfinger +# +# Touch at your own risk. + + +# Highlight mail addresses or url + +$mails = '/>/g; + +$USER =~ s/&/&/g; +$USER =~ s//>/g; + +# HTML Header + +print < + + + + finger $USER\@$HOST + + + + + + + + + \n"; + +# Finger-Talk options + +if ($USER) # is $USER nil ? +{ +print < + + + +UserQuery +} +else +{ +print < +
+

finger $USER\@$HOST

+
+ +HTMLHeader + +# Run finger command and save it into a buffer + +open(F, "-|") || exec $FINGERCMD, "$USER\@$HOST"; +@lines = ; +close(F); + +# Do highlighting using perl regular expressions on every line received. +# Order is important here. + +foreach $output (@lines) + { + $output =~ s/((\w)+\@((\w)+(.))*(\w)+)/$mails$1$urlspace$1$urlend/gi; # Highlight email address + $output =~ s/((http|ftp)(:\/\/)(\S)+)/$urls$1$urlspace$1$urlend/gi; # Highlight urls + $output =~ s/((\d)+\.(\d)+\.(\d)+\.(\d)+)/$ipNumber$1$close/gi; # Highlight IP number + $output =~ s/((\w)+\.(\w)+\.(\w|-)+\s)/$domainName$1$close/gi; # Highlight domain name (\s is important) + $output =~ s/(finger:)/$finger$1$close/gim; # Highlight finger + $output =~ s/(Linux)/$os$1$close/gim; # Highlight Linux + if ($USER) # is $USER nil ? + { + $output =~ s/^Login:\s*(\w*)/Login: $mails$1\@$HOST$urlspace$1$urlend/gi; + $output =~ s/^Login Name:\s*(\w*)/Login Name:$mails$1\@$HOST$urlspace$1$urlend/gi; + $output =~ s/Name:(((\s*)(\w+))+\n)/Name:$username$1$close\n/gi; # Linux + $output =~ s/In real life:(((\s*)(\w+))+\n)/In real life:$username$1$close\n/gi; # Solaris + $output =~ s/^Directory:((\s*)(\/(\w)+)+)/Directory:$directory$1$close/gi; # Highlight Directory + $output =~ s/Shell:((\s*)(\/(\w)+)+)/Shell:$shell$1$close/gi; # Highlight Shell + $output =~ s/(not presently logged)/$notLoggedIn$1$close/gi; + $output =~ s/con (\w*)/con $loggedIn$1$close/gi; + $output =~ s/^(New mail)/$newMail$1$close/gi; + $output =~ s/^(No mail.)/$noNewMail$1$close/gim; + $output =~ s/^(Plan:)/$plan$1$close/gi; + $output =~ s/^(No plan.)/$noPlan$1$close/gim; + } + else + { + $output =~ s/^(\w+)/$mails$1\@$HOST$urlspace$1$urlend/m unless ($output =~ m/$keywordlist/m); + } + # line consists of white space only? + if ($output =~ m/\S/gi) + { + print " \n"; + } + else + { + print " \n"; + } +} + +print "
$output
  
\n"; +print "
+ finger +
+HostQueryHead + + @lines = split /^/m, $buffer; + foreach $output2 (@lines) + { + if ($output2 =~ m/^(\w+)/gi and not ($output2 =~ m/$keywordlist/m)) + { + $USER = $&; + print " \n"; + # - talk\n\n"; + } + else + { + print " \n"; + } + } + +print < + + +HostQueryTail +} + +# HTMLTail + +print < + + +
finger\n
  
refresh rate: $REFRESHRATE seconds.
+ + +HTMLTail -- cgit v1.2.3