-
Notifications
You must be signed in to change notification settings - Fork 0
/
intelchannellogparser.cpp
92 lines (80 loc) · 2.68 KB
/
intelchannellogparser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "intelchannellogparser.h"
#include "provitel.h"
#include <QDebug>
#include <QStandardPaths>
#include <QMessageBox>
#include <QTimer>
#include <QFile>
#include <QThread>
#include <QtConcurrent/QtConcurrentRun>
#include <QCoreApplication>
IntelChannelLogParser::IntelChannelLogParser(ProviTel *parent, QString name, QString file)
{
proviTel = parent;
this->initialSetup = true;
this->name = name;
this->latestIntel = "";
this->exitThread = false;
fileLocation = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/EVE/logs/Chatlogs/" + file;
connect(this, SIGNAL(intelFound(QString, QString)), proviTel, SLOT(processIntel(QString, QString)));
QtConcurrent::run(this,&IntelChannelLogParser::checkIntel);
QObject::connect(QCoreApplication::instance(), SIGNAL(lastWindowClosed()), this, SLOT(quit()));
}
QString IntelChannelLogParser::getName()
{
return name;
}
void IntelChannelLogParser::checkIntel()
{
while(!exitThread){
QFile inputFile(fileLocation);
if (inputFile.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile);
bool newIntel = false;
while (!in.atEnd())
{
QString newLine = in.readLine();
if(in.atEnd())
{
if(latestIntel.compare("") == 0 || latestIntel.compare(newLine) != 0)
{
latestIntel = newLine;
if(!initialSetup)
{
//qDebug() << getName() << " " << latestIntel.toStdString().c_str();
transferIntel(latestIntel.toStdString().c_str());
}
}
}
else{
if(newIntel)
{
//latestIntel = newLine;
if(!initialSetup)
{
//qDebug() << getName() << " " << newLine.toStdString().c_str();
transferIntel(newLine.toStdString().c_str());
}
}
else if(latestIntel.compare(newLine) == 0)
{
newIntel = true;
}
}
}
inputFile.close();
}
initialSetup = false;
QThread::msleep(1500);
}
//QTimer::singleShot(1500, this, SLOT(checkIntel()));
}
void IntelChannelLogParser::transferIntel(QString intel)
{
emit intelFound(this->getName(), intel);
}
void IntelChannelLogParser::quit() {
exitThread = true;
qDebug() << "Thread exiting";
}