* Add error handling functions to ConfigHandler Refurbished functions setValue and value which were previously unused. These functions now set/get a setting with error handling. Currently recognizes only errors recognizable by QSettings. * Make use of value and setValue in ConfigHandler Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add checker for unrecognized general options Extraneous config options in [General] will be reported as errors. Added some placeholder functions to be implemented in future commits. * Introduce keysFromGroup function Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Check shortcut names for duplicates Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix notification spam Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Implement shortcut conflict checking Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix reading of fallbacks on error If there is a config error, some values would not be loaded correctly. Using the newly implemented function ConfigHandler::contains instead of QSettings::contains solves this issue. These changes reveal u bug that causes a crash on startup. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix crashes introduced in previous commit Because ConfigHandler is a dependency of most other classes, calling functions from those classes inside ConfigHandler caused infinite recursions in some cases. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add config file watcher Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add missing config options Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix bug in shortcut conflict detection Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add error resolved notification Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add GUI error message overlay Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add indicator in config window Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Use ConfigHandler::fileChanged in ConfigWindow Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix watcher sometimes not firing Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Improve config file watching performance Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add new way to handle config This is only a fundamental implementation. Future commits will replace everything with this new paradigm. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix getButtons and related functions Also refactored related code to use QList instead of QVector because QSettings does not work well with QVector. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Make good use of the new way * Implement proper checking for basic types Everything is covered, apart from KeySequence. * Move fallback path to ExistingDir value handler Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Use consistent naming scheme in ConfigHandler Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Implement config getters/setters via macro Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Surround text with tr and clang-format Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix colors being saved obfuscated Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add ValueHandler::represenation Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Move ValueHandler to separate files Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * confighandler.cpp: rename macro CUSTOM to OPTION Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix bug with shortcut conflict checker Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Update docs and fix setAllTheButtons Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Handle filenamePattern properly Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix failing build due to wrong function name Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix QSet error due to Qt version mismatch Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Replace QSharedPointer::get with data for older Qt versions Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix failing build on MacOS and ubuntu 18.04 Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add column headers to recognizedGeneralOptions map Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix ubuntu 18.04 error Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix false positive when shortcuts empty Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix wrong shortcut group prefix Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Implement proper shortcut checking Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add shortcut map in ConfigHandler Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Move ConfigShortcuts functions to ShortcutsWidget Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix minor bugs Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add fallback scheme: Pictures, HOME, TMP Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add config --check CLI option Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add config error log to GUI Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Rename ValueHandler::description to expected * Convert Qt's #AARRGGBB to #RRGGBBAA and vice versa Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Remove obsolete `saveAfterCopyPath` Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix errors in example config Also added an additional ; in front of actual comments to differentiate them from commented options. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Allow special value 'picker' in userColors Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Allow only name, #RRGGBB, and #RRGGBBAA color formats Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>
118 lines
3.6 KiB
C++
118 lines
3.6 KiB
C++
#include "history.h"
|
|
#include "src/utils/confighandler.h"
|
|
#include <QDir>
|
|
#include <QFile>
|
|
#include <QProcessEnvironment>
|
|
#include <QStringList>
|
|
|
|
History::History()
|
|
{
|
|
// Get cache history path
|
|
ConfigHandler config;
|
|
#ifdef Q_OS_WIN
|
|
m_historyPath = QDir::homePath() + "/AppData/Roaming/flameshot/history/";
|
|
#else
|
|
QString path = QProcessEnvironment::systemEnvironment().value(
|
|
"XDG_CACHE_HOME", QDir::homePath() + "/.cache");
|
|
m_historyPath = path + "/flameshot/history/";
|
|
#endif
|
|
|
|
// Check if directory for history exists and create if doesn't
|
|
QDir dir = QDir(m_historyPath);
|
|
if (!dir.exists())
|
|
dir.mkpath(".");
|
|
}
|
|
|
|
const QString& History::path()
|
|
{
|
|
return m_historyPath;
|
|
}
|
|
|
|
void History::save(const QPixmap& pixmap, const QString& fileName)
|
|
{
|
|
// scale preview only in local disk
|
|
QPixmap pixmapScaled = QPixmap(pixmap);
|
|
if (pixmap.height() / HISTORYPIXMAP_MAX_PREVIEW_HEIGHT >=
|
|
pixmap.width() / HISTORYPIXMAP_MAX_PREVIEW_WIDTH) {
|
|
pixmapScaled = pixmap.scaledToHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT,
|
|
Qt::SmoothTransformation);
|
|
} else {
|
|
pixmapScaled = pixmap.scaledToWidth(HISTORYPIXMAP_MAX_PREVIEW_WIDTH,
|
|
Qt::SmoothTransformation);
|
|
}
|
|
|
|
// save preview
|
|
QFile file(path() + fileName);
|
|
file.open(QIODevice::WriteOnly);
|
|
pixmapScaled.save(&file, "PNG");
|
|
|
|
history();
|
|
}
|
|
|
|
const QList<QString>& History::history()
|
|
{
|
|
QDir directory(path());
|
|
QStringList images = directory.entryList(QStringList() << "*.png"
|
|
<< "*.PNG",
|
|
QDir::Files,
|
|
QDir::Time);
|
|
int cnt = 0;
|
|
int max = ConfigHandler().uploadHistoryMax();
|
|
m_thumbs.clear();
|
|
foreach (QString fileName, images) {
|
|
if (++cnt <= max) {
|
|
m_thumbs.append(fileName);
|
|
} else {
|
|
QFile file(path() + fileName);
|
|
file.remove();
|
|
}
|
|
}
|
|
return m_thumbs;
|
|
}
|
|
|
|
const HISTORY_FILE_NAME& History::unpackFileName(const QString& fileNamePacked)
|
|
{
|
|
int nPathIndex = fileNamePacked.lastIndexOf("/");
|
|
QStringList unpackedFileName;
|
|
if (nPathIndex == -1) {
|
|
unpackedFileName = fileNamePacked.split("-");
|
|
} else {
|
|
unpackedFileName = fileNamePacked.mid(nPathIndex + 1).split("-");
|
|
}
|
|
|
|
switch (unpackedFileName.length()) {
|
|
case 3:
|
|
m_unpackedFileName.file = unpackedFileName[2];
|
|
m_unpackedFileName.token = unpackedFileName[1];
|
|
m_unpackedFileName.type = unpackedFileName[0];
|
|
break;
|
|
case 2:
|
|
m_unpackedFileName.file = unpackedFileName[1];
|
|
m_unpackedFileName.token = "";
|
|
m_unpackedFileName.type = unpackedFileName[0];
|
|
break;
|
|
default:
|
|
m_unpackedFileName.file = unpackedFileName[0];
|
|
m_unpackedFileName.token = "";
|
|
m_unpackedFileName.type = "";
|
|
break;
|
|
}
|
|
return m_unpackedFileName;
|
|
}
|
|
|
|
const QString& History::packFileName(const QString& storageType,
|
|
const QString& deleteToken,
|
|
const QString& fileName)
|
|
{
|
|
m_packedFileName = fileName;
|
|
if (storageType.length() > 0) {
|
|
if (deleteToken.length() > 0) {
|
|
m_packedFileName =
|
|
storageType + "-" + deleteToken + "-" + m_packedFileName;
|
|
} else {
|
|
m_packedFileName = storageType + "-" + m_packedFileName;
|
|
}
|
|
}
|
|
return m_packedFileName;
|
|
}
|