Index: kdecore/kernel/ktoolinvocation.cpp
===================================================================
--- kdecore/kernel/ktoolinvocation.cpp	(wersja 791099)
+++ kdecore/kernel/ktoolinvocation.cpp	(kopia robocza)
@@ -22,14 +22,20 @@
 #include "klauncher_iface.h"
 #include "kdebug.h"
 #include "kglobal.h"
+#include "kstandarddirs.h"
+#include "kcomponentdata.h"
+#include "kurl.h"
+#include "kmessage.h"
+#include <klockfile.h>
+#include <klocale.h>
+
 #include <QMutex>
 #include <QMutexLocker>
 #include <QCoreApplication>
-#include <klocale.h>
+#include <QThread>
 
 #include <errno.h>
 
-#include <QThread>
 
 KToolInvocation *KToolInvocation::self()
 {
@@ -229,5 +235,125 @@
                                 name, args, error, 0, pid, startup_id, false);
 }
 
+void KToolInvocation::invokeHelp( const QString& anchor,
+                                  const QString& _appname,
+                                  const QByteArray& startup_id )
+{
+    if (!isMainThreadActive())
+        return;
 
+    QString url;
+    QString appname;
+    if (_appname.isEmpty()) {
+        appname = QCoreApplication::instance()->applicationName();
+    } else
+        appname = _appname;
+
+    if (!anchor.isEmpty())
+        url = QString("help:/%1?anchor=%2").arg(appname).arg(anchor);
+    else
+        url = QString("help:/%1/index.html").arg(appname);
+
+    QDBusInterface *iface = new QDBusInterface(QLatin1String("org.kde.khelpcenter"),
+                                               QLatin1String("/KHelpCenter"),
+                                               QLatin1String("org.kde.khelpcenter.khelpcenter"),
+                                               QDBusConnection::sessionBus());
+    if ( !iface->isValid() )
+    {
+        QString error;
+#ifdef Q_WS_WIN
+        // startServiceByDesktopName() does not work yet; KRun:processDesktopExec returned 'KRun: syntax error in command "khelpcenter %u" , service "KHelpCenter" '
+        if (kdeinitExec( "khelpcenter", QStringList() << url, &error, 0, startup_id ))
+#else
+        if (startServiceByDesktopName("khelpcenter", url, &error, 0, 0, startup_id, false))
+#endif
+        {
+            KMessage::message(KMessage::Error,
+                              i18n("Could not launch the KDE Help Center:\n\n%1", error),
+                              i18n("Could not Launch Help Center"));
+            return;
+        }
+
+        delete iface;
+        iface = new QDBusInterface(QLatin1String("org.kde.khelpcenter"),
+                                   QLatin1String("/KHelpCenter"),
+                                   QLatin1String("org.kde.khelpcenter.khelpcenter"),
+                                   QDBusConnection::sessionBus());
+    }
+
+    iface->call("openUrl", url, startup_id );
+    delete iface;
+}
+
+void KToolInvocation::invokeMailer(const QString &address, const QString &subject, const QByteArray& startup_id)
+{
+    if (!isMainThreadActive())
+        return;
+
+    invokeMailer(address, QString(), QString(), subject, QString(), QString(),
+                 QStringList(), startup_id );
+}
+
+void KToolInvocation::invokeMailer(const KUrl &mailtoURL, const QByteArray& startup_id, bool allowAttachments )
+{
+    if (!isMainThreadActive())
+        return;
+
+    QString address = KUrl::fromPercentEncoding(mailtoURL.path().toLatin1()), subject, cc, bcc, body;
+    QStringList queries = mailtoURL.query().mid(1).split( '&');
+    QStringList attachURLs;
+    for (QStringList::Iterator it = queries.begin(); it != queries.end(); ++it)
+    {
+        QString q = (*it).toLower();
+        if (q.startsWith("subject="))
+            subject = KUrl::fromPercentEncoding((*it).mid(8).toLatin1());
+        else
+            if (q.startsWith("cc="))
+                cc = cc.isEmpty()? KUrl::fromPercentEncoding((*it).mid(3).toLatin1()): cc + ',' + KUrl::fromPercentEncoding((*it).mid(3).toLatin1());
+            else
+                if (q.startsWith("bcc="))
+                    bcc = bcc.isEmpty()? KUrl::fromPercentEncoding((*it).mid(4).toLatin1()): bcc + ',' + KUrl::fromPercentEncoding((*it).mid(4).toLatin1());
+                else
+                    if (q.startsWith("body="))
+                        body = KUrl::fromPercentEncoding((*it).mid(5).toLatin1());
+                    else
+                        if (allowAttachments && q.startsWith("attach="))
+                            attachURLs.push_back(KUrl::fromPercentEncoding((*it).mid(7).toLatin1()));
+                        else
+                            if (allowAttachments && q.startsWith("attachment="))
+                                attachURLs.push_back(KUrl::fromPercentEncoding((*it).mid(11).toLatin1()));
+                            else
+                                if (q.startsWith("to="))
+                                    address = address.isEmpty()? KUrl::fromPercentEncoding((*it).mid(3).toLatin1()): address + ',' + KUrl::fromPercentEncoding((*it).mid(3).toLatin1());
+    }
+
+    invokeMailer( address, cc, bcc, subject, body, QString(), attachURLs, startup_id );
+}
+
+void KToolInvocation::startKdeinit()
+{
+  KComponentData inst( "startkdeinitlock" );
+  KLockFile lock( KStandardDirs::locateLocal( "tmp", "startkdeinitlock", inst ));
+  if( lock.lock( KLockFile::NoBlockFlag ) != KLockFile::LockOK ) {
+     lock.lock();
+     if( QDBusConnection::sessionBus().interface()->isServiceRegistered( "org.kde.klauncher" ))
+         return; // whoever held the lock has already started it
+  }
+  // Try to launch kdeinit.
+  QString srv = KStandardDirs::findExe(QLatin1String("kdeinit4"));
+  if (srv.isEmpty())
+     return;
+//   this is disabled because we are in kdecore
+//  const bool gui = qApp && qApp->type() != QApplication::Tty;
+//  if ( gui )
+//    qApp->setOverrideCursor( Qt::WaitCursor );
+  QStringList args;
+#ifndef Q_WS_WIN
+  args += "--suicide";
+#endif
+  QProcess::execute(srv, args);
+//  if ( gui )
+//    qApp->restoreOverrideCursor();
+}
+
 #include "ktoolinvocation.moc"
Index: kdecore/kernel/ktoolinvocation_win.cpp
===================================================================
--- kdecore/kernel/ktoolinvocation_win.cpp	(wersja 791099)
+++ kdecore/kernel/ktoolinvocation_win.cpp	(kopia robocza)
@@ -1,6 +1,6 @@
 /*
    This file is part of the KDE libraries
-   Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>
+   Copyright (C) 2004-2008 Jaroslaw Staniek <js@iidea.pl>
    Copyright (C) 2006 Ralf Habacker <ralf.habacker@freenet.de>
 
    This library is free software; you can redistribute it and/or
@@ -23,146 +23,41 @@
 
 #include "kmessage.h"
 #include "klocale.h"
+#include "kurl.h"
+
 #include <QProcess>
 #include <QtCore/QCoreApplication>
 #include <QtCore/QHash>
 #include <QtDBus/QtDBus>
-#include <kcomponentdata.h>
-#include <klockfile.h>
-#include <kstandarddirs.h>
 
 #include "windows.h"
 #include "shellapi.h"
 
 
-void KToolInvocation::invokeHelp( const QString& anchor,
-                               const QString& _appname,
-                               const QByteArray& startup_id )
-{
-    if (!isMainThreadActive())
-        return;
-
-    QString url;
-    QString appname;
-    if (_appname.isEmpty()) {
-        appname = QCoreApplication::instance()->applicationName();
-    } else
-        appname = _appname;
-
-    if (!anchor.isEmpty())
-        url = QString("help:/%1?anchor=%2").arg(appname).arg(anchor);
-    else
-        url = QString("help:/%1/index.html").arg(appname);
-
-    QDBusInterface *iface = new QDBusInterface(QLatin1String("org.kde.khelpcenter"),
-                                               QLatin1String("/KHelpCenter"),
-                                               QLatin1String("org.kde.khelpcenter.khelpcenter"),
-                                               QDBusConnection::sessionBus());
-    if ( !iface->isValid() )
-    {
-        QString error;
-#if 1
-		if (kdeinitExec( "khelpcenter", QStringList() << url, &error, 0, startup_id ))
-#else
-		// does not work yet KRun:processDesktopExec returned 'KRun: syntax error in command "khelpcenter %u" , service "KHelpCenter" '
-        if (startServiceByDesktopName("khelpcenter", url, &error, 0, 0, startup_id, false))
-#endif
-        {
-            KMessage::message(KMessage::Error,
-                              i18n("Could not launch the KDE Help Center:\n\n%1", error),
-                              i18n("Could not Launch Help Center"));
-            return;
-        }
-        delete iface;
-        iface = new QDBusInterface(QLatin1String("org.kde.khelpcenter"),
-                                   QLatin1String("/KHelpCenter"),
-                                   QLatin1String("org.kde.khelpcenter.khelpcenter"),
-                                   QDBusConnection::sessionBus());
-    }
-
-    iface->call("openUrl", url, startup_id );
-    delete iface;
-}
-
-
 void KToolInvocation::invokeBrowser( const QString &url, const QByteArray& startup_id )
 {
-/*
    QString sOpen( "open" );
    ShellExecuteW(0, ( LPCWSTR )sOpen.utf16(), ( LPCWSTR )url.utf16(), 0, 0, SW_NORMAL);
-*/
 }
 
-void KToolInvocation::invokeMailer(const QString &address, const QString &subject, const QByteArray& startup_id)
-{
-/*
-   invokeMailer(address, QString::null, QString::null, subject, QString::null, QString::null,
-       QStringList(), startup_id );
-*/
-}
-
-void KToolInvocation::invokeMailer(const KUrl &mailtoURL, const QByteArray& startup_id, bool allowAttachments )
-{
-/*
-   QString address = KUrl::fromPercentEncoding(mailtoURL.path().toLatin1()), subject, cc, bcc, body;
-   QStringList queries = mailtoURL.query().mid(1).split( '&');
-   QStringList attachURLs;
-   for (QStringList::Iterator it = queries.begin(); it != queries.end(); ++it)
-   {
-     QString q = (*it).toLower();
-     if (q.startsWith("subject="))
-       subject = KUrl::fromPercentEncoding((*it).mid(8).toLatin1());
-     else
-     if (q.startsWith("cc="))
-		 cc = cc.isEmpty()? KUrl::fromPercentEncoding((*it).mid(3).toLatin1()): cc.toLatin1() + ',' + KUrl::fromPercentEncoding((*it).mid(3).toLatin1());
-     else
-     if (q.startsWith("bcc="))
-		 bcc = bcc.isEmpty()? KUrl::fromPercentEncoding((*it).mid(4).toLatin1()): bcc.toLatin1() + ',' + KUrl::fromPercentEncoding((*it).mid(4).toLatin1());
-     else
-     if (q.startsWith("body="))
-       body = KUrl::fromPercentEncoding((*it).mid(5).toLatin1());
-     else
-     if (allowAttachments && q.startsWith("attach="))
-       attachURLs.push_back(KUrl::fromPercentEncoding((*it).mid(7).toLatin1()));
-     else
-     if (allowAttachments && q.startsWith("attachment="))
-       attachURLs.push_back(KUrl::fromPercentEncoding((*it).mid(11).toLatin1()));
-     else
-     if (q.startsWith("to="))
-       address = address.isEmpty()? KUrl::fromPercentEncoding((*it).mid(3).toLatin1()): address + ',' + KUrl::fromPercentEncoding((*it).mid(3).toLatin1());
-   }
-
-   invokeMailer( address, cc, bcc, subject, body, QString::null, attachURLs, startup_id );
-*/
-}
-
 void KToolInvocation::invokeMailer(const QString &_to, const QString &_cc, const QString &_bcc,
                                 const QString &subject, const QString &body,
                                 const QString & /*messageFile TODO*/, const QStringList &attachURLs,
                                 const QByteArray& startup_id )
 {
-/*
-	KUrl url("mailto:"+_to);
-	url.setQuery("?subject="+subject);
-	url.addQueryItem("cc", _cc);
-	url.addQueryItem("bcc", _bcc);
-	url.addQueryItem("body", body);
-	for (QStringList::ConstIterator it = attachURLs.constBegin(); it != attachURLs.constEnd(); ++it)
-		url.addQueryItem("attach", QLatin1String( KUrl::toPercentEncoding(*it) ));
+  KUrl url("mailto:"+_to);
+  url.setQuery("?subject="+subject);
+  url.addQueryItem("cc", _cc);
+  url.addQueryItem("bcc", _bcc);
+  url.addQueryItem("body", body);
+  foreach (const QString& attachURL, attachURLs)
+    url.addQueryItem("attach", QLatin1String( KUrl::toPercentEncoding(attachURL) ));
 
    QString sOpen( "open" );
    ShellExecuteW(0, ( LPCWSTR )sOpen.utf16(), ( LPCWSTR )url.url().utf16(), 0, 0, SW_NORMAL);
-*/
 }
 
-void KToolInvocation::startKdeinit()
+void KToolInvocation::invokeTerminal(const QString &command, const QByteArray &startup_id)
 {
-   KComponentData inst( "startkdeinitlock" );
-   KLockFile lock( KStandardDirs::locateLocal( "tmp", "startkdeinitlock", inst ));
-   if( lock.lock( KLockFile::NoBlockFlag ) != KLockFile::LockOK ) {
-     lock.lock();
-     if( QDBusConnection::sessionBus().interface()->isServiceRegistered( "org.kde.klauncher" ))
-         return; // whoever held the lock has already started it
-   }
-   QProcess::execute("kdeinit4");
+    //TODO
 }
Index: kdecore/kernel/ktoolinvocation_x11.cpp
===================================================================
--- kdecore/kernel/ktoolinvocation_x11.cpp	(wersja 791099)
+++ kdecore/kernel/ktoolinvocation_x11.cpp	(kopia robocza)
@@ -1,9 +1,10 @@
 /* This file is part of the KDE libraries
     Copyright (c) 1997,1998 Matthias Kalle Dalheimer <kalle@kde.org>
-    Copyright (c) 2006 Thiago Macieira <thiago@kde.org>
-    Copyright (c) 2003,2004 Oswald Buddenhagen <ossi@kde.org>
-    Copyright (c) 2000-2004 Frerich Raabe <raabe@kde.org>
     Copyright (c) 1999 Espen Sand <espen@kde.org>
+    Copyright (c) 2000-2004 Frerich Raabe <raabe@kde.org>
+    Copyright (c) 2003,2004 Oswald Buddenhagen <ossi@kde.org>
+    Copyright (c) 2006 Thiago Macieira <thiago@kde.org>
+    Copyright (C) 2008 Aaron Seigo <aseigo@kde.org>
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -26,8 +27,6 @@
 #include "ktoolinvocation.h"
 
 #include <kconfiggroup.h>
-#include <kcomponentdata.h>
-#include <klockfile.h>
 
 #include "klauncher_iface.h"
 #include "kcmdlineargs.h"
@@ -49,88 +48,6 @@
 #include <QtCore/QFile>
 #include <QtDBus/QtDBus>
 
-void KToolInvocation::invokeHelp( const QString& anchor,
-                                  const QString& _appname,
-                                  const QByteArray& startup_id )
-{
-    if (!isMainThreadActive())
-        return;
-
-    QString url;
-    QString appname;
-    if (_appname.isEmpty()) {
-        appname = QCoreApplication::instance()->applicationName();
-    } else
-        appname = _appname;
-
-    if (!anchor.isEmpty())
-        url = QString("help:/%1?anchor=%2").arg(appname).arg(anchor);
-    else
-        url = QString("help:/%1/index.html").arg(appname);
-
-    QDBusInterface *iface = new QDBusInterface(QLatin1String("org.kde.khelpcenter"),
-                                               QLatin1String("/KHelpCenter"),
-                                               QLatin1String("org.kde.khelpcenter.khelpcenter"),
-                                               QDBusConnection::sessionBus());
-    if ( !iface->isValid() )
-    {
-        QString error;
-        if (startServiceByDesktopName("khelpcenter", url, &error, 0, 0, startup_id, false))
-        {
-            KMessage::message(KMessage::Error,
-                              i18n("Could not launch the KDE Help Center:\n\n%1", error),
-                              i18n("Could not Launch Help Center"));
-            return;
-        }
-
-        delete iface;
-        iface = new QDBusInterface(QLatin1String("org.kde.khelpcenter"),
-                                   QLatin1String("/KHelpCenter"),
-                                   QLatin1String("org.kde.khelpcenter.khelpcenter"),
-                                   QDBusConnection::sessionBus());
-    }
-
-    iface->call("openUrl", url, startup_id );
-    delete iface;
-}
-
-void KToolInvocation::invokeMailer(const KUrl &mailtoURL, const QByteArray& startup_id, bool allowAttachments )
-{
-    if (!isMainThreadActive())
-        return;
-
-    QString address = KUrl::fromPercentEncoding(mailtoURL.path().toLatin1()), subject, cc, bcc, body;
-    QStringList queries = mailtoURL.query().mid(1).split( '&');
-    QStringList attachURLs;
-    for (QStringList::Iterator it = queries.begin(); it != queries.end(); ++it)
-    {
-        QString q = (*it).toLower();
-        if (q.startsWith("subject="))
-            subject = KUrl::fromPercentEncoding((*it).mid(8).toLatin1());
-        else
-            if (q.startsWith("cc="))
-                cc = cc.isEmpty()? KUrl::fromPercentEncoding((*it).mid(3).toLatin1()): cc + ',' + KUrl::fromPercentEncoding((*it).mid(3).toLatin1());
-            else
-                if (q.startsWith("bcc="))
-                    bcc = bcc.isEmpty()? KUrl::fromPercentEncoding((*it).mid(4).toLatin1()): bcc + ',' + KUrl::fromPercentEncoding((*it).mid(4).toLatin1());
-                else
-                    if (q.startsWith("body="))
-                        body = KUrl::fromPercentEncoding((*it).mid(5).toLatin1());
-                    else
-                        if (allowAttachments && q.startsWith("attach="))
-                            attachURLs.push_back(KUrl::fromPercentEncoding((*it).mid(7).toLatin1()));
-                        else
-                            if (allowAttachments && q.startsWith("attachment="))
-                                attachURLs.push_back(KUrl::fromPercentEncoding((*it).mid(11).toLatin1()));
-                            else
-                                if (q.startsWith("to="))
-                                    address = address.isEmpty()? KUrl::fromPercentEncoding((*it).mid(3).toLatin1()): address + ',' + KUrl::fromPercentEncoding((*it).mid(3).toLatin1());
-    }
-
-    invokeMailer( address, cc, bcc, subject, body, QString(), attachURLs, startup_id );
-}
-
-
 static QStringList splitEmailAddressList( const QString & aStr )
 {
     // This is a copy of KPIM::splitEmailAddrList().
@@ -202,15 +119,6 @@
     return list;
 }
 
-void KToolInvocation::invokeMailer(const QString &address, const QString &subject, const QByteArray& startup_id)
-{
-    if (!isMainThreadActive())
-        return;
-
-    invokeMailer(address, QString(), QString(), subject, QString(), QString(),
-                 QStringList(), startup_id );
-}
-
 void KToolInvocation::invokeMailer(const QString &_to, const QString &_cc, const QString &_bcc,
                                    const QString &subject, const QString &body,
                                    const QString & /*messageFile TODO*/, const QStringList &attachURLs,
@@ -361,24 +269,33 @@
     }
 }
 
-void KToolInvocation::startKdeinit()
+void KToolInvocation::invokeTerminal(const QString &command, const QByteArray &startup_id)
 {
-  KComponentData inst( "startkdeinitlock" );
-  KLockFile lock( KStandardDirs::locateLocal( "tmp", "startkdeinitlock", inst ));
-  if( lock.lock( KLockFile::NoBlockFlag ) != KLockFile::LockOK ) {
-     lock.lock();
-     if( QDBusConnection::sessionBus().interface()->isServiceRegistered( "org.kde.klauncher" ))
-         return; // whoever held the lock has already started it
-  }
-  // Try to launch kdeinit.
-  QString srv = KStandardDirs::findExe(QLatin1String("kdeinit4"));
-  if (srv.isEmpty())
-     return;
-//   this is disabled because we are in kdecore
-//  const bool gui = qApp && qApp->type() != QApplication::Tty;
-//  if ( gui )
-//    qApp->setOverrideCursor( Qt::WaitCursor );
-  QProcess::execute(srv, QStringList() << "--suicide");
-//  if ( gui )
-//    qApp->restoreOverrideCursor();
+    if (!isMainThreadActive()) {
+        return;
+    }
+
+    KConfigGroup confGroup( KGlobal::config(), "General" );
+    QString exec = confGroup.readPathEntry("TerminalApplication", "konsole");
+
+    if (exec == "konsole") {
+        exec += " --noclose";
+    } else if (exec == "xterm") {
+        exec += " -hold";
+    }
+
+    if (!command.isEmpty()) {
+        exec += " -e " + command;
+    }
+
+    QStringList cmdTokens = KShell::splitArgs(exec);
+    QString cmd = cmdTokens.takeFirst();
+
+    QString error;
+    if (kdeinitExec(cmd, cmdTokens, &error, NULL, startup_id ))
+    {
+      KMessage::message(KMessage::Error,
+                      i18n("Could not launch the terminal client:\n\n%1", error),
+                      i18n("Could not Launch Terminal Client"));
+    }
 }
Index: kdecore/kernel/ktoolinvocation.h
===================================================================
--- kdecore/kernel/ktoolinvocation.h	(wersja 791099)
+++ kdecore/kernel/ktoolinvocation.h	(kopia robocza)
@@ -4,6 +4,7 @@
     Copyright (c) 1998-2005 Stephan Kulow <coolo@kde.org>
     Copyright (c) 1999-2004 Waldo Bastian <bastian@kde.org>
     Copyright (c) 2001-2005 Lubos Lunak <l.lunak@kde.org>
+    Copyright (C) 2008 Aaron Seigo <aseigo@kde.org>
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -145,6 +146,17 @@
    */
   static void invokeBrowser( const QString &url, const QByteArray& startup_id = "" );
 
+  /**
+   * Invokes the standard terminal application.
+   *
+   * @param command the command to execute
+   * @param startup_id for app startup notification, "0" for none,
+   *           "" ( empty string ) is the default
+   *
+   * @since 4.1
+   */
+  static void invokeTerminal(const QString &command, const QByteArray &startup_id = "");
+
 public:
   /**
    * Returns the DBus interface of the service launcher.
