00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "stabmon.h"
00023
00024 #ifdef QWS
00025 #include <qtopia/qcopenvelope_qws.h>
00026 #endif
00027
00028 #include <qfile.h>
00029
00030 #include <sys/stat.h>
00031 #if defined(Q_OS_LINUX) || defined(_OS_LINUX_)
00032 #include <unistd.h>
00033 #endif
00034 #include <stdlib.h>
00035
00036 SysFileMonitor::SysFileMonitor(QObject* parent) :
00037 QObject(parent)
00038 {
00039 startTimer(2000);
00040 }
00041
00042 const char * stab0 = "/var/run/stab";
00043 const char * stab1 = "/var/state/pcmcia/stab";
00044 const char * stab2 = "/var/lib/pcmcia/stab";
00045
00046 void SysFileMonitor::timerEvent(QTimerEvent*)
00047 {
00048 struct stat s;
00049
00050 static const char * tab [] = {
00051 stab0,
00052 stab1,
00053 stab2
00054 };
00055 static const int nstab = sizeof(tab)/sizeof(const char *);
00056 static int last[nstab];
00057
00058 bool ch = FALSE;
00059 for ( int i=0; i<nstab; i++ ) {
00060 if ( ::stat(tab[i], &s)==0 && (long)s.st_mtime != last[i] ) {
00061 last[i] = (long)s.st_mtime;
00062 ch=TRUE;
00063 }
00064 if ( ch ) {
00065 #ifndef QT_NO_COP
00066 QCopEnvelope("QPE/Card", "stabChanged()" );
00067 #endif
00068 break;
00069 }
00070 }
00071
00072
00073 static int mtabSize = 0;
00074 QFile f( "/proc/mounts" );
00075 if ( f.open(IO_ReadOnly) ) {
00076 #if 0
00077
00078 QByteArray ba = f.readAll();
00079 if ( (int)ba.size() != mtabSize ) {
00080 mtabSize = (int)ba.size();
00081 #ifndef QT_NO_COP
00082 QCopEnvelope("QPE/Card", "mtabChanged()" );
00083 #endif
00084 }
00085 #else
00086 QString s;
00087 while( !f.atEnd() ) {
00088 QString tmp;
00089 f.readLine( tmp, 1024 );
00090 s += tmp;
00091 }
00092 if ( (int)s.length() != mtabSize ) {
00093 mtabSize = (int)s.length();
00094 #ifndef QT_NO_COP
00095 QCopEnvelope("QPE/Card", "mtabChanged()" );
00096 #endif
00097 }
00098 #endif
00099 }
00100 }
00101