Debian Codegraph @

avogadro/molequeue/molequeuedialog.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_MOLEQUEUE_MOLEQUEUEDIALOG_H
7 #define AVOGADRO_MOLEQUEUE_MOLEQUEUEDIALOG_H
8
9 #include "avogadromolequeueexport.h"
10 #include <QtWidgets/QDialog>
11
12 #include <avogadro/core/avogadrocore.h>
13
14 namespace Avogadro::MoleQueue {
15 class JobObject;
16 class MoleQueueWidget;
17
18 namespace Ui {
19 class MoleQueueDialog;
20 }
21
22 /**
23 * @class MoleQueueDialog molequeuedialog.h
24 * <avogadro/molequeue/molequeuedialog.h>
25 * @brief The MoleQueueDialog class provides a thin wrapper around
26 * MoleQueueWidget for standalone use.
27 * @sa MoleQueueWidget MoleQueueManager
28 */
29 class AVOGADROMOLEQUEUE_EXPORT MoleQueueDialog : public QDialog
30 {
31 Q_OBJECT
32 public:
33 explicit MoleQueueDialog(QWidget* parent_ = nullptr);
34 ~MoleQueueDialog() override;
35
36 /**
37 * @brief Options controlling job submission behavior in the submitJob method.
38 */
39 enum SubmitOption
40 {
41 /**
42 * Keep the dialog open until MoleQueue replies to the submission request.
43 * If a submission error occurs, the user will have to opportunity to fix
44 * it.
45 */
46 WaitForSubmissionResponse = 0x1,
47
48 /**
49 * Use the program in the template job to initialize the queue/program view.
50 * All queues containing a matching program will be expanded, and the first
51 * match will be selected.
52 * To match, an existing program must contain the template program string,
53 * and comparisons are case insensitive.
54 */
55 SelectProgramFromTemplate = 0x2
56 };
57 Q_DECLARE_FLAGS(SubmitOptions, SubmitOption)
58
59 /**
60 * @brief Return values from submitJob indicating result.
61 */
62 enum SubmitStatus
63 {
64 /**
65 * The job was accepted by MoleQueue.
66 * This can only be returned when WaitForSubmissionResponse IS set as an
67 * option.
68 */
69 SubmissionSuccessful = 0,
70
71 /**
72 * The job was not submitted to MoleQueue, likely due to a disconnected
73 * server.
74 * This can only be returned when WaitForSubmissionResponse IS NOT
75 * set as an option.
76 */
77 SubmissionFailed,
78
79 /**
80 * The job was submitted to MoleQueue. This can only be returned when
81 * WaitForSubmissionResponse is NOT set as an option.
82 */
83 SubmissionAttempted,
84
85 /**
86 * The user canceled the submission.
87 */
88 SubmissionAborted,
89
90 /**
91 * The user requested that the job output be opened when finished, but
92 * the job did not finish successfully (the job was either canceled or
93 * failed).
94 */
95 JobFailed,
96
97 /**
98 * The user requested that the job output be opened when finished, and
99 * the job completed without error. The jobTemplate argument of
100 * submitJob will be overwritten with the current job details, fetched
101 * from the server after the job enters the "Finished" state.
102 */
103 JobFinished
104 };
105
106 /**
107 * Show a job configuration dialog and let the user submit the job to
108 * MoleQueue.
109 * @param parent_ The parent widget for parenting/layout purposes.
110 * @param caption The dialog title.
111 * @param jobTemplate A template job, used to initialize GUI options. If
112 * the user requests that the job output is opened and the job finishes
113 * successfully, this will be overwritten with the current job details, and
114 * JobFinished is returned.
115 * @param options Bitwise combination of flags that control dialog behavior.
116 * @param moleQueueId If not nullptr, the variable referenced by this pointer
117 * will be overwritten by the MoleQueue Id of the submitted job when the
118 * option WaitForSubmissionResponse is set.
119 * If an error occurs or the required option is not set, this value will be
120 * set to MoleQueueWidget::InvalidMoleQueueId.
121 * @param submissionRequestId If not nullptr, the variable referenced by this
122 * pointer will be overwritten by the submitJob JSON-RPC 2.0 request id.
123 * If an error occurs, this value will be set to -1.
124 * @return A SubmitStatus enum value indicating the result of the submission.
125 */
126 static SubmitStatus submitJob(QWidget* parent_, const QString& caption,
127 JobObject& jobTemplate, SubmitOptions options,
128 unsigned int* moleQueueId = nullptr,
129 int* submissionRequestId = nullptr);
130
131 /**
132 * Show a job configuration dialog and collect the user's selected options.
133 * @param windowParent The parent of the dialog window.
134 * @param caption Title of the dialog window.
135 * @param jobTemplate JobObject with initial options. Will be overwritten
136 * with the configured job options.
137 * @return True on success, false otherwise.
138 */
139 static bool promptForJobOptions(QWidget* windowParent, const QString& caption,
140 JobObject& jobTemplate);
141
142 /**
143 * @return A reference to the internal MoleQueueWidget instance.
144 * @{
145 */
146 MoleQueueWidget& widget();
147 const MoleQueueWidget& widget() const;
148 /** @} */
149
150 public slots:
151 void done(int r) override;
152
153 private:
154 using MetaMethod = QPair<QObject*, const char*>;
155 /**
156 * Wait @a timeout milliseconds for @a source to emit @a signal.
157 * @param signalList List of QObject* and const char* (signals) to listen for.
158 * @param msTimeout Timeout in milliseconds. A negative value will wait
159 * forever.
160 * @return True if a signal in @a signalList is received, false on timeout.
161 */
162 bool waitForSignal(const QList<MetaMethod>& signalList,
163 int msTimeout = 5000) const;
164
165 Ui::MoleQueueDialog* m_ui;
166 };
167
168 Q_DECLARE_OPERATORS_FOR_FLAGS(MoleQueueDialog::SubmitOptions)
169
170 } // namespace Avogadro::MoleQueue
171
172 #endif // AVOGADRO_MOLEQUEUE_MOLEQUEUEDIALOG_H