summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/kincidenceformatter.cpp328
-rw-r--r--libkcal/kincidenceformatter.h42
-rw-r--r--libkcal/libkcalE.pro2
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
10KIncidenceFormatter* KIncidenceFormatter::mInstance = 0;
11static KStaticDeleter<KIncidenceFormatter> insd;
12
13QString 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
28KIncidenceFormatter* KIncidenceFormatter::instance()
29{
30 if (!mInstance) {
31 mInstance = insd.setObject(new KIncidenceFormatter());
32 }
33 return mInstance;
34}
35KIncidenceFormatter::~KIncidenceFormatter()
36{
37 if (mInstance == this)
38 mInstance = insd.setObject(0);
39 //qDebug("KIncidenceFormatter::~KIncidenceFormatter ");
40}
41KIncidenceFormatter::KIncidenceFormatter()
42{
43 mColorMode = 0;
44}
45void 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
147void 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
203void KIncidenceFormatter::setJournal(Journal* )
204{
205
206}
207
208void 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}
215void 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
244void 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
323void 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
12using namespace KCal;
13
14class 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
@@ -27,24 +27,25 @@ HEADERS = \
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 \
39kincidenceformatter.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 \
@@ -64,24 +65,25 @@ SOURCES = \
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 \