-rw-r--r-- | core/launcher/stabmon.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/core/launcher/stabmon.cpp b/core/launcher/stabmon.cpp index 3d0d534..4e5f290 100644 --- a/core/launcher/stabmon.cpp +++ b/core/launcher/stabmon.cpp | |||
@@ -1,92 +1,102 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | 21 | ||
22 | #include "stabmon.h" | 22 | #include "stabmon.h" |
23 | 23 | ||
24 | #include <qpe/qcopenvelope_qws.h> | 24 | #ifdef QWS |
25 | #include <qtopia/qcopenvelope_qws.h> | ||
26 | #endif | ||
25 | 27 | ||
26 | #include <qfile.h> | 28 | #include <qfile.h> |
27 | #include <qcstring.h> | 29 | #include <qcstring.h> |
28 | 30 | ||
29 | #include <sys/stat.h> | 31 | #include <sys/stat.h> |
32 | #if defined(Q_OS_LINUX) || defined(_OS_LINUX_) | ||
30 | #include <unistd.h> | 33 | #include <unistd.h> |
34 | #endif | ||
31 | #include <stdlib.h> | 35 | #include <stdlib.h> |
32 | 36 | ||
33 | SysFileMonitor::SysFileMonitor(QObject* parent) : | 37 | SysFileMonitor::SysFileMonitor(QObject* parent) : |
34 | QObject(parent) | 38 | QObject(parent) |
35 | { | 39 | { |
36 | startTimer(2000); | 40 | startTimer(2000); |
37 | } | 41 | } |
38 | 42 | ||
39 | const char * stab0 = "/var/run/stab"; | 43 | const char * stab0 = "/var/run/stab"; |
40 | const char * stab1 = "/var/state/pcmcia/stab"; | 44 | const char * stab1 = "/var/state/pcmcia/stab"; |
41 | const char * stab2 = "/var/lib/pcmcia/stab"; | 45 | const char * stab2 = "/var/lib/pcmcia/stab"; |
42 | 46 | ||
43 | void SysFileMonitor::timerEvent(QTimerEvent*) | 47 | void SysFileMonitor::timerEvent(QTimerEvent*) |
44 | { | 48 | { |
45 | struct stat s; | 49 | struct stat s; |
46 | 50 | ||
47 | static const char * tab [] = { | 51 | static const char * tab [] = { |
48 | stab0, | 52 | stab0, |
49 | stab1, | 53 | stab1, |
50 | stab2 | 54 | stab2 |
51 | }; | 55 | }; |
52 | static const int nstab = sizeof(tab)/sizeof(const char *); | 56 | static const int nstab = sizeof(tab)/sizeof(const char *); |
53 | static int last[nstab]; | 57 | static int last[nstab]; |
54 | 58 | ||
55 | bool ch = FALSE; | 59 | bool ch = FALSE; |
56 | for ( int i=0; i<nstab; i++ ) { | 60 | for ( int i=0; i<nstab; i++ ) { |
57 | if ( ::stat(tab[i], &s)==0 && (long)s.st_mtime != last[i] ) { | 61 | if ( ::stat(tab[i], &s)==0 && (long)s.st_mtime != last[i] ) { |
58 | last[i] = (long)s.st_mtime; | 62 | last[i] = (long)s.st_mtime; |
59 | ch=TRUE; | 63 | ch=TRUE; |
60 | } | 64 | } |
61 | if ( ch ) { | 65 | if ( ch ) { |
66 | #ifndef QT_NO_COP | ||
62 | QCopEnvelope("QPE/Card", "stabChanged()" ); | 67 | QCopEnvelope("QPE/Card", "stabChanged()" ); |
68 | #endif | ||
63 | break; | 69 | break; |
64 | } | 70 | } |
65 | } | 71 | } |
66 | 72 | ||
67 | // st_size is no use, it's 0 for /proc/mounts too. Read it all. | 73 | // st_size is no use, it's 0 for /proc/mounts too. Read it all. |
68 | static int mtabSize = 0; | 74 | static int mtabSize = 0; |
69 | QFile f( "/proc/mounts" ); | 75 | QFile f( "/proc/mounts" ); |
70 | if ( f.open(IO_ReadOnly) ) { | 76 | if ( f.open(IO_ReadOnly) ) { |
71 | #if 0 | 77 | #if 0 |
72 | // readAll does not work correctly on sequential devices (as eg. /proc files) | 78 | // readAll does not work correctly on sequential devices (as eg. /proc files) |
73 | QByteArray ba = f.readAll(); | 79 | QByteArray ba = f.readAll(); |
74 | if ( (int)ba.size() != mtabSize ) { | 80 | if ( (int)ba.size() != mtabSize ) { |
75 | mtabSize = (int)ba.size(); | 81 | mtabSize = (int)ba.size(); |
82 | #ifndef QT_NO_COP | ||
76 | QCopEnvelope("QPE/Card", "mtabChanged()" ); | 83 | QCopEnvelope("QPE/Card", "mtabChanged()" ); |
84 | #endif | ||
77 | } | 85 | } |
78 | #else | 86 | #else |
79 | QString s; | 87 | QString s; |
80 | while( !f.atEnd() ) { | 88 | while( !f.atEnd() ) { |
81 | QString tmp; | 89 | QString tmp; |
82 | f.readLine( tmp, 1024 ); | 90 | f.readLine( tmp, 1024 ); |
83 | s += tmp; | 91 | s += tmp; |
84 | } | 92 | } |
85 | if ( (int)s.length() != mtabSize ) { | 93 | if ( (int)s.length() != mtabSize ) { |
86 | mtabSize = (int)s.length(); | 94 | mtabSize = (int)s.length(); |
95 | #ifndef QT_NO_COP | ||
87 | QCopEnvelope("QPE/Card", "mtabChanged()" ); | 96 | QCopEnvelope("QPE/Card", "mtabChanged()" ); |
97 | #endif | ||
88 | } | 98 | } |
89 | #endif | 99 | #endif |
90 | } | 100 | } |
91 | } | 101 | } |
92 | 102 | ||