summaryrefslogtreecommitdiffabout
path: root/libkcal/kincidenceformatter.cpp
Unidiff
Diffstat (limited to 'libkcal/kincidenceformatter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/kincidenceformatter.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/libkcal/kincidenceformatter.cpp b/libkcal/kincidenceformatter.cpp
index d1ace4f..9359fad 100644
--- a/libkcal/kincidenceformatter.cpp
+++ b/libkcal/kincidenceformatter.cpp
@@ -7,292 +7,295 @@
7#define size count 7#define size count
8#endif 8#endif
9 9
10KIncidenceFormatter* KIncidenceFormatter::mInstance = 0; 10KIncidenceFormatter* KIncidenceFormatter::mInstance = 0;
11static KStaticDeleter<KIncidenceFormatter> insd; 11static KStaticDeleter<KIncidenceFormatter> insd;
12 12
13QString KIncidenceFormatter::getFormattedText( Incidence * inc, bool details, bool created , bool modified ) 13QString KIncidenceFormatter::getFormattedText( Incidence * inc, bool details, bool created , bool modified )
14{ 14{
15// #ifndef QT_NO_INPUTDIALOG 15// #ifndef QT_NO_INPUTDIALOG
16// return QInputDialog::getItem( caption, label, items, current, editable ); 16// return QInputDialog::getItem( caption, label, items, current, editable );
17// #else 17// #else
18// return QString::null; 18// return QString::null;
19// #endif 19// #endif
20 mDetails = details; 20 mDetails = details;
21 mCreated = created ; 21 mCreated = created ;
22 mModified = modified; 22 mModified = modified;
23 mText = ""; 23 mText = "";
24 if ( inc->typeID() == eventID ) 24 if ( inc->typeID() == eventID )
25 setEvent((Event *) inc ); 25 setEvent((Event *) inc );
26 else if ( inc->typeID() == todoID ) 26 else if ( inc->typeID() == todoID )
27 setTodo((Todo *) inc ); 27 setTodo((Todo *) inc );
28 return mText; 28 return mText;
29} 29}
30 30
31KIncidenceFormatter* KIncidenceFormatter::instance() 31KIncidenceFormatter* KIncidenceFormatter::instance()
32{ 32{
33 if (!mInstance) { 33 if (!mInstance) {
34 mInstance = insd.setObject(new KIncidenceFormatter()); 34 mInstance = insd.setObject(new KIncidenceFormatter());
35 } 35 }
36 return mInstance; 36 return mInstance;
37} 37}
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 formatReadOnly(event);
55 } 56 }
56 else { 57 else {
57 if ( mColorMode == 1 ) { 58 if ( mColorMode == 1 ) {
58 mText +="<font color=\"#00A000\">"; 59 mText +="<font color=\"#00A000\">";
59 } 60 }
60 if ( mColorMode == 2 ) { 61 if ( mColorMode == 2 ) {
61 mText +="<font color=\"#C00000\">"; 62 mText +="<font color=\"#C00000\">";
62 } 63 }
63 // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>"; 64 // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>";
64 if ( mode == 1 ) { 65 if ( mode == 1 ) {
65 addTag("h2",i18n( "Local: " ) +deTag(event->summary())); 66 addTag("h2",i18n( "Local: " ) +deTag(event->summary()));
66 } else { 67 } else {
67 addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); 68 addTag("h2",i18n( "Remote: " ) +deTag(event->summary()));
68 } 69 }
70 formatReadOnly(event);
69 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); 71 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) );
70 if ( mColorMode ) 72 if ( mColorMode )
71 mText += "</font>"; 73 mText += "</font>";
72 } 74 }
73 if (event->cancelled ()) { 75 if (event->cancelled ()) {
74 mText +="<font color=\"#B00000\">"; 76 mText +="<font color=\"#B00000\">";
75 addTag("i",i18n("This event has been cancelled!")); 77 addTag("i",i18n("This event has been cancelled!"));
76 mText.append("<br>"); 78 mText.append("<br>");
77 mText += "</font>"; 79 mText += "</font>";
78 } 80 }
79 if (event->doesFloat()) { 81 if (event->doesFloat()) {
80 if (event->isMultiDay()) { 82 if (event->isMultiDay()) {
81 mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>") 83 mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>")
82 .arg(event->dtStartDateStr(shortDate)) 84 .arg(event->dtStartDateStr(shortDate))
83 .arg(event->dtEndDateStr(shortDate))); 85 .arg(event->dtEndDateStr(shortDate)));
84 } else { 86 } else {
85 mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate ))); 87 mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate )));
86 } 88 }
87 } else { 89 } else {
88 if (event->isMultiDay()) { 90 if (event->isMultiDay()) {
89 mText.append(i18n("<p><b>From:</b> %1</p> ") 91 mText.append(i18n("<p><b>From:</b> %1</p> ")
90 .arg(event->dtStartStr( shortDate))); 92 .arg(event->dtStartStr( shortDate)));
91 mText.append(i18n("<p><b>To:</b> %1</p>") 93 mText.append(i18n("<p><b>To:</b> %1</p>")
92 .arg(event->dtEndStr(shortDate))); 94 .arg(event->dtEndStr(shortDate)));
93 } else { 95 } else {
94 mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>") 96 mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>")
95 .arg(event->dtStartTimeStr()) 97 .arg(event->dtStartTimeStr())
96 .arg(event->dtEndTimeStr())); 98 .arg(event->dtEndTimeStr()));
97 mText.append(i18n("<p><b>On:</b> %1</p> ") 99 mText.append(i18n("<p><b>On:</b> %1</p> ")
98 .arg(event->dtStartDateStr( shortDate ))); 100 .arg(event->dtStartDateStr( shortDate )));
99 } 101 }
100 } 102 }
101 if (!event->location().isEmpty()) { 103 if (!event->location().isEmpty()) {
102 addTag("b",i18n("Location: ")); 104 addTag("b",i18n("Location: "));
103 mText.append(deTag(event->location())+"<br>"); 105 mText.append(deTag(event->location())+"<br>");
104 } 106 }
105 107
106 if (event->recurrence()->doesRecur()) { 108 if (event->recurrence()->doesRecur()) {
107 109
108 QString recurText = event->recurrence()->recurrenceText(); 110 QString recurText = event->recurrence()->recurrenceText();
109 addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>"); 111 addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>");
110 112
111 bool ok; 113 bool ok;
112 QDate start = QDate::currentDate(); 114 QDate start = QDate::currentDate();
113 QDateTime next; 115 QDateTime next;
114 next = event->getNextOccurence( QDateTime::currentDateTime() , &ok ); 116 next = event->getNextOccurence( QDateTime::currentDateTime() , &ok );
115 if ( ok ) { 117 if ( ok ) {
116 addTag("p",i18n("<b>Next recurrence is on:</b>") ); 118 addTag("p",i18n("<b>Next recurrence is on:</b>") );
117 addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate )); 119 addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate ));
118 120
119 } else { 121 } else {
120 bool last; 122 bool last;
121 QDate nextd; 123 QDate nextd;
122 nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last ); 124 nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last );
123 if ( last ) { 125 if ( last ) {
124 addTag("p",i18n("<b>Last recurrence was on:</b>") ); 126 addTag("p",i18n("<b>Last recurrence was on:</b>") );
125 addTag("p", KGlobal::locale()->formatDate( nextd, shortDate )); 127 addTag("p", KGlobal::locale()->formatDate( nextd, shortDate ));
126 } 128 }
127 } 129 }
128 } 130 }
129 131
130 132
131 if (event->isAlarmEnabled()) { 133 if (event->isAlarmEnabled()) {
132 Alarm *alarm =event->alarms().first() ; 134 Alarm *alarm =event->alarms().first() ;
133 QDateTime t = alarm->time(); 135 QDateTime t = alarm->time();
134 QString s =i18n("( %1 before )").arg( alarm->offsetText() ); 136 QString s =i18n("( %1 before )").arg( alarm->offsetText() );
135 addTag("p",i18n("<b>Alarm on: </b>") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate )); 137 addTag("p",i18n("<b>Alarm on: </b>") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate ));
136 //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); 138 //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate ));
137 //addTag("p",s); 139 //addTag("p",s);
138 } 140 }
139 141
140 142
141 143
142 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); 144 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() );
143 // mText.append(event->secrecyStr()+"<br>"); 145 // mText.append(event->secrecyStr()+"<br>");
144 formatCategories(event); 146 formatCategories(event);
145 147
146 formatReadOnly(event);
147 formatAttendees(event); 148 formatAttendees(event);
148 149
149 if ( mCreated ) { 150 if ( mCreated ) {
150#ifdef DESKTOP_VERSION 151#ifdef DESKTOP_VERSION
151 addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate )); 152 addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate ));
152#else 153#else
153 addTag("p",i18n("<b>Created: ") +" </b>"); 154 addTag("p",i18n("<b>Created: ") +" </b>");
154 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); 155 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate ));
155#endif 156#endif
156 157
157 } 158 }
158 if ( mModified ) { 159 if ( mModified ) {
159#ifdef DESKTOP_VERSION 160#ifdef DESKTOP_VERSION
160 addTag("p",i18n("<b>Last modified: ") +" </b>"+KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); 161 addTag("p",i18n("<b>Last modified: ") +" </b>"+KGlobal::locale()->formatDateTime( event->lastModified(), shortDate ));
161#else 162#else
162 addTag("p",i18n("<b>Last modified: ") +" </b>"); 163 addTag("p",i18n("<b>Last modified: ") +" </b>");
163 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); 164 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate ));
164#endif 165#endif
165 166
166 } 167 }
167 if ( mDetails ) { 168 if ( mDetails ) {
168 if (!event->description().isEmpty()) { 169 if (!event->description().isEmpty()) {
169 addTag("p",i18n("<b>Details: </b>")); 170 addTag("p",i18n("<b>Details: </b>"));
170 addTag("p",deTag(event->description())); 171 addTag("p",deTag(event->description()));
171 } 172 }
172 } 173 }
173 174
174} 175}
175 176
176void KIncidenceFormatter::setTodo(Todo *event ) 177void KIncidenceFormatter::setTodo(Todo *event )
177{ 178{
178 int mode = 0; 179 int mode = 0;
179 mCurrentIncidence = event; 180 mCurrentIncidence = event;
180 bool shortDate = true; 181 bool shortDate = true;
181 if (mode == 0 ) 182 if (mode == 0 ) {
182 addTag("h3",deTag(event->summary())); 183 addTag("h3",deTag(event->summary()));
184 formatReadOnly(event);
185 }
183 else { 186 else {
184 if ( mColorMode == 1 ) { 187 if ( mColorMode == 1 ) {
185 mText +="<font color=\"#00A000\">"; 188 mText +="<font color=\"#00A000\">";
186 } 189 }
187 if ( mColorMode == 2 ) { 190 if ( mColorMode == 2 ) {
188 mText +="<font color=\"#B00000\">"; 191 mText +="<font color=\"#B00000\">";
189 } 192 }
190 if ( mode == 1 ) { 193 if ( mode == 1 ) {
191 addTag("h2",i18n( "Local: " ) +deTag(event->summary())); 194 addTag("h2",i18n( "Local: " ) +deTag(event->summary()));
192 } else { 195 } else {
193 addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); 196 addTag("h2",i18n( "Remote: " ) +deTag(event->summary()));
194 } 197 }
198 formatReadOnly(event);
195 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); 199 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) );
196 if ( mColorMode ) 200 if ( mColorMode )
197 mText += "</font>"; 201 mText += "</font>";
198 } 202 }
199 if ( event->percentComplete() == 100 && event->hasCompletedDate() ) { 203 if ( event->percentComplete() == 100 && event->hasCompletedDate() ) {
200 mText +="<font color=\"#B00000\">"; 204 mText +="<font color=\"#B00000\">";
201 addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(shortDate) ) ); 205 addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(shortDate) ) );
202 mText += "</font>"; 206 mText += "</font>";
203 } else { 207 } else {
204 mText.append(i18n("<p><i>%1 % completed</i></p>") 208 mText.append(i18n("<p><i>%1 % completed</i></p>")
205 .arg(event->percentComplete())); 209 .arg(event->percentComplete()));
206 } 210 }
207 if (event->cancelled ()) { 211 if (event->cancelled ()) {
208 mText +="<font color=\"#B00000\">"; 212 mText +="<font color=\"#B00000\">";
209 addTag("i",i18n("This todo has been cancelled!")); 213 addTag("i",i18n("This todo has been cancelled!"));
210 mText.append("<br>"); 214 mText.append("<br>");
211 mText += "</font>"; 215 mText += "</font>";
212 } 216 }
213 217
214 218
215 if (event->recurrence()->doesRecur()) { 219 if (event->recurrence()->doesRecur()) {
216 220
217 QString recurText = event->recurrence()->recurrenceText(); 221 QString recurText = event->recurrence()->recurrenceText();
218 addTag("p","<em>" + i18n("This is a %1 recurring todo.").arg(recurText ) + "</em>"); 222 addTag("p","<em>" + i18n("This is a %1 recurring todo.").arg(recurText ) + "</em>");
219 } 223 }
220 224
221 if (event->hasStartDate()) { 225 if (event->hasStartDate()) {
222 mText.append(i18n("<p><b>Start on:</b> %1</p>").arg(event->dtStartStr(shortDate))); 226 mText.append(i18n("<p><b>Start on:</b> %1</p>").arg(event->dtStartStr(shortDate)));
223 } 227 }
224 228
225 229
226 if (event->hasDueDate()) { 230 if (event->hasDueDate()) {
227 mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(shortDate))); 231 mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(shortDate)));
228 } 232 }
229 233
230 if (!event->location().isEmpty()) { 234 if (!event->location().isEmpty()) {
231 addTag("b",i18n("Location: ")); 235 addTag("b",i18n("Location: "));
232 mText.append(deTag(event->location())+"<br>"); 236 mText.append(deTag(event->location())+"<br>");
233 } 237 }
234 238
235 mText.append(i18n("<p><b>Priority:</b> %2</p>") 239 mText.append(i18n("<p><b>Priority:</b> %2</p>")
236 .arg(QString::number(event->priority()))); 240 .arg(QString::number(event->priority())));
237 241
238 if (event->isAlarmEnabled()) { 242 if (event->isAlarmEnabled()) {
239 Alarm *alarm =event->alarms().first() ; 243 Alarm *alarm =event->alarms().first() ;
240 QDateTime t = alarm->time(); 244 QDateTime t = alarm->time();
241 QString s =i18n("( %1 before )").arg( alarm->offsetText() ); 245 QString s =i18n("( %1 before )").arg( alarm->offsetText() );
242 addTag("p",i18n("<b>Alarm on: ") + s +" </b>"); 246 addTag("p",i18n("<b>Alarm on: ") + s +" </b>");
243 addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); 247 addTag("p", KGlobal::locale()->formatDateTime( t, shortDate ));
244 //addTag("p",s); 248 //addTag("p",s);
245 } 249 }
246 250
247 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); 251 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() );
248 formatCategories(event); 252 formatCategories(event);
249 253
250 formatReadOnly(event);
251 formatAttendees(event); 254 formatAttendees(event);
252 if ( mCreated ) { 255 if ( mCreated ) {
253#ifdef DESKTOP_VERSION 256#ifdef DESKTOP_VERSION
254 addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate )); 257 addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate ));
255#else 258#else
256 addTag("p",i18n("<b>Created: ") +" </b>"); 259 addTag("p",i18n("<b>Created: ") +" </b>");
257 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); 260 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate ));
258#endif 261#endif
259 262
260 } 263 }
261 if ( mModified ) { 264 if ( mModified ) {
262#ifdef DESKTOP_VERSION 265#ifdef DESKTOP_VERSION
263 addTag("p",i18n("<b>Last modified: ") +" </b>"+KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); 266 addTag("p",i18n("<b>Last modified: ") +" </b>"+KGlobal::locale()->formatDateTime( event->lastModified(), shortDate ));
264#else 267#else
265 addTag("p",i18n("<b>Last modified: ") +" </b>"); 268 addTag("p",i18n("<b>Last modified: ") +" </b>");
266 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); 269 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate ));
267#endif 270#endif
268 271
269 } 272 }
270 if ( mDetails ) { 273 if ( mDetails ) {
271 if (!event->description().isEmpty()) { 274 if (!event->description().isEmpty()) {
272 addTag("p",i18n("<b>Details: </b>")); 275 addTag("p",i18n("<b>Details: </b>"));
273 addTag("p",deTag(event->description())); 276 addTag("p",deTag(event->description()));
274 } 277 }
275 } 278 }
276} 279}
277 280
278void KIncidenceFormatter::setJournal(Journal* ) 281void KIncidenceFormatter::setJournal(Journal* )
279{ 282{
280 283
281} 284}
282 285
283void KIncidenceFormatter::formatCategories(Incidence *event) 286void KIncidenceFormatter::formatCategories(Incidence *event)
284{ 287{
285 if (!event->categoriesStr().isEmpty()) { 288 if (!event->categoriesStr().isEmpty()) {
286 addTag("p",i18n("<b>Categories: </b>")+event->categoriesStrWithSpace() ); 289 addTag("p",i18n("<b>Categories: </b>")+event->categoriesStrWithSpace() );
287 //mText.append(event->categoriesStr()); 290 //mText.append(event->categoriesStr());
288 } 291 }
289} 292}
290void KIncidenceFormatter::addTag(const QString & tag,const QString & text) 293void KIncidenceFormatter::addTag(const QString & tag,const QString & text)
291{ 294{
292 int number=text.contains("\n"); 295 int number=text.contains("\n");
293 QString str = "<" + tag + ">"; 296 QString str = "<" + tag + ">";
294 QString tmpText=text; 297 QString tmpText=text;
295 QString tmpStr=str; 298 QString tmpStr=str;
296 if(number !=-1) 299 if(number !=-1)
297 { 300 {
298 if (number > 0) { 301 if (number > 0) {