logwatcher.qo.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef LOGWATCHER_H
00028 #define LOGWATCHER_H
00029
00030
00031 #include <graphics/X11/X_enter.h>
00032 #include <QDebug>
00033 #include <QTimer>
00034 #include <QDateTime>
00035 #include <QFileInfo>
00036 #include <graphics/X11/X_exit.h>
00037
00038 namespace casa {
00039
00040 class FileWatcher : public QObject {
00041 Q_OBJECT
00042
00043 public:
00044 FileWatcher(QString &file):watchFile(file), size(0){
00045 info.setFile(watchFile);
00046 size = info.size();
00047
00048 info.setCaching(false);
00049 dt = info.lastModified();
00050
00051 QTimer* timer = new QTimer(this);
00052 connect(timer, SIGNAL(timeout()), this, SLOT(update()));
00053 timer->start(500);
00054 }
00055 ~FileWatcher(){}
00056 public slots:
00057 void update() {
00058 info.refresh();
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 int sz = info.size();
00069 if (sz > size) {
00070 size = sz;
00071
00072 emit fileChanged(watchFile);
00073 }
00074 }
00075 signals:
00076 void fileChanged(const QString &file);
00077 private:
00078 QString watchFile;
00079 QDateTime dt;
00080 QFileInfo info;
00081 int size;
00082 };
00083
00084
00085 }
00086 #endif