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

KIO

  • sources
  • kde-4.12
  • kdelibs
  • kio
  • misc
ktelnetservice.cpp
Go to the documentation of this file.
1 //krazy:excludeall=license (it's a program, not a library)
2 /*
3  Copyright (c) 2001 Malte Starostik <malte@kde.org>
4  based on kmailservice.cpp,
5  Copyright (c) 2000 Simon Hausmann <hausmann@kde.org>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; see the file COPYING. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include <kapplication.h>
24 #include <ktoolinvocation.h>
25 #include <kauthorized.h>
26 #include <kmessagebox.h>
27 #include <kcmdlineargs.h>
28 #include <kdebug.h>
29 #include <klocale.h>
30 #include <kconfig.h>
31 #include <kconfiggroup.h>
32 #include <kurl.h>
33 
34 int main(int argc, char **argv)
35 {
36  KCmdLineOptions options;
37  options.add("+url");
38 
39  KCmdLineArgs::init(argc, argv, "ktelnetservice", "kdelibs4", ki18n("telnet service"),
40  "unknown", ki18n("telnet protocol handler"));
41  KCmdLineArgs::addCmdLineOptions(options);
42 
43  KApplication app;
44 
45  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
46 
47  if (args->count() != 1)
48  return 1;
49 
50  KConfig config("kdeglobals");
51  KConfigGroup cg(&config, "General");
52  QString terminal = cg.readPathEntry("TerminalApplication", "konsole");
53 
54  KUrl url(args->arg(0));
55  QStringList cmd;
56  if (terminal == "konsole")
57  cmd << "--noclose";
58 
59  cmd << "-e";
60  if ( url.protocol() == "telnet" )
61  cmd << "telnet";
62  else if ( url.protocol() == "ssh" )
63  cmd << "ssh";
64  else if ( url.protocol() == "rlogin" )
65  cmd << "rlogin";
66  else {
67  kError() << "Invalid protocol " << url.protocol() << endl;
68  return 2;
69  }
70 
71  if (!KAuthorized::authorize("shell_access"))
72  {
73  KMessageBox::sorry(0,
74  i18n("You do not have permission to access the %1 protocol.", url.protocol()));
75  return 3;
76  }
77 
78  if (!url.user().isEmpty())
79  {
80  cmd << "-l";
81  cmd << url.user();
82  }
83 
84  QString host;
85  if (!url.host().isEmpty())
86  host = url.host(); // telnet://host
87  else if (!url.path().isEmpty())
88  host = url.path(); // telnet:host
89 
90  if (host.isEmpty() || host.startsWith('-'))
91  {
92  kError() << "Invalid hostname " << host << endl;
93  return 2;
94  }
95 
96  cmd << host;
97 
98  if (url.port() > 0){
99  if ( url.protocol() == "ssh" )
100  cmd << "-p" << QString::number(url.port());
101  else
102  cmd << QString::number(url.port());
103  }
104 
105  KToolInvocation::kdeinitExec(terminal, cmd);
106 
107  return 0;
108 }
i18n
QString i18n(const char *text)
KConfigGroup::readPathEntry
QString readPathEntry(const QString &pKey, const QString &aDefault) const
KApplication
KCmdLineArgs::addCmdLineOptions
static void addCmdLineOptions(const KCmdLineOptions &options, const KLocalizedString &name=KLocalizedString(), const QByteArray &id=QByteArray(), const QByteArray &afterId=QByteArray())
kdebug.h
kapplication.h
kurl.h
KCmdLineOptions::add
KCmdLineOptions & add(const QByteArray &name, const KLocalizedString &description=KLocalizedString(), const QByteArray &defaultValue=QByteArray())
kauthorized.h
ki18n
KLocalizedString ki18n(const char *msg)
KCmdLineArgs::parsedArgs
static KCmdLineArgs * parsedArgs(const QByteArray &id=QByteArray())
kconfig.h
KCmdLineArgs
kError
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QString
KCmdLineArgs::arg
QString arg(int n) const
ktoolinvocation.h
klocale.h
main
int main(int argc, char **argv)
Definition: ktelnetservice.cpp:34
KUrl
KCmdLineArgs::count
int count() const
config
KSharedConfigPtr config()
kcmdlineargs.h
QStringList
KMessageBox::sorry
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
KConfigGroup
KConfig
KCmdLineArgs::init
static void init(int argc, char **argv, const QByteArray &appname, const QByteArray &catalog, const KLocalizedString &programName, const QByteArray &version, const KLocalizedString &description=KLocalizedString(), StdCmdLineArgs stdargs=StdCmdLineArgs(CmdLineArgQt|CmdLineArgKDE))
KAuthorized::authorize
bool authorize(const QString &genericAction)
kmessagebox.h
KCmdLineOptions
KToolInvocation::kdeinitExec
static int kdeinitExec(const QString &name, const QStringList &args=QStringList(), QString *error=0, int *pid=0, const QByteArray &startup_id=QByteArray())
kconfiggroup.h
KIO::number
QString number(KIO::filesize_t size)
Converts a size to a string representation Not unlike QString::number(...)
Definition: global.cpp:63
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal