Diffstat (limited to 'libopie/orecurrancewidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/orecurrancewidget.cpp | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/libopie/orecurrancewidget.cpp b/libopie/orecurrancewidget.cpp index db86184..471249d 100644 --- a/libopie/orecurrancewidget.cpp +++ b/libopie/orecurrancewidget.cpp | |||
@@ -5,88 +5,122 @@ | |||
5 | 5 | ||
6 | #include <qpe/timestring.h> | 6 | #include <qpe/timestring.h> |
7 | 7 | ||
8 | #include "orecurrancewidget.h" | 8 | #include "orecurrancewidget.h" |
9 | 9 | ||
10 | // Global Templates for use in setting up the repeat label... | 10 | // Global Templates for use in setting up the repeat label... |
11 | const QString strDayTemplate = QObject::tr("Every"); | 11 | const QString strDayTemplate = QObject::tr("Every"); |
12 | const QString strYearTemplate = QObject::tr("%1 %2 every "); | 12 | const QString strYearTemplate = QObject::tr("%1 %2 every "); |
13 | const QString strMonthDateTemplate = QObject::tr("The %1 every "); | 13 | const QString strMonthDateTemplate = QObject::tr("The %1 every "); |
14 | const QString strMonthDayTemplate = QObject::tr("The %1 %1 of every"); | 14 | const QString strMonthDayTemplate = QObject::tr("The %1 %1 of every"); |
15 | const QString strWeekTemplate = QObject::tr("Every "); | 15 | const QString strWeekTemplate = QObject::tr("Every "); |
16 | const QString dayLabel[] = { QObject::tr("Monday"), | 16 | const QString dayLabel[] = { QObject::tr("Monday"), |
17 | QObject::tr("Tuesday"), | 17 | QObject::tr("Tuesday"), |
18 | QObject::tr("Wednesday"), | 18 | QObject::tr("Wednesday"), |
19 | QObject::tr("Thursday"), | 19 | QObject::tr("Thursday"), |
20 | QObject::tr("Friday"), | 20 | QObject::tr("Friday"), |
21 | QObject::tr("Saturday"), | 21 | QObject::tr("Saturday"), |
22 | QObject::tr("Sunday") }; | 22 | QObject::tr("Sunday") }; |
23 | 23 | ||
24 | 24 | ||
25 | static QString numberPlacing( int x );// return the proper word format for | 25 | static QString numberPlacing( int x );// return the proper word format for |
26 | // x (1st, 2nd, etc) | 26 | // x (1st, 2nd, etc) |
27 | static int week( const QDate &dt ); // what week in the month is dt? | 27 | static int week( const QDate &dt ); // what week in the month is dt? |
28 | 28 | ||
29 | 29 | /** | |
30 | * Constructs the Widget | ||
31 | * @param startOnMonday Does the week start on monday | ||
32 | * @param newStart The start date of the recurrence | ||
33 | * @param parent The parent widget | ||
34 | * @param name the name of object | ||
35 | * @param modal if the dialog should be modal | ||
36 | * @param fl Additional window flags | ||
37 | */ | ||
30 | ORecurranceWidget::ORecurranceWidget( bool startOnMonday, | 38 | ORecurranceWidget::ORecurranceWidget( bool startOnMonday, |
31 | const QDate& newStart, | 39 | const QDate& newStart, |
32 | QWidget* parent, | 40 | QWidget* parent, |
33 | const char* name, | 41 | const char* name, |
34 | bool modal, | 42 | bool modal, |
35 | WFlags fl ) | 43 | WFlags fl ) |
36 | : ORecurranceBase( parent, name, modal, fl ), | 44 | : ORecurranceBase( parent, name, modal, fl ), |
37 | start( newStart ), | 45 | start( newStart ), |
38 | currInterval( None ), | 46 | currInterval( None ), |
39 | startWeekOnMonday( startOnMonday ) | 47 | startWeekOnMonday( startOnMonday ) |
40 | { | 48 | { |
41 | init(); | 49 | init(); |
42 | fraType->setButton( currInterval ); | 50 | fraType->setButton( currInterval ); |
43 | chkNoEnd->setChecked( TRUE ); | 51 | chkNoEnd->setChecked( TRUE ); |
44 | setupNone(); | 52 | setupNone(); |
45 | } | 53 | } |
54 | |||
55 | /** | ||
56 | * Different constructor | ||
57 | * @param startOnMonday Does the week start on monday? | ||
58 | * @param rp Already set ORecur object | ||
59 | * @param startDate The start date | ||
60 | * @param parent The parent widget | ||
61 | * @param name The name of the object | ||
62 | * @param modal | ||
63 | * @param fl The flags for window | ||
64 | */ | ||
46 | ORecurranceWidget::ORecurranceWidget( bool startOnMonday, | 65 | ORecurranceWidget::ORecurranceWidget( bool startOnMonday, |
47 | const ORecur& rp, const QDate& startDate, | 66 | const ORecur& rp, const QDate& startDate, |
48 | QWidget* parent, const char* name, | 67 | QWidget* parent, const char* name, |
49 | bool modal, WFlags fl) | 68 | bool modal, WFlags fl) |
50 | : ORecurranceBase( parent, name, modal, fl ), | 69 | : ORecurranceBase( parent, name, modal, fl ), |
51 | start( startDate ), | 70 | start( startDate ), |
52 | end( rp.endDate() ), | 71 | end( rp.endDate() ), |
53 | startWeekOnMonday( startOnMonday ) | 72 | startWeekOnMonday( startOnMonday ) |
54 | { | 73 | { |
55 | // do some stuff with the repeat pattern | 74 | // do some stuff with the repeat pattern |
56 | init(); | 75 | init(); |
57 | setRecurrence( rp ); | 76 | setRecurrence( rp ); |
58 | } | 77 | } |
59 | 78 | ||
60 | ORecurranceWidget::~ORecurranceWidget() { | 79 | ORecurranceWidget::~ORecurranceWidget() { |
61 | } | 80 | } |
81 | |||
82 | /** | ||
83 | * set the start date | ||
84 | * @param date the new start date | ||
85 | */ | ||
62 | void ORecurranceWidget::setStartDate( const QDate& date ) { | 86 | void ORecurranceWidget::setStartDate( const QDate& date ) { |
63 | qWarning("ORecurranceWidget::setStartDate"); | 87 | qWarning("ORecurranceWidget::setStartDate"); |
64 | setRecurrence( recurrence(), date ); | 88 | setRecurrence( recurrence(), date ); |
65 | } | 89 | } |
90 | /** | ||
91 | * set the recurrence | ||
92 | * @param rp The ORecur object with the new recurrence rules | ||
93 | */ | ||
66 | void ORecurranceWidget::setRecurrence( const ORecur& rp ) { | 94 | void ORecurranceWidget::setRecurrence( const ORecur& rp ) { |
67 | setRecurrence( rp, start ); | 95 | setRecurrence( rp, start ); |
68 | } | 96 | } |
97 | |||
98 | /** | ||
99 | * overloaded method taking ORecur and a new start date | ||
100 | * @param rp Recurrence rule | ||
101 | * @param date The new start date | ||
102 | */ | ||
69 | void ORecurranceWidget::setRecurrence( const ORecur& rp, const QDate& date ) { | 103 | void ORecurranceWidget::setRecurrence( const ORecur& rp, const QDate& date ) { |
70 | start = date; | 104 | start = date; |
71 | end = rp.endDate(); | 105 | end = rp.endDate(); |
72 | switch ( rp.type() ) { | 106 | switch ( rp.type() ) { |
73 | default: | 107 | default: |
74 | case ORecur::NoRepeat: | 108 | case ORecur::NoRepeat: |
75 | currInterval = None; | 109 | currInterval = None; |
76 | setupNone(); | 110 | setupNone(); |
77 | break; | 111 | break; |
78 | case ORecur::Daily: | 112 | case ORecur::Daily: |
79 | currInterval = Day; | 113 | currInterval = Day; |
80 | setupDaily(); | 114 | setupDaily(); |
81 | break; | 115 | break; |
82 | case ORecur::Weekly: | 116 | case ORecur::Weekly: |
83 | currInterval = Week; | 117 | currInterval = Week; |
84 | setupWeekly(); | 118 | setupWeekly(); |
85 | int day, buttons; | 119 | int day, buttons; |
86 | for ( day = 0x01, buttons = 0; buttons < 7; | 120 | for ( day = 0x01, buttons = 0; buttons < 7; |
87 | day = day << 1, buttons++ ) { | 121 | day = day << 1, buttons++ ) { |
88 | if ( rp.days() & day ) { | 122 | if ( rp.days() & day ) { |
89 | if ( startWeekOnMonday ) | 123 | if ( startWeekOnMonday ) |
90 | fraExtra->setButton( buttons ); | 124 | fraExtra->setButton( buttons ); |
91 | else { | 125 | else { |
92 | if ( buttons == 7 ) | 126 | if ( buttons == 7 ) |
@@ -102,48 +136,53 @@ void ORecurranceWidget::setRecurrence( const ORecur& rp, const QDate& date ) { | |||
102 | currInterval = Month; | 136 | currInterval = Month; |
103 | setupMonthly(); | 137 | setupMonthly(); |
104 | fraExtra->setButton( 0 ); | 138 | fraExtra->setButton( 0 ); |
105 | slotMonthLabel( 0 ); | 139 | slotMonthLabel( 0 ); |
106 | break; | 140 | break; |
107 | case ORecur::MonthlyDate: | 141 | case ORecur::MonthlyDate: |
108 | currInterval = Month; | 142 | currInterval = Month; |
109 | setupMonthly(); | 143 | setupMonthly(); |
110 | fraExtra->setButton( 1 ); | 144 | fraExtra->setButton( 1 ); |
111 | slotMonthLabel( 1 ); | 145 | slotMonthLabel( 1 ); |
112 | break; | 146 | break; |
113 | case ORecur::Yearly: | 147 | case ORecur::Yearly: |
114 | currInterval = Year; | 148 | currInterval = Year; |
115 | setupYearly(); | 149 | setupYearly(); |
116 | break; | 150 | break; |
117 | } | 151 | } |
118 | fraType->setButton( currInterval ); | 152 | fraType->setButton( currInterval ); |
119 | spinFreq->setValue( rp.frequency() ); | 153 | spinFreq->setValue( rp.frequency() ); |
120 | if ( !rp.hasEndDate() ) { | 154 | if ( !rp.hasEndDate() ) { |
121 | cmdEnd->setText( tr("No End Date") ); | 155 | cmdEnd->setText( tr("No End Date") ); |
122 | chkNoEnd->setChecked( TRUE ); | 156 | chkNoEnd->setChecked( TRUE ); |
123 | } else | 157 | } else |
124 | cmdEnd->setText( TimeString::shortDate( end ) ); | 158 | cmdEnd->setText( TimeString::shortDate( end ) ); |
125 | } | 159 | } |
160 | |||
161 | /** | ||
162 | * the user selected recurrence rule. | ||
163 | * @return The recurrence rule. | ||
164 | */ | ||
126 | ORecur ORecurranceWidget::recurrence()const { | 165 | ORecur ORecurranceWidget::recurrence()const { |
127 | QListIterator<QToolButton> it( listRTypeButtons ); | 166 | QListIterator<QToolButton> it( listRTypeButtons ); |
128 | QListIterator<QToolButton> itExtra( listExtra ); | 167 | QListIterator<QToolButton> itExtra( listExtra ); |
129 | ORecur rpTmp; | 168 | ORecur rpTmp; |
130 | int i; | 169 | int i; |
131 | for ( i = 0; *it; ++it, i++ ) { | 170 | for ( i = 0; *it; ++it, i++ ) { |
132 | if ( (*it)->isOn() ) { | 171 | if ( (*it)->isOn() ) { |
133 | switch ( i ) { | 172 | switch ( i ) { |
134 | case None: | 173 | case None: |
135 | rpTmp.setType( ORecur::NoRepeat ); | 174 | rpTmp.setType( ORecur::NoRepeat ); |
136 | break; | 175 | break; |
137 | case Day: | 176 | case Day: |
138 | rpTmp.setType( ORecur::Daily ); | 177 | rpTmp.setType( ORecur::Daily ); |
139 | break; | 178 | break; |
140 | case Week:{ | 179 | case Week:{ |
141 | rpTmp.setType( ORecur::Weekly ); | 180 | rpTmp.setType( ORecur::Weekly ); |
142 | int day; | 181 | int day; |
143 | int day2 = 0; | 182 | int day2 = 0; |
144 | for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) { | 183 | for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) { |
145 | if ( (*itExtra)->isOn() ) { | 184 | if ( (*itExtra)->isOn() ) { |
146 | if ( startWeekOnMonday ) | 185 | if ( startWeekOnMonday ) |
147 | day2 |= day; | 186 | day2 |= day; |
148 | else { | 187 | else { |
149 | if ( day == 1 ) | 188 | if ( day == 1 ) |
@@ -159,48 +198,53 @@ ORecur ORecurranceWidget::recurrence()const { | |||
159 | case Month: | 198 | case Month: |
160 | if ( cmdExtra1->isOn() ) | 199 | if ( cmdExtra1->isOn() ) |
161 | rpTmp.setType( ORecur::MonthlyDay ); | 200 | rpTmp.setType( ORecur::MonthlyDay ); |
162 | else if ( cmdExtra2->isOn() ) | 201 | else if ( cmdExtra2->isOn() ) |
163 | rpTmp.setType( ORecur::MonthlyDate ); | 202 | rpTmp.setType( ORecur::MonthlyDate ); |
164 | // figure out the montly day... | 203 | // figure out the montly day... |
165 | rpTmp.setPosition( week( start ) ); | 204 | rpTmp.setPosition( week( start ) ); |
166 | break; | 205 | break; |
167 | case Year: | 206 | case Year: |
168 | rpTmp.setType( ORecur::Yearly ); | 207 | rpTmp.setType( ORecur::Yearly ); |
169 | break; | 208 | break; |
170 | } | 209 | } |
171 | break; // no need to keep looking! | 210 | break; // no need to keep looking! |
172 | } | 211 | } |
173 | } | 212 | } |
174 | rpTmp.setFrequency(spinFreq->value() ); | 213 | rpTmp.setFrequency(spinFreq->value() ); |
175 | rpTmp.setHasEndDate( !chkNoEnd->isChecked() ); | 214 | rpTmp.setHasEndDate( !chkNoEnd->isChecked() ); |
176 | if ( rpTmp.hasEndDate() ) { | 215 | if ( rpTmp.hasEndDate() ) { |
177 | rpTmp.setEndDate( end ); | 216 | rpTmp.setEndDate( end ); |
178 | } | 217 | } |
179 | // timestamp it... | 218 | // timestamp it... |
180 | // rpTmp.setCreateTime( ); current DateTime is already set -zecke | 219 | // rpTmp.setCreateTime( ); current DateTime is already set -zecke |
181 | return rpTmp; | 220 | return rpTmp; |
182 | } | 221 | } |
222 | |||
223 | /** | ||
224 | * Return the end date of the recurrence. This is only | ||
225 | * valid if the recurrence rule does contain an enddate | ||
226 | */ | ||
183 | QDate ORecurranceWidget::endDate()const { | 227 | QDate ORecurranceWidget::endDate()const { |
184 | return end; | 228 | return end; |
185 | } | 229 | } |
186 | void ORecurranceWidget::slotSetRType(int rtype) { | 230 | void ORecurranceWidget::slotSetRType(int rtype) { |
187 | // now call the right function based on the type... | 231 | // now call the right function based on the type... |
188 | currInterval = static_cast<repeatButtons>(rtype); | 232 | currInterval = static_cast<repeatButtons>(rtype); |
189 | switch ( currInterval ) { | 233 | switch ( currInterval ) { |
190 | case None: | 234 | case None: |
191 | setupNone(); | 235 | setupNone(); |
192 | break; | 236 | break; |
193 | case Day: | 237 | case Day: |
194 | setupDaily(); | 238 | setupDaily(); |
195 | break; | 239 | break; |
196 | case Week: | 240 | case Week: |
197 | setupWeekly(); | 241 | setupWeekly(); |
198 | slotWeekLabel(); | 242 | slotWeekLabel(); |
199 | break; | 243 | break; |
200 | case Month: | 244 | case Month: |
201 | setupMonthly(); | 245 | setupMonthly(); |
202 | cmdExtra2->setOn( TRUE ); | 246 | cmdExtra2->setOn( TRUE ); |
203 | slotMonthLabel( 1 ); | 247 | slotMonthLabel( 1 ); |
204 | break; | 248 | break; |
205 | case Year: | 249 | case Year: |
206 | setupYearly(); | 250 | setupYearly(); |