summaryrefslogtreecommitdiffabout
path: root/libkcal/kincidenceformatter.cpp
Unidiff
Diffstat (limited to 'libkcal/kincidenceformatter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/kincidenceformatter.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/libkcal/kincidenceformatter.cpp b/libkcal/kincidenceformatter.cpp
index e506a96..d67ad52 100644
--- a/libkcal/kincidenceformatter.cpp
+++ b/libkcal/kincidenceformatter.cpp
@@ -38,285 +38,295 @@ KIncidenceFormatter* KIncidenceFormatter::instance()
38KIncidenceFormatter::~KIncidenceFormatter() 38KIncidenceFormatter::~KIncidenceFormatter()
39{ 39{
40 if (mInstance == this) 40 if (mInstance == this)
41 mInstance = insd.setObject(0); 41 mInstance = insd.setObject(0);
42 //qDebug("KIncidenceFormatter::~KIncidenceFormatter "); 42 //qDebug("KIncidenceFormatter::~KIncidenceFormatter ");
43} 43}
44KIncidenceFormatter::KIncidenceFormatter() 44KIncidenceFormatter::KIncidenceFormatter()
45{ 45{
46 mColorMode = 0; 46 mColorMode = 0;
47} 47}
48void KIncidenceFormatter::setEvent(Event *event) 48void KIncidenceFormatter::setEvent(Event *event)
49{ 49{
50 int mode = 0; 50 int mode = 0;
51 mCurrentIncidence = event; 51 mCurrentIncidence = event;
52 bool shortDate = true; 52 bool shortDate = true;
53 if ( mode == 0 ) { 53 if ( mode == 0 ) {
54 addTag("h3",deTag(event->summary())); 54 addTag("h3",deTag(event->summary()));
55 } 55 }
56 else { 56 else {
57 if ( mColorMode == 1 ) { 57 if ( mColorMode == 1 ) {
58 mText +="<font color=\"#00A000\">"; 58 mText +="<font color=\"#00A000\">";
59 } 59 }
60 if ( mColorMode == 2 ) { 60 if ( mColorMode == 2 ) {
61 mText +="<font color=\"#C00000\">"; 61 mText +="<font color=\"#C00000\">";
62 } 62 }
63 // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>"; 63 // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>";
64 if ( mode == 1 ) { 64 if ( mode == 1 ) {
65 addTag("h2",i18n( "Local: " ) +deTag(event->summary())); 65 addTag("h2",i18n( "Local: " ) +deTag(event->summary()));
66 } else { 66 } else {
67 addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); 67 addTag("h2",i18n( "Remote: " ) +deTag(event->summary()));
68 } 68 }
69 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); 69 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) );
70 if ( mColorMode ) 70 if ( mColorMode )
71 mText += "</font>"; 71 mText += "</font>";
72 } 72 }
73 if (event->cancelled ()) { 73 if (event->cancelled ()) {
74 mText +="<font color=\"#B00000\">"; 74 mText +="<font color=\"#B00000\">";
75 addTag("i",i18n("This event has been cancelled!")); 75 addTag("i",i18n("This event has been cancelled!"));
76 mText.append("<br>"); 76 mText.append("<br>");
77 mText += "</font>"; 77 mText += "</font>";
78 } 78 }
79 if (!event->location().isEmpty()) { 79 if (!event->location().isEmpty()) {
80 addTag("b",i18n("Location: ")); 80 addTag("b",i18n("Location: "));
81 mText.append(deTag(event->location())+"<br>"); 81 mText.append(deTag(event->location())+"<br>");
82 } 82 }
83 if (event->doesFloat()) { 83 if (event->doesFloat()) {
84 if (event->isMultiDay()) { 84 if (event->isMultiDay()) {
85 mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>") 85 mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>")
86 .arg(event->dtStartDateStr(shortDate)) 86 .arg(event->dtStartDateStr(shortDate))
87 .arg(event->dtEndDateStr(shortDate))); 87 .arg(event->dtEndDateStr(shortDate)));
88 } else { 88 } else {
89 mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate ))); 89 mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate )));
90 } 90 }
91 } else { 91 } else {
92 if (event->isMultiDay()) { 92 if (event->isMultiDay()) {
93 mText.append(i18n("<p><b>From:</b> %1</p> ") 93 mText.append(i18n("<p><b>From:</b> %1</p> ")
94 .arg(event->dtStartStr( shortDate))); 94 .arg(event->dtStartStr( shortDate)));
95 mText.append(i18n("<p><b>To:</b> %1</p>") 95 mText.append(i18n("<p><b>To:</b> %1</p>")
96 .arg(event->dtEndStr(shortDate))); 96 .arg(event->dtEndStr(shortDate)));
97 } else { 97 } else {
98 mText.append(i18n("<p><b>On:</b> %1</p> ") 98 mText.append(i18n("<p><b>On:</b> %1</p> ")
99 .arg(event->dtStartDateStr( shortDate ))); 99 .arg(event->dtStartDateStr( shortDate )));
100 mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>") 100 mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>")
101 .arg(event->dtStartTimeStr()) 101 .arg(event->dtStartTimeStr())
102 .arg(event->dtEndTimeStr())); 102 .arg(event->dtEndTimeStr()));
103 } 103 }
104 } 104 }
105 105
106 if (event->recurrence()->doesRecur()) { 106 if (event->recurrence()->doesRecur()) {
107 107
108 QString recurText = event->recurrence()->recurrenceText(); 108 QString recurText = event->recurrence()->recurrenceText();
109 addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>"); 109 addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>");
110 110
111 bool ok; 111 bool ok;
112 QDate start = QDate::currentDate(); 112 QDate start = QDate::currentDate();
113 QDateTime next; 113 QDateTime next;
114 next = event->getNextOccurence( QDateTime::currentDateTime() , &ok ); 114 next = event->getNextOccurence( QDateTime::currentDateTime() , &ok );
115 if ( ok ) { 115 if ( ok ) {
116 addTag("p",i18n("<b>Next recurrence is on:</b>") ); 116 addTag("p",i18n("<b>Next recurrence is on:</b>") );
117 addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate )); 117 addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate ));
118 118
119 } else { 119 } else {
120 bool last; 120 bool last;
121 QDate nextd; 121 QDate nextd;
122 nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last ); 122 nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last );
123 if ( last ) { 123 if ( last ) {
124 addTag("p",i18n("<b>Last recurrence was on:</b>") ); 124 addTag("p",i18n("<b>Last recurrence was on:</b>") );
125 addTag("p", KGlobal::locale()->formatDate( nextd, shortDate )); 125 addTag("p", KGlobal::locale()->formatDate( nextd, shortDate ));
126 } 126 }
127 } 127 }
128 } 128 }
129 129
130 130
131 if (event->isAlarmEnabled()) { 131 if (event->isAlarmEnabled()) {
132 Alarm *alarm =event->alarms().first() ; 132 Alarm *alarm =event->alarms().first() ;
133 QDateTime t = alarm->time(); 133 QDateTime t = alarm->time();
134 int min = t.secsTo( event->dtStart() )/60; 134 QString s =i18n("( %1 before )").arg( alarm->offsetText() );
135 QString s =i18n("(%1 min before)").arg( min );
136 addTag("p",i18n("<b>Alarm on: </b>") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate )); 135 addTag("p",i18n("<b>Alarm on: </b>") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate ));
137 //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); 136 //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate ));
138 //addTag("p",s); 137 //addTag("p",s);
139 } 138 }
140 139
140
141
141 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); 142 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() );
142 // mText.append(event->secrecyStr()+"<br>"); 143 // mText.append(event->secrecyStr()+"<br>");
143 formatCategories(event); 144 formatCategories(event);
144 if ( mDetails ) { 145 if ( mDetails ) {
145 if (!event->description().isEmpty()) { 146 if (!event->description().isEmpty()) {
146 addTag("p",i18n("<b>Details: </b>")); 147 addTag("p",i18n("<b>Details: </b>"));
147 addTag("p",deTag(event->description())); 148 addTag("p",deTag(event->description()));
148 } 149 }
149 } 150 }
150 151
151 formatReadOnly(event); 152 formatReadOnly(event);
152 formatAttendees(event); 153 formatAttendees(event);
153 154
154 if ( mCreated ) { 155 if ( mCreated ) {
155 addTag("p",i18n("<b>Created: ") +" </b>"); 156 addTag("p",i18n("<b>Created: ") +" </b>");
156 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); 157 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate ));
157 158
158 } 159 }
159 if ( mModified ) { 160 if ( mModified ) {
160 addTag("p",i18n("<b>Last modified: ") +" </b>"); 161 addTag("p",i18n("<b>Last modified: ") +" </b>");
161 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); 162 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate ));
162 163
163 } 164 }
164 165
165} 166}
166 167
167void KIncidenceFormatter::setTodo(Todo *event ) 168void KIncidenceFormatter::setTodo(Todo *event )
168{ 169{
169 int mode = 0; 170 int mode = 0;
170 mCurrentIncidence = event; 171 mCurrentIncidence = event;
171 bool shortDate = true; 172 bool shortDate = true;
172 if (mode == 0 ) 173 if (mode == 0 )
173 addTag("h3",deTag(event->summary())); 174 addTag("h3",deTag(event->summary()));
174 else { 175 else {
175 if ( mColorMode == 1 ) { 176 if ( mColorMode == 1 ) {
176 mText +="<font color=\"#00A000\">"; 177 mText +="<font color=\"#00A000\">";
177 } 178 }
178 if ( mColorMode == 2 ) { 179 if ( mColorMode == 2 ) {
179 mText +="<font color=\"#B00000\">"; 180 mText +="<font color=\"#B00000\">";
180 } 181 }
181 if ( mode == 1 ) { 182 if ( mode == 1 ) {
182 addTag("h2",i18n( "Local: " ) +deTag(event->summary())); 183 addTag("h2",i18n( "Local: " ) +deTag(event->summary()));
183 } else { 184 } else {
184 addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); 185 addTag("h2",i18n( "Remote: " ) +deTag(event->summary()));
185 } 186 }
186 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); 187 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) );
187 if ( mColorMode ) 188 if ( mColorMode )
188 mText += "</font>"; 189 mText += "</font>";
189 } 190 }
190 if ( event->percentComplete() == 100 && event->hasCompletedDate() ) { 191 if ( event->percentComplete() == 100 && event->hasCompletedDate() ) {
191 mText +="<font color=\"#B00000\">"; 192 mText +="<font color=\"#B00000\">";
192 addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(shortDate) ) ); 193 addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(shortDate) ) );
193 mText += "</font>"; 194 mText += "</font>";
194 } else { 195 } else {
195 mText.append(i18n("<p><i>%1 % completed</i></p>") 196 mText.append(i18n("<p><i>%1 % completed</i></p>")
196 .arg(event->percentComplete())); 197 .arg(event->percentComplete()));
197 } 198 }
198 if (event->cancelled ()) { 199 if (event->cancelled ()) {
199 mText +="<font color=\"#B00000\">"; 200 mText +="<font color=\"#B00000\">";
200 addTag("i",i18n("This todo has been cancelled!")); 201 addTag("i",i18n("This todo has been cancelled!"));
201 mText.append("<br>"); 202 mText.append("<br>");
202 mText += "</font>"; 203 mText += "</font>";
203 } 204 }
204 205
205 if (!event->location().isEmpty()) { 206 if (!event->location().isEmpty()) {
206 addTag("b",i18n("Location: ")); 207 addTag("b",i18n("Location: "));
207 mText.append(deTag(event->location())+"<br>"); 208 mText.append(deTag(event->location())+"<br>");
208 } 209 }
209 210
210 if (event->recurrence()->doesRecur()) { 211 if (event->recurrence()->doesRecur()) {
211 212
212 QString recurText = event->recurrence()->recurrenceText(); 213 QString recurText = event->recurrence()->recurrenceText();
213 addTag("p","<em>" + i18n("This is a %1 recurring todo.").arg(recurText ) + "</em>"); 214 addTag("p","<em>" + i18n("This is a %1 recurring todo.").arg(recurText ) + "</em>");
214 } 215 }
215 216
216 if (event->hasStartDate()) { 217 if (event->hasStartDate()) {
217 mText.append(i18n("<p><b>Start on:</b> %1</p>").arg(event->dtStartStr(shortDate))); 218 mText.append(i18n("<p><b>Start on:</b> %1</p>").arg(event->dtStartStr(shortDate)));
218 } 219 }
219 220
220 221
221 if (event->hasDueDate()) { 222 if (event->hasDueDate()) {
222 mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(shortDate))); 223 mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(shortDate)));
223 } 224 }
224 mText.append(i18n("<p><b>Priority:</b> %2</p>") 225 mText.append(i18n("<p><b>Priority:</b> %2</p>")
225 .arg(QString::number(event->priority()))); 226 .arg(QString::number(event->priority())));
226 227
228 if (event->isAlarmEnabled()) {
229 Alarm *alarm =event->alarms().first() ;
230 QDateTime t = alarm->time();
231 QString s =i18n("( %1 before )").arg( alarm->offsetText() );
232 addTag("p",i18n("<b>Alarm on: ") + s +" </b>");
233 addTag("p", KGlobal::locale()->formatDateTime( t, shortDate ));
234 //addTag("p",s);
235 }
236
227 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); 237 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() );
228 formatCategories(event); 238 formatCategories(event);
229 if ( mDetails ) { 239 if ( mDetails ) {
230 if (!event->description().isEmpty()) { 240 if (!event->description().isEmpty()) {
231 addTag("p",i18n("<b>Details: </b>")); 241 addTag("p",i18n("<b>Details: </b>"));
232 addTag("p",deTag(event->description())); 242 addTag("p",deTag(event->description()));
233 } 243 }
234 } 244 }
235 formatReadOnly(event); 245 formatReadOnly(event);
236 formatAttendees(event); 246 formatAttendees(event);
237 if ( mCreated ) { 247 if ( mCreated ) {
238 addTag("p",i18n("<b>Created: ") +" </b>"); 248 addTag("p",i18n("<b>Created: ") +" </b>");
239 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); 249 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate ));
240 250
241 } 251 }
242 if ( mModified ) { 252 if ( mModified ) {
243 addTag("p",i18n("<b>Last modified: ") +" </b>"); 253 addTag("p",i18n("<b>Last modified: ") +" </b>");
244 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); 254 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate ));
245 255
246 } 256 }
247} 257}
248 258
249void KIncidenceFormatter::setJournal(Journal* ) 259void KIncidenceFormatter::setJournal(Journal* )
250{ 260{
251 261
252} 262}
253 263
254void KIncidenceFormatter::formatCategories(Incidence *event) 264void KIncidenceFormatter::formatCategories(Incidence *event)
255{ 265{
256 if (!event->categoriesStr().isEmpty()) { 266 if (!event->categoriesStr().isEmpty()) {
257 addTag("p",i18n("<b>Categories: </b>")+event->categoriesStr() ); 267 addTag("p",i18n("<b>Categories: </b>")+event->categoriesStr() );
258 //mText.append(event->categoriesStr()); 268 //mText.append(event->categoriesStr());
259 } 269 }
260} 270}
261void KIncidenceFormatter::addTag(const QString & tag,const QString & text) 271void KIncidenceFormatter::addTag(const QString & tag,const QString & text)
262{ 272{
263 int number=text.contains("\n"); 273 int number=text.contains("\n");
264 QString str = "<" + tag + ">"; 274 QString str = "<" + tag + ">";
265 QString tmpText=text; 275 QString tmpText=text;
266 QString tmpStr=str; 276 QString tmpStr=str;
267 if(number !=-1) 277 if(number !=-1)
268 { 278 {
269 if (number > 0) { 279 if (number > 0) {
270 int pos=0; 280 int pos=0;
271 QString tmp; 281 QString tmp;
272 for(int i=0;i<=number;i++) { 282 for(int i=0;i<=number;i++) {
273 pos=tmpText.find("\n"); 283 pos=tmpText.find("\n");
274 tmp=tmpText.left(pos); 284 tmp=tmpText.left(pos);
275 tmpText=tmpText.right(tmpText.length()-pos-1); 285 tmpText=tmpText.right(tmpText.length()-pos-1);
276 tmpStr+=tmp+"<br>"; 286 tmpStr+=tmp+"<br>";
277 } 287 }
278 } 288 }
279 else tmpStr += tmpText; 289 else tmpStr += tmpText;
280 tmpStr+="</" + tag + ">"; 290 tmpStr+="</" + tag + ">";
281 mText.append(tmpStr); 291 mText.append(tmpStr);
282 } 292 }
283 else 293 else
284 { 294 {
285 str += text + "</" + tag + ">"; 295 str += text + "</" + tag + ">";
286 mText.append(str); 296 mText.append(str);
287 } 297 }
288} 298}
289 299
290void KIncidenceFormatter::formatAttendees(Incidence *event) 300void KIncidenceFormatter::formatAttendees(Incidence *event)
291{ 301{
292 QPtrList<Attendee> attendees = event->attendees(); 302 QPtrList<Attendee> attendees = event->attendees();
293 if (attendees.count()) { 303 if (attendees.count()) {
294 QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small); 304 QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small);
295 QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small); 305 QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small);
296 addTag("h3",i18n("Organizer")); 306 addTag("h3",i18n("Organizer"));
297 mText.append("<ul><li>"); 307 mText.append("<ul><li>");
298#if 0 308#if 0
299 //ndef KORG_NOKABC 309 //ndef KORG_NOKABC
300 310
301 KABC::AddressBook *add_book = KABC::StdAddressBook::self(); 311 KABC::AddressBook *add_book = KABC::StdAddressBook::self();
302 KABC::Addressee::List addressList; 312 KABC::Addressee::List addressList;
303 addressList = add_book->findByEmail(event->organizer()); 313 addressList = add_book->findByEmail(event->organizer());
304 KABC::Addressee o = addressList.first(); 314 KABC::Addressee o = addressList.first();
305 if (!o.isEmpty() && addressList.size()<2) { 315 if (!o.isEmpty() && addressList.size()<2) {
306 mText += "<a href=\"uid:" + o.uid() + "\">"; 316 mText += "<a href=\"uid:" + o.uid() + "\">";
307 mText += o.formattedName(); 317 mText += o.formattedName();
308 mText += "</a>\n"; 318 mText += "</a>\n";
309 } else { 319 } else {
310 mText.append(event->organizer()); 320 mText.append(event->organizer());
311 } 321 }
312#else 322#else
313 mText.append(event->organizer()); 323 mText.append(event->organizer());
314#endif 324#endif
315 if (iconPath) { 325 if (iconPath) {
316 mText += " <a href=\"mailto:" + event->organizer() + "\">"; 326 mText += " <a href=\"mailto:" + event->organizer() + "\">";
317 mText += "<IMG src=\"" + iconPath + "\">"; 327 mText += "<IMG src=\"" + iconPath + "\">";
318 mText += "</a>\n"; 328 mText += "</a>\n";
319 } 329 }
320 mText.append("</li></ul>"); 330 mText.append("</li></ul>");
321 331
322 addTag("h3",i18n("Attendees")); 332 addTag("h3",i18n("Attendees"));