Skip to content

Commit 7ed3cfc

Browse files
cleanup compiler warnings due to Qt function labeling return value no… (flameshot-org#4415)
* cleanup compiler warnings due to Qt function labeling return value nodiscard * clang format
1 parent 279adc7 commit 7ed3cfc

File tree

4 files changed

+69
-65
lines changed

4 files changed

+69
-65
lines changed

src/core/flameshot.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,10 @@ void Flameshot::exportCapture(const QPixmap& capture,
382382
QByteArray byteArray;
383383
QBuffer buffer(&byteArray);
384384
capture.save(&buffer, "PNG");
385-
QFile file;
386-
file.open(stdout, QIODevice::WriteOnly);
387-
388-
file.write(byteArray);
389-
file.close();
385+
if (QFile file; file.open(stdout, QIODevice::WriteOnly)) {
386+
file.write(byteArray);
387+
file.close();
388+
}
390389
}
391390

392391
if (tasks & CR::SAVE) {

src/utils/confighandler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,9 @@ void ConfigHandler::ensureFileWatched() const
749749
{
750750
QFile file(m_settings.fileName());
751751
if (!file.exists()) {
752-
file.open(QFileDevice::WriteOnly);
753-
file.close();
752+
if (file.open(QFileDevice::WriteOnly)) {
753+
file.close();
754+
}
754755
}
755756
if (m_configWatcher != nullptr && m_configWatcher->files().isEmpty() &&
756757
qApp != nullptr // ensures that the organization name can be accessed

src/utils/history.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ void History::save(const QPixmap& pixmap, const QString& fileName)
4444

4545
// save preview
4646
QFile file(path() + fileName);
47-
file.open(QIODevice::WriteOnly);
48-
pixmapScaled.save(&file, "PNG");
47+
if (file.open(QIODevice::WriteOnly)) {
48+
pixmapScaled.save(&file, "PNG");
49+
}
4950

5051
history();
5152
}

src/utils/screenshotsaver.cpp

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)