kio Library API Documentation

ktelnetservice.cpp

00001 /*
00002    Copyright (c) 2001 Malte Starostik <malte@kde.org>
00003    based on kmailservice.cpp,
00004    Copyright (c) 2000 Simon Hausmann <hausmann@kde.org>
00005 
00006    This program is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; see the file COPYING.  If not, write to
00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.
00020 */
00021 
00022 // $Id: ktelnetservice.cpp,v 1.3 2002/10/31 21:54:06 faure Exp $
00023 
00024 #include <kapplication.h>
00025 #include <kcmdlineargs.h>
00026 #include <kdebug.h>
00027 #include <klocale.h>
00028 #include <kprocess.h>
00029 
00030 static const KCmdLineOptions options[] =
00031 {
00032     {"+url", 0, 0},
00033     {0, 0, 0}
00034 };
00035 
00036 int main(int argc, char **argv)
00037 {
00038     KLocale::setMainCatalogue("kdelibs");
00039     KCmdLineArgs::init(argc, argv, "ktelnetservice", I18N_NOOP("telnet service"), I18N_NOOP("telnet protocol handler"));
00040     KCmdLineArgs::addCmdLineOptions(options);
00041 
00042     KApplication app;
00043 
00044     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00045 
00046     if (args->count() != 1)
00047         return 1;
00048 
00049     KURL url(args->arg(0));
00050     QStringList cmd;
00051 
00052     cmd << "-e";
00053         if ( url.protocol() == "telnet" )
00054             cmd << "telnet";
00055         else if ( url.protocol() == "rlogin" )
00056             cmd << "rlogin";
00057         else {
00058             kdError() << "Invalid protocol " << url.protocol() << endl;
00059             return 2;
00060         }
00061     if (!url.user().isEmpty())
00062     {
00063         cmd << "-l";
00064         cmd << url.user();
00065     }
00066 
00067     QString host;
00068     host = url.host();
00069     if (host.isEmpty() || host.startsWith("-"))
00070     {
00071         kdError() << "Invalid hostname " << host << endl;
00072         return 2;
00073     }
00074 
00075     cmd << host;
00076 
00077     if (url.port())
00078         cmd << QString::number(url.port());
00079 
00080     app.kdeinitExec("konsole", cmd);
00081 
00082     return 0;
00083 }
00084 
00085 // vim: ts=4 sw=4 noet
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Fri Feb 24 21:54:12 2006 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001