1 /* This file is part of Spectacle, the KDE screenshot utility 2 * SPDX-FileCopyrightText: 2019 Boudhayan Gupta <bgupta@kde.org> 3 * SPDX-License-Identifier: LGPL-2.0-or-later 4 */ 5 6 #pragma once 7 8 #include <QCommandLineParser> 9 #include <QObject> 10 11 #include "ExportManager.h" 12 #include "Gui/KSMainWindow.h" 13 #include "Platforms/PlatformLoader.h" 14 #include "QuickEditor/QuickEditor.h" 15 16 #include <memory> 17 18 namespace KWayland 19 { 20 namespace Client 21 { 22 class PlasmaShell; 23 } 24 } 25 26 using MainWindowPtr = std::unique_ptr<KSMainWindow>; 27 using EditorPtr = std::unique_ptr<QuickEditor>; 28 29 class SpectacleCore : public QObject 30 { 31 Q_OBJECT 32 33 public: 34 enum class StartMode { 35 Gui = 0, 36 DBus = 1, 37 Background = 2, 38 }; 39 40 explicit SpectacleCore(QObject *parent = nullptr); 41 ~SpectacleCore() override = default; 42 void init(); 43 44 QString filename() const; 45 void setFilename(const QString &filename); 46 47 void populateCommandLineParser(QCommandLineParser *lCmdLineParser); 48 void initGuiNoScreenshot(); 49 50 Q_SIGNALS: 51 52 void errorMessage(const QString &errString); 53 void allDone(); 54 void grabFailed(); 55 56 public Q_SLOTS: 57 58 void takeNewScreenshot(Spectacle::CaptureMode theCaptureMode, int theTimeout, bool theIncludePointer, bool theIncludeDecorations); 59 void showErrorMessage(const QString &theErrString); 60 void screenshotUpdated(const QPixmap &thePixmap); 61 void screenshotsUpdated(const QVector<QImage> &imgs); 62 void screenshotCanceled(); 63 void screenshotFailed(); 64 void doStartDragAndDrop(); 65 void doNotify(const QUrl &theSavedAt); 66 void doCopyPath(const QUrl &savedAt); 67 68 void onActivateRequested(QStringList arguments, const QString & /*workingDirectory */); 69 70 private: 71 void ensureGuiInitiad(); 72 void initGui(int theDelay, bool theIncludePointer, bool theIncludeDecorations); 73 Platform::GrabMode toPlatformGrabMode(Spectacle::CaptureMode theCaptureMode); 74 void setUpShortcuts(); 75 76 StartMode mStartMode; 77 bool mNotify; 78 QString mFileNameString; 79 QUrl mFileNameUrl; 80 PlatformPtr mPlatform; 81 MainWindowPtr mMainWindow = nullptr; 82 EditorPtr mQuickEditor; 83 bool mIsGuiInited = false; 84 bool mCopyImageToClipboard; 85 bool mCopyLocationToClipboard; 86 bool mSaveToOutput; 87 88 KWayland::Client::PlasmaShell *mWaylandPlasmashell = nullptr; 89 }; 90