@@ -44,37 +44,38 @@ bool saveToFilesystem(const QPixmap& capture,
4444 QString completePath = FileNameHandler ().properScreenshotPath (
4545 path, ConfigHandler ().saveAsFileExtension ());
4646 QFile file{ completePath };
47- file. open (QIODevice::WriteOnly) ;
47+ bool okay = false ;
4848
49- bool okay;
50- QString saveExtension;
51- saveExtension = QFileInfo (completePath).suffix ().toLower ();
52- if (saveExtension == " jpg" || saveExtension == " jpeg" ) {
53- okay = capture.save (&file, nullptr , ConfigHandler ().jpegQuality ());
54- } else {
55- okay = capture.save (&file);
56- }
49+ if (file. open (QIODevice::WriteOnly)) {
50+ QString saveExtension;
51+ saveExtension = QFileInfo (completePath).suffix ().toLower ();
52+ if (saveExtension == " jpg" || saveExtension == " jpeg" ) {
53+ okay = capture.save (&file, nullptr , ConfigHandler ().jpegQuality ());
54+ } else {
55+ okay = capture.save (&file);
56+ }
5757
58- QString saveMessage = messagePrefix;
59- QString notificationPath = completePath;
60- if (!saveMessage.isEmpty ()) {
61- saveMessage += " " ;
62- }
58+ QString saveMessage = messagePrefix;
59+ QString notificationPath = completePath;
60+ if (!saveMessage.isEmpty ()) {
61+ saveMessage += " " ;
62+ }
6363
64- if (okay) {
65- saveMessage += QObject::tr (" Capture saved as " ) + completePath;
66- AbstractLogger::info ().attachNotificationPath (notificationPath)
67- << saveMessage;
68- } else {
69- saveMessage += QObject::tr (" Error trying to save as " ) + completePath;
70- if (file.error () != QFile::NoError) {
71- saveMessage += " : " + file.errorString ();
64+ if (okay) {
65+ saveMessage += QObject::tr (" Capture saved as " ) + completePath;
66+ AbstractLogger::info ().attachNotificationPath (notificationPath)
67+ << saveMessage;
68+ } else {
69+ saveMessage +=
70+ QObject::tr (" Error trying to save as " ) + completePath;
71+ if (file.error () != QFile::NoError) {
72+ saveMessage += " : " + file.errorString ();
73+ }
74+ notificationPath = " " ;
75+ AbstractLogger::error ().attachNotificationPath (notificationPath)
76+ << saveMessage;
7277 }
73- notificationPath = " " ;
74- AbstractLogger::error ().attachNotificationPath (notificationPath)
75- << saveMessage;
7678 }
77-
7879 return okay;
7980}
8081
@@ -325,45 +326,47 @@ bool saveToFilesystemGUI(const QPixmap& capture)
325326 }
326327
327328 QFile file{ savePath };
328- file.open (QIODevice::WriteOnly);
329-
330- QString saveExtension;
331- saveExtension = QFileInfo (savePath).suffix ().toLower ();
332- if (saveExtension == " jpg" || saveExtension == " jpeg" ) {
333- okay = capture.save (&file, nullptr , ConfigHandler ().jpegQuality ());
334- } else {
335- okay = capture.save (&file);
336- }
329+ if (file.open (QIODevice::WriteOnly)) {
330+ QString saveExtension;
331+ saveExtension = QFileInfo (savePath).suffix ().toLower ();
332+ if (saveExtension == " jpg" || saveExtension == " jpeg" ) {
333+ okay = capture.save (&file, nullptr , ConfigHandler ().jpegQuality ());
334+ } else {
335+ okay = capture.save (&file);
336+ }
337337
338- if (okay) {
339- // Don't use QDir::separator() here, as Qt internally always uses '/'
340- QString pathNoFile = savePath.left (savePath.lastIndexOf (' /' ));
338+ if (okay) {
339+ // Don't use QDir::separator() here, as Qt internally always uses
340+ // '/'
341+ QString pathNoFile = savePath.left (savePath.lastIndexOf (' /' ));
341342
342- ConfigHandler ().setSavePath (pathNoFile);
343+ ConfigHandler ().setSavePath (pathNoFile);
343344
344- QString msg = QObject::tr (" Capture saved as " ) + savePath;
345- AbstractLogger ().attachNotificationPath (savePath) << msg;
345+ QString msg = QObject::tr (" Capture saved as " ) + savePath;
346+ AbstractLogger ().attachNotificationPath (savePath) << msg;
346347
347- if (config.copyPathAfterSave ()) {
348+ if (config.copyPathAfterSave ()) {
348349#ifdef Q_OS_WIN
349- savePath.replace (' /' , ' \\ ' );
350+ savePath.replace (' /' , ' \\ ' );
350351#endif
351- FlameshotDaemon::copyToClipboard (
352- savePath, QObject::tr (" Path copied to clipboard as " ) + savePath);
353- }
352+ FlameshotDaemon::copyToClipboard (
353+ savePath,
354+ QObject::tr (" Path copied to clipboard as " ) + savePath);
355+ }
354356
355- } else {
356- QString msg = QObject::tr (" Error trying to save as " ) + savePath;
357+ } else {
358+ QString msg = QObject::tr (" Error trying to save as " ) + savePath;
357359
358- if (file.error () != QFile::NoError) {
359- msg += " : " + file.errorString ();
360- }
360+ if (file.error () != QFile::NoError) {
361+ msg += " : " + file.errorString ();
362+ }
361363
362- QMessageBox saveErrBox (
363- QMessageBox::Warning, QObject::tr (" Save Error" ), msg);
364- saveErrBox.setWindowIcon (QIcon (GlobalValues::iconPath ()));
365- saveErrBox.exec ();
364+ QMessageBox saveErrBox (
365+ QMessageBox::Warning, QObject::tr (" Save Error" ), msg);
366+ saveErrBox.setWindowIcon (QIcon (GlobalValues::iconPath ()));
367+ saveErrBox.exec ();
368+ }
366369 }
367370
368371 return okay;
369- }
372+ }
0 commit comments