Changeset View
Changeset View
Standalone View
Standalone View
src/SpectacleCore.cpp
Show All 33 Lines | |||||
34 | #include <QDir> | 34 | #include <QDir> | ||
35 | #include <QDrag> | 35 | #include <QDrag> | ||
36 | #include <QKeySequence> | 36 | #include <QKeySequence> | ||
37 | #include <QMimeData> | 37 | #include <QMimeData> | ||
38 | #include <QProcess> | 38 | #include <QProcess> | ||
39 | #include <QTimer> | 39 | #include <QTimer> | ||
40 | 40 | | |||
41 | SpectacleCore::SpectacleCore(StartMode theStartMode, | 41 | SpectacleCore::SpectacleCore(StartMode theStartMode, | ||
42 | Spectacle::CaptureMode theCaptureMode, | 42 | CaptureMode theCaptureMode, | ||
43 | QString &theSaveFileName, | 43 | QString &theSaveFileName, | ||
44 | qint64 theDelayMsec, | 44 | qint64 theDelayMsec, | ||
45 | bool theNotifyOnGrab, | 45 | bool theNotifyOnGrab, | ||
46 | bool theCopyToClipboard, | 46 | bool theCopyToClipboard, | ||
47 | QObject *parent) : | 47 | QObject *parent) : | ||
48 | QObject(parent), | 48 | QObject(parent), | ||
49 | mStartMode(theStartMode), | 49 | mStartMode(theStartMode), | ||
50 | mNotify(theNotifyOnGrab), | 50 | mNotify(theNotifyOnGrab), | ||
51 | mPlatform(loadPlatform()), | 51 | mScreenshotPlugin(nullptr), | ||
52 | mMainWindow(nullptr), | 52 | mMainWindow(nullptr), | ||
53 | mIsGuiInited(false), | 53 | mIsGuiInited(false), | ||
54 | mCopyToClipboard(theCopyToClipboard) | 54 | mCopyToClipboard(theCopyToClipboard) | ||
55 | { | 55 | { | ||
56 | auto lConfig = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); | 56 | auto lConfig = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); | ||
57 | KConfigGroup lGuiConfig(lConfig, "GuiConfig"); | 57 | KConfigGroup lGuiConfig(lConfig, "GuiConfig"); | ||
58 | 58 | | |||
59 | if (!(theSaveFileName.isEmpty() || theSaveFileName.isNull())) { | 59 | if (!(theSaveFileName.isEmpty() || theSaveFileName.isNull())) { | ||
60 | if (QDir::isRelativePath(theSaveFileName)) { | 60 | if (QDir::isRelativePath(theSaveFileName)) { | ||
61 | theSaveFileName = QDir::current().absoluteFilePath(theSaveFileName); | 61 | theSaveFileName = QDir::current().absoluteFilePath(theSaveFileName); | ||
62 | } | 62 | } | ||
63 | setFilename(theSaveFileName); | 63 | setFilename(theSaveFileName); | ||
64 | } | 64 | } | ||
65 | 65 | | |||
66 | auto lSpectacleConfig = SpectacleConfig::instance(); | ||||
67 | | ||||
68 | //Get screenshot backend | ||||
69 | mScreenshotPlugin = lSpectacleConfig->screenshotBackend(); | ||||
70 | if(mScreenshotPlugin) { | ||||
71 | updateScreenshotBackendConnections(); | ||||
72 | } else { | ||||
73 | //TO DO: No backend found -> possibility to install a new backend | ||||
74 | emit errorMessage(QStringLiteral("No backend found")); | ||||
75 | return; | ||||
76 | } | ||||
77 | | ||||
78 | //connection if screenshot backend has changed | ||||
79 | connect(lSpectacleConfig, &SpectacleConfig::screenshotBackendChanged, this, [this](ScreenshotInterface* screenshotBackend) { | ||||
80 | mScreenshotPlugin = screenshotBackend; | ||||
81 | updateScreenshotBackendConnections(); | ||||
82 | }); | ||||
83 | | ||||
66 | // essential connections | 84 | // essential connections | ||
67 | connect(this, &SpectacleCore::errorMessage, this, &SpectacleCore::showErrorMessage); | 85 | connect(this, &SpectacleCore::errorMessage, this, &SpectacleCore::showErrorMessage); | ||
68 | connect(mPlatform.get(), &Platform::newScreenshotTaken, this, &SpectacleCore::screenshotUpdated); | | |||
69 | connect(mPlatform.get(), &Platform::newScreenshotFailed, this, &SpectacleCore::screenshotFailed); | | |||
70 | 86 | | |||
71 | auto lImmediateAvailable = mPlatform->supportedShutterModes().testFlag(Platform::ShutterMode::Immediate); | | |||
72 | auto lOnClickAvailable = mPlatform->supportedShutterModes().testFlag(Platform::ShutterMode::OnClick); | | |||
73 | if ((!lOnClickAvailable) && (theDelayMsec < 0)) { | | |||
74 | theDelayMsec = 0; | | |||
75 | } | | |||
76 | 87 | | |||
77 | // reset last region if it should not be remembered across restarts | 88 | // reset last region if it should not be remembered across restarts | ||
78 | auto lSpectacleConfig = SpectacleConfig::instance(); | | |||
79 | if(!lSpectacleConfig->alwaysRememberRegion()) { | 89 | if(!lSpectacleConfig->alwaysRememberRegion()) { | ||
80 | lSpectacleConfig->setCropRegion(QRect()); | 90 | lSpectacleConfig->setCropRegion(QRect()); | ||
81 | } | 91 | } | ||
82 | 92 | | |||
83 | // set up the export manager | 93 | // set up the export manager | ||
84 | auto lExportManager = ExportManager::instance(); | 94 | auto lExportManager = ExportManager::instance(); | ||
85 | lExportManager->setCaptureMode(theCaptureMode); | 95 | lExportManager->setCaptureMode(theCaptureMode); | ||
86 | connect(lExportManager, &ExportManager::errorMessage, this, &SpectacleCore::showErrorMessage); | 96 | connect(lExportManager, &ExportManager::errorMessage, this, &SpectacleCore::showErrorMessage); | ||
87 | connect(lExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doCopyPath); | 97 | connect(lExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doCopyPath); | ||
88 | connect(lExportManager, &ExportManager::forceNotify, this, &SpectacleCore::doNotify); | 98 | connect(lExportManager, &ExportManager::forceNotify, this, &SpectacleCore::doNotify); | ||
89 | connect(mPlatform.get(), &Platform::windowTitleChanged, lExportManager, &ExportManager::setWindowTitle); | | |||
90 | 99 | | |||
91 | switch (theStartMode) { | 100 | switch (theStartMode) { | ||
92 | case StartMode::DBus: | 101 | case StartMode::DBus: | ||
93 | break; | 102 | break; | ||
94 | case StartMode::Background: { | 103 | case StartMode::Background: { | ||
104 | //TO Do: Print error message, if there is no screenshot backend | ||||
105 | auto lImmediateAvailable = mScreenshotPlugin->supportedShutterModes().testFlag(ShutterMode::Immediate); | ||||
106 | | ||||
107 | auto lOnClickAvailable = mScreenshotPlugin->supportedShutterModes().testFlag(ShutterMode::OnClick); | ||||
108 | if ((!lOnClickAvailable) && (theDelayMsec < 0)) { | ||||
109 | theDelayMsec = 0; | ||||
110 | } | ||||
111 | | ||||
95 | auto lMsec = (KWindowSystem::compositingActive() ? 200 : 50) + theDelayMsec; | 112 | auto lMsec = (KWindowSystem::compositingActive() ? 200 : 50) + theDelayMsec; | ||
96 | auto lShutterMode = lImmediateAvailable ? Platform::ShutterMode::Immediate : Platform::ShutterMode::OnClick; | 113 | auto lShutterMode = lImmediateAvailable ? ShutterMode::Immediate : ShutterMode::OnClick; | ||
97 | auto lIncludePointer = lGuiConfig.readEntry("includePointer", true); | 114 | auto lIncludePointer = lGuiConfig.readEntry("includePointer", true); | ||
98 | auto lIncludeDecorations = lGuiConfig.readEntry("includeDecorations", true); | 115 | auto lIncludeDecorations = lGuiConfig.readEntry("includeDecorations", true); | ||
99 | const Platform::GrabMode lCaptureMode = toPlatformGrabMode(theCaptureMode); | 116 | QTimer::singleShot(lMsec, this, [ this, theCaptureMode, lShutterMode, lIncludePointer, lIncludeDecorations ]() { | ||
100 | QTimer::singleShot(lMsec, this, [ this, lCaptureMode, lShutterMode, lIncludePointer, lIncludeDecorations ]() { | 117 | mScreenshotPlugin->doGrab(lShutterMode, theCaptureMode, lIncludePointer, lIncludeDecorations); | ||
101 | mPlatform->doGrab(lShutterMode, lCaptureMode, lIncludePointer, lIncludeDecorations); | | |||
102 | }); | 118 | }); | ||
103 | } | 119 | } | ||
104 | break; | 120 | break; | ||
105 | case StartMode::Gui: | 121 | case StartMode::Gui: | ||
106 | initGui(lGuiConfig.readEntry("includePointer", true), lGuiConfig.readEntry("includeDecorations", true)); | 122 | initGui(lGuiConfig.readEntry("includePointer", true), lGuiConfig.readEntry("includeDecorations", true)); | ||
107 | break; | 123 | break; | ||
108 | } | 124 | } | ||
109 | setUpShortcuts(); | 125 | setUpShortcuts(); | ||
110 | } | 126 | } | ||
111 | 127 | | |||
128 | void SpectacleCore::updateScreenshotBackendConnections() { | ||||
129 | connect(mScreenshotPlugin, &ScreenshotInterface::newScreenshotTaken, this, &SpectacleCore::screenshotUpdated); | ||||
130 | connect(mScreenshotPlugin, &ScreenshotInterface::newScreenshotFailed, this, &SpectacleCore::screenshotFailed); | ||||
131 | //TO DO: What is this window title thing about? | ||||
132 | auto lExportManager = ExportManager::instance(); | ||||
133 | connect(mScreenshotPlugin, &ScreenshotInterface::windowTitleChanged, lExportManager, &ExportManager::setWindowTitle); | ||||
134 | | ||||
135 | // Update capture modes and shutter modes | ||||
136 | if(mMainWindow) { | ||||
137 | mMainWindow->setCaptureModes(mScreenshotPlugin->supportedCaptureModes()); | ||||
138 | mMainWindow->setShutterModes(mScreenshotPlugin->supportedShutterModes()); | ||||
139 | } | ||||
140 | } | ||||
141 | | ||||
112 | void SpectacleCore::setUpShortcuts() | 142 | void SpectacleCore::setUpShortcuts() | ||
113 | { | 143 | { | ||
114 | SpectacleConfig* config = SpectacleConfig::instance(); | 144 | SpectacleConfig* config = SpectacleConfig::instance(); | ||
115 | 145 | | |||
116 | QAction* openAction = config->shortCutActions->action(QStringLiteral("_launch")); | 146 | QAction* openAction = config->shortCutActions->action(QStringLiteral("_launch")); | ||
117 | KGlobalAccel::self()->setGlobalShortcut(openAction, Qt::Key_Print); | 147 | KGlobalAccel::self()->setGlobalShortcut(openAction, Qt::Key_Print); | ||
118 | 148 | | |||
119 | QAction* fullScreenAction = config->shortCutActions->action(QStringLiteral("FullScreenScreenShot")); | 149 | QAction* fullScreenAction = config->shortCutActions->action(QStringLiteral("FullScreenScreenShot")); | ||
Show All 33 Lines | 176 | { | |||
153 | 183 | | |||
154 | if (!(mStartMode == StartMode::Gui)) { | 184 | if (!(mStartMode == StartMode::Gui)) { | ||
155 | mStartMode = StartMode::Gui; | 185 | mStartMode = StartMode::Gui; | ||
156 | initGui(lIncludePointer, lIncludeDecorations); | 186 | initGui(lIncludePointer, lIncludeDecorations); | ||
157 | } else { | 187 | } else { | ||
158 | using Actions = SpectacleConfig::PrintKeyActionRunning; | 188 | using Actions = SpectacleConfig::PrintKeyActionRunning; | ||
159 | switch (SpectacleConfig::instance()->printKeyActionRunning()) { | 189 | switch (SpectacleConfig::instance()->printKeyActionRunning()) { | ||
160 | case Actions::TakeNewScreenshot: { | 190 | case Actions::TakeNewScreenshot: { | ||
161 | auto lShutterMode = mPlatform->supportedShutterModes().testFlag(Platform::ShutterMode::Immediate) ? Platform::ShutterMode::Immediate : Platform::ShutterMode::OnClick; | 191 | //Not sure? | ||
162 | auto lGrabMode = toPlatformGrabMode(ExportManager::instance()->captureMode()); | 192 | auto lShutterMode = mScreenshotPlugin->supportedShutterModes().testFlag(ShutterMode::Immediate) ? ShutterMode::Immediate : ShutterMode::OnClick; | ||
163 | QTimer::singleShot(KWindowSystem::compositingActive() ? 200 : 50, this, [this, lShutterMode, lGrabMode, lIncludePointer, lIncludeDecorations]() { | 193 | //Not sure? | ||
164 | mPlatform->doGrab(lShutterMode, lGrabMode, lIncludePointer, lIncludeDecorations); | 194 | QTimer::singleShot(KWindowSystem::compositingActive() ? 200 : 50, this, [this, lShutterMode, lIncludePointer, lIncludeDecorations]() { | ||
195 | mScreenshotPlugin->doGrab(lShutterMode, ExportManager::instance()->captureMode(), lIncludePointer, lIncludeDecorations); | ||||
165 | }); | 196 | }); | ||
166 | break; | 197 | break; | ||
167 | } | 198 | } | ||
168 | case Actions::FocusWindow: | 199 | case Actions::FocusWindow: | ||
169 | if (mMainWindow->isMinimized()) { | 200 | if (mMainWindow->isMinimized()) { | ||
170 | mMainWindow->setWindowState(mMainWindow->windowState() & ~Qt::WindowMinimized); | 201 | mMainWindow->setWindowState(mMainWindow->windowState() & ~Qt::WindowMinimized); | ||
171 | } | 202 | } | ||
172 | mMainWindow->activateWindow(); | 203 | mMainWindow->activateWindow(); | ||
173 | break; | 204 | break; | ||
174 | case Actions::StartNewInstance: | 205 | case Actions::StartNewInstance: | ||
175 | QProcess newInstance; | 206 | QProcess newInstance; | ||
176 | newInstance.setProgram(QStringLiteral("spectacle")); | 207 | newInstance.setProgram(QStringLiteral("spectacle")); | ||
177 | newInstance.startDetached(); | 208 | newInstance.startDetached(); | ||
178 | break; | 209 | break; | ||
179 | } | 210 | } | ||
180 | } | 211 | } | ||
181 | } | 212 | } | ||
182 | 213 | | |||
183 | void SpectacleCore::takeNewScreenshot(Spectacle::CaptureMode theCaptureMode, | 214 | void SpectacleCore::takeNewScreenshot(CaptureMode theCaptureMode, | ||
184 | int theTimeout, | 215 | int theTimeout, | ||
185 | bool theIncludePointer, | 216 | bool theIncludePointer, | ||
186 | bool theIncludeDecorations) | 217 | bool theIncludeDecorations) | ||
187 | { | 218 | { | ||
188 | ExportManager::instance()->setCaptureMode(theCaptureMode); | 219 | ExportManager::instance()->setCaptureMode(theCaptureMode); | ||
189 | auto lGrabMode = toPlatformGrabMode(theCaptureMode); | | |||
190 | 220 | | |||
191 | if (theTimeout < 0) { | 221 | if (theTimeout < 0) { | ||
192 | mPlatform->doGrab(Platform::ShutterMode::OnClick, lGrabMode, theIncludePointer, theIncludeDecorations); | 222 | //not sure | ||
223 | mScreenshotPlugin->doGrab(ShutterMode::OnClick, theCaptureMode, theIncludePointer, theIncludeDecorations); | ||||
193 | return; | 224 | return; | ||
194 | } | 225 | } | ||
195 | 226 | | |||
196 | // when compositing is enabled, we need to give it enough time for the window | 227 | // when compositing is enabled, we need to give it enough time for the window | ||
197 | // to disappear and all the effects are complete before we take the shot. there's | 228 | // to disappear and all the effects are complete before we take the shot. there's | ||
198 | // no way of knowing how long the disappearing effects take, but as per default | 229 | // no way of knowing how long the disappearing effects take, but as per default | ||
199 | // settings (and unless the user has set an extremely slow effect), 200 | 230 | // settings (and unless the user has set an extremely slow effect), 200 | ||
200 | // milliseconds is a good amount of wait time. | 231 | // milliseconds is a good amount of wait time. | ||
201 | 232 | | |||
202 | auto lMsec = KWindowSystem::compositingActive() ? 200 : 50; | 233 | auto lMsec = KWindowSystem::compositingActive() ? 200 : 50; | ||
203 | QTimer::singleShot(theTimeout + lMsec, this, [this, lGrabMode, theIncludePointer, theIncludeDecorations]() { | 234 | QTimer::singleShot(theTimeout + lMsec, this, [this, theCaptureMode, theIncludePointer, theIncludeDecorations]() { | ||
204 | mPlatform->doGrab(Platform::ShutterMode::Immediate, lGrabMode, theIncludePointer, theIncludeDecorations); | 235 | //not sure? | ||
236 | mScreenshotPlugin->doGrab(ShutterMode::Immediate, theCaptureMode, theIncludePointer, theIncludeDecorations); | ||||
205 | }); | 237 | }); | ||
206 | } | 238 | } | ||
207 | 239 | | |||
208 | void SpectacleCore::showErrorMessage(const QString &theErrString) | 240 | void SpectacleCore::showErrorMessage(const QString &theErrString) | ||
209 | { | 241 | { | ||
210 | qCDebug(SPECTACLE_CORE_LOG) << "ERROR: " << theErrString; | 242 | qCDebug(SPECTACLE_CORE_LOG) << "ERROR: " << theErrString; | ||
211 | 243 | | |||
212 | if (mStartMode == StartMode::Gui) { | 244 | if (mStartMode == StartMode::Gui) { | ||
213 | KMessageBox::error(nullptr, theErrString); | 245 | KMessageBox::error(nullptr, theErrString); | ||
214 | } | 246 | } | ||
215 | } | 247 | } | ||
216 | 248 | | |||
217 | void SpectacleCore::screenshotUpdated(const QPixmap &thePixmap) | 249 | void SpectacleCore::screenshotUpdated(const QPixmap &thePixmap) | ||
218 | { | 250 | { | ||
219 | auto lExportManager = ExportManager::instance(); | 251 | auto lExportManager = ExportManager::instance(); | ||
220 | 252 | | |||
221 | // if we were running in rectangular crop mode, now would be | 253 | // if we were running in rectangular crop mode, now would be | ||
222 | // the time to further process the image | 254 | // the time to further process the image | ||
223 | 255 | | |||
224 | if (lExportManager->captureMode() == Spectacle::CaptureMode::RectangularRegion) { | 256 | if (lExportManager->captureMode() == CaptureMode::RectangularRegion) { | ||
225 | if(!mQuickEditor) { | 257 | if(!mQuickEditor) { | ||
226 | mQuickEditor = std::make_unique<QuickEditor>(thePixmap); | 258 | mQuickEditor = std::make_unique<QuickEditor>(thePixmap); | ||
227 | connect(mQuickEditor.get(), &QuickEditor::grabDone, this, &SpectacleCore::screenshotUpdated); | 259 | connect(mQuickEditor.get(), &QuickEditor::grabDone, this, &SpectacleCore::screenshotUpdated); | ||
228 | connect(mQuickEditor.get(), &QuickEditor::grabCancelled, this, &SpectacleCore::screenshotFailed); | 260 | connect(mQuickEditor.get(), &QuickEditor::grabCancelled, this, &SpectacleCore::screenshotFailed); | ||
229 | mQuickEditor->showFullScreen(); | 261 | mQuickEditor->showFullScreen(); | ||
230 | return; | 262 | return; | ||
231 | } else { | 263 | } else { | ||
232 | mQuickEditor->hide(); | 264 | mQuickEditor->hide(); | ||
Show All 29 Lines | 274 | case StartMode::DBus: | |||
262 | break; | 294 | break; | ||
263 | case StartMode::Gui: | 295 | case StartMode::Gui: | ||
264 | mMainWindow->setScreenshotAndShow(thePixmap); | 296 | mMainWindow->setScreenshotAndShow(thePixmap); | ||
265 | } | 297 | } | ||
266 | } | 298 | } | ||
267 | 299 | | |||
268 | void SpectacleCore::screenshotFailed() | 300 | void SpectacleCore::screenshotFailed() | ||
269 | { | 301 | { | ||
270 | if (ExportManager::instance()->captureMode() == Spectacle::CaptureMode::RectangularRegion && mQuickEditor) { | 302 | if (ExportManager::instance()->captureMode() == CaptureMode::RectangularRegion && mQuickEditor) { | ||
271 | mQuickEditor->hide(); | 303 | mQuickEditor->hide(); | ||
272 | mQuickEditor.reset(nullptr); | 304 | mQuickEditor.reset(nullptr); | ||
273 | } | 305 | } | ||
274 | 306 | | |||
275 | switch (mStartMode) { | 307 | switch (mStartMode) { | ||
276 | case StartMode::Background: | 308 | case StartMode::Background: | ||
277 | showErrorMessage(i18n("Screenshot capture canceled or failed")); | 309 | showErrorMessage(i18n("Screenshot capture canceled or failed")); | ||
278 | emit allDone(); | 310 | emit allDone(); | ||
279 | return; | 311 | return; | ||
280 | case StartMode::DBus: | 312 | case StartMode::DBus: | ||
281 | emit grabFailed(); | 313 | emit grabFailed(); | ||
282 | emit allDone(); | 314 | emit allDone(); | ||
283 | return; | 315 | return; | ||
284 | case StartMode::Gui: | 316 | case StartMode::Gui: | ||
285 | mMainWindow->setScreenshotAndShow(QPixmap()); | 317 | mMainWindow->setScreenshotAndShow(QPixmap()); | ||
286 | } | 318 | } | ||
287 | } | 319 | } | ||
288 | 320 | | |||
289 | void SpectacleCore::doNotify(const QUrl &theSavedAt) | 321 | void SpectacleCore::doNotify(const QUrl &theSavedAt) | ||
290 | { | 322 | { | ||
291 | KNotification *lNotify = new KNotification(QStringLiteral("newScreenshotSaved")); | 323 | KNotification *lNotify = new KNotification(QStringLiteral("newScreenshotSaved")); | ||
292 | 324 | | |||
293 | switch(ExportManager::instance()->captureMode()) { | 325 | switch(ExportManager::instance()->captureMode()) { | ||
294 | case Spectacle::CaptureMode::AllScreens: | 326 | case CaptureMode::AllScreens: | ||
295 | lNotify->setTitle(i18nc("The entire screen area was captured, heading", "Full Screen Captured")); | 327 | lNotify->setTitle(i18nc("The entire screen area was captured, heading", "Full Screen Captured")); | ||
296 | break; | 328 | break; | ||
297 | case Spectacle::CaptureMode::CurrentScreen: | 329 | case CaptureMode::CurrentScreen: | ||
298 | lNotify->setTitle(i18nc("The current screen was captured, heading", "Current Screen Captured")); | 330 | lNotify->setTitle(i18nc("The current screen was captured, heading", "Current Screen Captured")); | ||
299 | break; | 331 | break; | ||
300 | case Spectacle::CaptureMode::ActiveWindow: | 332 | case CaptureMode::ActiveWindow: | ||
301 | lNotify->setTitle(i18nc("The active window was captured, heading", "Active Window Captured")); | 333 | lNotify->setTitle(i18nc("The active window was captured, heading", "Active Window Captured")); | ||
302 | break; | 334 | break; | ||
303 | case Spectacle::CaptureMode::WindowUnderCursor: | 335 | case CaptureMode::WindowUnderCursor: | ||
304 | case Spectacle::CaptureMode::TransientWithParent: | 336 | case CaptureMode::TransientWithParent: | ||
305 | lNotify->setTitle(i18nc("The window under the mouse was captured, heading", "Window Under Cursor Captured")); | 337 | lNotify->setTitle(i18nc("The window under the mouse was captured, heading", "Window Under Cursor Captured")); | ||
306 | break; | 338 | break; | ||
307 | case Spectacle::CaptureMode::RectangularRegion: | 339 | case CaptureMode::RectangularRegion: | ||
308 | lNotify->setTitle(i18nc("A rectangular region was captured, heading", "Rectangular Region Captured")); | 340 | lNotify->setTitle(i18nc("A rectangular region was captured, heading", "Rectangular Region Captured")); | ||
309 | break; | 341 | break; | ||
310 | case Spectacle::CaptureMode::InvalidChoice: | | |||
311 | break; | | |||
312 | } | 342 | } | ||
313 | 343 | | |||
314 | // a speaking message is prettier than a URL, special case for copy to clipboard and the default pictures location | 344 | // a speaking message is prettier than a URL, special case for copy to clipboard and the default pictures location | ||
315 | const QString &lSavePath = theSavedAt.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).path(); | 345 | const QString &lSavePath = theSavedAt.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).path(); | ||
316 | if (mCopyToClipboard) { | 346 | if (mCopyToClipboard) { | ||
317 | lNotify->setText(i18n("A screenshot was saved to your clipboard.")); | 347 | lNotify->setText(i18n("A screenshot was saved to your clipboard.")); | ||
318 | } else if (lSavePath == QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)) { | 348 | } else if (lSavePath == QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)) { | ||
319 | lNotify->setText(i18nc("Placeholder is filename", "A screenshot was saved as '%1' to your Pictures folder.", theSavedAt.fileName())); | 349 | lNotify->setText(i18nc("Placeholder is filename", "A screenshot was saved as '%1' to your Pictures folder.", theSavedAt.fileName())); | ||
Show All 36 Lines | 377 | { | |||
356 | lMimeData->setData(QStringLiteral("application/x-kde-suggestedfilename"), QFile::encodeName(lTempFile.fileName())); | 386 | lMimeData->setData(QStringLiteral("application/x-kde-suggestedfilename"), QFile::encodeName(lTempFile.fileName())); | ||
357 | 387 | | |||
358 | auto lDragHandler = new QDrag(this); | 388 | auto lDragHandler = new QDrag(this); | ||
359 | lDragHandler->setMimeData(lMimeData); | 389 | lDragHandler->setMimeData(lMimeData); | ||
360 | lDragHandler->setPixmap(lExportManager->pixmap().scaled(256, 256, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); | 390 | lDragHandler->setPixmap(lExportManager->pixmap().scaled(256, 256, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); | ||
361 | lDragHandler->exec(Qt::CopyAction); | 391 | lDragHandler->exec(Qt::CopyAction); | ||
362 | } | 392 | } | ||
363 | 393 | | |||
364 | // Private | | |||
365 | | ||||
366 | Platform::GrabMode SpectacleCore::toPlatformGrabMode(Spectacle::CaptureMode theCaptureMode) | | |||
367 | { | | |||
368 | switch(theCaptureMode) { | | |||
369 | case Spectacle::CaptureMode::InvalidChoice: | | |||
370 | return Platform::GrabMode::InvalidChoice; | | |||
371 | case Spectacle::CaptureMode::AllScreens: | | |||
372 | case Spectacle::CaptureMode::RectangularRegion: | | |||
373 | return Platform::GrabMode::AllScreens; | | |||
374 | case Spectacle::CaptureMode::TransientWithParent: | | |||
375 | return Platform::GrabMode::TransientWithParent; | | |||
376 | case Spectacle::CaptureMode::CurrentScreen: | | |||
377 | return Platform::GrabMode::CurrentScreen; | | |||
378 | case Spectacle::CaptureMode::ActiveWindow: | | |||
379 | return Platform::GrabMode::ActiveWindow; | | |||
380 | case Spectacle::CaptureMode::WindowUnderCursor: | | |||
381 | return Platform::GrabMode::WindowUnderCursor; | | |||
382 | } | | |||
383 | return Platform::GrabMode::InvalidChoice; | | |||
384 | } | | |||
385 | | ||||
386 | void SpectacleCore::initGui(bool theIncludePointer, bool theIncludeDecorations) | 394 | void SpectacleCore::initGui(bool theIncludePointer, bool theIncludeDecorations) | ||
387 | { | 395 | { | ||
388 | if (!mIsGuiInited) { | 396 | if (!mIsGuiInited) { | ||
389 | mMainWindow = std::make_unique<KSMainWindow>(mPlatform->supportedGrabModes(), mPlatform->supportedShutterModes()); | 397 | mMainWindow = std::make_unique<KSMainWindow>(mScreenshotPlugin->supportedCaptureModes(), mScreenshotPlugin->supportedShutterModes()); | ||
390 | 398 | | |||
391 | connect(mMainWindow.get(), &KSMainWindow::newScreenshotRequest, this, &SpectacleCore::takeNewScreenshot); | 399 | connect(mMainWindow.get(), &KSMainWindow::newScreenshotRequest, this, &SpectacleCore::takeNewScreenshot); | ||
392 | connect(mMainWindow.get(), &KSMainWindow::dragAndDropRequest, this, &SpectacleCore::doStartDragAndDrop); | 400 | connect(mMainWindow.get(), &KSMainWindow::dragAndDropRequest, this, &SpectacleCore::doStartDragAndDrop); | ||
393 | 401 | | |||
394 | mIsGuiInited = true; | 402 | mIsGuiInited = true; | ||
395 | 403 | | |||
396 | auto lShutterMode = mPlatform->supportedShutterModes().testFlag(Platform::ShutterMode::Immediate) ? Platform::ShutterMode::Immediate : Platform::ShutterMode::OnClick; | 404 | auto lShutterMode = mScreenshotPlugin->supportedShutterModes().testFlag(ShutterMode::Immediate) ? ShutterMode::Immediate : ShutterMode::OnClick; | ||
397 | auto lGrabMode = toPlatformGrabMode(ExportManager::instance()->captureMode()); | | |||
398 | 405 | | |||
399 | QTimer::singleShot(0, this, [this, lShutterMode, lGrabMode, theIncludePointer, theIncludeDecorations]() { | 406 | QTimer::singleShot(0, this, [this, lShutterMode, theIncludePointer, theIncludeDecorations]() { | ||
400 | mPlatform->doGrab(lShutterMode, lGrabMode, theIncludePointer, theIncludeDecorations); | 407 | mScreenshotPlugin->doGrab(lShutterMode, ExportManager::instance()->captureMode(), theIncludePointer, theIncludeDecorations); | ||
401 | }); | 408 | }); | ||
402 | } | 409 | } | ||
403 | } | 410 | } |