1 /******************************************************************************
2 
3   This source file is part of the Avogadro project.
4 
5   Copyright 2019 Kitware, Inc.
6 
7   This source code is released under the New BSD License, (the "License").
8 
9   Unless required by applicable law or agreed to in writing, software
10   distributed under the License is distributed on an "AS IS" BASIS,
11   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   See the License for the specific language governing permissions and
13   limitations under the License.
14 
15 ******************************************************************************/
16 
17 #ifndef AVOGADRO_QTPLUGINS_CALCULATIONWATCHER_H
18 #define AVOGADRO_QTPLUGINS_CALCULATIONWATCHER_H
19 
20 #include <QSharedPointer>
21 #include <QVariantMap>
22 
23 class QNetworkAccessManager;
24 class QNetworkReply;
25 
26 namespace Avogadro {
27 namespace QtPlugins {
28 
29 class CalculationWatcher : public QObject
30 {
31   Q_OBJECT
32 
33 public:
34   explicit CalculationWatcher(QSharedPointer<QNetworkAccessManager> manager,
35                               const QString& girderUrl,
36                               const QString& girderToken,
37                               const QString& pendingCalculationId,
38                               QObject* parent);
39   ~CalculationWatcher() override;
40 
41   void start();
42 
43 signals:
44   void finished(const QByteArray& cjson);
45   void error(const QString& errorMessage, QNetworkReply* error = nullptr);
46 
47 private slots:
48   void checkCalculation();
49   void finishCheckCalculation(const QVariant& results);
50 
51   void handleError(const QString& msg, QNetworkReply* networkReply);
52 
53 private:
54   QString m_girderUrl = "http://localhost:8080/api/v1";
55   QString m_girderToken;
56 
57   // These should be set before starting
58   QString m_pendingCalculationId;
59 
60   QSharedPointer<QNetworkAccessManager> m_networkManager;
61 };
62 
63 } // namespace QtPlugins
64 } // namespace Avogadro
65 
66 #endif // AVOGADRO_QTPLUGINS_CALCULATIONWATCHER_H
67