Changeset View
Standalone View
src/SpectacleCore.cpp
Show All 13 Lines | |||||
14 | * You should have received a copy of the GNU Lesser General Public License | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | * Boston, MA 02110-1301, USA. | 17 | * Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "SpectacleCore.h" | 20 | #include "SpectacleCore.h" | ||
21 | #include "spectacle_core_debug.h" | 21 | #include "spectacle_core_debug.h" | ||
22 | 22 | | |||
davidre: Already included in the header | |||||
23 | #include "Config.h" | 23 | #include "Config.h" | ||
24 | 24 | | |||
25 | #include <KGlobalAccel> | 25 | #include <KGlobalAccel> | ||
26 | #include <KLocalizedString> | 26 | #include <KLocalizedString> | ||
27 | #include <KMessageBox> | 27 | #include <KMessageBox> | ||
28 | #include <KNotification> | 28 | #include <KNotification> | ||
29 | #include <KRun> | 29 | #include <KRun> | ||
30 | #include <KWindowSystem> | 30 | #include <KWindowSystem> | ||
Show All 15 Lines | 41 | SpectacleCore::SpectacleCore(StartMode theStartMode, | |||
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 | mPlatform(loadPlatform()), | ||
52 | mMainWindow(nullptr), | 52 | mMainWindow(nullptr), | ||
53 | mIsGuiInited(false), | 53 | mIsGuiInited(false), | ||
54 | mCopyToClipboard(theCopyToClipboard) | 54 | mCopySaveLocationToClipboard(theCopyToClipboard), | ||
55 | mCopyImageToClipboard(false) | ||||
55 | { | 56 | { | ||
56 | auto lConfig = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); | 57 | auto lConfig = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); | ||
57 | KConfigGroup lGuiConfig(lConfig, "GuiConfig"); | 58 | KConfigGroup lGuiConfig(lConfig, "GuiConfig"); | ||
58 | 59 | | |||
59 | if (!(theSaveFileName.isEmpty() || theSaveFileName.isNull())) { | 60 | if (!(theSaveFileName.isEmpty() || theSaveFileName.isNull())) { | ||
60 | if (QDir::isRelativePath(theSaveFileName)) { | 61 | if (QDir::isRelativePath(theSaveFileName)) { | ||
61 | theSaveFileName = QDir::current().absoluteFilePath(theSaveFileName); | 62 | theSaveFileName = QDir::current().absoluteFilePath(theSaveFileName); | ||
62 | } | 63 | } | ||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | 147 | { | |||
150 | KConfigGroup lGuiConfig(lConfig, "GuiConfig"); | 151 | KConfigGroup lGuiConfig(lConfig, "GuiConfig"); | ||
151 | auto lIncludePointer = lGuiConfig.readEntry("includePointer", true); | 152 | auto lIncludePointer = lGuiConfig.readEntry("includePointer", true); | ||
152 | auto lIncludeDecorations = lGuiConfig.readEntry("includeDecorations", true); | 153 | auto lIncludeDecorations = lGuiConfig.readEntry("includeDecorations", true); | ||
153 | 154 | | |||
154 | if (!(mStartMode == StartMode::Gui)) { | 155 | if (!(mStartMode == StartMode::Gui)) { | ||
155 | mStartMode = StartMode::Gui; | 156 | mStartMode = StartMode::Gui; | ||
156 | initGui(lIncludePointer, lIncludeDecorations); | 157 | initGui(lIncludePointer, lIncludeDecorations); | ||
157 | } else { | 158 | } else { | ||
158 | using Actions = SpectacleConfig::PrintKeyActionRunning; | 159 | using Actions = SpectacleConfig::PrintKeyActionRunning; | ||
aprcela: enum the copy to clipboard, like this one? | |||||
159 | switch (SpectacleConfig::instance()->printKeyActionRunning()) { | 160 | switch (SpectacleConfig::instance()->printKeyActionRunning()) { | ||
160 | case Actions::TakeNewScreenshot: { | 161 | case Actions::TakeNewScreenshot: { | ||
161 | auto lShutterMode = mPlatform->supportedShutterModes().testFlag(Platform::ShutterMode::Immediate) ? Platform::ShutterMode::Immediate : Platform::ShutterMode::OnClick; | 162 | auto lShutterMode = mPlatform->supportedShutterModes().testFlag(Platform::ShutterMode::Immediate) ? Platform::ShutterMode::Immediate : Platform::ShutterMode::OnClick; | ||
162 | auto lGrabMode = toPlatformGrabMode(ExportManager::instance()->captureMode()); | 163 | auto lGrabMode = toPlatformGrabMode(ExportManager::instance()->captureMode()); | ||
163 | QTimer::singleShot(KWindowSystem::compositingActive() ? 200 : 50, this, [this, lShutterMode, lGrabMode, lIncludePointer, lIncludeDecorations]() { | 164 | QTimer::singleShot(KWindowSystem::compositingActive() ? 200 : 50, this, [this, lShutterMode, lGrabMode, lIncludePointer, lIncludeDecorations]() { | ||
164 | mPlatform->doGrab(lShutterMode, lGrabMode, lIncludePointer, lIncludeDecorations); | 165 | mPlatform->doGrab(lShutterMode, lGrabMode, lIncludePointer, lIncludeDecorations); | ||
165 | }); | 166 | }); | ||
166 | break; | 167 | break; | ||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 219 | { | |||
240 | switch (mStartMode) { | 241 | switch (mStartMode) { | ||
241 | case StartMode::Background: | 242 | case StartMode::Background: | ||
242 | case StartMode::DBus: | 243 | case StartMode::DBus: | ||
243 | { | 244 | { | ||
244 | if (mNotify) { | 245 | if (mNotify) { | ||
245 | connect(lExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doNotify); | 246 | connect(lExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doNotify); | ||
246 | } | 247 | } | ||
247 | 248 | | |||
248 | if (mCopyToClipboard) { | 249 | if (mCopySaveLocationToClipboard) { | ||
249 | lExportManager->doCopyToClipboard(mNotify); | 250 | lExportManager->doCopyToClipboard(mNotify); | ||
250 | } else { | 251 | } else { | ||
251 | QUrl lSavePath = (mStartMode == StartMode::Background && mFileNameUrl.isValid() && mFileNameUrl.isLocalFile()) ? | 252 | QUrl lSavePath = (mStartMode == StartMode::Background && mFileNameUrl.isValid() && mFileNameUrl.isLocalFile()) ? | ||
252 | mFileNameUrl : QUrl(); | 253 | mFileNameUrl : QUrl(); | ||
253 | lExportManager->doSave(lSavePath); | 254 | lExportManager->doSave(lSavePath); | ||
254 | } | 255 | } | ||
255 | 256 | | |||
256 | // if we notify, we emit allDone only if the user either dismissed the notification or pressed | 257 | // if we notify, we emit allDone only if the user either dismissed the notification or pressed | ||
257 | // the "Open" button, otherwise the app closes before it can react to it. | 258 | // the "Open" button, otherwise the app closes before it can react to it. | ||
258 | if (!mNotify) { | 259 | if (!mNotify) { | ||
259 | emit allDone(); | 260 | emit allDone(); | ||
260 | } | 261 | } | ||
261 | } | 262 | } | ||
262 | break; | 263 | break; | ||
263 | case StartMode::Gui: | 264 | case StartMode::Gui: | ||
264 | mMainWindow->setScreenshotAndShow(thePixmap); | 265 | mMainWindow->setScreenshotAndShow(thePixmap); | ||
266 | | ||||
267 | mCopyImageToClipboard = (SpectacleConfig::instance()->copyImageToClipboardSetting() == 1); | ||||
268 | using Actions = SpectacleConfig::CopyImageToClipboardSetting; | ||||
davidre: You would then call that here. | |||||
269 | switch (SpectacleConfig::instance()->copyImageToClipboardSetting()) { | ||||
270 | case Actions::DoNotChangeClipboard: | ||||
271 | break; | ||||
272 | case Actions::CopyImageToClipboard: | ||||
273 | { | ||||
274 | lExportManager->doCopyToClipboard(false); | ||||
Call KSMainWindow::showInlineMessage here, right after lExportManager->doCopyToClipboard(false); aprcela: Call `KSMainWindow::showInlineMessage` here, right after `lExportManager->doCopyToClipboard… | |||||
275 | } | ||||
276 | break; | ||||
277 | } | ||||
265 | } | 278 | } | ||
266 | } | 279 | } | ||
267 | 280 | | |||
268 | void SpectacleCore::screenshotFailed() | 281 | void SpectacleCore::screenshotFailed() | ||
269 | { | 282 | { | ||
270 | if (ExportManager::instance()->captureMode() == Spectacle::CaptureMode::RectangularRegion && mQuickEditor) { | 283 | if (ExportManager::instance()->captureMode() == Spectacle::CaptureMode::RectangularRegion && mQuickEditor) { | ||
271 | mQuickEditor->hide(); | 284 | mQuickEditor->hide(); | ||
272 | mQuickEditor.reset(nullptr); | 285 | mQuickEditor.reset(nullptr); | ||
Show All 35 Lines | 320 | case Spectacle::CaptureMode::RectangularRegion: | |||
308 | lNotify->setTitle(i18nc("A rectangular region was captured, heading", "Rectangular Region Captured")); | 321 | lNotify->setTitle(i18nc("A rectangular region was captured, heading", "Rectangular Region Captured")); | ||
309 | break; | 322 | break; | ||
310 | case Spectacle::CaptureMode::InvalidChoice: | 323 | case Spectacle::CaptureMode::InvalidChoice: | ||
311 | break; | 324 | break; | ||
312 | } | 325 | } | ||
313 | 326 | | |||
314 | // a speaking message is prettier than a URL, special case for copy to clipboard and the default pictures location | 327 | // 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(); | 328 | const QString &lSavePath = theSavedAt.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).path(); | ||
316 | if (mCopyToClipboard) { | 329 | if (mCopySaveLocationToClipboard || mCopyImageToClipboard) { | ||
Do we need the change here and in the if below now? We aren't calling doNotify anymore after auto copying right? davidre: Do we need the change here and in the if below now? We aren't calling doNotify anymore after… | |||||
aprcela: True, not needed anymore. Both are removed now. | |||||
317 | lNotify->setText(i18n("A screenshot was saved to your clipboard.")); | 330 | lNotify->setText(i18n("A screenshot was saved to your clipboard.")); | ||
318 | } else if (lSavePath == QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)) { | 331 | } 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())); | 332 | lNotify->setText(i18nc("Placeholder is filename", "A screenshot was saved as '%1' to your Pictures folder.", theSavedAt.fileName())); | ||
320 | } else { | 333 | } else { | ||
321 | lNotify->setText(i18n("A screenshot was saved as '%1' to '%2'.", theSavedAt.fileName(), lSavePath)); | 334 | lNotify->setText(i18n("A screenshot was saved as '%1' to '%2'.", theSavedAt.fileName(), lSavePath)); | ||
322 | } | 335 | } | ||
323 | 336 | | |||
324 | if (!mCopyToClipboard) { | 337 | if (!mCopySaveLocationToClipboard && !mCopyImageToClipboard) { | ||
davidre: else? | |||||
Continue with else for the if-else if.. above? Or you mean separate the check in this if with else for the !mCopySaveLocationToClipboard and !mCopyImageToClipboard variables? aprcela: Continue with else for the `if-else if..` above?
The upper one sets the text, while this one… | |||||
mCopySaveLocationToClipboard || mCopyImageToClipboard is true when at least one of them is true. davidre: `mCopySaveLocationToClipboard || mCopyImageToClipboard` is true when at least one of them is… | |||||
325 | lNotify->setUrls({theSavedAt}); | 338 | lNotify->setUrls({theSavedAt}); | ||
326 | lNotify->setDefaultAction(i18nc("Open the screenshot we just saved", "Open")); | 339 | lNotify->setDefaultAction(i18nc("Open the screenshot we just saved", "Open")); | ||
327 | connect(lNotify, QOverload<uint>::of(&KNotification::activated), this, [this, theSavedAt](uint index) { | 340 | connect(lNotify, QOverload<uint>::of(&KNotification::activated), this, [this, theSavedAt](uint index) { | ||
328 | if (index == 0) { | 341 | if (index == 0) { | ||
329 | new KRun(theSavedAt, nullptr); | 342 | new KRun(theSavedAt, nullptr); | ||
330 | QTimer::singleShot(250, this, &SpectacleCore::allDone); | 343 | QTimer::singleShot(250, this, &SpectacleCore::allDone); | ||
331 | } | 344 | } | ||
332 | }); | 345 | }); | ||
333 | } | 346 | } | ||
davidre: Why was this moved? | |||||
Because if this is where it was before, it would close Spectacle after the notification disappears: original: moved: aprcela: Because if this is where it was before, it would close Spectacle after the notification… | |||||
I understand you want to show feedback when copying. With moving this you broke the case when we want to show a notifcation after copying and then exit i.e. spectacle -b -c. I would also prefer if we could display a Inline message instead like when you use the button to copy to clipbboard. davidre: I understand you want to show feedback when copying. With moving this you broke the case when… | |||||
Reverted, works again. If we would use KSMainWindow::sendToClipboard than we have the problem when a user has both Quit after Save or copy and Copy image to clipboard activated, than Spectacle will immediately close after the image has been saved to the clipboard.. aprcela: Reverted, works again.
If we would use `KSMainWindow::sendToClipboard` than we have the… | |||||
334 | 347 | | |||
Oh you're right didn't think of that as I never use that feature myself. davidre: Oh you're right didn't think of that as I never use that feature myself.
Good news… | |||||
https://cgit.kde.org/spectacle.git/tree/src/Gui/KSMainWindow.h#n62 Is, unfortunately, private. aprcela: https://cgit.kde.org/spectacle.git/tree/src/Gui/KSMainWindow.h#n62
Is, unfortunately, private. | |||||
davidre: It seems I'm blind :D.
Just move it to the public group. | |||||
aprcela: done :) | |||||
335 | connect(lNotify, &QObject::destroyed, this, &SpectacleCore::allDone); | 348 | connect(lNotify, &QObject::destroyed, this, &SpectacleCore::allDone); | ||
336 | lNotify->sendEvent(); | 349 | lNotify->sendEvent(); | ||
337 | } | 350 | } | ||
338 | 351 | | |||
339 | void SpectacleCore::doCopyPath(const QUrl &savedAt) | 352 | void SpectacleCore::doCopyPath(const QUrl &savedAt) | ||
340 | { | 353 | { | ||
341 | if (SpectacleConfig::instance()->copySaveLocationToClipboard()) { | 354 | if (SpectacleConfig::instance()->copySaveLocationToClipboard()) { | ||
342 | qApp->clipboard()->setText(savedAt.toLocalFile()); | 355 | qApp->clipboard()->setText(savedAt.toLocalFile()); | ||
343 | } | 356 | } | ||
344 | } | 357 | } | ||
345 | 358 | | |||
346 | void SpectacleCore::doStartDragAndDrop() | 359 | void SpectacleCore::doStartDragAndDrop() | ||
347 | { | 360 | { | ||
348 | auto lExportManager = ExportManager::instance(); | 361 | auto lExportManager = ExportManager::instance(); | ||
349 | QUrl lTempFile = lExportManager->tempSave(); | 362 | QUrl lTempFile = lExportManager->tempSave(); | ||
350 | if (!lTempFile.isValid()) { | 363 | if (!lTempFile.isValid()) { | ||
I don't think we need a method here that is only called once and is a one liner davidre: I don't think we need a method here that is only called once and is a one liner | |||||
351 | return; | 364 | return; | ||
352 | } | 365 | } | ||
353 | 366 | | |||
354 | auto lMimeData = new QMimeData; | 367 | auto lMimeData = new QMimeData; | ||
355 | lMimeData->setUrls(QList<QUrl> { lTempFile }); | 368 | lMimeData->setUrls(QList<QUrl> { lTempFile }); | ||
356 | lMimeData->setData(QStringLiteral("application/x-kde-suggestedfilename"), QFile::encodeName(lTempFile.fileName())); | 369 | lMimeData->setData(QStringLiteral("application/x-kde-suggestedfilename"), QFile::encodeName(lTempFile.fileName())); | ||
357 | 370 | | |||
358 | auto lDragHandler = new QDrag(this); | 371 | auto lDragHandler = new QDrag(this); | ||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |
Already included in the header