Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/core/flameshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,10 @@ void Flameshot::exportCapture(const QPixmap& capture,
QByteArray byteArray;
QBuffer buffer(&byteArray);
capture.save(&buffer, "PNG");
QFile file;
file.open(stdout, QIODevice::WriteOnly);

file.write(byteArray);
file.close();
if (QFile file; file.open(stdout, QIODevice::WriteOnly)) {
file.write(byteArray);
file.close();
}
}

if (tasks & CR::SAVE) {
Expand Down
5 changes: 3 additions & 2 deletions src/utils/confighandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,9 @@ void ConfigHandler::ensureFileWatched() const
{
QFile file(m_settings.fileName());
if (!file.exists()) {
file.open(QFileDevice::WriteOnly);
file.close();
if (file.open(QFileDevice::WriteOnly)) {
file.close();
}
}
if (m_configWatcher != nullptr && m_configWatcher->files().isEmpty() &&
qApp != nullptr // ensures that the organization name can be accessed
Expand Down
5 changes: 3 additions & 2 deletions src/utils/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ void History::save(const QPixmap& pixmap, const QString& fileName)

// save preview
QFile file(path() + fileName);
file.open(QIODevice::WriteOnly);
pixmapScaled.save(&file, "PNG");
if (file.open(QIODevice::WriteOnly)) {
pixmapScaled.save(&file, "PNG");
}

history();
}
Expand Down
115 changes: 59 additions & 56 deletions src/utils/screenshotsaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,38 @@ bool saveToFilesystem(const QPixmap& capture,
QString completePath = FileNameHandler().properScreenshotPath(
path, ConfigHandler().saveAsFileExtension());
QFile file{ completePath };
file.open(QIODevice::WriteOnly);
bool okay = false;

bool okay;
QString saveExtension;
saveExtension = QFileInfo(completePath).suffix().toLower();
if (saveExtension == "jpg" || saveExtension == "jpeg") {
okay = capture.save(&file, nullptr, ConfigHandler().jpegQuality());
} else {
okay = capture.save(&file);
}
if (file.open(QIODevice::WriteOnly)) {
QString saveExtension;
saveExtension = QFileInfo(completePath).suffix().toLower();
if (saveExtension == "jpg" || saveExtension == "jpeg") {
okay = capture.save(&file, nullptr, ConfigHandler().jpegQuality());
} else {
okay = capture.save(&file);
}

QString saveMessage = messagePrefix;
QString notificationPath = completePath;
if (!saveMessage.isEmpty()) {
saveMessage += " ";
}
QString saveMessage = messagePrefix;
QString notificationPath = completePath;
if (!saveMessage.isEmpty()) {
saveMessage += " ";
}

if (okay) {
saveMessage += QObject::tr("Capture saved as ") + completePath;
AbstractLogger::info().attachNotificationPath(notificationPath)
<< saveMessage;
} else {
saveMessage += QObject::tr("Error trying to save as ") + completePath;
if (file.error() != QFile::NoError) {
saveMessage += ": " + file.errorString();
if (okay) {
saveMessage += QObject::tr("Capture saved as ") + completePath;
AbstractLogger::info().attachNotificationPath(notificationPath)
<< saveMessage;
} else {
saveMessage +=
QObject::tr("Error trying to save as ") + completePath;
if (file.error() != QFile::NoError) {
saveMessage += ": " + file.errorString();
}
notificationPath = "";
AbstractLogger::error().attachNotificationPath(notificationPath)
<< saveMessage;
}
notificationPath = "";
AbstractLogger::error().attachNotificationPath(notificationPath)
<< saveMessage;
}

return okay;
}

Expand Down Expand Up @@ -325,45 +326,47 @@ bool saveToFilesystemGUI(const QPixmap& capture)
}

QFile file{ savePath };
file.open(QIODevice::WriteOnly);

QString saveExtension;
saveExtension = QFileInfo(savePath).suffix().toLower();
if (saveExtension == "jpg" || saveExtension == "jpeg") {
okay = capture.save(&file, nullptr, ConfigHandler().jpegQuality());
} else {
okay = capture.save(&file);
}
if (file.open(QIODevice::WriteOnly)) {
QString saveExtension;
saveExtension = QFileInfo(savePath).suffix().toLower();
if (saveExtension == "jpg" || saveExtension == "jpeg") {
okay = capture.save(&file, nullptr, ConfigHandler().jpegQuality());
} else {
okay = capture.save(&file);
}

if (okay) {
// Don't use QDir::separator() here, as Qt internally always uses '/'
QString pathNoFile = savePath.left(savePath.lastIndexOf('/'));
if (okay) {
// Don't use QDir::separator() here, as Qt internally always uses
// '/'
QString pathNoFile = savePath.left(savePath.lastIndexOf('/'));

ConfigHandler().setSavePath(pathNoFile);
ConfigHandler().setSavePath(pathNoFile);

QString msg = QObject::tr("Capture saved as ") + savePath;
AbstractLogger().attachNotificationPath(savePath) << msg;
QString msg = QObject::tr("Capture saved as ") + savePath;
AbstractLogger().attachNotificationPath(savePath) << msg;

if (config.copyPathAfterSave()) {
if (config.copyPathAfterSave()) {
#ifdef Q_OS_WIN
savePath.replace('/', '\\');
savePath.replace('/', '\\');
#endif
FlameshotDaemon::copyToClipboard(
savePath, QObject::tr("Path copied to clipboard as ") + savePath);
}
FlameshotDaemon::copyToClipboard(
savePath,
QObject::tr("Path copied to clipboard as ") + savePath);
}

} else {
QString msg = QObject::tr("Error trying to save as ") + savePath;
} else {
QString msg = QObject::tr("Error trying to save as ") + savePath;

if (file.error() != QFile::NoError) {
msg += ": " + file.errorString();
}
if (file.error() != QFile::NoError) {
msg += ": " + file.errorString();
}

QMessageBox saveErrBox(
QMessageBox::Warning, QObject::tr("Save Error"), msg);
saveErrBox.setWindowIcon(QIcon(GlobalValues::iconPath()));
saveErrBox.exec();
QMessageBox saveErrBox(
QMessageBox::Warning, QObject::tr("Save Error"), msg);
saveErrBox.setWindowIcon(QIcon(GlobalValues::iconPath()));
saveErrBox.exec();
}
}

return okay;
}
}
4 changes: 3 additions & 1 deletion src/widgets/capture/capturewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,9 @@ void CaptureWidget::mouseDoubleClickEvent(QMouseEvent* event)
drawToolsData();
updateLayersPanel();
handleToolSignal(CaptureTool::REQ_ADD_CHILD_WIDGET);
m_panel->setToolWidget(m_activeTool->configurationWidget());
if (!m_activeTool.isNull()) {
m_panel->setToolWidget(m_activeTool->configurationWidget());
}
}
} else if (m_selection->geometry().contains(event->pos())) {
if ((event->button() == Qt::LeftButton) &&
Expand Down
Loading