Reformat debian/copyright to suit informal style habits.
[barry.git] / desktop / src / TaskEditDlg.cc
blob370ce65f99b413953902485365d54bc7b3fd8eff
1 ///
2 /// \file TaskEditDlg.cc
3 /// Dialog class to handle the editing of the Task record
4 ///
6 /*
7 Copyright (C) 2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include "TaskEditDlg.h"
23 #include "windowids.h"
24 #include <wx/valgen.h>
25 #include "wxval.h"
26 #include "util.h"
28 using namespace std;
29 using namespace Barry;
31 // begin wxGlade: ::extracode
32 // end wxGlade
35 //////////////////////////////////////////////////////////////////////////////
36 // TaskEditDlg class
38 TaskEditDlg::TaskEditDlg(wxWindow* parent,
39 Barry::Task &rec,
40 bool editable,
41 const Barry::TimeZones *device_zones)
42 : wxDialog(parent, Dialog_TaskEdit, _T("Task Record"))
43 , m_zones(device_zones ? device_zones : &m_static_zones)
44 , m_rec(rec)
45 , m_reminder_hours(0)
46 , m_reminder_minutes(0)
47 , m_interval(0)
48 , m_relative_date(false)
50 // set all weekday 'bits' to false
51 for( int i = 0; i < 7; i++ )
52 m_weekdays[i] = false;
54 if( editable ) {
55 bottom_buttons = CreateButtonSizer(wxOK | wxCANCEL);
57 else {
58 bottom_buttons = CreateButtonSizer(wxCANCEL);
61 // begin wxGlade: TaskEditDlg::TaskEditDlg
62 label_1 = new wxStaticText(this, wxID_ANY, wxT("Task:"));
63 m_TaskSummary = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
64 static_line_1 = new wxStaticLine(this, wxID_ANY);
65 label_2 = new wxStaticText(this, wxID_ANY, wxT("Status:"));
66 const wxString m_StatusChoice_choices[] = {
67 wxT("Not Started"),
68 wxT("In Progress"),
69 wxT("Completed"),
70 wxT("Waiting"),
71 wxT("Deferred")
73 m_StatusChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 5, m_StatusChoice_choices, 0);
74 label_9 = new wxStaticText(this, wxID_ANY, wxT("Priority:"));
75 const wxString m_PriorityChoice_choices[] = {
76 wxT("High"),
77 wxT("Normal"),
78 wxT("Low")
80 m_PriorityChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 3, m_PriorityChoice_choices, 0);
81 label_5 = new wxStaticText(this, wxID_ANY, wxT("Due:"));
82 m_DueCheck = new wxCheckBox(this, Dialog_TaskEdit_DueCheck, wxEmptyString);
83 m_DueDateCtrl = new wxDatePickerCtrl(this, Dialog_TaskEdit_DueDateCtrl, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY);
84 m_DueHoursSpinner = new wxSpinCtrl(this, Dialog_TaskEdit_DueHoursSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_WRAP|wxTE_NOHIDESEL, 0, 23);
85 label_11 = new wxStaticText(this, wxID_ANY, wxT(":"));
86 m_DueMinutesSpinner = new wxSpinCtrl(this, Dialog_TaskEdit_DueMinutesSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_WRAP|wxTE_NOHIDESEL, 0, 59);
87 label_8 = new wxStaticText(this, wxID_ANY, wxT("Time Zone:"));
88 const wxString m_TimezoneChoice_choices[] = {
89 wxT("System Time Zone")
91 m_TimezoneChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 1, m_TimezoneChoice_choices, 0);
92 label_10 = new wxStaticText(this, wxID_ANY, wxT("Reminder:"));
93 m_ReminderCheck = new wxCheckBox(this, Dialog_TaskEdit_ReminderCheck, wxEmptyString);
94 m_ReminderDateCtrl = new wxDatePickerCtrl(this, Dialog_TaskEdit_ReminderDateCtrl);
95 m_ReminderHoursSpinner = new wxSpinCtrl(this, Dialog_TaskEdit_ReminderHoursSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 999);
96 label_6 = new wxStaticText(this, wxID_ANY, wxT(":"));
97 m_ReminderMinutesSpinner = new wxSpinCtrl(this, Dialog_TaskEdit_ReminderMinutesSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 59);
98 static_line_2 = new wxStaticLine(this, wxID_ANY);
99 label_18 = new wxStaticText(this, wxID_ANY, wxT("Recurrence:"));
100 const wxString m_RecurrenceChoice_choices[] = {
101 wxT("None"),
102 wxT("Daily"),
103 wxT("Weekly"),
104 wxT("Monthly"),
105 wxT("Yearly")
107 m_RecurrenceChoice = new wxChoice(this, Dialog_TaskEdit_RecurrenceChoice, wxDefaultPosition, wxDefaultSize, 5, m_RecurrenceChoice_choices, 0);
108 RecurIntervalLabel = new wxStaticText(this, wxID_ANY, wxT("Interval:"));
109 RecurIntervalLabelB = new wxStaticText(this, wxID_ANY, wxT("Every"));
110 m_IntervalSpinner = new wxSpinCtrl(this, wxID_ANY, wxT("1"), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 999);
111 m_IntervalUnitLabel = new wxStaticText(this, wxID_ANY, wxT("days? weeks? months?"), wxDefaultPosition, wxDefaultSize, wxST_NO_AUTORESIZE);
112 RecurDaysLabel = new wxStaticText(this, wxID_ANY, wxT("Days:"));
113 m_SunCheck = new wxCheckBox(this, wxID_ANY, wxT("S"));
114 m_MonCheck = new wxCheckBox(this, wxID_ANY, wxT("M"));
115 m_TueCheck = new wxCheckBox(this, wxID_ANY, wxT("T"));
116 m_WedCheck = new wxCheckBox(this, wxID_ANY, wxT("W"));
117 m_ThuCheck = new wxCheckBox(this, wxID_ANY, wxT("T"));
118 m_FriCheck = new wxCheckBox(this, wxID_ANY, wxT("F"));
119 m_SatCheck = new wxCheckBox(this, wxID_ANY, wxT("S"));
120 RecurRelativeDateLabel = new wxStaticText(this, wxID_ANY, wxT("Relative Date:"));
121 m_RelativeDateCheck = new wxCheckBox(this, wxID_ANY, wxEmptyString);
122 RecurEndDateLabel = new wxStaticText(this, wxID_ANY, wxT("End Date:"));
123 m_NeverEndsCheck = new wxCheckBox(this, Dialog_TaskEdit_NeverEndsCheck, wxT("Never ends"));
124 m_RecurEndDateCtrl = new wxDatePickerCtrl(this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY);
125 static_line_3 = new wxStaticLine(this, wxID_ANY);
126 label_4 = new wxStaticText(this, wxID_ANY, wxT("Categories:"));
127 m_CategoriesText = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
128 label_3 = new wxStaticText(this, wxID_ANY, wxT("Notes:"));
129 m_NotesText = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
131 set_properties();
132 do_layout();
133 // end wxGlade
135 m_top_sizer->Add(bottom_buttons, 0, wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, 5);
137 // fill the time zone control with real time zones
138 m_TimezoneChoice->Clear();
139 m_TimezoneChoice->Append(wxT("Assume Local Timezone"), (void*)0);
140 Barry::TimeZones::const_iterator b, e;
141 for( b = m_zones->begin(), e = m_zones->end(); b != e; ++b ) {
142 m_TimezoneChoice->Append(
143 wxString(b->GetDescription().c_str(), wxConvUTF8),
144 (void*) &b->Index);
146 m_TimezoneChoice->SetSelection(0);
148 // layout again, in case sizes are different
149 RedoLayout();
152 void TaskEditDlg::RedoLayout()
154 m_top_sizer->Fit(this);
155 Layout();
159 BEGIN_EVENT_TABLE(TaskEditDlg, wxDialog)
160 // begin wxGlade: TaskEditDlg::event_table
161 EVT_CHECKBOX(Dialog_TaskEdit_DueCheck, TaskEditDlg::OnDueCheck)
162 EVT_CHECKBOX(Dialog_TaskEdit_ReminderCheck, TaskEditDlg::OnReminderCheck)
163 EVT_CHOICE(Dialog_TaskEdit_RecurrenceChoice, TaskEditDlg::OnRecurrenceChoice)
164 EVT_CHECKBOX(Dialog_TaskEdit_NeverEndsCheck, TaskEditDlg::OnEndDateCheckbox)
165 // end wxGlade
166 END_EVENT_TABLE();
169 // wxGlade: add TaskEditDlg event handlers
171 void TaskEditDlg::OnDueCheck(wxCommandEvent &event)
173 EnableDueDate(m_DueCheck->IsChecked());
175 // make sure the first date is in a recent range, if not previously
176 // valid...
177 MakeDateRecent(m_DueCheck->IsChecked(), m_DueDateCtrl);
180 void TaskEditDlg::OnRecurrenceChoice(wxCommandEvent &event)
182 TransferDataFromWindow();
183 EnableRecurMode(m_rec.Recurring);
186 void TaskEditDlg::OnEndDateCheckbox(wxCommandEvent &event)
188 m_RecurEndDateCtrl->Enable( !m_NeverEndsCheck->IsChecked() );
190 // make sure there is a recent date in the ctrl
191 MakeDateRecent(!m_NeverEndsCheck->IsChecked(), m_RecurEndDateCtrl);
194 void TaskEditDlg::OnReminderCheck(wxCommandEvent &event)
196 EnableReminderDate(m_ReminderCheck->IsChecked());
198 // make sure the first date is in a recent range, if not previously
199 // valid...
200 MakeDateRecent(m_ReminderCheck->IsChecked(), m_ReminderDateCtrl);
203 void TaskEditDlg::set_properties()
205 // begin wxGlade: TaskEditDlg::set_properties
206 SetTitle(wxT("Task Event"));
207 m_TaskSummary->SetFocus();
208 m_TaskSummary->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_rec.Summary)));
209 m_StatusChoice->SetSelection(0);
210 m_PriorityChoice->SetSelection(1);
211 m_DueDateCtrl->SetMinSize(wxSize(110, -1));
212 m_DueDateCtrl->SetValidator(DateTimeValidator(&m_DueDateObj.m_date));
213 m_DueHoursSpinner->SetMinSize(wxSize(45, -1));
214 m_DueHoursSpinner->SetValidator(wxGenericValidator(&m_DueDateObj.m_hour));
215 m_DueMinutesSpinner->SetMinSize(wxSize(45, -1));
216 m_DueMinutesSpinner->SetValidator(wxGenericValidator(&m_DueDateObj.m_min));
217 m_TimezoneChoice->SetSelection(0);
218 m_ReminderDateCtrl->SetMinSize(wxSize(110, -1));
219 m_ReminderDateCtrl->SetValidator(DateTimeValidator(&m_ReminderDateObj.m_date));
220 m_ReminderHoursSpinner->SetMinSize(wxSize(45, -1));
221 m_ReminderHoursSpinner->SetToolTip(wxT("Set Reminder to 0 to disable"));
222 m_ReminderHoursSpinner->SetValidator(wxGenericValidator(&m_ReminderDateObj.m_hour));
223 m_ReminderMinutesSpinner->SetMinSize(wxSize(45, -1));
224 m_ReminderMinutesSpinner->SetToolTip(wxT("Set Reminder to 0 to disable"));
225 m_ReminderMinutesSpinner->SetValidator(wxGenericValidator(&m_ReminderDateObj.m_min));
226 m_RecurrenceChoice->SetValidator(wxGenericValidator(&m_recur_choice));
227 m_RecurrenceChoice->SetSelection(0);
228 m_IntervalSpinner->SetMinSize(wxSize(45, -1));
229 m_IntervalSpinner->SetValidator(wxGenericValidator(&m_interval));
230 m_SunCheck->SetValidator(wxGenericValidator(&m_weekdays[0]));
231 m_MonCheck->SetValidator(wxGenericValidator(&m_weekdays[1]));
232 m_TueCheck->SetValidator(wxGenericValidator(&m_weekdays[2]));
233 m_WedCheck->SetValidator(wxGenericValidator(&m_weekdays[3]));
234 m_ThuCheck->SetValidator(wxGenericValidator(&m_weekdays[4]));
235 m_FriCheck->SetValidator(wxGenericValidator(&m_weekdays[5]));
236 m_SatCheck->SetValidator(wxGenericValidator(&m_weekdays[6]));
237 RecurRelativeDateLabel->SetToolTip(wxT("Relative monthly or yearly dates take the weekday of the start date into account. (eg. every first Sunday of month)"));
238 m_RelativeDateCheck->SetToolTip(wxT("Relative monthly or yearly dates take the weekday of the start date into account. (eg. every first Sunday of month)"));
239 m_RelativeDateCheck->SetValidator(wxGenericValidator(&m_relative_date));
240 m_NeverEndsCheck->SetValidator(wxGenericValidator(&m_rec.Perpetual));
241 m_NeverEndsCheck->SetValue(1);
242 m_RecurEndDateCtrl->SetMinSize(wxSize(110, -1));
243 m_RecurEndDateCtrl->Enable(false);
244 m_RecurEndDateCtrl->SetValidator(DateTimeValidator(&m_RecurEndDateObj.m_date));
245 m_CategoriesText->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_categories)));
246 m_NotesText->SetMinSize(wxSize(-1, 71));
247 m_NotesText->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_rec.Notes)));
248 // end wxGlade
251 void TaskEditDlg::do_layout()
253 // begin wxGlade: TaskEditDlg::do_layout
254 wxBoxSizer* sizer_surround = new wxBoxSizer(wxVERTICAL);
255 wxBoxSizer* sizer_1 = new wxBoxSizer(wxVERTICAL);
256 wxFlexGridSizer* grid_sizer_3 = new wxFlexGridSizer(2, 2, 5, 5);
257 wxFlexGridSizer* grid_sizer_4 = new wxFlexGridSizer(5, 2, 5, 5);
258 wxBoxSizer* sizer_8 = new wxBoxSizer(wxHORIZONTAL);
259 wxBoxSizer* m_DaysCtrlsSizer = new wxBoxSizer(wxHORIZONTAL);
260 wxBoxSizer* m_IntervalCtrlsSizer = new wxBoxSizer(wxHORIZONTAL);
261 wxFlexGridSizer* grid_sizer_2 = new wxFlexGridSizer(10, 2, 5, 5);
262 wxBoxSizer* sizer_5_copy = new wxBoxSizer(wxHORIZONTAL);
263 wxBoxSizer* sizer_3 = new wxBoxSizer(wxHORIZONTAL);
264 wxFlexGridSizer* grid_sizer_1 = new wxFlexGridSizer(2, 2, 5, 5);
265 grid_sizer_1->Add(label_1, 0, wxALIGN_CENTER_VERTICAL, 0);
266 grid_sizer_1->Add(m_TaskSummary, 0, wxEXPAND, 0);
267 grid_sizer_1->AddGrowableCol(1);
268 sizer_1->Add(grid_sizer_1, 0, wxEXPAND, 0);
269 sizer_1->Add(static_line_1, 0, wxALL|wxEXPAND, 5);
270 grid_sizer_2->Add(label_2, 0, wxALIGN_CENTER_VERTICAL, 0);
271 grid_sizer_2->Add(m_StatusChoice, 0, 0, 0);
272 grid_sizer_2->Add(label_9, 0, wxALIGN_CENTER_VERTICAL, 0);
273 grid_sizer_2->Add(m_PriorityChoice, 0, 0, 0);
274 grid_sizer_2->Add(label_5, 0, wxALIGN_CENTER_VERTICAL, 0);
275 sizer_3->Add(m_DueCheck, 0, 0, 0);
276 sizer_3->Add(m_DueDateCtrl, 0, 0, 0);
277 sizer_3->Add(20, 20, 0, 0, 0);
278 sizer_3->Add(m_DueHoursSpinner, 0, 0, 0);
279 sizer_3->Add(label_11, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 1);
280 sizer_3->Add(m_DueMinutesSpinner, 0, 0, 0);
281 grid_sizer_2->Add(sizer_3, 1, wxEXPAND, 0);
282 grid_sizer_2->Add(label_8, 0, wxALIGN_CENTER_VERTICAL, 0);
283 grid_sizer_2->Add(m_TimezoneChoice, 0, 0, 0);
284 grid_sizer_2->Add(label_10, 0, wxALIGN_CENTER_VERTICAL, 0);
285 sizer_5_copy->Add(m_ReminderCheck, 0, 0, 0);
286 sizer_5_copy->Add(m_ReminderDateCtrl, 0, 0, 0);
287 sizer_5_copy->Add(20, 20, 0, 0, 0);
288 sizer_5_copy->Add(m_ReminderHoursSpinner, 0, 0, 5);
289 sizer_5_copy->Add(label_6, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 1);
290 sizer_5_copy->Add(m_ReminderMinutesSpinner, 0, wxRIGHT, 5);
291 grid_sizer_2->Add(sizer_5_copy, 1, wxEXPAND, 0);
292 grid_sizer_2->AddGrowableCol(1);
293 sizer_1->Add(grid_sizer_2, 0, wxEXPAND, 0);
294 sizer_1->Add(static_line_2, 0, wxALL|wxEXPAND, 5);
295 grid_sizer_4->Add(label_18, 0, wxALIGN_CENTER_VERTICAL, 0);
296 grid_sizer_4->Add(m_RecurrenceChoice, 0, 0, 0);
297 grid_sizer_4->Add(RecurIntervalLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
298 m_IntervalCtrlsSizer->Add(RecurIntervalLabelB, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
299 m_IntervalCtrlsSizer->Add(m_IntervalSpinner, 0, wxRIGHT, 5);
300 m_IntervalCtrlsSizer->Add(m_IntervalUnitLabel, 1, wxALIGN_CENTER_VERTICAL, 0);
301 grid_sizer_4->Add(m_IntervalCtrlsSizer, 1, wxEXPAND, 0);
302 grid_sizer_4->Add(RecurDaysLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
303 m_DaysCtrlsSizer->Add(m_SunCheck, 0, wxRIGHT, 5);
304 m_DaysCtrlsSizer->Add(m_MonCheck, 0, wxRIGHT, 5);
305 m_DaysCtrlsSizer->Add(m_TueCheck, 0, wxRIGHT, 5);
306 m_DaysCtrlsSizer->Add(m_WedCheck, 0, wxRIGHT, 5);
307 m_DaysCtrlsSizer->Add(m_ThuCheck, 0, wxRIGHT, 5);
308 m_DaysCtrlsSizer->Add(m_FriCheck, 0, wxRIGHT, 5);
309 m_DaysCtrlsSizer->Add(m_SatCheck, 0, wxRIGHT, 5);
310 grid_sizer_4->Add(m_DaysCtrlsSizer, 1, wxEXPAND, 0);
311 grid_sizer_4->Add(RecurRelativeDateLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
312 grid_sizer_4->Add(m_RelativeDateCheck, 0, 0, 0);
313 grid_sizer_4->Add(RecurEndDateLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
314 sizer_8->Add(m_NeverEndsCheck, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 10);
315 sizer_8->Add(m_RecurEndDateCtrl, 0, wxALIGN_CENTER_VERTICAL, 0);
316 grid_sizer_4->Add(sizer_8, 1, wxEXPAND, 0);
317 grid_sizer_4->AddGrowableCol(1);
318 sizer_1->Add(grid_sizer_4, 0, wxEXPAND, 0);
319 sizer_1->Add(static_line_3, 0, wxALL|wxEXPAND, 5);
320 grid_sizer_3->Add(label_4, 0, wxALIGN_CENTER_VERTICAL, 0);
321 grid_sizer_3->Add(m_CategoriesText, 0, wxEXPAND, 0);
322 grid_sizer_3->Add(label_3, 0, wxRIGHT, 5);
323 grid_sizer_3->Add(m_NotesText, 1, wxEXPAND, 0);
324 grid_sizer_3->AddGrowableCol(1);
325 sizer_1->Add(grid_sizer_3, 1, wxEXPAND, 0);
326 sizer_surround->Add(sizer_1, 1, wxALL|wxEXPAND, 10);
327 SetSizer(sizer_surround);
328 sizer_surround->Fit(this);
329 Layout();
330 // end wxGlade
332 m_top_sizer = sizer_surround;
335 bool TaskEditDlg::TransferDataToWindow()
337 // prepare temporary variables, from record
339 m_rec.Categories.CategoryList2Str(m_categories);
341 // due time
342 m_DueCheck->SetValue(m_rec.DueTime.IsValid());
343 EnableDueDate(m_rec.DueTime.IsValid());
344 m_DueDateObj.Set(m_rec.DueTime.Time);
346 // alarm / reminder time
347 m_ReminderCheck->SetValue(m_rec.AlarmTime.IsValid());
348 EnableReminderDate(m_rec.AlarmTime.IsValid());
349 m_ReminderDateObj.Set(m_rec.AlarmTime.Time);
351 // status
352 #define S_NOT_STARTED 0
353 #define S_IN_PROGRESS 1
354 #define S_COMPLETED 2
355 #define S_WAITING 3
356 #define S_DEFERRED 4
357 switch( m_rec.StatusFlag )
359 case Barry::Task::NotStarted:
360 default:
361 m_StatusChoice->SetSelection(S_NOT_STARTED);
362 break;
364 case Barry::Task::InProgress:
365 m_StatusChoice->SetSelection(S_IN_PROGRESS);
366 break;
368 case Barry::Task::Completed:
369 m_StatusChoice->SetSelection(S_COMPLETED);
370 break;
372 case Barry::Task::Waiting:
373 m_StatusChoice->SetSelection(S_WAITING);
374 break;
376 case Barry::Task::Deferred:
377 m_StatusChoice->SetSelection(S_DEFERRED);
378 break;
381 // priority
382 #define P_HIGH 0
383 #define P_NORMAL 1
384 #define P_LOW 2
385 switch( m_rec.PriorityFlag )
387 case Barry::Task::High:
388 m_PriorityChoice->SetSelection(P_HIGH);
389 break;
391 case Barry::Task::Normal:
392 default:
393 m_PriorityChoice->SetSelection(P_NORMAL);
394 break;
396 case Barry::Task::Low:
397 m_PriorityChoice->SetSelection(P_LOW);
398 break;
401 // set the timezone choice only if the record's data is valid
402 m_TimezoneChoice->SetSelection(0); // default to none
403 if( m_rec.TimeZoneValid ) {
404 TimeZones::const_iterator i = m_zones->Find(m_rec.TimeZoneCode);
405 if( i != m_zones->end() ) {
406 int array_index = i - m_zones->begin();
407 // select item, skipping 0's "none" option
408 m_TimezoneChoice->SetSelection(array_index + 1);
412 // Note that recur_choice values are (zero-based) in the following
413 // order:
414 // None, Daily, Weekly, Monthly, Yearly
415 #define RC_NONE 0
416 #define RC_DAILY 1
417 #define RC_WEEKLY 2
418 #define RC_MONTHLY 3
419 #define RC_YEARLY 4
421 if( m_rec.Recurring ) {
422 switch( m_rec.RecurringType )
424 case Barry::RecurBase::Day:
425 m_recur_choice = RC_DAILY;
426 m_relative_date = false;
427 break;
429 case Barry::RecurBase::MonthByDate:
430 m_recur_choice = RC_MONTHLY;
431 m_relative_date = false;
432 break;
434 case Barry::RecurBase::MonthByDay:
435 m_recur_choice = RC_MONTHLY;
436 m_relative_date = true;
437 break;
439 case Barry::RecurBase::YearByDate:
440 m_recur_choice = RC_YEARLY;
441 m_relative_date = false;
442 break;
444 case Barry::RecurBase::YearByDay:
445 m_recur_choice = RC_YEARLY;
446 m_relative_date = true;
447 break;
449 case Barry::RecurBase::Week:
450 m_recur_choice = RC_WEEKLY;
451 m_relative_date = false;
452 m_weekdays[0] = m_rec.WeekDays & CAL_WD_SUN;
453 m_weekdays[1] = m_rec.WeekDays & CAL_WD_MON;
454 m_weekdays[2] = m_rec.WeekDays & CAL_WD_TUE;
455 m_weekdays[3] = m_rec.WeekDays & CAL_WD_WED;
456 m_weekdays[4] = m_rec.WeekDays & CAL_WD_THU;
457 m_weekdays[5] = m_rec.WeekDays & CAL_WD_FRI;
458 m_weekdays[6] = m_rec.WeekDays & CAL_WD_SAT;
459 break;
461 default:
462 cerr << "Bad RecurringType in CalendarEditDlg" << endl;
463 m_recur_choice = RC_NONE;
464 m_relative_date = false;
467 else {
468 m_recur_choice = RC_NONE;
469 m_relative_date = false;
472 m_interval = m_rec.Interval;
474 m_RecurEndDateObj.Set(m_rec.RecurringEndTime.Time);
475 if( m_rec.Perpetual ) {
476 m_RecurEndDateCtrl->Enable(false);
478 else {
479 m_RecurEndDateCtrl->Enable();
482 EnableRecurMode(m_rec.Recurring);
484 m_strings.Refresh();
486 return wxDialog::TransferDataToWindow();
489 bool TaskEditDlg::TransferDataFromWindow()
491 if( !wxDialog::TransferDataFromWindow() )
492 return false;
494 m_strings.Sync();
496 m_rec.Categories.CategoryStr2List(m_categories);
498 // due time
499 if( m_DueCheck->IsChecked() )
500 m_rec.DueTime.Time = m_DueDateObj.Get();
501 else
502 m_rec.DueTime.clear();
504 // alarm / reminder time
505 if( m_ReminderCheck->IsChecked() )
506 m_rec.AlarmTime.Time = m_ReminderDateObj.Get();
507 else
508 m_rec.AlarmTime.clear();
510 // status
511 switch( m_StatusChoice->GetSelection() )
513 case S_NOT_STARTED:
514 default:
515 m_rec.StatusFlag = Barry::Task::NotStarted;
516 break;
518 case S_IN_PROGRESS:
519 m_rec.StatusFlag = Barry::Task::InProgress;
520 break;
522 case S_COMPLETED:
523 m_rec.StatusFlag = Barry::Task::Completed;
524 break;
526 case S_WAITING:
527 m_rec.StatusFlag = Barry::Task::Waiting;
528 break;
530 case S_DEFERRED:
531 m_rec.StatusFlag = Barry::Task::Deferred;
532 break;
535 // priority
536 switch( m_PriorityChoice->GetSelection() )
538 case P_HIGH:
539 m_rec.PriorityFlag = Barry::Task::High;
540 break;
542 case P_NORMAL:
543 default:
544 m_rec.PriorityFlag = Barry::Task::Normal;
545 break;
547 case P_LOW:
548 m_rec.PriorityFlag = Barry::Task::Low;
549 break;
552 // set the timezone choice only if the record's data is valid
553 int sel = m_TimezoneChoice->GetSelection();
554 if( sel > 0 ) {
555 m_rec.TimeZoneCode = (*m_zones)[sel-1].Index;
556 m_rec.TimeZoneValid = true;
558 else {
559 // default was selected
560 m_rec.TimeZoneValid = false;
563 // Note that recur_choice values are (zero-based) in the following
564 // order:
565 // None, Daily, Weekly, Monthly, Yearly
566 switch( m_recur_choice )
568 case RC_NONE:
569 default:
570 m_rec.Recurring = false;
571 break;
573 case RC_DAILY:
574 m_rec.Recurring = true;
575 m_rec.RecurringType = Barry::RecurBase::Day;
576 break;
578 case RC_WEEKLY:
579 m_rec.Recurring = true;
580 m_rec.RecurringType = Barry::RecurBase::Week;
581 m_rec.WeekDays = 0;
582 if( m_weekdays[0] ) m_rec.WeekDays |= CAL_WD_SUN;
583 if( m_weekdays[1] ) m_rec.WeekDays |= CAL_WD_MON;
584 if( m_weekdays[2] ) m_rec.WeekDays |= CAL_WD_TUE;
585 if( m_weekdays[3] ) m_rec.WeekDays |= CAL_WD_WED;
586 if( m_weekdays[4] ) m_rec.WeekDays |= CAL_WD_THU;
587 if( m_weekdays[5] ) m_rec.WeekDays |= CAL_WD_FRI;
588 if( m_weekdays[6] ) m_rec.WeekDays |= CAL_WD_SAT;
589 break;
591 case RC_MONTHLY:
592 m_rec.Recurring = true;
593 if( m_relative_date )
594 m_rec.RecurringType = Barry::RecurBase::MonthByDay;
595 else
596 m_rec.RecurringType = Barry::RecurBase::MonthByDate;
597 break;
599 case RC_YEARLY:
600 m_rec.Recurring = true;
601 if( m_relative_date )
602 m_rec.RecurringType = Barry::RecurBase::YearByDay;
603 else
604 m_rec.RecurringType = Barry::RecurBase::YearByDate;
605 break;
609 m_rec.Interval = m_interval;
611 if( !m_rec.Perpetual ) {
612 m_rec.RecurringEndTime.Time = m_RecurEndDateObj.Get();
615 cout << "TaskEditDlg::TransferDataFromWindow():\n" << m_rec << endl;
616 return true;
619 void TaskEditDlg::EnableDueDate(bool enable)
621 m_DueDateCtrl->Enable(enable);
622 m_DueHoursSpinner->Enable(enable);
623 m_DueMinutesSpinner->Enable(enable);
624 m_RecurrenceChoice->Enable(enable);
626 if( !enable ) {
627 m_RecurrenceChoice->SetSelection(0);
628 EnableRecurMode(false);
632 void TaskEditDlg::EnableReminderDate(bool enable)
634 m_ReminderDateCtrl->Enable(enable);
635 m_ReminderHoursSpinner->Enable(enable);
636 m_ReminderMinutesSpinner->Enable(enable);
639 void TaskEditDlg::EnableRecurMode(bool recur)
641 // show all controls
642 RecurIntervalLabel->Show(recur);
643 RecurIntervalLabelB->Show(recur);
644 m_IntervalSpinner->Show(recur);
645 m_IntervalUnitLabel->Show(recur);
646 RecurDaysLabel->Show(recur);
647 m_SunCheck->Show(recur);
648 m_MonCheck->Show(recur);
649 m_TueCheck->Show(recur);
650 m_WedCheck->Show(recur);
651 m_ThuCheck->Show(recur);
652 m_FriCheck->Show(recur);
653 m_SatCheck->Show(recur);
654 RecurRelativeDateLabel->Show(recur);
655 m_RelativeDateCheck->Show(recur);
656 RecurEndDateLabel->Show(recur);
657 m_NeverEndsCheck->Show(recur);
658 m_RecurEndDateCtrl->Show(recur);
660 // enable based on choice
661 int choice = m_RecurrenceChoice->GetSelection();
662 m_SunCheck->Enable(choice == RC_WEEKLY);
663 m_MonCheck->Enable(choice == RC_WEEKLY);
664 m_TueCheck->Enable(choice == RC_WEEKLY);
665 m_WedCheck->Enable(choice == RC_WEEKLY);
666 m_ThuCheck->Enable(choice == RC_WEEKLY);
667 m_FriCheck->Enable(choice == RC_WEEKLY);
668 m_SatCheck->Enable(choice == RC_WEEKLY);
670 // update labels
671 if( recur ) {
672 switch( m_RecurrenceChoice->GetSelection() )
674 case RC_NONE:
675 default:
676 m_IntervalUnitLabel->SetLabel(_T(""));
677 break;
679 case RC_DAILY:
680 m_IntervalUnitLabel->SetLabel(_T("day(s)"));
681 break;
683 case RC_WEEKLY:
684 m_IntervalUnitLabel->SetLabel(_T("week(s)"));
685 break;
687 case RC_MONTHLY:
688 m_IntervalUnitLabel->SetLabel(_T("month(s)"));
689 break;
691 case RC_YEARLY:
692 m_IntervalUnitLabel->SetLabel(_T("year(s)"));
693 break;
697 RedoLayout();
702 // Note: this file is very similar to CalendarEditDlg.cc, and should be kept
703 // in lock step as much as possible. They are in separate files, since
704 // the GUI code is generated with wxglade