From 5af24c40137c80c4de65f63ce816f77ef8b7bea3 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 2 Dec 2024 13:08:45 +0900 Subject: Use tdeprocess.h Signed-off-by: Michele Calgaro --- lib/util/CMakeLists.txt | 2 +- lib/util/Makefile.am | 4 +- lib/util/blockingkprocess.cpp | 105 ---------------------------------------- lib/util/blockingkprocess.h | 93 ----------------------------------- lib/util/blockingtdeprocess.cpp | 105 ++++++++++++++++++++++++++++++++++++++++ lib/util/blockingtdeprocess.h | 93 +++++++++++++++++++++++++++++++++++ lib/util/execcommand.cpp | 2 +- lib/util/kdevshellwidget.cpp | 2 +- 8 files changed, 203 insertions(+), 203 deletions(-) delete mode 100644 lib/util/blockingkprocess.cpp delete mode 100644 lib/util/blockingkprocess.h create mode 100644 lib/util/blockingtdeprocess.cpp create mode 100644 lib/util/blockingtdeprocess.h (limited to 'lib/util') diff --git a/lib/util/CMakeLists.txt b/lib/util/CMakeLists.txt index 1eb17f35..121f85c2 100644 --- a/lib/util/CMakeLists.txt +++ b/lib/util/CMakeLists.txt @@ -30,7 +30,7 @@ install( FILES tde_add_library( kdevutil STATIC_PIC AUTOMOC SOURCES - blockingkprocess.cpp configwidgetproxy.cpp + blockingtdeprocess.cpp configwidgetproxy.cpp domutil.cpp execcommand.cpp filetemplate.cpp kdeveditorutil.cpp kdevjobtimer.cpp kdevshellwidget.cpp tdescriptactionmanager.cpp diff --git a/lib/util/Makefile.am b/lib/util/Makefile.am index 8bf28091..1f457040 100644 --- a/lib/util/Makefile.am +++ b/lib/util/Makefile.am @@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/lib/compat -I$(top_srcdir)/lib/interfaces -I$(top_s noinst_LTLIBRARIES = libkdevutil.la -libkdevutil_la_SOURCES = blockingkprocess.cpp configwidgetproxy.cpp domutil.cpp \ +libkdevutil_la_SOURCES = blockingtdeprocess.cpp configwidgetproxy.cpp domutil.cpp \ execcommand.cpp filetemplate.cpp kdeveditorutil.cpp kdevjobtimer.cpp \ kdevshellwidget.cpp tdescriptactionmanager.cpp rurl.cpp settings.cpp urlutil.cpp @@ -17,5 +17,5 @@ DOXYGEN_PROJECTNAME = KDevelop Utility Library DOXYGEN_DOCDIRPREFIX = kdev include ../../Doxyfile.am -noinst_HEADERS = blockingkprocess.h kdeveditorutil.h kdevjobtimer.h \ +noinst_HEADERS = blockingtdeprocess.h kdeveditorutil.h kdevjobtimer.h \ kdevshellwidget.h settings.h diff --git a/lib/util/blockingkprocess.cpp b/lib/util/blockingkprocess.cpp deleted file mode 100644 index 0c2b0650..00000000 --- a/lib/util/blockingkprocess.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2006 by Andras Mantia * -* amantia@kde.org * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -* * -***************************************************************************/ - -#include "blockingkprocess.h" - -#include -#include - -BlockingTDEProcess::BlockingTDEProcess(TQObject *parent, const char *name) - : TDEProcess(parent, name) -{ - m_stdOut = ""; - m_stdErr = ""; - m_timeoutValue = 60; - m_timer = 0L; - - connect(this, TQ_SIGNAL(receivedStdout(TDEProcess *, char *, int)), - this, TQ_SLOT(slotReceivedStdOut(TDEProcess *, char *, int))); - connect(this, TQ_SIGNAL(receivedStderr(TDEProcess *, char *, int)), - this, TQ_SLOT(slotReceivedStdErr(TDEProcess *, char *, int))); - connect(this, TQ_SIGNAL(processExited(TDEProcess *)), - this, TQ_SLOT(slotProcessExited(TDEProcess *))); -} - -BlockingTDEProcess::BlockingTDEProcess() - : TDEProcess() -{ - m_stdOut = ""; - m_stdErr = ""; - m_timeoutValue = 60; - m_timer = 0L; - connect(this, TQ_SIGNAL(receivedStdout(TDEProcess *, char *, int)), - this, TQ_SLOT(slotReceivedStdOut(TDEProcess *, char *, int))); - connect(this, TQ_SIGNAL(receivedStderr(TDEProcess *, char *, int)), - this, TQ_SLOT(slotReceivedStdErr(TDEProcess *, char *, int))); - connect(this, TQ_SIGNAL(processExited(TDEProcess *)), - this, TQ_SLOT(slotProcessExited(TDEProcess *))); -} - - -BlockingTDEProcess::~BlockingTDEProcess() -{ -} -bool BlockingTDEProcess::start(RunMode runmode, Communication comm) -{ - if (TDEProcess::start(runmode, comm)) - { - m_timeout = false; - m_timer = new TQTimer(); - connect(m_timer, TQ_SIGNAL(timeout()), this, TQ_SLOT(slotTimeOut())); - m_timer->start(m_timeoutValue*1000, true); - enter_loop(); - delete m_timer; - m_timer = 0L; - return !m_timeout; - } else - return false; -} - - -void BlockingTDEProcess::slotReceivedStdOut(TDEProcess *, char *buffer, int buflen) -{ - m_stdOut += TQString::fromLatin1(buffer, buflen); -} - -void BlockingTDEProcess::slotReceivedStdErr(TDEProcess *, char *buffer, int buflen) -{ - m_stdErr += TQString::fromLatin1(buffer, buflen); -} - -void BlockingTDEProcess::slotProcessExited(TDEProcess *) -{ - tqApp->exit_loop(); -} - -void BlockingTDEProcess::slotTimeOut() -{ - m_timeout = true; - kill(); - tqApp->exit_loop(); -} - - -void tqt_enter_modal( TQWidget *widget ); -void tqt_leave_modal( TQWidget *widget ); - -void BlockingTDEProcess::enter_loop() -{ - TQWidget dummy(0,0,WType_Dialog | WShowModal); - dummy.setFocusPolicy( TQWidget::NoFocus ); - tqt_enter_modal(&dummy); - tqApp->enter_loop(); - tqt_leave_modal(&dummy); -} - - -#include "blockingkprocess.moc" diff --git a/lib/util/blockingkprocess.h b/lib/util/blockingkprocess.h deleted file mode 100644 index b5a7e71e..00000000 --- a/lib/util/blockingkprocess.h +++ /dev/null @@ -1,93 +0,0 @@ - -/*************************************************************************** -* Copyright (C) 2006 by Andras Mantia * -* amantia@kde.org * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -* * -***************************************************************************/ - - -#ifndef BLOCKINGKPROCESS_H -#define BLOCKINGKPROCESS_H - -#include - -/** - * Blocking version of TDEProcess, which stores the stdout. - * Differences between start(TDEProcess::Block, TDEProcess::StdOut) and this - * class are: - * - the GUI update is not blocked why the external process is running - * - in case of problems there is a timeout (defaults to 60 seconds), after which the - * process is terminated. - * - the stdout is caught - it the caller request it - and can be read by the caller - * @author Andras Mantia -*/ - -class TQTimer; -class BlockingTDEProcess : public TDEProcess -{ - TQ_OBJECT - - -public: - BlockingTDEProcess(TQObject *parent, const char *name=0); - BlockingTDEProcess(); - - virtual ~BlockingTDEProcess(); - - /** - * Start the process. It waits until the process exits or the timeout is hit. - * @param runmode @see TDEProcess, use TDEProcess::NotifyOnExit to get proper behaviour, - * not TDEProcess::Block - * @param comm if Stdout is passed, it catches the output. For the rest @see TDEProcess - * @return true in case of success, false if there are problems to start the process - * or it was killed because of the timeout. - */ - virtual bool start(RunMode runmode=NotifyOnExit, Communication comm=NoCommunication); - - /** - * Get the output of the run process - * @return the output - */ - TQString stdOut() { return m_stdOut;} - /** - * Clear the internal stdout buffer. Useful in case the class is reused. - */ - void clearStdOut() { m_stdOut = "";} - /** - * Get the error output of the run process - * @return the output - */ - TQString stdErr() { return m_stdErr;} - /** - * Clear the internal stderr buffer. Useful in case the class is reused. - */ - void clearStdErr() { m_stdErr = "";} - - /** - * Sets the timeout - * @param timeout seconds after which the process is considered hung and killed. 0 disables the timeout. - */ - void setTimeOut(int timeout) { m_timeoutValue = timeout; } - -private slots: - void slotReceivedStdOut(TDEProcess *proc, char *buffer, int buflen); - void slotReceivedStdErr(TDEProcess *proc, char *buffer, int buflen); - void slotProcessExited(TDEProcess *proc); - void slotTimeOut(); - -private: - void enter_loop(); - - TQString m_stdOut; - TQString m_stdErr; - bool m_timeout; - int m_timeoutValue; - TQTimer *m_timer; -}; - -#endif diff --git a/lib/util/blockingtdeprocess.cpp b/lib/util/blockingtdeprocess.cpp new file mode 100644 index 00000000..f57ae77d --- /dev/null +++ b/lib/util/blockingtdeprocess.cpp @@ -0,0 +1,105 @@ +/*************************************************************************** +* Copyright (C) 2006 by Andras Mantia * +* amantia@kde.org * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +***************************************************************************/ + +#include "blockingtdeprocess.h" + +#include +#include + +BlockingTDEProcess::BlockingTDEProcess(TQObject *parent, const char *name) + : TDEProcess(parent, name) +{ + m_stdOut = ""; + m_stdErr = ""; + m_timeoutValue = 60; + m_timer = 0L; + + connect(this, TQ_SIGNAL(receivedStdout(TDEProcess *, char *, int)), + this, TQ_SLOT(slotReceivedStdOut(TDEProcess *, char *, int))); + connect(this, TQ_SIGNAL(receivedStderr(TDEProcess *, char *, int)), + this, TQ_SLOT(slotReceivedStdErr(TDEProcess *, char *, int))); + connect(this, TQ_SIGNAL(processExited(TDEProcess *)), + this, TQ_SLOT(slotProcessExited(TDEProcess *))); +} + +BlockingTDEProcess::BlockingTDEProcess() + : TDEProcess() +{ + m_stdOut = ""; + m_stdErr = ""; + m_timeoutValue = 60; + m_timer = 0L; + connect(this, TQ_SIGNAL(receivedStdout(TDEProcess *, char *, int)), + this, TQ_SLOT(slotReceivedStdOut(TDEProcess *, char *, int))); + connect(this, TQ_SIGNAL(receivedStderr(TDEProcess *, char *, int)), + this, TQ_SLOT(slotReceivedStdErr(TDEProcess *, char *, int))); + connect(this, TQ_SIGNAL(processExited(TDEProcess *)), + this, TQ_SLOT(slotProcessExited(TDEProcess *))); +} + + +BlockingTDEProcess::~BlockingTDEProcess() +{ +} +bool BlockingTDEProcess::start(RunMode runmode, Communication comm) +{ + if (TDEProcess::start(runmode, comm)) + { + m_timeout = false; + m_timer = new TQTimer(); + connect(m_timer, TQ_SIGNAL(timeout()), this, TQ_SLOT(slotTimeOut())); + m_timer->start(m_timeoutValue*1000, true); + enter_loop(); + delete m_timer; + m_timer = 0L; + return !m_timeout; + } else + return false; +} + + +void BlockingTDEProcess::slotReceivedStdOut(TDEProcess *, char *buffer, int buflen) +{ + m_stdOut += TQString::fromLatin1(buffer, buflen); +} + +void BlockingTDEProcess::slotReceivedStdErr(TDEProcess *, char *buffer, int buflen) +{ + m_stdErr += TQString::fromLatin1(buffer, buflen); +} + +void BlockingTDEProcess::slotProcessExited(TDEProcess *) +{ + tqApp->exit_loop(); +} + +void BlockingTDEProcess::slotTimeOut() +{ + m_timeout = true; + kill(); + tqApp->exit_loop(); +} + + +void tqt_enter_modal( TQWidget *widget ); +void tqt_leave_modal( TQWidget *widget ); + +void BlockingTDEProcess::enter_loop() +{ + TQWidget dummy(0,0,WType_Dialog | WShowModal); + dummy.setFocusPolicy( TQWidget::NoFocus ); + tqt_enter_modal(&dummy); + tqApp->enter_loop(); + tqt_leave_modal(&dummy); +} + + +#include "blockingtdeprocess.moc" diff --git a/lib/util/blockingtdeprocess.h b/lib/util/blockingtdeprocess.h new file mode 100644 index 00000000..2252f59f --- /dev/null +++ b/lib/util/blockingtdeprocess.h @@ -0,0 +1,93 @@ + +/*************************************************************************** +* Copyright (C) 2006 by Andras Mantia * +* amantia@kde.org * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +***************************************************************************/ + + +#ifndef BLOCKINGTDEPROCESS_H +#define BLOCKINGTDEPROCESS_H + +#include + +/** + * Blocking version of TDEProcess, which stores the stdout. + * Differences between start(TDEProcess::Block, TDEProcess::StdOut) and this + * class are: + * - the GUI update is not blocked why the external process is running + * - in case of problems there is a timeout (defaults to 60 seconds), after which the + * process is terminated. + * - the stdout is caught - it the caller request it - and can be read by the caller + * @author Andras Mantia +*/ + +class TQTimer; +class BlockingTDEProcess : public TDEProcess +{ + TQ_OBJECT + + +public: + BlockingTDEProcess(TQObject *parent, const char *name=0); + BlockingTDEProcess(); + + virtual ~BlockingTDEProcess(); + + /** + * Start the process. It waits until the process exits or the timeout is hit. + * @param runmode @see TDEProcess, use TDEProcess::NotifyOnExit to get proper behaviour, + * not TDEProcess::Block + * @param comm if Stdout is passed, it catches the output. For the rest @see TDEProcess + * @return true in case of success, false if there are problems to start the process + * or it was killed because of the timeout. + */ + virtual bool start(RunMode runmode=NotifyOnExit, Communication comm=NoCommunication); + + /** + * Get the output of the run process + * @return the output + */ + TQString stdOut() { return m_stdOut;} + /** + * Clear the internal stdout buffer. Useful in case the class is reused. + */ + void clearStdOut() { m_stdOut = "";} + /** + * Get the error output of the run process + * @return the output + */ + TQString stdErr() { return m_stdErr;} + /** + * Clear the internal stderr buffer. Useful in case the class is reused. + */ + void clearStdErr() { m_stdErr = "";} + + /** + * Sets the timeout + * @param timeout seconds after which the process is considered hung and killed. 0 disables the timeout. + */ + void setTimeOut(int timeout) { m_timeoutValue = timeout; } + +private slots: + void slotReceivedStdOut(TDEProcess *proc, char *buffer, int buflen); + void slotReceivedStdErr(TDEProcess *proc, char *buffer, int buflen); + void slotProcessExited(TDEProcess *proc); + void slotTimeOut(); + +private: + void enter_loop(); + + TQString m_stdOut; + TQString m_stdErr; + bool m_timeout; + int m_timeoutValue; + TQTimer *m_timer; +}; + +#endif diff --git a/lib/util/execcommand.cpp b/lib/util/execcommand.cpp index 6fb0f40c..0f6c7387 100644 --- a/lib/util/execcommand.cpp +++ b/lib/util/execcommand.cpp @@ -19,7 +19,7 @@ #include "execcommand.h" -#include +#include #include #include #include diff --git a/lib/util/kdevshellwidget.cpp b/lib/util/kdevshellwidget.cpp index 1db1b7e1..8cf5e265 100644 --- a/lib/util/kdevshellwidget.cpp +++ b/lib/util/kdevshellwidget.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include "kdevshellwidget.h" -- cgit v1.2.3