read only last 8 lines of history

This commit is contained in:
Niklas 2019-05-19 20:05:43 +02:00
parent 833002dff3
commit 880a6e7583

View File

@ -4,6 +4,7 @@
#include <io/ioutils.hpp> #include <io/ioutils.hpp>
#include <logs/screenshotfile.h> #include <logs/screenshotfile.h>
#include <utils.hpp> #include <utils.hpp>
#include <QTextCodec>
#include "mainwindow.hpp" #include "mainwindow.hpp"
@ -65,8 +66,20 @@ QList<LoggedRequest> requestlogging::getRequests() {
QFile requestFile(requestPath); QFile requestFile(requestPath);
if (!requestFile.exists() || !requestFile.open(QIODevice::ReadOnly)) return ret; if (!requestFile.exists() || !requestFile.open(QIODevice::ReadOnly)) return ret;
QByteArray line; QByteArray line;
requestFile.seek(requestFile.size());
long int pos = requestFile.pos();
int count = 0;
while(pos) {
requestFile.seek(--pos);
QString s = requestFile.read(1);
if(s == '\n') {
if(count++ == 8) break;
}
}
while ((line = requestFile.readLine()).size() != 0) { while ((line = requestFile.readLine()).size() != 0) {
LoggedRequest r; LoggedRequest r;
QTextStream stream(&line); QTextStream stream(&line);
@ -85,6 +98,8 @@ QList<LoggedRequest> requestlogging::getRequests() {
ret.append(r); ret.append(r);
} }
requestFile.close();
return ret; return ret;
} }