1 | /* |
---|
2 | Copyright (C) 2007 by Robert Knight <robertknight@gmail.com> |
---|
3 | |
---|
4 | Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008 |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2 of the License, or |
---|
9 | (at your option) any later version. |
---|
10 | |
---|
11 | This program is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with this program; if not, write to the Free Software |
---|
18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
---|
19 | 02110-1301 USA. |
---|
20 | */ |
---|
21 | |
---|
22 | #ifndef SHELLCOMMAND_H |
---|
23 | #define SHELLCOMMAND_H |
---|
24 | |
---|
25 | // Qt |
---|
26 | #include <QtCore/QStringList> |
---|
27 | |
---|
28 | namespace Konsole |
---|
29 | { |
---|
30 | |
---|
31 | /** |
---|
32 | * A class to parse and extract information about shell commands. |
---|
33 | * |
---|
34 | * ShellCommand can be used to: |
---|
35 | * |
---|
36 | * <ul> |
---|
37 | * <li>Take a command-line (eg "/bin/sh -c /path/to/my/script") and split it |
---|
38 | * into its component parts (eg. the command "/bin/sh" and the arguments |
---|
39 | * "-c","/path/to/my/script") |
---|
40 | * </li> |
---|
41 | * <li>Take a command and a list of arguments and combine them to |
---|
42 | * form a complete command line. |
---|
43 | * </li> |
---|
44 | * <li>Determine whether the binary specified by a command exists in the |
---|
45 | * user's PATH. |
---|
46 | * </li> |
---|
47 | * <li>Determine whether a command-line specifies the execution of |
---|
48 | * another command as the root user using su/sudo etc. |
---|
49 | * </li> |
---|
50 | * </ul> |
---|
51 | */ |
---|
52 | class ShellCommand |
---|
53 | { |
---|
54 | public: |
---|
55 | /** |
---|
56 | * Constructs a ShellCommand from a command line. |
---|
57 | * |
---|
58 | * @param fullCommand The command line to parse. |
---|
59 | */ |
---|
60 | ShellCommand(const QString& fullCommand); |
---|
61 | /** |
---|
62 | * Constructs a ShellCommand with the specified @p command and @p arguments. |
---|
63 | */ |
---|
64 | ShellCommand(const QString& command , const QStringList& arguments); |
---|
65 | |
---|
66 | /** Returns the command. */ |
---|
67 | QString command() const; |
---|
68 | /** Returns the arguments. */ |
---|
69 | QStringList arguments() const; |
---|
70 | |
---|
71 | /** |
---|
72 | * Returns the full command line. |
---|
73 | */ |
---|
74 | QString fullCommand() const; |
---|
75 | |
---|
76 | /** Returns true if this is a root command. */ |
---|
77 | bool isRootCommand() const; |
---|
78 | /** Returns true if the program specified by @p command() exists. */ |
---|
79 | bool isAvailable() const; |
---|
80 | |
---|
81 | /** Expands environment variables in @p text .*/ |
---|
82 | static QString expand(const QString& text); |
---|
83 | |
---|
84 | /** Expands environment variables in each string in @p list. */ |
---|
85 | static QStringList expand(const QStringList& items); |
---|
86 | |
---|
87 | private: |
---|
88 | QStringList _arguments; |
---|
89 | }; |
---|
90 | |
---|
91 | } |
---|
92 | |
---|
93 | #endif // SHELLCOMMAND_H |
---|
94 | |
---|