Debian Codegraph @

src/backend/uploader/script/ScriptUploader.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 Damir Porobic <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #ifndef KSNIP_SCRIPTUPLOADER_H
21 #define KSNIP_SCRIPTUPLOADER_H
22
23 #include <QProcess>
24 #include <QRegularExpression>
25 #include <QSharedPointer>
26 #include <QImage>
27
28 #include "src/backend/uploader/script/IScriptUploader.h"
29 #include "src/backend/config/IConfig.h"
30 #include "src/common/enum/UploadStatus.h"
31 #include "src/common/provider/ITempFileProvider.h"
32
33 class ScriptUploader : public IScriptUploader
34 {
35 Q_OBJECT
36 public:
37 explicit ScriptUploader(const QSharedPointer<IConfig> &config, const QSharedPointer<ITempFileProvider> &tempFileProvider);
38 ~ScriptUploader() override = default;
39 void upload(const QImage &image) override;
40 UploaderType type() const override;
41
42 private:
43 QSharedPointer<IConfig> mConfig;
44 QSharedPointer<ITempFileProvider> mTempFileProvider;
45 QProcess mProcessHandler;
46 QString mPathToTmpImage;
47
48 private slots:
49 void scriptFinished(int exitCode, QProcess::ExitStatus exitStatus);
50 void errorOccurred(QProcess::ProcessError error);
51 bool saveImageLocally(const QImage &image);
52 QString parseOutput(const QString &output) const;
53 void writeToConsole(const QString &output) const;
54 UploadStatus mapErrorTypeToStatus(QProcess::ProcessError errorType) const;
55 void handleSuccess();
56 void handleError(const UploadStatus &status, const QString &stdErrOutput);
57 };
58
59 #endif //KSNIP_SCRIPTUPLOADER_H