Diffstat (limited to 'noncore/unsupported/libopie/pim/opimnotify.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/libopie/pim/opimnotify.cpp | 227 |
1 files changed, 227 insertions, 0 deletions
diff --git a/noncore/unsupported/libopie/pim/opimnotify.cpp b/noncore/unsupported/libopie/pim/opimnotify.cpp new file mode 100644 index 0000000..af5514b --- a/dev/null +++ b/noncore/unsupported/libopie/pim/opimnotify.cpp | |||
@@ -0,0 +1,227 @@ | |||
1 | #include <qshared.h> | ||
2 | |||
3 | #include "opimnotify.h" | ||
4 | |||
5 | struct OPimNotify::Data : public QShared { | ||
6 | Data() : QShared(),dur(-1),parent(0) { | ||
7 | |||
8 | } | ||
9 | QDateTime start; | ||
10 | int dur; | ||
11 | QString application; | ||
12 | int parent; | ||
13 | }; | ||
14 | |||
15 | OPimNotify::OPimNotify( const QDateTime& start, int duration, int parent ) { | ||
16 | data = new Data; | ||
17 | data->start = start; | ||
18 | data->dur = duration; | ||
19 | data->parent = parent; | ||
20 | } | ||
21 | OPimNotify::OPimNotify( const OPimNotify& noti) | ||
22 | : data( noti.data ) | ||
23 | { | ||
24 | data->ref(); | ||
25 | } | ||
26 | OPimNotify::~OPimNotify() { | ||
27 | if ( data->deref() ) { | ||
28 | delete data; | ||
29 | data = 0l; | ||
30 | } | ||
31 | } | ||
32 | |||
33 | OPimNotify &OPimNotify::operator=( const OPimNotify& noti) { | ||
34 | noti.data->ref(); | ||
35 | deref(); | ||
36 | data = noti.data; | ||
37 | |||
38 | return *this; | ||
39 | } | ||
40 | bool OPimNotify::operator==( const OPimNotify& noti ) { | ||
41 | if ( data == noti.data ) return true; | ||
42 | if ( data->dur != noti.data->dur ) return false; | ||
43 | if ( data->parent != noti.data->parent ) return false; | ||
44 | if ( data->application != noti.data->application ) return false; | ||
45 | if ( data->start != noti.data->start ) return false; | ||
46 | |||
47 | return true; | ||
48 | } | ||
49 | QDateTime OPimNotify::dateTime()const { | ||
50 | return data->start; | ||
51 | } | ||
52 | QString OPimNotify::service()const { | ||
53 | return data->application; | ||
54 | } | ||
55 | int OPimNotify::parent()const { | ||
56 | return data->parent; | ||
57 | } | ||
58 | int OPimNotify::duration()const { | ||
59 | return data->dur; | ||
60 | } | ||
61 | QDateTime OPimNotify::endTime()const { | ||
62 | return QDateTime( data->start.date(), data->start.time().addSecs( data->dur) ); | ||
63 | } | ||
64 | void OPimNotify::setDateTime( const QDateTime& time ) { | ||
65 | copyIntern(); | ||
66 | data->start = time; | ||
67 | } | ||
68 | void OPimNotify::setDuration( int dur ) { | ||
69 | copyIntern(); | ||
70 | data->dur = dur; | ||
71 | } | ||
72 | void OPimNotify::setParent( int uid ) { | ||
73 | copyIntern(); | ||
74 | data->parent = uid; | ||
75 | } | ||
76 | void OPimNotify::setService( const QString& str ) { | ||
77 | copyIntern(); | ||
78 | data->application = str; | ||
79 | } | ||
80 | void OPimNotify::copyIntern() { | ||
81 | if ( data->count != 1 ) { | ||
82 | data->deref(); | ||
83 | Data* dat = new Data; | ||
84 | dat->start = data->start; | ||
85 | dat->dur = data->dur; | ||
86 | dat->application = data->application; | ||
87 | dat->parent = data->parent; | ||
88 | data = dat; | ||
89 | } | ||
90 | } | ||
91 | void OPimNotify::deref() { | ||
92 | if ( data->deref() ) { | ||
93 | delete data; | ||
94 | data = 0; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | /***********************************************************/ | ||
99 | struct OPimAlarm::Data : public QShared { | ||
100 | Data() : QShared() { | ||
101 | sound = 1; | ||
102 | } | ||
103 | int sound; | ||
104 | QString file; | ||
105 | }; | ||
106 | OPimAlarm::OPimAlarm( int sound, const QDateTime& start, int duration, int parent ) | ||
107 | : OPimNotify( start, duration, parent ) | ||
108 | { | ||
109 | data = new Data; | ||
110 | data->sound = sound; | ||
111 | } | ||
112 | OPimAlarm::OPimAlarm( const OPimAlarm& al) | ||
113 | : OPimNotify(al), data( al.data ) | ||
114 | { | ||
115 | data->ref(); | ||
116 | } | ||
117 | OPimAlarm::~OPimAlarm() { | ||
118 | if ( data->deref() ) { | ||
119 | delete data; | ||
120 | data = 0l; | ||
121 | } | ||
122 | } | ||
123 | OPimAlarm &OPimAlarm::operator=( const OPimAlarm& al) | ||
124 | { | ||
125 | OPimNotify::operator=( al ); | ||
126 | deref(); | ||
127 | al.data->ref(); | ||
128 | |||
129 | data = al.data; | ||
130 | |||
131 | |||
132 | return *this; | ||
133 | } | ||
134 | bool OPimAlarm::operator==( const OPimAlarm& al) { | ||
135 | if ( data->sound != al.data->sound ) return false; | ||
136 | else if ( data->sound == Custom && data->file != al.data->file ) | ||
137 | return false; | ||
138 | |||
139 | return OPimNotify::operator==( al ); | ||
140 | } | ||
141 | QString OPimAlarm::type()const { | ||
142 | return QString::fromLatin1("OPimAlarm"); | ||
143 | } | ||
144 | int OPimAlarm::sound()const { | ||
145 | return data->sound; | ||
146 | } | ||
147 | QString OPimAlarm::file()const { | ||
148 | return data->file; | ||
149 | } | ||
150 | void OPimAlarm::setSound( int snd) { | ||
151 | copyIntern(); | ||
152 | data->sound = snd; | ||
153 | } | ||
154 | void OPimAlarm::setFile( const QString& sound ) { | ||
155 | copyIntern(); | ||
156 | data->file = sound; | ||
157 | } | ||
158 | void OPimAlarm::deref() { | ||
159 | if ( data->deref() ) { | ||
160 | delete data; | ||
161 | data = 0l; | ||
162 | } | ||
163 | } | ||
164 | void OPimAlarm::copyIntern() { | ||
165 | if ( data->count != 1 ) { | ||
166 | data->deref(); | ||
167 | Data *newDat = new Data; | ||
168 | newDat->sound = data->sound; | ||
169 | newDat->file = data->file; | ||
170 | data = newDat; | ||
171 | } | ||
172 | } | ||
173 | /************************/ | ||
174 | struct OPimReminder::Data : public QShared { | ||
175 | Data() : QShared(), record( 0) { | ||
176 | } | ||
177 | int record; | ||
178 | |||
179 | }; | ||
180 | OPimReminder::OPimReminder( int uid, const QDateTime& start, int dur, int parent ) | ||
181 | : OPimNotify( start, dur, parent ) | ||
182 | { | ||
183 | data = new Data; | ||
184 | data->record = uid; | ||
185 | } | ||
186 | OPimReminder::OPimReminder( const OPimReminder& rem ) | ||
187 | : OPimNotify( rem ), data( rem.data ) | ||
188 | { | ||
189 | data->ref(); | ||
190 | } | ||
191 | OPimReminder& OPimReminder::operator=( const OPimReminder& rem) { | ||
192 | OPimNotify::operator=(rem ); | ||
193 | |||
194 | deref(); | ||
195 | rem.data->ref(); | ||
196 | data = rem.data; | ||
197 | |||
198 | return *this; | ||
199 | } | ||
200 | bool OPimReminder::operator==( const OPimReminder& rem) { | ||
201 | if ( data->record != rem.data->record ) return false; | ||
202 | |||
203 | return OPimNotify::operator==( rem ); | ||
204 | } | ||
205 | QString OPimReminder::type()const { | ||
206 | return QString::fromLatin1("OPimReminder"); | ||
207 | } | ||
208 | int OPimReminder::recordUid()const { | ||
209 | return data->record; | ||
210 | } | ||
211 | void OPimReminder::setRecordUid( int uid ) { | ||
212 | copyIntern(); | ||
213 | data->record = uid; | ||
214 | } | ||
215 | void OPimReminder::deref() { | ||
216 | if ( data->deref() ) { | ||
217 | delete data; | ||
218 | data = 0l; | ||
219 | } | ||
220 | } | ||
221 | void OPimReminder::copyIntern() { | ||
222 | if ( data->count != 1 ) { | ||
223 | Data* da = new Data; | ||
224 | da->record = data->record; | ||
225 | data = da; | ||
226 | } | ||
227 | } | ||