Added the ability to cache the last region (#2615)
* Added the ability to cache the last region * adding cli option * addressed typo comments and applied clang-format
This commit is contained in:
49
src/config/cacheutils.cpp
Normal file
49
src/config/cacheutils.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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;
|
||||
}
|
||||
Reference in New Issue
Block a user