mirror of
https://github.com/riuson/lcd-image-converter.git
synced 2026-03-24 17:06:59 +01:00
60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
#include "recentlist.h"
|
|
//-----------------------------------------------------------------------------
|
|
#include <QStringList>
|
|
#include <QStringListIterator>
|
|
#include <QSettings>
|
|
//-----------------------------------------------------------------------------
|
|
RecentList::RecentList(QObject *parent) :
|
|
QObject(parent)
|
|
{
|
|
this->mFiles = new QStringList();
|
|
|
|
// load from settings
|
|
QSettings sett;
|
|
int size = sett.beginReadArray("recent");
|
|
for (int i = 0; i < size; i++)
|
|
{
|
|
sett.setArrayIndex(i);
|
|
this->mFiles->append(sett.value("filename").toString());
|
|
}
|
|
sett.endArray();
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
RecentList::~RecentList()
|
|
{
|
|
// save to settings
|
|
QSettings sett;
|
|
sett.beginWriteArray("recent");
|
|
QStringListIterator recentFilesIterator(*this->mFiles);
|
|
int i = 0;
|
|
while (recentFilesIterator.hasNext())
|
|
{
|
|
sett.setArrayIndex(i++);
|
|
sett.setValue("filename", recentFilesIterator.next());
|
|
}
|
|
sett.endArray();
|
|
|
|
delete this->mFiles;
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
void RecentList::add(const QString &filename)
|
|
{
|
|
if (this->mFiles->contains(filename))
|
|
this->mFiles->removeOne(filename);
|
|
this->mFiles->insert(0, filename);
|
|
|
|
if (this->mFiles->count() > MaxRecentFiles)
|
|
{
|
|
for (int i = this->mFiles->count() - 1; i >= 10; i--)
|
|
this->mFiles->removeAt(i);
|
|
}
|
|
|
|
emit this->listChanged();
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
const QStringList * RecentList::files() const
|
|
{
|
|
return this->mFiles;
|
|
}
|
|
//-----------------------------------------------------------------------------
|