-rw-r--r-- | core/pim/datebook/dateentryimpl.cpp | 2 |
1 files changed, 0 insertions, 2 deletions
diff --git a/core/pim/datebook/dateentryimpl.cpp b/core/pim/datebook/dateentryimpl.cpp index e563db0..403378e 100644 --- a/core/pim/datebook/dateentryimpl.cpp +++ b/core/pim/datebook/dateentryimpl.cpp | |||
@@ -1,511 +1,509 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of 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 "dateentryimpl.h" | 21 | #include "dateentryimpl.h" |
22 | #include "repeatentry.h" | 22 | #include "repeatentry.h" |
23 | 23 | ||
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | #include <qpe/categoryselect.h> | 25 | #include <qpe/categoryselect.h> |
26 | #include <qpe/datebookmonth.h> | 26 | #include <qpe/datebookmonth.h> |
27 | #include <qpe/global.h> | 27 | #include <qpe/global.h> |
28 | #include <qpe/timeconversion.h> | 28 | #include <qpe/timeconversion.h> |
29 | #include <qpe/timestring.h> | 29 | #include <qpe/timestring.h> |
30 | #include <qpe/tzselect.h> | 30 | #include <qpe/tzselect.h> |
31 | 31 | ||
32 | #include <qcheckbox.h> | 32 | #include <qcheckbox.h> |
33 | #include <qcombobox.h> | 33 | #include <qcombobox.h> |
34 | #include <qlayout.h> | 34 | #include <qlayout.h> |
35 | #include <qlineedit.h> | 35 | #include <qlineedit.h> |
36 | #include <qmultilineedit.h> | 36 | #include <qmultilineedit.h> |
37 | #include <qpopupmenu.h> | 37 | #include <qpopupmenu.h> |
38 | #include <qscrollview.h> | 38 | #include <qscrollview.h> |
39 | #include <qspinbox.h> | 39 | #include <qspinbox.h> |
40 | #include <qtoolbutton.h> | 40 | #include <qtoolbutton.h> |
41 | 41 | ||
42 | #include "timepicker.h" | 42 | #include "timepicker.h" |
43 | 43 | ||
44 | #include <stdlib.h> | 44 | #include <stdlib.h> |
45 | 45 | ||
46 | #include <stdiostream.h> | ||
47 | |||
48 | /* | 46 | /* |
49 | * Constructs a DateEntry which is a child of 'parent', with the | 47 | * Constructs a DateEntry which is a child of 'parent', with the |
50 | * name 'name' and widget flags set to 'f' | 48 | * name 'name' and widget flags set to 'f' |
51 | * | 49 | * |
52 | * The dialog will by default be modeless, unless you set 'modal' to | 50 | * The dialog will by default be modeless, unless you set 'modal' to |
53 | * TRUE to construct a modal dialog. | 51 | * TRUE to construct a modal dialog. |
54 | */ | 52 | */ |
55 | 53 | ||
56 | DateEntry::DateEntry( bool startOnMonday, const QDateTime &start, | 54 | DateEntry::DateEntry( bool startOnMonday, const QDateTime &start, |
57 | const QDateTime &end, bool whichClock, QWidget* parent, | 55 | const QDateTime &end, bool whichClock, QWidget* parent, |
58 | const char* name ) | 56 | const char* name ) |
59 | : DateEntryBase( parent, name ), | 57 | : DateEntryBase( parent, name ), |
60 | ampm( whichClock ), | 58 | ampm( whichClock ), |
61 | startWeekOnMonday( startOnMonday ) | 59 | startWeekOnMonday( startOnMonday ) |
62 | { | 60 | { |
63 | init(); | 61 | init(); |
64 | setDates(start,end); | 62 | setDates(start,end); |
65 | setFocusProxy(comboDescription); | 63 | setFocusProxy(comboDescription); |
66 | } | 64 | } |
67 | 65 | ||
68 | static void addOrPick( QComboBox* combo, const QString& t ) | 66 | static void addOrPick( QComboBox* combo, const QString& t ) |
69 | { | 67 | { |
70 | // Pick an item if one excists | 68 | // Pick an item if one excists |
71 | for (int i=0; i<combo->count(); i++) { | 69 | for (int i=0; i<combo->count(); i++) { |
72 | if ( combo->text(i) == t ) { | 70 | if ( combo->text(i) == t ) { |
73 | combo->setCurrentItem(i); | 71 | combo->setCurrentItem(i); |
74 | return; | 72 | return; |
75 | } | 73 | } |
76 | } | 74 | } |
77 | 75 | ||
78 | // Else add one | 76 | // Else add one |
79 | combo->insertItem(t); | 77 | combo->insertItem(t); |
80 | combo->setCurrentItem(combo->count()-1); | 78 | combo->setCurrentItem(combo->count()-1); |
81 | } | 79 | } |
82 | 80 | ||
83 | DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, | 81 | DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, |
84 | QWidget* parent, const char* name ) | 82 | QWidget* parent, const char* name ) |
85 | : DateEntryBase( parent, name ), | 83 | : DateEntryBase( parent, name ), |
86 | ampm( whichClock ), | 84 | ampm( whichClock ), |
87 | startWeekOnMonday( startOnMonday ) | 85 | startWeekOnMonday( startOnMonday ) |
88 | { | 86 | { |
89 | init(); | 87 | init(); |
90 | setDates(event.start(),event.end()); | 88 | setDates(event.start(),event.end()); |
91 | comboCategory->setCategories( event.categories(), "Calendar", tr("Calendar") ); | 89 | comboCategory->setCategories( event.categories(), "Calendar", tr("Calendar") ); |
92 | if(!event.description().isEmpty()) | 90 | if(!event.description().isEmpty()) |
93 | addOrPick( comboDescription, event.description() ); | 91 | addOrPick( comboDescription, event.description() ); |
94 | if(!event.location().isEmpty()) | 92 | if(!event.location().isEmpty()) |
95 | addOrPick( comboLocation, event.location() ); | 93 | addOrPick( comboLocation, event.location() ); |
96 | checkAlarm->setChecked( event.hasAlarm() ); | 94 | checkAlarm->setChecked( event.hasAlarm() ); |
97 | checkAllDay->setChecked( event.type() == Event::AllDay ); | 95 | checkAllDay->setChecked( event.type() == Event::AllDay ); |
98 | if(!event.notes().isEmpty()) | 96 | if(!event.notes().isEmpty()) |
99 | editNote->setText(event.notes()); | 97 | editNote->setText(event.notes()); |
100 | spinAlarm->setValue(event.alarmTime()); | 98 | spinAlarm->setValue(event.alarmTime()); |
101 | if ( event.alarmSound() != Event::Silent ) | 99 | if ( event.alarmSound() != Event::Silent ) |
102 | comboSound->setCurrentItem( 1 ); | 100 | comboSound->setCurrentItem( 1 ); |
103 | if ( event.hasRepeat() ) { | 101 | if ( event.hasRepeat() ) { |
104 | rp = event.repeatPattern(); | 102 | rp = event.repeatPattern(); |
105 | cmdRepeat->setText( tr("Repeat...") ); | 103 | cmdRepeat->setText( tr("Repeat...") ); |
106 | } | 104 | } |
107 | setRepeatLabel(); | 105 | setRepeatLabel(); |
108 | } | 106 | } |
109 | 107 | ||
110 | void DateEntry::setDates( const QDateTime& s, const QDateTime& e ) | 108 | void DateEntry::setDates( const QDateTime& s, const QDateTime& e ) |
111 | { | 109 | { |
112 | startDate = s.date(); | 110 | startDate = s.date(); |
113 | endDate = e.date(); | 111 | endDate = e.date(); |
114 | startTime = s.time(); | 112 | startTime = s.time(); |
115 | endTime = e.time(); | 113 | endTime = e.time(); |
116 | 114 | ||
117 | startDateChanged( s.date().year(), s.date().month(), s.date().day() ); | 115 | startDateChanged( s.date().year(), s.date().month(), s.date().day() ); |
118 | endDateChanged( e.date().year(), e.date().month(), e.date().day() ); | 116 | endDateChanged( e.date().year(), e.date().month(), e.date().day() ); |
119 | 117 | ||
120 | updateTimeEdit(true,true); | 118 | updateTimeEdit(true,true); |
121 | } | 119 | } |
122 | 120 | ||
123 | void DateEntry::updateTimeEdit(bool s, bool e) { | 121 | void DateEntry::updateTimeEdit(bool s, bool e) { |
124 | 122 | ||
125 | // Comboboxes | 123 | // Comboboxes |
126 | QString strStart, strEnd; | 124 | QString strStart, strEnd; |
127 | int shour, ehour; | 125 | int shour, ehour; |
128 | if ( ampm ) { | 126 | if ( ampm ) { |
129 | shour = startTime.hour(); | 127 | shour = startTime.hour(); |
130 | ehour = endTime.hour(); | 128 | ehour = endTime.hour(); |
131 | if ( shour >= 12 ) { | 129 | if ( shour >= 12 ) { |
132 | if ( shour > 12 ) | 130 | if ( shour > 12 ) |
133 | shour -= 12; | 131 | shour -= 12; |
134 | strStart.sprintf( "%d:%02d PM", shour, startTime.minute() ); | 132 | strStart.sprintf( "%d:%02d PM", shour, startTime.minute() ); |
135 | } else { | 133 | } else { |
136 | if ( shour == 0 ) | 134 | if ( shour == 0 ) |
137 | shour = 12; | 135 | shour = 12; |
138 | strStart.sprintf( "%d:%02d AM", shour, startTime.minute() ); | 136 | strStart.sprintf( "%d:%02d AM", shour, startTime.minute() ); |
139 | } | 137 | } |
140 | if ( ehour == 24 && endTime.minute() == 0 ) { | 138 | if ( ehour == 24 && endTime.minute() == 0 ) { |
141 | strEnd = "11:59 PM"; // or "midnight" | 139 | strEnd = "11:59 PM"; // or "midnight" |
142 | } else if ( ehour >= 12 ) { | 140 | } else if ( ehour >= 12 ) { |
143 | if ( ehour > 12 ) | 141 | if ( ehour > 12 ) |
144 | ehour -= 12; | 142 | ehour -= 12; |
145 | strEnd.sprintf( "%d:%02d PM", ehour, endTime.minute() ); | 143 | strEnd.sprintf( "%d:%02d PM", ehour, endTime.minute() ); |
146 | } else { | 144 | } else { |
147 | if ( ehour == 0 ) | 145 | if ( ehour == 0 ) |
148 | ehour = 12; | 146 | ehour = 12; |
149 | strEnd.sprintf( "%d:%02d AM", ehour, endTime.minute() ); | 147 | strEnd.sprintf( "%d:%02d AM", ehour, endTime.minute() ); |
150 | } | 148 | } |
151 | } else { | 149 | } else { |
152 | strStart.sprintf( "%02d:%02d", startTime.hour(), startTime.minute() ); | 150 | strStart.sprintf( "%02d:%02d", startTime.hour(), startTime.minute() ); |
153 | strEnd.sprintf( "%02d:%02d", endTime.hour(), endTime.minute() ); | 151 | strEnd.sprintf( "%02d:%02d", endTime.hour(), endTime.minute() ); |
154 | } | 152 | } |
155 | 153 | ||
156 | if (s) comboStart->setText(strStart); | 154 | if (s) comboStart->setText(strStart); |
157 | if (e) comboEnd->setText(strEnd); | 155 | if (e) comboEnd->setText(strEnd); |
158 | } | 156 | } |
159 | 157 | ||
160 | void DateEntry::init() | 158 | void DateEntry::init() |
161 | { | 159 | { |
162 | comboDescription->setInsertionPolicy(QComboBox::AtCurrent); | 160 | comboDescription->setInsertionPolicy(QComboBox::AtCurrent); |
163 | comboLocation->setInsertionPolicy(QComboBox::AtCurrent); | 161 | comboLocation->setInsertionPolicy(QComboBox::AtCurrent); |
164 | 162 | ||
165 | initCombos(); | 163 | initCombos(); |
166 | QPopupMenu *m1 = new QPopupMenu( this ); | 164 | QPopupMenu *m1 = new QPopupMenu( this ); |
167 | startPicker = new DateBookMonth( m1, 0, TRUE ); | 165 | startPicker = new DateBookMonth( m1, 0, TRUE ); |
168 | m1->insertItem( startPicker ); | 166 | m1->insertItem( startPicker ); |
169 | buttonStart->setPopup( m1 ); | 167 | buttonStart->setPopup( m1 ); |
170 | connect( startPicker, SIGNAL( dateClicked( int, int, int ) ), | 168 | connect( startPicker, SIGNAL( dateClicked( int, int, int ) ), |
171 | this, SLOT( startDateChanged( int, int, int ) ) ); | 169 | this, SLOT( startDateChanged( int, int, int ) ) ); |
172 | 170 | ||
173 | //Let start button change both start and end dates | 171 | //Let start button change both start and end dates |
174 | connect( startPicker, SIGNAL( dateClicked( int, int, int ) ), | 172 | connect( startPicker, SIGNAL( dateClicked( int, int, int ) ), |
175 | this, SLOT( endDateChanged( int, int, int ) ) ); | 173 | this, SLOT( endDateChanged( int, int, int ) ) ); |
176 | connect( qApp, SIGNAL( clockChanged( bool ) ), | 174 | connect( qApp, SIGNAL( clockChanged( bool ) ), |
177 | this, SLOT( slotChangeClock( bool ) ) ); | 175 | this, SLOT( slotChangeClock( bool ) ) ); |
178 | connect( qApp, SIGNAL(weekChanged(bool)), | 176 | connect( qApp, SIGNAL(weekChanged(bool)), |
179 | this, SLOT(slotChangeStartOfWeek(bool)) ); | 177 | this, SLOT(slotChangeStartOfWeek(bool)) ); |
180 | 178 | ||
181 | QPopupMenu *m2 = new QPopupMenu( this ); | 179 | QPopupMenu *m2 = new QPopupMenu( this ); |
182 | endPicker = new DateBookMonth( m2, 0, TRUE ); | 180 | endPicker = new DateBookMonth( m2, 0, TRUE ); |
183 | m2->insertItem( endPicker ); | 181 | m2->insertItem( endPicker ); |
184 | buttonEnd->setPopup( m2 ); | 182 | buttonEnd->setPopup( m2 ); |
185 | connect( endPicker, SIGNAL( dateClicked( int, int, int ) ), | 183 | connect( endPicker, SIGNAL( dateClicked( int, int, int ) ), |
186 | this, SLOT( endDateChanged( int, int, int ) ) ); | 184 | this, SLOT( endDateChanged( int, int, int ) ) ); |
187 | 185 | ||
188 | connect(timePickerStart, SIGNAL( timeChanged(const QTime &) ), | 186 | connect(timePickerStart, SIGNAL( timeChanged(const QTime &) ), |
189 | this, SLOT( startTimePicked(const QTime &) )); | 187 | this, SLOT( startTimePicked(const QTime &) )); |
190 | editNote->setFixedVisibleLines(3); | 188 | editNote->setFixedVisibleLines(3); |
191 | } | 189 | } |
192 | 190 | ||
193 | /* | 191 | /* |
194 | * Destroys the object and frees any allocated resources | 192 | * Destroys the object and frees any allocated resources |
195 | */ | 193 | */ |
196 | DateEntry::~DateEntry() | 194 | DateEntry::~DateEntry() |
197 | { | 195 | { |
198 | // no need to delete child widgets, Qt does it all for us | 196 | // no need to delete child widgets, Qt does it all for us |
199 | //cout << "Del: " << comboStart->currentText() << endl; | 197 | //cout << "Del: " << comboStart->currentText() << endl; |
200 | } | 198 | } |
201 | 199 | ||
202 | /* | 200 | /* |
203 | * public slot | 201 | * public slot |
204 | */ | 202 | */ |
205 | void DateEntry::endDateChanged( int y, int m, int d ) | 203 | void DateEntry::endDateChanged( int y, int m, int d ) |
206 | { | 204 | { |
207 | endDate.setYMD( y, m, d ); | 205 | endDate.setYMD( y, m, d ); |
208 | if ( endDate < startDate ) { | 206 | if ( endDate < startDate ) { |
209 | endDate = startDate; | 207 | endDate = startDate; |
210 | } | 208 | } |
211 | 209 | ||
212 | buttonEnd->setText( TimeString::shortDate( endDate ) ); | 210 | buttonEnd->setText( TimeString::shortDate( endDate ) ); |
213 | 211 | ||
214 | endPicker->setDate( endDate.year(), endDate.month(), endDate.day() ); | 212 | endPicker->setDate( endDate.year(), endDate.month(), endDate.day() ); |
215 | } | 213 | } |
216 | 214 | ||
217 | static QTime parseTime( const QString& s, bool ampm ) | 215 | static QTime parseTime( const QString& s, bool ampm ) |
218 | { | 216 | { |
219 | QTime tmpTime; | 217 | QTime tmpTime; |
220 | QStringList l = QStringList::split( ':', s ); | 218 | QStringList l = QStringList::split( ':', s ); |
221 | int hour = l[0].toInt(); | 219 | int hour = l[0].toInt(); |
222 | if ( ampm ) { | 220 | if ( ampm ) { |
223 | int i=0; | 221 | int i=0; |
224 | while (i<int(l[1].length()) && l[1][i]>='0' && l[1][i]<='9') | 222 | while (i<int(l[1].length()) && l[1][i]>='0' && l[1][i]<='9') |
225 | i++; | 223 | i++; |
226 | QString digits = l[1].left(i); | 224 | QString digits = l[1].left(i); |
227 | if ( l[1].contains( "PM", FALSE ) ) { | 225 | if ( l[1].contains( "PM", FALSE ) ) { |
228 | if ( hour != 12 ) | 226 | if ( hour != 12 ) |
229 | hour += 12; | 227 | hour += 12; |
230 | } else { | 228 | } else { |
231 | if ( hour == 12 ) | 229 | if ( hour == 12 ) |
232 | hour = 0; | 230 | hour = 0; |
233 | } | 231 | } |
234 | l[1] = digits; | 232 | l[1] = digits; |
235 | } | 233 | } |
236 | int minute = l[1].toInt(); | 234 | int minute = l[1].toInt(); |
237 | if ( minute > 59 ) | 235 | if ( minute > 59 ) |
238 | minute = 59; | 236 | minute = 59; |
239 | else if ( minute < 0 ) | 237 | else if ( minute < 0 ) |
240 | minute = 0; | 238 | minute = 0; |
241 | if ( hour > 23 ) { | 239 | if ( hour > 23 ) { |
242 | hour = 23; | 240 | hour = 23; |
243 | minute = 59; | 241 | minute = 59; |
244 | } else if ( hour < 0 ) | 242 | } else if ( hour < 0 ) |
245 | hour = 0; | 243 | hour = 0; |
246 | tmpTime.setHMS( hour, minute, 0 ); | 244 | tmpTime.setHMS( hour, minute, 0 ); |
247 | return tmpTime; | 245 | return tmpTime; |
248 | } | 246 | } |
249 | 247 | ||
250 | /* | 248 | /* |
251 | * public slot | 249 | * public slot |
252 | */ | 250 | */ |
253 | void DateEntry::endTimeChanged( const QString &s ) | 251 | void DateEntry::endTimeChanged( const QString &s ) |
254 | { | 252 | { |
255 | QTime tmpTime = parseTime(s,ampm); | 253 | QTime tmpTime = parseTime(s,ampm); |
256 | if ( endDate > startDate || tmpTime >= startTime ) { | 254 | if ( endDate > startDate || tmpTime >= startTime ) { |
257 | endTime = tmpTime; | 255 | endTime = tmpTime; |
258 | } else { | 256 | } else { |
259 | endTime = startTime; | 257 | endTime = startTime; |
260 | //comboEnd->setCurrentItem( comboStart->currentItem() ); | 258 | //comboEnd->setCurrentItem( comboStart->currentItem() ); |
261 | } | 259 | } |
262 | 260 | ||
263 | } | 261 | } |
264 | 262 | ||
265 | void DateEntry::endTimeChanged( const QTime &t ) { | 263 | void DateEntry::endTimeChanged( const QTime &t ) { |
266 | } | 264 | } |
267 | 265 | ||
268 | /* | 266 | /* |
269 | * public slot | 267 | * public slot |
270 | */ | 268 | */ |
271 | void DateEntry::startDateChanged( int y, int m, int d ) | 269 | void DateEntry::startDateChanged( int y, int m, int d ) |
272 | { | 270 | { |
273 | QDate prev = startDate; | 271 | QDate prev = startDate; |
274 | startDate.setYMD( y, m, d ); | 272 | startDate.setYMD( y, m, d ); |
275 | if ( rp.type == Event::Weekly && | 273 | if ( rp.type == Event::Weekly && |
276 | startDate.dayOfWeek() != prev.dayOfWeek() ) { | 274 | startDate.dayOfWeek() != prev.dayOfWeek() ) { |
277 | // if we change the start of a weekly repeating event | 275 | // if we change the start of a weekly repeating event |
278 | // set the repeating day appropriately | 276 | // set the repeating day appropriately |
279 | char mask = 1 << (prev.dayOfWeek()-1); | 277 | char mask = 1 << (prev.dayOfWeek()-1); |
280 | rp.days &= (~mask); | 278 | rp.days &= (~mask); |
281 | rp.days |= 1 << (startDate.dayOfWeek()-1); | 279 | rp.days |= 1 << (startDate.dayOfWeek()-1); |
282 | } | 280 | } |
283 | 281 | ||
284 | buttonStart->setText( TimeString::shortDate( startDate ) ); | 282 | buttonStart->setText( TimeString::shortDate( startDate ) ); |
285 | 283 | ||
286 | // our pickers must be reset... | 284 | // our pickers must be reset... |
287 | startPicker->setDate( y, m, d ); | 285 | startPicker->setDate( y, m, d ); |
288 | endPicker->setDate( y, m, d ); | 286 | endPicker->setDate( y, m, d ); |
289 | } | 287 | } |
290 | 288 | ||
291 | /* | 289 | /* |
292 | * public slot | 290 | * public slot |
293 | */ | 291 | */ |
294 | void DateEntry::startTimeEdited( const QString &s ) | 292 | void DateEntry::startTimeEdited( const QString &s ) |
295 | { | 293 | { |
296 | startTimeChanged(parseTime(s,ampm)); | 294 | startTimeChanged(parseTime(s,ampm)); |
297 | updateTimeEdit(false,true); | 295 | updateTimeEdit(false,true); |
298 | timePickerStart->setHour(startTime.hour()); | 296 | timePickerStart->setHour(startTime.hour()); |
299 | timePickerStart->setMinute(startTime.minute()); | 297 | timePickerStart->setMinute(startTime.minute()); |
300 | } | 298 | } |
301 | 299 | ||
302 | void DateEntry::startTimeChanged( const QTime &t ) | 300 | void DateEntry::startTimeChanged( const QTime &t ) |
303 | { | 301 | { |
304 | int duration=startTime.secsTo(endTime); | 302 | int duration=startTime.secsTo(endTime); |
305 | startTime = t; | 303 | startTime = t; |
306 | endTime=t.addSecs(duration); | 304 | endTime=t.addSecs(duration); |
307 | } | 305 | } |
308 | void DateEntry::startTimePicked( const QTime &t ) { | 306 | void DateEntry::startTimePicked( const QTime &t ) { |
309 | startTimeChanged(t); | 307 | startTimeChanged(t); |
310 | updateTimeEdit(true,true); | 308 | updateTimeEdit(true,true); |
311 | } | 309 | } |
312 | 310 | ||
313 | /* | 311 | /* |
314 | * public slot | 312 | * public slot |
315 | */ | 313 | */ |
316 | void DateEntry::typeChanged( const QString &s ) | 314 | void DateEntry::typeChanged( const QString &s ) |
317 | { | 315 | { |
318 | bool b = s != "All Day"; | 316 | bool b = s != "All Day"; |
319 | buttonStart->setEnabled( b ); | 317 | buttonStart->setEnabled( b ); |
320 | comboStart->setEnabled( b ); | 318 | comboStart->setEnabled( b ); |
321 | comboEnd->setEnabled( b ); | 319 | comboEnd->setEnabled( b ); |
322 | } | 320 | } |
323 | 321 | ||
324 | void DateEntry::slotRepeat() | 322 | void DateEntry::slotRepeat() |
325 | { | 323 | { |
326 | // Work around for compiler Bug.. | 324 | // Work around for compiler Bug.. |
327 | RepeatEntry *e; | 325 | RepeatEntry *e; |
328 | 326 | ||
329 | // it is better in my opinion to just grab this from the mother, | 327 | // it is better in my opinion to just grab this from the mother, |
330 | // since, this dialog doesn't need to keep track of it... | 328 | // since, this dialog doesn't need to keep track of it... |
331 | if ( rp.type != Event::NoRepeat ) | 329 | if ( rp.type != Event::NoRepeat ) |
332 | e = new RepeatEntry( startWeekOnMonday, rp, startDate, this); | 330 | e = new RepeatEntry( startWeekOnMonday, rp, startDate, this); |
333 | else | 331 | else |
334 | e = new RepeatEntry( startWeekOnMonday, startDate, this ); | 332 | e = new RepeatEntry( startWeekOnMonday, startDate, this ); |
335 | 333 | ||
336 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 334 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
337 | e->showMaximized(); | 335 | e->showMaximized(); |
338 | #endif | 336 | #endif |
339 | if ( e->exec() ) { | 337 | if ( e->exec() ) { |
340 | rp = e->repeatPattern(); | 338 | rp = e->repeatPattern(); |
341 | setRepeatLabel(); | 339 | setRepeatLabel(); |
342 | } | 340 | } |
343 | } | 341 | } |
344 | 342 | ||
345 | void DateEntry::slotChangeStartOfWeek( bool onMonday ) | 343 | void DateEntry::slotChangeStartOfWeek( bool onMonday ) |
346 | { | 344 | { |
347 | startWeekOnMonday = onMonday; | 345 | startWeekOnMonday = onMonday; |
348 | } | 346 | } |
349 | 347 | ||
350 | Event DateEntry::event() | 348 | Event DateEntry::event() |
351 | { | 349 | { |
352 | Event ev; | 350 | Event ev; |
353 | Event::SoundTypeChoice st; | 351 | Event::SoundTypeChoice st; |
354 | ev.setDescription( comboDescription->currentText() ); | 352 | ev.setDescription( comboDescription->currentText() ); |
355 | ev.setLocation( comboLocation->currentText() ); | 353 | ev.setLocation( comboLocation->currentText() ); |
356 | ev.setCategories( comboCategory->currentCategories() ); | 354 | ev.setCategories( comboCategory->currentCategories() ); |
357 | ev.setType( checkAllDay->isChecked() ? Event::AllDay : Event::Normal ); | 355 | ev.setType( checkAllDay->isChecked() ? Event::AllDay : Event::Normal ); |
358 | if ( startDate > endDate ) { | 356 | if ( startDate > endDate ) { |
359 | QDate tmp = endDate; | 357 | QDate tmp = endDate; |
360 | endDate = startDate; | 358 | endDate = startDate; |
361 | startDate = tmp; | 359 | startDate = tmp; |
362 | } | 360 | } |
363 | 361 | ||
364 | // This is now done in the changed slots | 362 | // This is now done in the changed slots |
365 | // startTime = parseTime( comboStart->text(), ampm ); | 363 | // startTime = parseTime( comboStart->text(), ampm ); |
366 | //endTime = parseTime( comboEnd->text(), ampm ); | 364 | //endTime = parseTime( comboEnd->text(), ampm ); |
367 | 365 | ||
368 | if ( startTime > endTime && endDate == startDate ) { | 366 | if ( startTime > endTime && endDate == startDate ) { |
369 | QTime tmp = endTime; | 367 | QTime tmp = endTime; |
370 | endTime = startTime; | 368 | endTime = startTime; |
371 | startTime = tmp; | 369 | startTime = tmp; |
372 | } | 370 | } |
373 | // don't set the time if theres no need too | 371 | // don't set the time if theres no need too |
374 | if ( ev.type() == Event::AllDay ) { | 372 | if ( ev.type() == Event::AllDay ) { |
375 | startTime.setHMS( 0, 0, 0 ); | 373 | startTime.setHMS( 0, 0, 0 ); |
376 | endTime.setHMS( 23, 59, 59 ); | 374 | endTime.setHMS( 23, 59, 59 ); |
377 | } | 375 | } |
378 | 376 | ||
379 | // adjust start and end times based on timezone | 377 | // adjust start and end times based on timezone |
380 | QDateTime start( startDate, startTime ); | 378 | QDateTime start( startDate, startTime ); |
381 | QDateTime end( endDate, endTime ); | 379 | QDateTime end( endDate, endTime ); |
382 | time_t start_utc, end_utc; | 380 | time_t start_utc, end_utc; |
383 | 381 | ||
384 | // qDebug( "tz: %s", timezone->currentZone().latin1() ); | 382 | // qDebug( "tz: %s", timezone->currentZone().latin1() ); |
385 | 383 | ||
386 | // get real timezone | 384 | // get real timezone |
387 | QString realTZ; | 385 | QString realTZ; |
388 | realTZ = QString::fromLocal8Bit( getenv("TZ") ); | 386 | realTZ = QString::fromLocal8Bit( getenv("TZ") ); |
389 | 387 | ||
390 | // set timezone | 388 | // set timezone |
391 | if ( setenv( "TZ", timezone->currentZone(), true ) != 0 ) | 389 | if ( setenv( "TZ", timezone->currentZone(), true ) != 0 ) |
392 | qWarning( "There was a problem setting the timezone." ); | 390 | qWarning( "There was a problem setting the timezone." ); |
393 | 391 | ||
394 | // convert to UTC based on selected TZ (calling tzset internally) | 392 | // convert to UTC based on selected TZ (calling tzset internally) |
395 | start_utc = TimeConversion::toUTC( start ); | 393 | start_utc = TimeConversion::toUTC( start ); |
396 | end_utc = TimeConversion::toUTC( end ); | 394 | end_utc = TimeConversion::toUTC( end ); |
397 | 395 | ||
398 | // done playing around... put it all back | 396 | // done playing around... put it all back |
399 | unsetenv( "TZ" ); | 397 | unsetenv( "TZ" ); |
400 | if ( !realTZ.isNull() ) | 398 | if ( !realTZ.isNull() ) |
401 | if ( setenv( "TZ", realTZ, true ) != 0 ) | 399 | if ( setenv( "TZ", realTZ, true ) != 0 ) |
402 | qWarning( "There was a problem setting the timezone." ); | 400 | qWarning( "There was a problem setting the timezone." ); |
403 | 401 | ||
404 | // convert UTC to local time (calling tzset internally) | 402 | // convert UTC to local time (calling tzset internally) |
405 | ev.setStart( TimeConversion::fromUTC( start_utc ) ); | 403 | ev.setStart( TimeConversion::fromUTC( start_utc ) ); |
406 | ev.setEnd( TimeConversion::fromUTC( end_utc ) ); | 404 | ev.setEnd( TimeConversion::fromUTC( end_utc ) ); |
407 | 405 | ||
408 | // we only have one type of sound at the moment... LOUD!!! | 406 | // we only have one type of sound at the moment... LOUD!!! |
409 | if ( comboSound->currentItem() != 0 ) | 407 | if ( comboSound->currentItem() != 0 ) |
410 | st = Event::Loud; | 408 | st = Event::Loud; |
411 | else | 409 | else |
412 | st = Event::Silent; | 410 | st = Event::Silent; |
413 | ev.setAlarm( checkAlarm->isChecked(), spinAlarm->value(), st ); | 411 | ev.setAlarm( checkAlarm->isChecked(), spinAlarm->value(), st ); |
414 | if ( rp.type != Event::NoRepeat ) | 412 | if ( rp.type != Event::NoRepeat ) |
415 | ev.setRepeat( TRUE, rp ); | 413 | ev.setRepeat( TRUE, rp ); |
416 | ev.setNotes( editNote->text() ); | 414 | ev.setNotes( editNote->text() ); |
417 | 415 | ||
418 | //cout << "Start: " << comboStart->currentText() << endl; | 416 | //cout << "Start: " << comboStart->currentText() << endl; |
419 | 417 | ||
420 | return ev; | 418 | return ev; |
421 | } | 419 | } |
422 | 420 | ||
423 | void DateEntry::setRepeatLabel() | 421 | void DateEntry::setRepeatLabel() |
424 | { | 422 | { |
425 | 423 | ||
426 | switch( rp.type ) { | 424 | switch( rp.type ) { |
427 | case Event::Daily: | 425 | case Event::Daily: |
428 | cmdRepeat->setText( tr("Daily...") ); | 426 | cmdRepeat->setText( tr("Daily...") ); |
429 | break; | 427 | break; |
430 | case Event::Weekly: | 428 | case Event::Weekly: |
431 | cmdRepeat->setText( tr("Weekly...") ); | 429 | cmdRepeat->setText( tr("Weekly...") ); |
432 | break; | 430 | break; |
433 | case Event::MonthlyDay: | 431 | case Event::MonthlyDay: |
434 | case Event::MonthlyDate: | 432 | case Event::MonthlyDate: |
435 | cmdRepeat->setText( tr("Monthly...") ); | 433 | cmdRepeat->setText( tr("Monthly...") ); |
436 | break; | 434 | break; |
437 | case Event::Yearly: | 435 | case Event::Yearly: |
438 | cmdRepeat->setText( tr("Yearly...") ); | 436 | cmdRepeat->setText( tr("Yearly...") ); |
439 | break; | 437 | break; |
440 | default: | 438 | default: |
441 | cmdRepeat->setText( tr("No Repeat...") ); | 439 | cmdRepeat->setText( tr("No Repeat...") ); |
442 | } | 440 | } |
443 | } | 441 | } |
444 | 442 | ||
445 | void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundTypeChoice sound ) | 443 | void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundTypeChoice sound ) |
446 | { | 444 | { |
447 | checkAlarm->setChecked( alarmPreset ); | 445 | checkAlarm->setChecked( alarmPreset ); |
448 | spinAlarm->setValue( presetTime ); | 446 | spinAlarm->setValue( presetTime ); |
449 | if ( sound != Event::Silent ) | 447 | if ( sound != Event::Silent ) |
450 | comboSound->setCurrentItem( 1 ); | 448 | comboSound->setCurrentItem( 1 ); |
451 | else | 449 | else |
452 | comboSound->setCurrentItem( 0 ); | 450 | comboSound->setCurrentItem( 0 ); |
453 | } | 451 | } |
454 | 452 | ||
455 | void DateEntry::initCombos() | 453 | void DateEntry::initCombos() |
456 | { | 454 | { |
457 | /* | 455 | /* |
458 | comboStart->clear(); | 456 | comboStart->clear(); |
459 | comboEnd->clear(); | 457 | comboEnd->clear(); |
460 | if ( ampm ) { | 458 | if ( ampm ) { |
461 | for ( int i = 0; i < 24; i++ ) { | 459 | for ( int i = 0; i < 24; i++ ) { |
462 | if ( i == 0 ) { | 460 | if ( i == 0 ) { |
463 | comboStart->insertItem( "12:00 AM" ); | 461 | comboStart->insertItem( "12:00 AM" ); |
464 | comboStart->insertItem( "12:30 AM" ); | 462 | comboStart->insertItem( "12:30 AM" ); |
465 | comboEnd->insertItem( "12:00 AM" ); | 463 | comboEnd->insertItem( "12:00 AM" ); |
466 | comboEnd->insertItem( "12:30 AM" ); | 464 | comboEnd->insertItem( "12:30 AM" ); |
467 | } else if ( i == 12 ) { | 465 | } else if ( i == 12 ) { |
468 | comboStart->insertItem( "12:00 PM" ); | 466 | comboStart->insertItem( "12:00 PM" ); |
469 | comboStart->insertItem( "12:30 PM" ); | 467 | comboStart->insertItem( "12:30 PM" ); |
470 | comboEnd->insertItem( "12:00 PM" ); | 468 | comboEnd->insertItem( "12:00 PM" ); |
471 | comboEnd->insertItem( "12:30 PM" ); | 469 | comboEnd->insertItem( "12:30 PM" ); |
472 | } else if ( i > 12 ) { | 470 | } else if ( i > 12 ) { |
473 | comboStart->insertItem( QString::number( i - 12 ) + ":00 PM" ); | 471 | comboStart->insertItem( QString::number( i - 12 ) + ":00 PM" ); |
474 | comboStart->insertItem( QString::number( i - 12 ) + ":30 PM" ); | 472 | comboStart->insertItem( QString::number( i - 12 ) + ":30 PM" ); |
475 | comboEnd->insertItem( QString::number( i - 12 ) + ":00 PM" ); | 473 | comboEnd->insertItem( QString::number( i - 12 ) + ":00 PM" ); |
476 | comboEnd->insertItem( QString::number( i - 12 ) + ":30 PM" ); | 474 | comboEnd->insertItem( QString::number( i - 12 ) + ":30 PM" ); |
477 | } else { | 475 | } else { |
478 | comboStart->insertItem( QString::number( i) + ":00 AM" ); | 476 | comboStart->insertItem( QString::number( i) + ":00 AM" ); |
479 | comboStart->insertItem( QString::number( i ) + ":30 AM" ); | 477 | comboStart->insertItem( QString::number( i ) + ":30 AM" ); |
480 | comboEnd->insertItem( QString::number( i ) + ":00 AM" ); | 478 | comboEnd->insertItem( QString::number( i ) + ":00 AM" ); |
481 | comboEnd->insertItem( QString::number( i ) + ":30 AM" ); | 479 | comboEnd->insertItem( QString::number( i ) + ":30 AM" ); |
482 | } | 480 | } |
483 | } | 481 | } |
484 | } else { | 482 | } else { |
485 | for ( int i = 0; i < 24; i++ ) { | 483 | for ( int i = 0; i < 24; i++ ) { |
486 | if ( i < 10 ) { | 484 | if ( i < 10 ) { |
487 | comboStart->insertItem( QString("0") | 485 | comboStart->insertItem( QString("0") |
488 | + QString::number(i) + ":00" ); | 486 | + QString::number(i) + ":00" ); |
489 | comboStart->insertItem( QString("0") | 487 | comboStart->insertItem( QString("0") |
490 | + QString::number(i) + ":30" ); | 488 | + QString::number(i) + ":30" ); |
491 | comboEnd->insertItem( QString("0") | 489 | comboEnd->insertItem( QString("0") |
492 | + QString::number(i) + ":00" ); | 490 | + QString::number(i) + ":00" ); |
493 | comboEnd->insertItem( QString("0") | 491 | comboEnd->insertItem( QString("0") |
494 | + QString::number(i) + ":30" ); | 492 | + QString::number(i) + ":30" ); |
495 | } else { | 493 | } else { |
496 | comboStart->insertItem( QString::number(i) + ":00" ); | 494 | comboStart->insertItem( QString::number(i) + ":00" ); |
497 | comboStart->insertItem( QString::number(i) + ":30" ); | 495 | comboStart->insertItem( QString::number(i) + ":30" ); |
498 | comboEnd->insertItem( QString::number(i) + ":00" ); | 496 | comboEnd->insertItem( QString::number(i) + ":00" ); |
499 | comboEnd->insertItem( QString::number(i) + ":30" ); | 497 | comboEnd->insertItem( QString::number(i) + ":30" ); |
500 | } | 498 | } |
501 | } | 499 | } |
502 | } | 500 | } |
503 | */ | 501 | */ |
504 | } | 502 | } |
505 | 503 | ||
506 | void DateEntry::slotChangeClock( bool whichClock ) | 504 | void DateEntry::slotChangeClock( bool whichClock ) |
507 | { | 505 | { |
508 | ampm = whichClock; | 506 | ampm = whichClock; |
509 | initCombos(); | 507 | initCombos(); |
510 | setDates( QDateTime( startDate, startTime ), QDateTime( endDate, endTime ) ); | 508 | setDates( QDateTime( startDate, startTime ), QDateTime( endDate, endTime ) ); |
511 | } | 509 | } |