summaryrefslogtreecommitdiffabout
path: root/libkdepim/kincidenceformatter.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /libkdepim/kincidenceformatter.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'libkdepim/kincidenceformatter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kincidenceformatter.cpp326
1 files changed, 326 insertions, 0 deletions
diff --git a/libkdepim/kincidenceformatter.cpp b/libkdepim/kincidenceformatter.cpp
new file mode 100644
index 0000000..4815519
--- a/dev/null
+++ b/libkdepim/kincidenceformatter.cpp
@@ -0,0 +1,326 @@
1#include "kincidenceformatter.h"
2#include <kstaticdeleter.h>
3#include <kglobal.h>
4#include <klocale.h>
5#ifndef KORG_NOKABC
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#ifndef KORG_NOKABC
252
253 KABC::AddressBook *add_book = KABC::StdAddressBook::self();
254 KABC::Addressee::List addressList;
255 addressList = add_book->findByEmail(event->organizer());
256 KABC::Addressee o = addressList.first();
257 if (!o.isEmpty() && addressList.size()<2) {
258 mText += "<a href=\"uid:" + o.uid() + "\">";
259 mText += o.formattedName();
260 mText += "</a>\n";
261 } else {
262 mText.append(event->organizer());
263 }
264#else
265 mText.append(event->organizer());
266#endif
267 if (iconPath) {
268 mText += " <a href=\"mailto:" + event->organizer() + "\">";
269 mText += "<IMG src=\"" + iconPath + "\">";
270 mText += "</a>\n";
271 }
272 mText.append("</li></ul>");
273
274 addTag("h3",i18n("Attendees"));
275 Attendee *a;
276 mText.append("<ul>");
277 for(a=attendees.first();a;a=attendees.next()) {
278#ifndef KORG_NOKABC
279 if (a->name().isEmpty()) {
280 addressList = add_book->findByEmail(a->email());
281 KABC::Addressee o = addressList.first();
282 if (!o.isEmpty() && addressList.size()<2) {
283 mText += "<a href=\"uid:" + o.uid() + "\">";
284 mText += o.formattedName();
285 mText += "</a>\n";
286 } else {
287 mText += "<li>";
288 mText.append(a->email());
289 mText += "\n";
290 }
291 } else {
292 mText += "<li><a href=\"uid:" + a->uid() + "\">";
293 if (!a->name().isEmpty()) mText += a->name();
294 else mText += a->email();
295 mText += "</a>\n";
296 }
297#else
298 //qDebug("nokabc ");
299 mText += "<li><a href=\"uid:" + a->uid() + "\">";
300 if (!a->name().isEmpty()) mText += a->name();
301 else mText += a->email();
302 mText += "</a>\n";
303#endif
304
305 if (!a->email().isEmpty()) {
306 if (iconPath) {
307 mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">";
308 mText += "<IMG src=\"" + iconPath + "\">";
309 mText += "</a>\n";
310 }
311 }
312 if (a->status() != Attendee::NeedsAction )
313 mText +="[" + a->statusStr() + "] ";
314 if (a->role() == Attendee::Chair )
315 mText +="(" + a->roleStr().left(1) + ".)";
316 }
317 mText.append("</li></ul>");
318 }
319}
320
321void KIncidenceFormatter::formatReadOnly(Incidence *event)
322{
323 if (event->isReadOnly()) {
324 addTag("p","<em>(" + i18n("read-only") + ")</em>");
325 }
326}