Ticket #12945: Squashed-commit-of-the-following.patch

File Squashed-commit-of-the-following.patch, 3.2 KB (added by gbl08ma, 4 years ago)
  • src/apps/screenshot/ScreenshotWindow.cpp

    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()  
    608608}
    609609
    610610
     611void
     612ScreenshotWindow::_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
    611626status_t
    612627ScreenshotWindow::_SaveScreenshot()
    613628{
    ScreenshotWindow::_SaveScreenshot()  
    626641    // necessary, for example, when the user selects the Artwork folder from
    627642    // the list of predefined folders.
    628643    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;
    631649        }
    632650    } else if (!directoryEntry.IsDirectory()) {
    633651        // the entry exists but is not a directory.
    634652        // 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;
    636657    }
    637658
    638659    path.Append(fNameControl->Text());
    ScreenshotWindow::_SaveScreenshot()  
    655676            return B_CANCELED;
    656677    }
    657678
    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;
    659687}
    660688
    661689
  • src/apps/screenshot/ScreenshotWindow.h

    diff --git a/src/apps/screenshot/ScreenshotWindow.h b/src/apps/screenshot/ScreenshotWindow.h
    index cdb0148..0db27ff 100644
    a b private:  
    5050                                uint32 shortcutKey = 0);
    5151            void            _UpdateFilenameSelection();
    5252            void            _SetupTranslatorMenu();
     53            void            _DisplaySaveError(BString _message);
    5354            status_t        _SaveScreenshot();
    5455            void            _ShowSettings(bool activate);
    5556            BString         _FindValidFileName(const char* name);