Changeset View
Changeset View
Standalone View
Standalone View
src/SpectacleCore.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 42 | SpectacleCore::SpectacleCore(StartMode theStartMode, | |||
---|---|---|---|---|---|
47 | bool theCopyToClipboard, | 47 | bool theCopyToClipboard, | ||
48 | QObject *parent) : | 48 | QObject *parent) : | ||
49 | QObject(parent), | 49 | QObject(parent), | ||
50 | mStartMode(theStartMode), | 50 | mStartMode(theStartMode), | ||
51 | mNotify(theNotifyOnGrab), | 51 | mNotify(theNotifyOnGrab), | ||
52 | mPlatform(loadPlatform()), | 52 | mPlatform(loadPlatform()), | ||
53 | mMainWindow(nullptr), | 53 | mMainWindow(nullptr), | ||
54 | mIsGuiInited(false), | 54 | mIsGuiInited(false), | ||
55 | mCopySaveLocationToClipboard(theCopyToClipboard), | 55 | mCopySaveLocationToClipboard(theCopyToClipboard) | ||
56 | mCopyImageToClipboard(false) | | |||
57 | { | 56 | { | ||
58 | auto lConfig = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); | 57 | auto lConfig = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); | ||
59 | KConfigGroup lGuiConfig(lConfig, "GuiConfig"); | 58 | KConfigGroup lGuiConfig(lConfig, "GuiConfig"); | ||
60 | 59 | | |||
61 | if (!(theSaveFileName.isEmpty() || theSaveFileName.isNull())) { | 60 | if (!(theSaveFileName.isEmpty() || theSaveFileName.isNull())) { | ||
62 | if (QDir::isRelativePath(theSaveFileName)) { | 61 | if (QDir::isRelativePath(theSaveFileName)) { | ||
63 | theSaveFileName = QDir::current().absoluteFilePath(theSaveFileName); | 62 | theSaveFileName = QDir::current().absoluteFilePath(theSaveFileName); | ||
64 | } | 63 | } | ||
Show All 18 Lines | |||||
83 | } | 82 | } | ||
84 | 83 | | |||
85 | // set up the export manager | 84 | // set up the export manager | ||
86 | auto lExportManager = ExportManager::instance(); | 85 | auto lExportManager = ExportManager::instance(); | ||
87 | lExportManager->setCaptureMode(theCaptureMode); | 86 | lExportManager->setCaptureMode(theCaptureMode); | ||
88 | connect(lExportManager, &ExportManager::errorMessage, this, &SpectacleCore::showErrorMessage); | 87 | connect(lExportManager, &ExportManager::errorMessage, this, &SpectacleCore::showErrorMessage); | ||
89 | connect(lExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doCopyPath); | 88 | connect(lExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doCopyPath); | ||
90 | connect(lExportManager, &ExportManager::forceNotify, this, &SpectacleCore::doNotify); | 89 | connect(lExportManager, &ExportManager::forceNotify, this, &SpectacleCore::doNotify); | ||
90 | connect(lExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doTask); | ||||
91 | connect(lExportManager, &ExportManager::imageSavedAndCopied, this, &SpectacleCore::doTask); | ||||
91 | connect(mPlatform.get(), &Platform::windowTitleChanged, lExportManager, &ExportManager::setWindowTitle); | 92 | connect(mPlatform.get(), &Platform::windowTitleChanged, lExportManager, &ExportManager::setWindowTitle); | ||
92 | 93 | | |||
93 | switch (theStartMode) { | 94 | switch (theStartMode) { | ||
94 | case StartMode::DBus: | 95 | case StartMode::DBus: | ||
95 | break; | 96 | break; | ||
96 | case StartMode::Background: { | 97 | case StartMode::Background: { | ||
97 | auto lMsec = (KWindowSystem::compositingActive() ? 200 : 50) + theDelayMsec; | 98 | auto lMsec = (KWindowSystem::compositingActive() ? 200 : 50) + theDelayMsec; | ||
98 | auto lShutterMode = lImmediateAvailable ? Platform::ShutterMode::Immediate : Platform::ShutterMode::OnClick; | 99 | auto lShutterMode = lImmediateAvailable ? Platform::ShutterMode::Immediate : Platform::ShutterMode::OnClick; | ||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Line(s) | 246 | { | |||
260 | if (!mNotify) { | 261 | if (!mNotify) { | ||
261 | emit allDone(); | 262 | emit allDone(); | ||
262 | } | 263 | } | ||
263 | } | 264 | } | ||
264 | break; | 265 | break; | ||
265 | case StartMode::Gui: | 266 | case StartMode::Gui: | ||
266 | mMainWindow->setScreenshotAndShow(thePixmap); | 267 | mMainWindow->setScreenshotAndShow(thePixmap); | ||
267 | 268 | | |||
268 | mCopyImageToClipboard = (SpectacleConfig::instance()->afterTakingScreenshotAction() == 1); | 269 | bool autoSaveImage = SpectacleConfig::instance()->autoSaveImage(); | ||
269 | using Actions = SpectacleConfig::AfterTakingScreenshotAction; | 270 | bool copyImageToClipboard = SpectacleConfig::instance()->copyImageToClipboard(); | ||
270 | switch (SpectacleConfig::instance()->afterTakingScreenshotAction()) { | 271 | | ||
271 | case Actions::DoNothing: | 272 | if (autoSaveImage && copyImageToClipboard) { | ||
272 | break; | 273 | QUrl lSavePath = QUrl(); | ||
273 | case Actions::CopyImageToClipboard: | 274 | lExportManager->doSaveAndCopy(lSavePath); | ||
274 | { | 275 | } else if (autoSaveImage) { | ||
276 | QUrl lSavePath = QUrl(); | ||||
277 | lExportManager->doSave(lSavePath); | ||||
278 | } else if (copyImageToClipboard) { | ||||
275 | lExportManager->doCopyToClipboard(false); | 279 | lExportManager->doCopyToClipboard(false); | ||
276 | mMainWindow->showInlineMessage(i18n("The screenshot has been copied to the clipboard."), | 280 | mMainWindow->showInlineMessage(i18n("The screenshot has been copied to the clipboard."), | ||
277 | KMessageWidget::Information); | 281 | KMessageWidget::Information); | ||
278 | } | 282 | } | ||
279 | break; | | |||
280 | } | | |||
281 | } | 283 | } | ||
282 | } | 284 | } | ||
283 | 285 | | |||
284 | void SpectacleCore::screenshotFailed() | 286 | void SpectacleCore::screenshotFailed() | ||
285 | { | 287 | { | ||
286 | if (ExportManager::instance()->captureMode() == Spectacle::CaptureMode::RectangularRegion && mQuickEditor) { | 288 | if (ExportManager::instance()->captureMode() == Spectacle::CaptureMode::RectangularRegion && mQuickEditor) { | ||
287 | mQuickEditor->hide(); | 289 | mQuickEditor->hide(); | ||
288 | mQuickEditor.reset(nullptr); | 290 | mQuickEditor.reset(nullptr); | ||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | |||||
362 | 364 | | |||
363 | void SpectacleCore::doCopyPath(const QUrl &savedAt) | 365 | void SpectacleCore::doCopyPath(const QUrl &savedAt) | ||
364 | { | 366 | { | ||
365 | if (SpectacleConfig::instance()->copySaveLocationToClipboard()) { | 367 | if (SpectacleConfig::instance()->copySaveLocationToClipboard()) { | ||
366 | qApp->clipboard()->setText(savedAt.toLocalFile()); | 368 | qApp->clipboard()->setText(savedAt.toLocalFile()); | ||
367 | } | 369 | } | ||
368 | } | 370 | } | ||
369 | 371 | | |||
372 | void SpectacleCore::doTask(const QUrl &savedAt) | ||||
373 | { | ||||
374 | if (SpectacleConfig::instance()->runTask()) { | ||||
375 | QUrl taskLocationUrl = SpectacleConfig::instance()->taskLocation(); | ||||
376 | if (!taskLocationUrl.isValid() || !taskLocationUrl.isLocalFile()) { | ||||
377 | return; | ||||
378 | } | ||||
379 | QString taskLocationString = taskLocationUrl.toString(); | ||||
380 | QProcess taskProcess; | ||||
381 | taskProcess.setArguments(QStringList() << taskLocationUrl.path(QUrl::FullyEncoded) << savedAt.toString()); | ||||
382 | taskProcess.setWorkingDirectory(savedAt.path(QUrl::FullyEncoded | QUrl::RemoveFilename)); | ||||
383 | | ||||
384 | if (taskLocationString.endsWith(QStringLiteral(".sh"))) { | ||||
385 | QString userShell = QString::fromUtf8(qgetenv("SHELL")); | ||||
386 | taskProcess.setProgram(userShell); | ||||
387 | } else if (taskLocationString.endsWith(QStringLiteral(".py"))) { | ||||
388 | taskProcess.setProgram(QStringLiteral("python")); | ||||
389 | } else { | ||||
390 | taskProcess.setProgram(taskLocationString); | ||||
391 | } | ||||
392 | | ||||
393 | taskProcess.startDetached(); | ||||
394 | } | ||||
395 | } | ||||
396 | | ||||
370 | void SpectacleCore::doStartDragAndDrop() | 397 | void SpectacleCore::doStartDragAndDrop() | ||
371 | { | 398 | { | ||
372 | auto lExportManager = ExportManager::instance(); | 399 | auto lExportManager = ExportManager::instance(); | ||
373 | QUrl lTempFile = lExportManager->tempSave(); | 400 | QUrl lTempFile = lExportManager->tempSave(); | ||
374 | if (!lTempFile.isValid()) { | 401 | if (!lTempFile.isValid()) { | ||
375 | return; | 402 | return; | ||
376 | } | 403 | } | ||
377 | 404 | | |||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |