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.7 2004/01/08 10:04:20 bhards Exp $
00023 
00024 #include <kapplication.h>
00025 #include <kmessagebox.h>
00026 #include <kcmdlineargs.h>
00027 #include <kdebug.h>
00028 #include <klocale.h>
00029 #include <kprocess.h>
00030 
00031 static const KCmdLineOptions options[] =
00032 {
00033     {"+url", 0, 0},
00034     KCmdLineLastOption
00035 };
00036 
00037 int main(int argc, char **argv)
00038 {
00039     KLocale::setMainCatalogue("kdelibs");
00040     KCmdLineArgs::init(argc, argv, "ktelnetservice", I18N_NOOP("telnet service"),
00041                I18N_NOOP("telnet protocol handler"), "unknown");
00042     KCmdLineArgs::addCmdLineOptions(options);
00043 
00044     KApplication app;
00045 
00046     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00047     
00048     if (args->count() != 1)
00049         return 1;
00050 
00051     KURL url(args->arg(0));
00052     QStringList cmd;
00053     cmd << "--noclose";
00054 
00055     cmd << "-e";
00056         if ( url.protocol() == "telnet" )
00057             cmd << "telnet";
00058         else if ( url.protocol() == "rlogin" )
00059             cmd << "rlogin";
00060         else {
00061             kdError() << "Invalid protocol " << url.protocol() << endl;
00062             return 2;
00063         }
00064         
00065         if (!app.authorize("shell_access"))
00066         {
00067             KMessageBox::sorry(0, 
00068                 i18n("You do not have permission to access the %1 protocol.").arg(url.protocol()));
00069             return 3;
00070         }
00071         
00072     if (!url.user().isEmpty())
00073     {
00074         cmd << "-l";
00075         cmd << url.user();
00076     }
00077 
00078         if (!url.host().isEmpty())
00079            cmd << url.host(); // telnet://host
00080         else if (!url.path().isEmpty())
00081            cmd << url.path(); // telnet:host
00082         
00083     if (url.port())
00084         cmd << QString::number(url.port());
00085 
00086     app.kdeinitExec("konsole", cmd);
00087 
00088     return 0;
00089 }
00090 
00091 // vim: ts=4 sw=4 noet
KDE Logo
This file is part of the documentation for kio Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:35:07 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003