Changeset View
Changeset View
Standalone View
Standalone View
src/Gui/KSMainWindow.cpp
Show First 20 Lines • Show All 362 Lines • ▼ Show 20 Line(s) | 362 | if (!exportManager->isFileExists(location)) { | |||
---|---|---|---|---|---|
363 | location = cfgManager->lastSaveAsLocation(); | 363 | location = cfgManager->lastSaveAsLocation(); | ||
364 | } | 364 | } | ||
365 | break; | 365 | break; | ||
366 | } | 366 | } | ||
367 | 367 | | |||
368 | KIO::highlightInFileManager({location}); | 368 | KIO::highlightInFileManager({location}); | ||
369 | } | 369 | } | ||
370 | 370 | | |||
371 | void KSMainWindow::quit(const QuitBehavior quitBehavior) | | |||
372 | { | | |||
373 | qApp->setQuitOnLastWindowClosed(false); | | |||
374 | hide(); | | |||
375 | | ||||
376 | if (quitBehavior == QuitBehavior::QuitImmediately) { | | |||
377 | // Allow some time for clipboard content to transfer | | |||
378 | // TODO: Find better solution | | |||
379 | QTimer::singleShot(250, qApp, &QApplication::quit); | | |||
380 | } | | |||
381 | // TODO for else case: | | |||
382 | // Currently it is expected that you emit forceNotify, and finally quit | | |||
383 | // via a callback through KNotification::action1Activated. However, that | | |||
384 | // is not working quite right, see Bug #389694 which needs fixing. | | |||
385 | } | | |||
386 | | ||||
387 | void KSMainWindow::showInlineMessage(const QString& message, const KMessageWidget::MessageType messageType, | 371 | void KSMainWindow::showInlineMessage(const QString& message, const KMessageWidget::MessageType messageType, | ||
388 | const MessageDuration messageDuration, const QList<QAction*>& actions) | 372 | const MessageDuration messageDuration, const QList<QAction*>& actions) | ||
389 | { | 373 | { | ||
390 | const auto messageWidgetActions = mMessageWidget->actions(); | 374 | const auto messageWidgetActions = mMessageWidget->actions(); | ||
391 | for (QAction* action: messageWidgetActions) { | 375 | for (QAction* action: messageWidgetActions) { | ||
392 | mMessageWidget->removeAction(action); | 376 | mMessageWidget->removeAction(action); | ||
393 | } | 377 | } | ||
394 | for (QAction* action : actions) { | 378 | for (QAction* action : actions) { | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 420 | showInlineMessage(i18n("The shared image link (<a href=\"%1\">%1</a>) has been copied to the clipboard.", message), | |||
437 | KMessageWidget::Positive, MessageDuration::Persistent); | 421 | KMessageWidget::Positive, MessageDuration::Persistent); | ||
438 | QApplication::clipboard()->setText(message); | 422 | QApplication::clipboard()->setText(message); | ||
439 | } | 423 | } | ||
440 | } | 424 | } | ||
441 | } | 425 | } | ||
442 | 426 | | |||
443 | void KSMainWindow::sendToClipboard() | 427 | void KSMainWindow::sendToClipboard() | ||
444 | { | 428 | { | ||
445 | bool notify = false; | 429 | ExportManager::instance()->doCopyToClipboard(); | ||
446 | ExportManager::instance()->doCopyToClipboard(notify); | 430 | if (!SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) { | ||
447 | 431 | showInlineMessage(i18n("The screenshot has been copied to the clipboard."), | |||
448 | SpectacleConfig::instance()->quitAfterSaveOrCopyChecked() | | |||
449 | ? quit() | | |||
450 | : showInlineMessage(i18n("The screenshot has been copied to the clipboard."), | | |||
451 | KMessageWidget::Information); | 432 | KMessageWidget::Information); | ||
452 | } | 433 | } | ||
434 | } | ||||
453 | 435 | | |||
454 | void KSMainWindow::showPreferencesDialog() | 436 | void KSMainWindow::showPreferencesDialog() | ||
455 | { | 437 | { | ||
456 | SettingsDialog prefDialog(this); | 438 | SettingsDialog prefDialog(this); | ||
457 | prefDialog.exec(); | 439 | prefDialog.exec(); | ||
458 | } | 440 | } | ||
459 | 441 | | |||
460 | void KSMainWindow::imageSaved(const QUrl &location) | 442 | void KSMainWindow::imageSaved(const QUrl &location) | ||
461 | { | 443 | { | ||
462 | setWindowTitle(location.fileName()); | 444 | setWindowTitle(location.fileName()); | ||
463 | setWindowModified(false); | 445 | setWindowModified(false); | ||
464 | QAction* openContaining = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"), mMessageWidget); | 446 | QAction* openContaining = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"), mMessageWidget); | ||
465 | connect(openContaining, &QAction::triggered, [=] { KIO::highlightInFileManager({location});}); | 447 | connect(openContaining, &QAction::triggered, [=] { KIO::highlightInFileManager({location});}); | ||
466 | showInlineMessage(i18n("The screenshot was saved as <a href=\"%1\">%2</a>", | 448 | showInlineMessage(i18n("The screenshot was saved as <a href=\"%1\">%2</a>", | ||
467 | location.toString(), location.fileName()), KMessageWidget::Positive, | 449 | location.toString(), location.fileName()), KMessageWidget::Positive, | ||
468 | MessageDuration::AutoHide, {openContaining}); | 450 | MessageDuration::AutoHide, {openContaining}); | ||
469 | } | 451 | } | ||
470 | 452 | | |||
471 | void KSMainWindow::save() | 453 | void KSMainWindow::save() | ||
472 | { | 454 | { | ||
473 | SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::Save); | 455 | SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::Save); | ||
474 | setDefaultSaveAction(); | 456 | setDefaultSaveAction(); | ||
475 | 457 | ExportManager::instance()->doSave(QUrl()); | |||
476 | const bool quitChecked = SpectacleConfig::instance()->quitAfterSaveOrCopyChecked(); | | |||
477 | ExportManager::instance()->doSave(QUrl(), /* notify */ quitChecked); | | |||
478 | if (quitChecked) { | | |||
479 | quit(QuitBehavior::QuitExternally); | | |||
480 | } | | |||
481 | } | 458 | } | ||
482 | 459 | | |||
483 | void KSMainWindow::saveAs() | 460 | void KSMainWindow::saveAs() | ||
484 | { | 461 | { | ||
485 | SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::SaveAs); | 462 | SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::SaveAs); | ||
486 | setDefaultSaveAction(); | 463 | setDefaultSaveAction(); | ||
487 | 464 | ExportManager::instance()->doSaveAs(this); | |||
488 | const bool quitChecked = SpectacleConfig::instance()->quitAfterSaveOrCopyChecked(); | | |||
489 | if (ExportManager::instance()->doSaveAs(this, /* notify */ quitChecked) && quitChecked) { | | |||
490 | quit(QuitBehavior::QuitExternally); | | |||
491 | } | | |||
492 | } | 465 | } |