source: calamares/trunk/fuentes/src/libcalamares/utils/CommandList.h @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 17 months ago

sync with github

File size: 2.7 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2018, Adriaan de Groot <groot@kde.org>
4 *
5 *   Calamares is free software: you can redistribute it and/or modify
6 *   it under the terms of the GNU General Public License as published by
7 *   the Free Software Foundation, either version 3 of the License, or
8 *   (at your option) any later version.
9 *
10 *   Calamares is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *   GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef COMMANDLIST_H
20#define COMMANDLIST_H
21
22#include "Job.h"
23
24#include <QStringList>
25#include <QVariant>
26
27namespace CalamaresUtils
28{
29
30/**
31 * Each command can have an associated timeout in seconds. The timeout
32 * defaults to 10 seconds. Provide some convenience naming and construction.
33 */
34struct CommandLine : public QPair< QString, int >
35{
36    enum { TimeoutNotSet = -1 };
37
38    /// An invalid command line
39    CommandLine()
40        : QPair< QString, int >( QString(), TimeoutNotSet )
41    {
42    }
43
44    CommandLine( const QString& s )
45        : QPair< QString, int >( s, TimeoutNotSet )
46    {
47    }
48
49    CommandLine( const QString& s, int t )
50        : QPair< QString, int >( s, t)
51    {
52    }
53
54    QString command() const
55    {
56        return first;
57    }
58
59    int timeout() const
60    {
61        return second;
62    }
63
64    bool isValid() const
65    {
66        return !first.isEmpty();
67    }
68} ;
69
70/** @brief Abbreviation, used internally. */
71using CommandList_t = QList< CommandLine >;
72
73/**
74 * A list of commands; the list may have its own default timeout
75 * for commands (which is then applied to each individual command
76 * that doesn't have one of its own).
77 *
78 * Documentation for the format of commands can be found in
79 * `shellprocess.conf`.
80 */
81class CommandList : protected CommandList_t
82{
83public:
84    /** @brief empty command-list with timeout to apply to entries. */
85    CommandList( bool doChroot = true, int timeout = 10 );
86    CommandList( const QVariant& v, bool doChroot = true, int timeout = 10 );
87    ~CommandList();
88
89    bool doChroot() const
90    {
91        return m_doChroot;
92    }
93
94    Calamares::JobResult run();
95
96    using CommandList_t::isEmpty;
97    using CommandList_t::count;
98    using CommandList_t::cbegin;
99    using CommandList_t::cend;
100    using CommandList_t::const_iterator;
101    using CommandList_t::at;
102
103protected:
104    using CommandList_t::append;
105    void append( const QString& );
106
107private:
108    bool m_doChroot;
109    int m_timeout;
110} ;
111
112}  // namespace
113#endif // COMMANDLIST_H
Note: See TracBrowser for help on using the repository browser.