From c66219c9b88b342d0ae8b88538e5e320e73ab755 Mon Sep 17 00:00:00 2001
From: Gabriel Maia <gbl08ma@gmail.com>
Date: Wed, 7 Sep 2016 11:43:03 +0000
Subject: [PATCH] Screenshot: better error handling on save
Show error messages when saving fails, to enmake sure the user is not
confused by thinking the file saved when the window doesn't close.
---
src/apps/screenshot/ScreenshotWindow.cpp | 44 +++++++++++++++++++++++++++++---
1 file changed, 41 insertions(+), 3 deletions(-)
diff --git a/src/apps/screenshot/ScreenshotWindow.cpp b/src/apps/screenshot/ScreenshotWindow.cpp
index 58a6df3..2455286 100644
a
|
b
|
ScreenshotWindow::_SaveScreenshot()
|
626 | 626 | // necessary, for example, when the user selects the Artwork folder from |
627 | 627 | // the list of predefined folders. |
628 | 628 | if (!directoryEntry.Exists()) { |
629 | | if (create_directory(path.Path(), 0755) != B_OK) { |
| 629 | status_t directoryCreateStatus = create_directory(path.Path(), 0755); |
| 630 | if (directoryCreateStatus != B_OK) { |
| 631 | BString alertText; |
| 632 | alertText.SetToFormat(B_TRANSLATE("Error saving \"%s\":\n\t%s"), |
| 633 | fNameControl->Text(), strerror(directoryCreateStatus)); |
| 634 | |
| 635 | BAlert* alert = new BAlert("Error", alertText.String(), |
| 636 | B_TRANSLATE("OK"), NULL, NULL, |
| 637 | B_WIDTH_AS_USUAL, B_STOP_ALERT); |
| 638 | |
| 639 | alert->SetShortcut(0, B_ESCAPE); |
| 640 | alert->Go(); |
| 641 | |
630 | 642 | return B_ERROR; |
631 | 643 | } |
632 | 644 | } else if (!directoryEntry.IsDirectory()) { |
633 | 645 | // the entry exists but is not a directory. |
634 | 646 | // not much we can do |
635 | | return B_ERROR; |
| 647 | BString alertText; |
| 648 | alertText.SetToFormat(B_TRANSLATE("Error saving \"%s\":\n" |
| 649 | "The destination path exists but is not a folder."), |
| 650 | fNameControl->Text()); |
| 651 | |
| 652 | BAlert* alert = new BAlert("Error", alertText.String(), |
| 653 | B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); |
| 654 | |
| 655 | alert->SetShortcut(0, B_ESCAPE); |
| 656 | alert->Go(); |
| 657 | |
| 658 | return B_NOT_A_DIRECTORY; |
636 | 659 | } |
637 | 660 | |
638 | 661 | path.Append(fNameControl->Text()); |
… |
… |
ScreenshotWindow::_SaveScreenshot()
|
655 | 678 | return B_CANCELED; |
656 | 679 | } |
657 | 680 | |
658 | | return fUtility.Save(fScreenshot, path.Path(), fImageFileType); |
| 681 | status_t saveStatus = fUtility.Save(fScreenshot, |
| 682 | path.Path(), fImageFileType); |
| 683 | |
| 684 | if (saveStatus != B_OK) { |
| 685 | BString alertText; |
| 686 | alertText.SetToFormat(B_TRANSLATE("Error saving \"%s\":\n\t%s"), |
| 687 | fNameControl->Text(), strerror(saveStatus)); |
| 688 | |
| 689 | BAlert* alert = new BAlert("Error", alertText.String(), |
| 690 | B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); |
| 691 | |
| 692 | alert->SetShortcut(0, B_ESCAPE); |
| 693 | alert->Go(); |
| 694 | return B_ERROR; |
| 695 | } |
| 696 | return B_OK; |
659 | 697 | } |
660 | 698 | |
661 | 699 | |