ktelnetservice.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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 if (!url.host().isEmpty())
00069 host = url.host();
00070 else if (!url.path().isEmpty())
00071 host = url.path();
00072
00073 if (host.isEmpty() || host.startsWith("-"))
00074 {
00075 kdError() << "Invalid hostname " << host << endl;
00076 return 2;
00077 }
00078
00079 cmd << host;
00080
00081 if (url.port())
00082 cmd << QString::number(url.port());
00083
00084 app.kdeinitExec("konsole", cmd);
00085
00086 return 0;
00087 }
00088
00089
This file is part of the documentation for kdelibs Version 3.1.0.