• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KIO

ktelnetservice.cpp

Go to the documentation of this file.
00001 //krazy:excludeall=license (it's a program, not a library)
00002 /*
00003    Copyright (c) 2001 Malte Starostik <malte@kde.org>
00004    based on kmailservice.cpp,
00005    Copyright (c) 2000 Simon Hausmann <hausmann@kde.org>
00006 
00007    This program is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; see the file COPYING.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include <kapplication.h>
00024 #include <ktoolinvocation.h>
00025 #include <kauthorized.h>
00026 #include <kmessagebox.h>
00027 #include <kcmdlineargs.h>
00028 #include <kdebug.h>
00029 #include <klocale.h>
00030 #include <kconfig.h>
00031 #include <kconfiggroup.h>
00032 #include <kurl.h>
00033 
00034 int main(int argc, char **argv)
00035 {
00036     KCmdLineOptions options;
00037     options.add("+url");
00038 
00039     KCmdLineArgs::init(argc, argv, "ktelnetservice", "kdelibs4", ki18n("telnet service"),
00040                "unknown", ki18n("telnet protocol handler"));
00041     KCmdLineArgs::addCmdLineOptions(options);
00042 
00043     KApplication app;
00044 
00045     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00046 
00047     if (args->count() != 1)
00048         return 1;
00049 
00050     KConfig config("kdeglobals");
00051     KConfigGroup cg(&config, "General");
00052     QString terminal = cg.readPathEntry("TerminalApplication", "konsole");
00053 
00054     KUrl url(args->arg(0));
00055     QStringList cmd;
00056     if (terminal == "konsole")
00057         cmd << "--noclose";
00058 
00059     cmd << "-e";
00060         if ( url.protocol() == "telnet" )
00061             cmd << "telnet";
00062         else if ( url.protocol() == "ssh" )
00063             cmd << "ssh";
00064         else if ( url.protocol() == "rlogin" )
00065             cmd << "rlogin";
00066         else {
00067             kError() << "Invalid protocol " << url.protocol() << endl;
00068             return 2;
00069         }
00070 
00071         if (!KAuthorized::authorize("shell_access"))
00072         {
00073             KMessageBox::sorry(0,
00074                 i18n("You do not have permission to access the %1 protocol.", url.protocol()));
00075             return 3;
00076         }
00077 
00078     if (!url.user().isEmpty())
00079     {
00080         cmd << "-l";
00081         cmd << url.user();
00082     }
00083 
00084         QString host;
00085         if (!url.host().isEmpty())
00086            host = url.host(); // telnet://host
00087         else if (!url.path().isEmpty())
00088            host = url.path(); // telnet:host
00089 
00090         if (host.isEmpty() || host.startsWith('-'))
00091         {
00092             kError() << "Invalid hostname " << host << endl;
00093             return 2;
00094         }
00095 
00096         cmd << host;
00097 
00098     if (url.port() > 0){
00099             if ( url.protocol() == "ssh" )
00100         cmd << "-p" << QString::number(url.port());
00101         else
00102         cmd << QString::number(url.port());
00103     }
00104 
00105     KToolInvocation::kdeinitExec(terminal, cmd);
00106 
00107     return 0;
00108 }

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal