pilotDateEntry.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "options.h"
00030
00031 #include <stdlib.h>
00032
00033 #include <qtextcodec.h>
00034 #include <qdatetime.h>
00035
00036 #ifndef _KDEBUG_H_
00037 #include <kdebug.h>
00038 #endif
00039
00040 #include "pilotDateEntry.h"
00041
00042 static const char *pilotDateEntry_id = "$Id: pilotDateEntry.cc,v 1.14 2003/11/24 00:29:20 adridg Exp $";
00043
00044
00045 PilotDateEntry::PilotDateEntry(void):PilotAppCategory()
00046 {
00047 ::memset(&fAppointmentInfo, 0, sizeof(struct Appointment));
00048 }
00049
00050
00051
00052 PilotDateEntry::PilotDateEntry(PilotRecord * rec):PilotAppCategory(rec)
00053 {
00054 ::memset(&fAppointmentInfo, 0, sizeof(fAppointmentInfo));
00055 if (rec)
00056 {
00057 unpack_Appointment(&fAppointmentInfo,
00058 (unsigned char *) rec->getData(), rec->getLen());
00059 }
00060 return;
00061
00062
00063
00064 (void) pilotDateEntry_id;
00065 }
00066
00067 void PilotDateEntry::_copyExceptions(const PilotDateEntry & e)
00068 {
00069 if (e.fAppointmentInfo.exceptions > 0)
00070 {
00071 size_t blocksize = e.fAppointmentInfo.exceptions *
00072 sizeof(struct tm);
00073
00074 fAppointmentInfo.exception = (struct tm *)::malloc(blocksize);
00075
00076 if (fAppointmentInfo.exception)
00077 {
00078 fAppointmentInfo.exceptions =
00079 e.fAppointmentInfo.exceptions;
00080 ::memcpy(fAppointmentInfo.exception,
00081 e.fAppointmentInfo.exception, blocksize);
00082 }
00083 else
00084 {
00085 kdError(LIBPILOTDB_AREA) << __FUNCTION__
00086 << ": malloc() failed, exceptions not copied"
00087 << endl;
00088 fAppointmentInfo.exceptions = 0;
00089 }
00090 }
00091 else
00092 {
00093 fAppointmentInfo.exceptions = 0;
00094 fAppointmentInfo.exception = 0L;
00095 }
00096 }
00097
00098
00099 PilotDateEntry::PilotDateEntry(const PilotDateEntry & e):PilotAppCategory(e)
00100 {
00101 ::memcpy(&fAppointmentInfo, &e.fAppointmentInfo,
00102 sizeof(struct Appointment));
00103
00104 fAppointmentInfo.exception = 0L;
00105 fAppointmentInfo.description = 0L;
00106 fAppointmentInfo.note = 0L;
00107
00108 _copyExceptions(e);
00109 setDescriptionP(e.fAppointmentInfo.description);
00110 setNoteP(e.fAppointmentInfo.note);
00111 }
00112
00113
00114 PilotDateEntry & PilotDateEntry::operator = (const PilotDateEntry & e)
00115 {
00116 if (this != &e)
00117 {
00118 KPILOT_FREE(fAppointmentInfo.exception);
00119 KPILOT_FREE(fAppointmentInfo.description);
00120 KPILOT_FREE(fAppointmentInfo.note);
00121 ::memcpy(&fAppointmentInfo, &e.fAppointmentInfo,
00122 sizeof(fAppointmentInfo));
00123
00124
00125
00126
00127
00128
00129
00130
00131 fAppointmentInfo.exception = 0L;
00132 fAppointmentInfo.description = 0L;
00133 fAppointmentInfo.note = 0L;
00134
00135 _copyExceptions(e);
00136 setDescriptionP(e.fAppointmentInfo.description);
00137 setNoteP(e.fAppointmentInfo.note);
00138 }
00139
00140 return *this;
00141 }
00142
00143
00144 QString PilotDateEntry::getTextRepresentation(bool richText)
00145 {
00146 QString text, tmp;
00147 QString par = richText?CSL1("<p>"):QString::null;
00148 QString ps = richText?CSL1("</p>"):CSL1("\n");
00149 QString br = richText?CSL1("<br/>"):CSL1("\n");
00150
00151
00152 text += par;
00153 tmp=richText?CSL1("<b><big>%1</big></b>"):CSL1("%1");
00154 text += tmp.arg(rtExpand(getDescription(), richText));
00155 text += ps;
00156
00157 QDateTime dt(readTm(getEventStart()));
00158 QString startDate(dt.toString(Qt::LocalDate));
00159 text+=par;
00160 text+=i18n("Start date: %1").arg(startDate);
00161 text+=ps;
00162
00163 if (isEvent())
00164 {
00165 text+=par;
00166 text+=i18n("Whole-day event");
00167 text+=ps;
00168 }
00169 else
00170 {
00171 dt=readTm(getEventEnd());
00172 QString endDate(dt.toString(Qt::LocalDate));
00173 text+=par;
00174 text+=i18n("End date: %1").arg(endDate);
00175 text+=ps;
00176 }
00177
00178 if (getAlarm())
00179 {
00180 text+=par;
00181 tmp=i18n("%1 is the duration, %2 is the time unit", "Alarm: %1 %2 before event starts").
00182 arg(getAdvance());
00183 switch (getAdvanceUnits())
00184 {
00185 case advMinutes: tmp=tmp.arg(i18n("minutes")); break;
00186 case advHours: tmp=tmp.arg(i18n("hours")); break;
00187 case advDays: tmp=tmp.arg(i18n("days")); break;
00188 default: tmp=tmp.arg(QString::null); break;;
00189 }
00190 text+=tmp;
00191 text+=ps;
00192 }
00193
00194 if (getRepeatType() != repeatNone)
00195 {
00196 text+=par;
00197 tmp=i18n("Recurrence: every %1 %2");
00198 int freq = getRepeatFrequency();
00199 tmp=tmp.arg(freq);
00200
00201 switch(getRepeatType())
00202 {
00203 case repeatDaily: tmp=tmp.arg(i18n("day(s)")); break;
00204 case repeatWeekly: tmp=tmp.arg(i18n("week(s)")); break;
00205 case repeatMonthlyByDay:
00206 case repeatMonthlyByDate: tmp=tmp.arg(i18n("month(s)")); break;
00207 case repeatYearly: tmp=tmp.arg(i18n("year(s)")); break;
00208 default: tmp=tmp.arg(QString::null); break;
00209 }
00210 text+=tmp;
00211 text+=br;
00212
00213 bool repeatsForever = getRepeatForever();
00214 if (repeatsForever)
00215 {
00216 text+=i18n("Repeats indefinitely");
00217 }
00218 else
00219 {
00220 dt = readTm(getRepeatEnd()).date();
00221 text+=i18n("Until %1").arg(dt.toString(Qt::LocalDate));
00222 }
00223 text+=br;
00224
00225 if (getRepeatType()==repeatMonthlyByDay) text+=i18n("Repeating on the i-th day of week j")+br;
00226 if (getRepeatType()==repeatMonthlyByDate) text+=i18n("Repeating on the n-th day of the month")+br;
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 text+=ps;
00239 }
00240
00241 if (getExceptionCount()>0 )
00242 {
00243 text+=par;
00244 text+=i18n("Exceptions:")+br;
00245 for (int i = 0; i < getExceptionCount(); i++)
00246 {
00247 QDate exdt=readTm(getExceptions()[i]).date();
00248 text+=exdt.toString(Qt::LocalDate);
00249 text+=br;
00250 }
00251 text+=ps;
00252 }
00253
00254 if (!getNote().isEmpty())
00255 {
00256 text += richText?CSL1("<hr/>"):CSL1("-------------------------\n");
00257 text+=par;
00258 text+=richText?i18n("<b><em>Note:</em></b><br>"):i18n("Note:\n");
00259 text+=rtExpand(getNote(), richText);
00260 text+=ps;
00261 }
00262
00263 return text;
00264 }
00265
00266
00267 void *PilotDateEntry::pack(void *buf, int *len)
00268 {
00269 int i;
00270
00271 i = pack_Appointment(&fAppointmentInfo, (unsigned char *) buf, *len);
00272 *len = i;
00273 return buf;
00274 }
00275
00276
00277
00278
00279 void PilotDateEntry::setExceptions(struct tm *e) {
00280 if (fAppointmentInfo.exception != e)
00281 {
00282 KPILOT_FREE(fAppointmentInfo.exception);
00283 }
00284 fAppointmentInfo.exception=e;
00285 }
00286
00287
00288 void PilotDateEntry::setDescriptionP(const char *desc, int l)
00289 {
00290 FUNCTIONSETUP;
00291 KPILOT_FREE(fAppointmentInfo.description);
00292
00293 if (desc && *desc)
00294 {
00295 if (-1 == l) l=::strlen(desc);
00296 fAppointmentInfo.description =
00297 (char *) ::malloc(l + 1);
00298 if (fAppointmentInfo.description)
00299 {
00300 ::strcpy(fAppointmentInfo.description, desc);
00301 }
00302 else
00303 {
00304 kdError(LIBPILOTDB_AREA) << __FUNCTION__
00305 << ": malloc() failed, description not set"
00306 << endl;
00307 }
00308 }
00309 else
00310 {
00311 fAppointmentInfo.description = 0L;
00312 }
00313 }
00314
00315 void PilotDateEntry::setNoteP(const char *note, int l)
00316 {
00317 FUNCTIONSETUP;
00318 KPILOT_FREE(fAppointmentInfo.note);
00319
00320 if (note && *note)
00321 {
00322 if (-1 == l) l=::strlen(note);
00323 fAppointmentInfo.note = (char *)::malloc(l + 1);
00324 if (fAppointmentInfo.note)
00325 {
00326 strcpy(fAppointmentInfo.note, note);
00327 }
00328 else
00329 {
00330 kdError(LIBPILOTDB_AREA) << __FUNCTION__
00331 << ": malloc() failed, note not set" << endl;
00332 }
00333 }
00334 else
00335 {
00336 fAppointmentInfo.note = 0L;
00337 }
00338 }
00339
00340 void PilotDateEntry::setNote(const QString &s)
00341 {
00342 setNoteP(codec()->fromUnicode(s),s.length());
00343 }
00344
00345 void PilotDateEntry::setDescription(const QString &s)
00346 {
00347 setDescriptionP(codec()->fromUnicode(s),s.length());
00348 }
00349
00350 QString PilotDateEntry::getNote() const
00351 {
00352 return codec()->toUnicode(getNoteP());
00353 }
00354
00355 QString PilotDateEntry::getDescription() const
00356 {
00357 return codec()->toUnicode(getDescriptionP());
00358 }
00359
This file is part of the documentation for kpilot Library Version 3.2.2.