All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Slots | Signals | Public Member Functions
Qtilities::Core::QtilitiesProcess Class Reference

An easy to use way to launch external processes through an extended wrapper around QProcess. More...

#include <QtilitiesProcess.h>

Inheritance diagram for Qtilities::Core::QtilitiesProcess:
Inheritance graph
[legend]

List of all members.

Public Slots

virtual void stopProcess ()
 Stops the process.
- Public Slots inherited from Qtilities::Core::Task
void addCompletedSubTasks (int number_of_sub_tasks=1, const QString &message=QString(), Logger::MessageType type=Logger::Info)
 Function which should be used to add completed tasks from the process's side.
bool completeTask (ITask::TaskResult result=ITask::TaskResultFromBusyStateFailOnError, const QString &message=QString(), Logger::MessageType type=Logger::Info)
 Function which should be used to complete the task from the process's side.
virtual void pause ()
 Pauses the task from the user interface.
bool pauseTask (const QString &message=QString(), Logger::MessageType type=Logger::Info)
 Function which should be used to stop tasks from the process's side.
virtual void resume ()
 Resumes the task after it has been paused.
bool resumeTask (const QString &message=QString(), Logger::MessageType type=Logger::Info)
 Function which should be used to stop tasks from the process's side.
virtual void start ()
 Starts the task from the user interface.
bool startTask (int expected_subtasks=-1, const QString &message=QString(), Logger::MessageType type=Logger::Info)
 Function which should be used to start tasks from the process's side.
virtual void stop ()
 Stops the task from the user interface.
bool stopTask (const QString &message=QString(), Logger::MessageType type=Logger::Info)
 Function which should be used to stop tasks from the process's side.

Signals

void newStandardErrorMessage (const QString &message)
 Emitted when new standard error becomes available.
void newStandardOutputMessage (const QString &message)
 Emitted when new standard output becomes available.
- Signals inherited from Qtilities::Core::Task
void busyStateChanged (ITask::TaskBusyState new_busy_state, ITask::TaskBusyState old_busy_state) const
 Signal emitted when the busy state of the task changes.
void canPauseChanged (bool new_value) const
 Signal emitted when a task's ability to be paused changed.
void canStartChanged (bool new_value) const
 Signal emitted when a task's ability to be started changed.
void canStopChanged (bool new_value) const
 Signal emitted when a task's ability to be stopped changed.
void displayedNameChanged (const QString &displayed_name) const
 Signal emitted when the task's displayed name changes.
void newMessageLogged (const QString &message, Logger::MessageType) const
 Signal emitted when the new messages are logged in this task.
void stateChanged (ITask::TaskState new_state, ITask::TaskState old_state) const
 Signal emitted when the task's state changes.
void subTaskCompleted (int number_task_completed=1, const QString &message=QString(), Logger::MessageType type=Logger::Info) const
 Signal emitted when subtasks are completed in order to show the correct progress information.
void taskAboutToComplete () const
 Signal emitted when the task is about to be completed.
void taskAboutToPause () const
 Signal emitted when the task is about to be paused.
void taskAboutToResume () const
 Signal emitted when the task is about to be resumed from a paused state.
void taskAboutToStart () const
 Signal emitted when the task is about to be started.
void taskAboutToStop () const
 Signal emitted when the task is about to be stopped.
void taskCompleted (ITask::TaskResult result, const QString &message=QString(), Logger::MessageType type=Logger::Info) const
 Signal emitted when the task started.
void taskElapsedTimeChanged (int msec) const
 Signal emitted when the task's elapsed time changes.
void taskPaused () const
 Signal emitted when the task is paused.
void taskResumed () const
 Signal emitted when the task is resumed after it was paused.
void taskStarted (int expected_subtasks=-1, const QString &message=QString(), Logger::MessageType type=Logger::Info) const
 Signal emitted when the task started.
void taskStopped () const
 Signal emitted when the task is stopped during execution.
void taskSubTaskAboutToComplete () const
 Signal emitted when a sub task is about to be completed.
void taskTypeChanged (ITask::TaskType new_task_type) const
 Signal emitted when the task's type changes.

Public Member Functions

QStringList lineBreakStrings ()
 Gets the strings to be used for splitting logged messages.
QProcess * process ()
 Access to the QProcess instance contained and used within this object.
 QtilitiesProcess (const QString &task_name, bool enable_logging=true, bool read_process_buffers=true, QObject *parent=0)
 Constructs a new QtilitiesProcess instance.
void setLineBreakStrings (const QStringList &line_break_strings)
 Sets the strings to be used for splitting logged messages.
virtual bool startProcess (const QString &program, const QStringList &arguments, QProcess::OpenMode mode=QProcess::ReadWrite, int wait_for_started_msecs=30000)
 Starts the process, similar to QProcess::start().
- Public Member Functions inherited from Qtilities::Core::Task
TaskBusyState busyState () const
 The busy state of the task.
bool canPause () const
bool canStart () const
bool canStop () const
void clearLog ()
 Clears the task's log.
bool clearLogOnStart () const
 When true, the task's log will be cleared everytime the task is started.
int currentProgress () const
 Returns the number of subtasks completed.
AbstractLoggerEnginecustomLoggerEngine () const
 Returns the custom logger engine used by this task.
QString displayName () const
 Returns the display name for the task. The display name will typically be set just before emitting taskStarted() and contain a little bit more information than taskName().
int elapsedTime () const
 Returns the elapsed time in miliseconds of the last time the task was run.
QStringList lastErrorMessages (int count) const
 Returns the last error logged in the task while it was busy.
int lastErrorMessagesStackSize () const
 Gets the last error logged stack size.
void logError (const QString &message)
 Convenience function to log an error in the task log.
AbstractLoggerEngineloggerEngine () const
 Returns a reference to the logger engine logging activities of this task. When loggingEnabled() is false, this function will always return 0.
bool loggingEnabled () const
 Indicates if the activities of this task is logged.
void logMessage (const QString &message, Logger::MessageType type=Logger::Info)
 Logs a message to this task.
void logWarning (const QString &message)
 Convenience function to log a warning in the task log.
int numberOfSubTasks () const
 Returns the number of subtasks associated with the task.
QObject * objectBase ()
 Returns the QObject* base of the interface.
const QObject * objectBase () const
 Returns a const QObject* base of the interface.
ITaskparentTask () const
 The parent task of this task.
void removeCustomLoggerEngine ()
 Removes the current custom logger engine from this task.
void removeParentTask ()
 Removes the parent task of this task.
TaskResult result () const
 The result of the task.
void setClearLogOnStart (bool clear_log_on_start=true) const
 Sets if the log must be cleared when the task is started.
void setCustomLoggerEngine (AbstractLoggerEngine *engine, bool use_only_this_engine=false)
 Sets a custom logger engine to be used by this task.
void setDisplayName (const QString &display_name)
 Sets the display name of the task.
void setLastErrorMessagesStackSize (int size)
 Sets the last error logged stack size.
void setLastRunTime (int msec)
 This function allows you to overwrite the last run time of the task.
void setLogContext (Logger::MessageContextFlags message_context)
 Sets the default message logging context flags of this task.
void setLoggerEngine (AbstractLoggerEngine *engine)
 Sets the logger engine to be used by this task.
void setParentTask (ITask *parent_task)
void setSubTaskPerformanceIndication (SubTaskPerformanceIndication performance_indication)
 Sets what performance measures are used for sub tasks.
void setTaskLifeTimeFlags (TaskLifeTimeFlags task_lifetime_flags)
 Sets the task lifetime.
void setTaskName (const QString &task_name)
 Sets the name of the task.
void setTaskRemoveAction (TaskRemoveAction task_remove_action)
 Sets the task's remove action.
void setTaskStopAction (TaskStopAction task_stop_action)
 Sets the task's stop action.
void setTaskStopConfirmation (TaskStopConfirmation task_stop_confirmation)
 Sets the task's stop configuration action.
void setTaskType (TaskType task_type)
 Sets the task type.
TaskState state () const
 The state of the task.
SubTaskPerformanceIndication subTaskPerformanceIndication () const
 Gets what performance measures are used for sub tasks.
 Task (const QString &task_name, bool enable_logging=true, QObject *parent=0)
 Default constructor.
TaskLifeTimeFlags taskLifeTimeFlags () const
 Gets the task lifetime.
QString taskName () const
 The name of the task.
TaskRemoveAction taskRemoveAction () const
 Indicates what should happen to the task when the user click's on the "Remove Task" button in a Qtilities::CoreGui::SingleTaskWidget.
TaskStopAction taskStopAction () const
 Indicates what should happen to the task when the user click's on the "Stop Task" button in a Qtilities::CoreGui::SingleTaskWidget.
TaskStopConfirmation taskStopConfirmation () const
 Indicates what should happen to the task when the user click's on the "Stop Task" button in a Qtilities::CoreGui::SingleTaskWidget.
TaskType taskType () const
 The type of this task.
- Public Member Functions inherited from Qtilities::Core::Interfaces::ITask
bool elapsedTimeChangedNotificationsEnabled () const
 Indicates if elapsed time changed notifications through taskElapsedTimeChanged() are enabled.
virtual QString elapsedTimeString (int msec=-1, const QString &format="hh:mm:ss.zzz") const
 Returns the elapsed time of the task as a string.
int getWidgetLoggerEngineDisplaysFlag () const
 Gets the (int) WidgetLoggerEngine::MessageDisplaysFlag used when assigning logger engines to tasks.
void setWidgetLoggerEngineDisplaysFlag (int message_display_flags)
 Sets the (int) WidgetLoggerEngine::MessageDisplaysFlag used when assigning logger engines to tasks.
int taskID () const
 The ID of this task.
void toggleElapsedTimeChangedNotifications (bool is_enabled)
 Enables elapsed time changed notifications through taskElapsedTimeChanged().
- Public Member Functions inherited from Qtilities::Core::Interfaces::IObjectBase
QString objectOriginID () const
 Allows interfaces to provide some sort of source identification.
void setObjectOriginID (const QString &object_origin_id)
 Allows setting of the object source ID of this interface implementation.

Additional Inherited Members

- Public Types inherited from Qtilities::Core::Task
enum  TaskLifeTime {
  LifeTimeManual = 1, LifeTimeDestroyWhenSuccessful = 2, LifeTimeDestroyWhenSuccessfullWithWarnings = 4, LifeTimeDestroyWhenStopped = 8,
  LifeTimeDestroyWhenFailed = 16
}
 The possible ways that the lifetime of this task can be managed. More...
- Public Types inherited from Qtilities::Core::Interfaces::ITask
enum  SubTaskPerformanceIndication { SubTaskNoPerformanceIndication = 0, SubTaskTimeFromTaskStart = 1 }
 Indicates how sub tasks are timed. More...
enum  TaskBusyState { TaskBusyClean = 0, TaskBusyWithWarnings = 1, TaskBusyWithErrors = 2 }
 The possible busy states of the task. More...
enum  TaskRemoveAction { TaskDeleteWhenRemoved = 0, TaskHideWhenRemoved = 1 }
 Indicates what should happen to the task when the user click's on the "Remove Task" button in a Qtilities::CoreGui::SingleTaskWidget. The "Stop Task" becomes the "Remove Task" button when the task was stopped or completed. More...
enum  TaskResult {
  TaskNoResult = 0, TaskSuccessful = 1, TaskSuccessfulWithWarnings = 2, TaskSuccessfulWithErrors = 3,
  TaskResultFromBusyStateFailOnError = 4, TaskResultFromBusyStateSuccessOnError = 5, TaskFailed = 6
}
 The possible results of a completed task. More...
enum  TaskState {
  TaskNotStarted = 1, TaskBusy = 2, TaskPaused = 4, TaskStopped = 8,
  TaskCompleted = 16, TaskIdle = TaskNotStarted | TaskCompleted | TaskStopped
}
 The possible states in which a task might find itself. More...
enum  TaskStopAction { TaskDeleteWhenStopped = 0, TaskHideWhenStopped = 1, TaskDoNothingWhenStopped = 2 }
 Indicates what should happen to the task when the user stops it in a Qtilities::CoreGui::SingleTaskWidget. More...
enum  TaskStopConfirmation { TaskStopConfirmationNone = 0, TaskStopConfirmationMsgBox = 1 }
 Indicates if an confirmation message is required when an user stops the task in a Qtilities::CoreGui::SingleTaskWidget. More...
enum  TaskType { TaskLocal = 0, TaskGlobal = 1 }
 The possible types of tasks. More...

Detailed Description

An easy to use way to launch external processes through an extended wrapper around QProcess.

The QtilitiesProcess class simplifies usage of QProcess and provides ready to use logging and task integration capablities.

When logging is enabled, QtilitiesProcess will automatically log all stdout and stderr outputs in a logger engine. It takes care of splitting up messages received from the QProcess buffer for you, thus individual messages are logged to the logger engine.


Constructor & Destructor Documentation

Qtilities::Core::QtilitiesProcess::QtilitiesProcess ( const QString &  task_name,
bool  enable_logging = true,
bool  read_process_buffers = true,
QObject *  parent = 0 
)

Constructs a new QtilitiesProcess instance.

QtilitiesProcess

Parameters:
task_nameThe name of the task.
enable_loggingIndicates if messages received from the task must be buffered and logged to a task log assigned to this task.
read_process_buffersIndicates if messages in the process's buffers must be processed. When false, the process buffer won't be touched and you can manually access it through the process() function.
parentThe parent of this process.

Member Function Documentation

QStringList Qtilities::Core::QtilitiesProcess::lineBreakStrings ( )

Gets the strings to be used for splitting logged messages.

This function was added in Qtilities v1.1.

See also:
setLineBreakStrings()
void Qtilities::Core::QtilitiesProcess::newStandardErrorMessage ( const QString &  message)
signal

Emitted when new standard error becomes available.

This function was added in Qtilities v1.2.

void Qtilities::Core::QtilitiesProcess::newStandardOutputMessage ( const QString &  message)
signal

Emitted when new standard output becomes available.

This function was added in Qtilities v1.2.

void Qtilities::Core::QtilitiesProcess::setLineBreakStrings ( const QStringList &  line_break_strings)

Sets the strings to be used for splitting logged messages.

By default this list is empty an a line break character is used to received split messages.

You can however specify multiple strings to use using this function.

This function was added in Qtilities v1.1.

See also:
lineBreakStrings()
bool Qtilities::Core::QtilitiesProcess::startProcess ( const QString &  program,
const QStringList &  arguments,
QProcess::OpenMode  mode = QProcess::ReadWrite,
int  wait_for_started_msecs = 30000 
)
virtual

Starts the process, similar to QProcess::start().

Parameters:
programThe program to start.
argumentsThe arguments to send to the QProcess.
modeThe OpenMode of the QProcess.
wait_for_started_msecsThe wait for started time in milli seconds to be passed to the waitForStarted() call on the QProcess().
Returns:
True when the task was started successfully (thus waitForStarted() returned true), false otherwise.
void Qtilities::Core::QtilitiesProcess::stopProcess ( )
virtualslot

Stops the process.

This function will first call terminate() on the process, wait and then call kill().

Its important to call Task::stop() at the end of your implementation.



Qtilities : Reference Documentation Back to top Copyright © 2009-2013, Jaco Naudé