| 1 | /* |
| 2 | * Copyright (C) 2021 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 "ActionProcessor.h" |
| 21 | |
| 22 | ActionProcessor::ActionProcessor() : |
| 23 | mIsCaptureInProgress(false), |
| 24 | mIsPostProcessingEnabled(false), |
| 25 | mIsActionInProgress(false) |
| 26 | { |
| 27 | |
| 28 | } |
| 29 | |
| 30 | void ActionProcessor::process(const Action &action) |
| 31 | { |
| 32 | mCurrentAction = action; |
| 33 | mIsActionInProgress = true; |
| 34 | |
| 35 | if (mCurrentAction.isCaptureEnabled()) { |
| 36 | preCaptureProcessing(); |
| 37 | } else { |
| 38 | postCaptureProcessing(); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | void ActionProcessor::setPostProcessingEnabled(bool enabled) |
| 43 | { |
| 44 | mIsPostProcessingEnabled = enabled; |
| 45 | } |
| 46 | |
| 47 | bool ActionProcessor::isActionInProgress() const |
| 48 | { |
| 49 | return mIsActionInProgress; |
| 50 | } |
| 51 | |
| 52 | void ActionProcessor::captureFinished() |
| 53 | { |
| 54 | if(mIsCaptureInProgress) { |
| 55 | mIsCaptureInProgress = false; |
| 56 | postCaptureProcessing(); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void ActionProcessor::captureCanceled() |
| 61 | { |
| 62 | mIsCaptureInProgress = false; |
| 63 | mIsActionInProgress = false; |
| 64 | } |
| 65 | |
| 66 | void ActionProcessor::preCaptureProcessing() |
| 67 | { |
| 68 | mIsCaptureInProgress = true; |
| 69 | emit triggerCapture(mCurrentAction.captureMode(), mCurrentAction.includeCursor(), mCurrentAction.captureDelay()); |
| 70 | } |
| 71 | |
| 72 | void ActionProcessor::postCaptureProcessing() |
| 73 | { |
| 74 | if (!mIsPostProcessingEnabled && !mCurrentAction.isCaptureEnabled()) { |
| 75 | mIsActionInProgress = false; |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | if (mCurrentAction.isSaveEnabled()) { |
| 80 | emit triggerSave(); |
| 81 | } |
| 82 | |
| 83 | if (mCurrentAction.isCopyToClipboardEnabled()) { |
| 84 | emit triggerCopyToClipboard(); |
| 85 | } |
| 86 | |
| 87 | if (mCurrentAction.isOpenDirectoryEnabled()) { |
| 88 | emit triggerOpenDirectory(); |
| 89 | } |
| 90 | |
| 91 | if (mCurrentAction.isPinImageEnabled()) { |
| 92 | emit triggerPinImage(); |
| 93 | } |
| 94 | |
| 95 | if (mCurrentAction.isUploadEnabled()) { |
| 96 | emit triggerUpload(); |
| 97 | } |
| 98 | |
| 99 | if (mCurrentAction.isHideMainWindowEnabled()) { |
| 100 | emit triggerShow(true); |
| 101 | } |
| 102 | |
| 103 | if (!mCurrentAction.isHideMainWindowEnabled() && mCurrentAction.isCaptureEnabled()) { |
| 104 | emit triggerShow(false); |
| 105 | } |
| 106 | |
| 107 | mIsActionInProgress = false; |
| 108 | } |