kdelibs/kdeui/kernel/ktoolinvocation_x11.cpp

95 lines
3.5 KiB
C++
Raw Normal View History

2014-11-13 01:04:59 +02:00
/* This file is part of the KDE libraries
Copyright (c) 1997,1998 Matthias Kalle Dalheimer <kalle@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
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "ktoolinvocation.h"
#include "kconfig.h"
#include "kglobal.h"
#include "kshell.h"
#include "kservice.h"
#include "kconfiggroup.h"
#include "kmimetypetrader.h"
#include "kurl.h"
#include "kdebug.h"
2014-11-13 01:04:59 +02:00
void KToolInvocation::invokeMailer(const QString &address)
2014-11-13 01:04:59 +02:00
{
KConfig config(QString::fromLatin1("emaildefaults"));
KConfigGroup profileGrp(&config, "General");
2014-11-13 01:04:59 +02:00
QString command = profileGrp.readPathEntry("EmailClient", QString::fromLatin1("kmail"));
if( !command.contains( QLatin1Char('%') ))
2014-11-13 01:04:59 +02:00
{
command += QLatin1String(" %u");
2014-11-13 01:04:59 +02:00
}
if (profileGrp.readEntry("TerminalClient", false))
{
KConfigGroup confGroup( KGlobal::config(), "General" );
QString preferredTerminal = confGroup.readPathEntry("TerminalApplication", QString::fromLatin1("konsole"));
command = preferredTerminal + QString::fromLatin1(" -e ") + command;
}
QStringList cmdTokens = KShell::splitArgs(command);
QString cmd = cmdTokens.takeFirst();
startProgram(cmd, cmdTokens);
2014-11-13 01:04:59 +02:00
}
void KToolInvocation::invokeBrowser(const QString &url)
2014-11-13 01:04:59 +02:00
{
// This method should launch a webbrowser, preferably without doing a mimetype
// check first like kde-open would do.
const KService::Ptr htmlApp = KMimeTypeTrader::self()->preferredService(QLatin1String("text/html"));
if (htmlApp) {
startServiceByStorageId(htmlApp->entryPath(), QStringList() << url);
return;
2014-11-13 01:04:59 +02:00
}
// if one cannot be found then launch the service for the URL MIME type
startServiceForUrl(url);
2014-11-13 01:04:59 +02:00
}
void KToolInvocation::invokeTerminal(const QString &command,
const QString &workdir)
2014-11-13 01:04:59 +02:00
{
KConfigGroup confGroup( KGlobal::config(), "General" );
QString exec = confGroup.readPathEntry("TerminalApplication", QString::fromLatin1("konsole"));
QStringList cmdTokens = KShell::splitArgs(exec);
2014-11-13 01:04:59 +02:00
if (!command.isEmpty()) {
if (exec == QLatin1String("konsole")) {
cmdTokens << QString::fromLatin1("--noclose");
} else if (exec.startsWith(QLatin1String("xterm"))) {
cmdTokens << QString::fromLatin1("-hold");
2014-11-13 01:04:59 +02:00
}
cmdTokens << QString::fromLatin1("-e") << command;
2014-11-13 01:04:59 +02:00
}
QString cmd = cmdTokens.takeFirst();
2014-11-13 01:04:59 +02:00
startServiceInternal(
"start_program_with_workdir", cmd, cmdTokens, nullptr, false, workdir
);
2014-11-13 01:04:59 +02:00
}