From 1b4d62ef4d060945c6c8a717b1311615365de07f Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 10 Jul 2014 17:11:03 +0200 Subject: [PATCH] Add ProcessJobModule for loading external commands. --- src/libcalamaresui/CMakeLists.txt | 1 + .../modulesystem/ProcessJobModule.cpp | 84 +++++++++++++++++++ .../modulesystem/ProcessJobModule.h | 51 +++++++++++ 3 files changed, 136 insertions(+) create mode 100644 src/libcalamaresui/modulesystem/ProcessJobModule.cpp create mode 100644 src/libcalamaresui/modulesystem/ProcessJobModule.h diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index 491b41b59..af660fec2 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -3,6 +3,7 @@ set( CALAMARESUI_LIBRARY_TARGET calamaresui ) list( APPEND ${CALAMARESUI_LIBRARY_TARGET}_SOURCES modulesystem/Module.cpp modulesystem/ModuleManager.cpp + modulesystem/ProcessJobModule.cpp modulesystem/ViewModule.cpp utils/CalamaresUtilsGui.cpp diff --git a/src/libcalamaresui/modulesystem/ProcessJobModule.cpp b/src/libcalamaresui/modulesystem/ProcessJobModule.cpp new file mode 100644 index 000000000..cd5242757 --- /dev/null +++ b/src/libcalamaresui/modulesystem/ProcessJobModule.cpp @@ -0,0 +1,84 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Calamares 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 3 of the License, or + * (at your option) any later version. + * + * Calamares 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "ProcessJobModule.h" + +#include "JobQueue.h" +#include "ProcessJob.h" + +#include + +#include + +namespace Calamares { + + +Module::Type +ProcessJobModule::type() const +{ + return Job; +} + + +Module::Interface +ProcessJobModule::interface() const +{ + return Process; +} + + +void +ProcessJobModule::loadSelf() +{ + Calamares::job_ptr j = Calamares::job_ptr( new ProcessJob( m_command, + m_workingPath, + m_secondsTimeout ) ); + JobQueue::instance()->enqueue( j ); +} + + +void +ProcessJobModule::initFrom( const YAML::Node& node ) +{ + Module::initFrom( node ); + QDir directory( location() ); + m_workingPath = directory.absolutePath(); + + if ( node[ "command" ] ) + { + m_command = QString::fromStdString( node[ "command" ].as< std::string >() ); + } + + m_secondsTimeout = 30; + if ( node[ "timeout" ] ) + { + m_secondsTimeout = node[ "timeout" ].as< int >(); + } +} + + +ProcessJobModule::ProcessJobModule() + : Module() +{} + + +ProcessJobModule::~ProcessJobModule() +{} + + +} // namespace Calamares diff --git a/src/libcalamaresui/modulesystem/ProcessJobModule.h b/src/libcalamaresui/modulesystem/ProcessJobModule.h new file mode 100644 index 000000000..f5999087e --- /dev/null +++ b/src/libcalamaresui/modulesystem/ProcessJobModule.h @@ -0,0 +1,51 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Calamares 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 3 of the License, or + * (at your option) any later version. + * + * Calamares 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef CALAMARES_PROCESSJOBMODULE_H +#define CALAMARES_PROCESSJOBMODULE_H + +#include "Module.h" + +#include "UiDllMacro.h" + +namespace Calamares { + +class UIDLLEXPORT ProcessJobModule : public Module +{ +public: + Type type() const override; + Interface interface() const override; + + void loadSelf() override; + +protected: + void initFrom( const YAML::Node &node ) override; + +private: + friend class Module; + explicit ProcessJobModule(); + virtual ~ProcessJobModule(); + + QString m_command; + QString m_workingPath; + int m_secondsTimeout; +}; + +} // namespace Calamares + +#endif // CALAMARES_PROCESSJOBMODULE_H