casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
logwatcher.qo.h
Go to the documentation of this file.
1 //# Copyright (C) 2005
2 //# Associated Universities, Inc. Washington DC, USA.
3 //#
4 //# This library is free software; you can redistribute it and/or modify it
5 //# under the terms of the GNU Library General Public License as published by
6 //# the Free Software Foundation; either version 2 of the License, or (at your
7 //# option) any later version.
8 //#
9 //# This library is distributed in the hope that it will be useful, but WITHOUT
10 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 //# License for more details.
13 //#
14 //# You should have received a copy of the GNU Library General Public License
15 //# along with this library; if not, write to the Free Software Foundation,
16 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
17 //#
18 //# Correspondence concerning AIPS++ should be addressed as follows:
19 //# Internet email: aips2-request@nrao.edu.
20 //# Postal address: AIPS++ Project Office
21 //# National Radio Astronomy Observatory
22 //# 520 Edgemont Road
23 //# Charlottesville, VA 22903-2475 USA
24 //#
25 //# $Id: $
26 
27 #ifndef LOGWATCHER_H
28 #define LOGWATCHER_H
29 
30 
31 #include <graphics/X11/X_enter.h>
32 #include <QDebug>
33 #include <QTimer>
34 #include <QDateTime>
35 #include <QFileInfo>
36 #include <graphics/X11/X_exit.h>
37 
38 namespace casa {
39 
40 class FileWatcher : public QObject {
41  Q_OBJECT
42 
43 public:
44  FileWatcher(QString &file):watchFile(file), size(0){
45  info.setFile(watchFile);
46  size = info.size();
47  //qDebug() << "path=" << info.path() << " file=" << file;
48  info.setCaching(false);
49  dt = info.lastModified();
50  //qDebug() << "dt=" << dt.toString();
51  QTimer* timer = new QTimer(this);
52  connect(timer, SIGNAL(timeout()), this, SLOT(update()));
53  timer->start(500);
54  }
56 public slots:
57  void update() {
58  info.refresh();
59  /*
60  QDateTime dlt = info.lastModified();
61  //qDebug() << "dlt=" << dlt << " dt=" << dt;
62  if (dlt != dt) {
63  dt = dlt;
64  //qDebug() << "emit file changed";
65  emit fileChanged(watchFile);
66  }
67  */
68  int sz = info.size();
69  if (sz > size) {
70  size = sz;
71  //qDebug() << "emit file changed";
72  emit fileChanged(watchFile);
73  }
74  }
75 signals:
76  void fileChanged(const QString &file);
77 private:
78  QString watchFile;
79  QDateTime dt;
80  QFileInfo info;
81  int size;
82 };
83 
84 
85 }
86 #endif
FileWatcher(QString &file)
Definition: logwatcher.qo.h:44
void fileChanged(const QString &file)
Defines nreal time structures used by the VLA table filler.
Definition: nreal.h:100