-rw-r--r-- | library/alarmserver.cpp | 5 |
1 files changed, 0 insertions, 5 deletions
diff --git a/library/alarmserver.cpp b/library/alarmserver.cpp index 6f6f32d..48ab9c1 100644 --- a/library/alarmserver.cpp +++ b/library/alarmserver.cpp | |||
@@ -1,125 +1,120 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the 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 | #include <qdir.h> | 21 | #include <qdir.h> |
22 | #include <qfile.h> | ||
23 | #include <qmessagebox.h> | ||
24 | #include <qtextstream.h> | ||
25 | 22 | ||
26 | 23 | ||
27 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
28 | #include "global.h" | ||
29 | #include "resource.h" | ||
30 | 25 | ||
31 | #include <qpe/qcopenvelope_qws.h> | 26 | #include <qpe/qcopenvelope_qws.h> |
32 | #include "alarmserver.h" | 27 | #include "alarmserver.h" |
33 | #include <qpe/timeconversion.h> | 28 | #include <qpe/timeconversion.h> |
34 | 29 | ||
35 | #include <sys/types.h> | 30 | #include <sys/types.h> |
36 | #include <sys/stat.h> | 31 | #include <sys/stat.h> |
37 | 32 | ||
38 | #include <stdlib.h> | 33 | #include <stdlib.h> |
39 | #include <unistd.h> | 34 | #include <unistd.h> |
40 | 35 | ||
41 | 36 | ||
42 | #undef USE_ATD // not used anymore -- we run opie-alarm on suspend/resume | 37 | #undef USE_ATD // not used anymore -- we run opie-alarm on suspend/resume |
43 | 38 | ||
44 | 39 | ||
45 | struct timerEventItem | 40 | struct timerEventItem |
46 | { | 41 | { |
47 | time_t UTCtime; | 42 | time_t UTCtime; |
48 | QCString channel, message; | 43 | QCString channel, message; |
49 | int data; | 44 | int data; |
50 | bool operator==( const timerEventItem &right ) const | 45 | bool operator==( const timerEventItem &right ) const |
51 | { | 46 | { |
52 | return ( UTCtime == right.UTCtime | 47 | return ( UTCtime == right.UTCtime |
53 | && channel == right.channel | 48 | && channel == right.channel |
54 | && message == right.message | 49 | && message == right.message |
55 | && data == right.data ); | 50 | && data == right.data ); |
56 | } | 51 | } |
57 | }; | 52 | }; |
58 | 53 | ||
59 | class TimerReceiverObject : public QObject | 54 | class TimerReceiverObject : public QObject |
60 | { | 55 | { |
61 | public: | 56 | public: |
62 | TimerReceiverObject() | 57 | TimerReceiverObject() |
63 | { } | 58 | { } |
64 | ~TimerReceiverObject() | 59 | ~TimerReceiverObject() |
65 | { } | 60 | { } |
66 | void resetTimer(); | 61 | void resetTimer(); |
67 | void setTimerEventItem(); | 62 | void setTimerEventItem(); |
68 | void deleteTimer(); | 63 | void deleteTimer(); |
69 | protected: | 64 | protected: |
70 | void timerEvent( QTimerEvent *te ); | 65 | void timerEvent( QTimerEvent *te ); |
71 | 66 | ||
72 | #ifdef USE_ATD | 67 | #ifdef USE_ATD |
73 | private: | 68 | private: |
74 | QString atfilename; | 69 | QString atfilename; |
75 | #endif | 70 | #endif |
76 | }; | 71 | }; |
77 | 72 | ||
78 | TimerReceiverObject *timerEventReceiver = NULL; | 73 | TimerReceiverObject *timerEventReceiver = NULL; |
79 | QList<timerEventItem> timerEventList; | 74 | QList<timerEventItem> timerEventList; |
80 | timerEventItem *nearestTimerEvent = NULL; | 75 | timerEventItem *nearestTimerEvent = NULL; |
81 | 76 | ||
82 | 77 | ||
83 | // set the timer to go off on the next event in the list | 78 | // set the timer to go off on the next event in the list |
84 | void setNearestTimerEvent() | 79 | void setNearestTimerEvent() |
85 | { | 80 | { |
86 | nearestTimerEvent = NULL; | 81 | nearestTimerEvent = NULL; |
87 | QListIterator<timerEventItem> it( timerEventList ); | 82 | QListIterator<timerEventItem> it( timerEventList ); |
88 | if ( *it ) | 83 | if ( *it ) |
89 | nearestTimerEvent = *it; | 84 | nearestTimerEvent = *it; |
90 | for ( ; *it; ++it ) | 85 | for ( ; *it; ++it ) |
91 | if ( (*it)->UTCtime < nearestTimerEvent->UTCtime ) | 86 | if ( (*it)->UTCtime < nearestTimerEvent->UTCtime ) |
92 | nearestTimerEvent = *it; | 87 | nearestTimerEvent = *it; |
93 | if (nearestTimerEvent) | 88 | if (nearestTimerEvent) |
94 | timerEventReceiver->resetTimer(); | 89 | timerEventReceiver->resetTimer(); |
95 | else | 90 | else |
96 | timerEventReceiver->deleteTimer(); | 91 | timerEventReceiver->deleteTimer(); |
97 | } | 92 | } |
98 | 93 | ||
99 | 94 | ||
100 | //store current state to file | 95 | //store current state to file |
101 | //Simple implementation. Should run on a timer. | 96 | //Simple implementation. Should run on a timer. |
102 | 97 | ||
103 | static void saveState() | 98 | static void saveState() |
104 | { | 99 | { |
105 | QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" ); | 100 | QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" ); |
106 | if ( timerEventList.isEmpty() ) { | 101 | if ( timerEventList.isEmpty() ) { |
107 | unlink( savefilename ); | 102 | unlink( savefilename ); |
108 | return ; | 103 | return ; |
109 | } | 104 | } |
110 | 105 | ||
111 | QFile savefile(savefilename + ".new"); | 106 | QFile savefile(savefilename + ".new"); |
112 | if ( savefile.open(IO_WriteOnly) ) { | 107 | if ( savefile.open(IO_WriteOnly) ) { |
113 | QDataStream ds( &savefile ); | 108 | QDataStream ds( &savefile ); |
114 | 109 | ||
115 | //save | 110 | //save |
116 | 111 | ||
117 | QListIterator<timerEventItem> it( timerEventList ); | 112 | QListIterator<timerEventItem> it( timerEventList ); |
118 | for ( ; *it; ++it ) { | 113 | for ( ; *it; ++it ) { |
119 | ds << it.current()->UTCtime; | 114 | ds << it.current()->UTCtime; |
120 | ds << it.current()->channel; | 115 | ds << it.current()->channel; |
121 | ds << it.current()->message; | 116 | ds << it.current()->message; |
122 | ds << it.current()->data; | 117 | ds << it.current()->data; |
123 | } | 118 | } |
124 | 119 | ||
125 | 120 | ||