casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
logwatcher.qo.h
Go to the documentation of this file.
00001 //# Copyright (C) 2005
00002 //# Associated Universities, Inc. Washington DC, USA.
00003 //#
00004 //# This library is free software; you can redistribute it and/or modify it
00005 //# under the terms of the GNU Library General Public License as published by
00006 //# the Free Software Foundation; either version 2 of the License, or (at your
00007 //# option) any later version.
00008 //#
00009 //# This library is distributed in the hope that it will be useful, but WITHOUT
00010 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012 //# License for more details.
00013 //#
00014 //# You should have received a copy of the GNU Library General Public License
00015 //# along with this library; if not, write to the Free Software Foundation,
00016 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00017 //#
00018 //# Correspondence concerning AIPS++ should be addressed as follows:
00019 //#        Internet email: aips2-request@nrao.edu.
00020 //#        Postal address: AIPS++ Project Office
00021 //#                        National Radio Astronomy Observatory
00022 //#                        520 Edgemont Road
00023 //#                        Charlottesville, VA 22903-2475 USA
00024 //#
00025 //# $Id:  $
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       //qDebug() << "path=" << info.path() << " file=" << file;
00048       info.setCaching(false);
00049       dt = info.lastModified();
00050       //qDebug() << "dt=" << dt.toString();
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       QDateTime dlt = info.lastModified();
00061       //qDebug() << "dlt=" << dlt << " dt=" << dt; 
00062       if (dlt != dt) {
00063         dt = dlt;
00064         //qDebug() << "emit file changed";
00065         emit fileChanged(watchFile); 
00066       }
00067       */
00068       int sz = info.size(); 
00069       if (sz > size) {
00070         size = sz;
00071         //qDebug() << "emit file changed";
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