-rw-r--r-- | libkcal/kincidenceformatter.cpp | 328 | ||||
-rw-r--r-- | libkcal/kincidenceformatter.h | 42 | ||||
-rw-r--r-- | libkcal/libkcalE.pro | 2 |
3 files changed, 372 insertions, 0 deletions
diff --git a/libkcal/kincidenceformatter.cpp b/libkcal/kincidenceformatter.cpp new file mode 100644 index 0000000..2c45f21 --- a/dev/null +++ b/libkcal/kincidenceformatter.cpp | |||
@@ -0,0 +1,328 @@ | |||
1 | #include "kincidenceformatter.h" | ||
2 | #include <kstaticdeleter.h> | ||
3 | #include <kglobal.h> | ||
4 | #include <klocale.h> | ||
5 | #ifdef DEKTOP_VERSION | ||
6 | #include <kabc/stdaddressbook.h> | ||
7 | #define size count | ||
8 | #endif | ||
9 | |||
10 | KIncidenceFormatter* KIncidenceFormatter::mInstance = 0; | ||
11 | static KStaticDeleter<KIncidenceFormatter> insd; | ||
12 | |||
13 | QString KIncidenceFormatter::getFormattedText( Incidence * inc ) | ||
14 | { | ||
15 | // #ifndef QT_NO_INPUTDIALOG | ||
16 | // return QInputDialog::getItem( caption, label, items, current, editable ); | ||
17 | // #else | ||
18 | // return QString::null; | ||
19 | // #endif | ||
20 | mText = ""; | ||
21 | if ( inc->type() == "Event" ) | ||
22 | setEvent((Event *) inc ); | ||
23 | else if ( inc->type() == "Todo" ) | ||
24 | setTodo((Todo *) inc ); | ||
25 | return mText; | ||
26 | } | ||
27 | |||
28 | KIncidenceFormatter* KIncidenceFormatter::instance() | ||
29 | { | ||
30 | if (!mInstance) { | ||
31 | mInstance = insd.setObject(new KIncidenceFormatter()); | ||
32 | } | ||
33 | return mInstance; | ||
34 | } | ||
35 | KIncidenceFormatter::~KIncidenceFormatter() | ||
36 | { | ||
37 | if (mInstance == this) | ||
38 | mInstance = insd.setObject(0); | ||
39 | //qDebug("KIncidenceFormatter::~KIncidenceFormatter "); | ||
40 | } | ||
41 | KIncidenceFormatter::KIncidenceFormatter() | ||
42 | { | ||
43 | mColorMode = 0; | ||
44 | } | ||
45 | void KIncidenceFormatter::setEvent(Event *event) | ||
46 | { | ||
47 | int mode = 0; | ||
48 | mCurrentIncidence = event; | ||
49 | bool shortDate = true; | ||
50 | if ( mode == 0 ) { | ||
51 | addTag("h3",event->summary()); | ||
52 | } | ||
53 | else { | ||
54 | if ( mColorMode == 1 ) { | ||
55 | mText +="<font color=\"#00A000\">"; | ||
56 | } | ||
57 | if ( mColorMode == 2 ) { | ||
58 | mText +="<font color=\"#C00000\">"; | ||
59 | } | ||
60 | // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>"; | ||
61 | if ( mode == 1 ) { | ||
62 | addTag("h2",i18n( "Local: " ) +event->summary()); | ||
63 | } else { | ||
64 | addTag("h2",i18n( "Remote: " ) +event->summary()); | ||
65 | } | ||
66 | addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); | ||
67 | if ( mColorMode ) | ||
68 | mText += "</font>"; | ||
69 | } | ||
70 | if (event->cancelled ()) { | ||
71 | mText +="<font color=\"#B00000\">"; | ||
72 | addTag("i",i18n("This event has been cancelled!")); | ||
73 | mText.append("<br>"); | ||
74 | mText += "</font>"; | ||
75 | } | ||
76 | if (!event->location().isEmpty()) { | ||
77 | addTag("b",i18n("Location: ")); | ||
78 | mText.append(event->location()+"<br>"); | ||
79 | } | ||
80 | if (event->doesFloat()) { | ||
81 | if (event->isMultiDay()) { | ||
82 | mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>") | ||
83 | .arg(event->dtStartDateStr(shortDate)) | ||
84 | .arg(event->dtEndDateStr(shortDate))); | ||
85 | } else { | ||
86 | mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate ))); | ||
87 | } | ||
88 | } else { | ||
89 | if (event->isMultiDay()) { | ||
90 | mText.append(i18n("<p><b>From:</b> %1</p> ") | ||
91 | .arg(event->dtStartStr( shortDate))); | ||
92 | mText.append(i18n("<p><b>To:</b> %1</p>") | ||
93 | .arg(event->dtEndStr(shortDate))); | ||
94 | } else { | ||
95 | mText.append(i18n("<p><b>On:</b> %1</p> ") | ||
96 | .arg(event->dtStartDateStr( shortDate ))); | ||
97 | mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>") | ||
98 | .arg(event->dtStartTimeStr()) | ||
99 | .arg(event->dtEndTimeStr())); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | if (event->recurrence()->doesRecur()) { | ||
104 | |||
105 | QString recurText = event->recurrence()->recurrenceText(); | ||
106 | addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>"); | ||
107 | bool last; | ||
108 | QDate start = QDate::currentDate(); | ||
109 | QDate next; | ||
110 | next = event->recurrence()->getPreviousDate( start , &last ); | ||
111 | if ( !last ) { | ||
112 | next = event->recurrence()->getNextDate( start.addDays( - 1 ) ); | ||
113 | addTag("p",i18n("Next recurrence is on: ")+ KGlobal::locale()->formatDate( next, shortDate ) ); | ||
114 | //addTag("p", KGlobal::locale()->formatDate( next, shortDate )); | ||
115 | } else { | ||
116 | addTag("p",i18n("<b>Last recurrence was on:</b>") ); | ||
117 | addTag("p", KGlobal::locale()->formatDate( next, shortDate )); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | |||
122 | if (event->isAlarmEnabled()) { | ||
123 | Alarm *alarm =event->alarms().first() ; | ||
124 | QDateTime t = alarm->time(); | ||
125 | int min = t.secsTo( event->dtStart() )/60; | ||
126 | QString s =i18n("(%1 min before)").arg( min ); | ||
127 | addTag("p",i18n("<b>Alarm on: </b>") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate )); | ||
128 | //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); | ||
129 | //addTag("p",s); | ||
130 | } | ||
131 | |||
132 | addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); | ||
133 | // mText.append(event->secrecyStr()+"<br>"); | ||
134 | formatCategories(event); | ||
135 | if (!event->description().isEmpty()) { | ||
136 | addTag("p",i18n("<b>Details: </b>")); | ||
137 | addTag("p",event->description()); | ||
138 | } | ||
139 | |||
140 | |||
141 | formatReadOnly(event); | ||
142 | formatAttendees(event); | ||
143 | |||
144 | |||
145 | } | ||
146 | |||
147 | void KIncidenceFormatter::setTodo(Todo *event ) | ||
148 | { | ||
149 | int mode = 0; | ||
150 | mCurrentIncidence = event; | ||
151 | bool shortDate = true; | ||
152 | if (mode == 0 ) | ||
153 | addTag("h3",event->summary()); | ||
154 | else { | ||
155 | if ( mColorMode == 1 ) { | ||
156 | mText +="<font color=\"#00A000\">"; | ||
157 | } | ||
158 | if ( mColorMode == 2 ) { | ||
159 | mText +="<font color=\"#B00000\">"; | ||
160 | } | ||
161 | if ( mode == 1 ) { | ||
162 | addTag("h2",i18n( "Local: " ) +event->summary()); | ||
163 | } else { | ||
164 | addTag("h2",i18n( "Remote: " ) +event->summary()); | ||
165 | } | ||
166 | addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); | ||
167 | if ( mColorMode ) | ||
168 | mText += "</font>"; | ||
169 | } | ||
170 | if (event->cancelled ()) { | ||
171 | mText +="<font color=\"#B00000\">"; | ||
172 | addTag("i",i18n("This todo has been cancelled!")); | ||
173 | mText.append("<br>"); | ||
174 | mText += "</font>"; | ||
175 | } | ||
176 | |||
177 | if (!event->location().isEmpty()) { | ||
178 | addTag("b",i18n("Location: ")); | ||
179 | mText.append(event->location()+"<br>"); | ||
180 | } | ||
181 | if (event->hasDueDate()) { | ||
182 | mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(shortDate))); | ||
183 | } | ||
184 | mText.append(i18n("<p><b>Priority:</b> %2</p>") | ||
185 | .arg(QString::number(event->priority()))); | ||
186 | |||
187 | mText.append(i18n("<p><i>%1 % completed</i></p>") | ||
188 | .arg(event->percentComplete())); | ||
189 | addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); | ||
190 | formatCategories(event); | ||
191 | if (!event->description().isEmpty()) { | ||
192 | addTag("p",i18n("<b>Details: </b>")); | ||
193 | addTag("p",event->description()); | ||
194 | } | ||
195 | |||
196 | |||
197 | |||
198 | formatReadOnly(event); | ||
199 | formatAttendees(event); | ||
200 | |||
201 | } | ||
202 | |||
203 | void KIncidenceFormatter::setJournal(Journal* ) | ||
204 | { | ||
205 | |||
206 | } | ||
207 | |||
208 | void KIncidenceFormatter::formatCategories(Incidence *event) | ||
209 | { | ||
210 | if (!event->categoriesStr().isEmpty()) { | ||
211 | addTag("p",i18n("<b>Categories: </b>")+event->categoriesStr() ); | ||
212 | //mText.append(event->categoriesStr()); | ||
213 | } | ||
214 | } | ||
215 | void KIncidenceFormatter::addTag(const QString & tag,const QString & text) | ||
216 | { | ||
217 | int number=text.contains("\n"); | ||
218 | QString str = "<" + tag + ">"; | ||
219 | QString tmpText=text; | ||
220 | QString tmpStr=str; | ||
221 | if(number !=-1) | ||
222 | { | ||
223 | if (number > 0) { | ||
224 | int pos=0; | ||
225 | QString tmp; | ||
226 | for(int i=0;i<=number;i++) { | ||
227 | pos=tmpText.find("\n"); | ||
228 | tmp=tmpText.left(pos); | ||
229 | tmpText=tmpText.right(tmpText.length()-pos-1); | ||
230 | tmpStr+=tmp+"<br>"; | ||
231 | } | ||
232 | } | ||
233 | else tmpStr += tmpText; | ||
234 | tmpStr+="</" + tag + ">"; | ||
235 | mText.append(tmpStr); | ||
236 | } | ||
237 | else | ||
238 | { | ||
239 | str += text + "</" + tag + ">"; | ||
240 | mText.append(str); | ||
241 | } | ||
242 | } | ||
243 | |||
244 | void KIncidenceFormatter::formatAttendees(Incidence *event) | ||
245 | { | ||
246 | QPtrList<Attendee> attendees = event->attendees(); | ||
247 | if (attendees.count()) { | ||
248 | QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small); | ||
249 | addTag("h3",i18n("Organizer")); | ||
250 | mText.append("<ul><li>"); | ||
251 | #if 0 | ||
252 | //ndef KORG_NOKABC | ||
253 | |||
254 | KABC::AddressBook *add_book = KABC::StdAddressBook::self(); | ||
255 | KABC::Addressee::List addressList; | ||
256 | addressList = add_book->findByEmail(event->organizer()); | ||
257 | KABC::Addressee o = addressList.first(); | ||
258 | if (!o.isEmpty() && addressList.size()<2) { | ||
259 | mText += "<a href=\"uid:" + o.uid() + "\">"; | ||
260 | mText += o.formattedName(); | ||
261 | mText += "</a>\n"; | ||
262 | } else { | ||
263 | mText.append(event->organizer()); | ||
264 | } | ||
265 | #else | ||
266 | mText.append(event->organizer()); | ||
267 | #endif | ||
268 | if (iconPath) { | ||
269 | mText += " <a href=\"mailto:" + event->organizer() + "\">"; | ||
270 | mText += "<IMG src=\"" + iconPath + "\">"; | ||
271 | mText += "</a>\n"; | ||
272 | } | ||
273 | mText.append("</li></ul>"); | ||
274 | |||
275 | addTag("h3",i18n("Attendees")); | ||
276 | Attendee *a; | ||
277 | mText.append("<ul>"); | ||
278 | for(a=attendees.first();a;a=attendees.next()) { | ||
279 | #if 0 | ||
280 | //ndef KORG_NOKABC | ||
281 | if (a->name().isEmpty()) { | ||
282 | addressList = add_book->findByEmail(a->email()); | ||
283 | KABC::Addressee o = addressList.first(); | ||
284 | if (!o.isEmpty() && addressList.size()<2) { | ||
285 | mText += "<a href=\"uid:" + o.uid() + "\">"; | ||
286 | mText += o.formattedName(); | ||
287 | mText += "</a>\n"; | ||
288 | } else { | ||
289 | mText += "<li>"; | ||
290 | mText.append(a->email()); | ||
291 | mText += "\n"; | ||
292 | } | ||
293 | } else { | ||
294 | mText += "<li><a href=\"uid:" + a->uid() + "\">"; | ||
295 | if (!a->name().isEmpty()) mText += a->name(); | ||
296 | else mText += a->email(); | ||
297 | mText += "</a>\n"; | ||
298 | } | ||
299 | #else | ||
300 | //qDebug("nokabc "); | ||
301 | mText += "<li><a href=\"uid:" + a->uid() + "\">"; | ||
302 | if (!a->name().isEmpty()) mText += a->name(); | ||
303 | else mText += a->email(); | ||
304 | mText += "</a>\n"; | ||
305 | #endif | ||
306 | |||
307 | if (!a->email().isEmpty()) { | ||
308 | if (iconPath) { | ||
309 | mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">"; | ||
310 | mText += "<IMG src=\"" + iconPath + "\">"; | ||
311 | mText += "</a>\n"; | ||
312 | } | ||
313 | } | ||
314 | if (a->status() != Attendee::NeedsAction ) | ||
315 | mText +="[" + a->statusStr() + "] "; | ||
316 | if (a->role() == Attendee::Chair ) | ||
317 | mText +="(" + a->roleStr().left(1) + ".)"; | ||
318 | } | ||
319 | mText.append("</li></ul>"); | ||
320 | } | ||
321 | } | ||
322 | |||
323 | void KIncidenceFormatter::formatReadOnly(Incidence *event) | ||
324 | { | ||
325 | if (event->isReadOnly()) { | ||
326 | addTag("p","<em>(" + i18n("read-only") + ")</em>"); | ||
327 | } | ||
328 | } | ||
diff --git a/libkcal/kincidenceformatter.h b/libkcal/kincidenceformatter.h new file mode 100644 index 0000000..6165a9f --- a/dev/null +++ b/libkcal/kincidenceformatter.h | |||
@@ -0,0 +1,42 @@ | |||
1 | #ifndef KINCIDENCENFORMATTER_H | ||
2 | #define KINCIDENCENFORMATTER_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qobject.h> | ||
6 | |||
7 | #include "incidence.h" | ||
8 | #include "event.h" | ||
9 | #include "todo.h" | ||
10 | #include "journal.h" | ||
11 | |||
12 | using namespace KCal; | ||
13 | |||
14 | class KIncidenceFormatter : public QObject | ||
15 | { | ||
16 | public: | ||
17 | static KIncidenceFormatter* instance(); | ||
18 | KIncidenceFormatter(); | ||
19 | ~KIncidenceFormatter(); | ||
20 | QString getFormattedText( Incidence * inc ); | ||
21 | |||
22 | void setEvent(Event *event); | ||
23 | void setTodo(Todo *event ); | ||
24 | void setJournal(Journal* ); | ||
25 | |||
26 | protected: | ||
27 | int mColorMode; | ||
28 | void addTag(const QString & tag,const QString & text); | ||
29 | |||
30 | void formatCategories(Incidence *event); | ||
31 | void formatAttendees(Incidence *event); | ||
32 | void formatReadOnly(Incidence *event); | ||
33 | |||
34 | private: | ||
35 | bool mSyncMode; | ||
36 | |||
37 | QString mText; | ||
38 | Incidence* mCurrentIncidence; | ||
39 | static KIncidenceFormatter* mInstance; | ||
40 | }; | ||
41 | |||
42 | #endif | ||
diff --git a/libkcal/libkcalE.pro b/libkcal/libkcalE.pro index f5be980..1f5ef78 100644 --- a/libkcal/libkcalE.pro +++ b/libkcal/libkcalE.pro | |||
@@ -1,89 +1,91 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | TARGET = microkcal | 3 | TARGET = microkcal |
4 | 4 | ||
5 | INCLUDEPATH += ../microkde ../qtcompat versit ../microkde/kdecore $(QPEDIR)/include | 5 | INCLUDEPATH += ../microkde ../qtcompat versit ../microkde/kdecore $(QPEDIR)/include |
6 | INCLUDEPATH += ../libical/src/libical | 6 | INCLUDEPATH += ../libical/src/libical |
7 | INCLUDEPATH += ../libical/src/libicalss | 7 | INCLUDEPATH += ../libical/src/libicalss |
8 | OBJECTS_DIR = obj/$(PLATFORM) | 8 | OBJECTS_DIR = obj/$(PLATFORM) |
9 | MOC_DIR = moc/$(PLATFORM) | 9 | MOC_DIR = moc/$(PLATFORM) |
10 | DESTDIR = $(QPEDIR)/lib | 10 | DESTDIR = $(QPEDIR)/lib |
11 | LIBS += ../libical/lib/$(PLATFORM)/libical.a | 11 | LIBS += ../libical/lib/$(PLATFORM)/libical.a |
12 | LIBS += ../libical/lib/$(PLATFORM)/libicalss.a | 12 | LIBS += ../libical/lib/$(PLATFORM)/libicalss.a |
13 | 13 | ||
14 | INTERFACES = \ | 14 | INTERFACES = \ |
15 | 15 | ||
16 | HEADERS = \ | 16 | HEADERS = \ |
17 | alarm.h \ | 17 | alarm.h \ |
18 | attachment.h \ | 18 | attachment.h \ |
19 | attendee.h \ | 19 | attendee.h \ |
20 | calendar.h \ | 20 | calendar.h \ |
21 | calendarlocal.h \ | 21 | calendarlocal.h \ |
22 | calfilter.h \ | 22 | calfilter.h \ |
23 | calformat.h \ | 23 | calformat.h \ |
24 | calstorage.h \ | 24 | calstorage.h \ |
25 | compat.h \ | 25 | compat.h \ |
26 | customproperties.h \ | 26 | customproperties.h \ |
27 | dummyscheduler.h \ | 27 | dummyscheduler.h \ |
28 | duration.h \ | 28 | duration.h \ |
29 | event.h \ | 29 | event.h \ |
30 | exceptions.h \ | 30 | exceptions.h \ |
31 | filestorage.h \ | 31 | filestorage.h \ |
32 | freebusy.h \ | 32 | freebusy.h \ |
33 | icaldrag.h \ | 33 | icaldrag.h \ |
34 | icalformat.h \ | 34 | icalformat.h \ |
35 | icalformatimpl.h \ | 35 | icalformatimpl.h \ |
36 | imipscheduler.h \ | 36 | imipscheduler.h \ |
37 | incidence.h \ | 37 | incidence.h \ |
38 | incidencebase.h \ | 38 | incidencebase.h \ |
39 | kincidenceformatter.h \ | ||
39 | journal.h \ | 40 | journal.h \ |
40 | period.h \ | 41 | period.h \ |
41 | person.h \ | 42 | person.h \ |
42 | qtopiaformat.h \ | 43 | qtopiaformat.h \ |
43 | sharpformat.h \ | 44 | sharpformat.h \ |
44 | phoneformat.h \ | 45 | phoneformat.h \ |
45 | recurrence.h \ | 46 | recurrence.h \ |
46 | scheduler.h \ | 47 | scheduler.h \ |
47 | todo.h \ | 48 | todo.h \ |
48 | vcaldrag.h \ | 49 | vcaldrag.h \ |
49 | vcalformat.h \ | 50 | vcalformat.h \ |
50 | versit/port.h \ | 51 | versit/port.h \ |
51 | versit/vcc.h \ | 52 | versit/vcc.h \ |
52 | versit/vobject.h \ | 53 | versit/vobject.h \ |
53 | 54 | ||
54 | SOURCES = \ | 55 | SOURCES = \ |
55 | alarm.cpp \ | 56 | alarm.cpp \ |
56 | attachment.cpp \ | 57 | attachment.cpp \ |
57 | attendee.cpp \ | 58 | attendee.cpp \ |
58 | calendar.cpp \ | 59 | calendar.cpp \ |
59 | calendarlocal.cpp \ | 60 | calendarlocal.cpp \ |
60 | calfilter.cpp \ | 61 | calfilter.cpp \ |
61 | calformat.cpp \ | 62 | calformat.cpp \ |
62 | compat.cpp \ | 63 | compat.cpp \ |
63 | customproperties.cpp \ | 64 | customproperties.cpp \ |
64 | dummyscheduler.cpp \ | 65 | dummyscheduler.cpp \ |
65 | duration.cpp \ | 66 | duration.cpp \ |
66 | event.cpp \ | 67 | event.cpp \ |
67 | exceptions.cpp \ | 68 | exceptions.cpp \ |
68 | filestorage.cpp \ | 69 | filestorage.cpp \ |
69 | freebusy.cpp \ | 70 | freebusy.cpp \ |
70 | icaldrag.cpp \ | 71 | icaldrag.cpp \ |
71 | icalformat.cpp \ | 72 | icalformat.cpp \ |
72 | icalformatimpl.cpp \ | 73 | icalformatimpl.cpp \ |
73 | imipscheduler.cpp \ | 74 | imipscheduler.cpp \ |
74 | incidence.cpp \ | 75 | incidence.cpp \ |
75 | incidencebase.cpp \ | 76 | incidencebase.cpp \ |
77 | kincidenceformatter.cpp \ | ||
76 | journal.cpp \ | 78 | journal.cpp \ |
77 | period.cpp \ | 79 | period.cpp \ |
78 | person.cpp \ | 80 | person.cpp \ |
79 | qtopiaformat.cpp \ | 81 | qtopiaformat.cpp \ |
80 | sharpformat.cpp \ | 82 | sharpformat.cpp \ |
81 | phoneformat.cpp \ | 83 | phoneformat.cpp \ |
82 | recurrence.cpp \ | 84 | recurrence.cpp \ |
83 | scheduler.cpp \ | 85 | scheduler.cpp \ |
84 | todo.cpp \ | 86 | todo.cpp \ |
85 | vcaldrag.cpp \ | 87 | vcaldrag.cpp \ |
86 | vcalformat.cpp \ | 88 | vcalformat.cpp \ |
87 | versit/vcc.c \ | 89 | versit/vcc.c \ |
88 | versit/vobject.c \ | 90 | versit/vobject.c \ |
89 | 91 | ||