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

kio

ktelnetservice.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 // $Id: ktelnetservice.cpp 539297 2006-05-10 09:55:22Z hasso $
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 #include <ksimpleconfig.h>
00031 
00032 static const KCmdLineOptions options[] =
00033 {
00034     {"+url", 0, 0},
00035     KCmdLineLastOption
00036 };
00037 
00038 int main(int argc, char **argv)
00039 {
00040     KLocale::setMainCatalogue("kdelibs");
00041     KCmdLineArgs::init(argc, argv, "ktelnetservice", I18N_NOOP("telnet service"),
00042                I18N_NOOP("telnet protocol handler"), "unknown");
00043     KCmdLineArgs::addCmdLineOptions(options);
00044 
00045     KApplication app;
00046 
00047     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00048     
00049     if (args->count() != 1)
00050         return 1;
00051 
00052     KConfig *config = new KConfig("kdeglobals", true);
00053     config->setGroup("General");
00054     QString terminal = config->readPathEntry("TerminalApplication", "konsole");
00055 
00056     KURL url(args->arg(0));
00057     QStringList cmd;
00058     if (terminal == "konsole")
00059         cmd << "--noclose";
00060 
00061     cmd << "-e";
00062         if ( url.protocol() == "telnet" )
00063             cmd << "telnet";
00064         else if ( url.protocol() == "ssh" )
00065             cmd << "ssh";
00066         else if ( url.protocol() == "rlogin" )
00067             cmd << "rlogin";
00068         else {
00069             kdError() << "Invalid protocol " << url.protocol() << endl;
00070             return 2;
00071         }
00072         
00073         if (!app.authorize("shell_access"))
00074         {
00075             KMessageBox::sorry(0, 
00076                 i18n("You do not have permission to access the %1 protocol.").arg(url.protocol()));
00077             return 3;
00078         }
00079         
00080     if (!url.user().isEmpty())
00081     {
00082         cmd << "-l";
00083         cmd << url.user();
00084     }
00085 
00086         QString host;
00087         if (!url.host().isEmpty())
00088            host = url.host(); // telnet://host
00089         else if (!url.path().isEmpty())
00090            host = url.path(); // telnet:host
00091 
00092         if (host.isEmpty() || host.startsWith("-"))
00093         {
00094             kdError() << "Invalid hostname " << host << endl;
00095             return 2;
00096         }
00097 
00098         cmd << host;
00099         
00100     if (url.port()){
00101             if ( url.protocol() == "ssh" )
00102         cmd << "-p" << QString::number(url.port());
00103         else
00104         cmd << QString::number(url.port());
00105     }
00106 
00107     app.kdeinitExec(terminal, cmd);
00108 
00109     return 0;
00110 }
00111 
00112 // vim: ts=4 sw=4 noet

kio

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

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
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