1 // Copyright (C) 2014-2018 Manuel Schneider
2 
3 #pragma once
4 #include <QUrl>
5 #include <functional>
6 #include "albert/action.h"
7 #include "../core_globals.h"
8 
9 namespace Core {
10 
11 
12 //! @brief Base class for standard actions
13 struct EXPORT_CORE StandardActionBase : public Action
14 {
15 public:
16     StandardActionBase(const QString &text);
17     QString text() const override;
18 
19 private:
20     QString text_;
21 };
22 
23 
24 
25 //! @brief A standard action holding a std::function
26 struct EXPORT_CORE FuncAction : public StandardActionBase
27 {
28 public:
29     FuncAction(const QString &text, std::function<void()> action);
30     void activate() override;
31 
32 private:
33     std::function<void()> action_;
34 };
35 
36 
37 
38 // A standard action that copies text into the clipboard
39 struct EXPORT_CORE ClipAction : public StandardActionBase
40 {
41 public:
42     ClipAction(const QString &text, QString clipBoardText);
43     void activate() override;
44 
45 private:
46     QString clipBoardText_;
47 };
48 
49 
50 
51 // A standard action that opens an url using QDesktopServices
52 struct EXPORT_CORE UrlAction : public StandardActionBase
53 {
54 public:
55     UrlAction(const QString &text, QUrl url);
56     void activate() override;
57 
58 private:
59     QUrl url_ ;
60 };
61 
62 
63 
64 // A standard action that starts a process
65 struct EXPORT_CORE ProcAction : public StandardActionBase
66 {
67 public:
68     ProcAction(const QString &text, const QStringList &commandline, const QString &workingDirectory = QString());
69     void activate() override;
70 
71 protected:
72     QStringList commandline_;
73     QString workingDir_;
74 };
75 
76 
77 
78 // A standard action that runs commands in a terminal
79 struct EXPORT_CORE TermAction : public ProcAction
80 {
81     enum class CloseBehavior {
82         CloseOnSuccess,
83         CloseOnExit,
84         DoNotClose
85     };
86 
87 public:
88 
89     /**
90      * @brief TermAction constructor
91      * @param text The description of the action
92      * @param commandline The command to execute
93      * @param workingDirectory The working directory where to run the command
94      * @param shell Should the command be wrapped in a shell?
95      * @param behavior The close behavior when using the shell
96      */
97     TermAction(const QString &text, const QStringList &commandline, const QString &workingDirectory = QString(),
98                bool shell = true, CloseBehavior behavior = CloseBehavior::CloseOnSuccess);
99     void activate() override;
100 
101 private:
102     bool shell_;
103     CloseBehavior behavior_;
104 };
105 
106 
107 
108 }
109