From 847566fef90370058c9a548257b2c0e48478ee5d Mon Sep 17 00:00:00 2001
From: Gabriel Maia <gbl08ma@gmail.com>
Date: Sun, 22 Jan 2017 00:32:52 +0000
Subject: [PATCH] Squashed commit of the following:
commit b3be8f4145f928535925bd784f7258420640519f
Author: Gabriel Maia <gbl08ma@gmail.com>
Date: Sun Jan 22 00:21:12 2017 +0000
Screenshot: clean up error handling code
commit c66219c9b88b342d0ae8b88538e5e320e73ab755
Author: Gabriel Maia <gbl08ma@gmail.com>
Date: Wed Sep 7 11:43:03 2016 +0000
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 | 36 ++++++++++++++++++++++++++++----
src/apps/screenshot/ScreenshotWindow.h | 1 +
2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/src/apps/screenshot/ScreenshotWindow.cpp b/src/apps/screenshot/ScreenshotWindow.cpp
index 58a6df3..ecfcd4b 100644
a
|
b
|
ScreenshotWindow::_SetupTranslatorMenu()
|
608 | 608 | } |
609 | 609 | |
610 | 610 | |
| 611 | void |
| 612 | ScreenshotWindow::_DisplaySaveError(BString _message) { |
| 613 | BString alertText; |
| 614 | alertText.SetToFormat(B_TRANSLATE("Error saving \"%s\":\n\t%s"), |
| 615 | fNameControl->Text(), _message.String()); |
| 616 | |
| 617 | BAlert* alert = new BAlert(B_TRANSLATE("Failed to save screenshot"), |
| 618 | alertText.String(), B_TRANSLATE("OK"), |
| 619 | NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); |
| 620 | |
| 621 | alert->SetShortcut(0, B_ESCAPE); |
| 622 | alert->Go(); |
| 623 | } |
| 624 | |
| 625 | |
611 | 626 | status_t |
612 | 627 | ScreenshotWindow::_SaveScreenshot() |
613 | 628 | { |
… |
… |
ScreenshotWindow::_SaveScreenshot()
|
626 | 641 | // necessary, for example, when the user selects the Artwork folder from |
627 | 642 | // the list of predefined folders. |
628 | 643 | if (!directoryEntry.Exists()) { |
629 | | if (create_directory(path.Path(), 0755) != B_OK) { |
630 | | return B_ERROR; |
| 644 | status_t directoryCreateStatus = create_directory(path.Path(), 0755); |
| 645 | if (directoryCreateStatus != B_OK) { |
| 646 | _DisplaySaveError(strerror(directoryCreateStatus)); |
| 647 | |
| 648 | return directoryCreateStatus; |
631 | 649 | } |
632 | 650 | } else if (!directoryEntry.IsDirectory()) { |
633 | 651 | // the entry exists but is not a directory. |
634 | 652 | // not much we can do |
635 | | return B_ERROR; |
| 653 | _DisplaySaveError( |
| 654 | B_TRANSLATE("The destination path exists but is not a folder.")); |
| 655 | |
| 656 | return B_NOT_A_DIRECTORY; |
636 | 657 | } |
637 | 658 | |
638 | 659 | path.Append(fNameControl->Text()); |
… |
… |
ScreenshotWindow::_SaveScreenshot()
|
655 | 676 | return B_CANCELED; |
656 | 677 | } |
657 | 678 | |
658 | | return fUtility.Save(fScreenshot, path.Path(), fImageFileType); |
| 679 | status_t saveStatus = fUtility.Save(fScreenshot, |
| 680 | path.Path(), fImageFileType); |
| 681 | |
| 682 | if (saveStatus != B_OK) { |
| 683 | _DisplaySaveError(strerror(saveStatus)); |
| 684 | return saveStatus; |
| 685 | } |
| 686 | return B_OK; |
659 | 687 | } |
660 | 688 | |
661 | 689 | |
diff --git a/src/apps/screenshot/ScreenshotWindow.h b/src/apps/screenshot/ScreenshotWindow.h
index cdb0148..0db27ff 100644
a
|
b
|
private:
|
50 | 50 | uint32 shortcutKey = 0); |
51 | 51 | void _UpdateFilenameSelection(); |
52 | 52 | void _SetupTranslatorMenu(); |
| 53 | void _DisplaySaveError(BString _message); |
53 | 54 | status_t _SaveScreenshot(); |
54 | 55 | void _ShowSettings(bool activate); |
55 | 56 | BString _FindValidFileName(const char* name); |