mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
kinit: check the process exit code on state change
for flexibility Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
71704a410d
commit
c72478ab01
2 changed files with 39 additions and 34 deletions
|
@ -77,6 +77,7 @@ KLauncherProcess::KLauncherProcess(QObject *parent)
|
||||||
: QProcess(parent),
|
: QProcess(parent),
|
||||||
m_kstartupinfo(nullptr),
|
m_kstartupinfo(nullptr),
|
||||||
m_startuptimer(nullptr),
|
m_startuptimer(nullptr),
|
||||||
|
m_window(0),
|
||||||
m_temp(false)
|
m_temp(false)
|
||||||
{
|
{
|
||||||
connect(
|
connect(
|
||||||
|
@ -90,16 +91,21 @@ KLauncherProcess::~KLauncherProcess()
|
||||||
removeTemp(m_temp, m_args);
|
removeTemp(m_temp, m_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KLauncherProcess::setupStartup(const QString &appexe, const KService::Ptr kservice,
|
void KLauncherProcess::setupProcess(const QString &appexe, const QStringList &args,
|
||||||
const qint64 timeout, const bool temp, const QStringList &args)
|
const quint64 window, const KService::Ptr kservice,
|
||||||
|
const qint64 timeout, const bool temp)
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_kstartupinfoid.none() == true);
|
Q_ASSERT(m_kstartupinfoid.none() == true);
|
||||||
|
m_appexe = appexe;
|
||||||
|
m_args = args;
|
||||||
|
m_window = window;
|
||||||
|
m_temp = temp;
|
||||||
QByteArray startupwmclass;
|
QByteArray startupwmclass;
|
||||||
if (KRun::checkStartupNotify(kservice.data(), &startupwmclass)) {
|
if (KRun::checkStartupNotify(kservice.data(), &startupwmclass)) {
|
||||||
m_kstartupinfoid.initId(KStartupInfo::createNewStartupId());
|
m_kstartupinfoid.initId(KStartupInfo::createNewStartupId());
|
||||||
kDebug() << "setting up ASN for" << kservice->entryPath() << m_kstartupinfoid.id();
|
kDebug() << "setting up ASN for" << kservice->entryPath() << m_kstartupinfoid.id();
|
||||||
m_kstartupinfodata.setHostname();
|
m_kstartupinfodata.setHostname();
|
||||||
m_kstartupinfodata.setBin(QFileInfo(appexe).fileName());
|
m_kstartupinfodata.setBin(QFileInfo(m_appexe).fileName());
|
||||||
m_kstartupinfodata.setDescription(i18n("Launching %1", kservice->name()));
|
m_kstartupinfodata.setDescription(i18n("Launching %1", kservice->name()));
|
||||||
m_kstartupinfodata.setIcon(kservice->icon());
|
m_kstartupinfodata.setIcon(kservice->icon());
|
||||||
m_kstartupinfodata.setApplicationId(kservice->entryPath());
|
m_kstartupinfodata.setApplicationId(kservice->entryPath());
|
||||||
|
@ -109,20 +115,34 @@ void KLauncherProcess::setupStartup(const QString &appexe, const KService::Ptr k
|
||||||
QProcess::setProcessEnvironment(processenv);
|
QProcess::setProcessEnvironment(processenv);
|
||||||
sendSIStart(timeout);
|
sendSIStart(timeout);
|
||||||
} else {
|
} else {
|
||||||
kDebug() << "no ASN for" << appexe;
|
kDebug() << "no ASN for" << m_appexe;
|
||||||
}
|
}
|
||||||
m_temp = temp;
|
|
||||||
m_args = args;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KLauncherProcess::slotProcessStateChanged(QProcess::ProcessState state)
|
void KLauncherProcess::slotProcessStateChanged(QProcess::ProcessState state)
|
||||||
{
|
{
|
||||||
kDebug() << "process state changed" << this << state;
|
kDebug() << "process state changed" << m_appexe << state;
|
||||||
if (state == QProcess::Starting && !m_kstartupinfoid.none()) {
|
if (state == QProcess::Starting && !m_kstartupinfoid.none()) {
|
||||||
m_kstartupinfodata.addPid(QProcess::pid());
|
m_kstartupinfodata.addPid(QProcess::pid());
|
||||||
sendSIChange();
|
sendSIChange();
|
||||||
} else if (state == QProcess::NotRunning && !m_kstartupinfoid.none()) {
|
} else if (state == QProcess::NotRunning) {
|
||||||
sendSIFinish();
|
if (!m_kstartupinfoid.none()) {
|
||||||
|
sendSIFinish();
|
||||||
|
}
|
||||||
|
if (exitCode() != 0) {
|
||||||
|
kError() << "finished with error" << m_appexe;
|
||||||
|
const QByteArray processerror = readAllStandardError();
|
||||||
|
if (processerror.isEmpty()) {
|
||||||
|
showError(i18n("Application exited abnormally: %1", m_appexe), m_window);
|
||||||
|
} else {
|
||||||
|
KMessageBox::detailedErrorWId(
|
||||||
|
static_cast<WId>(m_window),
|
||||||
|
i18n("Application exited abnormally: %1", m_appexe),
|
||||||
|
QString::fromLocal8Bit(processerror.constData(), processerror.size())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deleteLater();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,14 +155,14 @@ void KLauncherProcess::slotStartupRemoved(const KStartupInfoId &kstartupinfoid,
|
||||||
|
|
||||||
kDebug() << "startup removed" << kstartupinfoid.id() << m_kstartupinfoid.id();
|
kDebug() << "startup removed" << kstartupinfoid.id() << m_kstartupinfoid.id();
|
||||||
if (kstartupinfoid.id() == m_kstartupinfoid.id() || kstartupinfodata.is_pid(QProcess::pid())) {
|
if (kstartupinfoid.id() == m_kstartupinfoid.id() || kstartupinfodata.is_pid(QProcess::pid())) {
|
||||||
kDebug() << "startup done for process" << this;
|
kDebug() << "startup done for process" << m_appexe;
|
||||||
sendSIFinish();
|
sendSIFinish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KLauncherProcess::slotStartupTimeout()
|
void KLauncherProcess::slotStartupTimeout()
|
||||||
{
|
{
|
||||||
kWarning() << "timed out while waiting for process" << this;
|
kWarning() << "timed out while waiting for process" << m_appexe;
|
||||||
sendSIFinish();
|
sendSIFinish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +193,7 @@ void KLauncherProcess::sendSIChange()
|
||||||
if (m_kstartupinfoid.none()) {
|
if (m_kstartupinfoid.none()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
kDebug() << "sending ASN change for" << m_kstartupinfodata.bin();
|
kDebug() << "sending ASN change for" << m_appexe;
|
||||||
KStartupInfo::sendChange(m_kstartupinfoid, m_kstartupinfodata);
|
KStartupInfo::sendChange(m_kstartupinfoid, m_kstartupinfodata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +202,7 @@ void KLauncherProcess::sendSIFinish()
|
||||||
if (m_kstartupinfoid.none()) {
|
if (m_kstartupinfoid.none()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
kDebug() << "sending ASN finish for" << m_kstartupinfodata.bin();
|
kDebug() << "sending ASN finish for" << m_appexe;
|
||||||
KStartupInfo::sendFinish(m_kstartupinfoid, m_kstartupinfodata);
|
KStartupInfo::sendFinish(m_kstartupinfoid, m_kstartupinfodata);
|
||||||
m_kstartupinfoid = KStartupInfoId();
|
m_kstartupinfoid = KStartupInfoId();
|
||||||
m_kstartupinfodata = KStartupInfoData();
|
m_kstartupinfodata = KStartupInfoData();
|
||||||
|
@ -435,7 +455,6 @@ void KLauncherAdaptor::slotProcessFinished(int exitcode)
|
||||||
KLauncherProcess* process = qobject_cast<KLauncherProcess*>(sender());
|
KLauncherProcess* process = qobject_cast<KLauncherProcess*>(sender());
|
||||||
kDebug() << "process finished" << process << exitcode;
|
kDebug() << "process finished" << process << exitcode;
|
||||||
m_processes.removeOne(process);
|
m_processes.removeOne(process);
|
||||||
process->deleteLater();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString KLauncherAdaptor::findExe(const QString &app) const
|
QString KLauncherAdaptor::findExe(const QString &app) const
|
||||||
|
@ -502,7 +521,7 @@ bool KLauncherAdaptor::startProgram(const QString &app, const QStringList &args,
|
||||||
}
|
}
|
||||||
process->setProcessEnvironment(processenv);
|
process->setProcessEnvironment(processenv);
|
||||||
process->setWorkingDirectory(workdir);
|
process->setWorkingDirectory(workdir);
|
||||||
process->setupStartup(appexe, kservice, timeout, temp, args);
|
process->setupProcess(appexe, args, window, kservice, timeout, temp);
|
||||||
kDebug() << "starting" << appexe << args << envs << workdir;
|
kDebug() << "starting" << appexe << args << envs << workdir;
|
||||||
process->start(appexe, args);
|
process->start(appexe, args);
|
||||||
while (process->state() == QProcess::Starting) {
|
while (process->state() == QProcess::Starting) {
|
||||||
|
@ -516,22 +535,6 @@ bool KLauncherAdaptor::startProgram(const QString &app, const QStringList &args,
|
||||||
showError(i18n("Could not start the application: %1", app), window);
|
showError(i18n("Could not start the application: %1", app), window);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (process->state() == QProcess::NotRunning && process->exitCode() != 0) {
|
|
||||||
kError() << "started but finished with error" << appexe;
|
|
||||||
const QByteArray processerror = process->readAllStandardError();
|
|
||||||
m_processes.removeOne(process);
|
|
||||||
process->deleteLater();
|
|
||||||
if (processerror.isEmpty()) {
|
|
||||||
showError(i18n("Application exited abnormally: %1", app), window);
|
|
||||||
} else {
|
|
||||||
KMessageBox::detailedErrorWId(
|
|
||||||
static_cast<WId>(window),
|
|
||||||
i18n("Application exited abnormally: %1", app),
|
|
||||||
QString::fromLocal8Bit(processerror.constData(), processerror.size())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
kDebug() << "started" << appexe;
|
kDebug() << "started" << appexe;
|
||||||
connect(process, SIGNAL(finished(int)), this, SLOT(slotProcessFinished(int)));
|
connect(process, SIGNAL(finished(int)), this, SLOT(slotProcessFinished(int)));
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -35,8 +35,8 @@ public:
|
||||||
explicit KLauncherProcess(QObject *parent);
|
explicit KLauncherProcess(QObject *parent);
|
||||||
~KLauncherProcess();
|
~KLauncherProcess();
|
||||||
|
|
||||||
void setupStartup(const QString &appexe, const KService::Ptr kservice, const qint64 timeout,
|
void setupProcess(const QString &appexe, const QStringList &args, const quint64 window,
|
||||||
const bool temp, const QStringList &args);
|
const KService::Ptr kservice, const qint64 timeout, const bool temp);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void slotProcessStateChanged(QProcess::ProcessState state);
|
void slotProcessStateChanged(QProcess::ProcessState state);
|
||||||
|
@ -54,8 +54,10 @@ private:
|
||||||
QTimer* m_startuptimer;
|
QTimer* m_startuptimer;
|
||||||
KStartupInfoId m_kstartupinfoid;
|
KStartupInfoId m_kstartupinfoid;
|
||||||
KStartupInfoData m_kstartupinfodata;
|
KStartupInfoData m_kstartupinfodata;
|
||||||
bool m_temp;
|
QString m_appexe;
|
||||||
QStringList m_args;
|
QStringList m_args;
|
||||||
|
quint64 m_window;
|
||||||
|
bool m_temp;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Adaptor class for interface org.kde.KLauncher
|
// Adaptor class for interface org.kde.KLauncher
|
||||||
|
|
Loading…
Add table
Reference in a new issue