Ticket #12945: 0001-Screenshot-better-error-handling-on-save.patch

File 0001-Screenshot-better-error-handling-on-save.patch, 2.6 KB (added by gbl08ma, 4 years ago)
  • src/apps/screenshot/ScreenshotWindow.cpp

    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()  
    626626    // necessary, for example, when the user selects the Artwork folder from
    627627    // the list of predefined folders.
    628628    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
    630642            return B_ERROR;
    631643        }
    632644    } else if (!directoryEntry.IsDirectory()) {
    633645        // the entry exists but is not a directory.
    634646        // 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;
    636659    }
    637660
    638661    path.Append(fNameControl->Text());
    ScreenshotWindow::_SaveScreenshot()  
    655678            return B_CANCELED;
    656679    }
    657680
    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;
    659697}
    660698
    661699