Debian Codegraph @

src/gui/operations/UploadOperation.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2019 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 #include "UploadOperation.h"
21
22 UploadOperation::UploadOperation(
23 QImage image,
24 const QSharedPointer<IUploader> &uploader,
25 const QSharedPointer<IConfig> &config,
26 const QSharedPointer<IMessageBoxService> &messageBoxService) :
27 mImage(std::move(image)),
28 mUploader(uploader),
29 mConfig(config),
30 mMessageBoxService(messageBoxService)
31 {
32 Q_ASSERT(mUploader != nullptr);
33 }
34
35 bool UploadOperation::execute()
36 {
37 if (mUploader->type() == UploaderType::Script && !PathHelper::isPathValid(mConfig->uploadScriptPath())) {
38 mMessageBoxService->ok(tr("Upload Script Required"),
39 tr("Please add an upload script via Options > Settings > Upload Script"));
40 } else if (!mImage.isNull() && proceedWithUpload()) {
41 mUploader->upload(mImage);
42 return true;
43 }
44 return false;
45 }
46
47 bool UploadOperation::proceedWithUpload() const
48 {
49 return !mConfig->confirmBeforeUpload() || askIfCanProceedWithUpload();
50 }
51
52 bool UploadOperation::askIfCanProceedWithUpload() const
53 {
54 return mMessageBoxService->yesNo(tr("Capture Upload"),
55 tr("You are about to upload the image to an external destination, do you want to proceed?"));
56 }