50#include <QRegularExpression>
52#include "RecentFiles.hh"
56namespace OpenFlipper {
60void addRecentFile(QString _file,
DataType _type) {
63 QStringList recentFiles = OpenFlipperSettings().
value(
"Core/File/RecentFiles", QStringList()).toStringList();
64 QStringList recentTypes = OpenFlipperSettings().
value(
"Core/File/RecentTypes", QStringList()).toStringList();
69 for (
int i = 0 ; i < recentFiles.size() ; ++i)
70 if ( _file == recentFiles[i] && type == recentTypes[i] ){
71 recentFiles.removeAt(i);
72 recentTypes.removeAt(i);
76 if ( recentFiles.size() >= OpenFlipperSettings().value(
"Core/File/MaxRecent",15).toInt() ) {
77 recentFiles.pop_back();
78 recentTypes.pop_back();
81 recentFiles.push_front(_file);
82 recentTypes.push_front(type);
84 OpenFlipperSettings().
setValue(
"Core/File/RecentFiles", recentFiles);
85 OpenFlipperSettings().
setValue(
"Core/File/RecentTypes", recentTypes);
88void rememberRecentItem(
const QString &propName,
const QString &itemName,
const int RECENT_ITEMS_MAX_SIZE) {
90 QStringList recentItems = OpenFlipperSettings().
value(propName, QStringList()).toStringList();
93 int position = recentItems.indexOf(QRegularExpression(QRegularExpression::escape(itemName)));
94 if (position != -1) recentItems.removeAt(position);
97 if (recentItems.size() >= RECENT_ITEMS_MAX_SIZE) recentItems.removeLast();
100 recentItems.push_front(itemName);
103 OpenFlipperSettings().
setValue(propName, recentItems);
106QStringList getRecentItems(
const QString &propName) {
107 return OpenFlipperSettings().
value(propName, QStringList()).toStringList();
110QString getMostRecentItem(
const QString &propName) {
111 QStringList sl = OpenFlipperSettings().
value(propName, QStringList()).toStringList();
112 if (sl.empty())
return QString();
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...