summaryrefslogtreecommitdiff
path: root/library/alarmserver.cpp
Unidiff
Diffstat (limited to 'library/alarmserver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/alarmserver.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/library/alarmserver.cpp b/library/alarmserver.cpp
index 48ab9c1..ba7b015 100644
--- a/library/alarmserver.cpp
+++ b/library/alarmserver.cpp
@@ -1,160 +1,159 @@
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 "alarmserver.h"
22
23 22
23#include <qpe/global.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25
26#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
27#include "alarmserver.h"
28#include <qpe/timeconversion.h> 26#include <qpe/timeconversion.h>
29 27
28#include <qdir.h>
29
30#include <sys/types.h> 30#include <sys/types.h>
31#include <sys/stat.h> 31#include <sys/stat.h>
32
33#include <stdlib.h> 32#include <stdlib.h>
34#include <unistd.h> 33#include <unistd.h>
35 34
36 35
37#undef USE_ATD // not used anymore -- we run opie-alarm on suspend/resume 36#undef USE_ATD // not used anymore -- we run opie-alarm on suspend/resume
38 37
39 38
40struct timerEventItem 39struct timerEventItem
41{ 40{
42 time_t UTCtime; 41 time_t UTCtime;
43 QCString channel, message; 42 QCString channel, message;
44 int data; 43 int data;
45 bool operator==( const timerEventItem &right ) const 44 bool operator==( const timerEventItem &right ) const
46 { 45 {
47 return ( UTCtime == right.UTCtime 46 return ( UTCtime == right.UTCtime
48 && channel == right.channel 47 && channel == right.channel
49 && message == right.message 48 && message == right.message
50 && data == right.data ); 49 && data == right.data );
51 } 50 }
52}; 51};
53 52
54class TimerReceiverObject : public QObject 53class TimerReceiverObject : public QObject
55{ 54{
56public: 55public:
57 TimerReceiverObject() 56 TimerReceiverObject()
58 { } 57 { }
59 ~TimerReceiverObject() 58 ~TimerReceiverObject()
60 { } 59 { }
61 void resetTimer(); 60 void resetTimer();
62 void setTimerEventItem(); 61 void setTimerEventItem();
63 void deleteTimer(); 62 void deleteTimer();
64protected: 63protected:
65 void timerEvent( QTimerEvent *te ); 64 void timerEvent( QTimerEvent *te );
66 65
67#ifdef USE_ATD 66#ifdef USE_ATD
68private: 67private:
69 QString atfilename; 68 QString atfilename;
70#endif 69#endif
71}; 70};
72 71
73TimerReceiverObject *timerEventReceiver = NULL; 72TimerReceiverObject *timerEventReceiver = NULL;
74QList<timerEventItem> timerEventList; 73QList<timerEventItem> timerEventList;
75timerEventItem *nearestTimerEvent = NULL; 74timerEventItem *nearestTimerEvent = NULL;
76 75
77 76
78// set the timer to go off on the next event in the list 77// set the timer to go off on the next event in the list
79void setNearestTimerEvent() 78void setNearestTimerEvent()
80{ 79{
81 nearestTimerEvent = NULL; 80 nearestTimerEvent = NULL;
82 QListIterator<timerEventItem> it( timerEventList ); 81 QListIterator<timerEventItem> it( timerEventList );
83 if ( *it ) 82 if ( *it )
84 nearestTimerEvent = *it; 83 nearestTimerEvent = *it;
85 for ( ; *it; ++it ) 84 for ( ; *it; ++it )
86 if ( (*it)->UTCtime < nearestTimerEvent->UTCtime ) 85 if ( (*it)->UTCtime < nearestTimerEvent->UTCtime )
87 nearestTimerEvent = *it; 86 nearestTimerEvent = *it;
88 if (nearestTimerEvent) 87 if (nearestTimerEvent)
89 timerEventReceiver->resetTimer(); 88 timerEventReceiver->resetTimer();
90 else 89 else
91 timerEventReceiver->deleteTimer(); 90 timerEventReceiver->deleteTimer();
92} 91}
93 92
94 93
95//store current state to file 94//store current state to file
96//Simple implementation. Should run on a timer. 95//Simple implementation. Should run on a timer.
97 96
98static void saveState() 97static void saveState()
99{ 98{
100 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" ); 99 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" );
101 if ( timerEventList.isEmpty() ) { 100 if ( timerEventList.isEmpty() ) {
102 unlink( savefilename ); 101 unlink( savefilename );
103 return ; 102 return ;
104 } 103 }
105 104
106 QFile savefile(savefilename + ".new"); 105 QFile savefile(savefilename + ".new");
107 if ( savefile.open(IO_WriteOnly) ) { 106 if ( savefile.open(IO_WriteOnly) ) {
108 QDataStream ds( &savefile ); 107 QDataStream ds( &savefile );
109 108
110 //save 109 //save
111 110
112 QListIterator<timerEventItem> it( timerEventList ); 111 QListIterator<timerEventItem> it( timerEventList );
113 for ( ; *it; ++it ) { 112 for ( ; *it; ++it ) {
114 ds << it.current()->UTCtime; 113 ds << it.current()->UTCtime;
115 ds << it.current()->channel; 114 ds << it.current()->channel;
116 ds << it.current()->message; 115 ds << it.current()->message;
117 ds << it.current()->data; 116 ds << it.current()->data;
118 } 117 }
119 118
120 119
121 savefile.close(); 120 savefile.close();
122 unlink( savefilename ); 121 unlink( savefilename );
123 QDir d; 122 QDir d;
124 d.rename(savefilename + ".new", savefilename); 123 d.rename(savefilename + ".new", savefilename);
125 124
126 } 125 }
127} 126}
128 127
129/*! 128/*!
130 Sets up the alarm server. Restoring to previous state (session management). 129 Sets up the alarm server. Restoring to previous state (session management).
131 */ 130 */
132void AlarmServer::initialize() 131void AlarmServer::initialize()
133{ 132{
134 //read autosave file and put events in timerEventList 133 //read autosave file and put events in timerEventList
135 134
136 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" ); 135 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" );
137 136
138 QFile savefile(savefilename); 137 QFile savefile(savefilename);
139 if ( savefile.open(IO_ReadOnly) ) { 138 if ( savefile.open(IO_ReadOnly) ) {
140 QDataStream ds( &savefile ); 139 QDataStream ds( &savefile );
141 while ( !ds.atEnd() ) { 140 while ( !ds.atEnd() ) {
142 timerEventItem *newTimerEventItem = new timerEventItem; 141 timerEventItem *newTimerEventItem = new timerEventItem;
143 ds >> newTimerEventItem->UTCtime; 142 ds >> newTimerEventItem->UTCtime;
144 ds >> newTimerEventItem->channel; 143 ds >> newTimerEventItem->channel;
145 ds >> newTimerEventItem->message; 144 ds >> newTimerEventItem->message;
146 ds >> newTimerEventItem->data; 145 ds >> newTimerEventItem->data;
147 timerEventList.append( newTimerEventItem ); 146 timerEventList.append( newTimerEventItem );
148 } 147 }
149 savefile.close(); 148 savefile.close();
150 if (!timerEventReceiver) 149 if (!timerEventReceiver)
151 timerEventReceiver = new TimerReceiverObject; 150 timerEventReceiver = new TimerReceiverObject;
152 setNearestTimerEvent(); 151 setNearestTimerEvent();
153 } 152 }
154} 153}
155 154
156 155
157#ifdef USE_ATD 156#ifdef USE_ATD
158 157
159static const char* atdir = "/var/spool/at/"; 158static const char* atdir = "/var/spool/at/";
160 159