Files
flameshot/src/config/cacheutils.cpp
El Thoro f7e41f4d70 Cppcheck and clazy warning fixes (#2821)
* Cppcheck and clazy warning fixes

* Clang-format

* Revert QRect call by value

* Revert QPoint call by value

* Revert complained renamings

---------

Co-authored-by: Haris Gušić <harisgusic.dev@gmail.com>
2023-01-29 16:01:02 +01:00

50 lines
1.0 KiB
C++

// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2021 Jeremy Borgman
#include "cacheutils.h"
#include <QDataStream>
#include <QDir>
#include <QFile>
#include <QRect>
#include <QStandardPaths>
#include <QString>
QString getCachePath()
{
auto cachePath =
QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
if (!QDir(cachePath).exists()) {
QDir().mkpath(cachePath);
}
return cachePath;
}
void setLastRegion(QRect const& newRegion)
{
auto cachePath = getCachePath() + "/region.txt";
QFile file(cachePath);
if (file.open(QIODevice::WriteOnly)) {
QDataStream out(&file);
out << newRegion;
file.close();
}
}
QRect getLastRegion()
{
auto cachePath = getCachePath() + "/region.txt";
QFile file(cachePath);
QRect lastRegion;
if (file.open(QIODevice::ReadOnly)) {
QDataStream input(&file);
input >> lastRegion;
file.close();
} else {
lastRegion = QRect(0, 0, 0, 0);
}
return lastRegion;
}