Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef CHATLOG_H
- #define CHATLOG_H
- #include <QThread>
- #include <QFile>
- #include <QStringList>
- #include <QFile>
- #include <QRegExp>
- #include <QSettings>
- class QChatlog : public QThread
- {
- Q_OBJECT
- public:
- explicit QChatlog(QObject *parent = 0);
- ~QChatlog();
- bool KillThread();
- void GetLines();
- signals:
- void OnMedicHeal(QString Medic,int Price);
- void OnHotdog(QString Seller,int Price);
- void OnLineRead(QString Line);
- protected:
- void run();
- private:
- void DecomposeLine(QString Line);
- bool BreakThread;
- int LineCount;
- QStringList ChatlogLines;
- QFile * Chatlog;
- };
- #endif // CHATLOG_H
- #include "Chatlog.h"
- QChatlog::QChatlog(QObject *parent) : QThread(parent), BreakThread(false), LineCount(0)
- {
- QSettings settings(QSettings::UserScope, "Microsoft", "Windows");
- settings.beginGroup("CurrentVersion/Explorer/Shell Folders");
- QString Path = settings.value("Personal").toString();
- Path.append("\\GTA San Andreas User Files\\SAMP\\chatlog.txt");
- Chatlog=new QFile(Path);
- ChatlogLines.clear();
- Chatlog->open(QIODevice::ReadOnly | QIODevice::Text);
- GetLines();
- start();
- }
- QChatlog::~QChatlog()
- {
- KillThread();
- ChatlogLines.clear();
- Chatlog->close();
- delete Chatlog;
- }
- void QChatlog::run()
- {
- while(!BreakThread)
- {
- this->msleep(500);
- int OldLineCount=LineCount;
- GetLines();
- for(int i=OldLineCount;i<LineCount;i++)
- DecomposeLine(this->ChatlogLines.at(i));
- }
- return;
- }
- void QChatlog::GetLines()
- {
- while(!Chatlog->atEnd())
- {
- LineCount++;
- ChatlogLines.append(Chatlog->readLine());
- }
- }
- bool QChatlog::KillThread()
- {
- if(!isRunning()) return false;
- BreakThread=true;
- terminate();
- wait();
- BreakThread=false;
- return isFinished();
- }
- void QChatlog::DecomposeLine(QString Line)
- {
- if(Line.indexOf("bietet dir eine Heilung für")!=-1)
- {
- QRegExp r("(.*)Arzt (\\w+)(.*)\\$(\\d+)(.*)");
- if(r.indexIn(Line)!=-1)
- emit OnMedicHeal(r.cap(2),r.cap(4).toInt());
- }
- else if(Line.indexOf("bietet dir einen Hotdog für")!=-1)
- {
- QRegExp r("(.*)Verkäufer (\\w+)(.*)\\$(\\d+)(.*)");
- if(r.indexIn(Line)!=-1)
- emit OnHotdog(r.cap(2),r.cap(4).toInt());
- }
- else emit OnLineRead(Line);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement